@seqyuan/annovibe 0.8.118 → 0.8.119

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 (155) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-path-routes-manifest.json +10 -9
  3. package/.next/build-manifest.json +3 -3
  4. package/.next/prerender-manifest.json +27 -3
  5. package/.next/react-loadable-manifest.json +4 -4
  6. package/.next/required-server-files.js +1 -1
  7. package/.next/required-server-files.json +1 -1
  8. package/.next/routes-manifest.json +6 -0
  9. package/.next/server/app/_global-error/page.js +2 -2
  10. package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  11. package/.next/server/app/_global-error.html +1 -1
  12. package/.next/server/app/_global-error.rsc +1 -1
  13. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  14. package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  15. package/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  16. package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  17. package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  18. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  19. package/.next/server/app/_not-found/page.js +2 -2
  20. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  21. package/.next/server/app/_not-found.html +1 -1
  22. package/.next/server/app/_not-found.rsc +1 -1
  23. package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  24. package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  25. package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  26. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  27. package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  28. package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  29. package/.next/server/app/api/agent/[id]/events/route.js +4 -3
  30. package/.next/server/app/api/agent/[id]/prepare/route.js +1 -1
  31. package/.next/server/app/api/agent/[id]/route.js +1 -1
  32. package/.next/server/app/api/agent/new/route.js +1 -1
  33. package/.next/server/app/api/agent/running/events/route.js +2 -2
  34. package/.next/server/app/api/agent/runtime/route.js +1 -1
  35. package/.next/server/app/api/apps/[id]/[[...path]]/route.js +1 -1
  36. package/.next/server/app/api/apps/route.js +2 -2
  37. package/.next/server/app/api/auth/all-providers/route.js +1 -1
  38. package/.next/server/app/api/auth/api-key/[provider]/route.js +1 -1
  39. package/.next/server/app/api/auth/login/[provider]/route.js +2 -2
  40. package/.next/server/app/api/auth/login/route.js +1 -1
  41. package/.next/server/app/api/auth/logout/[provider]/route.js +1 -1
  42. package/.next/server/app/api/auth/providers/route.js +1 -1
  43. package/.next/server/app/api/auth/status/route.js +1 -1
  44. package/.next/server/app/api/auth/totp/route.js +1 -1
  45. package/.next/server/app/api/debug-models/route.js +1 -1
  46. package/.next/server/app/api/default-cwd/route.js +1 -1
  47. package/.next/server/app/api/file-tree/delete/route.js +1 -1
  48. package/.next/server/app/api/file-tree/mkdir/route.js +1 -1
  49. package/.next/server/app/api/file-tree/rename/route.js +1 -1
  50. package/.next/server/app/api/file-tree/reveal/route.js +1 -1
  51. package/.next/server/app/api/file-tree/write/route.js +1 -1
  52. package/.next/server/app/api/file-watch/route.js +2 -2
  53. package/.next/server/app/api/files/[...path]/route.js +1 -1
  54. package/.next/server/app/api/harness/route.js +1 -1
  55. package/.next/server/app/api/home/route.js +1 -1
  56. package/.next/server/app/api/im/cancel/route.js +1 -1
  57. package/.next/server/app/api/im/gateway-status/route.js +1 -1
  58. package/.next/server/app/api/im/gateway-token/route.js +1 -1
  59. package/.next/server/app/api/im/project/route.js +1 -1
  60. package/.next/server/app/api/im/projects/route.js +1 -1
  61. package/.next/server/app/api/im/session-ids/route.js +1 -1
  62. package/.next/server/app/api/im/turn/route.js +2 -2
  63. package/.next/server/app/api/images/upload/route.js +1 -1
  64. package/.next/server/app/api/internal/runtime/route.js +1 -1
  65. package/.next/server/app/api/memory/dismiss/route.js +2 -2
  66. package/.next/server/app/api/memory/promote/route.js +2 -2
  67. package/.next/server/app/api/models/route.js +1 -1
  68. package/.next/server/app/api/models-config/discover/route.js +1 -1
  69. package/.next/server/app/api/models-config/route.js +1 -1
  70. package/.next/server/app/api/models-config/test/route.js +1 -1
  71. package/.next/server/app/api/plot-kernels/route.js +1 -1
  72. package/.next/server/app/api/plot-kernels/save/route.js +1 -1
  73. package/.next/server/app/api/plot-kernels/status/route.js +1 -1
  74. package/.next/server/app/api/plot-kernels/stop/route.js +1 -1
  75. package/.next/server/app/api/projects/browse/route.js +1 -1
  76. package/.next/server/app/api/projects/route.js +1 -1
  77. package/.next/server/app/api/search/route.js +1 -1
  78. package/.next/server/app/api/sessions/[id]/context/route.js +1 -1
  79. package/.next/server/app/api/sessions/[id]/kernel-state/route.js +1 -1
  80. package/.next/server/app/api/sessions/[id]/plan/route.js +1 -1
  81. package/.next/server/app/api/sessions/[id]/route.js +1 -1
  82. package/.next/server/app/api/sessions/[id]/workbench-artifact/route.js +1 -1
  83. package/.next/server/app/api/sessions/[id]/workbench-review/route.js +1 -1
  84. package/.next/server/app/api/sessions/new/route.js +1 -1
  85. package/.next/server/app/api/sessions/route.js +1 -1
  86. package/.next/server/app/api/settings/route.js +1 -1
  87. package/.next/server/app/api/skills/install/route.js +2 -2
  88. package/.next/server/app/api/skills/route.js +2 -2
  89. package/.next/server/app/api/skills/search/route.js +1 -1
  90. package/.next/server/app/api/soul/route.js +1 -1
  91. package/.next/server/app/api/subagents/status/route.js +1 -1
  92. package/.next/server/app/api/version/route.js +1 -1
  93. package/.next/server/app/favicon.ico/route.js +1 -1
  94. package/.next/server/app/icon.svg/route.js +1 -1
  95. package/.next/server/app/index.html +1 -1
  96. package/.next/server/app/index.rsc +2 -2
  97. package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  98. package/.next/server/app/index.segments/_full.segment.rsc +2 -2
  99. package/.next/server/app/index.segments/_head.segment.rsc +1 -1
  100. package/.next/server/app/index.segments/_index.segment.rsc +1 -1
  101. package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  102. package/.next/server/app/login/page.js +2 -2
  103. package/.next/server/app/login/page_client-reference-manifest.js +1 -1
  104. package/.next/server/app/login.html +1 -1
  105. package/.next/server/app/login.rsc +1 -1
  106. package/.next/server/app/login.segments/_full.segment.rsc +1 -1
  107. package/.next/server/app/login.segments/_head.segment.rsc +1 -1
  108. package/.next/server/app/login.segments/_index.segment.rsc +1 -1
  109. package/.next/server/app/login.segments/_tree.segment.rsc +1 -1
  110. package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +1 -1
  111. package/.next/server/app/login.segments/login.segment.rsc +1 -1
  112. package/.next/server/app/page.js +25 -46
  113. package/.next/server/app/page_client-reference-manifest.js +1 -1
  114. package/.next/server/app/smoke/page.js +3 -3
  115. package/.next/server/app/smoke/page_client-reference-manifest.js +1 -1
  116. package/.next/server/app/smoke/session-stream/page.js +2 -0
  117. package/.next/server/app/smoke/session-stream/page_client-reference-manifest.js +1 -0
  118. package/.next/server/app/smoke/session-stream.html +1 -0
  119. package/.next/server/app/smoke/session-stream.meta +16 -0
  120. package/.next/server/app/smoke/session-stream.rsc +24 -0
  121. package/.next/server/app/smoke/session-stream.segments/_full.segment.rsc +24 -0
  122. package/.next/server/app/smoke/session-stream.segments/_head.segment.rsc +6 -0
  123. package/.next/server/app/smoke/session-stream.segments/_index.segment.rsc +7 -0
  124. package/.next/server/app/smoke/session-stream.segments/_tree.segment.rsc +5 -0
  125. package/.next/server/app/smoke/session-stream.segments/smoke/session-stream/__PAGE__.segment.rsc +9 -0
  126. package/.next/server/app/smoke/session-stream.segments/smoke/session-stream.segment.rsc +5 -0
  127. package/.next/server/app/smoke/session-stream.segments/smoke.segment.rsc +5 -0
  128. package/.next/server/app/smoke.html +2 -2
  129. package/.next/server/app/smoke.rsc +1 -1
  130. package/.next/server/app/smoke.segments/_full.segment.rsc +1 -1
  131. package/.next/server/app/smoke.segments/_head.segment.rsc +1 -1
  132. package/.next/server/app/smoke.segments/_index.segment.rsc +1 -1
  133. package/.next/server/app/smoke.segments/_tree.segment.rsc +1 -1
  134. package/.next/server/app/smoke.segments/smoke/__PAGE__.segment.rsc +1 -1
  135. package/.next/server/app/smoke.segments/smoke.segment.rsc +1 -1
  136. package/.next/server/app-paths-manifest.json +10 -9
  137. package/.next/server/chunks/6195.js +22 -0
  138. package/.next/server/chunks/6429.js +4 -4
  139. package/.next/server/middleware-build-manifest.js +1 -1
  140. package/.next/server/middleware-react-loadable-manifest.js +1 -1
  141. package/.next/server/middleware.js +3 -3
  142. package/.next/server/pages/404.html +1 -1
  143. package/.next/server/pages/500.html +1 -1
  144. package/.next/server/server-reference-manifest.json +1 -1
  145. package/.next/static/chunks/{2170a4aa.4213bb2183c9cdf9.js → 2170a4aa.d07a50e84fe80b17.js} +1 -1
  146. package/.next/static/chunks/{8436.cab94b59cca0a8ff.js → 8436.9907b3b603222d78.js} +1 -1
  147. package/.next/static/chunks/9165-0ef91ee28d0cb634.js +22 -0
  148. package/.next/static/chunks/app/page-61270b5b6e8b536e.js +46 -0
  149. package/.next/static/chunks/app/smoke/session-stream/page-2ac078e0b43f898b.js +6 -0
  150. package/.next/static/chunks/{webpack-b13282f72690ef5e.js → webpack-961560b05f7e7346.js} +1 -1
  151. package/.next/static/tobhDGatjzn_cJ3Pv_lo5/_buildManifest.js +1 -0
  152. package/package.json +1 -1
  153. package/.next/static/1B01EFTy_VE5f-wDbv0NA/_buildManifest.js +0 -1
  154. package/.next/static/chunks/app/page-9f3943bb144fd4e3.js +0 -67
  155. /package/.next/static/{1B01EFTy_VE5f-wDbv0NA → tobhDGatjzn_cJ3Pv_lo5}/_ssgManifest.js +0 -0
@@ -1,68 +1,47 @@
1
- (()=>{var a={};a.id=8974,a.ids=[8974],a.modules={261:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/app-paths")},478:(a,b,c)=>{Promise.resolve().then(c.bind(c,60613))},1708:a=>{"use strict";a.exports=require("node:process")},2798:(a,b,c)=>{let d=c(76708),e=c(95380),f=c(18994),g=c(32835);function h(a,b,c,f,g){let h=[].slice.call(arguments,1),i=h.length,j="function"==typeof h[i-1];if(!j&&!d())throw Error("Callback required as last argument");if(j){if(i<2)throw Error("Too few arguments provided");2===i?(g=c,c=b,b=f=void 0):3===i&&(b.getContext&&void 0===g?(g=f,f=void 0):(g=f,f=c,c=b,b=void 0))}else{if(i<1)throw Error("Too few arguments provided");return 1===i?(c=b,b=f=void 0):2!==i||b.getContext||(f=c,c=b,b=void 0),new Promise(function(d,g){try{let g=e.create(c,f);d(a(g,b,f))}catch(a){g(a)}})}try{let d=e.create(c,f);g(null,a(d,b,f))}catch(a){g(a)}}e.create,b.toCanvas=h.bind(null,f.render),h.bind(null,f.renderToDataURL),h.bind(null,function(a,b,c){return g.render(a,c)})},3295:a=>{"use strict";a.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},5206:(a,b,c)=>{Promise.resolve().then(c.bind(c,35790))},9709:(a,b,c)=>{"use strict";let d=!0,e=c(74075),f=c(80183);e.deflateSync||(d=!1);let g=c(81769),h=c(42516),i=c(96277),j=c(92858),k=c(83670);a.exports=function(a,b){let c,l,m,n;if(!d)throw Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let o=[],p=new g(a);if(new i(b,{read:p.read.bind(p),error:function(a){c=a},metadata:function(a){l=a},gamma:function(a){m=a},palette:function(a){l.palette=a},transColor:function(a){l.transColor=a},inflateData:function(a){o.push(a)},simpleTransparency:function(){l.alpha=!0}}).start(),p.process(),c)throw c;let q=Buffer.concat(o);if(o.length=0,l.interlace)n=e.inflateSync(q);else{let a=((l.width*l.bpp*l.depth+7>>3)+1)*l.height;n=f(q,{chunkSize:a,maxLength:a})}if(q=null,!n||!n.length)throw Error("bad png - invalid inflate data response");let r=h.process(n,l);q=null;let s=j.dataToBitMap(r,l);r=null;let t=k(s,l);return l.data=t,l.gamma=m||0,l}},10846:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},12097:(a,b)=>{b.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};b.isValid=function(a){return null!=a&&""!==a&&!isNaN(a)&&a>=0&&a<=7},b.from=function(a){return b.isValid(a)?parseInt(a,10):void 0},b.getPenaltyN1=function(a){let b=a.size,c=0,d=0,e=0,f=null,g=null;for(let h=0;h<b;h++){d=e=0,f=g=null;for(let i=0;i<b;i++){let b=a.get(h,i);b===f?d++:(d>=5&&(c+=3+(d-5)),f=b,d=1),(b=a.get(i,h))===g?e++:(e>=5&&(c+=3+(e-5)),g=b,e=1)}d>=5&&(c+=3+(d-5)),e>=5&&(c+=3+(e-5))}return c},b.getPenaltyN2=function(a){let b=a.size,c=0;for(let d=0;d<b-1;d++)for(let e=0;e<b-1;e++){let b=a.get(d,e)+a.get(d,e+1)+a.get(d+1,e)+a.get(d+1,e+1);(4===b||0===b)&&c++}return 3*c},b.getPenaltyN3=function(a){let b=a.size,c=0,d=0,e=0;for(let f=0;f<b;f++){d=e=0;for(let g=0;g<b;g++)d=d<<1&2047|a.get(f,g),g>=10&&(1488===d||93===d)&&c++,e=e<<1&2047|a.get(g,f),g>=10&&(1488===e||93===e)&&c++}return 40*c},b.getPenaltyN4=function(a){let b=0,c=a.data.length;for(let d=0;d<c;d++)b+=a.data[d];return 10*Math.abs(Math.ceil(100*b/c/5)-10)},b.applyMask=function(a,c){let d=c.size;for(let e=0;e<d;e++)for(let f=0;f<d;f++)c.isReserved(f,e)||c.xor(f,e,function(a,c,d){switch(a){case b.Patterns.PATTERN000:return(c+d)%2==0;case b.Patterns.PATTERN001:return c%2==0;case b.Patterns.PATTERN010:return d%3==0;case b.Patterns.PATTERN011:return(c+d)%3==0;case b.Patterns.PATTERN100:return(Math.floor(c/2)+Math.floor(d/3))%2==0;case b.Patterns.PATTERN101:return c*d%2+c*d%3==0;case b.Patterns.PATTERN110:return(c*d%2+c*d%3)%2==0;case b.Patterns.PATTERN111:return(c*d%3+(c+d)%2)%2==0;default:throw Error("bad maskPattern:"+a)}}(a,f,e))},b.getBestMask=function(a,c){let d=Object.keys(b.Patterns).length,e=0,f=1/0;for(let g=0;g<d;g++){c(g),b.applyMask(g,a);let d=b.getPenaltyN1(a)+b.getPenaltyN2(a)+b.getPenaltyN3(a)+b.getPenaltyN4(a);b.applyMask(g,a),d<f&&(f=d,e=g)}return e}},12412:a=>{"use strict";a.exports=require("assert")},17891:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/get-segment-param")},18994:(a,b,c)=>{let d=c(88397);b.render=function(a,b,c){var e;let f=c,g=b;void 0!==f||b&&b.getContext||(f=b,b=void 0),b||(g=function(){try{return document.createElement("canvas")}catch(a){throw Error("You need to specify a canvas element")}}()),f=d.getOptions(f);let h=d.getImageWidth(a.modules.size,f),i=g.getContext("2d"),j=i.createImageData(h,h);return d.qrToImageData(j.data,a,f),e=g,i.clearRect(0,0,e.width,e.height),e.style||(e.style={}),e.height=h,e.width=h,e.style.height=h+"px",e.style.width=h+"px",i.putImageData(j,0,0),g},b.renderToDataURL=function(a,c,d){let e=d;void 0!==e||c&&c.getContext||(e=c,c=void 0),e||(e={});let f=b.render(a,c,e),g=e.type||"image/png",h=e.rendererOpts||{};return f.toDataURL(g,h.quality)}},19099:(a,b,c)=>{"use strict";var d=c(54839);c.o(d,"useRouter")&&c.d(b,{useRouter:function(){return d.useRouter}}),c.o(d,"useSearchParams")&&c.d(b,{useSearchParams:function(){return d.useSearchParams}})},19121:a=>{"use strict";a.exports=require("next/dist/server/app-render/action-async-storage.external.js")},19477:(a,b,c)=>{let d=c(58856),e=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],f=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];b.getBlocksCount=function(a,b){switch(b){case d.L:return e[(a-1)*4+0];case d.M:return e[(a-1)*4+1];case d.Q:return e[(a-1)*4+2];case d.H:return e[(a-1)*4+3];default:return}},b.getTotalCodewordsCount=function(a,b){switch(b){case d.L:return f[(a-1)*4+0];case d.M:return f[(a-1)*4+1];case d.Q:return f[(a-1)*4+2];case d.H:return f[(a-1)*4+3];default:return}}},23372:(a,b,c)=>{"use strict";let d=c(28354),e=c(74075),f=c(57949),g=c(27459),h=c(96277),i=c(92858),j=c(83670),k=a.exports=function(a){f.call(this),this._parser=new h(a,{read:this.read.bind(this),error:this._handleError.bind(this),metadata:this._handleMetaData.bind(this),gamma:this.emit.bind(this,"gamma"),palette:this._handlePalette.bind(this),transColor:this._handleTransColor.bind(this),finished:this._finished.bind(this),inflateData:this._inflateData.bind(this),simpleTransparency:this._simpleTransparency.bind(this),headersFinished:this._headersFinished.bind(this)}),this._options=a,this.writable=!0,this._parser.start()};d.inherits(k,f),k.prototype._handleError=function(a){this.emit("error",a),this.writable=!1,this.destroy(),this._inflate&&this._inflate.destroy&&this._inflate.destroy(),this._filter&&(this._filter.destroy(),this._filter.on("error",function(){})),this.errord=!0},k.prototype._inflateData=function(a){if(!this._inflate)if(this._bitmapInfo.interlace)this._inflate=e.createInflate(),this._inflate.on("error",this.emit.bind(this,"error")),this._filter.on("complete",this._complete.bind(this)),this._inflate.pipe(this._filter);else{let a=((this._bitmapInfo.width*this._bitmapInfo.bpp*this._bitmapInfo.depth+7>>3)+1)*this._bitmapInfo.height,b=Math.max(a,e.Z_MIN_CHUNK);this._inflate=e.createInflate({chunkSize:b});let c=a,d=this.emit.bind(this,"error");this._inflate.on("error",function(a){c&&d(a)}),this._filter.on("complete",this._complete.bind(this));let f=this._filter.write.bind(this._filter);this._inflate.on("data",function(a){c&&(a.length>c&&(a=a.slice(0,c)),c-=a.length,f(a))}),this._inflate.on("end",this._filter.end.bind(this._filter))}this._inflate.write(a)},k.prototype._handleMetaData=function(a){this._metaData=a,this._bitmapInfo=Object.create(a),this._filter=new g(this._bitmapInfo)},k.prototype._handleTransColor=function(a){this._bitmapInfo.transColor=a},k.prototype._handlePalette=function(a){this._bitmapInfo.palette=a},k.prototype._simpleTransparency=function(){this._metaData.alpha=!0},k.prototype._headersFinished=function(){this.emit("metadata",this._metaData)},k.prototype._finished=function(){this.errord||(this._inflate?this._inflate.end():this.emit("error","No Inflate block"))},k.prototype._complete=function(a){let b;if(!this.errord){try{let c=i.dataToBitMap(a,this._bitmapInfo);b=j(c,this._bitmapInfo),c=null}catch(a){this._handleError(a);return}this.emit("parsed",b)}}},26713:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/is-bot")},27137:(a,b,c)=>{let d=c(93669),e=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function f(a){this.mode=d.ALPHANUMERIC,this.data=a}f.getBitsLength=function(a){return 11*Math.floor(a/2)+a%2*6},f.prototype.getLength=function(){return this.data.length},f.prototype.getBitsLength=function(){return f.getBitsLength(this.data.length)},f.prototype.write=function(a){let b;for(b=0;b+2<=this.data.length;b+=2){let c=45*e.indexOf(this.data[b]);c+=e.indexOf(this.data[b+1]),a.put(c,11)}this.data.length%2&&a.put(e.indexOf(this.data[b]),6)},a.exports=f},27459:(a,b,c)=>{"use strict";let d=c(28354),e=c(57949),f=c(27734),g=a.exports=function(a){e.call(this);let b=[],c=this;this._filter=new f(a,{read:this.read.bind(this),write:function(a){b.push(a)},complete:function(){c.emit("complete",Buffer.concat(b))}}),this._filter.start()};d.inherits(g,e)},27734:(a,b,c)=>{"use strict";let d=c(59725),e=c(55211);function f(a,b,c){let d=a*b;return 8!==c&&(d=Math.ceil(d/(8/c))),d}let g=a.exports=function(a,b){let c=a.width,e=a.height,g=a.interlace,h=a.bpp,i=a.depth;if(this.read=b.read,this.write=b.write,this.complete=b.complete,this._imageIndex=0,this._images=[],g){let a=d.getImagePasses(c,e);for(let b=0;b<a.length;b++)this._images.push({byteWidth:f(a[b].width,h,i),height:a[b].height,lineIndex:0})}else this._images.push({byteWidth:f(c,h,i),height:e,lineIndex:0});8===i?this._xComparison=h:16===i?this._xComparison=2*h:this._xComparison=1};g.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this))},g.prototype._unFilterType1=function(a,b,c){let d=this._xComparison,e=d-1;for(let f=0;f<c;f++){let c=a[1+f],g=f>e?b[f-d]:0;b[f]=c+g}},g.prototype._unFilterType2=function(a,b,c){let d=this._lastLine;for(let e=0;e<c;e++){let c=a[1+e],f=d?d[e]:0;b[e]=c+f}},g.prototype._unFilterType3=function(a,b,c){let d=this._xComparison,e=d-1,f=this._lastLine;for(let g=0;g<c;g++){let c=a[1+g],h=f?f[g]:0,i=Math.floor(((g>e?b[g-d]:0)+h)/2);b[g]=c+i}},g.prototype._unFilterType4=function(a,b,c){let d=this._xComparison,f=d-1,g=this._lastLine;for(let h=0;h<c;h++){let c=a[1+h],i=g?g[h]:0,j=e(h>f?b[h-d]:0,i,h>f&&g?g[h-d]:0);b[h]=c+j}},g.prototype._reverseFilterLine=function(a){let b,c=a[0],d=this._images[this._imageIndex],e=d.byteWidth;if(0===c)b=a.slice(1,e+1);else switch(b=Buffer.alloc(e),c){case 1:this._unFilterType1(a,b,e);break;case 2:this._unFilterType2(a,b,e);break;case 3:this._unFilterType3(a,b,e);break;case 4:this._unFilterType4(a,b,e);break;default:throw Error("Unrecognised filter type - "+c)}this.write(b),d.lineIndex++,d.lineIndex>=d.height?(this._lastLine=null,this._imageIndex++,d=this._images[this._imageIndex]):this._lastLine=b,d?this.read(d.byteWidth+1,this._reverseFilterLine.bind(this)):(this._lastLine=null,this.complete())}},27910:a=>{"use strict";a.exports=require("stream")},28354:a=>{"use strict";a.exports=require("util")},28964:(a,b,c)=>{let d=c(93669);function e(a){this.mode=d.NUMERIC,this.data=a.toString()}e.getBitsLength=function(a){return 10*Math.floor(a/3)+(a%3?a%3*3+1:0)},e.prototype.getLength=function(){return this.data.length},e.prototype.getBitsLength=function(){return e.getBitsLength(this.data.length)},e.prototype.write=function(a){let b,c;for(b=0;b+3<=this.data.length;b+=3)c=parseInt(this.data.substr(b,3),10),a.put(c,10);let d=this.data.length-b;d>0&&(c=parseInt(this.data.substr(b),10),a.put(c,3*d+1))},a.exports=e},29021:a=>{"use strict";a.exports=require("fs")},29294:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-async-storage.external.js")},31964:(a,b,c)=>{"use strict";let d=c(55211),e={0:function(a,b,c,d,e){for(let f=0;f<c;f++)d[e+f]=a[b+f]},1:function(a,b,c,d,e,f){for(let g=0;g<c;g++){let c=g>=f?a[b+g-f]:0,h=a[b+g]-c;d[e+g]=h}},2:function(a,b,c,d,e){for(let f=0;f<c;f++){let g=b>0?a[b+f-c]:0,h=a[b+f]-g;d[e+f]=h}},3:function(a,b,c,d,e,f){for(let g=0;g<c;g++){let h=g>=f?a[b+g-f]:0,i=b>0?a[b+g-c]:0,j=a[b+g]-(h+i>>1);d[e+g]=j}},4:function(a,b,c,e,f,g){for(let h=0;h<c;h++){let i=h>=g?a[b+h-g]:0,j=b>0?a[b+h-c]:0,k=b>0&&h>=g?a[b+h-(c+g)]:0,l=a[b+h]-d(i,j,k);e[f+h]=l}}},f={0:function(a,b,c){let d=0,e=b+c;for(let c=b;c<e;c++)d+=Math.abs(a[c]);return d},1:function(a,b,c,d){let e=0;for(let f=0;f<c;f++){let c=f>=d?a[b+f-d]:0;e+=Math.abs(a[b+f]-c)}return e},2:function(a,b,c){let d=0,e=b+c;for(let f=b;f<e;f++){let e=b>0?a[f-c]:0;d+=Math.abs(a[f]-e)}return d},3:function(a,b,c,d){let e=0;for(let f=0;f<c;f++){let g=f>=d?a[b+f-d]:0,h=b>0?a[b+f-c]:0;e+=Math.abs(a[b+f]-(g+h>>1))}return e},4:function(a,b,c,e){let f=0;for(let g=0;g<c;g++){let h=g>=e?a[b+g-e]:0,i=b>0?a[b+g-c]:0,j=b>0&&g>=e?a[b+g-(c+e)]:0;f+=Math.abs(a[b+g]-d(h,i,j))}return f}};a.exports=function(a,b,c,d,g){let h;if("filterType"in d&&-1!==d.filterType)if("number"==typeof d.filterType)h=[d.filterType];else throw Error("unrecognised filter types");else h=[0,1,2,3,4];16===d.bitDepth&&(g*=2);let i=b*g,j=0,k=0,l=Buffer.alloc((i+1)*c),m=h[0];for(let b=0;b<c;b++){if(h.length>1){let b=1/0;for(let c=0;c<h.length;c++){let d=f[h[c]](a,k,i,g);d<b&&(m=h[c],b=d)}}l[j]=m,j++,e[m](a,k,i,l,j,g),j+=i,k+=i}return l}},32835:(a,b,c)=>{let d=c(88397);function e(a,b){let c=a.a/255,d=b+'="'+a.hex+'"';return c<1?d+" "+b+'-opacity="'+c.toFixed(2).slice(1)+'"':d}function f(a,b,c){let d=a+b;return void 0!==c&&(d+=" "+c),d}b.render=function(a,b,c){let g=d.getOptions(b),h=a.modules.size,i=a.modules.data,j=h+2*g.margin,k=g.color.light.a?"<path "+e(g.color.light,"fill")+' d="M0 0h'+j+"v"+j+'H0z"/>':"",l="<path "+e(g.color.dark,"stroke")+' d="'+function(a,b,c){let d="",e=0,g=!1,h=0;for(let i=0;i<a.length;i++){let j=Math.floor(i%b),k=Math.floor(i/b);j||g||(g=!0),a[i]?(h++,i>0&&j>0&&a[i-1]||(d+=g?f("M",j+c,.5+k+c):f("m",e,0),e=0,g=!1),j+1<b&&a[i+1]||(d+=f("h",h),h=0)):e++}return d}(i,h,g.margin)+'"/>',m='<svg xmlns="http://www.w3.org/2000/svg" '+(g.width?'width="'+g.width+'" height="'+g.width+'" ':"")+('viewBox="0 0 '+j+" ")+j+'" shape-rendering="crispEdges">'+k+l+"</svg>\n";return"function"==typeof c&&c(null,m),m}},33873:a=>{"use strict";a.exports=require("path")},34447:(a,b,c)=>{"use strict";let d=c(28354),e=c(27910),f=c(23372),g=c(49149),h=c(58879),i=b.O=function(a){e.call(this),a=a||{},this.width=0|a.width,this.height=0|a.height,this.data=this.width>0&&this.height>0?Buffer.alloc(4*this.width*this.height):null,a.fill&&this.data&&this.data.fill(0),this.gamma=0,this.readable=this.writable=!0,this._parser=new f(a),this._parser.on("error",this.emit.bind(this,"error")),this._parser.on("close",this._handleClose.bind(this)),this._parser.on("metadata",this._metadata.bind(this)),this._parser.on("gamma",this._gamma.bind(this)),this._parser.on("parsed",(function(a){this.data=a,this.emit("parsed",a)}).bind(this)),this._packer=new g(a),this._packer.on("data",this.emit.bind(this,"data")),this._packer.on("end",this.emit.bind(this,"end")),this._parser.on("close",this._handleClose.bind(this)),this._packer.on("error",this.emit.bind(this,"error"))};d.inherits(i,e),i.sync=h,i.prototype.pack=function(){return this.data&&this.data.length?process.nextTick((function(){this._packer.pack(this.data,this.width,this.height,this.gamma)}).bind(this)):this.emit("error","No data provided"),this},i.prototype.parse=function(a,b){if(b){let a,c;a=(function(a){this.removeListener("error",c),this.data=a,b(null,this)}).bind(this),c=(function(c){this.removeListener("parsed",a),b(c,null)}).bind(this),this.once("parsed",a),this.once("error",c)}return this.end(a),this},i.prototype.write=function(a){return this._parser.write(a),!0},i.prototype.end=function(a){this._parser.end(a)},i.prototype._metadata=function(a){this.width=a.width,this.height=a.height,this.emit("metadata",a)},i.prototype._gamma=function(a){this.gamma=a},i.prototype._handleClose=function(){this._parser.writable||this._packer.readable||this.emit("close")},i.bitblt=function(a,b,c,d,e,f,g,h){if(d|=0,e|=0,f|=0,g|=0,h|=0,(c|=0)>a.width||d>a.height||c+e>a.width||d+f>a.height)throw Error("bitblt reading outside image");if(g>b.width||h>b.height||g+e>b.width||h+f>b.height)throw Error("bitblt writing outside image");for(let i=0;i<f;i++)a.data.copy(b.data,(h+i)*b.width+g<<2,(d+i)*a.width+c<<2,(d+i)*a.width+c+e<<2)},i.prototype.bitblt=function(a,b,c,d,e,f,g){return i.bitblt(this,a,b,c,d,e,f,g),this},i.adjustGamma=function(a){if(a.gamma){for(let b=0;b<a.height;b++)for(let c=0;c<a.width;c++){let d=a.width*b+c<<2;for(let b=0;b<3;b++){let c=a.data[d+b]/255;c=Math.pow(c,1/2.2/a.gamma),a.data[d+b]=Math.round(255*c)}}a.gamma=0}},i.prototype.adjustGamma=function(){i.adjustGamma(this)}},35790:(a,b,c)=>{"use strict";c.d(b,{AppShell:()=>d});let d=(0,c(77943).registerClientReference)(function(){throw Error("Attempted to call AppShell() from the server but AppShell is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.")},"/home/runner/work/annovibe/annovibe/components/AppShell.tsx","AppShell")},38937:(a,b,c)=>{let d=c(93669);function e(a){this.mode=d.BYTE,"string"==typeof a?this.data=new TextEncoder().encode(a):this.data=new Uint8Array(a)}e.getBitsLength=function(a){return 8*a},e.prototype.getLength=function(){return this.data.length},e.prototype.getBitsLength=function(){return e.getBitsLength(this.data.length)},e.prototype.write=function(a){for(let b=0,c=this.data.length;b<c;b++)a.put(this.data[b],8)},a.exports=e},39477:(a,b,c)=>{let d=c(58305).getSymbolSize;b.getPositions=function(a){let b=d(a);return[[0,0],[b-7,0],[0,b-7]]}},39588:(a,b,c)=>{let d=c(93669),e=c(28964),f=c(27137),g=c(38937),h=c(64424),i=c(64323),j=c(58305),k=c(84879);function l(a){return unescape(encodeURIComponent(a)).length}function m(a,b,c){let d,e=[];for(;null!==(d=a.exec(c));)e.push({data:d[0],index:d.index,mode:b,length:d[0].length});return e}function n(a){let b,c,e=m(i.NUMERIC,d.NUMERIC,a),f=m(i.ALPHANUMERIC,d.ALPHANUMERIC,a);return j.isKanjiModeEnabled()?(b=m(i.BYTE,d.BYTE,a),c=m(i.KANJI,d.KANJI,a)):(b=m(i.BYTE_KANJI,d.BYTE,a),c=[]),e.concat(f,b,c).sort(function(a,b){return a.index-b.index}).map(function(a){return{data:a.data,mode:a.mode,length:a.length}})}function o(a,b){switch(b){case d.NUMERIC:return e.getBitsLength(a);case d.ALPHANUMERIC:return f.getBitsLength(a);case d.KANJI:return h.getBitsLength(a);case d.BYTE:return g.getBitsLength(a)}}function p(a,b){let c,i=d.getBestModeForData(a);if((c=d.from(b,i))!==d.BYTE&&c.bit<i.bit)throw Error('"'+a+'" cannot be encoded with mode '+d.toString(c)+".\n Suggested mode is: "+d.toString(i));switch(c===d.KANJI&&!j.isKanjiModeEnabled()&&(c=d.BYTE),c){case d.NUMERIC:return new e(a);case d.ALPHANUMERIC:return new f(a);case d.KANJI:return new h(a);case d.BYTE:return new g(a)}}b.fromArray=function(a){return a.reduce(function(a,b){return"string"==typeof b?a.push(p(b,null)):b.data&&a.push(p(b.data,b.mode)),a},[])},b.fromString=function(a,c){let e=function(a,b){let c={},e={start:{}},f=["start"];for(let g=0;g<a.length;g++){let h=a[g],i=[];for(let a=0;a<h.length;a++){let j=h[a],k=""+g+a;i.push(k),c[k]={node:j,lastCount:0},e[k]={};for(let a=0;a<f.length;a++){let g=f[a];c[g]&&c[g].node.mode===j.mode?(e[g][k]=o(c[g].lastCount+j.length,j.mode)-o(c[g].lastCount,j.mode),c[g].lastCount+=j.length):(c[g]&&(c[g].lastCount=j.length),e[g][k]=o(j.length,j.mode)+4+d.getCharCountIndicator(j.mode,b))}}f=i}for(let a=0;a<f.length;a++)e[f[a]].end=0;return{map:e,table:c}}(function(a){let b=[];for(let c=0;c<a.length;c++){let e=a[c];switch(e.mode){case d.NUMERIC:b.push([e,{data:e.data,mode:d.ALPHANUMERIC,length:e.length},{data:e.data,mode:d.BYTE,length:e.length}]);break;case d.ALPHANUMERIC:b.push([e,{data:e.data,mode:d.BYTE,length:e.length}]);break;case d.KANJI:b.push([e,{data:e.data,mode:d.BYTE,length:l(e.data)}]);break;case d.BYTE:b.push([{data:e.data,mode:d.BYTE,length:l(e.data)}])}}return b}(n(a,j.isKanjiModeEnabled())),c),f=k.find_path(e.map,"start","end"),g=[];for(let a=1;a<f.length-1;a++)g.push(e.table[f[a]].node);return b.fromArray(g.reduce(function(a,b){let c=a.length-1>=0?a[a.length-1]:null;return c&&c.mode===b.mode?a[a.length-1].data+=b.data:a.push(b),a},[]))},b.rawSplit=function(a){return b.fromArray(n(a,j.isKanjiModeEnabled()))}},40355:(a,b,c)=>{let d=c(76708),e=c(95380),f=c(46387),g=c(72081),h=c(66530),i=c(90082);function j(a,b,c){if(void 0===a)throw Error("String required as first argument");if(void 0===c&&(c=b,b={}),"function"!=typeof c)if(d())b=c||{},c=null;else throw Error("Callback required as last argument");return{opts:b,cb:c}}function k(a){switch(a){case"svg":return i;case"txt":case"utf8":return g;default:return f}}function l(a,b,c){if(!c.cb)return new Promise(function(d,f){try{let g=e.create(b,c.opts);return a(g,c.opts,function(a,b){return a?f(a):d(b)})}catch(a){f(a)}});try{let d=e.create(b,c.opts);return a(d,c.opts,c.cb)}catch(a){c.cb(a)}}b.create=e.create,b.toCanvas=c(2798).toCanvas,b.toString=function(a,b,c){let d=j(a,b,c);return l(function(a){switch(a){case"svg":return i;case"terminal":return h;default:return g}}(d.opts?d.opts.type:void 0).render,a,d)},b.toDataURL=function(a,b,c){let d=j(a,b,c);return l(k(d.opts.type).renderToDataURL,a,d)},b.toBuffer=function(a,b,c){let d=j(a,b,c);return l(k(d.opts.type).renderToBuffer,a,d)},b.toFile=function(a,b,c,e){if("string"!=typeof a||"string"!=typeof b&&"object"!=typeof b)throw Error("Invalid argument");if(arguments.length<3&&!d())throw Error("Too few arguments provided");let f=j(b,c,e);return l(k(f.opts.type||a.slice((a.lastIndexOf(".")-1>>>0)+2).toLowerCase()).renderToFile.bind(null,a),b,f)},b.toFileStream=function(a,b,c){if(arguments.length<2)throw Error("Too few arguments provided");let d=j(b,c,a.emit.bind(a,"error"));l(k("png").renderToFileStream.bind(null,a),b,d)}},41025:a=>{"use strict";a.exports=require("next/dist/server/app-render/dynamic-access-async-storage.external.js")},42516:(a,b,c)=>{"use strict";let d=c(81769),e=c(27734);b.process=function(a,b){let c=[],f=new d(a);return new e(b,{read:f.read.bind(f),write:function(a){c.push(a)},complete:function(){}}).start(),f.process(),Buffer.concat(c)}},43144:(a,b,c)=>{let d=c(81754);b.mul=function(a,b){let c=new Uint8Array(a.length+b.length-1);for(let e=0;e<a.length;e++)for(let f=0;f<b.length;f++)c[e+f]^=d.mul(a[e],b[f]);return c},b.mod=function(a,b){let c=new Uint8Array(a);for(;c.length-b.length>=0;){let a=c[0];for(let e=0;e<b.length;e++)c[e]^=d.mul(b[e],a);let e=0;for(;e<c.length&&0===c[e];)e++;c=c.slice(e)}return c},b.generateECPolynomial=function(a){let c=new Uint8Array([1]);for(let e=0;e<a;e++)c=b.mul(c,new Uint8Array([1,d.exp(e)]));return c}},43894:a=>{"use strict";let b=[];for(let a=0;a<256;a++){let c=a;for(let a=0;a<8;a++)1&c?c=0xedb88320^c>>>1:c>>>=1;b[a]=c}let c=a.exports=function(){this._crc=-1};c.prototype.write=function(a){for(let c=0;c<a.length;c++)this._crc=b[(this._crc^a[c])&255]^this._crc>>>8;return!0},c.prototype.crc32=function(){return -1^this._crc},c.crc32=function(a){let c=-1;for(let d=0;d<a.length;d++)c=b[(c^a[d])&255]^c>>>8;return -1^c}},43954:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/interception-routes")},46349:a=>{function b(a){if(!a||a<1)throw Error("BitMatrix size must be defined and greater than 0");this.size=a,this.data=new Uint8Array(a*a),this.reservedBit=new Uint8Array(a*a)}b.prototype.set=function(a,b,c,d){let e=a*this.size+b;this.data[e]=c,d&&(this.reservedBit[e]=!0)},b.prototype.get=function(a,b){return this.data[a*this.size+b]},b.prototype.xor=function(a,b,c){this.data[a*this.size+b]^=c},b.prototype.isReserved=function(a,b){return this.reservedBit[a*this.size+b]},a.exports=b},46387:(a,b,c)=>{let d=c(29021),e=c(34447).O,f=c(88397);b.render=function(a,b){let c=f.getOptions(b),d=c.rendererOpts,g=f.getImageWidth(a.modules.size,c);d.width=g,d.height=g;let h=new e(d);return f.qrToImageData(h.data,a,c),h},b.renderToDataURL=function(a,c,d){void 0===d&&(d=c,c=void 0),b.renderToBuffer(a,c,function(a,b){a&&d(a);let c="data:image/png;base64,";c+=b.toString("base64"),d(null,c)})},b.renderToBuffer=function(a,c,d){void 0===d&&(d=c,c=void 0);let e=b.render(a,c),f=[];e.on("error",d),e.on("data",function(a){f.push(a)}),e.on("end",function(){d(null,Buffer.concat(f))}),e.pack()},b.renderToFile=function(a,c,e,f){void 0===f&&(f=e,e=void 0);let g=!1,h=(...a)=>{g||(g=!0,f.apply(null,a))},i=d.createWriteStream(a);i.on("error",h),i.on("close",h),b.renderToFileStream(i,c,e)},b.renderToFileStream=function(a,c,d){b.render(c,d).pack().pipe(a)}},49149:(a,b,c)=>{"use strict";let d=c(28354),e=c(27910),f=c(67269),g=c(98052),h=a.exports=function(a){e.call(this),this._packer=new g(a||{}),this._deflate=this._packer.createDeflate(),this.readable=!0};d.inherits(h,e),h.prototype.pack=function(a,b,c,d){this.emit("data",Buffer.from(f.PNG_SIGNATURE)),this.emit("data",this._packer.packIHDR(b,c)),d&&this.emit("data",this._packer.packGAMA(d));let e=this._packer.filterData(a,b,c);this._deflate.on("error",this.emit.bind(this,"error")),this._deflate.on("data",(function(a){this.emit("data",this._packer.packIDAT(a))}).bind(this)),this._deflate.on("end",(function(){this.emit("data",this._packer.packIEND()),this.emit("end")}).bind(this)),this._deflate.end(e)}},49998:(a,b,c)=>{"use strict";a.exports=c(40355)},52002:a=>{function b(){this.buffer=[],this.length=0}b.prototype={get:function(a){let b=Math.floor(a/8);return(this.buffer[b]>>>7-a%8&1)==1},put:function(a,b){for(let c=0;c<b;c++)this.putBit((a>>>b-c-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(a){let b=Math.floor(this.length/8);this.buffer.length<=b&&this.buffer.push(0),a&&(this.buffer[b]|=128>>>this.length%8),this.length++}},a.exports=b},52324:(a,b,c)=>{let d=c(58305),e=c(19477),f=c(58856),g=c(93669),h=c(83929),i=d.getBCHDigit(7973);function j(a,b){return g.getCharCountIndicator(a,b)+4}b.from=function(a,b){return h.isValid(a)?parseInt(a,10):b},b.getCapacity=function(a,b,c){if(!h.isValid(a))throw Error("Invalid QR Code version");void 0===c&&(c=g.BYTE);let f=(d.getSymbolTotalCodewords(a)-e.getTotalCodewordsCount(a,b))*8;if(c===g.MIXED)return f;let i=f-j(c,a);switch(c){case g.NUMERIC:return Math.floor(i/10*3);case g.ALPHANUMERIC:return Math.floor(i/11*2);case g.KANJI:return Math.floor(i/13);case g.BYTE:default:return Math.floor(i/8)}},b.getBestVersionForData=function(a,c){let d,e=f.from(c,f.M);if(Array.isArray(a)){if(a.length>1){for(let c=1;c<=40;c++)if(function(a,b){let c=0;return a.forEach(function(a){let d=j(a.mode,b);c+=d+a.getBitsLength()}),c}(a,c)<=b.getCapacity(c,e,g.MIXED))return c;return}if(0===a.length)return 1;d=a[0]}else d=a;return function(a,c,d){for(let e=1;e<=40;e++)if(c<=b.getCapacity(e,d,a))return e}(d.mode,d.getLength(),e)},b.getEncodedBits=function(a){if(!h.isValid(a)||a<7)throw Error("Invalid QR Code version");let b=a<<12;for(;d.getBCHDigit(b)-i>=0;)b^=7973<<d.getBCHDigit(b)-i;return a<<12|b}},55211:a=>{"use strict";a.exports=function(a,b,c){let d=a+b-c,e=Math.abs(d-a),f=Math.abs(d-b),g=Math.abs(d-c);return e<=f&&e<=g?a:f<=g?b:c}},55258:(a,b,c)=>{let d=c(58305),e=d.getBCHDigit(1335);b.getEncodedBits=function(a,b){let c=a.bit<<3|b,f=c<<10;for(;d.getBCHDigit(f)-e>=0;)f^=1335<<d.getBCHDigit(f)-e;return(c<<10|f)^21522}},57949:(a,b,c)=>{"use strict";let d=c(28354),e=c(27910),f=a.exports=function(){e.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=!1,this._encoding="utf8",this.writable=!0};d.inherits(f,e),f.prototype.read=function(a,b){this._reads.push({length:Math.abs(a),allowLess:a<0,func:b}),process.nextTick((function(){this._process(),this._paused&&this._reads&&this._reads.length>0&&(this._paused=!1,this.emit("drain"))}).bind(this))},f.prototype.write=function(a,b){let c;return this.writable?(c=Buffer.isBuffer(a)?a:Buffer.from(a,b||this._encoding),this._buffers.push(c),this._buffered+=c.length,this._process(),this._reads&&0===this._reads.length&&(this._paused=!0),this.writable&&!this._paused):(this.emit("error",Error("Stream not writable")),!1)},f.prototype.end=function(a,b){a&&this.write(a,b),this.writable=!1,this._buffers&&(0===this._buffers.length?this._end():(this._buffers.push(null),this._process()))},f.prototype.destroySoon=f.prototype.end,f.prototype._end=function(){this._reads.length>0&&this.emit("error",Error("Unexpected end of input")),this.destroy()},f.prototype.destroy=function(){this._buffers&&(this.writable=!1,this._reads=null,this._buffers=null,this.emit("close"))},f.prototype._processReadAllowingLess=function(a){this._reads.shift();let b=this._buffers[0];b.length>a.length?(this._buffered-=a.length,this._buffers[0]=b.slice(a.length),a.func.call(this,b.slice(0,a.length))):(this._buffered-=b.length,this._buffers.shift(),a.func.call(this,b))},f.prototype._processRead=function(a){this._reads.shift();let b=0,c=0,d=Buffer.alloc(a.length);for(;b<a.length;){let e=this._buffers[c++],f=Math.min(e.length,a.length-b);e.copy(d,b,0,f),b+=f,f!==e.length&&(this._buffers[--c]=e.slice(f))}c>0&&this._buffers.splice(0,c),this._buffered-=a.length,a.func.call(this,d)},f.prototype._process=function(){try{for(;this._buffered>0&&this._reads&&this._reads.length>0;){let a=this._reads[0];if(a.allowLess)this._processReadAllowingLess(a);else if(this._buffered>=a.length)this._processRead(a);else break}this._buffers&&!this.writable&&this._end()}catch(a){this.emit("error",a)}}},58305:(a,b)=>{let c,d=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];b.getSymbolSize=function(a){if(!a)throw Error('"version" cannot be null or undefined');if(a<1||a>40)throw Error('"version" should be in range from 1 to 40');return 4*a+17},b.getSymbolTotalCodewords=function(a){return d[a]},b.getBCHDigit=function(a){let b=0;for(;0!==a;)b++,a>>>=1;return b},b.setToSJISFunction=function(a){if("function"!=typeof a)throw Error('"toSJISFunc" is not a valid function.');c=a},b.isKanjiModeEnabled=function(){return void 0!==c},b.toSJIS=function(a){return c(a)}},58856:(a,b)=>{b.L={bit:1},b.M={bit:0},b.Q={bit:3},b.H={bit:2},b.isValid=function(a){return a&&void 0!==a.bit&&a.bit>=0&&a.bit<4},b.from=function(a,c){if(b.isValid(a))return a;try{if("string"!=typeof a)throw Error("Param is not a string");switch(a.toLowerCase()){case"l":case"low":return b.L;case"m":case"medium":return b.M;case"q":case"quartile":return b.Q;case"h":case"high":return b.H;default:throw Error("Unknown EC Level: "+a)}}catch(a){return c}}},58879:(a,b,c)=>{"use strict";let d=c(9709),e=c(80706);b.read=function(a,b){return d(a,b||{})},b.write=function(a,b){return e(a,b)}},59725:(a,b)=>{"use strict";let c=[{x:[0],y:[0]},{x:[4],y:[0]},{x:[0,4],y:[4]},{x:[2,6],y:[0,4]},{x:[0,2,4,6],y:[2,6]},{x:[1,3,5,7],y:[0,2,4,6]},{x:[0,1,2,3,4,5,6,7],y:[1,3,5,7]}];b.getImagePasses=function(a,b){let d=[],e=a%8,f=b%8,g=(a-e)/8,h=(b-f)/8;for(let a=0;a<c.length;a++){let b=c[a],i=g*b.x.length,j=h*b.y.length;for(let a=0;a<b.x.length;a++)if(b.x[a]<e)i++;else break;for(let a=0;a<b.y.length;a++)if(b.y[a]<f)j++;else break;i>0&&j>0&&d.push({width:i,height:j,index:a})}return d},b.getInterlaceIterator=function(a){return function(b,d,e){let f=b%c[e].x.length,g=(b-f)/c[e].x.length*8+c[e].x[f],h=d%c[e].y.length;return 4*g+((d-h)/c[e].y.length*8+c[e].y[h])*a*4}}},60613:(a,b,c)=>{"use strict";c.d(b,{AppShell:()=>d1});var d=c(48249),e=c(67484),f=c.n(e),g=c(19099);function h(a,b){let c=b&&a.startsWith(b)?"~"+a.slice(b.length):a,d=c.includes("/")?"/":"\\",e=c.split(d).filter(Boolean);return e.length<=2?c:"..."+d+e.slice(-2).join(d)}function i(a){let b=new Date(a);return Number.isNaN(b.getTime())?"":b.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function j({open:a,cwd:b,homeDir:c,onClose:f,onSelectSession:g}){let[k,l]=(0,e.useState)(""),[m,n]=(0,e.useState)("current"),[o,p]=(0,e.useState)([]),[q,r]=(0,e.useState)(!1),[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)(!1),w=(0,e.useRef)(null);if(!a)return null;let x=k.trim(),y=o.reduce((a,b)=>a+b.matches.length,0);return(0,d.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:a=>{a.target===a.currentTarget&&f()},children:(0,d.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,d.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,d.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,d.jsx)("input",{ref:w,value:k,onChange:a=>l(a.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,d.jsx)("button",{type:"button",onClick:f,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.background="none",a.currentTarget.style.color="var(--text-dim)"},children:(0,d.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,d.jsx)("path",{d:"M4 4 12 12"}),(0,d.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,d.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!b},{value:"all",label:"All history",disabled:!1}].map(a=>(0,d.jsx)("button",{type:"button",disabled:a.disabled,onClick:()=>n(a.value),style:{height:24,padding:"0 9px",background:m===a.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:a.disabled?"var(--text-dim)":m===a.value?"var(--text)":"var(--text-muted)",cursor:a.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:a.label},a.value))}),(0,d.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===m&&b?h(b,c):"Searching every saved session"})]})]}),(0,d.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[x.length<2&&(0,d.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),x.length>=2&&q&&0===o.length&&(0,d.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),s&&(0,d.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:s}),x.length>=2&&!q&&!s&&0===o.length&&(0,d.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),o.map(a=>(0,d.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,d.jsxs)("button",{type:"button",onClick:()=>{g(a.session),f()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,d.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:a.session.name||a.session.firstMessage||"(no messages)"}),(0,d.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:i(a.session.modified)})]}),(0,d.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h(a.session.cwd,c)})]}),a.matchCount>a.matches.length&&(0,d.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[a.matchCount," matches"]})]}),a.matches.map(b=>(0,d.jsxs)("button",{type:"button",onClick:()=>{g(a.session),f()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="none"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,d.jsx)("span",{style:{minWidth:54,color:"user"===b.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:b.role}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:i(b.timestamp)})]}),(0,d.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(a,b){let c=b.trim();if(!c)return a;let e=a.toLowerCase().indexOf(c.toLowerCase());return e<0?a:(0,d.jsxs)(d.Fragment,{children:[a.slice(0,e),(0,d.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:a.slice(e,e+c.length)}),a.slice(e+c.length)]})}(b.snippet,x)})]},b.entryId))]},a.session.id))]}),(0,d.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,d.jsx)("span",{children:y>0?`${y}${u?"+":""} results`:"Esc to close"}),q&&o.length>0&&(0,d.jsx)("span",{children:"Updating..."})]})]})})}function k({open:a,initialPath:b,onClose:c,onSelect:f}){let[g,h]=(0,e.useState)(""),[i,j]=(0,e.useState)(null),[l,m]=(0,e.useState)([]),[n,o]=(0,e.useState)([]),[p,q]=(0,e.useState)(""),[r,s]=(0,e.useState)(!1),[t,u]=(0,e.useState)(null),v=(0,e.useCallback)(async a=>{s(!0),u(null);try{let b=a?`/api/projects/browse?dir=${encodeURIComponent(a)}`:"/api/projects/browse",c=await fetch(b),d=await c.json();if(!c.ok||d.error)throw Error(d.error??`HTTP ${c.status}`);h(d.current??""),j(d.parent??null),m(d.directories??[]),o(d.drives??[]),q(d.current??"")}catch(a){u(a instanceof Error?a.message:String(a))}finally{s(!1)}},[]);return a?(0,d.jsx)("div",{onMouseDown:a=>{a.target===a.currentTarget&&c()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:(0,d.jsxs)("div",{style:{width:"min(560px, 100%)",maxHeight:"min(720px, 88dvh)",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{height:48,padding:"0 14px",display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border)"},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Select project path"}),(0,d.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11},children:"Server filesystem"})]}),(0,d.jsx)("button",{type:"button",onClick:c,"aria-label":"Close",title:"Close",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.background="transparent",a.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,d.jsx)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:(0,d.jsxs)("form",{onSubmit:a=>{a.preventDefault();let b=p.trim();b&&f(b)},style:{display:"flex",gap:8},children:[(0,d.jsx)("input",{value:p,onChange:a=>q(a.target.value),placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,d.jsx)("button",{type:"button",onClick:()=>{let a=p.trim();a&&v(a)},disabled:!p.trim()||r,style:{height:32,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:p.trim()&&!r?"var(--text-muted)":"var(--text-dim)",cursor:p.trim()&&!r?"pointer":"default",fontSize:12},children:"Browse"}),(0,d.jsx)("button",{type:"submit",disabled:!p.trim(),style:{height:32,padding:"0 11px",border:"none",borderRadius:6,background:p.trim()?"var(--accent)":"var(--bg-hover)",color:p.trim()?"#fff":"var(--text-dim)",cursor:p.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Use Path"})]})}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,d.jsx)("button",{type:"button",onClick:()=>i&&void v(i),disabled:!i,style:{width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:i?"var(--bg)":"transparent",color:i?"var(--text-muted)":"var(--text-dim)",cursor:i?"pointer":"default",padding:0},title:"Up",children:(0,d.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("polyline",{points:"2 6.5 5 3.5 8 6.5"})})}),n.length>0&&(0,d.jsxs)("select",{value:n.find(a=>g.toLowerCase().startsWith(a.toLowerCase()))??"",onChange:a=>{a.target.value&&v(a.target.value)},style:{height:28,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",fontSize:12},children:[(0,d.jsx)("option",{value:"",children:"Drive"}),n.map(a=>(0,d.jsx)("option",{value:a,children:a},a))]}),(0,d.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:g,children:g})]}),(0,d.jsx)("div",{style:{flex:1,minHeight:220,maxHeight:360,overflowY:"auto",padding:6},children:r?(0,d.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):t?(0,d.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12},children:t}):0===l.length?(0,d.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):l.map(a=>(0,d.jsxs)("button",{type:"button",onClick:()=>void v(a.path),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 9px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.background="transparent",a.currentTarget.style.color="var(--text-muted)"},title:a.path,children:[(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--accent)",flexShrink:0},children:(0,d.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,d.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name}),(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:(0,d.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},a.path))}),(0,d.jsxs)("div",{style:{padding:12,borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,d.jsx)("div",{style:{minWidth:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:g,children:g}),(0,d.jsxs)("div",{style:{display:"flex",gap:7,flexShrink:0},children:[(0,d.jsx)("button",{type:"button",onClick:c,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,d.jsx)("button",{type:"button",onClick:()=>g&&f(g),disabled:!g,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:g?"var(--accent)":"var(--bg-hover)",color:g?"#fff":"var(--text-dim)",cursor:g?"pointer":"default",fontSize:12,fontWeight:650},children:"Select"})]})]})]})}):null}let l="AnnoVibe";function m(a){}async function n(a,b){let c=`${a}: HTTP ${b.status}`;try{let d=await b.json();return"string"==typeof d.error&&d.error?`${a}: ${d.error}`:c}catch{return c}}function o(a){return new DOMException(a,"TimeoutError")}function p(a,b){return a instanceof DOMException&&("AbortError"===a.name||"TimeoutError"===a.name)||a instanceof Error&&/aborted without reason|AbortError/i.test(a.message)?b:a instanceof Error?a.message:String(a)}function q(a){let b=new Date(a),c=new Date().getTime()-b.getTime(),d=Math.floor(c/6e4),e=Math.floor(c/36e5),f=Math.floor(c/864e5);return d<1?"just now":d<60?`${d}m ago`:e<24?`${e}h ago`:f<7?`${f}d ago`:b.toLocaleDateString()}function r(a,b){let c=b&&a.startsWith(b)?"~"+a.slice(b.length):a,d=c.includes("/")?"/":"\\",e=c.split(d).filter(Boolean);return e.length<=2?c:"…/"+e.slice(-2).join(d)}function s(a,b){if(!a)return"No Project";let c=a.replace(/[\\/]+$/,""),d=c.includes("/")?"/":"\\";return c.split(d).filter(Boolean).pop()||r(a,b)}function t(){let[a,b]=(0,e.useState)(!1),[c,f]=(0,e.useState)(!1),g=(0,e.useRef)(null),h=function(a){let[b,c]=(0,e.useState)(a);return(0,e.useRef)(null),(0,e.useRef)(0),b}(a?"v0.8.118":l),i=(0,e.useCallback)(a=>{b(a),f(!0),setTimeout(()=>f(!1),(a?6:8)*4*(1e3/60)+100)},[]),j=(0,e.useCallback)(()=>{g.current&&clearTimeout(g.current);let b=!a;i(b),b&&(g.current=setTimeout(()=>i(!1),3e3))},[a,i]);return(0,d.jsx)("button",{onClick:j,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:a?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"9ch"},children:h})}function u({selectedSessionId:a,onSelectSession:b,onNewSession:c,onNewWorkbench:f,initialSessionId:g,onInitialRestoreDone:h,refreshKey:i,onSessionDeleted:l,selectedCwd:q,onCwdChange:A}){let[B,C]=(0,e.useState)([]),[D,E]=(0,e.useState)({}),[F,G]=(0,e.useState)(()=>new Set),H=(0,e.useRef)(!1),[I,J]=(0,e.useState)(!0),[K,L]=(0,e.useState)(!1),[M,N]=(0,e.useState)(null),[O,P]=(0,e.useState)(null),[Q,R]=(0,e.useState)(""),[S,T]=(0,e.useState)(null),[U,V]=(0,e.useState)(!1),[W,X]=(0,e.useState)("project"),[Y,Z]=(0,e.useState)(null),[$,_]=(0,e.useState)(!1),[aa,ab]=(0,e.useState)(!1),[ac,ad]=(0,e.useState)(()=>new Set),[ae,af]=(0,e.useState)(()=>new Set),[ag,ah]=(0,e.useState)(null),[ai,aj]=(0,e.useState)(null),[ak,al]=(0,e.useState)(null),[am,an]=(0,e.useState)(!1),ao=(0,e.useRef)(null),ap=(0,e.useRef)(!1),aq=(0,e.useRef)(!1);(0,e.useRef)(!1);let ar=(0,e.useRef)(new Map),as=(0,e.useCallback)(async(a=!1)=>{try{let b;a&&J(!0);let c=new AbortController;try{b=setTimeout(()=>c.abort(o("Project loading timed out")),6e4);let a=await fetch("/api/projects?sessions=false",{signal:c.signal});if(!a.ok)throw Error(await n("projects",a));let d=await a.json();C(d.projects),N(null)}finally{clearTimeout(b)}}catch(a){N(p(a,"Loading projects timed out. Codex may still be starting; click Refresh to retry."))}finally{a&&J(!1)}},[]),at=(0,e.useCallback)(async(a,b=!1)=>{if(!a)return;let c=ar.current.get(a);if(c)return c;let d=(async()=>{E(b=>({...b,[a]:{sessions:b[a]?.sessions??[],loaded:b[a]?.loaded??!1,error:null,loading:!0,stale:b[a]?.stale??!1}}));try{let c;b&&J(!0);let d=new AbortController;try{c=setTimeout(()=>d.abort(o("Chat loading timed out")),6e4);let b=await fetch(`/api/sessions?cwd=${encodeURIComponent(a)}`,{signal:d.signal});if(!b.ok)throw Error(await n("sessions",b));let e=await b.json();e.runningSessionIds&&!H.current&&G(new Set(e.runningSessionIds)),E(b=>({...b,[a]:{sessions:e.sessions,loaded:!0,loading:!1,error:null,stale:!1}}))}finally{clearTimeout(c)}}catch(c){let b=p(c,"Loading chats timed out. Codex may still be starting; click Refresh to retry.");E(c=>({...c,[a]:{sessions:c[a]?.sessions??[],loaded:c[a]?.loaded??!1,loading:!1,error:b,stale:(c[a]?.sessions?.length??0)>0}}))}finally{b&&J(!1),ar.current.delete(a)}})();return ar.current.set(a,d),d},[]);(0,e.useRef)(!1),(0,e.useRef)(!1);let au=(0,e.useCallback)(async(a,b=!1)=>{try{let c=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,create:b})}),d=await c.json();if(!c.ok||d.error)return T(d.error??`HTTP ${c.status}`),!1;return as(!1),!0}catch(a){return T(a instanceof Error?a.message:String(a)),!1}},[as]),av=(0,e.useCallback)(a=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,touch:!0})}).catch(()=>{})},[]),aw=(0,e.useCallback)(a=>{aq.current=!0,P(a),T(null),af(b=>{if(!b.has(a))return b;let c=new Set(b);return c.delete(a),m(c),c}),A?.(a),av(a),at(a,!1)},[at,A,av]),ax=q??O,ay=(0,e.useCallback)(a=>{if(!a){X("agent"),V(!0);return}let b="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;c?.(b,a)},[c]),az=(0,e.useCallback)(a=>{if(!a){X("workbench"),V(!0);return}f?.(a)},[f]),aA=(0,e.useCallback)(async a=>{await au(a,!0)&&(aw(a),V(!1),T(null),"agent"===W&&ay(a),"workbench"===W&&az(a))},[aw,ay,az,W,au]),aB=(0,e.useCallback)(a=>{Z(a),_(!0)},[]),aC=(0,e.useCallback)(()=>{_(!1),Z(null)},[]),aD=(0,e.useCallback)(a=>{let b=Y??ax;aC(),"agent"===a?ay(b):az(b)},[aC,ay,az,ax,Y]),aE=(0,e.useCallback)(()=>{aB(ax)},[ax,aB]),aF=(0,e.useCallback)(()=>{X("project"),T(null),V(!0)},[]),aG=(0,e.useMemo)(()=>[...ax&&!B.some(a=>a.cwd===ax)?[{cwd:ax,displayName:s(ax,Q),chatCount:D[ax]?.sessions.length??0,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...B].sort((a,b)=>{let c=!0===a.pinned;if(c!==(!0===b.pinned))return c?-1:1;let d="number"==typeof a.sortOrder?a.sortOrder:Number.MAX_SAFE_INTEGER,e="number"==typeof b.sortOrder?b.sortOrder:Number.MAX_SAFE_INTEGER;return d!==e?d-e:(a.displayName||"").localeCompare(b.displayName||"",void 0,{numeric:!0,sensitivity:"base"})}),[ax,Q,B,D]),aH=(0,e.useMemo)(()=>{let a=a=>{let b=D[a.cwd],c=[...b?.sessions??[]].sort((a,b)=>(b.modified||"").localeCompare(a.modified||""));return{project:a,cwd:a.cwd,displayName:a.displayName||s(a.cwd,Q),sessions:c,sessionsState:b,lastAccessed:(a.lastAccessed??a.created??"")||c[0]?.modified||""}},b=aG.filter(a=>!0===a.pinned).map(a);if(ax){let c=aG.find(a=>a.cwd===ax);c&&!0!==c.pinned&&b.push(a(c))}return b},[ax,Q,D,aG]),aI=(0,e.useCallback)((a,c=!1)=>{a.cwd!==ax&&(ap.current=!0,P(a.cwd)),af(b=>{if(!b.has(a.cwd))return b;let c=new Set(b);return c.delete(a.cwd),m(c),c}),av(a.cwd),b(a,c)},[b,ax,av]),aJ=(0,e.useCallback)(a=>{af(b=>{let c=new Set(b);return c.has(a)?c.delete(a):c.add(a),m(c),c})},[]),aK=(0,e.useCallback)(a=>{ad(b=>{let c=new Set(b);return c.has(a)?c.delete(a):c.add(a),c})},[]),aL=(0,e.useCallback)(async a=>{al("reorder");try{let b=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:a})}),c=await b.json();if(!b.ok||c.error)throw Error(c.error??`HTTP ${b.status}`);C(c.projects??[]),N(null)}catch(a){N(a instanceof Error?a.message:String(a)),as(!1)}finally{al(null)}},[as]),aM=(0,e.useCallback)(async(a,b)=>{al(`pin:${a}`);try{let c=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,pinned:b})}),d=await c.json();if(!c.ok||d.error)throw Error(d.error??`HTTP ${c.status}`);C(d.projects??[]),N(null)}catch(a){N(a instanceof Error?a.message:String(a)),as(!1)}finally{al(null)}},[as]),aN=(0,e.useCallback)((a,b)=>{if(!a||!b||a===b)return;let c=aG.map(a=>a.cwd).filter(Boolean),d=c.indexOf(a),e=c.indexOf(b);if(-1===d||-1===e)return;let f=[...c];f.splice(d,1);let g=f.indexOf(b);f.splice(g,0,a),aL(f)},[aL,aG]),aO=(0,e.useCallback)(async()=>{L(!0);try{await as(!1);let a=new Set([...Object.entries(D).filter(([,a])=>a.loaded||a.loading).map(([a])=>a),...ax?[ax]:[]]);await Promise.all([...a].map(a=>at(a,!1)))}finally{L(!1)}},[ax,as,at,D]);return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,d.jsx)("div",{style:{padding:"12px 10px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,d.jsx)(t,{}),(0,d.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,d.jsxs)("button",{onClick:aE,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",height:32,paddingLeft:10,paddingRight:12,borderRadius:7,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:ax?`New chat in ${ax}`:"New chat in a project path",onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-selected)",a.currentTarget.style.color="var(--accent)",a.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text-muted)",a.currentTarget.style.borderColor="var(--border)"},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[(0,d.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,d.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"New Chat"]}),(0,d.jsx)("button",{onClick:()=>ab(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",width:32,height:32,borderRadius:7,padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:"Search conversations",onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-selected)",a.currentTarget.style.color="var(--accent)",a.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text-muted)",a.currentTarget.style.borderColor="var(--border)"},children:(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"7",cy:"7",r:"4.4"}),(0,d.jsx)("path",{d:"M10.4 10.4 13.2 13.2"})]})})]})]})}),(0,d.jsx)(j,{open:aa,cwd:ax,homeDir:Q,onClose:()=>ab(!1),onSelectSession:a=>{aI(a)}}),(0,d.jsxs)("div",{ref:ao,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,d.jsxs)("button",{type:"button",onClick:()=>an(a=>!a),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:ax?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:ax?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:ax??"Select project",children:[(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--accent)"},children:(0,d.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,d.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:ax?"var(--text)":"var(--text-dim)"},children:ax?aG.find(a=>a.cwd===ax)?.displayName??r(ax,Q):"Select project…"}),(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:am?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,d.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),ax&&(0,d.jsx)(w,{pinned:aG.find(a=>a.cwd===ax)?.pinned===!0,onToggle:()=>void aM(ax,aG.find(a=>a.cwd===ax)?.pinned!==!0)}),am&&(0,d.jsxs)("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:10,right:10,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden",maxHeight:280,overflowY:"auto"},children:[0===aG.length&&(0,d.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),aG.map(a=>{let b=a.cwd===ax;return(0,d.jsx)(x,{project:a,homeDir:Q,isCurrent:b,onSelect:()=>{aw(a.cwd),an(!1)},onTogglePinned:()=>void aM(a.cwd,!0!==a.pinned)},a.cwd)}),(0,d.jsxs)("button",{type:"button",onClick:()=>{an(!1),aF()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:aG.length>0?"1px solid var(--border)":"none",color:"var(--accent)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,d.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"Add project…"]})]})]}),(0,d.jsxs)("div",{style:{flexShrink:0,padding:"10px 10px 6px"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase"},children:"Projects"}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:"auto"},children:[(0,d.jsx)("button",{type:"button",onClick:aO,disabled:K,title:"Refresh projects and chats","aria-label":"Refresh projects and chats",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:K?"var(--accent)":"var(--text-dim)",cursor:K?"default":"pointer",flexShrink:0},children:(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:K?"spin 0.9s linear infinite":void 0},children:[(0,d.jsx)("path",{d:"M21 12a9 9 0 0 1-15.5 6.2"}),(0,d.jsx)("path",{d:"M3 12A9 9 0 0 1 18.5 5.8"}),(0,d.jsx)("path",{d:"M7 18H5.5v1.5"}),(0,d.jsx)("path",{d:"M17 6h1.5V4.5"})]})}),(0,d.jsxs)("button",{type:"button",onClick:aF,title:"New project","aria-label":"New project",style:{height:26,display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:"0 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,transition:"background 0.12s, color 0.12s, border-color 0.12s",flexShrink:0},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-selected)",a.currentTarget.style.color="var(--accent)",a.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text-muted)",a.currentTarget.style.borderColor="var(--border)"},children:[(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v4.5A1.5 1.5 0 0 1 13 12H3a1.5 1.5 0 0 1-1.5-1.5v-6Z"}),(0,d.jsx)("path",{d:"M11 7v3M9.5 8.5h3"})]}),"New Project"]})]})]}),S&&(0,d.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:S})]}),(0,d.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[I&&0===B.length&&(0,d.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading…"}),M&&(0,d.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:M}),!I&&!M&&0===aH.length&&(0,d.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!I&&!M&&aH.map(b=>{let c,e=ae.has(b.cwd),f=b.cwd===ax,g=ac.has(b.cwd),h=function(a){let b=new Map;for(let c of a)b.set(c.id,{session:c,children:[]});let c=new Map;for(let b of a)b.parentSessionId&&c.set(b.id,b.parentSessionId);let d=[];for(let a of b.values()){let e=function(a){let d=c.get(a),e=new Set;for(;d&&!e.has(d);){if(e.add(d),b.has(d))return d;d=c.get(d)}return null}(a.session.id);e?b.get(e).children.push(a):d.push(a)}let e=a=>{a.sort((a,b)=>(b.session.modified||"").localeCompare(a.session.modified||"")),a.forEach(a=>e(a.children))};return e(d),d}(b.sessions),i=h.length,j=h;if(i>10&&!g){j=h.slice(0,10);let b=h.find(b=>(function a(b,c){return!!c&&(b.session.id===c||b.children.some(b=>a(b,c)))})(b,a));b&&!j.includes(b)&&(j=[...j,b])}let k=i-j.length;return(0,d.jsxs)("div",{style:{marginBottom:6,borderTop:ai===b.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(ai===b.cwd),opacity:ag===b.cwd?.55:1},onDragOver:a=>{ag&&ag!==b.cwd&&(a.preventDefault(),a.dataTransfer.dropEffect="move",aj(b.cwd))},onDragLeave:()=>{ai===b.cwd&&aj(null)},onDrop:a=>{a.preventDefault();let c=a.dataTransfer.getData("text/project-cwd")||ag;aj(null),ah(null),c&&aN(c,b.cwd)},children:[(0,d.jsx)(y,{group:b,isCurrent:f,isCollapsed:e,isDragging:ag===b.cwd,pinBusy:ak===`pin:${b.cwd}`,onToggle:()=>aJ(b.cwd),onSelect:()=>aw(b.cwd),onTogglePinned:()=>void aM(b.cwd,!0!==b.project.pinned),onDragStart:a=>{ah(b.cwd),a.dataTransfer.effectAllowed="move",a.dataTransfer.setData("text/project-cwd",b.cwd)},onDragEnd:()=>{ah(null),aj(null)}}),!e&&(0,d.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[(c=b.sessionsState,c?.loading&&!c?.loaded?(0,d.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:12,fontStyle:"italic"},children:"Loading chats…"}):c?.error&&!c?.stale?(0,d.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"#f87171",textAlign:"left",fontSize:12},children:c.error}):0===b.sessions.length?(0,d.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-muted)",textAlign:"left",fontSize:12},children:"No sessions yet. Use New Chat above to start one."}):(0,d.jsxs)(d.Fragment,{children:[c?.stale&&(0,d.jsx)("div",{style:{width:"100%",padding:"4px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:10,fontStyle:"italic"},children:"Showing cached data — refresh failed"}),j.map(c=>(0,d.jsx)(z,{node:c,selectedSessionId:a,onSelectSession:aI,onRenamed:()=>void at(b.cwd,!1),onSessionDeleted:a=>{l?.(a),at(b.cwd,!1)},depth:0,runningSessionIds:F},c.session.id))]})),(g||k>0)&&i>10&&(0,d.jsx)("button",{type:"button",onClick:()=>aK(b.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:g?"Show less":`Show ${Math.max(0,k)} more`})]})]},b.cwd||"__no_project")})]}),$&&(0,d.jsx)(v,{cwd:Y,onChoose:aD,onClose:aC}),(0,d.jsx)(k,{open:U,initialPath:ax,onClose:()=>V(!1),onSelect:a=>aA(a)})]})}function v({cwd:a,onChoose:b,onClose:c}){let e=a?s(a):"Choose a project path next";return(0,d.jsx)("div",{onMouseDown:a=>{a.target===a.currentTarget&&c()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.28)"},children:(0,d.jsxs)("div",{style:{width:"min(420px, 100%)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 40px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:"14px 16px 12px",borderBottom:"1px solid var(--border)",display:"flex",justifyContent:"space-between",gap:12},children:[(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Start a new session"}),(0,d.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11},children:"Current project"}),(0,d.jsx)("div",{title:a??void 0,style:{marginTop:2,color:"var(--text)",fontSize:12,fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e}),a&&(0,d.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a})]}),(0,d.jsx)("button",{type:"button",onClick:c,"aria-label":"Close",title:"Close",style:{width:28,height:28,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},children:"x"})]}),(0,d.jsxs)("div",{style:{padding:14,display:"grid",gap:10},children:[(0,d.jsxs)("button",{type:"button",onClick:()=>b("agent"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer"},children:[(0,d.jsx)("span",{style:{fontSize:13,fontWeight:750},children:"Agent Chat"}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"General coding or analysis chat in this project."})]}),(0,d.jsxs)("button",{type:"button",onClick:()=>b("workbench"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid rgba(37,99,235,0.45)",borderRadius:10,background:"rgba(37,99,235,0.08)",color:"var(--text)",cursor:"pointer"},children:[(0,d.jsx)("span",{style:{fontSize:13,fontWeight:750,color:"var(--accent)"},children:"Workbench"}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"Dedicated R/Python warm-runtime session for data loading, plots, and artifacts."})]})]})]})})}function w({pinned:a,onToggle:b}){return(0,d.jsx)("button",{type:"button",onClick:b,title:a?"Unpin project":"Pin project to sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:"auto",padding:0,border:"1px solid var(--border)",borderRadius:7,background:a?"rgba(234,179,8,0.12)":"var(--bg-hover)",color:a?"#ca8a04":"var(--text-muted)",cursor:"pointer",flexShrink:0},children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:a?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 17v5"}),(0,d.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})}function x({project:a,homeDir:b,isCurrent:c,onSelect:f,onTogglePinned:g}){let[h,i]=(0,e.useState)(!1),j=a.displayName||s(a.cwd,b);return(0,d.jsxs)("div",{onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),style:{display:"flex",alignItems:"center",gap:4,background:c?"var(--bg-selected)":h?"var(--bg-hover)":"none",borderBottom:"1px solid var(--border)"},children:[(0,d.jsx)("span",{style:{width:10,marginLeft:6,flexShrink:0}}),(0,d.jsxs)("button",{type:"button",onClick:f,title:a.cwd,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px 8px 0",background:"none",border:"none",color:c?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[c?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,d.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),(0,d.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:j}),!a.exists&&(0,d.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,d.jsx)("button",{type:"button",onClick:a=>{a.stopPropagation(),g()},title:"Pin to sidebar",tabIndex:h?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,marginRight:4,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:+!!h,pointerEvents:h?"auto":"none"},children:(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 17v5"}),(0,d.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})]})}function y({group:a,isCurrent:b,isCollapsed:c,isDragging:f,pinBusy:g,onToggle:h,onSelect:i,onTogglePinned:j,onDragStart:k,onDragEnd:l}){let[m,n]=(0,e.useState)(!1),o=a.lastAccessed,p=Math.max(0,a.project.chatCount??a.sessions.length??0),r=!0===a.project.pinned,s=(0,e.useCallback)(()=>{b?h():i()},[b,i,h]);return(0,d.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:s,onDragStart:k,onDragEnd:l,onKeyDown:a=>{("Enter"===a.key||" "===a.key)&&(a.preventDefault(),s())},onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),title:a.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:b?"var(--bg-selected)":m?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:f?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, opacity 0.12s",opacity:f?.55:1},children:[(0,d.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:c?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,d.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,d.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:b?"var(--accent)":"var(--text-dim)"},children:c?(0,d.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,d.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,d.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:b?650:560,color:"var(--text)"},children:a.displayName}),!a.project.exists&&(0,d.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!m&&p>0&&(0,d.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[p," ",1===p?"chat":"chats"]}),!m&&o&&(0,d.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:q(o)}),r?(0,d.jsx)("button",{type:"button",onClick:a=>{a.stopPropagation(),j()},title:"Unpin project",tabIndex:m?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"rgba(234,179,8,0.12)",color:"#ca8a04",cursor:"pointer",flexShrink:0,opacity:m?1:.85,transition:"opacity 0.12s"},children:(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 17v5"}),(0,d.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}):(0,d.jsx)("button",{type:"button",onClick:a=>{a.stopPropagation(),j()},disabled:g,title:"Pin project to sidebar",tabIndex:m?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:g?"wait":"pointer",flexShrink:0,opacity:+!!m,transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="#ca8a04"},onMouseLeave:a=>{a.currentTarget.style.background="transparent",a.currentTarget.style.color="var(--text-muted)"},children:(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 17v5"}),(0,d.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),(0,d.jsx)("span",{title:"Drag to reorder",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:m?1:.35,transition:"opacity 0.12s",cursor:"grab"},children:(0,d.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor",children:[(0,d.jsx)("circle",{cx:"2",cy:"2",r:"1"}),(0,d.jsx)("circle",{cx:"8",cy:"2",r:"1"}),(0,d.jsx)("circle",{cx:"2",cy:"6",r:"1"}),(0,d.jsx)("circle",{cx:"8",cy:"6",r:"1"}),(0,d.jsx)("circle",{cx:"2",cy:"10",r:"1"}),(0,d.jsx)("circle",{cx:"8",cy:"10",r:"1"})]})})]})}function z({node:a,selectedSessionId:b,onSelectSession:c,onRenamed:f,onSessionDeleted:g,depth:h,runningSessionIds:i}){let[j,k]=(0,e.useState)(!1),l=a.children.length>0;return(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{style:{position:"relative"},children:[h>0&&(0,d.jsx)("div",{style:{position:"absolute",left:12*h+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,d.jsx)(A,{session:a.session,isSelected:a.session.id===b,onClick:()=>c(a.session),onRenamed:f,onDeleted:a=>g?.(a),depth:h,hasChildren:l,collapsed:j,onToggleCollapse:()=>k(a=>!a),isRunning:i.has(a.session.id)})]}),l&&!j&&(0,d.jsx)("div",{children:a.children.map(a=>(0,d.jsx)(z,{node:a,selectedSessionId:b,onSelectSession:c,onRenamed:f,onSessionDeleted:g,depth:h+1,runningSessionIds:i},a.session.id))})]})}function A({session:a,isSelected:b,onClick:c,onRenamed:f,onDeleted:g,depth:h=0,hasChildren:i=!1,collapsed:j=!1,onToggleCollapse:k,isRunning:l=!1}){let[m,n]=(0,e.useState)(!1),[o,p]=(0,e.useState)(!1),[r,s]=(0,e.useState)(""),[t,u]=(0,e.useState)(!1),[v,w]=(0,e.useState)(!1),x=(0,e.useRef)(null),y=a.name||a.firstMessage.slice(0,50)||a.id.slice(0,12),z=(0,e.useCallback)(b=>{b.stopPropagation(),s(a.name??""),p(!0),setTimeout(()=>x.current?.select(),0)},[a.name]),B=(0,e.useCallback)(async()=>{let b=r.trim();if(p(!1),b!==(a.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(a.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:b})}),f?.()}catch{}},[r,a.id,a.name,f]),C=(0,e.useCallback)(a=>{a.stopPropagation(),u(!0)},[]),D=(0,e.useCallback)(async b=>{b.stopPropagation(),u(!1),w(!0);try{await fetch(`/api/sessions/${encodeURIComponent(a.id)}`,{method:"DELETE"}),g?.(a.id)}catch{w(!1)}},[a.id,g]),E=(0,e.useCallback)(a=>{a.stopPropagation(),u(!1)},[]),F="workbench"===a.sessionKind;return(0,d.jsx)("div",{onClick:t||o?void 0:c,onMouseEnter:()=>n(!0),onMouseLeave:()=>{n(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:h>0?12*h+14:14,paddingRight:8,cursor:t||o?"default":"pointer",background:t?"rgba(239,68,68,0.06)":b?"var(--bg-selected)":m?"var(--bg-hover)":"transparent",borderLeft:t?"2px solid #ef4444":b?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:v?.5:1,gap:6,overflow:"hidden"},children:t?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,d.jsxs)("span",{style:{fontWeight:600},children:["“",y.slice(0,22),y.length>22?"…":"","”"]}),"?"]}),(0,d.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,d.jsxs)("button",{onClick:D,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:30,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,d.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,d.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,d.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),"Delete"]}),(0,d.jsx)("button",{onClick:E,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:"Cancel"})]})]}):o?(0,d.jsx)("input",{ref:x,value:r,onChange:a=>s(a.target.value),onBlur:B,onKeyDown:a=>{"Enter"===a.key&&B(),"Escape"===a.key&&p(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:28}}):(0,d.jsxs)(d.Fragment,{children:[h>0&&(0,d.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,d.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,d.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,d.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),0===h&&(0,d.jsx)("span",{"aria-hidden":"true",style:{width:l?7:5,height:l?7:5,borderRadius:"50%",background:l?"#22c55e":b?"var(--accent)":"var(--text-dim)",opacity:b?1:.35,flexShrink:0,...l?{boxShadow:"0 0 6px rgba(34,197,94,0.5)",animation:"pulse 2s infinite"}:{}}}),F&&(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M4 19V5"}),(0,d.jsx)("path",{d:"M4 19h16"}),(0,d.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,d.jsxs)("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:1},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:b?600:500,lineHeight:"18px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:F?"var(--accent)":"var(--text)"},title:y,children:y}),(0,d.jsxs)("div",{style:{display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,d.jsx)("span",{title:a.modified,children:q(a.modified)}),(0,d.jsxs)("span",{children:[a.messageCount," msgs"]}),!1===a.cwdExists&&(0,d.jsx)("span",{title:`Project path missing: ${a.cwd}`,style:{color:"#f87171"},children:"missing path"})]})]}),i&&(0,d.jsx)("button",{onClick:a=>{a.stopPropagation(),k?.()},title:j?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:j?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),m&&(0,d.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,d.jsx)("button",{onClick:z,title:"Rename",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-selected)",a.currentTarget.style.color="var(--accent)",a.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text-muted)",a.currentTarget.style.borderColor="var(--border)"},children:(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,d.jsx)("button",{onClick:C,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="rgba(239,68,68,0.08)",a.currentTarget.style.color="#ef4444",a.currentTarget.style.borderColor="rgba(239,68,68,0.35)"},onMouseLeave:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text-muted)",a.currentTarget.style.borderColor="var(--border)"},children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,d.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,d.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,d.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}var B=c(62418);let C="subagent",D=["retain","recall","reflect"],E=[],F=["read","bash","edit","write"],G=["bash","read","edit","write","grep","find","ls"],H=[...G,"kernel_plot_run","kernel_plot_render","kernel_plot_inspect","kernel_plot_stop","kernel_plot_artifacts"],I=[...G,C];function J(a){return[...a].sort().join(",")}function K(a){switch(a){case"none":return E;case"default":return F;case"workbench":return H;case"agent":return I;default:return G}}function L(a,b){return[...new Set([...K(a),...b])]}let M=new Map,N=["off","default","full","agent"],O={off:"none",default:"default",full:"full",agent:"agent"},P={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},Q={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},R=["auto","off","minimal","low","medium","high","xhigh"],S={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},T=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function U({doc:a,onRemove:b}){var c;let e=a.fileName.split(".").pop()?.toLowerCase()??"",f=function(a){switch(a){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(e),g=(c=a.size)<1024?`${c} B`:c<1048576?`${(c/1024).toFixed(1)} KB`:`${(c/1048576).toFixed(1)} MB`;return(0,d.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:a.fileName,children:[(0,d.jsx)("span",{style:{color:f.color,fontSize:14,flexShrink:0},children:f.emoji}),(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:a.fileName}),(0,d.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[e.toUpperCase()," \xb7 ",g,a.extractionError?" \xb7 no text":a.truncated?" \xb7 truncated":a.extractedText?" \xb7 text":""]})]}),(0,d.jsx)("button",{onClick:b,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:a=>{a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.color="var(--text-dim)"},children:(0,d.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,d.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,d.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}function V(a){return a.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&apos;/g,"'")}async function W(a){let b=await c.e(1688).then(c.bind(c,81688));b.GlobalWorkerOptions.workerSrc=new c.U(c(19224)).toString();let d=await b.getDocument({data:a.slice(0)}).promise,e=[];for(let a=1;a<=d.numPages;a+=1){let b=await d.getPage(a),c=(await b.getTextContent()).items.map(a=>"str"in a?a.str:"").filter(Boolean).join(" ");c.trim()&&e.push(`Page ${a}
2
- ${c}`)}return e.join("\n\n")}async function X(a){let b=(await c.e(7890).then(c.t.bind(c,55509,23))).default,d=await b.loadAsync(a),e=["word/document.xml",...Object.keys(d.files).filter(a=>/^word\/(footnotes|endnotes|comments)\.xml$/i.test(a)).sort()],f=[];for(let a of e){let b=d.file(a);if(!b)continue;let c=[...(await b.async("string")).replace(/<w:(br|cr)[^>]*\/>/g,"\n").replace(/<\/w:p>/g,"\n").matchAll(/<w:t[^>]*>([\s\S]*?)<\/w:t>/g)];f.push(...c.map(a=>V(a[1])))}return f.join("").replace(/[ \t]+\n/g,"\n")}async function Y(a){let b=await c.e(7765).then(c.bind(c,77765)),d=b.read(a,{type:"array"});return d.SheetNames.map(a=>{let c=d.Sheets[a],e=b.utils.sheet_to_csv(c);return`Sheet: ${a}
3
- ${e}`}).join("\n\n")}async function Z(a){let b=(await c.e(7890).then(c.t.bind(c,55509,23))).default,d=await b.loadAsync(a),e=Object.keys(d.files).map(a=>({name:a,match:/^ppt\/slides\/slide(\d+)\.xml$/i.exec(a)})).filter(a=>null!==a.match).sort((a,b)=>Number(a.match[1])-Number(b.match[1])),f=[];for(let{name:a,match:b}of e){let c=[...(await d.file(a).async("string")).matchAll(/<a:t[^>]*>([\s\S]*?)<\/a:t>/g)].map(a=>V(a[1]).trim()).filter(Boolean);c.length&&f.push(`Slide ${b[1]}
4
- ${c.join("\n")}`)}return f.join("\n\n")}async function $(a,b){let c=a.name.split(".").pop()?.toLowerCase()??"";try{let d,e="";if(a.type.startsWith("text/")||["csv","tsv","md","txt","json","xml"].includes(c))e=new TextDecoder("utf-8").decode(b);else if("pdf"===c||"application/pdf"===a.type)e=await W(b);else if("docx"===c)e=await X(b);else if("xlsx"===c)e=await Y(b);else{if("pptx"!==c)return{extractionError:"Text extraction is not supported for this file type"};e=await Z(b)}let{text:f,truncated:g}=(d=e.replace(/\r\n/g,"\n").replace(/\n{4,}/g,"\n\n\n").trim()).length<=6e4?{text:d,truncated:!1}:{text:`${d.slice(0,6e4)}
1
+ (()=>{var a={};a.id=8974,a.ids=[8974],a.modules={261:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/app-paths")},478:(a,b,c)=>{Promise.resolve().then(c.bind(c,55998))},1708:a=>{"use strict";a.exports=require("node:process")},2798:(a,b,c)=>{let d=c(76708),e=c(95380),f=c(18994),g=c(32835);function h(a,b,c,f,g){let h=[].slice.call(arguments,1),i=h.length,j="function"==typeof h[i-1];if(!j&&!d())throw Error("Callback required as last argument");if(j){if(i<2)throw Error("Too few arguments provided");2===i?(g=c,c=b,b=f=void 0):3===i&&(b.getContext&&void 0===g?(g=f,f=void 0):(g=f,f=c,c=b,b=void 0))}else{if(i<1)throw Error("Too few arguments provided");return 1===i?(c=b,b=f=void 0):2!==i||b.getContext||(f=c,c=b,b=void 0),new Promise(function(d,g){try{let g=e.create(c,f);d(a(g,b,f))}catch(a){g(a)}})}try{let d=e.create(c,f);g(null,a(d,b,f))}catch(a){g(a)}}e.create,b.toCanvas=h.bind(null,f.render),h.bind(null,f.renderToDataURL),h.bind(null,function(a,b,c){return g.render(a,c)})},3295:a=>{"use strict";a.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},5206:(a,b,c)=>{Promise.resolve().then(c.bind(c,35790))},9709:(a,b,c)=>{"use strict";let d=!0,e=c(74075),f=c(80183);e.deflateSync||(d=!1);let g=c(81769),h=c(42516),i=c(96277),j=c(92858),k=c(83670);a.exports=function(a,b){let c,l,m,n;if(!d)throw Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let o=[],p=new g(a);if(new i(b,{read:p.read.bind(p),error:function(a){c=a},metadata:function(a){l=a},gamma:function(a){m=a},palette:function(a){l.palette=a},transColor:function(a){l.transColor=a},inflateData:function(a){o.push(a)},simpleTransparency:function(){l.alpha=!0}}).start(),p.process(),c)throw c;let q=Buffer.concat(o);if(o.length=0,l.interlace)n=e.inflateSync(q);else{let a=((l.width*l.bpp*l.depth+7>>3)+1)*l.height;n=f(q,{chunkSize:a,maxLength:a})}if(q=null,!n||!n.length)throw Error("bad png - invalid inflate data response");let r=h.process(n,l);q=null;let s=j.dataToBitMap(r,l);r=null;let t=k(s,l);return l.data=t,l.gamma=m||0,l}},10846:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},12097:(a,b)=>{b.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};b.isValid=function(a){return null!=a&&""!==a&&!isNaN(a)&&a>=0&&a<=7},b.from=function(a){return b.isValid(a)?parseInt(a,10):void 0},b.getPenaltyN1=function(a){let b=a.size,c=0,d=0,e=0,f=null,g=null;for(let h=0;h<b;h++){d=e=0,f=g=null;for(let i=0;i<b;i++){let b=a.get(h,i);b===f?d++:(d>=5&&(c+=3+(d-5)),f=b,d=1),(b=a.get(i,h))===g?e++:(e>=5&&(c+=3+(e-5)),g=b,e=1)}d>=5&&(c+=3+(d-5)),e>=5&&(c+=3+(e-5))}return c},b.getPenaltyN2=function(a){let b=a.size,c=0;for(let d=0;d<b-1;d++)for(let e=0;e<b-1;e++){let b=a.get(d,e)+a.get(d,e+1)+a.get(d+1,e)+a.get(d+1,e+1);(4===b||0===b)&&c++}return 3*c},b.getPenaltyN3=function(a){let b=a.size,c=0,d=0,e=0;for(let f=0;f<b;f++){d=e=0;for(let g=0;g<b;g++)d=d<<1&2047|a.get(f,g),g>=10&&(1488===d||93===d)&&c++,e=e<<1&2047|a.get(g,f),g>=10&&(1488===e||93===e)&&c++}return 40*c},b.getPenaltyN4=function(a){let b=0,c=a.data.length;for(let d=0;d<c;d++)b+=a.data[d];return 10*Math.abs(Math.ceil(100*b/c/5)-10)},b.applyMask=function(a,c){let d=c.size;for(let e=0;e<d;e++)for(let f=0;f<d;f++)c.isReserved(f,e)||c.xor(f,e,function(a,c,d){switch(a){case b.Patterns.PATTERN000:return(c+d)%2==0;case b.Patterns.PATTERN001:return c%2==0;case b.Patterns.PATTERN010:return d%3==0;case b.Patterns.PATTERN011:return(c+d)%3==0;case b.Patterns.PATTERN100:return(Math.floor(c/2)+Math.floor(d/3))%2==0;case b.Patterns.PATTERN101:return c*d%2+c*d%3==0;case b.Patterns.PATTERN110:return(c*d%2+c*d%3)%2==0;case b.Patterns.PATTERN111:return(c*d%3+(c+d)%2)%2==0;default:throw Error("bad maskPattern:"+a)}}(a,f,e))},b.getBestMask=function(a,c){let d=Object.keys(b.Patterns).length,e=0,f=1/0;for(let g=0;g<d;g++){c(g),b.applyMask(g,a);let d=b.getPenaltyN1(a)+b.getPenaltyN2(a)+b.getPenaltyN3(a)+b.getPenaltyN4(a);b.applyMask(g,a),d<f&&(f=d,e=g)}return e}},12412:a=>{"use strict";a.exports=require("assert")},17891:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/get-segment-param")},18994:(a,b,c)=>{let d=c(88397);b.render=function(a,b,c){var e;let f=c,g=b;void 0!==f||b&&b.getContext||(f=b,b=void 0),b||(g=function(){try{return document.createElement("canvas")}catch(a){throw Error("You need to specify a canvas element")}}()),f=d.getOptions(f);let h=d.getImageWidth(a.modules.size,f),i=g.getContext("2d"),j=i.createImageData(h,h);return d.qrToImageData(j.data,a,f),e=g,i.clearRect(0,0,e.width,e.height),e.style||(e.style={}),e.height=h,e.width=h,e.style.height=h+"px",e.style.width=h+"px",i.putImageData(j,0,0),g},b.renderToDataURL=function(a,c,d){let e=d;void 0!==e||c&&c.getContext||(e=c,c=void 0),e||(e={});let f=b.render(a,c,e),g=e.type||"image/png",h=e.rendererOpts||{};return f.toDataURL(g,h.quality)}},19099:(a,b,c)=>{"use strict";var d=c(54839);c.o(d,"useRouter")&&c.d(b,{useRouter:function(){return d.useRouter}}),c.o(d,"useSearchParams")&&c.d(b,{useSearchParams:function(){return d.useSearchParams}})},19121:a=>{"use strict";a.exports=require("next/dist/server/app-render/action-async-storage.external.js")},19477:(a,b,c)=>{let d=c(58856),e=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],f=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];b.getBlocksCount=function(a,b){switch(b){case d.L:return e[(a-1)*4+0];case d.M:return e[(a-1)*4+1];case d.Q:return e[(a-1)*4+2];case d.H:return e[(a-1)*4+3];default:return}},b.getTotalCodewordsCount=function(a,b){switch(b){case d.L:return f[(a-1)*4+0];case d.M:return f[(a-1)*4+1];case d.Q:return f[(a-1)*4+2];case d.H:return f[(a-1)*4+3];default:return}}},23372:(a,b,c)=>{"use strict";let d=c(28354),e=c(74075),f=c(57949),g=c(27459),h=c(96277),i=c(92858),j=c(83670),k=a.exports=function(a){f.call(this),this._parser=new h(a,{read:this.read.bind(this),error:this._handleError.bind(this),metadata:this._handleMetaData.bind(this),gamma:this.emit.bind(this,"gamma"),palette:this._handlePalette.bind(this),transColor:this._handleTransColor.bind(this),finished:this._finished.bind(this),inflateData:this._inflateData.bind(this),simpleTransparency:this._simpleTransparency.bind(this),headersFinished:this._headersFinished.bind(this)}),this._options=a,this.writable=!0,this._parser.start()};d.inherits(k,f),k.prototype._handleError=function(a){this.emit("error",a),this.writable=!1,this.destroy(),this._inflate&&this._inflate.destroy&&this._inflate.destroy(),this._filter&&(this._filter.destroy(),this._filter.on("error",function(){})),this.errord=!0},k.prototype._inflateData=function(a){if(!this._inflate)if(this._bitmapInfo.interlace)this._inflate=e.createInflate(),this._inflate.on("error",this.emit.bind(this,"error")),this._filter.on("complete",this._complete.bind(this)),this._inflate.pipe(this._filter);else{let a=((this._bitmapInfo.width*this._bitmapInfo.bpp*this._bitmapInfo.depth+7>>3)+1)*this._bitmapInfo.height,b=Math.max(a,e.Z_MIN_CHUNK);this._inflate=e.createInflate({chunkSize:b});let c=a,d=this.emit.bind(this,"error");this._inflate.on("error",function(a){c&&d(a)}),this._filter.on("complete",this._complete.bind(this));let f=this._filter.write.bind(this._filter);this._inflate.on("data",function(a){c&&(a.length>c&&(a=a.slice(0,c)),c-=a.length,f(a))}),this._inflate.on("end",this._filter.end.bind(this._filter))}this._inflate.write(a)},k.prototype._handleMetaData=function(a){this._metaData=a,this._bitmapInfo=Object.create(a),this._filter=new g(this._bitmapInfo)},k.prototype._handleTransColor=function(a){this._bitmapInfo.transColor=a},k.prototype._handlePalette=function(a){this._bitmapInfo.palette=a},k.prototype._simpleTransparency=function(){this._metaData.alpha=!0},k.prototype._headersFinished=function(){this.emit("metadata",this._metaData)},k.prototype._finished=function(){this.errord||(this._inflate?this._inflate.end():this.emit("error","No Inflate block"))},k.prototype._complete=function(a){let b;if(!this.errord){try{let c=i.dataToBitMap(a,this._bitmapInfo);b=j(c,this._bitmapInfo),c=null}catch(a){this._handleError(a);return}this.emit("parsed",b)}}},26713:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/is-bot")},27137:(a,b,c)=>{let d=c(93669),e=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function f(a){this.mode=d.ALPHANUMERIC,this.data=a}f.getBitsLength=function(a){return 11*Math.floor(a/2)+a%2*6},f.prototype.getLength=function(){return this.data.length},f.prototype.getBitsLength=function(){return f.getBitsLength(this.data.length)},f.prototype.write=function(a){let b;for(b=0;b+2<=this.data.length;b+=2){let c=45*e.indexOf(this.data[b]);c+=e.indexOf(this.data[b+1]),a.put(c,11)}this.data.length%2&&a.put(e.indexOf(this.data[b]),6)},a.exports=f},27459:(a,b,c)=>{"use strict";let d=c(28354),e=c(57949),f=c(27734),g=a.exports=function(a){e.call(this);let b=[],c=this;this._filter=new f(a,{read:this.read.bind(this),write:function(a){b.push(a)},complete:function(){c.emit("complete",Buffer.concat(b))}}),this._filter.start()};d.inherits(g,e)},27734:(a,b,c)=>{"use strict";let d=c(59725),e=c(55211);function f(a,b,c){let d=a*b;return 8!==c&&(d=Math.ceil(d/(8/c))),d}let g=a.exports=function(a,b){let c=a.width,e=a.height,g=a.interlace,h=a.bpp,i=a.depth;if(this.read=b.read,this.write=b.write,this.complete=b.complete,this._imageIndex=0,this._images=[],g){let a=d.getImagePasses(c,e);for(let b=0;b<a.length;b++)this._images.push({byteWidth:f(a[b].width,h,i),height:a[b].height,lineIndex:0})}else this._images.push({byteWidth:f(c,h,i),height:e,lineIndex:0});8===i?this._xComparison=h:16===i?this._xComparison=2*h:this._xComparison=1};g.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this))},g.prototype._unFilterType1=function(a,b,c){let d=this._xComparison,e=d-1;for(let f=0;f<c;f++){let c=a[1+f],g=f>e?b[f-d]:0;b[f]=c+g}},g.prototype._unFilterType2=function(a,b,c){let d=this._lastLine;for(let e=0;e<c;e++){let c=a[1+e],f=d?d[e]:0;b[e]=c+f}},g.prototype._unFilterType3=function(a,b,c){let d=this._xComparison,e=d-1,f=this._lastLine;for(let g=0;g<c;g++){let c=a[1+g],h=f?f[g]:0,i=Math.floor(((g>e?b[g-d]:0)+h)/2);b[g]=c+i}},g.prototype._unFilterType4=function(a,b,c){let d=this._xComparison,f=d-1,g=this._lastLine;for(let h=0;h<c;h++){let c=a[1+h],i=g?g[h]:0,j=e(h>f?b[h-d]:0,i,h>f&&g?g[h-d]:0);b[h]=c+j}},g.prototype._reverseFilterLine=function(a){let b,c=a[0],d=this._images[this._imageIndex],e=d.byteWidth;if(0===c)b=a.slice(1,e+1);else switch(b=Buffer.alloc(e),c){case 1:this._unFilterType1(a,b,e);break;case 2:this._unFilterType2(a,b,e);break;case 3:this._unFilterType3(a,b,e);break;case 4:this._unFilterType4(a,b,e);break;default:throw Error("Unrecognised filter type - "+c)}this.write(b),d.lineIndex++,d.lineIndex>=d.height?(this._lastLine=null,this._imageIndex++,d=this._images[this._imageIndex]):this._lastLine=b,d?this.read(d.byteWidth+1,this._reverseFilterLine.bind(this)):(this._lastLine=null,this.complete())}},27910:a=>{"use strict";a.exports=require("stream")},28354:a=>{"use strict";a.exports=require("util")},28964:(a,b,c)=>{let d=c(93669);function e(a){this.mode=d.NUMERIC,this.data=a.toString()}e.getBitsLength=function(a){return 10*Math.floor(a/3)+(a%3?a%3*3+1:0)},e.prototype.getLength=function(){return this.data.length},e.prototype.getBitsLength=function(){return e.getBitsLength(this.data.length)},e.prototype.write=function(a){let b,c;for(b=0;b+3<=this.data.length;b+=3)c=parseInt(this.data.substr(b,3),10),a.put(c,10);let d=this.data.length-b;d>0&&(c=parseInt(this.data.substr(b),10),a.put(c,3*d+1))},a.exports=e},29021:a=>{"use strict";a.exports=require("fs")},29294:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-async-storage.external.js")},31964:(a,b,c)=>{"use strict";let d=c(55211),e={0:function(a,b,c,d,e){for(let f=0;f<c;f++)d[e+f]=a[b+f]},1:function(a,b,c,d,e,f){for(let g=0;g<c;g++){let c=g>=f?a[b+g-f]:0,h=a[b+g]-c;d[e+g]=h}},2:function(a,b,c,d,e){for(let f=0;f<c;f++){let g=b>0?a[b+f-c]:0,h=a[b+f]-g;d[e+f]=h}},3:function(a,b,c,d,e,f){for(let g=0;g<c;g++){let h=g>=f?a[b+g-f]:0,i=b>0?a[b+g-c]:0,j=a[b+g]-(h+i>>1);d[e+g]=j}},4:function(a,b,c,e,f,g){for(let h=0;h<c;h++){let i=h>=g?a[b+h-g]:0,j=b>0?a[b+h-c]:0,k=b>0&&h>=g?a[b+h-(c+g)]:0,l=a[b+h]-d(i,j,k);e[f+h]=l}}},f={0:function(a,b,c){let d=0,e=b+c;for(let c=b;c<e;c++)d+=Math.abs(a[c]);return d},1:function(a,b,c,d){let e=0;for(let f=0;f<c;f++){let c=f>=d?a[b+f-d]:0;e+=Math.abs(a[b+f]-c)}return e},2:function(a,b,c){let d=0,e=b+c;for(let f=b;f<e;f++){let e=b>0?a[f-c]:0;d+=Math.abs(a[f]-e)}return d},3:function(a,b,c,d){let e=0;for(let f=0;f<c;f++){let g=f>=d?a[b+f-d]:0,h=b>0?a[b+f-c]:0;e+=Math.abs(a[b+f]-(g+h>>1))}return e},4:function(a,b,c,e){let f=0;for(let g=0;g<c;g++){let h=g>=e?a[b+g-e]:0,i=b>0?a[b+g-c]:0,j=b>0&&g>=e?a[b+g-(c+e)]:0;f+=Math.abs(a[b+g]-d(h,i,j))}return f}};a.exports=function(a,b,c,d,g){let h;if("filterType"in d&&-1!==d.filterType)if("number"==typeof d.filterType)h=[d.filterType];else throw Error("unrecognised filter types");else h=[0,1,2,3,4];16===d.bitDepth&&(g*=2);let i=b*g,j=0,k=0,l=Buffer.alloc((i+1)*c),m=h[0];for(let b=0;b<c;b++){if(h.length>1){let b=1/0;for(let c=0;c<h.length;c++){let d=f[h[c]](a,k,i,g);d<b&&(m=h[c],b=d)}}l[j]=m,j++,e[m](a,k,i,l,j,g),j+=i,k+=i}return l}},32835:(a,b,c)=>{let d=c(88397);function e(a,b){let c=a.a/255,d=b+'="'+a.hex+'"';return c<1?d+" "+b+'-opacity="'+c.toFixed(2).slice(1)+'"':d}function f(a,b,c){let d=a+b;return void 0!==c&&(d+=" "+c),d}b.render=function(a,b,c){let g=d.getOptions(b),h=a.modules.size,i=a.modules.data,j=h+2*g.margin,k=g.color.light.a?"<path "+e(g.color.light,"fill")+' d="M0 0h'+j+"v"+j+'H0z"/>':"",l="<path "+e(g.color.dark,"stroke")+' d="'+function(a,b,c){let d="",e=0,g=!1,h=0;for(let i=0;i<a.length;i++){let j=Math.floor(i%b),k=Math.floor(i/b);j||g||(g=!0),a[i]?(h++,i>0&&j>0&&a[i-1]||(d+=g?f("M",j+c,.5+k+c):f("m",e,0),e=0,g=!1),j+1<b&&a[i+1]||(d+=f("h",h),h=0)):e++}return d}(i,h,g.margin)+'"/>',m='<svg xmlns="http://www.w3.org/2000/svg" '+(g.width?'width="'+g.width+'" height="'+g.width+'" ':"")+('viewBox="0 0 '+j+" ")+j+'" shape-rendering="crispEdges">'+k+l+"</svg>\n";return"function"==typeof c&&c(null,m),m}},33873:a=>{"use strict";a.exports=require("path")},34447:(a,b,c)=>{"use strict";let d=c(28354),e=c(27910),f=c(23372),g=c(49149),h=c(58879),i=b.O=function(a){e.call(this),a=a||{},this.width=0|a.width,this.height=0|a.height,this.data=this.width>0&&this.height>0?Buffer.alloc(4*this.width*this.height):null,a.fill&&this.data&&this.data.fill(0),this.gamma=0,this.readable=this.writable=!0,this._parser=new f(a),this._parser.on("error",this.emit.bind(this,"error")),this._parser.on("close",this._handleClose.bind(this)),this._parser.on("metadata",this._metadata.bind(this)),this._parser.on("gamma",this._gamma.bind(this)),this._parser.on("parsed",(function(a){this.data=a,this.emit("parsed",a)}).bind(this)),this._packer=new g(a),this._packer.on("data",this.emit.bind(this,"data")),this._packer.on("end",this.emit.bind(this,"end")),this._parser.on("close",this._handleClose.bind(this)),this._packer.on("error",this.emit.bind(this,"error"))};d.inherits(i,e),i.sync=h,i.prototype.pack=function(){return this.data&&this.data.length?process.nextTick((function(){this._packer.pack(this.data,this.width,this.height,this.gamma)}).bind(this)):this.emit("error","No data provided"),this},i.prototype.parse=function(a,b){if(b){let a,c;a=(function(a){this.removeListener("error",c),this.data=a,b(null,this)}).bind(this),c=(function(c){this.removeListener("parsed",a),b(c,null)}).bind(this),this.once("parsed",a),this.once("error",c)}return this.end(a),this},i.prototype.write=function(a){return this._parser.write(a),!0},i.prototype.end=function(a){this._parser.end(a)},i.prototype._metadata=function(a){this.width=a.width,this.height=a.height,this.emit("metadata",a)},i.prototype._gamma=function(a){this.gamma=a},i.prototype._handleClose=function(){this._parser.writable||this._packer.readable||this.emit("close")},i.bitblt=function(a,b,c,d,e,f,g,h){if(d|=0,e|=0,f|=0,g|=0,h|=0,(c|=0)>a.width||d>a.height||c+e>a.width||d+f>a.height)throw Error("bitblt reading outside image");if(g>b.width||h>b.height||g+e>b.width||h+f>b.height)throw Error("bitblt writing outside image");for(let i=0;i<f;i++)a.data.copy(b.data,(h+i)*b.width+g<<2,(d+i)*a.width+c<<2,(d+i)*a.width+c+e<<2)},i.prototype.bitblt=function(a,b,c,d,e,f,g){return i.bitblt(this,a,b,c,d,e,f,g),this},i.adjustGamma=function(a){if(a.gamma){for(let b=0;b<a.height;b++)for(let c=0;c<a.width;c++){let d=a.width*b+c<<2;for(let b=0;b<3;b++){let c=a.data[d+b]/255;c=Math.pow(c,1/2.2/a.gamma),a.data[d+b]=Math.round(255*c)}}a.gamma=0}},i.prototype.adjustGamma=function(){i.adjustGamma(this)}},35790:(a,b,c)=>{"use strict";c.d(b,{AppShell:()=>d});let d=(0,c(77943).registerClientReference)(function(){throw Error("Attempted to call AppShell() from the server but AppShell is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.")},"/home/runner/work/annovibe/annovibe/components/AppShell.tsx","AppShell")},38937:(a,b,c)=>{let d=c(93669);function e(a){this.mode=d.BYTE,"string"==typeof a?this.data=new TextEncoder().encode(a):this.data=new Uint8Array(a)}e.getBitsLength=function(a){return 8*a},e.prototype.getLength=function(){return this.data.length},e.prototype.getBitsLength=function(){return e.getBitsLength(this.data.length)},e.prototype.write=function(a){for(let b=0,c=this.data.length;b<c;b++)a.put(this.data[b],8)},a.exports=e},39477:(a,b,c)=>{let d=c(58305).getSymbolSize;b.getPositions=function(a){let b=d(a);return[[0,0],[b-7,0],[0,b-7]]}},39588:(a,b,c)=>{let d=c(93669),e=c(28964),f=c(27137),g=c(38937),h=c(64424),i=c(64323),j=c(58305),k=c(84879);function l(a){return unescape(encodeURIComponent(a)).length}function m(a,b,c){let d,e=[];for(;null!==(d=a.exec(c));)e.push({data:d[0],index:d.index,mode:b,length:d[0].length});return e}function n(a){let b,c,e=m(i.NUMERIC,d.NUMERIC,a),f=m(i.ALPHANUMERIC,d.ALPHANUMERIC,a);return j.isKanjiModeEnabled()?(b=m(i.BYTE,d.BYTE,a),c=m(i.KANJI,d.KANJI,a)):(b=m(i.BYTE_KANJI,d.BYTE,a),c=[]),e.concat(f,b,c).sort(function(a,b){return a.index-b.index}).map(function(a){return{data:a.data,mode:a.mode,length:a.length}})}function o(a,b){switch(b){case d.NUMERIC:return e.getBitsLength(a);case d.ALPHANUMERIC:return f.getBitsLength(a);case d.KANJI:return h.getBitsLength(a);case d.BYTE:return g.getBitsLength(a)}}function p(a,b){let c,i=d.getBestModeForData(a);if((c=d.from(b,i))!==d.BYTE&&c.bit<i.bit)throw Error('"'+a+'" cannot be encoded with mode '+d.toString(c)+".\n Suggested mode is: "+d.toString(i));switch(c===d.KANJI&&!j.isKanjiModeEnabled()&&(c=d.BYTE),c){case d.NUMERIC:return new e(a);case d.ALPHANUMERIC:return new f(a);case d.KANJI:return new h(a);case d.BYTE:return new g(a)}}b.fromArray=function(a){return a.reduce(function(a,b){return"string"==typeof b?a.push(p(b,null)):b.data&&a.push(p(b.data,b.mode)),a},[])},b.fromString=function(a,c){let e=function(a,b){let c={},e={start:{}},f=["start"];for(let g=0;g<a.length;g++){let h=a[g],i=[];for(let a=0;a<h.length;a++){let j=h[a],k=""+g+a;i.push(k),c[k]={node:j,lastCount:0},e[k]={};for(let a=0;a<f.length;a++){let g=f[a];c[g]&&c[g].node.mode===j.mode?(e[g][k]=o(c[g].lastCount+j.length,j.mode)-o(c[g].lastCount,j.mode),c[g].lastCount+=j.length):(c[g]&&(c[g].lastCount=j.length),e[g][k]=o(j.length,j.mode)+4+d.getCharCountIndicator(j.mode,b))}}f=i}for(let a=0;a<f.length;a++)e[f[a]].end=0;return{map:e,table:c}}(function(a){let b=[];for(let c=0;c<a.length;c++){let e=a[c];switch(e.mode){case d.NUMERIC:b.push([e,{data:e.data,mode:d.ALPHANUMERIC,length:e.length},{data:e.data,mode:d.BYTE,length:e.length}]);break;case d.ALPHANUMERIC:b.push([e,{data:e.data,mode:d.BYTE,length:e.length}]);break;case d.KANJI:b.push([e,{data:e.data,mode:d.BYTE,length:l(e.data)}]);break;case d.BYTE:b.push([{data:e.data,mode:d.BYTE,length:l(e.data)}])}}return b}(n(a,j.isKanjiModeEnabled())),c),f=k.find_path(e.map,"start","end"),g=[];for(let a=1;a<f.length-1;a++)g.push(e.table[f[a]].node);return b.fromArray(g.reduce(function(a,b){let c=a.length-1>=0?a[a.length-1]:null;return c&&c.mode===b.mode?a[a.length-1].data+=b.data:a.push(b),a},[]))},b.rawSplit=function(a){return b.fromArray(n(a,j.isKanjiModeEnabled()))}},40355:(a,b,c)=>{let d=c(76708),e=c(95380),f=c(46387),g=c(72081),h=c(66530),i=c(90082);function j(a,b,c){if(void 0===a)throw Error("String required as first argument");if(void 0===c&&(c=b,b={}),"function"!=typeof c)if(d())b=c||{},c=null;else throw Error("Callback required as last argument");return{opts:b,cb:c}}function k(a){switch(a){case"svg":return i;case"txt":case"utf8":return g;default:return f}}function l(a,b,c){if(!c.cb)return new Promise(function(d,f){try{let g=e.create(b,c.opts);return a(g,c.opts,function(a,b){return a?f(a):d(b)})}catch(a){f(a)}});try{let d=e.create(b,c.opts);return a(d,c.opts,c.cb)}catch(a){c.cb(a)}}b.create=e.create,b.toCanvas=c(2798).toCanvas,b.toString=function(a,b,c){let d=j(a,b,c);return l(function(a){switch(a){case"svg":return i;case"terminal":return h;default:return g}}(d.opts?d.opts.type:void 0).render,a,d)},b.toDataURL=function(a,b,c){let d=j(a,b,c);return l(k(d.opts.type).renderToDataURL,a,d)},b.toBuffer=function(a,b,c){let d=j(a,b,c);return l(k(d.opts.type).renderToBuffer,a,d)},b.toFile=function(a,b,c,e){if("string"!=typeof a||"string"!=typeof b&&"object"!=typeof b)throw Error("Invalid argument");if(arguments.length<3&&!d())throw Error("Too few arguments provided");let f=j(b,c,e);return l(k(f.opts.type||a.slice((a.lastIndexOf(".")-1>>>0)+2).toLowerCase()).renderToFile.bind(null,a),b,f)},b.toFileStream=function(a,b,c){if(arguments.length<2)throw Error("Too few arguments provided");let d=j(b,c,a.emit.bind(a,"error"));l(k("png").renderToFileStream.bind(null,a),b,d)}},41025:a=>{"use strict";a.exports=require("next/dist/server/app-render/dynamic-access-async-storage.external.js")},42516:(a,b,c)=>{"use strict";let d=c(81769),e=c(27734);b.process=function(a,b){let c=[],f=new d(a);return new e(b,{read:f.read.bind(f),write:function(a){c.push(a)},complete:function(){}}).start(),f.process(),Buffer.concat(c)}},43144:(a,b,c)=>{let d=c(81754);b.mul=function(a,b){let c=new Uint8Array(a.length+b.length-1);for(let e=0;e<a.length;e++)for(let f=0;f<b.length;f++)c[e+f]^=d.mul(a[e],b[f]);return c},b.mod=function(a,b){let c=new Uint8Array(a);for(;c.length-b.length>=0;){let a=c[0];for(let e=0;e<b.length;e++)c[e]^=d.mul(b[e],a);let e=0;for(;e<c.length&&0===c[e];)e++;c=c.slice(e)}return c},b.generateECPolynomial=function(a){let c=new Uint8Array([1]);for(let e=0;e<a;e++)c=b.mul(c,new Uint8Array([1,d.exp(e)]));return c}},43894:a=>{"use strict";let b=[];for(let a=0;a<256;a++){let c=a;for(let a=0;a<8;a++)1&c?c=0xedb88320^c>>>1:c>>>=1;b[a]=c}let c=a.exports=function(){this._crc=-1};c.prototype.write=function(a){for(let c=0;c<a.length;c++)this._crc=b[(this._crc^a[c])&255]^this._crc>>>8;return!0},c.prototype.crc32=function(){return -1^this._crc},c.crc32=function(a){let c=-1;for(let d=0;d<a.length;d++)c=b[(c^a[d])&255]^c>>>8;return -1^c}},43954:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/interception-routes")},46349:a=>{function b(a){if(!a||a<1)throw Error("BitMatrix size must be defined and greater than 0");this.size=a,this.data=new Uint8Array(a*a),this.reservedBit=new Uint8Array(a*a)}b.prototype.set=function(a,b,c,d){let e=a*this.size+b;this.data[e]=c,d&&(this.reservedBit[e]=!0)},b.prototype.get=function(a,b){return this.data[a*this.size+b]},b.prototype.xor=function(a,b,c){this.data[a*this.size+b]^=c},b.prototype.isReserved=function(a,b){return this.reservedBit[a*this.size+b]},a.exports=b},46387:(a,b,c)=>{let d=c(29021),e=c(34447).O,f=c(88397);b.render=function(a,b){let c=f.getOptions(b),d=c.rendererOpts,g=f.getImageWidth(a.modules.size,c);d.width=g,d.height=g;let h=new e(d);return f.qrToImageData(h.data,a,c),h},b.renderToDataURL=function(a,c,d){void 0===d&&(d=c,c=void 0),b.renderToBuffer(a,c,function(a,b){a&&d(a);let c="data:image/png;base64,";c+=b.toString("base64"),d(null,c)})},b.renderToBuffer=function(a,c,d){void 0===d&&(d=c,c=void 0);let e=b.render(a,c),f=[];e.on("error",d),e.on("data",function(a){f.push(a)}),e.on("end",function(){d(null,Buffer.concat(f))}),e.pack()},b.renderToFile=function(a,c,e,f){void 0===f&&(f=e,e=void 0);let g=!1,h=(...a)=>{g||(g=!0,f.apply(null,a))},i=d.createWriteStream(a);i.on("error",h),i.on("close",h),b.renderToFileStream(i,c,e)},b.renderToFileStream=function(a,c,d){b.render(c,d).pack().pipe(a)}},49149:(a,b,c)=>{"use strict";let d=c(28354),e=c(27910),f=c(67269),g=c(98052),h=a.exports=function(a){e.call(this),this._packer=new g(a||{}),this._deflate=this._packer.createDeflate(),this.readable=!0};d.inherits(h,e),h.prototype.pack=function(a,b,c,d){this.emit("data",Buffer.from(f.PNG_SIGNATURE)),this.emit("data",this._packer.packIHDR(b,c)),d&&this.emit("data",this._packer.packGAMA(d));let e=this._packer.filterData(a,b,c);this._deflate.on("error",this.emit.bind(this,"error")),this._deflate.on("data",(function(a){this.emit("data",this._packer.packIDAT(a))}).bind(this)),this._deflate.on("end",(function(){this.emit("data",this._packer.packIEND()),this.emit("end")}).bind(this)),this._deflate.end(e)}},49998:(a,b,c)=>{"use strict";a.exports=c(40355)},52002:a=>{function b(){this.buffer=[],this.length=0}b.prototype={get:function(a){let b=Math.floor(a/8);return(this.buffer[b]>>>7-a%8&1)==1},put:function(a,b){for(let c=0;c<b;c++)this.putBit((a>>>b-c-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(a){let b=Math.floor(this.length/8);this.buffer.length<=b&&this.buffer.push(0),a&&(this.buffer[b]|=128>>>this.length%8),this.length++}},a.exports=b},52324:(a,b,c)=>{let d=c(58305),e=c(19477),f=c(58856),g=c(93669),h=c(83929),i=d.getBCHDigit(7973);function j(a,b){return g.getCharCountIndicator(a,b)+4}b.from=function(a,b){return h.isValid(a)?parseInt(a,10):b},b.getCapacity=function(a,b,c){if(!h.isValid(a))throw Error("Invalid QR Code version");void 0===c&&(c=g.BYTE);let f=(d.getSymbolTotalCodewords(a)-e.getTotalCodewordsCount(a,b))*8;if(c===g.MIXED)return f;let i=f-j(c,a);switch(c){case g.NUMERIC:return Math.floor(i/10*3);case g.ALPHANUMERIC:return Math.floor(i/11*2);case g.KANJI:return Math.floor(i/13);case g.BYTE:default:return Math.floor(i/8)}},b.getBestVersionForData=function(a,c){let d,e=f.from(c,f.M);if(Array.isArray(a)){if(a.length>1){for(let c=1;c<=40;c++)if(function(a,b){let c=0;return a.forEach(function(a){let d=j(a.mode,b);c+=d+a.getBitsLength()}),c}(a,c)<=b.getCapacity(c,e,g.MIXED))return c;return}if(0===a.length)return 1;d=a[0]}else d=a;return function(a,c,d){for(let e=1;e<=40;e++)if(c<=b.getCapacity(e,d,a))return e}(d.mode,d.getLength(),e)},b.getEncodedBits=function(a){if(!h.isValid(a)||a<7)throw Error("Invalid QR Code version");let b=a<<12;for(;d.getBCHDigit(b)-i>=0;)b^=7973<<d.getBCHDigit(b)-i;return a<<12|b}},55211:a=>{"use strict";a.exports=function(a,b,c){let d=a+b-c,e=Math.abs(d-a),f=Math.abs(d-b),g=Math.abs(d-c);return e<=f&&e<=g?a:f<=g?b:c}},55258:(a,b,c)=>{let d=c(58305),e=d.getBCHDigit(1335);b.getEncodedBits=function(a,b){let c=a.bit<<3|b,f=c<<10;for(;d.getBCHDigit(f)-e>=0;)f^=1335<<d.getBCHDigit(f)-e;return(c<<10|f)^21522}},55897:(a,b,c)=>{"use strict";c.r(b),c.d(b,{__next_app__:()=>M,handler:()=>O,routeModule:()=>N});var d=c(7553),e=c(84006),f=c(67798),g=c(34775),h=c(99373),i=c(73461),j=c(1020),k=c(26349),l=c(54365),m=c(16023),n=c(63747),o=c(24235),p=c(23938),q=c(261),r=c(66758),s=c(77243),t=c(26713),u=c(37527),v=c(22820),w=c(88216),x=c(47929),y=c(79551),z=c(71797),A=c(89125),B=c(86439),C=c(77068),D=c(27269),E=c(61287),F=c(81494),G=c(70722),H=c(70753),I=c(43954),J=c(17891),K={};for(let a in E)0>["default","__next_app__","routeModule","handler"].indexOf(a)&&(K[a]=()=>E[a]);c.d(b,K);let L={children:["",{children:["__PAGE__",{},{page:[()=>Promise.resolve().then(c.bind(c,99647)),"/home/runner/work/annovibe/annovibe/app/page.tsx"],metadata:{icon:[async a=>(await Promise.resolve().then(c.bind(c,86364))).default(a)],apple:[],openGraph:[],twitter:[],manifest:void 0}}]},{layout:[()=>Promise.resolve().then(c.bind(c,32056)),"/home/runner/work/annovibe/annovibe/app/layout.tsx"],"global-error":[()=>Promise.resolve().then(c.t.bind(c,95547,23)),"next/dist/client/components/builtin/global-error.js"],"not-found":[()=>Promise.resolve().then(c.t.bind(c,55091,23)),"next/dist/client/components/builtin/not-found.js"],forbidden:[()=>Promise.resolve().then(c.t.bind(c,45270,23)),"next/dist/client/components/builtin/forbidden.js"],unauthorized:[()=>Promise.resolve().then(c.t.bind(c,28193,23)),"next/dist/client/components/builtin/unauthorized.js"],metadata:{icon:[async a=>(await Promise.resolve().then(c.bind(c,86364))).default(a)],apple:[],openGraph:[],twitter:[],manifest:void 0}},[]]}.children,M={require:c,loadChunk:()=>Promise.resolve()},N=new d.AppPageRouteModule({definition:{kind:e.RouteKind.APP_PAGE,page:"/page",pathname:"/",bundlePath:"",filename:"",appPaths:[]},userland:{loaderTree:L},distDir:".next",relativeProjectDir:""});async function O(a,b,d){var K,P,Q,R,S;d.requestMeta&&(0,h.setRequestMeta)(a,d.requestMeta),N.isDev&&(0,h.addRequestMeta)(a,"devRequestTimingInternalsEnd",process.hrtime.bigint());let T=!!(0,h.getRequestMeta)(a,"minimalMode"),U="/page";"/index"===U&&(U="/");let V=await N.prepare(a,b,{srcPage:U,multiZoneDraftMode:!1});if(!V)return b.statusCode=400,b.end("Bad Request"),null==d.waitUntil||d.waitUntil.call(d,Promise.resolve()),null;let{buildId:W,query:X,params:Y,pageIsDynamic:Z,buildManifest:$,nextFontManifest:_,reactLoadableManifest:aa,serverActionsManifest:ab,clientReferenceManifest:ac,subresourceIntegrityManifest:ad,prerenderManifest:ae,isDraftMode:af,resolvedPathname:ag,revalidateOnlyGenerated:ah,routerServerContext:ai,nextConfig:aj,parsedUrl:ak,interceptionRoutePatterns:al,deploymentId:am,clientAssetToken:an}=V,ao=(0,q.normalizeAppPath)(U),{isOnDemandRevalidate:ap}=V,aq=aj.experimental.ppr&&!aj.cacheComponents&&(0,I.isInterceptionRouteAppPath)(ag)?null:N.match(ag,ae),ar=(null==aq?void 0:aq.route)??null,as=!!ae.routes[ag],at=a.headers["user-agent"]||"",au=(0,t.getBotType)(at),av=(0,p.isHtmlBotRequest)(a),aw=(0,h.getRequestMeta)(a,"isPrefetchRSCRequest")??"1"===a.headers[s.NEXT_ROUTER_PREFETCH_HEADER],ax=(0,h.getRequestMeta)(a,"isRSCRequest")??!!a.headers[s.RSC_HEADER],ay=(0,r.getIsPossibleServerAction)(a),az=(0,m.checkIsAppPPREnabled)(aj.experimental.ppr),aA=a.headers[x.NEXT_RESUME_STATE_LENGTH_HEADER];if(!(0,h.getRequestMeta)(a,"postponed")&&T&&az&&ay&&aA&&"string"==typeof aA){let e=parseInt(aA,10),{maxPostponedStateSize:f,maxPostponedStateSizeBytes:g}=(0,D.getMaxPostponedStateSize)(aj.experimental.maxPostponedStateSize);if(!isNaN(e)&&e>0){if(e>g)return b.statusCode=413,b.end((0,D.getPostponedStateExceededErrorMessage)(f)),null==d.waitUntil||d.waitUntil.call(d,Promise.resolve()),null;let i="1 MB",j=(null==(S=aj.experimental.serverActions)?void 0:S.bodySizeLimit)??i,k=e+(j!==i?c(95726).parse(j):1048576),l=await (0,D.readBodyWithSizeLimit)(a,k);if(null===l)return b.statusCode=413,b.end("Request body exceeded limit. To configure the body size limit for Server Actions, see: https://nextjs.org/docs/app/api-reference/next-config-js/serverActions#bodysizelimit"),null==d.waitUntil||d.waitUntil.call(d,Promise.resolve()),null;if(l.length>=e){let b=l.subarray(0,e).toString("utf8");(0,h.addRequestMeta)(a,"postponed",b);let c=l.subarray(e);(0,h.addRequestMeta)(a,"actionBody",c)}else throw Object.defineProperty(Error(`invariant: expected ${e} bytes of postponed state but only received ${l.length} bytes`),"__NEXT_ERROR_CODE",{value:"E979",enumerable:!1,configurable:!0})}}if(!(0,h.getRequestMeta)(a,"postponed")&&az&&"1"===a.headers[x.NEXT_RESUME_HEADER]&&"POST"===a.method){let{maxPostponedStateSize:c,maxPostponedStateSizeBytes:e}=(0,D.getMaxPostponedStateSize)(aj.experimental.maxPostponedStateSize),f=await (0,D.readBodyWithSizeLimit)(a,e);if(null===f)return b.statusCode=413,b.end((0,D.getPostponedStateExceededErrorMessage)(c)),null==d.waitUntil||d.waitUntil.call(d,Promise.resolve()),null;let g=f.toString("utf8");(0,h.addRequestMeta)(a,"postponed",g)}let aB=!0===N.isDev||!0===aj.experimental.exposeTestingApiInProductionBuild,aC=aB&&("1"===a.headers[s.NEXT_INSTANT_PREFETCH_HEADER]||void 0===a.headers[s.RSC_HEADER]&&"string"==typeof a.headers.cookie&&a.headers.cookie.includes(s.NEXT_INSTANT_TEST_COOKIE+"=")),aD=(az||aC)&&((null==(K=ae.routes[ao]??ae.dynamicRoutes[ao])?void 0:K.renderingMode)==="PARTIALLY_STATIC"||aC&&(aB||(null==ai?void 0:ai.experimentalTestProxy)===!0)),aE=aC&&aD,aF=aE&&!0===N.isDev,aG=!1,aH=aD?(0,h.getRequestMeta)(a,"postponed"):void 0,aI=null==(P=ae.routes[ag])?void 0:P.prefetchDataRoute,aJ=aD&&ax&&!aw&&!aI;T&&(aJ=aJ&&!!aH);let aK=(0,h.getRequestMeta)(a,"segmentPrefetchRSCRequest"),aL=(!au||!aD)&&(!at||(0,p.shouldServeStreamingMetadata)(at,aj.htmlLimitedBots)),aM=!!((ar||as||ae.routes[ao])&&!(au&&aD)),aN=aD&&!0===aj.cacheComponents,aO=!0===N.isDev||!aM||"string"==typeof aH||(aN&&(0,h.getRequestMeta)(a,"onCacheEntryV2")?aJ&&!T:aJ),aP=!!au&&aD,aQ=(null==ar?void 0:ar.remainingPrerenderableParams)??[],aR=(null==ar?void 0:ar.fallback)===null&&((null==(Q=ar.fallbackRootParams)?void 0:Q.length)??0)>0,aS=null;if(!af&&aM&&!aO&&!ay&&!aH&&!aJ){let a=aq?"string"==typeof(null==ar?void 0:ar.fallback)?ar.fallback:aq.source:null;if(!0===aj.experimental.partialFallbacks&&a&&(null==ar?void 0:ar.fallbackRouteParams)&&!aR){if(aQ.length>0){let b,c=(b=new Map(aQ.map(a=>[a.paramName,a])),a.split("/").map(a=>{let c=(0,J.getSegmentParam)(a);if(!c)return a;let d=b.get(c.paramName);if(!d)return a;let e=null==Y?void 0:Y[d.paramName];if(!e)return a;let f=Array.isArray(e)?e.map(a=>encodeURIComponent(a)).join("/"):encodeURIComponent(e);return a.replace(function(a){let{repeat:b,optional:c}=(0,J.getParamProperties)(a.paramType);return c?`[[...${a.paramName}]]`:b?`[...${a.paramName}]`:`[${a.paramName}]`}(d),f)}).join("/")||"/");aS=c!==a?c:null}}else aS=ag}let aT=aS;!aT&&(N.isDev||aM&&Z&&(null==ar?void 0:ar.fallbackRouteParams)&&!ay)&&(aT=ag),N.isDev||af||!aM||!ax||aJ||(0,k.d)(a.headers);let aU={...E,tree:L,handler:O,routeModule:N,__next_app__:M};ab&&ac&&(0,o.setManifestsSingleton)({page:U,clientReferenceManifest:ac,serverActionsManifest:ab});let aV=a.method||"GET",aW=(0,g.getTracer)(),aX=aW.getActiveScopeSpan(),aY=!!(null==ai?void 0:ai.isWrappedByNextServer),aZ=!0===aj.experimental.partialFallbacks&&aQ.length>0?(null==ar||null==(R=ar.fallbackRouteParams)?void 0:R.filter(a=>!aQ.some(b=>b.paramName===a.paramName)))??[]:[],a$=async()=>((null==ai?void 0:ai.render404)?await ai.render404(a,b,ak,!1):b.end("This page could not be found"),null);try{let f,k=N.getVaryHeader(ag,al);b.setHeader("Vary",k);let m=async(c,d)=>{let e=new l.NodeNextRequest(a),g=new l.NodeNextResponse(b);return N.render(e,g,d).finally(()=>{if(!c)return;c.setAttributes({"http.status_code":b.statusCode,"next.rsc":!1});let a=aW.getRootSpanAttributes();if(!a)return;if(a.get("next.span_type")!==i.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${a.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let d=a.get("next.route");if(d){let a=`${aV} ${d}`;c.setAttributes({"next.route":d,"http.route":d,"next.span_name":a}),c.updateName(a),f&&f!==c&&(f.setAttribute("http.route",d),f.updateName(a))}else c.updateName(`${aV} ${U}`)})},o=(0,h.getRequestMeta)(a,"incrementalCache")||await N.getIncrementalCache(a,aj,ae,T);null==o||o.resetRequestCache(),globalThis.__incrementalCache=o;let p=async({span:e,postponed:f,fallbackRouteParams:g,forceStaticRender:i})=>{let k={query:X,params:Y,page:ao,sharedContext:{buildId:W,deploymentId:am,clientAssetToken:an},serverComponentsHmrCache:(0,h.getRequestMeta)(a,"serverComponentsHmrCache"),fallbackRouteParams:g,renderOpts:{App:()=>null,Document:()=>null,pageConfig:{},ComponentMod:aU,Component:(0,j.T)(aU),params:Y,routeModule:N,page:U,postponed:f,shouldWaitOnAllReady:aP,serveStreamingMetadata:aL,supportsDynamicResponse:"string"==typeof f||aO,buildManifest:$,nextFontManifest:_,reactLoadableManifest:aa,subresourceIntegrityManifest:ad,setCacheStatus:null==ai?void 0:ai.setCacheStatus,setIsrStatus:null==ai?void 0:ai.setIsrStatus,setReactDebugChannel:null==ai?void 0:ai.setReactDebugChannel,sendErrorsToBrowser:null==ai?void 0:ai.sendErrorsToBrowser,dir:c(33873).join(process.cwd(),N.relativeProjectDir),isDraftMode:af,botType:au,isOnDemandRevalidate:ap,isPossibleServerAction:ay,assetPrefix:aj.assetPrefix,nextConfigOutput:aj.output,crossOrigin:aj.crossOrigin,trailingSlash:aj.trailingSlash,images:aj.images,previewProps:ae.preview,enableTainting:aj.experimental.taint,htmlLimitedBots:aj.htmlLimitedBots,reactMaxHeadersLength:aj.reactMaxHeadersLength,multiZoneDraftMode:!1,incrementalCache:o,cacheLifeProfiles:aj.cacheLife,basePath:aj.basePath,serverActions:aj.experimental.serverActions,logServerFunctions:"object"==typeof aj.logging&&!!aj.logging.serverFunctions,...aE||aF||aG?{isBuildTimePrerendering:!0,supportsDynamicResponse:!1,isStaticGeneration:!0,isDebugDynamicAccesses:aF}:{},cacheComponents:!!aj.cacheComponents,experimental:{isRoutePPREnabled:aD,expireTime:aj.expireTime,staleTimes:aj.experimental.staleTimes,dynamicOnHover:!!aj.experimental.dynamicOnHover,optimisticRouting:!!aj.experimental.optimisticRouting,inlineCss:!!aj.experimental.inlineCss,prefetchInlining:aj.experimental.prefetchInlining??!1,authInterrupts:!!aj.experimental.authInterrupts,cachedNavigations:!!aj.experimental.cachedNavigations,clientTraceMetadata:aj.experimental.clientTraceMetadata||[],clientParamParsingOrigins:aj.experimental.clientParamParsingOrigins,maxPostponedStateSizeBytes:(0,C.parseMaxPostponedStateSize)(aj.experimental.maxPostponedStateSize)},waitUntil:d.waitUntil,onClose:a=>{b.on("close",a)},onAfterTaskError:()=>{},onInstrumentationRequestError:(b,c,d,e)=>N.onRequestError(a,b,d,e,ai),err:(0,h.getRequestMeta)(a,"invokeError")}};i&&(k.renderOpts.supportsDynamicResponse=!1);let l=await m(e,k),{metadata:n}=l,{cacheControl:p,headers:q={},fetchTags:r,fetchMetrics:s}=n;if(r&&(q[x.NEXT_CACHE_TAGS_HEADER]=r),a.fetchMetrics=s,aM&&(null==p?void 0:p.revalidate)===0&&!N.isDev&&!aD){let a=n.staticBailoutInfo,b=Object.defineProperty(Error(`Page changed from static to dynamic at runtime ${ag}${(null==a?void 0:a.description)?`, reason: ${a.description}`:""}
2
+ see more here https://nextjs.org/docs/messages/app-static-to-dynamic-error`),"__NEXT_ERROR_CODE",{value:"E132",enumerable:!1,configurable:!0});if(null==a?void 0:a.stack){let c=a.stack;b.stack=b.message+c.substring(c.indexOf("\n"))}throw b}return{value:{kind:u.CachedRouteKind.APP_PAGE,html:l,headers:q,rscData:n.flightData,postponed:n.postponed,status:n.statusCode,segmentData:n.segmentData},cacheControl:p}},q=async({hasResolved:c,previousCacheEntry:f,isRevalidating:g,span:i,forceStaticRender:j=!1})=>{let k,l=!1===N.isDev,m=c||b.writableEnded;if(ap&&ah&&!f&&!T)return(null==ai?void 0:ai.render404)?await ai.render404(a,b):(b.statusCode=404,b.end("This page could not be found")),null;if(ar&&(k=(0,v.parseFallbackField)(ar.fallback)),!0===aj.experimental.partialFallbacks&&(null==ar?void 0:ar.fallback)===null&&!aR&&aQ.length>0&&(k=v.FallbackMode.PRERENDER),k===v.FallbackMode.PRERENDER&&(0,t.isBot)(at)&&(!aD||av)&&(k=v.FallbackMode.BLOCKING_STATIC_RENDER),(null==f?void 0:f.isStale)===-1&&(ap=!0),ap&&(k!==v.FallbackMode.NOT_FOUND||f)&&(k=v.FallbackMode.BLOCKING_STATIC_RENDER),!T&&k!==v.FallbackMode.BLOCKING_STATIC_RENDER&&aT&&!m&&!af&&Z&&(l||!as)){if((l||ar)&&k===v.FallbackMode.NOT_FOUND){if(aj.adapterPath)return await a$();throw new B.NoFallbackError}if(aD&&(aj.cacheComponents?!aJ:!ax)){let b=l&&"string"==typeof(null==ar?void 0:ar.fallback)?ar.fallback:ao,f=(l||aE)&&(null==ar?void 0:ar.fallbackRouteParams)?(0,n.createOpaqueFallbackRouteParams)(ar.fallbackRouteParams):aG?(0,n.getFallbackRouteParams)(ao,N):null;aE&&f&&(0,h.addRequestMeta)(a,"fallbackParams",f);let g=await N.handleResponse({cacheKey:b,req:a,nextConfig:aj,routeKind:e.RouteKind.APP_PAGE,isFallback:!0,prerenderManifest:ae,isRoutePPREnabled:aD,responseGenerator:async()=>p({span:i,postponed:void 0,fallbackRouteParams:f,forceStaticRender:!0}),waitUntil:d.waitUntil,isMinimalMode:T});if(null===g)return null;if(g)return T||!aD||!(aQ.length>0)||!0!==aj.experimental.partialFallbacks||!aS||!o||ap||aG||aB||aC||aw||(0,H.scheduleOnNextTick)(async()=>{let b=N.getResponseCache(a);try{await b.revalidate(aS,o,aD,!1,a=>p({span:a.span,postponed:void 0,fallbackRouteParams:aZ.length>0?(0,n.createOpaqueFallbackRouteParams)(aZ):null,forceStaticRender:!0}),null,c,d.waitUntil)}catch(a){console.error("Error revalidating the page in the background",a)}}),delete g.cacheControl,g}}let r=ap||g||!aH?void 0:aH;if(aN&&!T&&o&&(aJ||ay)&&!j){let b=await o.get(ag,{kind:u.IncrementalCacheKind.APP_PAGE,isRoutePPREnabled:!0,isFallback:!1});b&&b.value&&b.value.kind===u.CachedRouteKind.APP_PAGE&&(r=b.value.postponed,b&&(-1===b.isStale||!0===b.isStale)&&(0,H.scheduleOnNextTick)(async()=>{let b=N.getResponseCache(a);try{await b.revalidate(ag,o,aD,!1,a=>q({...a,forceStaticRender:!0}),null,c,d.waitUntil)}catch(a){console.error("Error revalidating the page in the background",a)}}))}if((aE||aF)&&void 0!==r)return{cacheControl:{revalidate:1,expire:void 0},value:{kind:u.CachedRouteKind.PAGES,html:w.default.EMPTY,pageData:{},headers:void 0,status:void 0}};let s=(l&&(0,h.getRequestMeta)(a,"renderFallbackShell")||aE&&!as)&&(null==ar?void 0:ar.fallbackRouteParams)?(0,n.createOpaqueFallbackRouteParams)(ar.fallbackRouteParams):aG?(0,n.getFallbackRouteParams)(ao,N):null;if((l||aE)&&aj.cacheComponents&&!as&&(null==ar?void 0:ar.fallbackRouteParams)){let b=(0,n.createOpaqueFallbackRouteParams)(ar.fallbackRouteParams);b&&(0,h.addRequestMeta)(a,"fallbackParams",b)}return p({span:i,postponed:r,fallbackRouteParams:s,forceStaticRender:j})},r=async c=>{var f,g,i,j,k;let l,m=await N.handleResponse({cacheKey:aS,responseGenerator:a=>q({span:c,...a}),routeKind:e.RouteKind.APP_PAGE,isOnDemandRevalidate:ap,isRoutePPREnabled:aD,req:a,nextConfig:aj,prerenderManifest:ae,waitUntil:d.waitUntil,isMinimalMode:T});if(af&&b.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate"),N.isDev&&b.setHeader("Cache-Control","no-cache, must-revalidate"),!m){if(aS)throw Object.defineProperty(Error("invariant: cache entry required but not generated"),"__NEXT_ERROR_CODE",{value:"E62",enumerable:!1,configurable:!0});return null}if((null==(f=m.value)?void 0:f.kind)!==u.CachedRouteKind.APP_PAGE)throw Object.defineProperty(Error(`Invariant app-page handler received invalid cache entry ${null==(i=m.value)?void 0:i.kind}`),"__NEXT_ERROR_CODE",{value:"E707",enumerable:!1,configurable:!0});let n="string"==typeof m.value.postponed;ax&&!ay&&am&&b.setHeader(x.NEXT_NAV_DEPLOYMENT_ID_HEADER,am),aM&&!aJ&&(!n||aw)&&(T||b.setHeader("x-nextjs-cache",ap?"REVALIDATED":m.isMiss?"MISS":m.isStale?"STALE":"HIT"),b.setHeader(s.NEXT_IS_PRERENDER_HEADER,"1"));let{value:o}=m;if(aH)l={revalidate:0,expire:void 0};else if(aJ)l={revalidate:0,expire:void 0};else if(!N.isDev)if(af)l={revalidate:0,expire:void 0};else if(aM){if(m.cacheControl)if("number"==typeof m.cacheControl.revalidate){if(m.cacheControl.revalidate<1)throw Object.defineProperty(Error(`Invalid revalidate configuration provided: ${m.cacheControl.revalidate} < 1`),"__NEXT_ERROR_CODE",{value:"E22",enumerable:!1,configurable:!0});l={revalidate:m.cacheControl.revalidate,expire:(null==(j=m.cacheControl)?void 0:j.expire)??aj.expireTime}}else l={revalidate:x.CACHE_ONE_YEAR_SECONDS,expire:void 0}}else b.getHeader("Cache-Control")||(l={revalidate:0,expire:void 0});if(m.cacheControl=l,"string"==typeof aK&&(null==o?void 0:o.kind)===u.CachedRouteKind.APP_PAGE&&o.segmentData){b.setHeader(s.NEXT_DID_POSTPONE_HEADER,"2");let c=null==(k=o.headers)?void 0:k[x.NEXT_CACHE_TAGS_HEADER];T&&aM&&c&&"string"==typeof c&&b.setHeader(x.NEXT_CACHE_TAGS_HEADER,c);let d=o.segmentData.get(aK);return void 0!==d?(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:w.default.fromStatic(d,s.RSC_CONTENT_TYPE_HEADER),cacheControl:m.cacheControl}):(b.statusCode=204,(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:w.default.EMPTY,cacheControl:m.cacheControl}))}let r=aN?(0,h.getRequestMeta)(a,"onCacheEntryV2")??(0,h.getRequestMeta)(a,"onCacheEntry"):(0,h.getRequestMeta)(a,"onCacheEntry");if(r&&await r(m,{url:(0,h.getRequestMeta)(a,"initURL")??a.url}))return null;if(o.headers){let a={...o.headers};for(let[c,d]of(T&&aM||delete a[x.NEXT_CACHE_TAGS_HEADER],Object.entries(a)))if(void 0!==d)if(Array.isArray(d))for(let a of d)b.appendHeader(c,a);else"number"==typeof d&&(d=d.toString()),b.appendHeader(c,d)}let t=null==(g=o.headers)?void 0:g[x.NEXT_CACHE_TAGS_HEADER];if(T&&aM&&t&&"string"==typeof t&&b.setHeader(x.NEXT_CACHE_TAGS_HEADER,t),!o.status||ax&&aD||(b.statusCode=o.status),!T&&o.status&&F.RedirectStatusCode[o.status]&&ax&&(b.statusCode=200),n&&!aJ&&b.setHeader(s.NEXT_DID_POSTPONE_HEADER,"1"),ax&&!af){if(void 0===o.rscData){if(o.html.contentType!==s.RSC_CONTENT_TYPE_HEADER)if(aj.cacheComponents)return b.statusCode=404,(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:w.default.EMPTY,cacheControl:m.cacheControl});else throw Object.defineProperty(new G.InvariantError(`Expected RSC response, got ${o.html.contentType}`),"__NEXT_ERROR_CODE",{value:"E789",enumerable:!1,configurable:!0});return(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:o.html,cacheControl:m.cacheControl})}return(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:w.default.fromStatic(o.rscData,s.RSC_CONTENT_TYPE_HEADER),cacheControl:m.cacheControl})}let v=o.html;if(aC&&aE){let c=!0===N.isDev?crypto.randomUUID():null;return v.pipeThrough((0,z.createInstantTestScriptInsertionTransformStream)(c)),(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:v,cacheControl:{revalidate:0,expire:void 0}})}if(!n||T||ax)return(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:v,cacheControl:m.cacheControl});if(aE||aF)return v.push(new ReadableStream({start(a){a.enqueue(y.ENCODED_TAGS.CLOSED.BODY_AND_HTML),a.close()}})),(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:v,cacheControl:{revalidate:0,expire:void 0}});let B=new TransformStream;return v.push(B.readable),p({span:c,postponed:o.postponed,fallbackRouteParams:null,forceStaticRender:!1}).then(async a=>{var b,c;if(!a)throw Object.defineProperty(Error("Invariant: expected a result to be returned"),"__NEXT_ERROR_CODE",{value:"E463",enumerable:!1,configurable:!0});if((null==(b=a.value)?void 0:b.kind)!==u.CachedRouteKind.APP_PAGE)throw Object.defineProperty(Error(`Invariant: expected a page response, got ${null==(c=a.value)?void 0:c.kind}`),"__NEXT_ERROR_CODE",{value:"E305",enumerable:!1,configurable:!0});await a.value.html.pipeTo(B.writable)}).catch(a=>{B.writable.abort(a).catch(a=>{console.error("couldn't abort transformer",a)})}),(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:v,cacheControl:{revalidate:0,expire:void 0}})};if(!aY||!aX)return f=aW.getActiveScopeSpan(),await aW.withPropagatedContext(a.headers,()=>aW.trace(i.BaseServerSpan.handleRequest,{spanName:`${aV} ${U}`,kind:g.SpanKind.SERVER,attributes:{"http.method":aV,"http.target":a.url}},r),void 0,!aY);await r(aX)}catch(b){throw b instanceof B.NoFallbackError||await N.onRequestError(a,b,{routerKind:"App Router",routePath:U,routeType:"render",revalidateReason:(0,f.c)({isStaticGeneration:aM,isOnDemandRevalidate:ap})},!1,ai),b}}},55998:(a,b,c)=>{"use strict";c.d(b,{AppShell:()=>dr});var d=c(48249),e=c(67484),f=c.n(e),g=c(19099);function h(a,b){let c=b&&a.startsWith(b)?"~"+a.slice(b.length):a,d=c.includes("/")?"/":"\\",e=c.split(d).filter(Boolean);return e.length<=2?c:"..."+d+e.slice(-2).join(d)}function i(a){let b=new Date(a);return Number.isNaN(b.getTime())?"":b.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function j({open:a,cwd:b,homeDir:c,onClose:f,onSelectSession:g}){let[k,l]=(0,e.useState)(""),[m,n]=(0,e.useState)("current"),[o,p]=(0,e.useState)([]),[q,r]=(0,e.useState)(!1),[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)(!1),w=(0,e.useRef)(null);if(!a)return null;let x=k.trim(),y=o.reduce((a,b)=>a+b.matches.length,0);return(0,d.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Search conversation history",style:{position:"fixed",inset:0,zIndex:500,display:"flex",alignItems:"flex-start",justifyContent:"center",padding:"8vh 16px 16px",background:"rgba(0,0,0,0.28)"},onMouseDown:a=>{a.target===a.currentTarget&&f()},children:(0,d.jsxs)("div",{style:{width:"min(760px, 100%)",maxHeight:"78vh",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 16px 48px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:8,padding:"0 10px"},children:[(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,d.jsx)("circle",{cx:"7",cy:"7",r:"4.5"}),(0,d.jsx)("path",{d:"M10.5 10.5 13.5 13.5"})]}),(0,d.jsx)("input",{ref:w,value:k,onChange:a=>l(a.target.value),placeholder:"Search conversation history...",style:{flex:1,minWidth:0,height:38,background:"transparent",border:"none",outline:"none",color:"var(--text)",fontSize:14}})]}),(0,d.jsx)("button",{type:"button",onClick:f,title:"Close",style:{width:34,height:34,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"none",border:"none",borderRadius:7,color:"var(--text-dim)",cursor:"pointer"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.background="none",a.currentTarget.style.color="var(--text-dim)"},children:(0,d.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,d.jsx)("path",{d:"M4 4 12 12"}),(0,d.jsx)("path",{d:"M12 4 4 12"})]})})]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:10},children:[(0,d.jsx)("div",{style:{display:"inline-flex",padding:2,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7},children:[{value:"current",label:"Current project",disabled:!b},{value:"all",label:"All history",disabled:!1}].map(a=>(0,d.jsx)("button",{type:"button",disabled:a.disabled,onClick:()=>n(a.value),style:{height:24,padding:"0 9px",background:m===a.value?"var(--bg-selected)":"transparent",border:"none",borderRadius:5,color:a.disabled?"var(--text-dim)":m===a.value?"var(--text)":"var(--text-muted)",cursor:a.disabled?"not-allowed":"pointer",fontSize:11,fontWeight:500},children:a.label},a.value))}),(0,d.jsx)("div",{style:{flex:1,minWidth:0,color:"var(--text-dim)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"current"===m&&b?h(b,c):"Searching every saved session"})]})]}),(0,d.jsxs)("div",{style:{flex:1,overflowY:"auto",minHeight:180},children:[x.length<2&&(0,d.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Type at least 2 characters to search saved conversations."}),x.length>=2&&q&&0===o.length&&(0,d.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"Searching..."}),s&&(0,d.jsx)("div",{style:{padding:18,color:"#ef4444",fontSize:13},children:s}),x.length>=2&&!q&&!s&&0===o.length&&(0,d.jsx)("div",{style:{padding:28,textAlign:"center",color:"var(--text-muted)",fontSize:13},children:"No matching conversations found."}),o.map(a=>(0,d.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,d.jsxs)("button",{type:"button",onClick:()=>{g(a.session),f()},style:{width:"100%",display:"flex",alignItems:"center",gap:10,padding:"10px 12px",background:"var(--bg-panel)",border:"none",borderBottom:"1px solid var(--border)",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,d.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:600},children:a.session.name||a.session.firstMessage||"(no messages)"}),(0,d.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:11},children:i(a.session.modified)})]}),(0,d.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h(a.session.cwd,c)})]}),a.matchCount>a.matches.length&&(0,d.jsxs)("span",{style:{flexShrink:0,color:"var(--text-muted)",fontSize:11},children:[a.matchCount," matches"]})]}),a.matches.map(b=>(0,d.jsxs)("button",{type:"button",onClick:()=>{g(a.session),f()},style:{width:"100%",padding:"9px 14px 9px 28px",background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",textAlign:"left"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="none"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3},children:[(0,d.jsx)("span",{style:{minWidth:54,color:"user"===b.role?"var(--accent)":"var(--text-dim)",fontSize:11,fontWeight:600,textTransform:"capitalize"},children:b.role}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:i(b.timestamp)})]}),(0,d.jsx)("div",{style:{fontSize:12,lineHeight:1.45,color:"var(--text-muted)"},children:function(a,b){let c=b.trim();if(!c)return a;let e=a.toLowerCase().indexOf(c.toLowerCase());return e<0?a:(0,d.jsxs)(d.Fragment,{children:[a.slice(0,e),(0,d.jsx)("mark",{style:{background:"rgba(37,99,235,0.16)",color:"var(--text)",borderRadius:3,padding:"0 2px"},children:a.slice(e,e+c.length)}),a.slice(e+c.length)]})}(b.snippet,x)})]},b.entryId))]},a.session.id))]}),(0,d.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,d.jsx)("span",{children:y>0?`${y}${u?"+":""} results`:"Esc to close"}),q&&o.length>0&&(0,d.jsx)("span",{children:"Updating..."})]})]})})}function k({open:a,initialPath:b,onClose:c,onSelect:f}){let[g,h]=(0,e.useState)(""),[i,j]=(0,e.useState)(null),[l,m]=(0,e.useState)([]),[n,o]=(0,e.useState)([]),[p,q]=(0,e.useState)(""),[r,s]=(0,e.useState)(!1),[t,u]=(0,e.useState)(null),v=(0,e.useCallback)(async a=>{s(!0),u(null);try{let b=a?`/api/projects/browse?dir=${encodeURIComponent(a)}`:"/api/projects/browse",c=await fetch(b),d=await c.json();if(!c.ok||d.error)throw Error(d.error??`HTTP ${c.status}`);h(d.current??""),j(d.parent??null),m(d.directories??[]),o(d.drives??[]),q(d.current??"")}catch(a){u(a instanceof Error?a.message:String(a))}finally{s(!1)}},[]);return a?(0,d.jsx)("div",{onMouseDown:a=>{a.target===a.currentTarget&&c()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.34)"},children:(0,d.jsxs)("div",{style:{width:"min(560px, 100%)",maxHeight:"min(720px, 88dvh)",display:"flex",flexDirection:"column",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,boxShadow:"0 12px 40px rgba(0,0,0,0.25)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{height:48,padding:"0 14px",display:"flex",alignItems:"center",justifyContent:"space-between",borderBottom:"1px solid var(--border)"},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Select project path"}),(0,d.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:11},children:"Server filesystem"})]}),(0,d.jsx)("button",{type:"button",onClick:c,"aria-label":"Close",title:"Close",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.background="transparent",a.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,d.jsx)("div",{style:{padding:12,borderBottom:"1px solid var(--border)"},children:(0,d.jsxs)("form",{onSubmit:a=>{a.preventDefault();let b=p.trim();b&&f(b)},style:{display:"flex",gap:8},children:[(0,d.jsx)("input",{value:p,onChange:a=>q(a.target.value),placeholder:"/path/to/project",style:{flex:1,minWidth:0,height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:12,outline:"none"}}),(0,d.jsx)("button",{type:"button",onClick:()=>{let a=p.trim();a&&v(a)},disabled:!p.trim()||r,style:{height:32,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:p.trim()&&!r?"var(--text-muted)":"var(--text-dim)",cursor:p.trim()&&!r?"pointer":"default",fontSize:12},children:"Browse"}),(0,d.jsx)("button",{type:"submit",disabled:!p.trim(),style:{height:32,padding:"0 11px",border:"none",borderRadius:6,background:p.trim()?"var(--accent)":"var(--bg-hover)",color:p.trim()?"#fff":"var(--text-dim)",cursor:p.trim()?"pointer":"default",fontSize:12,fontWeight:650},children:"Use Path"})]})}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,d.jsx)("button",{type:"button",onClick:()=>i&&void v(i),disabled:!i,style:{width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:i?"var(--bg)":"transparent",color:i?"var(--text-muted)":"var(--text-dim)",cursor:i?"pointer":"default",padding:0},title:"Up",children:(0,d.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("polyline",{points:"2 6.5 5 3.5 8 6.5"})})}),n.length>0&&(0,d.jsxs)("select",{value:n.find(a=>g.toLowerCase().startsWith(a.toLowerCase()))??"",onChange:a=>{a.target.value&&v(a.target.value)},style:{height:28,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",fontSize:12},children:[(0,d.jsx)("option",{value:"",children:"Drive"}),n.map(a=>(0,d.jsx)("option",{value:a,children:a},a))]}),(0,d.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:g,children:g})]}),(0,d.jsx)("div",{style:{flex:1,minHeight:220,maxHeight:360,overflowY:"auto",padding:6},children:r?(0,d.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):t?(0,d.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12},children:t}):0===l.length?(0,d.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):l.map(a=>(0,d.jsxs)("button",{type:"button",onClick:()=>void v(a.path),style:{width:"100%",display:"flex",alignItems:"center",gap:9,padding:"8px 9px",border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:12},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.background="transparent",a.currentTarget.style.color="var(--text-muted)"},title:a.path,children:[(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--accent)",flexShrink:0},children:(0,d.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}),(0,d.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name}),(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:(0,d.jsx)("polyline",{points:"3.5 2 6.5 5 3.5 8"})})]},a.path))}),(0,d.jsxs)("div",{style:{padding:12,borderTop:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,d.jsx)("div",{style:{minWidth:0,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:g,children:g}),(0,d.jsxs)("div",{style:{display:"flex",gap:7,flexShrink:0},children:[(0,d.jsx)("button",{type:"button",onClick:c,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}),(0,d.jsx)("button",{type:"button",onClick:()=>g&&f(g),disabled:!g,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:g?"var(--accent)":"var(--bg-hover)",color:g?"#fff":"var(--text-dim)",cursor:g?"pointer":"default",fontSize:12,fontWeight:650},children:"Select"})]})]})]})}):null}let l="AnnoVibe";function m(a){}async function n(a,b){let c=`${a}: HTTP ${b.status}`;try{let d=await b.json();return"string"==typeof d.error&&d.error?`${a}: ${d.error}`:c}catch{return c}}function o(a){return new DOMException(a,"TimeoutError")}function p(a,b){return a instanceof DOMException&&("AbortError"===a.name||"TimeoutError"===a.name)||a instanceof Error&&/aborted without reason|AbortError/i.test(a.message)?b:a instanceof Error?a.message:String(a)}function q(a){let b=new Date(a),c=new Date().getTime()-b.getTime(),d=Math.floor(c/6e4),e=Math.floor(c/36e5),f=Math.floor(c/864e5);return d<1?"just now":d<60?`${d}m ago`:e<24?`${e}h ago`:f<7?`${f}d ago`:b.toLocaleDateString()}function r(a,b){let c=b&&a.startsWith(b)?"~"+a.slice(b.length):a,d=c.includes("/")?"/":"\\",e=c.split(d).filter(Boolean);return e.length<=2?c:"…/"+e.slice(-2).join(d)}function s(a,b){if(!a)return"No Project";let c=a.replace(/[\\/]+$/,""),d=c.includes("/")?"/":"\\";return c.split(d).filter(Boolean).pop()||r(a,b)}function t(){let[a,b]=(0,e.useState)(!1),[c,f]=(0,e.useState)(!1),g=(0,e.useRef)(null),h=function(a){let[b,c]=(0,e.useState)(a);return(0,e.useRef)(null),(0,e.useRef)(0),b}(a?"v0.8.119":l),i=(0,e.useCallback)(a=>{b(a),f(!0),setTimeout(()=>f(!1),(a?6:8)*4*(1e3/60)+100)},[]),j=(0,e.useCallback)(()=>{g.current&&clearTimeout(g.current);let b=!a;i(b),b&&(g.current=setTimeout(()=>i(!1),3e3))},[a,i]);return(0,d.jsx)("button",{onClick:j,style:{background:"none",border:"none",padding:0,cursor:"default",fontWeight:700,fontSize:15,letterSpacing:"-0.01em",color:a?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",minWidth:"9ch"},children:h})}function u({selectedSessionId:a,onSelectSession:b,onNewSession:c,onNewWorkbench:f,initialSessionId:g,onInitialRestoreDone:h,refreshKey:i,onSessionDeleted:l,selectedCwd:q,onCwdChange:A}){let[B,C]=(0,e.useState)([]),[D,E]=(0,e.useState)({}),[F,G]=(0,e.useState)(()=>new Set),H=(0,e.useRef)(!1),[I,J]=(0,e.useState)(!0),[K,L]=(0,e.useState)(!1),[M,N]=(0,e.useState)(null),[O,P]=(0,e.useState)(null),[Q,R]=(0,e.useState)(""),[S,T]=(0,e.useState)(null),[U,V]=(0,e.useState)(!1),[W,X]=(0,e.useState)("project"),[Y,Z]=(0,e.useState)(null),[$,_]=(0,e.useState)(!1),[aa,ab]=(0,e.useState)(!1),[ac,ad]=(0,e.useState)(()=>new Set),[ae,af]=(0,e.useState)(()=>new Set),[ag,ah]=(0,e.useState)(null),[ai,aj]=(0,e.useState)(null),[ak,al]=(0,e.useState)(null),[am,an]=(0,e.useState)(!1),ao=(0,e.useRef)(null),ap=(0,e.useRef)(!1),aq=(0,e.useRef)(!1);(0,e.useRef)(!1);let ar=(0,e.useRef)(new Map),as=(0,e.useCallback)(async(a=!1)=>{try{let b;a&&J(!0);let c=new AbortController;try{b=setTimeout(()=>c.abort(o("Project loading timed out")),6e4);let a=await fetch("/api/projects?sessions=false",{signal:c.signal});if(!a.ok)throw Error(await n("projects",a));let d=await a.json();C(d.projects),N(null)}finally{clearTimeout(b)}}catch(a){N(p(a,"Loading projects timed out. Codex may still be starting; click Refresh to retry."))}finally{a&&J(!1)}},[]),at=(0,e.useCallback)(async(a,b=!1)=>{if(!a)return;let c=ar.current.get(a);if(c)return c;let d=(async()=>{E(b=>({...b,[a]:{sessions:b[a]?.sessions??[],loaded:b[a]?.loaded??!1,error:null,loading:!0,stale:b[a]?.stale??!1}}));try{let c;b&&J(!0);let d=new AbortController;try{c=setTimeout(()=>d.abort(o("Chat loading timed out")),6e4);let b=await fetch(`/api/sessions?cwd=${encodeURIComponent(a)}`,{signal:d.signal});if(!b.ok)throw Error(await n("sessions",b));let e=await b.json();e.runningSessionIds&&!H.current&&G(new Set(e.runningSessionIds)),E(b=>({...b,[a]:{sessions:e.sessions,loaded:!0,loading:!1,error:null,stale:!1}}))}finally{clearTimeout(c)}}catch(c){let b=p(c,"Loading chats timed out. Codex may still be starting; click Refresh to retry.");E(c=>({...c,[a]:{sessions:c[a]?.sessions??[],loaded:c[a]?.loaded??!1,loading:!1,error:b,stale:(c[a]?.sessions?.length??0)>0}}))}finally{b&&J(!1),ar.current.delete(a)}})();return ar.current.set(a,d),d},[]);(0,e.useRef)(!1),(0,e.useRef)(!1);let au=(0,e.useCallback)(async(a,b=!1)=>{try{let c=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,create:b})}),d=await c.json();if(!c.ok||d.error)return T(d.error??`HTTP ${c.status}`),!1;return as(!1),!0}catch(a){return T(a instanceof Error?a.message:String(a)),!1}},[as]),av=(0,e.useCallback)(a=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,touch:!0})}).catch(()=>{})},[]),aw=(0,e.useCallback)(a=>{aq.current=!0,P(a),T(null),af(b=>{if(!b.has(a))return b;let c=new Set(b);return c.delete(a),m(c),c}),A?.(a),av(a),at(a,!1)},[at,A,av]),ax=q??O,ay=(0,e.useCallback)(a=>{if(!a){X("agent"),V(!0);return}let b="function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;c?.(b,a)},[c]),az=(0,e.useCallback)(a=>{if(!a){X("workbench"),V(!0);return}f?.(a)},[f]),aA=(0,e.useCallback)(async a=>{await au(a,!0)&&(aw(a),V(!1),T(null),"agent"===W&&ay(a),"workbench"===W&&az(a))},[aw,ay,az,W,au]),aB=(0,e.useCallback)(a=>{Z(a),_(!0)},[]),aC=(0,e.useCallback)(()=>{_(!1),Z(null)},[]),aD=(0,e.useCallback)(a=>{let b=Y??ax;aC(),"agent"===a?ay(b):az(b)},[aC,ay,az,ax,Y]),aE=(0,e.useCallback)(()=>{aB(ax)},[ax,aB]),aF=(0,e.useCallback)(()=>{X("project"),T(null),V(!0)},[]),aG=(0,e.useMemo)(()=>[...ax&&!B.some(a=>a.cwd===ax)?[{cwd:ax,displayName:s(ax,Q),chatCount:D[ax]?.sessions.length??0,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...B].sort((a,b)=>{let c=!0===a.pinned;if(c!==(!0===b.pinned))return c?-1:1;let d="number"==typeof a.sortOrder?a.sortOrder:Number.MAX_SAFE_INTEGER,e="number"==typeof b.sortOrder?b.sortOrder:Number.MAX_SAFE_INTEGER;return d!==e?d-e:(a.displayName||"").localeCompare(b.displayName||"",void 0,{numeric:!0,sensitivity:"base"})}),[ax,Q,B,D]),aH=(0,e.useMemo)(()=>{let a=a=>{let b=D[a.cwd],c=[...b?.sessions??[]].sort((a,b)=>(b.modified||"").localeCompare(a.modified||""));return{project:a,cwd:a.cwd,displayName:a.displayName||s(a.cwd,Q),sessions:c,sessionsState:b,lastAccessed:(a.lastAccessed??a.created??"")||c[0]?.modified||""}},b=aG.filter(a=>!0===a.pinned).map(a);if(ax){let c=aG.find(a=>a.cwd===ax);c&&!0!==c.pinned&&b.push(a(c))}return b},[ax,Q,D,aG]),aI=(0,e.useCallback)((a,c=!1)=>{a.cwd!==ax&&(ap.current=!0,P(a.cwd)),af(b=>{if(!b.has(a.cwd))return b;let c=new Set(b);return c.delete(a.cwd),m(c),c}),av(a.cwd),b(a,c)},[b,ax,av]),aJ=(0,e.useCallback)(a=>{af(b=>{let c=new Set(b);return c.has(a)?c.delete(a):c.add(a),m(c),c})},[]),aK=(0,e.useCallback)(a=>{ad(b=>{let c=new Set(b);return c.has(a)?c.delete(a):c.add(a),c})},[]),aL=(0,e.useCallback)(async a=>{al("reorder");try{let b=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:a})}),c=await b.json();if(!b.ok||c.error)throw Error(c.error??`HTTP ${b.status}`);C(c.projects??[]),N(null)}catch(a){N(a instanceof Error?a.message:String(a)),as(!1)}finally{al(null)}},[as]),aM=(0,e.useCallback)(async(a,b)=>{al(`pin:${a}`);try{let c=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,pinned:b})}),d=await c.json();if(!c.ok||d.error)throw Error(d.error??`HTTP ${c.status}`);C(d.projects??[]),N(null)}catch(a){N(a instanceof Error?a.message:String(a)),as(!1)}finally{al(null)}},[as]),aN=(0,e.useCallback)((a,b)=>{if(!a||!b||a===b)return;let c=aG.map(a=>a.cwd).filter(Boolean),d=c.indexOf(a),e=c.indexOf(b);if(-1===d||-1===e)return;let f=[...c];f.splice(d,1);let g=f.indexOf(b);f.splice(g,0,a),aL(f)},[aL,aG]),aO=(0,e.useCallback)(async()=>{L(!0);try{await as(!1);let a=new Set([...Object.entries(D).filter(([,a])=>a.loaded||a.loading).map(([a])=>a),...ax?[ax]:[]]);await Promise.all([...a].map(a=>at(a,!1)))}finally{L(!1)}},[ax,as,at,D]);return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,d.jsx)("div",{style:{padding:"12px 10px 10px",borderBottom:"1px solid var(--border)",flexShrink:0},children:(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,d.jsx)(t,{}),(0,d.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,d.jsxs)("button",{onClick:aE,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",height:32,paddingLeft:10,paddingRight:12,borderRadius:7,fontSize:12,fontWeight:500,letterSpacing:"-0.01em",flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:ax?`New chat in ${ax}`:"New chat in a project path",onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-selected)",a.currentTarget.style.color="var(--accent)",a.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text-muted)",a.currentTarget.style.borderColor="var(--border)"},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[(0,d.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,d.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"New Chat"]}),(0,d.jsx)("button",{onClick:()=>ab(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",width:32,height:32,borderRadius:7,padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s, border-color 0.12s"},title:"Search conversations",onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-selected)",a.currentTarget.style.color="var(--accent)",a.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text-muted)",a.currentTarget.style.borderColor="var(--border)"},children:(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"7",cy:"7",r:"4.4"}),(0,d.jsx)("path",{d:"M10.4 10.4 13.2 13.2"})]})})]})]})}),(0,d.jsx)(j,{open:aa,cwd:ax,homeDir:Q,onClose:()=>ab(!1),onSelectSession:a=>{aI(a)}}),(0,d.jsxs)("div",{ref:ao,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,d.jsxs)("button",{type:"button",onClick:()=>an(a=>!a),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:ax?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:ax?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:ax??"Select project",children:[(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--accent)"},children:(0,d.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,d.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11,color:ax?"var(--text)":"var(--text-dim)"},children:ax?aG.find(a=>a.cwd===ax)?.displayName??r(ax,Q):"Select project…"}),(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:am?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,d.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),ax&&(0,d.jsx)(w,{pinned:aG.find(a=>a.cwd===ax)?.pinned===!0,onToggle:()=>void aM(ax,aG.find(a=>a.cwd===ax)?.pinned!==!0)}),am&&(0,d.jsxs)("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:10,right:10,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 6px 20px rgba(0,0,0,0.10)",overflow:"hidden",maxHeight:280,overflowY:"auto"},children:[0===aG.length&&(0,d.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),aG.map(a=>{let b=a.cwd===ax;return(0,d.jsx)(x,{project:a,homeDir:Q,isCurrent:b,onSelect:()=>{aw(a.cwd),an(!1)},onTogglePinned:()=>void aM(a.cwd,!0!==a.pinned)},a.cwd)}),(0,d.jsxs)("button",{type:"button",onClick:()=>{an(!1),aF()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:aG.length>0?"1px solid var(--border)":"none",color:"var(--accent)",cursor:"pointer",textAlign:"left",fontSize:11},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("line",{x1:"6",y1:"1",x2:"6",y2:"11"}),(0,d.jsx)("line",{x1:"1",y1:"6",x2:"11",y2:"6"})]}),"Add project…"]})]})]}),(0,d.jsxs)("div",{style:{flexShrink:0,padding:"10px 10px 6px"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase"},children:"Projects"}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:"auto"},children:[(0,d.jsx)("button",{type:"button",onClick:aO,disabled:K,title:"Refresh projects and chats","aria-label":"Refresh projects and chats",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:K?"var(--accent)":"var(--text-dim)",cursor:K?"default":"pointer",flexShrink:0},children:(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:K?"spin 0.9s linear infinite":void 0},children:[(0,d.jsx)("path",{d:"M21 12a9 9 0 0 1-15.5 6.2"}),(0,d.jsx)("path",{d:"M3 12A9 9 0 0 1 18.5 5.8"}),(0,d.jsx)("path",{d:"M7 18H5.5v1.5"}),(0,d.jsx)("path",{d:"M17 6h1.5V4.5"})]})}),(0,d.jsxs)("button",{type:"button",onClick:aF,title:"New project","aria-label":"New project",style:{height:26,display:"flex",alignItems:"center",justifyContent:"center",gap:5,padding:"0 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-hover)",color:"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,transition:"background 0.12s, color 0.12s, border-color 0.12s",flexShrink:0},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-selected)",a.currentTarget.style.color="var(--accent)",a.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text-muted)",a.currentTarget.style.borderColor="var(--border)"},children:[(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v4.5A1.5 1.5 0 0 1 13 12H3a1.5 1.5 0 0 1-1.5-1.5v-6Z"}),(0,d.jsx)("path",{d:"M11 7v3M9.5 8.5h3"})]}),"New Project"]})]})]}),S&&(0,d.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:S})]}),(0,d.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[I&&0===B.length&&(0,d.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading…"}),M&&(0,d.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:M}),!I&&!M&&0===aH.length&&(0,d.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!I&&!M&&aH.map(b=>{let c,e=ae.has(b.cwd),f=b.cwd===ax,g=ac.has(b.cwd),h=function(a){let b=new Map;for(let c of a)b.set(c.id,{session:c,children:[]});let c=new Map;for(let b of a)b.parentSessionId&&c.set(b.id,b.parentSessionId);let d=[];for(let a of b.values()){let e=function(a){let d=c.get(a),e=new Set;for(;d&&!e.has(d);){if(e.add(d),b.has(d))return d;d=c.get(d)}return null}(a.session.id);e?b.get(e).children.push(a):d.push(a)}let e=a=>{a.sort((a,b)=>(b.session.modified||"").localeCompare(a.session.modified||"")),a.forEach(a=>e(a.children))};return e(d),d}(b.sessions),i=h.length,j=h;if(i>10&&!g){j=h.slice(0,10);let b=h.find(b=>(function a(b,c){return!!c&&(b.session.id===c||b.children.some(b=>a(b,c)))})(b,a));b&&!j.includes(b)&&(j=[...j,b])}let k=i-j.length;return(0,d.jsxs)("div",{style:{marginBottom:6,borderTop:ai===b.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(ai===b.cwd),opacity:ag===b.cwd?.55:1},onDragOver:a=>{ag&&ag!==b.cwd&&(a.preventDefault(),a.dataTransfer.dropEffect="move",aj(b.cwd))},onDragLeave:()=>{ai===b.cwd&&aj(null)},onDrop:a=>{a.preventDefault();let c=a.dataTransfer.getData("text/project-cwd")||ag;aj(null),ah(null),c&&aN(c,b.cwd)},children:[(0,d.jsx)(y,{group:b,isCurrent:f,isCollapsed:e,isDragging:ag===b.cwd,pinBusy:ak===`pin:${b.cwd}`,onToggle:()=>aJ(b.cwd),onSelect:()=>aw(b.cwd),onTogglePinned:()=>void aM(b.cwd,!0!==b.project.pinned),onDragStart:a=>{ah(b.cwd),a.dataTransfer.effectAllowed="move",a.dataTransfer.setData("text/project-cwd",b.cwd)},onDragEnd:()=>{ah(null),aj(null)}}),!e&&(0,d.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[(c=b.sessionsState,c?.loading&&!c?.loaded?(0,d.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:12,fontStyle:"italic"},children:"Loading chats…"}):c?.error&&!c?.stale?(0,d.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"#f87171",textAlign:"left",fontSize:12},children:c.error}):0===b.sessions.length?(0,d.jsx)("div",{style:{width:"100%",padding:"10px 12px",color:"var(--text-muted)",textAlign:"left",fontSize:12},children:"No sessions yet. Use New Chat above to start one."}):(0,d.jsxs)(d.Fragment,{children:[c?.stale&&(0,d.jsx)("div",{style:{width:"100%",padding:"4px 12px",color:"var(--text-dim)",textAlign:"left",fontSize:10,fontStyle:"italic"},children:"Showing cached data — refresh failed"}),j.map(c=>(0,d.jsx)(z,{node:c,selectedSessionId:a,onSelectSession:aI,onRenamed:()=>void at(b.cwd,!1),onSessionDeleted:a=>{l?.(a),at(b.cwd,!1)},depth:0,runningSessionIds:F},c.session.id))]})),(g||k>0)&&i>10&&(0,d.jsx)("button",{type:"button",onClick:()=>aK(b.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:g?"Show less":`Show ${Math.max(0,k)} more`})]})]},b.cwd||"__no_project")})]}),$&&(0,d.jsx)(v,{cwd:Y,onChoose:aD,onClose:aC}),(0,d.jsx)(k,{open:U,initialPath:ax,onClose:()=>V(!1),onSelect:a=>aA(a)})]})}function v({cwd:a,onChoose:b,onClose:c}){let e=a?s(a):"Choose a project path next";return(0,d.jsx)("div",{onMouseDown:a=>{a.target===a.currentTarget&&c()},style:{position:"fixed",inset:0,zIndex:1200,display:"flex",alignItems:"center",justifyContent:"center",padding:18,background:"rgba(0,0,0,0.28)"},children:(0,d.jsxs)("div",{style:{width:"min(420px, 100%)",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 12px 40px rgba(0,0,0,0.24)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:"14px 16px 12px",borderBottom:"1px solid var(--border)",display:"flex",justifyContent:"space-between",gap:12},children:[(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:750},children:"Start a new session"}),(0,d.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11},children:"Current project"}),(0,d.jsx)("div",{title:a??void 0,style:{marginTop:2,color:"var(--text)",fontSize:12,fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e}),a&&(0,d.jsx)("div",{style:{marginTop:2,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a})]}),(0,d.jsx)("button",{type:"button",onClick:c,"aria-label":"Close",title:"Close",style:{width:28,height:28,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},children:"x"})]}),(0,d.jsxs)("div",{style:{padding:14,display:"grid",gap:10},children:[(0,d.jsxs)("button",{type:"button",onClick:()=>b("agent"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer"},children:[(0,d.jsx)("span",{style:{fontSize:13,fontWeight:750},children:"Agent Chat"}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"General coding or analysis chat in this project."})]}),(0,d.jsxs)("button",{type:"button",onClick:()=>b("workbench"),style:{display:"grid",gap:5,textAlign:"left",padding:"13px 14px",border:"1px solid rgba(37,99,235,0.45)",borderRadius:10,background:"rgba(37,99,235,0.08)",color:"var(--text)",cursor:"pointer"},children:[(0,d.jsx)("span",{style:{fontSize:13,fontWeight:750,color:"var(--accent)"},children:"Workbench"}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.45},children:"Dedicated R/Python warm-runtime session for data loading, plots, and artifacts."})]})]})]})})}function w({pinned:a,onToggle:b}){return(0,d.jsx)("button",{type:"button",onClick:b,title:a?"Unpin project":"Pin project to sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:"auto",padding:0,border:"1px solid var(--border)",borderRadius:7,background:a?"rgba(234,179,8,0.12)":"var(--bg-hover)",color:a?"#ca8a04":"var(--text-muted)",cursor:"pointer",flexShrink:0},children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:a?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 17v5"}),(0,d.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})}function x({project:a,homeDir:b,isCurrent:c,onSelect:f,onTogglePinned:g}){let[h,i]=(0,e.useState)(!1),j=a.displayName||s(a.cwd,b);return(0,d.jsxs)("div",{onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),style:{display:"flex",alignItems:"center",gap:4,background:c?"var(--bg-selected)":h?"var(--bg-hover)":"none",borderBottom:"1px solid var(--border)"},children:[(0,d.jsx)("span",{style:{width:10,marginLeft:6,flexShrink:0}}),(0,d.jsxs)("button",{type:"button",onClick:f,title:a.cwd,style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:7,padding:"8px 10px 8px 0",background:"none",border:"none",color:c?"var(--text)":"var(--text-muted)",cursor:"pointer",textAlign:"left",fontSize:11,fontFamily:"var(--font-mono)"},children:[c?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,d.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),(0,d.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:j}),!a.exists&&(0,d.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"})]}),(0,d.jsx)("button",{type:"button",onClick:a=>{a.stopPropagation(),g()},title:"Pin to sidebar",tabIndex:h?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,marginRight:4,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,opacity:+!!h,pointerEvents:h?"auto":"none"},children:(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 17v5"}),(0,d.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})})]})}function y({group:a,isCurrent:b,isCollapsed:c,isDragging:f,pinBusy:g,onToggle:h,onSelect:i,onTogglePinned:j,onDragStart:k,onDragEnd:l}){let[m,n]=(0,e.useState)(!1),o=a.lastAccessed,p=Math.max(0,a.project.chatCount??a.sessions.length??0),r=!0===a.project.pinned,s=(0,e.useCallback)(()=>{b?h():i()},[b,i,h]);return(0,d.jsxs)("div",{role:"button",tabIndex:0,draggable:!0,onClick:s,onDragStart:k,onDragEnd:l,onKeyDown:a=>{("Enter"===a.key||" "===a.key)&&(a.preventDefault(),s())},onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),title:a.cwd,style:{width:"100%",height:32,display:"flex",alignItems:"center",gap:5,padding:"0 8px",background:b?"var(--bg-selected)":m?"var(--bg-hover)":"transparent",border:"none",borderRadius:6,color:"var(--text)",cursor:f?"grabbing":"pointer",textAlign:"left",overflow:"hidden",transition:"background 0.12s, opacity 0.12s",opacity:f?.55:1},children:[(0,d.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:c?"none":"rotate(90deg)",transition:"transform 0.15s",flexShrink:0,color:"var(--text-dim)"},children:(0,d.jsx)("polyline",{points:"3 2 7 5 3 8"})}),(0,d.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:b?"var(--accent)":"var(--text-dim)"},children:c?(0,d.jsx)("path",{d:"M1.5 4.5A1.5 1.5 0 0 1 3 3h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6v5A1.5 1.5 0 0 1 13 12.5H3A1.5 1.5 0 0 1 1.5 11V4.5Z"}):(0,d.jsx)("path",{d:"M1.5 5A1.5 1.5 0 0 1 3 3.5h3l1.2 1.5H13A1.5 1.5 0 0 1 14.5 6.5L13.6 11A1.5 1.5 0 0 1 12.1 12.5H3A1.5 1.5 0 0 1 1.5 11V5Z"})}),(0,d.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:13,fontWeight:b?650:560,color:"var(--text)"},children:a.displayName}),!a.project.exists&&(0,d.jsx)("span",{style:{flexShrink:0,color:"#f87171",fontSize:10},children:"missing"}),!m&&p>0&&(0,d.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[p," ",1===p?"chat":"chats"]}),!m&&o&&(0,d.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:q(o)}),r?(0,d.jsx)("button",{type:"button",onClick:a=>{a.stopPropagation(),j()},title:"Unpin project",tabIndex:m?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"rgba(234,179,8,0.12)",color:"#ca8a04",cursor:"pointer",flexShrink:0,opacity:m?1:.85,transition:"opacity 0.12s"},children:(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 17v5"}),(0,d.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}):(0,d.jsx)("button",{type:"button",onClick:a=>{a.stopPropagation(),j()},disabled:g,title:"Pin project to sidebar",tabIndex:m?0:-1,style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:g?"wait":"pointer",flexShrink:0,opacity:+!!m,transition:"opacity 0.12s, background 0.12s, color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="#ca8a04"},onMouseLeave:a=>{a.currentTarget.style.background="transparent",a.currentTarget.style.color="var(--text-muted)"},children:(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 17v5"}),(0,d.jsx)("path",{d:"M5 3h14l-4 7v4l-6 3v-7L5 3Z"})]})}),(0,d.jsx)("span",{title:"Drag to reorder",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:22,flexShrink:0,color:"var(--text-dim)",opacity:m?1:.35,transition:"opacity 0.12s",cursor:"grab"},children:(0,d.jsxs)("svg",{width:"10",height:"12",viewBox:"0 0 10 12",fill:"currentColor",children:[(0,d.jsx)("circle",{cx:"2",cy:"2",r:"1"}),(0,d.jsx)("circle",{cx:"8",cy:"2",r:"1"}),(0,d.jsx)("circle",{cx:"2",cy:"6",r:"1"}),(0,d.jsx)("circle",{cx:"8",cy:"6",r:"1"}),(0,d.jsx)("circle",{cx:"2",cy:"10",r:"1"}),(0,d.jsx)("circle",{cx:"8",cy:"10",r:"1"})]})})]})}function z({node:a,selectedSessionId:b,onSelectSession:c,onRenamed:f,onSessionDeleted:g,depth:h,runningSessionIds:i}){let[j,k]=(0,e.useState)(!1),l=a.children.length>0;return(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{style:{position:"relative"},children:[h>0&&(0,d.jsx)("div",{style:{position:"absolute",left:12*h+6,top:0,bottom:0,width:1,background:"var(--border)",pointerEvents:"none"}}),(0,d.jsx)(A,{session:a.session,isSelected:a.session.id===b,onClick:()=>c(a.session),onRenamed:f,onDeleted:a=>g?.(a),depth:h,hasChildren:l,collapsed:j,onToggleCollapse:()=>k(a=>!a),isRunning:i.has(a.session.id)})]}),l&&!j&&(0,d.jsx)("div",{children:a.children.map(a=>(0,d.jsx)(z,{node:a,selectedSessionId:b,onSelectSession:c,onRenamed:f,onSessionDeleted:g,depth:h+1,runningSessionIds:i},a.session.id))})]})}function A({session:a,isSelected:b,onClick:c,onRenamed:f,onDeleted:g,depth:h=0,hasChildren:i=!1,collapsed:j=!1,onToggleCollapse:k,isRunning:l=!1}){let[m,n]=(0,e.useState)(!1),[o,p]=(0,e.useState)(!1),[r,s]=(0,e.useState)(""),[t,u]=(0,e.useState)(!1),[v,w]=(0,e.useState)(!1),x=(0,e.useRef)(null),y=a.name||a.firstMessage.slice(0,50)||a.id.slice(0,12),z=(0,e.useCallback)(b=>{b.stopPropagation(),s(a.name??""),p(!0),setTimeout(()=>x.current?.select(),0)},[a.name]),B=(0,e.useCallback)(async()=>{let b=r.trim();if(p(!1),b!==(a.name??""))try{await fetch(`/api/sessions/${encodeURIComponent(a.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:b})}),f?.()}catch{}},[r,a.id,a.name,f]),C=(0,e.useCallback)(a=>{a.stopPropagation(),u(!0)},[]),D=(0,e.useCallback)(async b=>{b.stopPropagation(),u(!1),w(!0);try{await fetch(`/api/sessions/${encodeURIComponent(a.id)}`,{method:"DELETE"}),g?.(a.id)}catch{w(!1)}},[a.id,g]),E=(0,e.useCallback)(a=>{a.stopPropagation(),u(!1)},[]),F="workbench"===a.sessionKind;return(0,d.jsx)("div",{onClick:t||o?void 0:c,onMouseEnter:()=>n(!0),onMouseLeave:()=>{n(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:h>0?12*h+14:14,paddingRight:8,cursor:t||o?"default":"pointer",background:t?"rgba(239,68,68,0.06)":b?"var(--bg-selected)":m?"var(--bg-hover)":"transparent",borderLeft:t?"2px solid #ef4444":b?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:v?.5:1,gap:6,overflow:"hidden"},children:t?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{style:{flex:1,minWidth:0,fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["Delete ",(0,d.jsxs)("span",{style:{fontWeight:600},children:["“",y.slice(0,22),y.length>22?"…":"","”"]}),"?"]}),(0,d.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,d.jsxs)("button",{onClick:D,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,height:30,padding:"0 11px",background:"#ef4444",border:"none",borderRadius:6,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,d.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,d.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,d.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]}),"Delete"]}),(0,d.jsx)("button",{onClick:E,style:{display:"flex",alignItems:"center",justifyContent:"center",height:30,padding:"0 11px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:500,whiteSpace:"nowrap"},children:"Cancel"})]})]}):o?(0,d.jsx)("input",{ref:x,value:r,onChange:a=>s(a.target.value),onBlur:B,onKeyDown:a=>{"Enter"===a.key&&B(),"Escape"===a.key&&p(!1)},autoFocus:!0,style:{flex:1,fontSize:12,padding:"5px 8px",border:"1px solid var(--accent)",borderRadius:5,outline:"none",background:"var(--bg)",color:"var(--text)",height:28}}):(0,d.jsxs)(d.Fragment,{children:[h>0&&(0,d.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,d.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,d.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,d.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),0===h&&(0,d.jsx)("span",{"aria-hidden":"true",style:{width:l?7:5,height:l?7:5,borderRadius:"50%",background:l?"#22c55e":b?"var(--accent)":"var(--text-dim)",opacity:b?1:.35,flexShrink:0,...l?{boxShadow:"0 0 6px rgba(34,197,94,0.5)",animation:"pulse 2s infinite"}:{}}}),F&&(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M4 19V5"}),(0,d.jsx)("path",{d:"M4 19h16"}),(0,d.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,d.jsxs)("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:1},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:b?600:500,lineHeight:"18px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:F?"var(--accent)":"var(--text)"},title:y,children:y}),(0,d.jsxs)("div",{style:{display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,d.jsx)("span",{title:a.modified,children:q(a.modified)}),(0,d.jsxs)("span",{children:[a.messageCount," msgs"]}),!1===a.cwdExists&&(0,d.jsx)("span",{title:`Project path missing: ${a.cwd}`,style:{color:"#f87171"},children:"missing path"})]})]}),i&&(0,d.jsx)("button",{onClick:a=>{a.stopPropagation(),k?.()},title:j?"Expand forks":"Collapse forks",style:{display:"flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",transform:j?"rotate(-90deg)":"none",transition:"transform 0.15s"},children:(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})}),m&&(0,d.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:[(0,d.jsx)("button",{onClick:z,title:"Rename",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-selected)",a.currentTarget.style.color="var(--accent)",a.currentTarget.style.borderColor="rgba(37,99,235,0.35)"},onMouseLeave:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text-muted)",a.currentTarget.style.borderColor="var(--border)"},children:(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})})}),(0,d.jsx)("button",{onClick:C,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="rgba(239,68,68,0.08)",a.currentTarget.style.color="#ef4444",a.currentTarget.style.borderColor="rgba(239,68,68,0.35)"},onMouseLeave:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text-muted)",a.currentTarget.style.borderColor="var(--border)"},children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,d.jsx)("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),(0,d.jsx)("path",{d:"M10 11v6M14 11v6"}),(0,d.jsx)("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})]})]})})}var B=c(62418),C=c(29947);let D=new Map,E=["off","default","full","agent"],F={off:"none",default:"default",full:"full",agent:"agent"},G={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},H={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},I=["auto","off","minimal","low","medium","high","xhigh"],J={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},K=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function L({doc:a,onRemove:b}){var c;let e=a.fileName.split(".").pop()?.toLowerCase()??"",f=function(a){switch(a){case"pdf":return{emoji:"\uD83D\uDCC4",color:"#ef4444"};case"docx":case"doc":return{emoji:"\uD83D\uDCDD",color:"#3b82f6"};case"xlsx":case"xls":return{emoji:"\uD83D\uDCCA",color:"#22c55e"};case"pptx":case"ppt":return{emoji:"\uD83D\uDCFD",color:"#f97316"};default:return{emoji:"\uD83D\uDCCE",color:"var(--text-muted)"}}}(e),g=(c=a.size)<1024?`${c} B`:c<1048576?`${(c/1024).toFixed(1)} KB`:`${(c/1048576).toFixed(1)} MB`;return(0,d.jsxs)("div",{style:{position:"relative",display:"flex",alignItems:"center",gap:6,padding:"5px 10px 5px 7px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,maxWidth:200},title:a.fileName,children:[(0,d.jsx)("span",{style:{color:f.color,fontSize:14,flexShrink:0},children:f.emoji}),(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",lineHeight:1.3},children:a.fileName}),(0,d.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.3},children:[e.toUpperCase()," \xb7 ",g,a.extractionError?" \xb7 no text":a.truncated?" \xb7 truncated":a.extractedText?" \xb7 text":""]})]}),(0,d.jsx)("button",{onClick:b,style:{flexShrink:0,width:14,height:14,borderRadius:"50%",background:"var(--bg-hover)",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-dim)"},onMouseEnter:a=>{a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.color="var(--text-dim)"},children:(0,d.jsxs)("svg",{width:"7",height:"7",viewBox:"0 0 7 7",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,d.jsx)("line",{x1:"1",y1:"1",x2:"6",y2:"6"}),(0,d.jsx)("line",{x1:"6",y1:"1",x2:"1",y2:"6"})]})})]})}function M(a){return a.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&apos;/g,"'")}async function N(a){let b=await c.e(1688).then(c.bind(c,81688));b.GlobalWorkerOptions.workerSrc=new c.U(c(19224)).toString();let d=await b.getDocument({data:a.slice(0)}).promise,e=[];for(let a=1;a<=d.numPages;a+=1){let b=await d.getPage(a),c=(await b.getTextContent()).items.map(a=>"str"in a?a.str:"").filter(Boolean).join(" ");c.trim()&&e.push(`Page ${a}
3
+ ${c}`)}return e.join("\n\n")}async function O(a){let b=(await c.e(7890).then(c.t.bind(c,55509,23))).default,d=await b.loadAsync(a),e=["word/document.xml",...Object.keys(d.files).filter(a=>/^word\/(footnotes|endnotes|comments)\.xml$/i.test(a)).sort()],f=[];for(let a of e){let b=d.file(a);if(!b)continue;let c=[...(await b.async("string")).replace(/<w:(br|cr)[^>]*\/>/g,"\n").replace(/<\/w:p>/g,"\n").matchAll(/<w:t[^>]*>([\s\S]*?)<\/w:t>/g)];f.push(...c.map(a=>M(a[1])))}return f.join("").replace(/[ \t]+\n/g,"\n")}async function P(a){let b=await c.e(7765).then(c.bind(c,77765)),d=b.read(a,{type:"array"});return d.SheetNames.map(a=>{let c=d.Sheets[a],e=b.utils.sheet_to_csv(c);return`Sheet: ${a}
4
+ ${e}`}).join("\n\n")}async function Q(a){let b=(await c.e(7890).then(c.t.bind(c,55509,23))).default,d=await b.loadAsync(a),e=Object.keys(d.files).map(a=>({name:a,match:/^ppt\/slides\/slide(\d+)\.xml$/i.exec(a)})).filter(a=>null!==a.match).sort((a,b)=>Number(a.match[1])-Number(b.match[1])),f=[];for(let{name:a,match:b}of e){let c=[...(await d.file(a).async("string")).matchAll(/<a:t[^>]*>([\s\S]*?)<\/a:t>/g)].map(a=>M(a[1]).trim()).filter(Boolean);c.length&&f.push(`Slide ${b[1]}
5
+ ${c.join("\n")}`)}return f.join("\n\n")}async function R(a,b){let c=a.name.split(".").pop()?.toLowerCase()??"";try{let d,e="";if(a.type.startsWith("text/")||["csv","tsv","md","txt","json","xml"].includes(c))e=new TextDecoder("utf-8").decode(b);else if("pdf"===c||"application/pdf"===a.type)e=await N(b);else if("docx"===c)e=await O(b);else if("xlsx"===c)e=await P(b);else{if("pptx"!==c)return{extractionError:"Text extraction is not supported for this file type"};e=await Q(b)}let{text:f,truncated:g}=(d=e.replace(/\r\n/g,"\n").replace(/\n{4,}/g,"\n\n\n").trim()).length<=6e4?{text:d,truncated:!1}:{text:`${d.slice(0,6e4)}
5
6
 
6
- [truncated after 60000 characters]`,truncated:!0};if(!f)return{extractionError:"No extractable text found"};return{extractedText:f,truncated:g}}catch(a){return{extractionError:a instanceof Error?a.message:String(a)}}}let _=(0,e.forwardRef)(function({onSend:a,onAbort:b,onSteer:c,onFollowUp:f,isStreaming:g,model:h,modelNames:i,modelList:j,onModelChange:k,onCompact:l,onAbortCompaction:m,isCompacting:n,compactError:o,toolPreset:p,sessionKind:q,onToolPresetChange:r,memoryTools:s,onMemoryToolsChange:t,thinkingLevel:u,onThinkingLevelChange:v,availableThinkingLevels:w,thinkingLevelMap:x,retryInfo:y,soundEnabled:z,onSoundToggle:A,planMode:B,onPlanModeChange:C,cornerBadge:E,promptHistory:F,sessionHistoryKey:G,activeFilePath:H,onDismissFileContext:I},J){let K,L,V,[W,X]=(0,e.useState)(""),[Y,Z]=(0,e.useState)(!1),[_,aa]=(0,e.useState)(null),[ab,ac]=(0,e.useState)(!1),[ad,ae]=(0,e.useState)(!1),[af,ag]=(0,e.useState)(!1),[ah,ai]=(0,e.useState)(!1),[aj,ak]=(0,e.useState)(!1),[al,am]=(0,e.useState)(null),[an,ao]=(0,e.useState)([]),[ap,aq]=(0,e.useState)([]),ar=function(a=768){let[b,c]=(0,e.useState)(!1);return b}(),as=ar?{display:"none"}:void 0,at=ar?28:32,au=ar?"6px 8px":"8px 12px",av=ar?160:180,aw=ar&&!g,ax=aj?"var(--text)":"var(--text-muted)",ay={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},az=ar?{position:"sticky",bottom:0,zIndex:30,padding:"8px 0 calc(env(safe-area-inset-bottom, 0px) + 8px)",background:"linear-gradient(to top, color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 86%, transparent))",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",borderTop:"1px solid color-mix(in srgb, var(--border) 65%, transparent)"}:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:52},[aA,aB]=(0,e.useState)(null),aC=(0,e.useRef)(null),aD=(0,e.useRef)(null),aE=(0,e.useRef)(null),aF=(0,e.useRef)(null),aG=(0,e.useRef)(null),aH=(0,e.useRef)(null),aI=(0,e.useRef)(null),aJ=(0,e.useRef)(null),aK=(0,e.useRef)(null),aL=(0,e.useRef)(null),aM=(0,e.useCallback)(a=>{let b=aC.current;if(!b)return void X(b=>b+(b?" ":"")+a);let c=b.selectionStart??b.value.length,d=b.selectionEnd??b.value.length,e=b.value.slice(0,c),f=b.value.slice(d),g=!(e.length>0)||e.endsWith(" ")||e.endsWith("\n")?"":" ";X(e+g+a+f),requestAnimationFrame(()=>{let b=aC.current;if(!b)return;let d=c+g.length+a.length;b.setSelectionRange(d,d),b.focus(),b.style.height="auto",b.style.height=`${Math.min(b.scrollHeight,200)}px`})},[]);(0,e.useImperativeHandle)(J,()=>({insertIfEmpty(a){let b=aC.current;(b?b.value:W).trim()||(X(a),requestAnimationFrame(()=>{b&&(b.focus(),b.style.height="auto",b.style.height=`${Math.min(b.scrollHeight,200)}px`)}))},insertText(a){aM(a)},addImages(a){aN(a)},addFiles(a){aO(a)}}));let aN=(0,e.useCallback)(async a=>{let b=a.filter(a=>a.type.startsWith("image/"));if(!b.length)return;let c=await Promise.all(b.map(a=>new Promise((b,c)=>{let d=new FileReader;d.onload=()=>{b({data:d.result.split(",")[1],mimeType:a.type,previewUrl:URL.createObjectURL(a)})},d.onerror=c,d.readAsDataURL(a)})));ao(a=>[...a,...c])},[]),aO=(0,e.useCallback)(async a=>{let b=a.filter(a=>a.type.startsWith("image/")),c=a.filter(a=>!a.type.startsWith("image/"));if(b.length&&aN(b),c.length){let a=await Promise.all(c.map(a=>new Promise((b,c)=>{let d=new FileReader;d.onload=async()=>{let c=d.result,e=await $(a,c);b({data:c,fileName:a.name,mimeType:a.type||"application/octet-stream",size:a.size,...e})},d.onerror=c,d.readAsArrayBuffer(a)})));aq(b=>[...b,...a])}},[aN]),aP=(0,e.useCallback)(a=>{ao(b=>{let c=[...b];return URL.revokeObjectURL(c[a].previewUrl),c.splice(a,1),c})},[]),aQ=(0,e.useCallback)(a=>{aq(b=>{let c=[...b];return c.splice(a,1),c})},[]),aR=(0,e.useCallback)(()=>{ao(a=>(a.forEach(a=>URL.revokeObjectURL(a.previewUrl)),[])),aq([])},[]),aS=j&&j.length>0?j.map(a=>({provider:a.provider,modelId:a.id,name:a.name,input:a.input})):Object.entries(i??{}).map(([a,b])=>({provider:h?.provider??"unknown",modelId:a,name:b})),aT=[];for(let a of aS){let b=aT.find(b=>b.provider===a.provider);b?b.options.push(a):aT.push({provider:a.provider,options:[a]})}let aU=h?aS.find(a=>a.modelId===h.modelId&&a.provider===h.provider)?.name??h.modelId:aS.length>0?aS[0].name:null,aV=h?aS.find(a=>a.modelId===h.modelId&&a.provider===h.provider):aS[0],aW=aV?.input?.includes("image")??!0,aX=an.length>0&&aV?.input!==void 0&&!aW,aY=(!!W.trim()||an.length>0||ap.length>0)&&!aX,aZ=l?T:T.filter(a=>"/compact"!==a.command),a$=aZ.filter(a=>"native"===a.kind),a_=aZ.filter(a=>"shortcut"===a.kind),a0=s??[],a1=a0.length>0?`${a0.length} enabled`:"off",a2=aS.length>0&&!!aU&&!!k,a3=!!v,a4=!!r&&"workbench"!==q,a5=!!t,a6=aU??"Default",a7=(()=>{let a=u??"auto";if("auto"===a||!x)return a;let b=x[a];return null!=b?b:a})(),a8=(p??"full")==="workbench"?"workbench":Object.entries(O).find(([,a])=>a===(p??"full"))?.[0]??"full",a9=ar?26:32,ba=ar?7:9,bb=ar?3:6,bc={position:"fixed",left:8,right:8,bottom:"calc(env(safe-area-inset-bottom, 0px) + 8px)",zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 -6px 24px rgba(0,0,0,0.14)",overflow:"hidden",maxHeight:"min(60dvh, 420px)"},bd=ar&&(Y||ab||ad||af||ah||aj);(0,e.useEffect)(()=>{aX||aB(null)},[aX]);let be=(0,e.useCallback)(a=>{if(!W.trim()){X(a),requestAnimationFrame(()=>{let b=aC.current;b&&(b.focus(),b.setSelectionRange(a.length,a.length),b.style.height="auto",b.style.height=`${Math.min(b.scrollHeight,200)}px`)});return}aM(a)},[aM,W]),bf=(0,e.useCallback)(()=>{let b=W.trim();if(b||an.length||ap.length){if(an.length&&!aW)return void aB("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!g){if("/compact"===b&&!an.length&&!ap.length&&l){n?m?.():l(),X(""),aC.current&&(aC.current.style.height="auto");return}a(b,an.length?an:void 0,ap.length?ap:void 0),X(""),aR(),aC.current&&(aC.current.style.height="auto")}}},[W,an,ap,aW,g,a,aR,l,m,n]),bg=(0,e.useCallback)(a=>{let b=W.trim();if(!b&&!an.length&&!ap.length)return;if(an.length&&!aW)return void aB("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let d=an.length?an:void 0,e=ap.length?ap:void 0;"steer"===a&&c?c(b,d,e):"followup"===a&&f&&f(b,d,e),X(""),aR(),aC.current&&(aC.current.style.height="auto")},[W,an,ap,aW,c,f,aR]),bh=F??[],bi=G??null,bj=(0,e.useCallback)(a=>{if("ArrowUp"===a.key&&!a.shiftKey&&!a.ctrlKey&&!a.metaKey&&bh.length>0){let b=aC.current;if(!b)return;let c=b.selectionStart??0;if(b.value.slice(0,c).includes("\n"))return;a.preventDefault();let d=function(a,b,c){let d;if(!a||0===c.length)return null;let e=((d=M.get(a))||(d={cursor:-1,draftSnapshot:""},M.set(a,d)),d);if(-1===e.cursor)e.draftSnapshot=b,e.cursor=0;else{if(!(e.cursor<c.length-1))return null;e.cursor+=1}return c[e.cursor]??null}(bi,b.value,bh);null!==d&&(X(d),requestAnimationFrame(()=>{b.setSelectionRange(d.length,d.length)}));return}if("ArrowDown"===a.key&&!a.shiftKey&&!a.ctrlKey&&!a.metaKey&&function(a){if(!a)return!1;let b=M.get(a);return(b?.cursor??-1)>=0}(bi)){a.preventDefault();let b=function(a,b){if(!a)return null;let c=M.get(a);if(!c||-1===c.cursor)return null;if(c.cursor>0)return c.cursor-=1,{text:b[c.cursor]??"",returnedToPresent:!1};let d=c.draftSnapshot;return c.cursor=-1,c.draftSnapshot="",{text:d,returnedToPresent:!0}}(bi,bh);b&&(X(b.text),b.returnedToPresent&&requestAnimationFrame(()=>{let a=aC.current;a&&a.setSelectionRange(b.text.length,b.text.length)}));return}"Enter"===a.key&&!a.shiftKey&&!a.nativeEvent.isComposing&&(a.preventDefault(),bi&&M.set(bi,{cursor:-1,draftSnapshot:""}),g&&(c||f)?bg(c?"steer":"followup"):bf())},[g,c,f,bg,bf,bh,bi]),bk=(0,e.useCallback)(()=>{let a=aC.current;a&&(a.style.height="auto",a.style.height=`${Math.min(a.scrollHeight,200)}px`)},[]),bl=(0,e.useCallback)(a=>{let b=Array.from(a.clipboardData?.items??[]).filter(a=>"file"===a.kind&&(a.type.startsWith("image/")||a.type.includes("pdf")||a.type.includes("officedocument")||a.type.includes("msword")||a.type.includes("ms-")));b.length&&(a.preventDefault(),aO(b.map(a=>a.getAsFile()).filter(a=>null!==a)))},[aO]);return(0,e.useEffect)(()=>{if(!Y&&!ab&&!ad&&!af&&!ah&&!aj)return;let a=a=>{let b=a.target;if(!(b instanceof Node))return;let c=!!aD.current?.contains(b),d=!!aE.current?.contains(b);c||d||Z(!1),aF.current?.contains(b)||ac(!1),aG.current?.contains(b)||ae(!1),aH.current?.contains(b)||ag(!1),aI.current?.contains(b)||ai(!1),aJ.current?.contains(b)||ak(!1)};return document.addEventListener("pointerdown",a,!0),()=>{document.removeEventListener("pointerdown",a,!0)}},[Y,ab,ad,af,ah,aj]),(0,e.useEffect)(()=>{if(!r)return;let a=!1;return fetch("/api/subagents/status").then(a=>a.ok?a.json():null).then(b=>{a||am(!!b?.ready)}).catch(()=>{a||am(!1)}),()=>{a=!0}},[r]),(0,d.jsxs)("div",{style:az,children:[bd&&(0,d.jsx)("div",{"aria-hidden":!0,onClick:()=>{Z(!1),ac(!1),ae(!1),ag(!1),ai(!1),ak(!1)},style:{position:"fixed",inset:0,zIndex:490,background:"rgba(15, 23, 42, 0.18)",backdropFilter:"blur(1.5px)",WebkitBackdropFilter:"blur(1.5px)"}}),(0,d.jsx)("input",{ref:aK,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:a=>{aN(Array.from(a.target.files??[])),a.target.value=""}}),(0,d.jsx)("input",{ref:aL,type:"file",accept:".pdf,.docx,.xlsx,.pptx,.doc,.xls,.ppt,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation",multiple:!0,style:{display:"none"},onChange:a=>{aO(Array.from(a.target.files??[])),a.target.value=""}}),(0,d.jsxs)("div",{style:{maxWidth:ar?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:ar?"0 8px":void 0,boxSizing:"border-box"},children:[E&&(0,d.jsx)("div",{style:{position:"absolute",right:8,top:-22,display:"flex",alignItems:"center",justifyContent:"flex-end",maxWidth:"min(320px, 60vw)",minHeight:18,zIndex:2,fontFamily:"var(--font-mono)",overflow:"hidden"},children:E}),y&&(0,d.jsxs)("div",{style:{marginBottom:ar?6:8,padding:ar?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:ar?11:12,color:"rgba(180,130,0,0.9)",display:"flex",alignItems:"center",gap:6},children:[(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,d.jsx)("path",{d:"M3 3v5h5"})]}),"Retrying (",y.attempt,"/",y.maxAttempts,")…",y.errorMessage&&(0,d.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",y.errorMessage]})]}),H&&(0,d.jsxs)("div",{style:{marginBottom:ar?6:8,padding:ar?"3px 8px":"4px 10px",background:"color-mix(in srgb, var(--accent) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--accent) 25%, transparent)",borderRadius:6,fontSize:ar?11:12,color:"var(--text-muted)",display:"inline-flex",alignItems:"center",gap:6,maxWidth:"100%"},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,d.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,d.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:H.replace(/^.*[\\/]/,"")}),I&&(0,d.jsx)("button",{type:"button",onClick:a=>{a.stopPropagation(),I()},title:"Stop including this file in context",style:{background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:14,lineHeight:1,padding:"0 2px",flexShrink:0},children:"\xd7"})]}),(an.length>0||ap.length>0)&&(0,d.jsxs)("div",{style:{marginBottom:6},children:[(0,d.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"flex-end"},children:[an.map((a,b)=>(0,d.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,d.jsx)("img",{src:a.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:`1px solid ${aX?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,d.jsx)("button",{onClick:()=>aP(b),style:{position:"absolute",top:-4,right:-4,width:16,height:16,borderRadius:"50%",background:"var(--bg-panel)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-muted)"},children:(0,d.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,d.jsx)("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),(0,d.jsx)("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})})]},`img-${b}`)),ap.map((a,b)=>(0,d.jsx)(U,{doc:a,onRemove:()=>aQ(b)},`doc-${b}`))]}),(aX||aA)&&(0,d.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:ar?11:12,color:"rgba(185,28,28,0.95)"},children:[(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),(0,d.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,d.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),(0,d.jsx)("span",{children:aA??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,d.jsxs)("div",{style:{display:"flex",gap:ar?4:8,alignItems:ar?"flex-end":"center",background:"var(--bg)",border:`1px solid ${g&&(c||f)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:ar?13:14,padding:ar?"8px 8px 8px 10px":"10px 10px 10px 14px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[(0,d.jsx)("textarea",{ref:aC,value:W,onChange:a=>X(a.target.value),onKeyDown:bj,onInput:bk,onPaste:bl,placeholder:g&&(c||f)?"Steer 立即注入 / Follow-up 排队…":g?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:ar?"stretch":void 0,background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:14,lineHeight:1.6,fontFamily:"inherit",minHeight:24,maxHeight:200,overflow:"auto",paddingTop:+!!ar,paddingBottom:+!!ar}}),g?(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:ar?4:6,flexShrink:0,alignSelf:"flex-end"},children:[c&&(0,d.jsxs)("button",{onClick:()=>bg("steer"),disabled:!aY,title:aX?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!ar,padding:ar?"6px 8px":"7px 12px",background:aY?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:aY?"rgba(180,130,0,1)":"var(--text-dim)",cursor:aY?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M5 1 L9 5 L5 9"}),(0,d.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),!ar&&"Steer"]}),f&&(0,d.jsxs)("button",{onClick:()=>bg("followup"),disabled:!aY,title:aX?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!ar,padding:ar?"6px 8px":"7px 12px",background:aY?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:aY?"rgba(99,102,241,1)":"var(--text-dim)",cursor:aY?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"6"}),(0,d.jsx)("polyline",{points:"2.5 3.5 5 1 7.5 3.5"}),(0,d.jsx)("line",{x1:"2",y1:"9",x2:"8",y2:"9"})]}),!ar&&"Follow-up"]})]}):(0,d.jsxs)("button",{onClick:bf,disabled:!aY,title:aX?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:ar?3:6,padding:ar?"5px 9px":"7px 14px",marginBottom:+!!ar,background:aY?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:aY?"#fff":"var(--text-dim)",cursor:aY?"pointer":"not-allowed",fontSize:ar?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:aY?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,d.jsxs)("svg",{width:ar?13:14,height:ar?13:14,viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("line",{x1:"2",y1:"7",x2:"11",y2:"7"}),(0,d.jsx)("polyline",{points:"7.5 3 12 7 7.5 11"})]}),"Send"]})]}),(0,d.jsxs)("div",{className:"chat-input-toolbar",style:{marginTop:ar?5:8,display:"flex",alignItems:ar?"flex-start":"center",gap:bb,flexWrap:ar?"wrap":"nowrap"},children:[(0,d.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:ar?"1 1 100%":"0 0 auto",width:ar?"100%":void 0,display:"flex",alignItems:"center",gap:2*!ar,flexWrap:ar?"wrap":"nowrap",rowGap:4*!!ar},children:[(0,d.jsx)("button",{onClick:()=>aK.current?.click(),disabled:g,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:a9,height:a9,padding:0,background:"none",border:"none",borderRadius:ba,color:an.length||ap.length?"var(--accent)":"var(--text-muted)",cursor:g?"not-allowed":"pointer",opacity:g?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{g||(a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color=an.length||ap.length?"var(--accent)":"var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background="none",a.currentTarget.style.color=an.length||ap.length?"var(--accent)":"var(--text-muted)"},onContextMenu:a=>{a.preventDefault(),aL.current?.click()},children:(0,d.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),(0,d.jsxs)("div",{ref:aF,style:{position:"relative"},children:[(0,d.jsxs)("button",{onClick:()=>{g||(ac(a=>!a),ae(!1),Z(!1),ag(!1),ai(!1),ak(!1))},disabled:g,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:a9,height:a9,padding:0,background:ab?"var(--bg-hover)":"none",border:"none",borderRadius:ba,color:o?"#ef4444":"var(--text-muted)",cursor:g?"not-allowed":"pointer",opacity:g?.5:1,fontSize:15,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{g||(a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color=o?"#ef4444":"var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background=ab?"var(--bg-hover)":"none",a.currentTarget.style.color=o?"#ef4444":"var(--text-muted)"},children:["/",o&&(0,d.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"#ef4444"}})]}),ab&&(0,d.jsxs)("div",{style:{...ar?bc:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:320,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,d.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:o?"1px solid var(--border)":"none"},children:"Commands"}),o&&(0,d.jsx)("div",{style:{padding:"7px 10px",fontSize:11,color:"#ef4444",background:"rgba(239,68,68,0.06)",borderBottom:"1px solid var(--border)",lineHeight:1.45},children:o}),a$.length>0&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Native"}),a$.map(a=>(0,d.jsxs)("button",{onClick:()=>{(ac(!1),"/compact"===a.command&&n)?m?.():be(a.command)},style:{display:"flex",alignItems:"center",gap:ar?6:8,width:"100%",padding:au,background:"none",border:"none",color:"/compact"===a.command&&n?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:ar?11:12,textAlign:"left"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="none"},children:[(0,d.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"/compact"===a.command&&n?"#ef4444":"var(--text-dim)"},children:"/compact"===a.command&&n?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,d.jsx)("rect",{x:"2",y:"2",width:"6",height:"6",rx:"1",fill:"currentColor"})}):(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,d.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,d.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,d.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]})}),(0,d.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,d.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:"/compact"===a.command&&n?"停止压缩":a.label}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"/compact"===a.command&&n?"中止当前压缩任务":a.description})]})]},a.command))]}),a_.length>0&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{style:{marginTop:2*(a$.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:a$.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),a_.map(a=>(0,d.jsxs)("button",{onClick:()=>{ac(!1),be(a.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:au,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:ar?11:12,textAlign:"left"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="none"},children:[(0,d.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:13},children:"/"}),(0,d.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,d.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:a.label}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:a.description})]})]},a.command))]})]})]}),t&&(0,d.jsxs)("div",{ref:aG,style:{position:"relative"},children:[(0,d.jsxs)("button",{onClick:()=>{g||(ae(a=>!a),ac(!1),Z(!1),ag(!1),ai(!1),ak(!1))},disabled:g,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:at,padding:0,background:ad?"var(--bg-hover)":"none",border:"none",borderRadius:ar?8:9,color:a0.length>0?"var(--accent)":"var(--text-muted)",cursor:g?"not-allowed":"pointer",opacity:g?.5:1,fontSize:13,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{g||(a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color=a0.length>0?"var(--accent)":"var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background=ad?"var(--bg-hover)":"none",a.currentTarget.style.color=a0.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),a0.length>0&&(0,d.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),ad&&(0,d.jsxs)("div",{style:{...ar?bc:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:280,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,d.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:"1px solid var(--border)"},children:"Memory Tools"}),D.map(a=>{let b=a0.includes(a),c=Q[a];return(0,d.jsxs)("button",{onClick:()=>{t(b?a0.filter(b=>b!==a):[...a0,a])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:au,background:b?"var(--bg-selected)":"none",border:"none",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ar?11:12,textAlign:"left"},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="none")},children:[b?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,d.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),(0,d.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,d.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:c.label}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:c.description})]})]},a)})]})]}),a2&&(0,d.jsxs)("div",{ref:aD,style:{position:"relative",flex:ar?"1 1 160px":void 0,minWidth:0},children:[(0,d.jsxs)("button",{onClick:a=>{if(!ar){let b=a.currentTarget.getBoundingClientRect();aa({top:b.top,left:b.left,width:b.width})}ac(!1),ae(!1),ag(!1),ai(!1),ak(!1),Z(a=>!a)},disabled:g,style:{display:"flex",alignItems:"center",gap:6,padding:au,height:at,width:ar?"100%":void 0,maxWidth:ar?"100%":220,overflow:"hidden",background:Y?"var(--bg-hover)":"none",border:"none",borderRadius:ar?8:9,color:"var(--text-muted)",cursor:g?"not-allowed":"pointer",fontSize:ar?11:12,opacity:g?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{g||(a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background=Y?"var(--bg-hover)":"none",a.currentTarget.style.color="var(--text-muted)"},children:[(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,d.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,d.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,d.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,d.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,d.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,d.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,d.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,d.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,d.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,d.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:aU})]}),Y&&(ar?(0,d.jsxs)("div",{ref:aE,style:{...bc,display:"flex",flexDirection:"column"},children:[(0,d.jsxs)("div",{style:{padding:"8px 12px 6px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,d.jsx)("div",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Models"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:aU})]}),(0,d.jsx)("div",{style:{overflowY:"auto"},children:aT.map((a,b)=>(0,d.jsxs)("div",{children:[aT.length>1&&(0,d.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:b>0?"1px solid var(--border)":"none"},children:a.provider}),a.options.map(a=>{let b=a.modelId===h?.modelId&&a.provider===h?.provider;return(0,d.jsxs)("button",{onClick:()=>{Z(!1),b||k(a.provider,a.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"10px 12px",background:b?"var(--bg-selected)":"none",border:"none",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:b?600:400},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="none")},children:[b?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,d.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),(0,d.jsx)("span",{style:{flex:1,minWidth:0,whiteSpace:"normal",lineHeight:1.35},children:a.name}),a.input?.includes("image")&&(0,d.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font-mono)",marginLeft:8},children:"image"})]},`${a.provider}:${a.modelId}`)})]},a.provider))})]}):_&&(L=(K=window.visualViewport?.height??window.innerHeight)-_.top+6,V=Math.max(120,Math.min(_.top-8,.6*K)),(0,d.jsx)("div",{ref:aE,style:{position:"fixed",bottom:L,left:_.left,zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",width:"max-content",minWidth:_.width,maxHeight:V,overflowY:"auto"},children:aT.map((a,b)=>(0,d.jsxs)("div",{children:[aT.length>1&&(0,d.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:b>0?"1px solid var(--border)":"none"},children:a.provider}),a.options.map(a=>{let b=a.modelId===h?.modelId&&a.provider===h?.provider;return(0,d.jsxs)("button",{onClick:()=>{Z(!1),b||k(a.provider,a.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:b?"var(--bg-selected)":"none",border:"none",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:b?600:400,whiteSpace:"nowrap"},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="none")},children:[b?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,d.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),(0,d.jsx)("span",{style:{flex:1,minWidth:0},children:a.name}),a.input?.includes("image")&&(0,d.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font-mono)",marginLeft:12},children:"image"})]},`${a.provider}:${a.modelId}`)})]},a.provider))})))]}),ar&&!g&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{ref:aJ,style:{position:"relative",flexShrink:0},children:[(0,d.jsx)("button",{onClick:()=>{ac(!1),ae(!1),Z(!1),ag(!1),ai(!1),ak(a=>!a)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:aj?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ax,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.background=aj?"var(--bg-hover)":"none",a.currentTarget.style.color=aj?"var(--text)":"var(--text-muted)"},children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,d.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,d.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),aj&&(0,d.jsxs)("div",{style:{...bc,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,d.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,d.jsxs)("div",{style:{display:"grid",gap:4},children:[a2&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),ai(!1),ag(!1),ae(!1),Z(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:a6})]}),(a3||a4)&&(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[a3&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),Z(!1),ag(!1),ae(!1),ai(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:a7})]}),a4&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),Z(!1),ai(!1),ae(!1),ag(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:a8})]})]}),a5&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),Z(!1),ai(!1),ag(!1),ae(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,d.jsx)("div",{style:{fontSize:12,color:a0.length>0?"var(--accent)":"var(--text)",marginTop:2},children:a1})]}),void 0!==C&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),C(!B)},style:{...ay,border:B?"1px solid rgba(59,130,246,0.24)":"none",background:B?"rgba(59,130,246,0.06)":"none"},children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Mode"}),(0,d.jsx)("div",{style:{fontSize:12,color:B?"#3b82f6":"var(--text)",marginTop:2},children:B?"Plan(只读规划)":"Code(可执行)"})]})]})]})]}),(0,d.jsx)("button",{onClick:A,title:z?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:"none",border:"none",borderRadius:8,color:z?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:z?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)",a.currentTarget.style.opacity="1"},onMouseLeave:a=>{a.currentTarget.style.background="none",a.currentTarget.style.color=z?"var(--text-muted)":"var(--text-dim)",a.currentTarget.style.opacity=z?"1":"0.55"},children:z?(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,d.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,d.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,d.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,d.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]}),(0,d.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:aw?"none":void 0,flex:ar?"0 0 auto":1,width:ar?0:void 0,height:ar?0:void 0}}),(0,d.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:"0 0 auto",width:ar?"auto":void 0,display:"flex",alignItems:"center",gap:ar?4:2,marginLeft:ar?0:"auto",marginTop:0},children:[aw&&!ar&&(0,d.jsxs)("div",{ref:aJ,style:{position:"relative"},children:[(0,d.jsx)("button",{onClick:()=>{ac(!1),ae(!1),Z(!1),ag(!1),ai(!1),ak(a=>!a)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:aj?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ax,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.background=aj?"var(--bg-hover)":"none",a.currentTarget.style.color=aj?"var(--text)":"var(--text-muted)"},children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,d.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,d.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),aj&&(0,d.jsxs)("div",{style:{...bc,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,d.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,d.jsxs)("div",{style:{display:"grid",gap:4},children:[a2&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),ai(!1),ag(!1),ae(!1),Z(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:a6})]}),(a3||a4)&&(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[a3&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),Z(!1),ag(!1),ae(!1),ai(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:a7})]}),a4&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),Z(!1),ai(!1),ae(!1),ag(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:a8})]})]}),a5&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),Z(!1),ai(!1),ag(!1),ae(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,d.jsx)("div",{style:{fontSize:12,color:a0.length>0?"var(--accent)":"var(--text)",marginTop:2},children:a1})]})]})]})]}),(!aw&&!g||ar&&ah)&&v&&(0,d.jsxs)("div",{ref:aI,style:{position:"relative"},children:[!aw&&!g&&(0,d.jsxs)("button",{onClick:()=>{g||(ac(!1),ae(!1),Z(!1),ag(!1),ak(!1),ai(a=>!a))},disabled:g,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:ar?3:5,padding:au,height:at,background:ah?"var(--bg-hover)":"none",border:"none",borderRadius:ar?8:9,color:"var(--text-muted)",cursor:g?"not-allowed":"pointer",fontSize:ar?11:12,opacity:g?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{g||(a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background=ah?"var(--bg-hover)":"none",a.currentTarget.style.color="var(--text-muted)"},children:[(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M9.5 2A5.5 5.5 0 0 0 4 7.5c0 1.7.78 3.21 2 4.21V14a1 1 0 0 0 1 1h5a1 1 0 0 0 1-1v-2.29c1.22-1 2-2.51 2-4.21A5.5 5.5 0 0 0 9.5 2z"}),(0,d.jsx)("line",{x1:"7",y1:"18",x2:"12",y2:"18"}),(0,d.jsx)("line",{x1:"8",y1:"21",x2:"11",y2:"21"})]}),(0,d.jsx)("span",{style:as,children:(()=>{let a=u??"auto";if("auto"===a||!x)return a;let b=x[a];return null!=b?b:a})()})]}),ah&&(0,d.jsx)("div",{style:{...ar?bc:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:av},overflow:"hidden"},children:R.filter(a=>!w||"auto"===a||w.includes(a)).map(a=>{let b=(u??"auto")===a,c=S[a],e="auto"!==a&&x?x[a]:void 0,f=null!=e&&e!==a?e:a,g=null!=e&&e!==a;return(0,d.jsxs)("button",{onClick:()=>{ai(!1),b||v(a)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:b?"var(--bg-selected)":"none",border:"none",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ar?11:12,textAlign:"left",fontWeight:b?600:400,whiteSpace:"nowrap"},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="none")},children:[b?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,d.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),(0,d.jsxs)("span",{style:{flex:1},children:[f,g&&(0,d.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",a,")"]})]}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:c})]},a)})})]}),(!aw&&!g||ar&&af)&&a4&&(0,d.jsxs)("div",{ref:aH,style:{position:"relative"},children:[!aw&&!g&&(0,d.jsxs)("button",{onClick:()=>{g||(ac(!1),ae(!1),Z(!1),ai(!1),ak(!1),ag(a=>!a))},disabled:g,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:ar?3:5,padding:au,height:at,background:af?"var(--bg-hover)":"none",border:"none",borderRadius:ar?8:9,color:(p??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:g?"not-allowed":"pointer",fontSize:ar?11:12,opacity:g?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{g||(a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color=(p??"full")==="workbench"?"var(--accent)":"var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background=af?"var(--bg-hover)":"none",a.currentTarget.style.color=(p??"full")==="workbench"?"var(--accent)":"var(--text-muted)"},children:[(0,d.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),(0,d.jsx)("span",{style:as,children:a8})]}),af&&(0,d.jsx)("div",{style:{...ar?bc:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:120},overflow:"hidden"},children:N.map(a=>{let b=O[a],c=(p??"full")===b,e="agent"===a&&!1===al,f=e?"需安装 pi-subagents":P[a];return(0,d.jsxs)("button",{onClick:()=>{!e&&(ag(!1),c||r(b))},disabled:e,title:e?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:c?"var(--bg-selected)":"none",border:"none",color:c?"var(--text)":"var(--text-muted)",cursor:e?"not-allowed":"pointer",fontSize:ar?11:12,textAlign:"left",fontWeight:c?600:400,opacity:e?.5:1,whiteSpace:"nowrap"},onMouseEnter:a=>{c||e||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{c||(a.currentTarget.style.background="none")},children:[c?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,d.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),(0,d.jsx)("span",{style:{flex:1},children:a}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:f})]},a)})})]}),g&&(0,d.jsxs)("button",{onClick:b,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:at,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:ar?8:9,color:"#ef4444",cursor:"pointer",fontSize:ar?11:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="rgba(239,68,68,0.16)"},onMouseLeave:a=>{a.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,d.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),"Stop"]}),!aw&&void 0!==C&&(0,d.jsxs)("button",{onClick:()=>{g||C(!B)},disabled:g,title:B?"切换到 Code 模式(可执行代码)":"切换到 Plan 模式(只读规划)",style:{display:"flex",alignItems:"center",gap:6,padding:au,height:at,background:B?"rgba(59,130,246,0.08)":"none",border:B?"1px solid rgba(59,130,246,0.24)":"none",borderRadius:ar?8:9,color:B?"#3b82f6":"var(--text-muted)",cursor:g?"not-allowed":"pointer",fontSize:ar?11:12,opacity:g?.5:1,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:a=>{g||(a.currentTarget.style.background=B?"rgba(59,130,246,0.14)":"var(--bg-hover)",a.currentTarget.style.color=B?"#3b82f6":"var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background=B?"rgba(59,130,246,0.08)":"none",a.currentTarget.style.color=B?"#3b82f6":"var(--text-muted)"},children:[(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,d.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,d.jsx)("span",{style:as,children:B?"Plan":"Code"})]}),!ar&&void 0!==A&&(0,d.jsx)("button",{onClick:A,title:z?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:ar?28:32,height:ar?28:32,padding:0,background:"none",border:"none",borderRadius:ar?8:9,color:z?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:z?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)",a.currentTarget.style.opacity="1"},onMouseLeave:a=>{a.currentTarget.style.background="none",a.currentTarget.style.color=z?"var(--text-muted)":"var(--text-dim)",a.currentTarget.style.opacity=z?"1":"0.55"},children:z?(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,d.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,d.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,d.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,d.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]})]})]})});function aa(a){return"user"===a.role?{bg:"rgba(37,99,235,0.18)",border:"rgba(37,99,235,0.7)"}:{bg:"rgba(107,114,128,0.12)",border:"rgba(107,114,128,0.5)"}}function ab({messages:a,streamingMessage:b,scrollContainer:c,messageRefs:f}){let[g,h]=(0,e.useState)(0),[i,j]=(0,e.useState)(1),[k,l]=(0,e.useState)(!1),[m,n]=(0,e.useState)([]),[o,p]=(0,e.useState)(!1),[q,r]=(0,e.useState)(null),s=(0,e.useRef)(!1),t=(0,e.useRef)(null),u=(0,e.useMemo)(()=>b?[...a,b]:a,[a,b]),v=(0,e.useRef)(u);v.current=u;let w=(0,e.useRef)(null);w.current=()=>{let a=c.current;if(!a)return;let b=a.scrollHeight,d=a.clientHeight,e=b-d;l(e>20),e<=0?(h(0),j(1)):(h(a.scrollTop/e),j(d/b));let g=f.current,i=[],k=0,m=v.current;for(let c=0;c<m.length;c++){let d=m[c];if("user"!==d.role&&"assistant"!==d.role)continue;let e=g?.[k];if(k++,("user"===d.role||"assistant"===d.role&&(d.content??[]).some(a=>"text"===a.type))&&e&&b>0){let c=e.getBoundingClientRect(),f=a.getBoundingClientRect(),g=c.top-f.top+a.scrollTop,h=c.height;i.push({topRatio:g/b,heightRatio:h/b,msg:d,index:i.length})}}n(i)},(0,e.useCallback)(()=>w.current(),[]);let x=(0,e.useCallback)(a=>{let b=c.current;if(!b)return;let d=b.scrollHeight-b.clientHeight;d<=0||(b.scrollTop=Math.max(0,Math.min(1-i,a))/(1-i)*d)},[c,i]),y=(0,e.useCallback)(a=>{if(!k)return;s.current=!0;let b=a.currentTarget.getBoundingClientRect(),c=(a.clientY-b.top)/b.height,d=c-g*(1-i),e=d>=0&&d<=i?d:i/2;x(c-e);let f=a=>{s.current&&x((a.clientY-b.top)/b.height-e)},h=()=>{s.current=!1,window.removeEventListener("mousemove",f),window.removeEventListener("mouseup",h)};window.addEventListener("mousemove",f),window.addEventListener("mouseup",h)},[k,i,g,x]),z=t.current?.clientHeight??600,A=(0,e.useMemo)(()=>{if(!o||0===m.length)return[];let a=m.map(a=>Math.round(a.topRatio*z-11));for(let b=0;b<10;b++){for(let b=1;b<a.length;b++){let c=a[b-1]+22+2;a[b]<c&&(a[b]=c)}for(let b=a.length-2;b>=0;b--){let c=a[b+1]-22-2;a[b]>c&&(a[b]=c)}}for(let b=0;b<a.length;b++)a[b]=Math.max(0,Math.min(z-22,a[b]));return a},[o,m,z]);if(!k)return null;let B=g*(1-i)*100,C=100*i,D=null!==q&&m.length>0?m.reduce((a,b)=>Math.abs(b.topRatio-q)<Math.abs(m[a].topRatio-q)?b.index:a,0):null;return(0,d.jsxs)("div",{ref:t,onMouseDown:y,onMouseEnter:()=>p(!0),onMouseLeave:()=>{p(!1),r(null)},onMouseMove:a=>{let b=a.currentTarget.getBoundingClientRect();r((a.clientY-b.top)/b.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,d.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${B}%`,height:`${C}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),m.map(a=>{let b=aa(a.msg),c=o&&D===a.index,e="user"===a.msg.role,f=100*a.topRatio;return(0,d.jsx)("div",{style:{position:"absolute",top:`${f}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,d.jsx)("div",{style:{width:e?8:6,height:e?8:6,borderRadius:e?2:"50%",background:b.bg,border:`1.5px solid ${b.border}`,flexShrink:0,transition:"transform 0.1s",transform:c?"scale(1.6)":"scale(1)"}})},a.index)}),(0,d.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),o&&m.map((a,b)=>{let c=function(a){if("user"===a.role){let b=a.content;return"string"==typeof b?b.slice(0,200):Array.isArray(b)?b.filter(a=>"text"===a.type&&a.text).map(a=>a.text).join("\n").slice(0,200):""}if("assistant"===a.role){let b=a.content??[],c=b.filter(a=>"text"===a.type).map(a=>a.text).join(" ");if(c)return c.slice(0,200);let d=b.filter(a=>"toolCall"===a.type).map(a=>a.toolName);if(d.length)return d.join(", ")}return""}(a.msg),e=aa(a.msg),f=D===a.index;return c&&0!==A.length?(0,d.jsx)("div",{style:{position:"absolute",top:A[b],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${f?e.border:"var(--border)"}`,borderRight:`1px solid ${f?e.border:"var(--border)"}`,borderBottom:`1px solid ${f?e.border:"var(--border)"}`,borderLeft:`2px solid ${e.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:f?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,d.jsx)("div",{style:{fontSize:11,color:f?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:c})},a.index):null})]})}function ac(a){return"object"==typeof a&&null!==a&&!Array.isArray(a)}function ad(a,b=220){if(!a)return;let c=a.trim();if(c)return c.length>b?`${c.slice(0,b)}...`:c}function ae(...a){for(let b of a)if("string"==typeof b&&b.trim())return b}function af(...a){for(let b of a)if("number"==typeof b&&Number.isFinite(b))return b}function ag(a){let b=new Map;for(let c of a){if("custom"===c.role&&"subagent-notify"===c.customType&&"string"==typeof c.content){let a=c.content.match(/^Background task (completed|failed|paused):\s*\*\*(.+?)\*\*(?:\s+\((.+?)\))?/);if(a){let d=`bg-${a[2]}-${c.timestamp??""}`;b.set(d,{id:d,agent:a[2],status:a[1],task:a[3],summary:ad(c.content.split("\n").slice(3).join("\n")),timestamp:c.timestamp})}}if("assistant"===c.role){let a=c.content;if(!a)continue;for(let d of a)if("toolCall"===d.type&&"subagent"===d.toolName&&d.input){let a=d.input,e=a.agent??(a.chain?"chain":a.tasks?"parallel":a.action??"subagent"),f="string"==typeof a.task?a.task:void 0,g=d.toolCallId??`sub-${e}-${c.timestamp??Date.now()}`;b.set(g,{id:g,agent:e,status:"running",task:f,timestamp:c.timestamp})}}if("toolResult"===c.role){if(c.toolName&&"subagent"!==c.toolName||!c.toolCallId||!b.has(c.toolCallId))continue;let a=b.get(c.toolCallId),d=c.content.filter(a=>"text"===a.type).map(a=>a.text).join("\n");b.set(c.toolCallId,function(a,b,c){let d;if(!ac(b))return{...a,summary:ad(c)};let e=Array.isArray(b.results)?b.results.filter(ac):[],f=e[0],g=f?.progressSummary,h=f&&(d=f.artifactPaths)?Object.values(d).filter(a=>"string"==typeof a&&a.trim().length>0):[],i=ae(f?.finalOutput,f?.output,c);return{...a,mode:ae(b.mode),runId:ae(b.runId),agent:ae(f?.agent,a.agent)??a.agent,task:ae(f?.task,a.task),summary:ad(i),model:ae(f?.model),durationMs:af(g?.durationMs),toolCount:af(g?.toolCount),tokens:af(g?.tokens),outputPath:ae(f?.savedOutputPath,f?.artifactPaths?.outputPath),sessionFile:ae(f?.sessionFile,f?.artifactPaths?.jsonlPath),artifacts:h,resultCount:e.length||void 0}}({...a,status:function(a){if(a.isError)return"failed";let b=a.details;return ac(b)&&Array.isArray(b.results)&&b.results.some(a=>ac(a)&&"number"==typeof a.exitCode&&0!==a.exitCode)?"failed":"completed"}(c)},c.details,d))}}return Array.from(b.values()).sort((a,b)=>(b.timestamp??0)-(a.timestamp??0))}function ah({messages:a,runs:b}){let c=(0,e.useMemo)(()=>ag(a??[]),[a]),f=b??c,g=f.filter(a=>"running"===a.status),h=f.filter(a=>"running"!==a.status);return 0===f.length?null:(0,d.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[g.length>0&&(0,d.jsx)(ai,{title:`Active (${g.length})`,runs:g}),h.length>0&&(0,d.jsx)(ai,{title:`Completed (${h.length})`,runs:h,compact:g.length>0})]})}function ai({title:a,runs:b,compact:c}){return(0,d.jsxs)("div",{style:{marginBottom:c?10:16},children:[(0,d.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",marginBottom:8,textTransform:"uppercase",letterSpacing:"0.05em"},children:a}),b.map(a=>(0,d.jsx)(aj,{run:a},a.id))]})}function aj({run:a}){let[b,c]=(0,e.useState)(!1),f="running"===a.status,g="completed"===a.status?"#22c55e":"failed"===a.status?"#ef4444":f?"var(--accent)":"var(--text-dim)",h="failed"===a.status?"rgba(248,113,113,0.35)":f?"rgba(99,102,241,0.25)":"var(--border)",i="failed"===a.status?"rgba(248,113,113,0.05)":f?"rgba(99,102,241,0.05)":"var(--bg-panel)",j=[a.mode,a.resultCount&&a.resultCount>1?`${a.resultCount} results`:void 0,void 0!==a.toolCount?`${a.toolCount} tools`:void 0,void 0!==a.tokens?`${a.tokens.toLocaleString()} tok`:void 0,void 0!==a.durationMs?`${Math.round(a.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),k=!!(a.summary||a.outputPath||a.sessionFile||a.artifacts?.length||a.model||a.runId);return(0,d.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${h}`,background:i,marginBottom:6,fontSize:12,overflow:"hidden"},children:[(0,d.jsxs)("button",{onClick:()=>k&&c(a=>!a),style:{display:"flex",alignItems:"center",gap:7,width:"100%",border:"none",background:"transparent",padding:"8px 10px",color:"var(--text-muted)",textAlign:"left",cursor:k?"pointer":"default"},children:[(0,d.jsx)(ak,{running:f,color:g}),(0,d.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.agent}),(0,d.jsx)("span",{style:{color:g,fontSize:10,fontWeight:700,flexShrink:0},children:a.status}),j&&(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:j}),k&&(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:b?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,d.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),a.task&&(0,d.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:ad(a.task,150)}),b&&k&&(0,d.jsxs)("div",{style:{borderTop:`1px solid ${h}`,background:"var(--bg)",padding:"8px 10px",display:"flex",flexDirection:"column",gap:7},children:[a.summary&&(0,d.jsx)("pre",{style:{margin:0,color:"var(--text-muted)",fontSize:11,lineHeight:1.45,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:a.summary}),(0,d.jsx)(al,{run:a})]})]})}function ak({running:a,color:b}){return(0,d.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:b,display:"inline-block",animation:a?"pulse 1.5s infinite":void 0,flexShrink:0}})}function al({run:a}){let b=[a.model?["model",a.model]:void 0,a.runId?["run",a.runId]:void 0,a.outputPath?["output",a.outputPath]:void 0,a.sessionFile?["session",a.sessionFile]:void 0,...(a.artifacts??[]).slice(0,4).map((a,b)=>[`artifact ${b+1}`,a])].filter(Boolean);return 0===b.length?null:(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:3},children:b.map(([a,b])=>(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"58px minmax(0, 1fr)",gap:6,fontSize:10},children:[(0,d.jsx)("span",{style:{color:"var(--text-dim)",textTransform:"uppercase"},children:a}),(0,d.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:b,children:b})]},`${a}:${b}`))})}function am({sessionKind:a,toolPreset:b,initialSourcePath:c,initialKernel:e,isNew:f,isStreaming:g=!1,onResume:h,onDismiss:i}){if(f||"workbench"!==a)return null;let j=c?c.replace(/\\/g,"/").split("/").filter(Boolean).pop()??c:null,k="workbench"===b;return(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 14px",background:"rgba(37,99,235,0.06)",borderBottom:"1px solid rgba(37,99,235,0.18)",fontSize:12,flexShrink:0},children:[(0,d.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M4 19V5"}),(0,d.jsx)("path",{d:"M4 19h16"}),(0,d.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,d.jsxs)("span",{style:{color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["This is an ",(0,d.jsxs)("strong",{children:[k?"active":"inactive"," Workbench"]})," session",j&&(0,d.jsxs)("span",{style:{color:"var(--text-muted)"},children:[" \xb7 Source: ",(0,d.jsx)("code",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--accent)"},children:j})]}),e&&(0,d.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" \xb7 Kernel: ",e.toUpperCase()]})]}),(0,d.jsx)("div",{style:{flex:1}}),(0,d.jsx)("button",{type:"button",onClick:i,style:{border:"1px solid var(--border)",borderRadius:6,padding:"2px 10px",height:26,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:"Dismiss"}),(0,d.jsx)("button",{type:"button",onClick:h,disabled:g,title:g?"Wait until the agent finishes before updating Workbench":k?"Reload the initial data source into the warm runtime":"Restore Workbench tools and reload the initial data source",style:{border:"1px solid rgba(37,99,235,0.45)",borderRadius:6,padding:"2px 12px",height:26,background:"rgba(37,99,235,0.12)",color:"var(--accent)",cursor:g?"not-allowed":"pointer",fontSize:11,fontWeight:600,opacity:g?.55:1,whiteSpace:"nowrap"},children:k?"Reload Initial Data":"Resume Workbench"})]})}function an(a){if("assistant"!==a.role)return a;let b=a.content;if(!Array.isArray(b))return a;let c=b.map(a=>("object"!=typeof a||null===a||Array.isArray(a)||"toolCall"!==a.type?null:{type:"toolCall",toolCallId:"string"==typeof a.toolCallId?a.toolCallId:"string"==typeof a.id?a.id:"",toolName:"string"==typeof a.toolName?a.toolName:"string"==typeof a.name?a.name:"",input:"object"!=typeof a.input||null===a.input||Array.isArray(a.input)?"object"!=typeof a.arguments||null===a.arguments||Array.isArray(a.arguments)?{}:a.arguments:a.input})??a);return{...a,content:c}}async function ao(a,b){let c=await fetch(`/api/agent/${encodeURIComponent(a)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)}),d=await c.json().catch(()=>({}));if(!c.ok||d.error)throw Error(d.error??`HTTP ${c.status}`);return d.data}var ap=c(31343);async function aq(a,b){if(!b.length)return[];let c=await fetch("/api/images/upload",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,images:b.map(a=>({data:a.data,mimeType:a.mimeType,name:a.name}))})}),d=await c.json().catch(()=>({}));if(!c.ok||d.error)throw Error(d.error??`Upload failed (HTTP ${c.status})`);return(d.uploaded??[]).map((a,c)=>({...a,previewUrl:b[c]?.previewUrl}))}async function ar(a,b,c){let d=new TextDecoder,e="",f=new Promise(a=>{c?.aborted?a():c?.addEventListener("abort",()=>a(),{once:!0})});for(;;){let c=await Promise.race([a.read(),f.then(()=>({done:!0,value:void 0}))]);if(c.done)break;let g=(e+=d.decode(c.value,{stream:!0})).split("\n");for(let a of(e=g.pop()||"",g)){if(!a.startsWith("data: "))continue;let c=a.slice(6);if("[DONE]"!==c)try{b(c)}catch{}}}if(e.trim())for(let a of e.split("\n")){if(!a.startsWith("data: "))continue;let c=a.slice(6);if("[DONE]"!==c)try{b(c)}catch{}}}let as="__annovibeStreamSessions__",at="__annovibeStreamListeners__",au="__annovibeStreamErrorCallbacks__";function av(){let a=globalThis;return a[as]||(a[as]=new Map),a[as]}function aw(){let a=globalThis;return a[au]||(a[au]=new Map),a[au]}function ax(a){return{sessionId:a,phase:"idle",startedAt:null,lastEventAt:null,lastHeartbeatAt:null,reconnectCount:0,lastSyncReason:null,accumulatedText:"",toolCalls:[],toolResults:[],statusText:null,streamingMessage:null,isStreaming:!1,error:null}}function ay(a,b){let c;for(let d of(!(c=globalThis)[at]&&(c[at]=new Map),c[at]).get(a)??[])try{d(b)}catch{}}function az(a){a.textThrottleTimer&&(clearTimeout(a.textThrottleTimer),a.textThrottleTimer=null),a.textDirty&&(a.textDirty=!1,aB(a))}function aA(a,b=!1){let c=Date.now();if(a.snapshot.lastEventAt=c,!b){a.textDirty=!0,a.textThrottleTimer||(a.textThrottleTimer=setTimeout(()=>{a.textThrottleTimer=null,a.textDirty&&(a.textDirty=!1,aB(a))},100));return}az(a),aB(a)}function aB(a,b){let c=Date.now(),d=function(a){let b=[];for(let c of a.toolCalls.values())b.push({type:"toolCall",toolCallId:c.toolCallId,toolName:c.toolName,input:c.input??{}});let c=a.accumulatedText.trim();return c&&b.push({type:"text",text:c}),b}(a),e=(b??a.snapshot.phase)==="active";a.snapshot={...a.snapshot,phase:b??a.snapshot.phase,lastEventAt:c,accumulatedText:a.accumulatedText,toolCalls:[...a.toolCalls.values()],toolResults:[...a.toolResults.values()],statusText:e?function(a){if(a.activeToolId){let b=a.toolCalls.get(a.activeToolId);if(b){let a=Math.max(0,Math.floor((Date.now()-b.startedAt)/1e3));return`Running ${b.toolName||"tool"}… (${a}s)`}}return a.accumulatedText.trim()?"Generating response…":a.toolCalls.size>0?"Finishing tool results…":null}(a):a.snapshot.statusText,streamingMessage:e&&d.length>0?{role:"assistant",content:d}:null,isStreaming:e},ay(a.snapshot.sessionId,{type:"snapshot-updated",snapshot:a.snapshot})}function aC(a){aD(a),a.idleCheckTimer=setInterval(()=>{if("connected"!==a.connectionState)return;let b=Math.max(a.snapshot.lastEventAt??0,a.snapshot.lastHeartbeatAt??0);if(Date.now()-b>=18e4){aE(a),az(a);let b="Stream idle timeout — no activity for 180s.";a.snapshot={...a.snapshot,phase:"error",isStreaming:!1,streamingMessage:null,statusText:null,error:b},aD(a),ay(a.snapshot.sessionId,{type:"error",snapshot:a.snapshot});let c=aw().get(a.snapshot.sessionId);if(c)try{c(a.snapshot.sessionId,b)}catch{}}},1e4)}function aD(a){a.idleCheckTimer&&(clearInterval(a.idleCheckTimer),a.idleCheckTimer=null)}function aE(a){a.toolProgressTimer&&(clearInterval(a.toolProgressTimer),a.toolProgressTimer=null)}function aF(a){let b=av(),c=b.get(a);return c||(c={snapshot:ax(a),accumulatedText:"",toolCalls:new Map,toolResults:new Map,toolProgressTimer:null,activeToolId:null,textThrottleTimer:null,textDirty:!1,connectionState:"idle",idleCheckTimer:null},b.set(a,c)),c}function aG(a,b){let c=aw();return c.set(a,b),()=>{c.get(a)===b&&c.delete(a)}}function aH(a){let b=av(),c=b.get(a);c&&(aE(c),aD(c),az(c)),b.delete(a)}let aI="__annovibeSessionMessageCache__";function aJ(){let a=globalThis;if(!a[aI]){var b;let c={entries:new Map,cleanupTimer:null};a[aI]=c,(b=c).cleanupTimer||(b.cleanupTimer=setInterval(()=>{let a=Date.now();for(let[c,d]of b.entries)a-d.loadedAt>72e5&&b.entries.delete(c)},6e4))}return a[aI]}function aK(a){let b=aJ(),c=b.entries.get(a);return c?Date.now()-c.loadedAt>72e5?(b.entries.delete(a),null):(c.loadedAt=Date.now(),{...c,messages:[...c.messages],entryIds:[...c.entryIds]}):null}function aL(a,b,c,d,e){let f=aJ(),g=f.entries.get(a);if(!g)return;let h=new Set(g.entryIds),i=[],j=[];for(let a=0;a<b.length;a++){let d=c[a];d&&!h.has(d)&&(i.push(b[a]),j.push(d))}0!==i.length&&f.entries.set(a,{...g,messages:[...i,...g.messages],entryIds:[...j,...g.entryIds],hasMore:d,loadedMessagesCount:e,loadedAt:Date.now()})}function aM(a,b){switch(b.type){case"start":return{isStreaming:!0,streamingMessage:null};case"update":return{isStreaming:!0,streamingMessage:b.message};case"end":case"reset":return{isStreaming:!1,streamingMessage:null};default:return a}}function aN(){return"u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,11)}-${Math.random().toString(36).slice(2,11)}`}let aO=["read","bash","grep","find","ls"];function aP(a,b){return a.trim()||0!==b?`text:${a}|images:${b}`:null}function aQ(a){return"string"==typeof a?aP(a,0):Array.isArray(a)?aP(a.filter(a=>!!a&&"object"==typeof a&&"text"===a.type&&"string"==typeof a.text).map(a=>a.text).join("\n"),a.filter(a=>!!a&&"object"==typeof a&&"image"===a.type).length):null}function aR(a){let b=new Map;for(let c of a){let a="user"!==c.role?null:aQ(c.content);a&&b.set(a,(b.get(a)??0)+1)}return b}function aS(a,b,c){return a.sessionId===b&&(!a.leafId||c.includes(a.leafId))}let aT=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function aU(a){return aT.some(b=>a.type.startsWith(b))}function aV({agentPhase:a,startedAt:b}){let[c,f]=(0,e.useState)(0);return(0,d.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,d.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[function(a){if(a?.kind==="running_tools"){let b=a.tools.map(a=>a.args??a.name);return 0===b.length?"Running tool…":1===b.length?`Running ${b[0]}…`:`Running ${b.slice(0,2).join(", ")}${b.length>2?` (+${b.length-2})`:""}…`}return a?.kind==="waiting_model"?"Waiting for model…":"Working…"}(a),"\xa0\xa0",function(a){if(a<60)return`${a}s`;let b=Math.floor(a/60);return`${b}m ${String(a%60).padStart(2,"0")}s`}(c)]})})}function aW(a){return a>=1e6?`${(a/1e6).toFixed(1)}M`:a>=1e3?`${(a/1e3).toFixed(1)}K`:String(a)}function aX({goal:a,planTasks:b,isRunning:c,onExecutePlan:f,onContinuePlanning:g,onEditPlan:h}){let[i,j]=(0,e.useState)(!1),k=(0,e.useCallback)(()=>j(a=>!a),[]),l=a&&"dropped"!==a.status,m=b&&b.length>0;if(!l&&!m)return null;let n=(0,e.useMemo)(()=>!a?.tokenBudget||a.tokenBudget<=0?null:Math.min(100,Math.round(a.tokensUsed/a.tokenBudget*100)),[a?.tokenBudget,a?.tokensUsed]),o=b?.filter(a=>"completed"===a.status).length??0,p=!!b&&o===b.length;return(0,d.jsxs)("div",{style:{marginBottom:16,borderRadius:10,border:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"hidden"},children:[l&&(0,d.jsxs)("div",{style:{padding:"10px 14px",borderBottom:m?"1px solid var(--border)":"none"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[(0,d.jsx)("span",{style:{flexShrink:0,borderRadius:4,padding:"1px 6px",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"#fff",background:function(a){switch(a){case"active":return"rgba(37,99,235,0.85)";case"complete":return"rgba(34,197,94,0.85)";case"budget-limited":return"rgba(245,158,11,0.85)";case"paused":return"rgba(148,163,184,0.85)";case"dropped":return"rgba(239,68,68,0.85)"}}(a.status)},children:function(a){switch(a){case"active":return"进行中";case"paused":return"已暂停";case"budget-limited":return"预算受限";case"complete":return"已完成";case"dropped":return"已放弃"}}(a.status)}),(0,d.jsx)("span",{style:{fontSize:11,fontWeight:500,color:"var(--text-muted)"},children:"Goal"})]}),(0,d.jsx)("p",{style:{margin:"0 0 6px",fontSize:13,lineHeight:1.5,color:"var(--text)",whiteSpace:"pre-wrap"},children:a.objective}),(0,d.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"4px 16px",fontSize:11,color:"var(--text-muted)"},children:[(0,d.jsx)("span",{children:function(a){if(a<60)return`${a}s`;let b=Math.floor(a/60);if(b<60)return`${b}m ${String(a%60).padStart(2,"0")}s`;let c=Math.floor(b/60);return`${c}h ${b%60}m`}(a.timeUsedSeconds)}),(0,d.jsxs)("span",{children:[aW(a.tokensUsed),a.tokenBudget?` / ${aW(a.tokenBudget)} tokens`:" tokens"]}),null!=n&&(0,d.jsxs)("span",{children:[n,"%"]})]}),null!=n&&(0,d.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,overflow:"hidden",background:"var(--border)"},children:(0,d.jsx)("div",{style:{height:"100%",borderRadius:999,background:n>=100?"rgba(239,68,68,0.6)":"rgba(37,99,235,0.5)",width:`${Math.min(n,100)}%`,transition:"width 0.3s"}})})]}),m&&(0,d.jsxs)("div",{style:{padding:"4px 14px 10px"},children:[(0,d.jsxs)("div",{onClick:k,role:"button",tabIndex:0,onKeyDown:a=>{("Enter"===a.key||" "===a.key)&&k()},"aria-expanded":!i,style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,cursor:"pointer",padding:"6px 0"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,d.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,d.jsxs)("span",{style:{fontSize:12,fontWeight:500,color:"#3b82f6"},children:["Plan \xb7 ",b.length," 步"]}),p&&(0,d.jsxs)("span",{style:{borderRadius:4,padding:"0 6px",fontSize:10,fontWeight:600,background:"rgba(34,197,94,0.12)",color:"rgba(34,197,94,0.85)"},children:["已完成 ",o,"/",b.length]})]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[(h||g||f)&&(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[h&&(0,d.jsx)("button",{type:"button",onClick:a=>{a.stopPropagation(),h()},disabled:c,style:{borderRadius:5,padding:"3px 8px",fontSize:11,fontWeight:500,color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border)",cursor:c?"not-allowed":"pointer",opacity:c?.55:1},children:"修改计划"}),g&&(0,d.jsx)("button",{type:"button",onClick:a=>{a.stopPropagation(),g()},disabled:c,style:{borderRadius:5,padding:"3px 8px",fontSize:11,fontWeight:500,color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border)",cursor:c?"not-allowed":"pointer",opacity:c?.55:1},children:"继续规划"}),f&&(0,d.jsx)("button",{type:"button",onClick:a=>{a.stopPropagation(),f()},disabled:c,style:{borderRadius:5,padding:"3px 10px",fontSize:11,fontWeight:500,color:"#fff",background:c?"rgba(59,130,246,0.3)":"#3b82f6",border:"none",cursor:c?"not-allowed":"pointer"},children:"执行计划"})]}),(0,d.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:i?"rotate(-90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:(0,d.jsx)("polyline",{points:"6 9 12 15 18 9"})})]})]}),!i&&(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:b.map(a=>(0,d.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,borderRadius:4,padding:"3px 8px",background:"inProgress"===a.status?"rgba(59,130,246,0.04)":"transparent"},children:[(0,d.jsx)("div",{style:{marginTop:1},children:function(a){switch(a){case"completed":return(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"rgba(34,197,94,0.12)",stroke:"rgba(34,197,94,0.6)",strokeWidth:"1.5"}),(0,d.jsx)("path",{d:"M7 12.5l3 3 7-7",stroke:"rgba(34,197,94,0.9)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]});case"inProgress":return(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"rgba(59,130,246,0.2)",strokeWidth:"2.5"}),(0,d.jsx)("path",{d:"M12 2a10 10 0 0 1 10 10",stroke:"rgba(59,130,246,0.85)",strokeWidth:"2.5",strokeLinecap:"round",children:(0,d.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"1.5s",repeatCount:"indefinite"})})]});default:return(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:(0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"var(--border)",strokeWidth:"1.5"})})}}(a.status)}),(0,d.jsx)("span",{style:{fontSize:12,lineHeight:1.5,...function(a){switch(a){case"completed":return{color:"rgba(34,197,94,0.85)",textDecoration:"line-through"};case"inProgress":return{color:"#3b82f6",fontWeight:500};default:return{color:"var(--text-muted)"}}}(a.status)},children:a.step})]},a.id))})]})]})}let aY=["annotate and analyze.","vibe code bioinformatics.","turn data into figures.","inspect your project.","build a reproducible report.","run R/Python plots.","summarize that paper.","review the pipeline.","compare markers.","draft methods.","find the next analysis step."];function aZ({phrases:a}){let[b,c]=(0,e.useState)(()=>Math.floor(Math.random()*a.length)),[f,g]=(0,e.useState)(""),[h,i]=(0,e.useState)(!1),[j,k]=(0,e.useState)(!0);return(0,d.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[f,(0,d.jsx)("span",{style:{opacity:+!!j,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function a$({status:a}){let b=a?.current??"0.8.118"??"0.0.0";if(a?.updateAvailable){let c=a.latest?`v${a.latest}`:"latest";return(0,d.jsxs)("span",{title:`Current v${b}; latest ${c}; run ${a.updateCommand}`,style:{display:"block",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:11,color:"var(--accent)"},children:["Update: ",(0,d.jsx)("code",{style:{fontFamily:"var(--font-mono)",color:"var(--accent)"},children:a.updateCommand})]})}return(0,d.jsxs)("span",{title:`AnnoVibe v${b}`,style:{fontSize:11,color:"var(--text-dim)",whiteSpace:"nowrap"},children:["v",b]})}function a_({session:a,newSessionCwd:b,onAgentEnd:c,onSessionCreated:f,onSessionForked:g,modelsRefreshKey:h,chatInputRef:i,onBranchDataChange:j,onSessionStatsChange:k,onContextUsageChange:m,onToolPresetActive:n,generativeUI:o,activeFilePath:p,onOpenFileAtLine:q}){var r;let s,[t,u]=(0,e.useState)(null),[v,w]=(0,e.useState)(!1),[x,y]=(0,e.useState)([]),[z,A]=(0,e.useState)(""),[E,K]=(0,e.useState)(!1);(0,e.useRef)(!1);let[M,N]=(0,e.useState)(!1),O=p&&!M?p:null,{data:P,loading:Q,error:R,messages:S,entryIds:T,streamState:U,agentRunning:V,modelNames:W,modelList:X,modelThinkingLevels:Y,modelThinkingLevelMaps:Z,toolPreset:$,memoryTools:aa,thinkingLevel:ac,retryInfo:ad,contextUsage:ae,forkingEntryId:af,isCompacting:ai,compactError:aj,displayModel:ak,sessionStats:al,agentPhase:as,agentError:at,isNew:au,loadMoreMessages:aw,hasMoreMessages:aB,totalMessages:aI,loadedMessagesCount:aT,messagesEndRef:aW,scrollContainerRef:a0,lastUserMsgRef:a1,handleSend:a2,handleAbort:a3,handleFork:a4,handleNavigate:a5,handleModelChange:a6,handleCompact:a7,handleSteer:a8,handleFollowUp:a9,handleAbortCompaction:ba,handleToolPresetChange:bb,handleMemoryToolsChange:bc,handleThinkingLevelChange:bd,handleAgentEventRef:be}=function(a){let{session:b,newSessionCwd:c,planMode:d=!1,onAgentEnd:f,onSessionCreated:g,onSessionForked:h,modelsRefreshKey:i,onBranchDataChange:j,onPlanModeState:k}=a,l=null===b&&null!==c,[m,n]=(0,e.useState)(null),[o,p]=(0,e.useState)(!l),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)([]),[w,x]=(0,e.useState)([]),[y,z]=(0,e.useState)(0),[A,B]=(0,e.useState)(!1),[E,K]=(0,e.useState)(0),[M,N]=(0,e.useReducer)(aM,{isStreaming:!1,streamingMessage:null}),[O,P]=(0,e.useState)(!1),[Q,R]=(0,e.useState)({}),[S,T]=(0,e.useState)([]),[U,V]=(0,e.useState)({}),[W,X]=(0,e.useState)({}),[Y,Z]=(0,e.useState)(null),[$,_]=(0,e.useState)("full"),[aa,ab]=(0,e.useState)([...D]),[ac,ad]=(0,e.useState)("auto"),[ae,af]=(0,e.useState)(null),[ag,ah]=(0,e.useState)(null),[ai,aj]=(0,e.useState)(null),[ak,al]=(0,e.useState)(null),[am,as]=(0,e.useState)(null),[at,au]=(0,e.useState)(null),[aw,aB]=(0,e.useState)(!1),[aI,aT]=(0,e.useState)(null),[aU,aV]=(0,e.useState)(null),[aW,aX]=(0,e.useState)(null),aY=(0,e.useRef)(null),aZ=(0,e.useRef)(b?.id??null),a$=(0,e.useRef)(!1),a_=(0,e.useRef)(null);(0,e.useRef)(null);let a0=(0,e.useRef)(null),a1=(0,e.useRef)(!1),a2=(0,e.useRef)(null),a3=(0,e.useRef)(!1),a4=(0,e.useRef)(null),a5=(0,e.useRef)(null),a6=(0,e.useRef)(new Map),a7=(0,e.useRef)(new Map),a8=(0,e.useRef)(null),a9=(0,e.useRef)(null),ba=(0,e.useRef)(0),bb=(0,e.useRef)(0),bc=(0,e.useRef)(!1),bd=(0,e.useRef)(0),be=(0,e.useRef)(!1),bf=a.setNewSessionModel??Z,bg=a.setToolPreset??_,bh=a.setMemoryTools??ab,bi=am??m?.context.model??at??null,bj=l?Y:bi,bk=(0,e.useCallback)(()=>d?aO:L($,aa),[aa,d,$]),bl=(0,e.useCallback)(a=>a?.length?a.map((a,b)=>{let c=`Attachment ${b+1}: ${a.fileName} (${a.mimeType||"application/octet-stream"}, ${a.size} bytes)`;if(a.extractedText){let b=a.truncated?"\n[The extracted text was truncated before sending.]":"";return`${c}
7
- ${b}
8
- ${a.extractedText}`.trim()}return`${c}
9
- [Text extraction unavailable: ${a.extractionError??"unsupported file type"}]`}).join("\n\n---\n\n"):"",[]),bm=(0,e.useCallback)(async a=>{let b=await fetch(`/api/agent/${encodeURIComponent(a)}/prepare`,{method:"POST"});if(!b.ok)throw Error((await b.json().catch(()=>({}))).error??`Failed to prepare session (HTTP ${b.status})`)},[]),bn=(()=>{let a={input:0,output:0,cacheRead:0,cacheWrite:0},b=0;for(let c of u){if("assistant"!==c.role)continue;let d=c.usage;d&&(a.input+=d.input??0,a.output+=d.output??0,a.cacheRead+=d.cacheRead??0,a.cacheWrite+=d.cacheWrite??0,b+=d.cost?.total??0)}return a.input+a.output+a.cacheRead+a.cacheWrite>0?{tokens:a,cost:b}:null})(),bo=(0,e.useRef)(!1),bp=(0,e.useCallback)(async()=>{let a=aZ.current;if(!a||bo.current||be.current)return;bo.current=!0,bc.current=!0;let b=0,c=aK(a);b=c?c.loadedMessagesCount:50;try{for(;;)try{let c=await fetch(`/api/sessions/${encodeURIComponent(a)}?limit=100&offset=${b}`);if(!c.ok)break;let d=await c.json();if(aZ.current!==a)break;let e=d.context.messages,f=d.context.entryIds??[];if(0===e.length)break;v(a=>[...e,...a]),x(a=>[...f,...a]);let g=b+e.length;if(K(g),bd.current=g,B(d.hasMore??!1),aL(a,e,f,d.hasMore??!1,g),b=g,!d.hasMore)break;await new Promise(a=>setTimeout(a,800))}catch{break}}finally{bo.current=!1,be.current=!0,bc.current=!1}},[]),bq=(0,e.useCallback)(async(a,b=!1,c=!1)=>{try{if(b&&p(!0),!c&&!a$.current){let c=aK(a);if(c)return z(c.totalMessages),B(c.hasMore),K(c.loadedMessagesCount),v(c.messages),x(c.entryIds),t(c.leafId),bd.current=c.loadedMessagesCount,b&&p(!1),c.hasMore&&!be.current&&setTimeout(()=>{bp()},1500),null}let e=c?`/api/sessions/${encodeURIComponent(a)}?includeState`:`/api/sessions/${encodeURIComponent(a)}?limit=50&offset=0`,f=new AbortController,g=setTimeout(()=>f.abort(),3e4),h=await fetch(e,{signal:f.signal}).finally(()=>clearTimeout(g));if(aZ.current&&aZ.current!==a)return null;if(404===h.status)return b&&(n(null),t(null),v([]),r(null)),null;if(!h.ok)throw Error(`HTTP ${h.status}`);let i=await h.json();c||(z(i.totalMessages??i.context.messages.length),B(i.hasMore??!1),K(i.context.messages.length)),n(i),t(i.leafId);let j=i.context.messages,l=aR(j),m=new Map,o=Date.now();for(let[b,c]of a6.current)if(c.sessionId===a){if(o-c.createdAt>12e4){a6.current.delete(b);continue}if(c.confirmKey){let a=l.get(c.confirmKey)??0,d=m.get(c.confirmKey)??0;a-d>c.confirmCountAtCreate&&(a6.current.delete(b),m.set(c.confirmKey,d+1))}}if(a7.current=l,!a$.current){var d;let b=i.context.entryIds??[],e=[...a6.current.values()].filter(c=>aS(c,a,b)).map(a=>a.message),f=e.length>0?[...j,...e]:j,g=f.length;!c&&bd.current>g?(z(i.totalMessages??i.context.messages.length),B(i.hasMore??!1)):(v(f),x(b),c?bd.current=g:bd.current=Math.max(bd.current,g)),c||(d={sessionId:a,leafId:i.leafId,messages:f,entryIds:b,totalMessages:i.totalMessages??i.context.messages.length,hasMore:i.hasMore??!1,loadedMessagesCount:i.context.messages.length},aJ().entries.set(a,{...d,loadedAt:Date.now()}))}return as(a=>{if(!a)return null;let b=i.context.model;return b?.provider===a.provider&&b.modelId===a.modelId?null:a}),r(null),!i.agentState?.state?.thinkingLevel&&i.context.thinkingLevel&&"off"!==i.context.thinkingLevel&&ad(i.context.thinkingLevel),i.agentState?.state?.planMode&&k?.(i.agentState.state.planMode),i.agentState??null}catch(a){return r(String(a)),null}finally{b&&p(!1)}},[k,bp]),br=(0,e.useRef)(!1),bs=(0,e.useCallback)(async()=>{if(br.current)return;br.current=!0;let a=aZ.current;if(!a){br.current=!1;return}try{let b=await fetch(`/api/sessions/${encodeURIComponent(a)}?limit=50&offset=${E}`);if(!b.ok)return;let c=await b.json(),d=c.context.messages,e=c.context.entryIds??[];v(a=>[...d,...a]),x(a=>[...e,...a]),K(a=>a+d.length),B(c.hasMore??!1),aL(a,d,e,c.hasMore??!1,E+d.length)}catch{}finally{br.current=!1}},[E]),bt=(0,e.useCallback)(async(a,b)=>{try{let c=b?`/api/sessions/${encodeURIComponent(a)}/context?leafId=${encodeURIComponent(b)}`:`/api/sessions/${encodeURIComponent(a)}/context`,d=await fetch(c);if(!d.ok)throw Error(`HTTP ${d.status}`);let e=await d.json(),f=e.context.messages,g=e.context.entryIds??[],h=aR(f),i=new Map,j=Date.now();for(let[b,c]of a6.current)if(c.sessionId===a){if(j-c.createdAt>12e4){a6.current.delete(b);continue}if(c.confirmKey){let a=h.get(c.confirmKey)??0,d=i.get(c.confirmKey)??0;a-d>c.confirmCountAtCreate&&(a6.current.delete(b),i.set(c.confirmKey,d+1))}}a7.current=h;let k=[...a6.current.values()].filter(b=>aS(b,a,g)).map(a=>a.message);v(k.length>0?[...f,...k]:f),x(g)}catch(a){console.error("Failed to load context:",a)}},[]),bu=(0,e.useCallback)(async a=>{try{let b=await ao(a,{type:"get_tools"});if(b){let a,c,d,e;bg((c=(a=b.filter(a=>a.active).map(a=>a.name)).filter(a=>!D.includes(a)),d=J(a),e=J(c),""===d?"none":d===J(F)?"default":d===J(G)?"full":d===J(H)?"workbench":d===J(I)?"agent":""===e?"none":e===J(F)?"default":e===J(G)?"full":e===J(H)?"workbench":e===J(I)||a.includes(C)?"agent":"default")),bh(D.filter(a=>b.some(b=>b.active&&b.name===a)))}}catch(a){console.error("Failed to load tools:",a)}},[bh,bg]),bv=(0,e.useCallback)((a,b={})=>{aY.current?.close(),aY.current=null;let c=`/api/agent/${encodeURIComponent(a)}/events${b.replay?"?replay=1":""}`;return!function(a){let b=aF(a);if("active"===b.snapshot.phase)return aA(b,!0),aC(b),b.snapshot;let c=Date.now();b.snapshot={...ax(a),phase:"active",startedAt:c,lastEventAt:c,isStreaming:!0,streamingMessage:{role:"assistant",content:[]}},aC(b),aA(b,!0),b.snapshot}(a),new Promise((d,e)=>{let f=!1,g=null,h=a=>{if(!f){if(f=!0,clearTimeout(i),a){g?.close(),aY.current===g&&(aY.current=null),e(a);return}d()}},i=setTimeout(()=>{b.requireConnected?h(Error("Timed out waiting for event stream connection")):h()},b.timeoutMs??3e4);aY.current=g=function(a){let{url:b,onEvent:c,onStateChange:d,onFatalError:e,maxReconnectAttempts:f=1/0,reconnectBaseMs:g=1e3,reconnectMaxMs:h=3e4,autoReconnect:i=!0}=a,j="idle",k=new AbortController,l=0,m=null,n=!1,o=a=>{j!==a&&(j=a,d?.(a))},p=()=>{null!==m&&(clearTimeout(m),m=null)},q=()=>{if(n)return;if(!i)return void o("error");if(l>=f){o("error"),e?.(Error(`Max reconnect attempts (${f}) reached`));return}let a=Math.min(h,g*2**l);l+=1,o("connecting"),m=setTimeout(()=>{m=null,r()},a)},r=async()=>{if(!n){p(),k=new AbortController,o("connecting");try{let a=await fetch(b,{signal:k.signal,headers:{Accept:"text/event-stream","Cache-Control":"no-cache"}});if(!a.ok)throw Error(`HTTP ${a.status}: ${a.statusText}`);let d=a.body;if(!d)throw Error("Response has no readable body");let e=d.getReader();o("connected"),l=0,await ar(e,c,k.signal),e.releaseLock(),o("closed"),!n&&i&&q()}catch(a){if(n||a instanceof DOMException&&"AbortError"===a.name)return void o("closed");o("error"),i&&q()}}};return{get state(){return j},connect:()=>{n=!1,l=0,p(),r()},close:()=>{n=!0,p(),k.abort(),o("closed")},get abortController(){return k}}}({url:c,onEvent:a=>{try{let b=JSON.parse(a);"connected"===b.type&&h(),a_.current?.(b)}catch{}},onStateChange:c=>{!function(a,b){let c=av().get(a);if(!c)return;let d=c.connectionState;c.connectionState=b,"connected"===b&&"connected"!==d&&(c.snapshot={...c.snapshot,lastEventAt:Date.now(),lastHeartbeatAt:Date.now()},aC(c)),"connected"!==b&&"connected"===d&&aD(c)}(a,c),b.requireConnected&&"error"===c&&h(Error("Failed to connect event stream"))},reconnectBaseMs:1e3,reconnectMaxMs:3e4}),g.connect()})},[]),bw=(0,e.useCallback)(async(a,b="manual")=>{if(!a||aZ.current!==a)return;let c=ba.current;try{let b=await fetch(`/api/agent/${encodeURIComponent(a)}`),d=await b.json().catch(()=>({}));if(aZ.current!==a||ba.current!==c)return;if(d.running){if(a$.current=!0,P(!0),aV(a=>a??{kind:"waiting_model"}),!aY.current||"closed"===aY.current.state||"error"===aY.current.state){let b;(b=av().get(a))&&(b.snapshot={...b.snapshot,reconnectCount:b.snapshot.reconnectCount+1,lastSyncReason:"sse-reconnect",lastEventAt:Date.now()},aA(b,!0)),bv(a,{replay:!0})}}else a$.current=!1,aY.current?.close(),aY.current=null,aH(a),P(!1),aV(null),af(null),N({type:"end"}),await bq(a);d.state?.contextUsage!==void 0&&ah(d.state.contextUsage??null),d.state?.systemPrompt!==void 0&&aj(d.state.systemPrompt??null),d.state?.isCompacting!==void 0&&aB(d.state.isCompacting),d.state?.thinkingLevel!==void 0&&ad(d.state.thinkingLevel??"auto"),d.state?.planMode!==void 0&&k?.(d.state.planMode)}catch{}},[bv,bq,k]);a_.current=(0,e.useCallback)(a=>{bb.current=Date.now();let b=aZ.current;switch(b&&function(a,b){let c=aF(a),d=Date.now();switch(b.type){case"agent_start":if("active"===c.snapshot.phase)return aA(c,!0),c.snapshot;return aE(c),c.accumulatedText="",c.toolCalls.clear(),c.toolResults.clear(),c.activeToolId=null,c.snapshot={...ax(a),phase:"active",startedAt:d,lastEventAt:d,isStreaming:!0,streamingMessage:{role:"assistant",content:[]}},aC(c),aA(c,!0),c.snapshot;case"message_update":{let a=b.message;if(!a||"assistant"!==a.role)return c.snapshot;let e=a.content;for(let a of Array.isArray(e)?e:[])"object"==typeof a&&null!==a&&"type"in a&&("text"===a.type?c.accumulatedText=a.text??"":"toolCall"===a.type&&a.toolCallId&&!c.toolCalls.has(a.toolCallId)&&c.toolCalls.set(a.toolCallId,{...a,startedAt:d}));return aA(c,!1),c.snapshot}case"tool_execution_start":{let a="string"==typeof b.toolCallId?b.toolCallId:"",e="string"==typeof b.toolName?b.toolName:"tool",f=b.input??{};if(!a)return c.snapshot;let g=c.toolCalls.get(a);return c.toolCalls.set(a,{type:"toolCall",toolCallId:a,toolName:e,input:g?.input??f,startedAt:g?.startedAt??d}),c.activeToolId=a,aE(c),c.activeToolId&&(c.toolProgressTimer=setInterval(()=>aA(c,!0),1e3)),aA(c,!0),c.snapshot}case"tool_execution_end":{let a="string"==typeof b.toolCallId?b.toolCallId:"",e="string"==typeof b.toolName?b.toolName:"tool",f="string"==typeof b.result?b.result:JSON.stringify(b.result??"");if(a){let g=c.toolCalls.get(a);g&&c.toolCalls.set(a,{...g,endedAt:d}),c.toolResults.set(a,{role:"toolResult",toolCallId:a,toolName:e,content:[{type:"text",text:f}],isError:!!b.isError,timestamp:d}),c.activeToolId===a&&(c.activeToolId=null,aE(c))}return aA(c,!0),c.snapshot}case"message_end":return az(c),aA(c,!0),c.snapshot;case"agent_end":{az(c),aE(c),aD(c);let d="string"==typeof b.error?b.error:null;return c.activeToolId=null,c.snapshot={...c.snapshot,phase:d?"error":"completed",isStreaming:!1,streamingMessage:null,statusText:null,error:d},ay(a,d?{type:"error",snapshot:c.snapshot}:{type:"completed",snapshot:c.snapshot}),c.snapshot}case"heartbeat":return c.snapshot={...c.snapshot,lastHeartbeatAt:d},c.snapshot;default:return c.snapshot}}(b,a),a.type){case"agent_start":aX(null),a$.current=!0,P(!0),aV({kind:"waiting_model"}),N({type:"start"});break;case"agent_end":a$.current=!1,aY.current?.close(),aY.current=null,P(!1),aV(null),af(null),N({type:"end"}),aZ.current&&fetch(`/api/agent/${encodeURIComponent(aZ.current)}`).then(a=>a.json()).then(a=>{a.state?.contextUsage!==void 0&&ah(a.state.contextUsage??null),a.state?.systemPrompt!==void 0&&aj(a.state.systemPrompt??null),a.state?.isCompacting!==void 0&&aB(a.state.isCompacting)}).catch(()=>{}),f?.();break;case"message_start":case"message_update":{if(!a$.current)break;let b=a.message;if(b?.role==="user")break;b&&N({type:"update",message:an(b)}),aV(null);break}case"message_end":{if(!a$.current)break;let b=a.message;b&&"user"!==b.role&&v(a=>[...a,an(b)]),N({type:"reset"}),aV({kind:"waiting_model"});break}case"prompt_done":if(!a$.current)break;bw(aZ.current??"","prompt_done");break;case"tool_execution_start":{let b=a.toolCallId,c=a.toolName,d=a.args,e="bash"===c&&"string"==typeof d?.command?d.command:void 0;aV(a=>{let d=a?.kind==="running_tools"?[...a.tools]:[];return d.some(a=>a.id===b)||d.push({id:b,name:c,args:e}),{kind:"running_tools",tools:d}});break}case"tool_execution_end":{let b=a.toolCallId;aV(a=>{if(a?.kind!=="running_tools")return a;let c=a.tools.filter(a=>a.id!==b);return 0===c.length?{kind:"waiting_model"}:{kind:"running_tools",tools:c}});break}case"auto_retry_start":af({attempt:a.attempt,maxAttempts:a.maxAttempts,errorMessage:a.errorMessage});break;case"auto_retry_end":af(null);break;case"auto_compaction_start":case"compaction_start":aB(!0),aT(null);break;case"auto_compaction_end":case"compaction_end":aB(!1),a.errorMessage?aT(a.errorMessage):!a.aborted&&aZ.current&&bq(aZ.current)}},[bq,f]);let bx=(0,e.useCallback)(async(a,e,f,h)=>{if(!a.trim()&&!e?.length&&!f?.length||O)return;ba.current+=1;let i=bl(f),j=a.trim()?i?`${a}
7
+ [truncated after 60000 characters]`,truncated:!0};if(!f)return{extractionError:"No extractable text found"};return{extractedText:f,truncated:g}}catch(a){return{extractionError:a instanceof Error?a.message:String(a)}}}let S=(0,e.forwardRef)(function({onSend:a,onAbort:b,onSteer:c,onFollowUp:f,isStreaming:g,model:h,modelNames:i,modelList:j,onModelChange:k,onCompact:l,onAbortCompaction:m,isCompacting:n,compactError:o,toolPreset:p,sessionKind:q,onToolPresetChange:r,memoryTools:s,onMemoryToolsChange:t,thinkingLevel:u,onThinkingLevelChange:v,availableThinkingLevels:w,thinkingLevelMap:x,retryInfo:y,soundEnabled:z,onSoundToggle:A,planMode:B,onPlanModeChange:M,cornerBadge:N,promptHistory:O,sessionHistoryKey:P,activeFilePath:Q,onDismissFileContext:S},T){let U,V,W,[X,Y]=(0,e.useState)(""),[Z,$]=(0,e.useState)(!1),[_,aa]=(0,e.useState)(null),[ab,ac]=(0,e.useState)(!1),[ad,ae]=(0,e.useState)(!1),[af,ag]=(0,e.useState)(!1),[ah,ai]=(0,e.useState)(!1),[aj,ak]=(0,e.useState)(!1),[al,am]=(0,e.useState)(null),[an,ao]=(0,e.useState)([]),[ap,aq]=(0,e.useState)([]),ar=function(a=768){let[b,c]=(0,e.useState)(!1);return b}(),as=ar?{display:"none"}:void 0,at=ar?28:32,au=ar?"6px 8px":"8px 12px",av=ar?160:180,aw=ar&&!g,ax=aj?"var(--text)":"var(--text-muted)",ay={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},az=ar?{position:"sticky",bottom:0,zIndex:30,padding:"8px 0 calc(env(safe-area-inset-bottom, 0px) + 8px)",background:"linear-gradient(to top, color-mix(in srgb, var(--bg) 96%, transparent), color-mix(in srgb, var(--bg) 86%, transparent))",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",borderTop:"1px solid color-mix(in srgb, var(--border) 65%, transparent)"}:{flexShrink:0,background:"transparent",padding:"0 16px 8px",paddingRight:52},[aA,aB]=(0,e.useState)(null),aC=(0,e.useRef)(null),aD=(0,e.useRef)(null),aE=(0,e.useRef)(null),aF=(0,e.useRef)(null),aG=(0,e.useRef)(null),aH=(0,e.useRef)(null),aI=(0,e.useRef)(null),aJ=(0,e.useRef)(null),aK=(0,e.useRef)(null),aL=(0,e.useRef)(null),aM=(0,e.useCallback)(a=>{let b=aC.current;if(!b)return void Y(b=>b+(b?" ":"")+a);let c=b.selectionStart??b.value.length,d=b.selectionEnd??b.value.length,e=b.value.slice(0,c),f=b.value.slice(d),g=!(e.length>0)||e.endsWith(" ")||e.endsWith("\n")?"":" ";Y(e+g+a+f),requestAnimationFrame(()=>{let b=aC.current;if(!b)return;let d=c+g.length+a.length;b.setSelectionRange(d,d),b.focus(),b.style.height="auto",b.style.height=`${Math.min(b.scrollHeight,200)}px`})},[]);(0,e.useImperativeHandle)(T,()=>({insertIfEmpty(a){let b=aC.current;(b?b.value:X).trim()||(Y(a),requestAnimationFrame(()=>{b&&(b.focus(),b.style.height="auto",b.style.height=`${Math.min(b.scrollHeight,200)}px`)}))},insertText(a){aM(a)},addImages(a){aN(a)},addFiles(a){aO(a)}}));let aN=(0,e.useCallback)(async a=>{let b=a.filter(a=>a.type.startsWith("image/"));if(!b.length)return;let c=await Promise.all(b.map(a=>new Promise((b,c)=>{let d=new FileReader;d.onload=()=>{b({data:d.result.split(",")[1],mimeType:a.type,previewUrl:URL.createObjectURL(a)})},d.onerror=c,d.readAsDataURL(a)})));ao(a=>[...a,...c])},[]),aO=(0,e.useCallback)(async a=>{let b=a.filter(a=>a.type.startsWith("image/")),c=a.filter(a=>!a.type.startsWith("image/"));if(b.length&&aN(b),c.length){let a=await Promise.all(c.map(a=>new Promise((b,c)=>{let d=new FileReader;d.onload=async()=>{let c=d.result,e=await R(a,c);b({data:c,fileName:a.name,mimeType:a.type||"application/octet-stream",size:a.size,...e})},d.onerror=c,d.readAsArrayBuffer(a)})));aq(b=>[...b,...a])}},[aN]),aP=(0,e.useCallback)(a=>{ao(b=>{let c=[...b];return URL.revokeObjectURL(c[a].previewUrl),c.splice(a,1),c})},[]),aQ=(0,e.useCallback)(a=>{aq(b=>{let c=[...b];return c.splice(a,1),c})},[]),aR=(0,e.useCallback)(()=>{ao(a=>(a.forEach(a=>URL.revokeObjectURL(a.previewUrl)),[])),aq([])},[]),aS=j&&j.length>0?j.map(a=>({provider:a.provider,modelId:a.id,name:a.name,input:a.input})):Object.entries(i??{}).map(([a,b])=>({provider:h?.provider??"unknown",modelId:a,name:b})),aT=[];for(let a of aS){let b=aT.find(b=>b.provider===a.provider);b?b.options.push(a):aT.push({provider:a.provider,options:[a]})}let aU=h?aS.find(a=>a.modelId===h.modelId&&a.provider===h.provider)?.name??h.modelId:aS.length>0?aS[0].name:null,aV=h?aS.find(a=>a.modelId===h.modelId&&a.provider===h.provider):aS[0],aW=aV?.input?.includes("image")??!0,aX=an.length>0&&aV?.input!==void 0&&!aW,aY=(!!X.trim()||an.length>0||ap.length>0)&&!aX,aZ=l?K:K.filter(a=>"/compact"!==a.command),a$=aZ.filter(a=>"native"===a.kind),a_=aZ.filter(a=>"shortcut"===a.kind),a0=s??[],a1=a0.length>0?`${a0.length} enabled`:"off",a2=aS.length>0&&!!aU&&!!k,a3=!!v,a4=!!r&&"workbench"!==q,a5=!!t,a6=aU??"Default",a7=(()=>{let a=u??"auto";if("auto"===a||!x)return a;let b=x[a];return null!=b?b:a})(),a8=(p??"full")==="workbench"?"workbench":Object.entries(F).find(([,a])=>a===(p??"full"))?.[0]??"full",a9=ar?26:32,ba=ar?7:9,bb=ar?3:6,bc={position:"fixed",left:8,right:8,bottom:"calc(env(safe-area-inset-bottom, 0px) + 8px)",zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 -6px 24px rgba(0,0,0,0.14)",overflow:"hidden",maxHeight:"min(60dvh, 420px)"},bd=ar&&(Z||ab||ad||af||ah||aj);(0,e.useEffect)(()=>{aX||aB(null)},[aX]);let be=(0,e.useCallback)(a=>{if(!X.trim()){Y(a),requestAnimationFrame(()=>{let b=aC.current;b&&(b.focus(),b.setSelectionRange(a.length,a.length),b.style.height="auto",b.style.height=`${Math.min(b.scrollHeight,200)}px`)});return}aM(a)},[aM,X]),bf=(0,e.useCallback)(()=>{let b=X.trim();if(b||an.length||ap.length){if(an.length&&!aW)return void aB("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!g){if("/compact"===b&&!an.length&&!ap.length&&l){n?m?.():l(),Y(""),aC.current&&(aC.current.style.height="auto");return}a(b,an.length?an:void 0,ap.length?ap:void 0),Y(""),aR(),aC.current&&(aC.current.style.height="auto")}}},[X,an,ap,aW,g,a,aR,l,m,n]),bg=(0,e.useCallback)(a=>{let b=X.trim();if(!b&&!an.length&&!ap.length)return;if(an.length&&!aW)return void aB("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let d=an.length?an:void 0,e=ap.length?ap:void 0;"steer"===a&&c?c(b,d,e):"followup"===a&&f&&f(b,d,e),Y(""),aR(),aC.current&&(aC.current.style.height="auto")},[X,an,ap,aW,c,f,aR]),bh=O??[],bi=P??null,bj=(0,e.useCallback)(a=>{if("ArrowUp"===a.key&&!a.shiftKey&&!a.ctrlKey&&!a.metaKey&&bh.length>0){let b=aC.current;if(!b)return;let c=b.selectionStart??0;if(b.value.slice(0,c).includes("\n"))return;a.preventDefault();let d=function(a,b,c){let d;if(!a||0===c.length)return null;let e=((d=D.get(a))||(d={cursor:-1,draftSnapshot:""},D.set(a,d)),d);if(-1===e.cursor)e.draftSnapshot=b,e.cursor=0;else{if(!(e.cursor<c.length-1))return null;e.cursor+=1}return c[e.cursor]??null}(bi,b.value,bh);null!==d&&(Y(d),requestAnimationFrame(()=>{b.setSelectionRange(d.length,d.length)}));return}if("ArrowDown"===a.key&&!a.shiftKey&&!a.ctrlKey&&!a.metaKey&&function(a){if(!a)return!1;let b=D.get(a);return(b?.cursor??-1)>=0}(bi)){a.preventDefault();let b=function(a,b){if(!a)return null;let c=D.get(a);if(!c||-1===c.cursor)return null;if(c.cursor>0)return c.cursor-=1,{text:b[c.cursor]??"",returnedToPresent:!1};let d=c.draftSnapshot;return c.cursor=-1,c.draftSnapshot="",{text:d,returnedToPresent:!0}}(bi,bh);b&&(Y(b.text),b.returnedToPresent&&requestAnimationFrame(()=>{let a=aC.current;a&&a.setSelectionRange(b.text.length,b.text.length)}));return}"Enter"===a.key&&!a.shiftKey&&!a.nativeEvent.isComposing&&(a.preventDefault(),bi&&D.set(bi,{cursor:-1,draftSnapshot:""}),g&&(c||f)?bg(c?"steer":"followup"):bf())},[g,c,f,bg,bf,bh,bi]),bk=(0,e.useCallback)(()=>{let a=aC.current;a&&(a.style.height="auto",a.style.height=`${Math.min(a.scrollHeight,200)}px`)},[]),bl=(0,e.useCallback)(a=>{let b=Array.from(a.clipboardData?.items??[]).filter(a=>"file"===a.kind&&(a.type.startsWith("image/")||a.type.includes("pdf")||a.type.includes("officedocument")||a.type.includes("msword")||a.type.includes("ms-")));b.length&&(a.preventDefault(),aO(b.map(a=>a.getAsFile()).filter(a=>null!==a)))},[aO]);return(0,e.useEffect)(()=>{if(!Z&&!ab&&!ad&&!af&&!ah&&!aj)return;let a=a=>{let b=a.target;if(!(b instanceof Node))return;let c=!!aD.current?.contains(b),d=!!aE.current?.contains(b);c||d||$(!1),aF.current?.contains(b)||ac(!1),aG.current?.contains(b)||ae(!1),aH.current?.contains(b)||ag(!1),aI.current?.contains(b)||ai(!1),aJ.current?.contains(b)||ak(!1)};return document.addEventListener("pointerdown",a,!0),()=>{document.removeEventListener("pointerdown",a,!0)}},[Z,ab,ad,af,ah,aj]),(0,e.useEffect)(()=>{if(!r)return;let a=!1;return fetch("/api/subagents/status").then(a=>a.ok?a.json():null).then(b=>{a||am(!!b?.ready)}).catch(()=>{a||am(!1)}),()=>{a=!0}},[r]),(0,d.jsxs)("div",{style:az,children:[bd&&(0,d.jsx)("div",{"aria-hidden":!0,onClick:()=>{$(!1),ac(!1),ae(!1),ag(!1),ai(!1),ak(!1)},style:{position:"fixed",inset:0,zIndex:490,background:"rgba(15, 23, 42, 0.18)",backdropFilter:"blur(1.5px)",WebkitBackdropFilter:"blur(1.5px)"}}),(0,d.jsx)("input",{ref:aK,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:a=>{aN(Array.from(a.target.files??[])),a.target.value=""}}),(0,d.jsx)("input",{ref:aL,type:"file",accept:".pdf,.docx,.xlsx,.pptx,.doc,.xls,.ppt,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.presentationml.presentation",multiple:!0,style:{display:"none"},onChange:a=>{aO(Array.from(a.target.files??[])),a.target.value=""}}),(0,d.jsxs)("div",{style:{maxWidth:ar?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:ar?"0 8px":void 0,boxSizing:"border-box"},children:[N&&(0,d.jsx)("div",{style:{position:"absolute",right:8,top:-22,display:"flex",alignItems:"center",justifyContent:"flex-end",maxWidth:"min(320px, 60vw)",minHeight:18,zIndex:2,fontFamily:"var(--font-mono)",overflow:"hidden"},children:N}),y&&(0,d.jsxs)("div",{style:{marginBottom:ar?6:8,padding:ar?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:ar?11:12,color:"rgba(180,130,0,0.9)",display:"flex",alignItems:"center",gap:6},children:[(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),(0,d.jsx)("path",{d:"M3 3v5h5"})]}),"Retrying (",y.attempt,"/",y.maxAttempts,")…",y.errorMessage&&(0,d.jsxs)("span",{style:{opacity:.7,marginLeft:4},children:["— ",y.errorMessage]})]}),Q&&(0,d.jsxs)("div",{style:{marginBottom:ar?6:8,padding:ar?"3px 8px":"4px 10px",background:"color-mix(in srgb, var(--accent) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--accent) 25%, transparent)",borderRadius:6,fontSize:ar?11:12,color:"var(--text-muted)",display:"inline-flex",alignItems:"center",gap:6,maxWidth:"100%"},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"}),(0,d.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,d.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Q.replace(/^.*[\\/]/,"")}),S&&(0,d.jsx)("button",{type:"button",onClick:a=>{a.stopPropagation(),S()},title:"Stop including this file in context",style:{background:"none",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:14,lineHeight:1,padding:"0 2px",flexShrink:0},children:"\xd7"})]}),(an.length>0||ap.length>0)&&(0,d.jsxs)("div",{style:{marginBottom:6},children:[(0,d.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"flex-end"},children:[an.map((a,b)=>(0,d.jsxs)("div",{style:{position:"relative",flexShrink:0},children:[(0,d.jsx)("img",{src:a.previewUrl,alt:"",style:{width:56,height:56,objectFit:"cover",borderRadius:6,border:`1px solid ${aX?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,d.jsx)("button",{onClick:()=>aP(b),style:{position:"absolute",top:-4,right:-4,width:16,height:16,borderRadius:"50%",background:"var(--bg-panel)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,color:"var(--text-muted)"},children:(0,d.jsxs)("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,d.jsx)("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),(0,d.jsx)("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})})]},`img-${b}`)),ap.map((a,b)=>(0,d.jsx)(L,{doc:a,onRemove:()=>aQ(b)},`doc-${b}`))]}),(aX||aA)&&(0,d.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:ar?11:12,color:"rgba(185,28,28,0.95)"},children:[(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),(0,d.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,d.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),(0,d.jsx)("span",{children:aA??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,d.jsxs)("div",{style:{display:"flex",gap:ar?4:8,alignItems:ar?"flex-end":"center",background:"var(--bg)",border:`1px solid ${g&&(c||f)?"rgba(234,179,8,0.4)":"color-mix(in srgb, var(--border) 70%, transparent)"}`,borderRadius:ar?13:14,padding:ar?"8px 8px 8px 10px":"10px 10px 10px 14px",boxShadow:"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",transition:"border-color 0.15s, background 0.15s, box-shadow 0.15s"},children:[(0,d.jsx)("textarea",{ref:aC,value:X,onChange:a=>Y(a.target.value),onKeyDown:bj,onInput:bk,onPaste:bl,placeholder:g&&(c||f)?"Steer 立即注入 / Follow-up 排队…":g?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:ar?"stretch":void 0,background:"none",border:"none",outline:"none",resize:"none",color:"var(--text)",fontSize:14,lineHeight:1.6,fontFamily:"inherit",minHeight:24,maxHeight:200,overflow:"auto",paddingTop:+!!ar,paddingBottom:+!!ar}}),g?(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:ar?4:6,flexShrink:0,alignSelf:"flex-end"},children:[c&&(0,d.jsxs)("button",{onClick:()=>bg("steer"),disabled:!aY,title:aX?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!ar,padding:ar?"6px 8px":"7px 12px",background:aY?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:aY?"rgba(180,130,0,1)":"var(--text-dim)",cursor:aY?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M5 1 L9 5 L5 9"}),(0,d.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})]}),!ar&&"Steer"]}),f&&(0,d.jsxs)("button",{onClick:()=>bg("followup"),disabled:!aY,title:aX?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!ar,padding:ar?"6px 8px":"7px 12px",background:aY?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:aY?"rgba(99,102,241,1)":"var(--text-dim)",cursor:aY?"pointer":"not-allowed",fontSize:13,fontWeight:600,letterSpacing:"-0.01em",transition:"background 0.12s"},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("line",{x1:"5",y1:"1",x2:"5",y2:"6"}),(0,d.jsx)("polyline",{points:"2.5 3.5 5 1 7.5 3.5"}),(0,d.jsx)("line",{x1:"2",y1:"9",x2:"8",y2:"9"})]}),!ar&&"Follow-up"]})]}):(0,d.jsxs)("button",{onClick:bf,disabled:!aY,title:aX?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:ar?3:6,padding:ar?"5px 9px":"7px 14px",marginBottom:+!!ar,background:aY?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:aY?"#fff":"var(--text-dim)",cursor:aY?"pointer":"not-allowed",fontSize:ar?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:aY?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,d.jsxs)("svg",{width:ar?13:14,height:ar?13:14,viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("line",{x1:"2",y1:"7",x2:"11",y2:"7"}),(0,d.jsx)("polyline",{points:"7.5 3 12 7 7.5 11"})]}),"Send"]})]}),(0,d.jsxs)("div",{className:"chat-input-toolbar",style:{marginTop:ar?5:8,display:"flex",alignItems:ar?"flex-start":"center",gap:bb,flexWrap:ar?"wrap":"nowrap"},children:[(0,d.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:ar?"1 1 100%":"0 0 auto",width:ar?"100%":void 0,display:"flex",alignItems:"center",gap:2*!ar,flexWrap:ar?"wrap":"nowrap",rowGap:4*!!ar},children:[(0,d.jsx)("button",{onClick:()=>aK.current?.click(),disabled:g,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:a9,height:a9,padding:0,background:"none",border:"none",borderRadius:ba,color:an.length||ap.length?"var(--accent)":"var(--text-muted)",cursor:g?"not-allowed":"pointer",opacity:g?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{g||(a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color=an.length||ap.length?"var(--accent)":"var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background="none",a.currentTarget.style.color=an.length||ap.length?"var(--accent)":"var(--text-muted)"},onContextMenu:a=>{a.preventDefault(),aL.current?.click()},children:(0,d.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),(0,d.jsxs)("div",{ref:aF,style:{position:"relative"},children:[(0,d.jsxs)("button",{onClick:()=>{g||(ac(a=>!a),ae(!1),$(!1),ag(!1),ai(!1),ak(!1))},disabled:g,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:a9,height:a9,padding:0,background:ab?"var(--bg-hover)":"none",border:"none",borderRadius:ba,color:o?"#ef4444":"var(--text-muted)",cursor:g?"not-allowed":"pointer",opacity:g?.5:1,fontSize:15,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{g||(a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color=o?"#ef4444":"var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background=ab?"var(--bg-hover)":"none",a.currentTarget.style.color=o?"#ef4444":"var(--text-muted)"},children:["/",o&&(0,d.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"#ef4444"}})]}),ab&&(0,d.jsxs)("div",{style:{...ar?bc:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:320,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,d.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:o?"1px solid var(--border)":"none"},children:"Commands"}),o&&(0,d.jsx)("div",{style:{padding:"7px 10px",fontSize:11,color:"#ef4444",background:"rgba(239,68,68,0.06)",borderBottom:"1px solid var(--border)",lineHeight:1.45},children:o}),a$.length>0&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Native"}),a$.map(a=>(0,d.jsxs)("button",{onClick:()=>{(ac(!1),"/compact"===a.command&&n)?m?.():be(a.command)},style:{display:"flex",alignItems:"center",gap:ar?6:8,width:"100%",padding:au,background:"none",border:"none",color:"/compact"===a.command&&n?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:ar?11:12,textAlign:"left"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="none"},children:[(0,d.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"/compact"===a.command&&n?"#ef4444":"var(--text-dim)"},children:"/compact"===a.command&&n?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,d.jsx)("rect",{x:"2",y:"2",width:"6",height:"6",rx:"1",fill:"currentColor"})}):(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,d.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,d.jsx)("line",{x1:"10",y1:"14",x2:"3",y2:"21"}),(0,d.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"})]})}),(0,d.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,d.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:"/compact"===a.command&&n?"停止压缩":a.label}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:"/compact"===a.command&&n?"中止当前压缩任务":a.description})]})]},a.command))]}),a_.length>0&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{style:{marginTop:2*(a$.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:a$.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),a_.map(a=>(0,d.jsxs)("button",{onClick:()=>{ac(!1),be(a.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:au,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:ar?11:12,textAlign:"left"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="none"},children:[(0,d.jsx)("span",{style:{width:18,flexShrink:0,display:"flex",justifyContent:"center",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:13},children:"/"}),(0,d.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,d.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:a.label}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:a.description})]})]},a.command))]})]})]}),t&&(0,d.jsxs)("div",{ref:aG,style:{position:"relative"},children:[(0,d.jsxs)("button",{onClick:()=>{g||(ae(a=>!a),ac(!1),$(!1),ag(!1),ai(!1),ak(!1))},disabled:g,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:at,padding:0,background:ad?"var(--bg-hover)":"none",border:"none",borderRadius:ar?8:9,color:a0.length>0?"var(--accent)":"var(--text-muted)",cursor:g?"not-allowed":"pointer",opacity:g?.5:1,fontSize:13,fontWeight:700,fontFamily:"var(--font-mono)",transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{g||(a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color=a0.length>0?"var(--accent)":"var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background=ad?"var(--bg-hover)":"none",a.currentTarget.style.color=a0.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),a0.length>0&&(0,d.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),ad&&(0,d.jsxs)("div",{style:{...ar?bc:{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:100,minWidth:280,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)"},overflow:"hidden"},children:[(0,d.jsx)("div",{style:{padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderBottom:"1px solid var(--border)"},children:"Memory Tools"}),C.SN.map(a=>{let b=a0.includes(a),c=H[a];return(0,d.jsxs)("button",{onClick:()=>{t(b?a0.filter(b=>b!==a):[...a0,a])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:au,background:b?"var(--bg-selected)":"none",border:"none",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ar?11:12,textAlign:"left"},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="none")},children:[b?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,d.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),(0,d.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:8},children:[(0,d.jsx)("span",{style:{fontFamily:"var(--font-mono)",color:"var(--text)"},children:c.label}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:c.description})]})]},a)})]})]}),a2&&(0,d.jsxs)("div",{ref:aD,style:{position:"relative",flex:ar?"1 1 160px":void 0,minWidth:0},children:[(0,d.jsxs)("button",{onClick:a=>{if(!ar){let b=a.currentTarget.getBoundingClientRect();aa({top:b.top,left:b.left,width:b.width})}ac(!1),ae(!1),ag(!1),ai(!1),ak(!1),$(a=>!a)},disabled:g,style:{display:"flex",alignItems:"center",gap:6,padding:au,height:at,width:ar?"100%":void 0,maxWidth:ar?"100%":220,overflow:"hidden",background:Z?"var(--bg-hover)":"none",border:"none",borderRadius:ar?8:9,color:"var(--text-muted)",cursor:g?"not-allowed":"pointer",fontSize:ar?11:12,opacity:g?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{g||(a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background=Z?"var(--bg-hover)":"none",a.currentTarget.style.color="var(--text-muted)"},children:[(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,d.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,d.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,d.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,d.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,d.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,d.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,d.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,d.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,d.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,d.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:aU})]}),Z&&(ar?(0,d.jsxs)("div",{ref:aE,style:{...bc,display:"flex",flexDirection:"column"},children:[(0,d.jsxs)("div",{style:{padding:"8px 12px 6px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,d.jsx)("div",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Models"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:aU})]}),(0,d.jsx)("div",{style:{overflowY:"auto"},children:aT.map((a,b)=>(0,d.jsxs)("div",{children:[aT.length>1&&(0,d.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:b>0?"1px solid var(--border)":"none"},children:a.provider}),a.options.map(a=>{let b=a.modelId===h?.modelId&&a.provider===h?.provider;return(0,d.jsxs)("button",{onClick:()=>{$(!1),b||k(a.provider,a.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"10px 12px",background:b?"var(--bg-selected)":"none",border:"none",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:b?600:400},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="none")},children:[b?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,d.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),(0,d.jsx)("span",{style:{flex:1,minWidth:0,whiteSpace:"normal",lineHeight:1.35},children:a.name}),a.input?.includes("image")&&(0,d.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font-mono)",marginLeft:8},children:"image"})]},`${a.provider}:${a.modelId}`)})]},a.provider))})]}):_&&(V=(U=window.visualViewport?.height??window.innerHeight)-_.top+6,W=Math.max(120,Math.min(_.top-8,.6*U)),(0,d.jsx)("div",{ref:aE,style:{position:"fixed",bottom:V,left:_.left,zIndex:500,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",overflow:"hidden",width:"max-content",minWidth:_.width,maxHeight:W,overflowY:"auto"},children:aT.map((a,b)=>(0,d.jsxs)("div",{children:[aT.length>1&&(0,d.jsx)("div",{style:{padding:"6px 12px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:b>0?"1px solid var(--border)":"none"},children:a.provider}),a.options.map(a=>{let b=a.modelId===h?.modelId&&a.provider===h?.provider;return(0,d.jsxs)("button",{onClick:()=>{$(!1),b||k(a.provider,a.modelId)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:b?"var(--bg-selected)":"none",border:"none",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,textAlign:"left",fontWeight:b?600:400,whiteSpace:"nowrap"},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="none")},children:[b?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,d.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),(0,d.jsx)("span",{style:{flex:1,minWidth:0},children:a.name}),a.input?.includes("image")&&(0,d.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontFamily:"var(--font-mono)",marginLeft:12},children:"image"})]},`${a.provider}:${a.modelId}`)})]},a.provider))})))]}),ar&&!g&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{ref:aJ,style:{position:"relative",flexShrink:0},children:[(0,d.jsx)("button",{onClick:()=>{ac(!1),ae(!1),$(!1),ag(!1),ai(!1),ak(a=>!a)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:aj?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ax,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.background=aj?"var(--bg-hover)":"none",a.currentTarget.style.color=aj?"var(--text)":"var(--text-muted)"},children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,d.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,d.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),aj&&(0,d.jsxs)("div",{style:{...bc,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,d.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,d.jsxs)("div",{style:{display:"grid",gap:4},children:[a2&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),ai(!1),ag(!1),ae(!1),$(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:a6})]}),(a3||a4)&&(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[a3&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),$(!1),ag(!1),ae(!1),ai(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:a7})]}),a4&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),$(!1),ai(!1),ae(!1),ag(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:a8})]})]}),a5&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),$(!1),ai(!1),ag(!1),ae(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,d.jsx)("div",{style:{fontSize:12,color:a0.length>0?"var(--accent)":"var(--text)",marginTop:2},children:a1})]}),void 0!==M&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),M(!B)},style:{...ay,border:B?"1px solid rgba(59,130,246,0.24)":"none",background:B?"rgba(59,130,246,0.06)":"none"},children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Mode"}),(0,d.jsx)("div",{style:{fontSize:12,color:B?"#3b82f6":"var(--text)",marginTop:2},children:B?"Plan(只读规划)":"Code(可执行)"})]})]})]})]}),(0,d.jsx)("button",{onClick:A,title:z?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:"none",border:"none",borderRadius:8,color:z?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:z?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)",a.currentTarget.style.opacity="1"},onMouseLeave:a=>{a.currentTarget.style.background="none",a.currentTarget.style.color=z?"var(--text-muted)":"var(--text-dim)",a.currentTarget.style.opacity=z?"1":"0.55"},children:z?(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,d.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,d.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,d.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,d.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]}),(0,d.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:aw?"none":void 0,flex:ar?"0 0 auto":1,width:ar?0:void 0,height:ar?0:void 0}}),(0,d.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:"0 0 auto",width:ar?"auto":void 0,display:"flex",alignItems:"center",gap:ar?4:2,marginLeft:ar?0:"auto",marginTop:0},children:[aw&&!ar&&(0,d.jsxs)("div",{ref:aJ,style:{position:"relative"},children:[(0,d.jsx)("button",{onClick:()=>{ac(!1),ae(!1),$(!1),ag(!1),ai(!1),ak(a=>!a)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:aj?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:ax,cursor:"pointer",transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.background=aj?"var(--bg-hover)":"none",a.currentTarget.style.color=aj?"var(--text)":"var(--text-muted)"},children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,d.jsx)("circle",{cx:"12",cy:"12",r:"1.5"}),(0,d.jsx)("circle",{cx:"19",cy:"12",r:"1.5"})]})}),aj&&(0,d.jsxs)("div",{style:{...bc,zIndex:510,padding:"6px",display:"flex",flexDirection:"column",gap:4},children:[(0,d.jsx)("div",{style:{padding:"4px 6px 2px",fontSize:10,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"More"}),(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:"0 6px 4px"},children:"模型、推理、工具等设置已收进这里。"}),(0,d.jsxs)("div",{style:{display:"grid",gap:4},children:[a2&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),ai(!1),ag(!1),ae(!1),$(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Model"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2,wordBreak:"break-word",lineHeight:1.35},children:a6})]}),(a3||a4)&&(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[a3&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),$(!1),ag(!1),ae(!1),ai(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Thinking"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:a7})]}),a4&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),$(!1),ai(!1),ae(!1),ag(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Tools"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text)",marginTop:2},children:a8})]})]}),a5&&(0,d.jsxs)("button",{onClick:()=>{ak(!1),$(!1),ai(!1),ag(!1),ae(!0)},style:ay,children:[(0,d.jsx)("div",{style:{fontSize:"10px",color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Memory"}),(0,d.jsx)("div",{style:{fontSize:12,color:a0.length>0?"var(--accent)":"var(--text)",marginTop:2},children:a1})]})]})]})]}),(!aw&&!g||ar&&ah)&&v&&(0,d.jsxs)("div",{ref:aI,style:{position:"relative"},children:[!aw&&!g&&(0,d.jsxs)("button",{onClick:()=>{g||(ac(!1),ae(!1),$(!1),ag(!1),ak(!1),ai(a=>!a))},disabled:g,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:ar?3:5,padding:au,height:at,background:ah?"var(--bg-hover)":"none",border:"none",borderRadius:ar?8:9,color:"var(--text-muted)",cursor:g?"not-allowed":"pointer",fontSize:ar?11:12,opacity:g?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{g||(a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background=ah?"var(--bg-hover)":"none",a.currentTarget.style.color="var(--text-muted)"},children:[(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M9.5 2A5.5 5.5 0 0 0 4 7.5c0 1.7.78 3.21 2 4.21V14a1 1 0 0 0 1 1h5a1 1 0 0 0 1-1v-2.29c1.22-1 2-2.51 2-4.21A5.5 5.5 0 0 0 9.5 2z"}),(0,d.jsx)("line",{x1:"7",y1:"18",x2:"12",y2:"18"}),(0,d.jsx)("line",{x1:"8",y1:"21",x2:"11",y2:"21"})]}),(0,d.jsx)("span",{style:as,children:(()=>{let a=u??"auto";if("auto"===a||!x)return a;let b=x[a];return null!=b?b:a})()})]}),ah&&(0,d.jsx)("div",{style:{...ar?bc:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:av},overflow:"hidden"},children:I.filter(a=>!w||"auto"===a||w.includes(a)).map(a=>{let b=(u??"auto")===a,c=J[a],e="auto"!==a&&x?x[a]:void 0,f=null!=e&&e!==a?e:a,g=null!=e&&e!==a;return(0,d.jsxs)("button",{onClick:()=>{ai(!1),b||v(a)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:b?"var(--bg-selected)":"none",border:"none",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:ar?11:12,textAlign:"left",fontWeight:b?600:400,whiteSpace:"nowrap"},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="none")},children:[b?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,d.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),(0,d.jsxs)("span",{style:{flex:1},children:[f,g&&(0,d.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",fontFamily:"var(--font-mono)",marginLeft:5},children:["(",a,")"]})]}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:c})]},a)})})]}),(!aw&&!g||ar&&af)&&a4&&(0,d.jsxs)("div",{ref:aH,style:{position:"relative"},children:[!aw&&!g&&(0,d.jsxs)("button",{onClick:()=>{g||(ac(!1),ae(!1),$(!1),ai(!1),ak(!1),ag(a=>!a))},disabled:g,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:ar?3:5,padding:au,height:at,background:af?"var(--bg-hover)":"none",border:"none",borderRadius:ar?8:9,color:(p??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:g?"not-allowed":"pointer",fontSize:ar?11:12,opacity:g?.5:1,transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{g||(a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color=(p??"full")==="workbench"?"var(--accent)":"var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background=af?"var(--bg-hover)":"none",a.currentTarget.style.color=(p??"full")==="workbench"?"var(--accent)":"var(--text-muted)"},children:[(0,d.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),(0,d.jsx)("span",{style:as,children:a8})]}),af&&(0,d.jsx)("div",{style:{...ar?bc:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:100,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 -4px 16px rgba(0,0,0,0.10)",minWidth:120},overflow:"hidden"},children:E.map(a=>{let b=F[a],c=(p??"full")===b,e="agent"===a&&!1===al,f=e?"需安装 pi-subagents":G[a];return(0,d.jsxs)("button",{onClick:()=>{!e&&(ag(!1),c||r(b))},disabled:e,title:e?"运行 pi install npm:pi-subagents 后再启用":void 0,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"7px 12px",background:c?"var(--bg-selected)":"none",border:"none",color:c?"var(--text)":"var(--text-muted)",cursor:e?"not-allowed":"pointer",fontSize:ar?11:12,textAlign:"left",fontWeight:c?600:400,opacity:e?.5:1,whiteSpace:"nowrap"},onMouseEnter:a=>{c||e||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{c||(a.currentTarget.style.background="none")},children:[c?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:(0,d.jsx)("polyline",{points:"1.5 5 4 7.5 8.5 2.5"})}):(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),(0,d.jsx)("span",{style:{flex:1},children:a}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",marginLeft:8},children:f})]},a)})})]}),g&&(0,d.jsxs)("button",{onClick:b,title:"停止 Agent",style:{display:"flex",alignItems:"center",gap:6,padding:"8px 14px",height:at,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:ar?8:9,color:"#ef4444",cursor:"pointer",fontSize:ar?11:12,fontWeight:600,whiteSpace:"nowrap",letterSpacing:"-0.01em",transition:"background 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="rgba(239,68,68,0.16)"},onMouseLeave:a=>{a.currentTarget.style.background="rgba(239,68,68,0.08)"},children:[(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",children:(0,d.jsx)("rect",{x:"1.5",y:"1.5",width:"7",height:"7",rx:"1.5",fill:"currentColor"})}),"Stop"]}),!aw&&void 0!==M&&(0,d.jsxs)("button",{onClick:()=>{g||M(!B)},disabled:g,title:B?"切换到 Code 模式(可执行代码)":"切换到 Plan 模式(只读规划)",style:{display:"flex",alignItems:"center",gap:6,padding:au,height:at,background:B?"rgba(59,130,246,0.08)":"none",border:B?"1px solid rgba(59,130,246,0.24)":"none",borderRadius:ar?8:9,color:B?"#3b82f6":"var(--text-muted)",cursor:g?"not-allowed":"pointer",fontSize:ar?11:12,opacity:g?.5:1,transition:"background 0.12s, color 0.12s, border-color 0.12s"},onMouseEnter:a=>{g||(a.currentTarget.style.background=B?"rgba(59,130,246,0.14)":"var(--bg-hover)",a.currentTarget.style.color=B?"#3b82f6":"var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background=B?"rgba(59,130,246,0.08)":"none",a.currentTarget.style.color=B?"#3b82f6":"var(--text-muted)"},children:[(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,d.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,d.jsx)("span",{style:as,children:B?"Plan":"Code"})]}),!ar&&void 0!==A&&(0,d.jsx)("button",{onClick:A,title:z?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:ar?28:32,height:ar?28:32,padding:0,background:"none",border:"none",borderRadius:ar?8:9,color:z?"var(--text-muted)":"var(--text-dim)",cursor:"pointer",opacity:z?1:.55,transition:"background 0.12s, color 0.12s, opacity 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)",a.currentTarget.style.opacity="1"},onMouseLeave:a=>{a.currentTarget.style.background="none",a.currentTarget.style.color=z?"var(--text-muted)":"var(--text-dim)",a.currentTarget.style.opacity=z?"1":"0.55"},children:z?(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,d.jsx)("path",{d:"M15.54 8.46a5 5 0 0 1 0 7.07"}),(0,d.jsx)("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14"})]}):(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),(0,d.jsx)("line",{x1:"23",y1:"9",x2:"17",y2:"15"}),(0,d.jsx)("line",{x1:"17",y1:"9",x2:"23",y2:"15"})]})})]})]})]})]})});function T(a){return"user"===a.role?{bg:"rgba(37,99,235,0.18)",border:"rgba(37,99,235,0.7)"}:{bg:"rgba(107,114,128,0.12)",border:"rgba(107,114,128,0.5)"}}function U({messages:a,streamingMessage:b,scrollContainer:c,messageRefs:f}){let[g,h]=(0,e.useState)(0),[i,j]=(0,e.useState)(1),[k,l]=(0,e.useState)(!1),[m,n]=(0,e.useState)([]),[o,p]=(0,e.useState)(!1),[q,r]=(0,e.useState)(null),s=(0,e.useRef)(!1),t=(0,e.useRef)(null),u=(0,e.useMemo)(()=>b?[...a,b]:a,[a,b]),v=(0,e.useRef)(u);v.current=u;let w=(0,e.useRef)(null);w.current=()=>{let a=c.current;if(!a)return;let b=a.scrollHeight,d=a.clientHeight,e=b-d;l(e>20),e<=0?(h(0),j(1)):(h(a.scrollTop/e),j(d/b));let g=f.current,i=[],k=0,m=v.current;for(let c=0;c<m.length;c++){let d=m[c];if("user"!==d.role&&"assistant"!==d.role)continue;let e=g?.[k];if(k++,("user"===d.role||"assistant"===d.role&&(d.content??[]).some(a=>"text"===a.type))&&e&&b>0){let c=e.getBoundingClientRect(),f=a.getBoundingClientRect(),g=c.top-f.top+a.scrollTop,h=c.height;i.push({topRatio:g/b,heightRatio:h/b,msg:d,index:i.length})}}n(i)},(0,e.useCallback)(()=>w.current(),[]);let x=(0,e.useCallback)(a=>{let b=c.current;if(!b)return;let d=b.scrollHeight-b.clientHeight;d<=0||(b.scrollTop=Math.max(0,Math.min(1-i,a))/(1-i)*d)},[c,i]),y=(0,e.useCallback)(a=>{if(!k)return;s.current=!0;let b=a.currentTarget.getBoundingClientRect(),c=(a.clientY-b.top)/b.height,d=c-g*(1-i),e=d>=0&&d<=i?d:i/2;x(c-e);let f=a=>{s.current&&x((a.clientY-b.top)/b.height-e)},h=()=>{s.current=!1,window.removeEventListener("mousemove",f),window.removeEventListener("mouseup",h)};window.addEventListener("mousemove",f),window.addEventListener("mouseup",h)},[k,i,g,x]),z=t.current?.clientHeight??600,A=(0,e.useMemo)(()=>{if(!o||0===m.length)return[];let a=m.map(a=>Math.round(a.topRatio*z-11));for(let b=0;b<10;b++){for(let b=1;b<a.length;b++){let c=a[b-1]+22+2;a[b]<c&&(a[b]=c)}for(let b=a.length-2;b>=0;b--){let c=a[b+1]-22-2;a[b]>c&&(a[b]=c)}}for(let b=0;b<a.length;b++)a[b]=Math.max(0,Math.min(z-22,a[b]));return a},[o,m,z]);if(!k)return null;let B=g*(1-i)*100,C=100*i,D=null!==q&&m.length>0?m.reduce((a,b)=>Math.abs(b.topRatio-q)<Math.abs(m[a].topRatio-q)?b.index:a,0):null;return(0,d.jsxs)("div",{ref:t,onMouseDown:y,onMouseEnter:()=>p(!0),onMouseLeave:()=>{p(!1),r(null)},onMouseMove:a=>{let b=a.currentTarget.getBoundingClientRect();r((a.clientY-b.top)/b.height)},style:{width:36,flexShrink:0,position:"relative",cursor:"default",userSelect:"none",borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"visible"},children:[(0,d.jsx)("div",{style:{position:"absolute",left:0,right:0,top:`${B}%`,height:`${C}%`,background:"rgba(100,100,100,0.1)",borderTop:"1px solid rgba(100,100,100,0.2)",borderBottom:"1px solid rgba(100,100,100,0.2)",pointerEvents:"none",zIndex:1}}),m.map(a=>{let b=T(a.msg),c=o&&D===a.index,e="user"===a.msg.role,f=100*a.topRatio;return(0,d.jsx)("div",{style:{position:"absolute",top:`${f}%`,transform:"translateY(-50%)",left:0,right:0,height:"12px",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:2},children:(0,d.jsx)("div",{style:{width:e?8:6,height:e?8:6,borderRadius:e?2:"50%",background:b.bg,border:`1.5px solid ${b.border}`,flexShrink:0,transition:"transform 0.1s",transform:c?"scale(1.6)":"scale(1)"}})},a.index)}),(0,d.jsx)("div",{style:{position:"absolute",left:"50%",top:0,bottom:0,width:1,background:"var(--border)",transform:"translateX(-50%)",zIndex:0}}),o&&m.map((a,b)=>{let c=function(a){if("user"===a.role){let b=a.content;return"string"==typeof b?b.slice(0,200):Array.isArray(b)?b.filter(a=>"text"===a.type&&a.text).map(a=>a.text).join("\n").slice(0,200):""}if("assistant"===a.role){let b=a.content??[],c=b.filter(a=>"text"===a.type).map(a=>a.text).join(" ");if(c)return c.slice(0,200);let d=b.filter(a=>"toolCall"===a.type).map(a=>a.toolName);if(d.length)return d.join(", ")}return""}(a.msg),e=T(a.msg),f=D===a.index;return c&&0!==A.length?(0,d.jsx)("div",{style:{position:"absolute",top:A[b],right:"100%",marginRight:6,background:"var(--bg)",borderTop:`1px solid ${f?e.border:"var(--border)"}`,borderRight:`1px solid ${f?e.border:"var(--border)"}`,borderBottom:`1px solid ${f?e.border:"var(--border)"}`,borderLeft:`2px solid ${e.border}`,borderRadius:4,padding:"2px 7px",width:200,zIndex:100,pointerEvents:"none",opacity:f?1:.45,transition:"top 0.1s, opacity 0.1s"},children:(0,d.jsx)("div",{style:{fontSize:11,color:f?"var(--text)":"var(--text-muted)",lineHeight:1.4,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:c})},a.index):null})]})}function V(a){return"object"==typeof a&&null!==a&&!Array.isArray(a)}function W(a,b=220){if(!a)return;let c=a.trim();if(c)return c.length>b?`${c.slice(0,b)}...`:c}function X(...a){for(let b of a)if("string"==typeof b&&b.trim())return b}function Y(...a){for(let b of a)if("number"==typeof b&&Number.isFinite(b))return b}function Z(a){let b=new Map;for(let c of a){if("custom"===c.role&&"subagent-notify"===c.customType&&"string"==typeof c.content){let a=c.content.match(/^Background task (completed|failed|paused):\s*\*\*(.+?)\*\*(?:\s+\((.+?)\))?/);if(a){let d=`bg-${a[2]}-${c.timestamp??""}`;b.set(d,{id:d,agent:a[2],status:a[1],task:a[3],summary:W(c.content.split("\n").slice(3).join("\n")),timestamp:c.timestamp})}}if("assistant"===c.role){let a=c.content;if(!a)continue;for(let d of a)if("toolCall"===d.type&&"subagent"===d.toolName&&d.input){let a=d.input,e=a.agent??(a.chain?"chain":a.tasks?"parallel":a.action??"subagent"),f="string"==typeof a.task?a.task:void 0,g=d.toolCallId??`sub-${e}-${c.timestamp??Date.now()}`;b.set(g,{id:g,agent:e,status:"running",task:f,timestamp:c.timestamp})}}if("toolResult"===c.role){if(c.toolName&&"subagent"!==c.toolName||!c.toolCallId||!b.has(c.toolCallId))continue;let a=b.get(c.toolCallId),d=c.content.filter(a=>"text"===a.type).map(a=>a.text).join("\n");b.set(c.toolCallId,function(a,b,c){let d;if(!V(b))return{...a,summary:W(c)};let e=Array.isArray(b.results)?b.results.filter(V):[],f=e[0],g=f?.progressSummary,h=f&&(d=f.artifactPaths)?Object.values(d).filter(a=>"string"==typeof a&&a.trim().length>0):[],i=X(f?.finalOutput,f?.output,c);return{...a,mode:X(b.mode),runId:X(b.runId),agent:X(f?.agent,a.agent)??a.agent,task:X(f?.task,a.task),summary:W(i),model:X(f?.model),durationMs:Y(g?.durationMs),toolCount:Y(g?.toolCount),tokens:Y(g?.tokens),outputPath:X(f?.savedOutputPath,f?.artifactPaths?.outputPath),sessionFile:X(f?.sessionFile,f?.artifactPaths?.jsonlPath),artifacts:h,resultCount:e.length||void 0}}({...a,status:function(a){if(a.isError)return"failed";let b=a.details;return V(b)&&Array.isArray(b.results)&&b.results.some(a=>V(a)&&"number"==typeof a.exitCode&&0!==a.exitCode)?"failed":"completed"}(c)},c.details,d))}}return Array.from(b.values()).sort((a,b)=>(b.timestamp??0)-(a.timestamp??0))}function $({messages:a,runs:b}){let c=(0,e.useMemo)(()=>Z(a??[]),[a]),f=b??c,g=f.filter(a=>"running"===a.status),h=f.filter(a=>"running"!==a.status);return 0===f.length?null:(0,d.jsxs)("div",{style:{height:"100%",overflow:"auto",padding:12},children:[g.length>0&&(0,d.jsx)(_,{title:`Active (${g.length})`,runs:g}),h.length>0&&(0,d.jsx)(_,{title:`Completed (${h.length})`,runs:h,compact:g.length>0})]})}function _({title:a,runs:b,compact:c}){return(0,d.jsxs)("div",{style:{marginBottom:c?10:16},children:[(0,d.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",marginBottom:8,textTransform:"uppercase",letterSpacing:"0.05em"},children:a}),b.map(a=>(0,d.jsx)(aa,{run:a},a.id))]})}function aa({run:a}){let[b,c]=(0,e.useState)(!1),f="running"===a.status,g="completed"===a.status?"#22c55e":"failed"===a.status?"#ef4444":f?"var(--accent)":"var(--text-dim)",h="failed"===a.status?"rgba(248,113,113,0.35)":f?"rgba(99,102,241,0.25)":"var(--border)",i="failed"===a.status?"rgba(248,113,113,0.05)":f?"rgba(99,102,241,0.05)":"var(--bg-panel)",j=[a.mode,a.resultCount&&a.resultCount>1?`${a.resultCount} results`:void 0,void 0!==a.toolCount?`${a.toolCount} tools`:void 0,void 0!==a.tokens?`${a.tokens.toLocaleString()} tok`:void 0,void 0!==a.durationMs?`${Math.round(a.durationMs/1e3)}s`:void 0].filter(Boolean).join(" \xb7 "),k=!!(a.summary||a.outputPath||a.sessionFile||a.artifacts?.length||a.model||a.runId);return(0,d.jsxs)("div",{style:{borderRadius:6,border:`1px solid ${h}`,background:i,marginBottom:6,fontSize:12,overflow:"hidden"},children:[(0,d.jsxs)("button",{onClick:()=>k&&c(a=>!a),style:{display:"flex",alignItems:"center",gap:7,width:"100%",border:"none",background:"transparent",padding:"8px 10px",color:"var(--text-muted)",textAlign:"left",cursor:k?"pointer":"default"},children:[(0,d.jsx)(ab,{running:f,color:g}),(0,d.jsx)("span",{style:{fontWeight:650,color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.agent}),(0,d.jsx)("span",{style:{color:g,fontSize:10,fontWeight:700,flexShrink:0},children:a.status}),j&&(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto",whiteSpace:"nowrap"},children:j}),k&&(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:b?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,d.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),a.task&&(0,d.jsx)("div",{style:{padding:"0 10px 8px 25px",color:"var(--text-muted)",fontSize:11,lineHeight:1.4},children:W(a.task,150)}),b&&k&&(0,d.jsxs)("div",{style:{borderTop:`1px solid ${h}`,background:"var(--bg)",padding:"8px 10px",display:"flex",flexDirection:"column",gap:7},children:[a.summary&&(0,d.jsx)("pre",{style:{margin:0,color:"var(--text-muted)",fontSize:11,lineHeight:1.45,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:a.summary}),(0,d.jsx)(ac,{run:a})]})]})}function ab({running:a,color:b}){return(0,d.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:b,display:"inline-block",animation:a?"pulse 1.5s infinite":void 0,flexShrink:0}})}function ac({run:a}){let b=[a.model?["model",a.model]:void 0,a.runId?["run",a.runId]:void 0,a.outputPath?["output",a.outputPath]:void 0,a.sessionFile?["session",a.sessionFile]:void 0,...(a.artifacts??[]).slice(0,4).map((a,b)=>[`artifact ${b+1}`,a])].filter(Boolean);return 0===b.length?null:(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:3},children:b.map(([a,b])=>(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"58px minmax(0, 1fr)",gap:6,fontSize:10},children:[(0,d.jsx)("span",{style:{color:"var(--text-dim)",textTransform:"uppercase"},children:a}),(0,d.jsx)("span",{style:{color:"var(--text-muted)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:b,children:b})]},`${a}:${b}`))})}function ad({sessionKind:a,toolPreset:b,initialSourcePath:c,initialKernel:e,isNew:f,isStreaming:g=!1,onResume:h,onDismiss:i}){if(f||"workbench"!==a)return null;let j=c?c.replace(/\\/g,"/").split("/").filter(Boolean).pop()??c:null,k="workbench"===b;return(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 14px",background:"rgba(37,99,235,0.06)",borderBottom:"1px solid rgba(37,99,235,0.18)",fontSize:12,flexShrink:0},children:[(0,d.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M4 19V5"}),(0,d.jsx)("path",{d:"M4 19h16"}),(0,d.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,d.jsxs)("span",{style:{color:"var(--text)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["This is an ",(0,d.jsxs)("strong",{children:[k?"active":"inactive"," Workbench"]})," session",j&&(0,d.jsxs)("span",{style:{color:"var(--text-muted)"},children:[" \xb7 Source: ",(0,d.jsx)("code",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--accent)"},children:j})]}),e&&(0,d.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" \xb7 Kernel: ",e.toUpperCase()]})]}),(0,d.jsx)("div",{style:{flex:1}}),(0,d.jsx)("button",{type:"button",onClick:i,style:{border:"1px solid var(--border)",borderRadius:6,padding:"2px 10px",height:26,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:11},children:"Dismiss"}),(0,d.jsx)("button",{type:"button",onClick:h,disabled:g,title:g?"Wait until the agent finishes before updating Workbench":k?"Reload the initial data source into the warm runtime":"Restore Workbench tools and reload the initial data source",style:{border:"1px solid rgba(37,99,235,0.45)",borderRadius:6,padding:"2px 12px",height:26,background:"rgba(37,99,235,0.12)",color:"var(--accent)",cursor:g?"not-allowed":"pointer",fontSize:11,fontWeight:600,opacity:g?.55:1,whiteSpace:"nowrap"},children:k?"Reload Initial Data":"Resume Workbench"})]})}var ae=c(76195);let af=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function ag(a){return af.some(b=>a.type.startsWith(b))}function ah({agentPhase:a,startedAt:b}){let[c,f]=(0,e.useState)(0);return(0,d.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,d.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[function(a){if(a?.kind==="running_tools"){let b=a.tools.map(a=>a.args??a.name);return 0===b.length?"Running tool…":1===b.length?`Running ${b[0]}…`:`Running ${b.slice(0,2).join(", ")}${b.length>2?` (+${b.length-2})`:""}…`}return a?.kind==="waiting_model"?"Waiting for model…":"Working…"}(a),"\xa0\xa0",function(a){if(a<60)return`${a}s`;let b=Math.floor(a/60);return`${b}m ${String(a%60).padStart(2,"0")}s`}(c)]})})}function ai(a){return a>=1e6?`${(a/1e6).toFixed(1)}M`:a>=1e3?`${(a/1e3).toFixed(1)}K`:String(a)}function aj({goal:a,planTasks:b,isRunning:c,onExecutePlan:f,onContinuePlanning:g,onEditPlan:h}){let[i,j]=(0,e.useState)(!1),k=(0,e.useCallback)(()=>j(a=>!a),[]),l=a&&"dropped"!==a.status,m=b&&b.length>0;if(!l&&!m)return null;let n=(0,e.useMemo)(()=>!a?.tokenBudget||a.tokenBudget<=0?null:Math.min(100,Math.round(a.tokensUsed/a.tokenBudget*100)),[a?.tokenBudget,a?.tokensUsed]),o=b?.filter(a=>"completed"===a.status).length??0,p=!!b&&o===b.length;return(0,d.jsxs)("div",{style:{marginBottom:16,borderRadius:10,border:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"hidden"},children:[l&&(0,d.jsxs)("div",{style:{padding:"10px 14px",borderBottom:m?"1px solid var(--border)":"none"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[(0,d.jsx)("span",{style:{flexShrink:0,borderRadius:4,padding:"1px 6px",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"#fff",background:function(a){switch(a){case"active":return"rgba(37,99,235,0.85)";case"complete":return"rgba(34,197,94,0.85)";case"budget-limited":return"rgba(245,158,11,0.85)";case"paused":return"rgba(148,163,184,0.85)";case"dropped":return"rgba(239,68,68,0.85)"}}(a.status)},children:function(a){switch(a){case"active":return"进行中";case"paused":return"已暂停";case"budget-limited":return"预算受限";case"complete":return"已完成";case"dropped":return"已放弃"}}(a.status)}),(0,d.jsx)("span",{style:{fontSize:11,fontWeight:500,color:"var(--text-muted)"},children:"Goal"})]}),(0,d.jsx)("p",{style:{margin:"0 0 6px",fontSize:13,lineHeight:1.5,color:"var(--text)",whiteSpace:"pre-wrap"},children:a.objective}),(0,d.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"4px 16px",fontSize:11,color:"var(--text-muted)"},children:[(0,d.jsx)("span",{children:function(a){if(a<60)return`${a}s`;let b=Math.floor(a/60);if(b<60)return`${b}m ${String(a%60).padStart(2,"0")}s`;let c=Math.floor(b/60);return`${c}h ${b%60}m`}(a.timeUsedSeconds)}),(0,d.jsxs)("span",{children:[ai(a.tokensUsed),a.tokenBudget?` / ${ai(a.tokenBudget)} tokens`:" tokens"]}),null!=n&&(0,d.jsxs)("span",{children:[n,"%"]})]}),null!=n&&(0,d.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,overflow:"hidden",background:"var(--border)"},children:(0,d.jsx)("div",{style:{height:"100%",borderRadius:999,background:n>=100?"rgba(239,68,68,0.6)":"rgba(37,99,235,0.5)",width:`${Math.min(n,100)}%`,transition:"width 0.3s"}})})]}),m&&(0,d.jsxs)("div",{style:{padding:"4px 14px 10px"},children:[(0,d.jsxs)("div",{onClick:k,role:"button",tabIndex:0,onKeyDown:a=>{("Enter"===a.key||" "===a.key)&&k()},"aria-expanded":!i,style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,cursor:"pointer",padding:"6px 0"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,d.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]}),(0,d.jsxs)("span",{style:{fontSize:12,fontWeight:500,color:"#3b82f6"},children:["Plan \xb7 ",b.length," 步"]}),p&&(0,d.jsxs)("span",{style:{borderRadius:4,padding:"0 6px",fontSize:10,fontWeight:600,background:"rgba(34,197,94,0.12)",color:"rgba(34,197,94,0.85)"},children:["已完成 ",o,"/",b.length]})]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[(h||g||f)&&(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[h&&(0,d.jsx)("button",{type:"button",onClick:a=>{a.stopPropagation(),h()},disabled:c,style:{borderRadius:5,padding:"3px 8px",fontSize:11,fontWeight:500,color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border)",cursor:c?"not-allowed":"pointer",opacity:c?.55:1},children:"修改计划"}),g&&(0,d.jsx)("button",{type:"button",onClick:a=>{a.stopPropagation(),g()},disabled:c,style:{borderRadius:5,padding:"3px 8px",fontSize:11,fontWeight:500,color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border)",cursor:c?"not-allowed":"pointer",opacity:c?.55:1},children:"继续规划"}),f&&(0,d.jsx)("button",{type:"button",onClick:a=>{a.stopPropagation(),f()},disabled:c,style:{borderRadius:5,padding:"3px 10px",fontSize:11,fontWeight:500,color:"#fff",background:c?"rgba(59,130,246,0.3)":"#3b82f6",border:"none",cursor:c?"not-allowed":"pointer"},children:"执行计划"})]}),(0,d.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:i?"rotate(-90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:(0,d.jsx)("polyline",{points:"6 9 12 15 18 9"})})]})]}),!i&&(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:b.map(a=>(0,d.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8,borderRadius:4,padding:"3px 8px",background:"inProgress"===a.status?"rgba(59,130,246,0.04)":"transparent"},children:[(0,d.jsx)("div",{style:{marginTop:1},children:function(a){switch(a){case"completed":return(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"rgba(34,197,94,0.12)",stroke:"rgba(34,197,94,0.6)",strokeWidth:"1.5"}),(0,d.jsx)("path",{d:"M7 12.5l3 3 7-7",stroke:"rgba(34,197,94,0.9)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]});case"inProgress":return(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"rgba(59,130,246,0.2)",strokeWidth:"2.5"}),(0,d.jsx)("path",{d:"M12 2a10 10 0 0 1 10 10",stroke:"rgba(59,130,246,0.85)",strokeWidth:"2.5",strokeLinecap:"round",children:(0,d.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"1.5s",repeatCount:"indefinite"})})]});default:return(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",style:{flexShrink:0},children:(0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"var(--border)",strokeWidth:"1.5"})})}}(a.status)}),(0,d.jsx)("span",{style:{fontSize:12,lineHeight:1.5,...function(a){switch(a){case"completed":return{color:"rgba(34,197,94,0.85)",textDecoration:"line-through"};case"inProgress":return{color:"#3b82f6",fontWeight:500};default:return{color:"var(--text-muted)"}}}(a.status)},children:a.step})]},a.id))})]})]})}var ak=c(37267);let al=["annotate and analyze.","vibe code bioinformatics.","turn data into figures.","inspect your project.","build a reproducible report.","run R/Python plots.","summarize that paper.","review the pipeline.","compare markers.","draft methods.","find the next analysis step."];function am({phrases:a}){let[b,c]=(0,e.useState)(()=>Math.floor(Math.random()*a.length)),[f,g]=(0,e.useState)(""),[h,i]=(0,e.useState)(!1),[j,k]=(0,e.useState)(!0);return(0,d.jsxs)("span",{style:{color:"var(--text-muted)",fontWeight:400},children:[f,(0,d.jsx)("span",{style:{opacity:+!!j,color:"var(--accent)",marginLeft:1},children:"▍"})]})}function an({status:a}){let b=a?.current??"0.8.119"??"0.0.0";if(a?.updateAvailable){let c=a.latest?`v${a.latest}`:"latest";return(0,d.jsxs)("span",{title:`Current v${b}; latest ${c}; run ${a.updateCommand}`,style:{display:"block",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:11,color:"var(--accent)"},children:["Update: ",(0,d.jsx)("code",{style:{fontFamily:"var(--font-mono)",color:"var(--accent)"},children:a.updateCommand})]})}return(0,d.jsxs)("span",{title:`AnnoVibe v${b}`,style:{fontSize:11,color:"var(--text-dim)",whiteSpace:"nowrap"},children:["v",b]})}function ao({session:a,newSessionCwd:b,onAgentEnd:c,onSessionCreated:f,onSessionForked:g,modelsRefreshKey:h,chatInputRef:i,onBranchDataChange:j,onSessionStatsChange:k,onContextUsageChange:m,onToolPresetActive:n,generativeUI:o,activeFilePath:p,onOpenFileAtLine:q}){var r;let s,[t,u]=(0,e.useState)(null),[v,w]=(0,e.useState)(!1),[x,y]=(0,e.useState)([]),[z,A]=(0,e.useState)(""),[D,E]=(0,e.useState)(!1);(0,e.useRef)(!1);let[F,G]=(0,e.useState)(!1),H=p&&!F?p:null,I=(0,e.useCallback)(a=>{let b;w(a.enabled),E(a.executing);let c=(b=a.todos.findIndex(a=>!a.completed),a.todos.map((a,c)=>({id:`plan-${a.step||c+1}`,step:a.text,status:a.completed?"completed":c===b?"inProgress":"pending"})));a.enabled||a.executing||c.length>0?y(c):y([])},[]),{data:J,loading:K,error:L,messages:M,entryIds:N,streamState:O,agentRunning:P,modelNames:Q,modelList:R,modelThinkingLevels:T,modelThinkingLevelMaps:V,toolPreset:W,memoryTools:X,thinkingLevel:Y,retryInfo:_,contextUsage:aa,forkingEntryId:ab,isCompacting:ac,compactError:af,displayModel:ai,sessionStats:ap,agentPhase:aq,agentError:ar,isNew:as,loadMoreMessages:at,hasMoreMessages:au,totalMessages:av,loadedMessagesCount:aw,messagesEndRef:ax,scrollContainerRef:ay,lastUserMsgRef:az,handleSend:aA,handleAbort:aB,handleFork:aC,handleNavigate:aD,handleModelChange:aE,handleCompact:aF,handleSteer:aG,handleFollowUp:aH,handleAbortCompaction:aI,handleToolPresetChange:aJ,handleMemoryToolsChange:aK,handleThinkingLevelChange:aL,handleAgentEventRef:aM}=(0,ae.T)({session:a,newSessionCwd:b,planMode:v,onAgentEnd:c,onSessionCreated:f,onSessionForked:g,modelsRefreshKey:h,onBranchDataChange:j,onPlanModeState:I}),{soundEnabled:aN,onSoundToggle:aO,playDoneSound:aP}=function(){let[a,b]=(0,e.useState)(()=>!0),c=(0,e.useRef)(a);return{soundEnabled:a,onSoundToggle:(0,e.useCallback)(()=>{b(a=>{let b=!a;return localStorage.setItem("pi-sound-enabled",String(b)),b})},[]),playDoneSound:(0,e.useCallback)(()=>{if(c.current)try{let a=new AudioContext;"suspended"===a.state&&a.resume().catch(()=>{});let b=a.currentTime;[523.25,659.25].forEach((c,d)=>{let e=a.createOscillator(),f=a.createGain();e.connect(f),f.connect(a.destination),e.type="sine",e.frequency.value=c;let g=b+.18*d;f.gain.setValueAtTime(0,g),f.gain.linearRampToValueAtTime(.18,g+.02),f.gain.exponentialRampToValueAtTime(.001,g+.45),e.start(g),e.stop(g+.45)}),setTimeout(()=>a.close(),1200)}catch{}},[]),soundEnabledRef:c}}();(0,e.useRef)(aP).current=aP,(0,e.useRef)(aN).current=aN,aM.current,ap&&(ap.tokens.input,ap.tokens.output,ap.tokens.cacheRead,ap.tokens.cacheWrite,ap.cost),(0,e.useRef)(ap).current=ap,aa&&(aa.percent,aa.contextWindow,aa.tokens),(0,e.useRef)(aa).current=aa;let aQ=(0,e.useCallback)(a=>{i?.current?.addFiles(a)},[i]),aR=(0,e.useCallback)((a,b,c)=>{let d=c?.findIndex(b=>b.src===a)??-1;a$({src:a,gallery:c,index:d>=0?d:0})},[]),{isDragOver:aS,handleDragEnter:aT,handleDragOver:aU,handleDragLeave:aV,handleDrop:aW}=function(a){let[b,c]=(0,e.useState)(!1),d=(0,e.useRef)(0),f=(0,e.useCallback)(a=>{Array.from(a.dataTransfer.items).some(ag)&&(a.preventDefault(),d.current+=1,c(!0))},[]),g=(0,e.useCallback)(a=>{Array.from(a.dataTransfer.items).some(ag)&&a.preventDefault()},[]);return{isDragOver:b,handleDragEnter:f,handleDragOver:g,handleDragLeave:(0,e.useCallback)(()=>{d.current-=1,d.current<=0&&(d.current=0,c(!1))},[]),handleDrop:(0,e.useCallback)(b=>{b.preventDefault(),d.current=0,c(!1),a(Array.from(b.dataTransfer.files))},[a])}}(aQ),[aX,aY]=(0,e.useState)(null),[aZ,a$]=(0,e.useState)(null),a_=M.filter(a=>"user"===a.role||"assistant"===a.role),a0=(r=a_.length,(s=(0,e.useRef)([])).current=Array(r).fill(null).map((a,b)=>s.current[b]??null),s),a1=(0,e.useMemo)(()=>{let a=new Map;for(let b of M)"toolResult"===b.role&&a.set(b.toolCallId,b);return a},[M]),a2=as&&0===M.length&&!O.isStreaming&&!P,a3=J?.info?.cwd??a?.cwd??b??null,a4=function(a){if(!a)return null;let b=a.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean);return b[b.length-1]||a}(a3),a5=function(a=768){let[b,c]=(0,e.useState)(!1);return b}(),[a6,a7]=(0,e.useState)(!1),[a8,a9]=(0,e.useState)(!1),ba=Z(M),bb=ba.filter(a=>"running"===a.status).length,bc=(0,e.useCallback)(()=>{a?.id&&!P&&(async()=>{await aJ("workbench");let a=J?.sessionMeta;if(a?.initialSourcePath&&a.initialKernel){let b=`Resume this Workbench session. Reload only the initial data file \`${a.initialSourcePath}\` using the ${a.initialKernel.toUpperCase()} runtime. Do not rerun previous analyses or load extra files unless I ask. Use the chat history only as context for what to do next.`;await aA(b)}})()},[P,J?.sessionMeta,aA,aJ,a?.id]),bd=ai?T[`${ai.provider}:${ai.modelId}`]??null:null,be=ai?V[`${ai.provider}:${ai.modelId}`]??null:null,bf=J?.sessionMeta?.sessionKind??null,bg=a?.id??b??"new-chat",bh=(0,e.useMemo)(()=>(function(a){let b=[];for(let c=a.length-1;c>=0;c-=1){let d=a[c];if("user"!==d.role)continue;let e=d.text.trim();e&&b.push(e)}return b})(a_.map(a=>{let b;return{role:a.role,text:"string"==typeof(b=a.content)?b:Array.isArray(b)?b.filter(a=>!!a&&"object"==typeof a&&"text"===a.type&&"string"==typeof a.text).map(a=>a.text).join("\n"):""}})),[a_]),bi=(0,e.useCallback)(()=>{let b=!v;w(b);let c=a?.id;if(c){let a=b?["read","bash","grep","find","ls"]:(0,C.tE)(W,X);(0,ak.$)(c,{type:"set_tools",toolNames:a,planMode:b}).catch(()=>{})}b&&E(!1)},[X,v,a?.id,W]),bj=(0,e.useCallback)(async(a,b,c)=>{if("/plan"===a.trim()||a.trim().startsWith("/plan "))return void bi();let d=a;H&&a.trim()&&(d=`${a}
10
8
 
11
- Attached document text:
9
+ [Current file: \`${H}\`]`),await aA(d,b,c)},[bi,aA,H]),bk=(0,d.jsx)(S,{ref:i,onSend:bj,onAbort:aB,onSteer:P?aG:void 0,onFollowUp:P?aH:void 0,isStreaming:P,model:ai,modelNames:Q,modelList:R,onModelChange:aE,onCompact:a||as?aF:void 0,onAbortCompaction:aI,isCompacting:ac,compactError:af,toolPreset:W,sessionKind:bf,onToolPresetChange:a||as?aJ:void 0,memoryTools:X,onMemoryToolsChange:a||as?aK:void 0,thinkingLevel:Y,onThinkingLevelChange:a||as?aL:void 0,availableThinkingLevels:bd,thinkingLevelMap:be,retryInfo:_,soundEnabled:aN,onSoundToggle:aO,cornerBadge:a2?(0,d.jsx)(an,{status:aX}):void 0,promptHistory:bh,sessionHistoryKey:bg,planMode:v,onPlanModeChange:()=>bi(),activeFilePath:H,onDismissFileContext:()=>G(!0)}),bl=(0,e.useCallback)(()=>{P||0===x.length||aA("请继续完善这个计划,补充遗漏的风险、步骤和验证方式。保持编号列表格式。")},[P,aA,x.length]),bm=(0,e.useCallback)(()=>{if(P||0===x.length)return;let a=z||x.map((a,b)=>`${b+1}. ${a.step}`).join("\n");i?.current?.insertText(`请按以下修改后的计划继续规划:
12
10
 
13
- ${i}`:a:i?`Attached document text:
14
-
15
- ${i}`:"",k=[],n=l?c:b?.cwd??m?.info?.cwd;if(e?.length&&n)try{k=await aq(n,e)}catch(a){aX(a instanceof Error?a.message:String(a));return}let o=k.length?k.map(a=>{var b;return{type:"image",path:a.path,mimeType:a.mimeType,name:a.name,source:{type:"url",url:(b=a.path,`/api/files/${(0,ap.HG)(b)}?type=read`),media_type:a.mimeType}}}):e?.map(a=>({type:"image",source:{type:"base64",media_type:a.mimeType,data:a.data}})),p={role:"user",content:o?.length?[...j.trim()?[{type:"text",text:j}]:[],...o]:j,timestamp:Date.now()},q=aN(),r=l?null:b?.id??null,s=a8.current,t=aQ(p.content);a6.current.set(q,{localId:q,sessionId:r??"__new__",leafId:s,message:p,createdAt:Date.now(),kind:"prompt",confirmKey:t,confirmCountAtCreate:l?0:t?a7.current.get(t)??0:0}),v(a=>[...a,p]),aX(null),a$.current=!0,P(!0),aV({kind:"waiting_model"}),N({type:"start"}),a3.current=!0;let u=S.find(a=>a.provider===bi?.provider&&a.id===bi?.modelId)?.input,w=!u||0===u.length||u.includes("image")?e?.map(a=>({type:"image",data:a.data,mimeType:a.mimeType})):void 0;try{if(l&&c){Y&&au(Y);let b=h??bk(),e=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:c,type:"prompt",message:j,toolNames:b,planMode:d,deferPrompt:!0,...w?.length?{images:w}:{},...Y?{provider:Y.provider,modelId:Y.modelId}:{},..."auto"!==ac?{thinkingLevel:ac}:{}})}),f=await e.json().catch(()=>({}));if(!e.ok||f.error||!f.sessionId)throw Error(f.error??`HTTP ${e.status}`);let i=f.sessionId;aZ.current=i;let k=a6.current.get(q);k&&(k.sessionId=i),a0.current?.(),a0.current=aG(i,()=>{aZ.current===i&&(P(!1),aV(null))}),a9.current=i,bb.current=Date.now(),bv(i),await ao(i,{type:"prompt",message:j,toolNames:b,planMode:d,...w?.length?{images:w}:{}}),g?.({id:i,path:"",cwd:c,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:1,firstMessage:a})}else if(b){let a=h??bk();await bm(b.id),a0.current?.(),a0.current=aG(b.id,()=>{aZ.current===b.id&&(P(!1),aV(null))}),bb.current=Date.now(),bv(b.id),await ao(b.id,{type:"prompt",message:j,toolNames:a,planMode:d,...w?.length?{images:w}:{}})}}catch(a){if(a6.current.delete(q),console.error("Failed to send message:",a),l&&aZ.current){let a=aZ.current;aZ.current=null,a9.current=null,fetch(`/api/sessions/${encodeURIComponent(a)}`,{method:"DELETE"}).catch(()=>{})}aX(a instanceof Error?a.message:String(a)),a$.current=!1,P(!1),aV(null),N({type:"end"})}},[l,c,Y,bk,ac,b,m?.info?.cwd,O,bv,g,bl,d,S,bi,bm]),by=(0,e.useCallback)(async()=>{let a=aZ.current;if(a){a$.current=!1,aX(null),P(!1),aV(null),N({type:"end"}),aY.current?.close(),aY.current=null,aH(a);try{await ao(a,{type:"abort"}),await bq(a)}catch(b){console.error("Failed to abort:",b),await bq(a)}}},[bq]),bz=(0,e.useCallback)(async a=>{let b=aZ.current;if(b){al(a);try{let{cancelled:c,newSessionId:d}=await ao(b,{type:"fork",entryId:a})??{};!c&&d&&h?.(d)}catch(a){console.error("Fork failed:",a)}finally{al(null)}}},[h]),bA=(0,e.useCallback)(async a=>{let b=aZ.current;b&&(ao(b,{type:"navigate_tree",targetId:a}).catch(()=>{}),t(a),await bt(b,a))},[bt]);(0,e.useCallback)(async a=>{t(a);let b=aZ.current;b&&(await bt(b,a),a&&ao(b,{type:"navigate_tree",targetId:a}).catch(()=>{}))},[bt]);let bB=(0,e.useCallback)(async(a,b)=>{if(l)return void bf({provider:a,modelId:b});let c=aZ.current;if(c)try{var d;aX(null);let e=await ao(c,{type:"set_model",provider:a,modelId:b}),f={provider:e.provider,modelId:e.id};e.thinkingLevel&&(d=e.thinkingLevel,"auto"===d||"off"===d||"minimal"===d||"low"===d||"medium"===d||"high"===d||"xhigh"===d)&&ad(e.thinkingLevel),as(f),n(a=>a?{...a,context:{...a.context,model:f}}:a)}catch(b){let a=b instanceof Error?b.message:String(b);console.error("Failed to set model:",b),aX(a)}},[l,bf]),bC=(0,e.useCallback)(async()=>{let a=aZ.current;if(a&&!aw){aB(!0),aT(null);try{await ao(a,{type:"compact"}),await bq(a,!0)}catch(a){aT(a instanceof Error?a.message:String(a))}finally{aB(!1)}}},[aw,bq]),bD=(0,e.useCallback)(async(a,b,c)=>{let d=aZ.current;if(!d)return;let e=bl(c),f=a.trim()?e?`${a}
16
-
17
- Attached document text:
18
-
19
- ${e}`:a:e?`Attached document text:
20
-
21
- ${e}`:"",g=S.find(a=>a.provider===bi?.provider&&a.id===bi?.modelId)?.input,h=!g||0===g.length||g.includes("image")?b?.map(a=>({type:"image",data:a.data,mimeType:a.mimeType})):void 0,i={role:"user",content:`[steer] ${f}`,timestamp:Date.now()},j=aN(),k=aP(f,h?.length??0);a6.current.set(j,{localId:j,sessionId:d,leafId:a8.current,message:i,createdAt:Date.now(),kind:"steer",confirmKey:k,confirmCountAtCreate:k?a7.current.get(k)??0:0}),v(a=>[...a,i]);try{await ao(d,{type:"steer",message:f,...h?.length?{images:h}:{}})}catch(a){a6.current.delete(j),console.error("Failed to steer:",a)}},[bl,S,bi]),bE=(0,e.useCallback)(async(a,b,c)=>{let d=aZ.current;if(!d)return;let e=bl(c),f=a.trim()?e?`${a}
22
-
23
- Attached document text:
24
-
25
- ${e}`:a:e?`Attached document text:
26
-
27
- ${e}`:"",g=S.find(a=>a.provider===bi?.provider&&a.id===bi?.modelId)?.input,h=!g||0===g.length||g.includes("image")?b?.map(a=>({type:"image",data:a.data,mimeType:a.mimeType})):void 0,i={role:"user",content:f,timestamp:Date.now()},j=aN(),k=aP(f,h?.length??0);a6.current.set(j,{localId:j,sessionId:d,leafId:a8.current,message:i,createdAt:Date.now(),kind:"follow_up",confirmKey:k,confirmCountAtCreate:k?a7.current.get(k)??0:0}),v(a=>[...a,i]);try{await ao(d,{type:"follow_up",message:f,...h?.length?{images:h}:{}})}catch(a){a6.current.delete(j),console.error("Failed to follow up:",a)}},[bl,S,bi]),bF=(0,e.useCallback)(async()=>{let a=aZ.current;if(a)try{await ao(a,{type:"abort_compaction"})}catch(a){console.error("Failed to abort compaction:",a)}},[]),bG=(0,e.useCallback)(async a=>{if(ad(a),"auto"===a)return;let b=aZ.current;if(b)try{await ao(b,{type:"set_thinking_level",level:a})}catch(a){console.error("Failed to set thinking level:",a)}},[]),bH=(0,e.useCallback)(async a=>{bg(a);let b=L(a,aa),c=aZ.current;if(c)try{await ao(c,{type:"set_tools",toolNames:b})}catch(a){console.error("Failed to set tools:",a)}},[aa,bg]),bI=(0,e.useCallback)(async a=>{bh(a);let b=L($,a),c=aZ.current;if(c)try{await ao(c,{type:"set_tools",toolNames:b})}catch(a){console.error("Failed to set memory tools:",a)}},[bh,$]);return(0,e.useCallback)((a="smooth")=>{a4.current?.scrollIntoView({behavior:a})},[]),(0,e.useCallback)(()=>{let a=a5.current,b=a2.current;if(!a||!b)return;let c=b.getBoundingClientRect().top-a.getBoundingClientRect().top+a.scrollTop;a.scrollTo({top:c-16,behavior:"smooth"})},[]),{data:m,loading:o,error:q,activeLeafId:s,messages:u,entryIds:w,streamState:M,agentRunning:O,modelNames:Q,modelList:S,modelThinkingLevels:U,modelThinkingLevelMaps:W,newSessionModel:Y,toolPreset:$,memoryTools:aa,thinkingLevel:ac,retryInfo:ae,contextUsage:ag,systemPrompt:ai,forkingEntryId:ak,isCompacting:aw,compactError:aI,currentModel:bi,displayModel:bj,sessionStats:bn,agentPhase:aU,agentError:aW,isNew:l,sessionIdRef:aZ,sseReaderRef:aY,messagesEndRef:a4,scrollContainerRef:a5,lastUserMsgRef:a2,pendingScrollToUserRef:a3,initialScrollDoneRef:a1,handleSend:bx,handleAbort:by,handleFork:bz,handleNavigate:bA,handleModelChange:bB,handleCompact:bC,handleSteer:bD,handleFollowUp:bE,handleAbortCompaction:bF,handleToolPresetChange:bH,handleMemoryToolsChange:bI,handleThinkingLevelChange:bG,loadTools:bu,setActiveLeafId:t,setData:n,setMessages:v,dispatch:N,setAgentRunning:P,setForkingEntryId:al,loadMoreMessages:bs,hasMoreMessages:A,totalMessages:y,loadedMessagesCount:E,handleAgentEventRef:a_}}({session:a,newSessionCwd:b,planMode:v,onAgentEnd:c,onSessionCreated:f,onSessionForked:g,modelsRefreshKey:h,onBranchDataChange:j,onPlanModeState:(0,e.useCallback)(a=>{let b;w(a.enabled),K(a.executing);let c=(b=a.todos.findIndex(a=>!a.completed),a.todos.map((a,c)=>({id:`plan-${a.step||c+1}`,step:a.text,status:a.completed?"completed":c===b?"inProgress":"pending"})));a.enabled||a.executing||c.length>0?y(c):y([])},[])}),{soundEnabled:bf,onSoundToggle:bg,playDoneSound:bh}=function(){let[a,b]=(0,e.useState)(()=>!0),c=(0,e.useRef)(a);return{soundEnabled:a,onSoundToggle:(0,e.useCallback)(()=>{b(a=>{let b=!a;return localStorage.setItem("pi-sound-enabled",String(b)),b})},[]),playDoneSound:(0,e.useCallback)(()=>{if(c.current)try{let a=new AudioContext;"suspended"===a.state&&a.resume().catch(()=>{});let b=a.currentTime;[523.25,659.25].forEach((c,d)=>{let e=a.createOscillator(),f=a.createGain();e.connect(f),f.connect(a.destination),e.type="sine",e.frequency.value=c;let g=b+.18*d;f.gain.setValueAtTime(0,g),f.gain.linearRampToValueAtTime(.18,g+.02),f.gain.exponentialRampToValueAtTime(.001,g+.45),e.start(g),e.stop(g+.45)}),setTimeout(()=>a.close(),1200)}catch{}},[]),soundEnabledRef:c}}();(0,e.useRef)(bh).current=bh,(0,e.useRef)(bf).current=bf,be.current,al&&(al.tokens.input,al.tokens.output,al.tokens.cacheRead,al.tokens.cacheWrite,al.cost),(0,e.useRef)(al).current=al,ae&&(ae.percent,ae.contextWindow,ae.tokens),(0,e.useRef)(ae).current=ae;let bi=(0,e.useCallback)(a=>{i?.current?.addFiles(a)},[i]),bj=(0,e.useCallback)((a,b,c)=>{let d=c?.findIndex(b=>b.src===a)??-1;bs({src:a,gallery:c,index:d>=0?d:0})},[]),{isDragOver:bk,handleDragEnter:bl,handleDragOver:bm,handleDragLeave:bn,handleDrop:bo}=function(a){let[b,c]=(0,e.useState)(!1),d=(0,e.useRef)(0),f=(0,e.useCallback)(a=>{Array.from(a.dataTransfer.items).some(aU)&&(a.preventDefault(),d.current+=1,c(!0))},[]),g=(0,e.useCallback)(a=>{Array.from(a.dataTransfer.items).some(aU)&&a.preventDefault()},[]);return{isDragOver:b,handleDragEnter:f,handleDragOver:g,handleDragLeave:(0,e.useCallback)(()=>{d.current-=1,d.current<=0&&(d.current=0,c(!1))},[]),handleDrop:(0,e.useCallback)(b=>{b.preventDefault(),d.current=0,c(!1),a(Array.from(b.dataTransfer.files))},[a])}}(bi),[bp,bq]=(0,e.useState)(null),[br,bs]=(0,e.useState)(null),bt=S.filter(a=>"user"===a.role||"assistant"===a.role),bu=(r=bt.length,(s=(0,e.useRef)([])).current=Array(r).fill(null).map((a,b)=>s.current[b]??null),s),bv=(0,e.useMemo)(()=>{let a=new Map;for(let b of S)"toolResult"===b.role&&a.set(b.toolCallId,b);return a},[S]),bw=au&&0===S.length&&!U.isStreaming&&!V,bx=P?.info?.cwd??a?.cwd??b??null,by=function(a){if(!a)return null;let b=a.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean);return b[b.length-1]||a}(bx),bz=function(a=768){let[b,c]=(0,e.useState)(!1);return b}(),[bA,bB]=(0,e.useState)(!1),[bC,bD]=(0,e.useState)(!1),bE=ag(S),bF=bE.filter(a=>"running"===a.status).length,bG=(0,e.useCallback)(()=>{a?.id&&!V&&(async()=>{await bb("workbench");let a=P?.sessionMeta;if(a?.initialSourcePath&&a.initialKernel){let b=`Resume this Workbench session. Reload only the initial data file \`${a.initialSourcePath}\` using the ${a.initialKernel.toUpperCase()} runtime. Do not rerun previous analyses or load extra files unless I ask. Use the chat history only as context for what to do next.`;await a2(b)}})()},[V,P?.sessionMeta,a2,bb,a?.id]),bH=ak?Y[`${ak.provider}:${ak.modelId}`]??null:null,bI=ak?Z[`${ak.provider}:${ak.modelId}`]??null:null,bJ=P?.sessionMeta?.sessionKind??null,bK=a?.id??b??"new-chat",bL=(0,e.useMemo)(()=>(function(a){let b=[];for(let c=a.length-1;c>=0;c-=1){let d=a[c];if("user"!==d.role)continue;let e=d.text.trim();e&&b.push(e)}return b})(bt.map(a=>{let b;return{role:a.role,text:"string"==typeof(b=a.content)?b:Array.isArray(b)?b.filter(a=>!!a&&"object"==typeof a&&"text"===a.type&&"string"==typeof a.text).map(a=>a.text).join("\n"):""}})),[bt]),bM=(0,e.useCallback)(()=>{let b=!v;w(b);let c=a?.id;c&&ao(c,{type:"set_tools",toolNames:b?["read","bash","grep","find","ls"]:L($,aa),planMode:b}).catch(()=>{}),b&&K(!1)},[aa,v,a?.id,$]),bN=(0,e.useCallback)(async(a,b,c)=>{if("/plan"===a.trim()||a.trim().startsWith("/plan "))return void bM();let d=a;O&&a.trim()&&(d=`${a}
28
-
29
- [Current file: \`${O}\`]`),await a2(d,b,c)},[bM,a2,O]),bO=(0,d.jsx)(_,{ref:i,onSend:bN,onAbort:a3,onSteer:V?a8:void 0,onFollowUp:V?a9:void 0,isStreaming:V,model:ak,modelNames:W,modelList:X,onModelChange:a6,onCompact:a||au?a7:void 0,onAbortCompaction:ba,isCompacting:ai,compactError:aj,toolPreset:$,sessionKind:bJ,onToolPresetChange:a||au?bb:void 0,memoryTools:aa,onMemoryToolsChange:a||au?bc:void 0,thinkingLevel:ac,onThinkingLevelChange:a||au?bd:void 0,availableThinkingLevels:bH,thinkingLevelMap:bI,retryInfo:ad,soundEnabled:bf,onSoundToggle:bg,cornerBadge:bw?(0,d.jsx)(a$,{status:bp}):void 0,promptHistory:bL,sessionHistoryKey:bK,planMode:v,onPlanModeChange:()=>bM(),activeFilePath:O,onDismissFileContext:()=>N(!0)}),bP=(0,e.useCallback)(()=>{V||0===x.length||a2("请继续完善这个计划,补充遗漏的风险、步骤和验证方式。保持编号列表格式。")},[V,a2,x.length]),bQ=(0,e.useCallback)(()=>{if(V||0===x.length)return;let a=z||x.map((a,b)=>`${b+1}. ${a.step}`).join("\n");i?.current?.insertText(`请按以下修改后的计划继续规划:
30
-
31
- ${a}`)},[V,i,x,z]),bR=(0,e.useCallback)(()=>{let b=a?.id;b&&!V&&0!==x.length&&(async()=>{let a=await fetch(`/api/sessions/${encodeURIComponent(b)}/plan`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planText:z,tasks:x})});if(!a.ok)throw Error(`Failed to save plan: HTTP ${a.status}`);let c=L($,aa);await ao(b,{type:"set_tools",toolNames:c,planMode:!1}),w(!1),K(!0),y(a=>a.map((a,b)=>({...a,status:0===b?"inProgress":"pending"}))),await a2(`Execute the approved plan from .annovibe-plan.md. Start with: ${x[0].step}`,void 0,void 0,c)})().catch(()=>{})},[V,a2,aa,x,z,a?.id,$]),bS=(0,e.useCallback)(a=>{V?i?.current?.insertText(a):a2(a)},[V,i,a2]),bT=(0,e.useCallback)((a,b,c)=>{if(V)return;let d=a.includes("```")?"````":"```",e=`${d}${b||""}
11
+ ${a}`)},[P,i,x,z]),bn=(0,e.useCallback)(()=>{let b=a?.id;b&&!P&&0!==x.length&&(async()=>{let a=await fetch(`/api/sessions/${encodeURIComponent(b)}/plan`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({planText:z,tasks:x})});if(!a.ok)throw Error(`Failed to save plan: HTTP ${a.status}`);let c=(0,C.tE)(W,X);await (0,ak.$)(b,{type:"set_tools",toolNames:c,planMode:!1}),w(!1),E(!0),y(a=>a.map((a,b)=>({...a,status:0===b?"inProgress":"pending"}))),await aA(`Execute the approved plan from .annovibe-plan.md. Start with: ${x[0].step}`,void 0,void 0,c)})().catch(()=>{})},[P,aA,X,x,z,a?.id,W]),bo=(0,e.useCallback)(a=>{P?i?.current?.insertText(a):aA(a)},[P,i,aA]),bp=(0,e.useCallback)((a,b,c)=>{if(P)return;let d=a.includes("```")?"````":"```",e=`${d}${b||""}
32
12
  ${a}
33
- ${d}`,f=c?` to \`${c}\``:" to the appropriate file";a2(`Please write the following code${f} and then run it to show the result:
13
+ ${d}`,f=c?` to \`${c}\``:" to the appropriate file";aA(`Please write the following code${f} and then run it to show the result:
34
14
 
35
- ${e}`)},[V,a2]),bU=(0,e.useCallback)((a,b)=>{if(V)return;let c=a.includes("```")?"````":"```",d=`${c}${b||""}
15
+ ${e}`)},[P,aA]),bq=(0,e.useCallback)((a,b)=>{if(P)return;let c=a.includes("```")?"````":"```",d=`${c}${b||""}
36
16
  ${a}
37
- ${c}`;a2(`Please run the following code and show the output:
17
+ ${c}`;aA(`Please run the following code and show the output:
38
18
 
39
- ${d}`)},[V,a2]),bV=(0,e.useCallback)((a,b)=>{if(V)return;let c=b?` to \`${b}\``:"",d=a.includes("```")?"````":"```",e=`${d}diff
19
+ ${d}`)},[P,aA]),br=(0,e.useCallback)((a,b)=>{if(P)return;let c=b?` to \`${b}\``:"",d=a.includes("```")?"````":"```",e=`${d}diff
40
20
  ${a}
41
- ${d}`;a2(`Please apply this diff${c}:
21
+ ${d}`;aA(`Please apply this diff${c}:
42
22
 
43
- ${e}`)},[V,a2]);return Q?(0,d.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:"Loading session..."}):R?(0,d.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:R}):(0,d.jsxs)("div",{className:"relative flex h-full flex-col overflow-hidden",onDragEnter:bl,onDragOver:bm,onDragLeave:bn,onDrop:bo,children:[bk&&(0,d.jsxs)("div",{className:"pointer-events-none absolute inset-0 z-50 flex animate-[drop-zone-in_0.15s_ease_both] items-center justify-center bg-[rgba(37,99,235,0.06)] backdrop-blur-[1px]",children:[(0,d.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:[0,.8,1.6].map(a=>(0,d.jsx)("div",{className:"absolute h-[720px] w-[720px] rounded-full border-[1.5px] border-solid border-[rgba(37,99,235,0.5)] animate-[drop-ripple_2.4s_ease-out_infinite_backwards]",style:{transformOrigin:"center",animationDelay:`${a}s`}},a))}),(0,d.jsxs)("svg",{width:"280",height:"280",viewBox:"0 0 140 140",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"drop-shadow-[0_6px_18px_rgba(37,99,235,0.18)]",children:[(0,d.jsx)("rect",{x:"28",y:"44",width:"84",height:"60",rx:"8",fill:"rgba(37,99,235,0.08)",stroke:"rgba(37,99,235,0.50)",strokeWidth:"1.8"}),(0,d.jsx)("path",{d:"M36 100 L54 72 L68 88 L80 74 L104 100Z",fill:"rgba(37,99,235,0.16)",stroke:"rgba(37,99,235,0.40)",strokeWidth:"1.4",strokeLinejoin:"round"}),(0,d.jsx)("circle",{cx:"96",cy:"58",r:"8",fill:"rgba(37,99,235,0.22)",stroke:"rgba(37,99,235,0.55)",strokeWidth:"1.6"}),(0,d.jsxs)("g",{stroke:"rgba(37,99,235,0.45)",strokeWidth:"1.4",strokeLinecap:"round",children:[(0,d.jsx)("line",{x1:"96",y1:"46",x2:"96",y2:"43"}),(0,d.jsx)("line",{x1:"96",y1:"70",x2:"96",y2:"73"}),(0,d.jsx)("line",{x1:"84",y1:"58",x2:"81",y2:"58"}),(0,d.jsx)("line",{x1:"108",y1:"58",x2:"111",y2:"58"}),(0,d.jsx)("line",{x1:"87.5",y1:"49.5",x2:"85.4",y2:"47.4"}),(0,d.jsx)("line",{x1:"104.5",y1:"66.5",x2:"106.6",y2:"68.6"}),(0,d.jsx)("line",{x1:"104.5",y1:"49.5",x2:"106.6",y2:"47.4"}),(0,d.jsx)("line",{x1:"87.5",y1:"66.5",x2:"85.4",y2:"68.6"})]})]})]}),!bC&&(0,d.jsx)(am,{sessionKind:bJ,toolPreset:$,initialSourcePath:P?.sessionMeta?.initialSourcePath??null,initialKernel:P?.sessionMeta?.initialKernel??null,isNew:au,isStreaming:V,onResume:bG,onDismiss:()=>bD(!0)}),bw?(0,d.jsx)("div",{className:"flex flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-8",children:(0,d.jsxs)("div",{className:"w-full max-w-[820px]",children:[(0,d.jsxs)("div",{className:"mb-3",style:{display:"flex",flexDirection:"column",alignItems:"stretch",justifyContent:"flex-start",gap:10,marginLeft:16,marginRight:16,fontFamily:"var(--font-mono)"},children:[by&&(0,d.jsxs)("div",{style:{padding:bz?"7px 9px":"9px 12px",border:"1px solid var(--border)",borderRadius:bz?9:10,background:"linear-gradient(180deg, var(--bg-panel), rgba(127,127,127,0.03))",minWidth:0,display:"flex",alignItems:"flex-start",gap:bz?8:10,boxShadow:bz?"0 2px 10px rgba(0,0,0,0.04)":"none"},children:[(0,d.jsx)("div",{"aria-hidden":!0,style:{flex:"0 0 auto",width:bz?18:20,height:bz?18:20,borderRadius:6,marginTop:1,background:"rgba(37,99,235,0.10)",border:"1px solid rgba(37,99,235,0.20)",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--accent)"},children:(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M3 7.5 12 4l9 3.5-9 3.5-9-3.5Z"}),(0,d.jsx)("path",{d:"M7 10v4.5c0 .8 2.2 2 5 2s5-1.2 5-2V10"})]})}),(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsx)("div",{style:{fontSize:9,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.08em",marginBottom:2},children:"Current Project"}),(0,d.jsx)("div",{style:{fontSize:bz?12.5:14,color:"var(--text)",fontWeight:700,lineHeight:1.3,wordBreak:"break-word"},children:by}),bx&&(0,d.jsx)("div",{title:bx,style:{fontSize:10.5,color:"var(--text-dim)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:bx})]})]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0,flex:1,lineHeight:1.4},children:[(0,d.jsx)("span",{style:{fontSize:23,color:"var(--text)",fontWeight:750,letterSpacing:0},children:l}),(0,d.jsx)("span",{style:{fontSize:14,minWidth:0,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:(0,d.jsx)(aZ,{phrases:aY})})]})]}),bO]})}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{className:"relative flex flex-1 overflow-hidden",children:[(0,d.jsx)("div",{ref:a0,className:"flex-1 overflow-y-auto pt-4 [scrollbar-width:none]",children:(0,d.jsxs)("div",{className:"mx-auto max-w-[820px] px-4",style:bz?{paddingBottom:"calc(env(safe-area-inset-bottom, 0px) + 128px)"}:void 0,children:[(0,d.jsx)(aX,{goal:P?.sessionMeta?.goal??null,planTasks:x,isRunning:V,onExecutePlan:v&&x.length>0?bR:void 0,onContinuePlanning:v&&x.length>0?bP:void 0,onEditPlan:v&&x.length>0?bQ:void 0}),(()=>{let c=-1;for(let a=S.length-1;a>=0;a--)if("user"===S[a].role){c=a;break}let e=0;return(0,d.jsxs)(d.Fragment,{children:[aB&&S.length>0&&(0,d.jsx)("div",{style:{textAlign:"center",padding:"8px 0 4px"},children:(0,d.jsxs)("button",{onClick:()=>aw(),style:{padding:"6px 16px",fontSize:11,color:"var(--accent)",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer",transition:"background 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="var(--bg-panel)"},children:["Load ",aI-aT," earlier message",aI-aT==1?"":"s"]})}),S.map((f,g)=>{let h="user"===f.role&&g>0&&"assistant"===S[g-1].role?T[g-1]:void 0,j="user"===f.role||"assistant"===f.role,k=j?e++:-1,l=!1;if("assistant"===f.role){l=!0;for(let a=g+1;a<S.length;a++){let b=S[a].role;if("user"===b)break;if("assistant"===b){l=!1;break}}l&&U.isStreaming&&g===S.length-1&&(l=!1)}let m=(0,d.jsx)(B.D,{message:f,toolResults:bv,modelNames:W,entryId:T[g],onFork:V||au||0===g&&"user"===f.role?void 0:a4,forking:af===T[g],onNavigate:V?void 0:a5,prevAssistantEntryId:V?void 0:h,onEditContent:a=>i?.current?.insertIfEmpty(a),onSendMessage:bS,showTimestamp:l,prevTimestamp:g>0?S[g-1].timestamp:void 0,renderVisualCodeBlocks:!!o,cwd:P?.info?.cwd??a?.cwd??b??void 0,onOpenImage:bj,activeFilePath:O,agentRunning:V,onApplyToFile:bT,onRunCode:bU,onOpenFileAtLine:q,onAcceptDiff:bV},g);return j?(0,d.jsx)("div",{ref:a=>{bu.current[k]=a,g===c&&(a1.current=a)},style:{contentVisibility:"auto",containIntrinsicSize:"auto 100px"},children:m},g):m})]})})(),V&&(0,d.jsx)(aV,{agentPhase:as,startedAt:t}),U.isStreaming&&U.streamingMessage&&(0,d.jsx)(B.D,{message:U.streamingMessage,isStreaming:!0,toolResults:bv,modelNames:W,onSendMessage:bS,renderVisualCodeBlocks:!!o,cwd:P?.info?.cwd??a?.cwd??b??void 0,activeFilePath:O,agentRunning:V,onApplyToFile:bT,onRunCode:bU,onOpenFileAtLine:q,onAcceptDiff:bV}),V&&!U.streamingMessage&&(0,d.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,d.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:function(a){if(a?.kind==="running_tools"){let b=a.tools.map(a=>a.name);return 0===b.length?"Running tool...":1===b.length?`Running ${b[0]}...`:b.length<=3?`Running ${b.join(", ")}...`:`Running ${b.slice(0,2).join(", ")} (+${b.length-2})...`}return a?.kind==="waiting_model"?"Waiting for model...":"Thinking..."}(as)})}),P?.info?.cwd&&!1===P.info.cwdExists&&(0,d.jsxs)("div",{className:"my-3 rounded-[7px] border border-[rgba(248,113,113,0.35)] bg-[rgba(248,113,113,0.07)] px-3 py-2 text-[12px] leading-relaxed text-red-400",children:["Project directory no longer exists: ",(0,d.jsx)("code",{className:"font-mono",children:P.info.cwd})]}),at&&(0,d.jsx)("div",{className:"my-3 rounded-[7px] border border-[rgba(248,113,113,0.35)] bg-[rgba(248,113,113,0.07)] px-3 py-2 text-[12px] leading-relaxed text-red-400",children:at}),V&&(0,d.jsx)("div",{style:{height:a0.current?a0.current.clientHeight:"80vh"}}),(0,d.jsx)("div",{ref:aW})]})}),!bz&&(0,d.jsx)(ab,{messages:S,streamingMessage:U.streamingMessage,scrollContainer:a0,messageRefs:bu}),bE.length>0&&(0,d.jsxs)("button",{onClick:()=>bB(a=>!a),title:bA?"Hide subagent runs":"Show subagent runs",style:{position:"absolute",right:bz?8:bA?260:40,top:8,minWidth:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:bF>0||bE.length>1?"0 8px":0,background:bA?"var(--bg-selected)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:bA?"var(--accent)":"var(--text-dim)",cursor:"pointer",zIndex:30,fontSize:12,transition:"right 0.2s ease, background 0.12s"},onMouseEnter:a=>{bA||(a.currentTarget.style.color="var(--text)")},onMouseLeave:a=>{bA||(a.currentTarget.style.color="var(--text-dim)")},children:[(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,d.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,d.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,d.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),(bF>0||bE.length>1)&&(0,d.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,fontSize:10,fontWeight:700,color:bF>0?"var(--accent)":"var(--text-dim)"},children:[bF>0&&(0,d.jsxs)("span",{children:[bF," active"]}),(0,d.jsx)("span",{children:bE.length})]})]}),bA&&bE.length>0&&(0,d.jsxs)("div",{style:{position:"absolute",right:bz?8:48,top:4,bottom:4,width:bz?"calc(100vw - 16px)":250,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"-2px 0 12px rgba(0,0,0,0.08)",zIndex:25,overflow:"hidden"},children:[(0,d.jsx)("div",{style:{padding:"6px 12px",fontSize:11,fontWeight:600,color:"var(--text-dim)",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Subagents"}),(0,d.jsx)(ah,{runs:bE})]})]}),(0,d.jsx)("div",{className:"relative",children:bO})]}),br&&(0,d.jsxs)("div",{style:{position:"fixed",inset:0,zIndex:100,background:"rgba(0,0,0,0.85)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"zoom-out"},onClick:()=>bs(null),children:[br.gallery&&br.gallery.length>1&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("button",{style:{position:"absolute",left:16,top:"50%",transform:"translateY(-50%)",background:"rgba(255,255,255,0.15)",border:"none",borderRadius:8,color:"#fff",fontSize:28,width:44,height:44,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:101},onClick:a=>{a.stopPropagation();let b=((br.index??0)-1+br.gallery.length)%br.gallery.length;bs({...br,src:br.gallery[b].src,index:b})},children:"←"}),(0,d.jsx)("button",{style:{position:"absolute",right:16,top:"50%",transform:"translateY(-50%)",background:"rgba(255,255,255,0.15)",border:"none",borderRadius:8,color:"#fff",fontSize:28,width:44,height:44,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:101},onClick:a=>{a.stopPropagation();let b=((br.index??0)+1)%br.gallery.length;bs({...br,src:br.gallery[b].src,index:b})},children:"→"})]}),(0,d.jsx)("img",{src:br.src,alt:"",style:{maxWidth:"95vw",maxHeight:"95vh",objectFit:"contain",borderRadius:8,boxShadow:"0 8px 40px rgba(0,0,0,0.5)"}}),(0,d.jsx)("div",{style:{position:"absolute",bottom:16,left:"50%",transform:"translateX(-50%)",background:"rgba(0,0,0,0.5)",color:"rgba(255,255,255,0.7)",borderRadius:6,padding:"4px 12px",fontSize:12},children:br.gallery&&br.gallery.length>1?`${(br.index??0)+1} / ${br.gallery.length}`:"Click anywhere to close"})]})]})}var a0=c(90707),a1=c(52515);class a2 extends f().Component{static getDerivedStateFromError(a){return{hasError:!0,message:a instanceof Error?a.message:String(a)}}componentDidCatch(a,b){console.error("File viewer crashed",{filePath:this.props.filePath,error:a,componentStack:b.componentStack})}componentDidUpdate(a){a.filePath!==this.props.filePath&&this.state.hasError&&this.setState({hasError:!1,message:null})}render(){return this.state.hasError?(0,d.jsx)(a1.fj,{style:{background:"var(--bg)"},children:(0,d.jsx)(a1.nG,{tone:"error",children:(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,alignItems:"center",textAlign:"center"},children:[(0,d.jsx)("div",{children:"Preview crashed for this file."}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",maxWidth:560,wordBreak:"break-word"},children:this.props.filePath}),this.state.message&&(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",maxWidth:560,wordBreak:"break-word"},children:this.state.message})]})})}):this.props.children}constructor(...a){super(...a),this.state={hasError:!1,message:null}}}function a3(a,b,c){return Math.min(Math.max(a,b),c)}function a4({id:a,filePath:b,fileName:c,cwd:f,active:g,stackIndex:h,zIndex:i,onClose:j,onFocus:k,onOpenFile:l}){let[m,n]=(0,e.useState)(()=>{let a,b,c;return b=Math.max(320,1208-(a=h%6*28)),c=Math.max(260,828-a),{left:36+a,top:36+a,width:Math.min(1180,b),height:Math.min(820,c),maximized:!1}}),[o,p]=(0,e.useState)(!1),[q,r]=(0,e.useState)(!1),s=(0,e.useRef)(null),t=(0,e.useRef)(null),u=(0,e.useRef)(null),v=(0,e.useCallback)(b=>{k(a),0!==b.button||m.maximized||(b.preventDefault(),b.currentTarget.setPointerCapture(b.pointerId),t.current={pointerId:b.pointerId,startX:b.clientX,startY:b.clientY,left:m.left,top:m.top},p(!0))},[m.left,m.maximized,m.top,a,k]),w=(0,e.useCallback)(a=>{let b=t.current;if(!b||b.pointerId!==a.pointerId)return;let c=b.left+a.clientX-b.startX,d=b.top+a.clientY-b.startY;n(a=>({...a,left:a3(c,8,Math.max(8,window.innerWidth-120)),top:a3(d,8,Math.max(8,window.innerHeight-48))}))},[]),x=(0,e.useCallback)(a=>{let b=t.current;b?.pointerId===a.pointerId&&(a.currentTarget.releasePointerCapture(a.pointerId),t.current=null,p(!1))},[]),y=(0,e.useCallback)(()=>{k(a),n(a=>({...a,maximized:!a.maximized}))},[a,k]),z=(0,e.useCallback)(b=>{k(a),0!==b.button||m.maximized||(b.preventDefault(),b.stopPropagation(),b.currentTarget.setPointerCapture(b.pointerId),u.current={pointerId:b.pointerId,startX:b.clientX,startY:b.clientY,width:m.width,height:m.height},r(!0))},[m.height,m.maximized,m.width,a,k]),A=(0,e.useCallback)(a=>{let b=u.current;if(!b||b.pointerId!==a.pointerId)return;let c=b.width+a.clientX-b.startX,d=b.height+a.clientY-b.startY;n(a=>({...a,width:a3(c,360,Math.max(360,window.innerWidth-a.left-8)),height:a3(d,280,Math.max(280,window.innerHeight-a.top-8))}))},[]),B=(0,e.useCallback)(a=>{let b=u.current;b?.pointerId===a.pointerId&&(a.currentTarget.releasePointerCapture(a.pointerId),u.current=null,r(!1))},[]),C=m.maximized?{position:"fixed",inset:12,zIndex:i}:{position:"fixed",left:m.left,top:m.top,width:m.width,height:m.height,zIndex:i};return(0,d.jsxs)("div",{ref:s,role:"dialog","aria-label":`Preview ${c}`,tabIndex:-1,onPointerDown:()=>k(a),onKeyDown:b=>{"Escape"===b.key&&j(a)},style:{...C,display:"flex",flexDirection:"column",minWidth:m.maximized?void 0:360,minHeight:m.maximized?void 0:280,background:"var(--bg)",border:g?"1px solid rgba(37,99,235,0.55)":"1px solid var(--border)",borderRadius:8,boxShadow:g?"0 18px 60px rgba(0,0,0,0.26)":"0 10px 34px rgba(0,0,0,0.20)",overflow:"hidden",outline:"none"},children:[(0,d.jsxs)("div",{onPointerDown:v,onPointerMove:w,onPointerUp:x,onPointerCancel:x,style:{height:34,display:"flex",alignItems:"center",gap:8,padding:"0 8px 0 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",cursor:m.maximized?"default":o?"grabbing":"grab",flexShrink:0,userSelect:"none"},children:[(0,d.jsx)("div",{style:{minWidth:0,flex:1},children:(0,d.jsx)("div",{title:b,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontWeight:650,color:"var(--text)"},children:c})}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:y,title:m.maximized?"Restore preview":"Maximize preview","aria-label":m.maximized?"Restore preview":"Maximize preview",style:a5,children:m.maximized?(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,d.jsx)("path",{d:"M6 3.5h6.5V10"}),(0,d.jsx)("path",{d:"M3.5 6H10v6.5H3.5z"})]}):(0,d.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,d.jsx)("path",{d:"M4 4h8v8H4z"})})}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:()=>j(a),title:"Close preview","aria-label":"Close preview",style:a5,children:(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round","aria-hidden":"true",children:[(0,d.jsx)("line",{x1:"4",y1:"4",x2:"12",y2:"12"}),(0,d.jsx)("line",{x1:"12",y1:"4",x2:"4",y2:"12"})]})})]}),(0,d.jsx)("div",{style:{flex:1,minHeight:0,overflow:"hidden",background:"var(--bg)"},children:(0,d.jsx)(a2,{filePath:b,children:(0,d.jsx)(a0.h,{filePath:b,cwd:f,onOpenFile:l})})}),!m.maximized&&(0,d.jsx)("div",{role:"separator","aria-orientation":"horizontal","aria-label":"Resize preview",title:"Resize preview",onPointerDown:z,onPointerMove:A,onPointerUp:B,onPointerCancel:B,style:{position:"absolute",right:0,bottom:0,width:18,height:18,cursor:"nwse-resize",color:"var(--text-dim)",display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:3,background:"linear-gradient(135deg, transparent 0 48%, rgba(127,127,127,0.18) 48% 52%, transparent 52% 100%)"}})]})}let a5={width:26,height:24,padding:0,border:"1px solid transparent",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0};function a6(a){return{dirCache:new Map,pathIndex:new Map,loadedDirs:new Set,revision:0,workspaceRoot:a}}function a7(a,b){if(b.delete(a.path),a.children)for(let c of a.children)a7(c,b)}function a8(a,b,c){let d=new Map;if(b)for(let a of b)d.set(a.path,a);if(b){let d=new Set(a.map(a=>a.path));for(let a of b)d.has(a.path)||a7(a,c)}return a.map(a=>{let b=d.get(a.path);return b&&(a.id=b.id,b.childrenLoaded&&b.children?(a.children=b.children,a.childrenLoaded=!0):b.childrenLoaded&&!b.children&&(a.childrenLoaded=!0)),c.set(a.path,a),a})}function a9(a,b,c){let d=a8(c,a.dirCache.get(b),a.pathIndex);a.dirCache.set(b,d),a.loadedDirs.add(b)}function ba(a,b,c){let d=a.dirCache.get(b);if(!d)return;let e=d.findIndex(a=>a.path===c.path);if(-1!==e){let a=d[e];"folder"===a.type&&"folder"===c.type&&(c.children=a.children,c.childrenLoaded=a.childrenLoaded),d[e]=c}else d.push(c),d.sort(bc);a.pathIndex.set(c.path,c)}function bb(a,b,c){let d=a.dirCache.get(b);d&&a.dirCache.set(b,d.filter(a=>a.path!==c));let e=a.pathIndex.get(c);e&&a7(e,a.pathIndex),a.dirCache.delete(c),a.loadedDirs.delete(c)}function bc(a,b){return"folder"===a.type&&"folder"!==b.type?-1:"folder"!==a.type&&"folder"===b.type?1:a.name.localeCompare(b.name)}let bd=new Set(["node_modules","vendor","venv",".venv","Pods","dist","build","out","target",".output","bin","obj",".next",".nuxt",".cache",".turbo",".parcel-cache",".git",".svn",".hg",".idea",".vscode",".vs","coverage",".nyc_output","__pycache__",".pytest_cache",".mypy_cache",".tox","logs","tmp","temp",".annodex-uploads"]),be="var(--text-dim)";function bf({size:a=14,open:b=!1}){return b?(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 16 16",fill:"none",children:[(0,d.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5h7.5v1H1V4.5Z",fill:be}),(0,d.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:be,strokeWidth:"1",fill:be,fillOpacity:"0.12"})]}):(0,d.jsx)("svg",{width:a,height:a,viewBox:"0 0 16 16",fill:"none",children:(0,d.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5H14a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4.5Z",stroke:be,strokeWidth:"1",fill:be,fillOpacity:"0.1"})})}function bg({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 16 16",fill:"none",children:[(0,d.jsx)("path",{d:"M3 2h7l3 3v9H3V2Z",stroke:be,strokeWidth:"1",fill:be,fillOpacity:"0.08"}),(0,d.jsx)("path",{d:"M10 2v3h3",stroke:be,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function bh({label:a,size:b=14}){let c=b/14;return(0,d.jsxs)("svg",{width:b,height:b,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:be,strokeWidth:"0.9",fill:be,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:be,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("text",{x:"7",y:"9.5",textAnchor:"middle",fontSize:3.4*c,fontFamily:"var(--font-mono), monospace",fontWeight:"600",fill:be,letterSpacing:"0",children:a})]})}function bi({size:a=14}){return(0,d.jsx)(bh,{label:"TS",size:a})}function bj({size:a=14}){return(0,d.jsx)(bh,{label:"TSX",size:a})}function bk({size:a=14}){return(0,d.jsx)(bh,{label:"JS",size:a})}function bl({size:a=14}){return(0,d.jsx)(bh,{label:"JSX",size:a})}function bm({size:a=14}){return(0,d.jsx)(bh,{label:"PY",size:a})}function bn({size:a=14}){return(0,d.jsx)(bh,{label:"{}",size:a})}function bo({size:a=14}){return(0,d.jsx)(bh,{label:"CSS",size:a})}function bp({size:a=14}){return(0,d.jsx)(bh,{label:"SC",size:a})}function bq({size:a=14}){return(0,d.jsx)(bh,{label:"HTM",size:a})}function br({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:be,strokeWidth:"0.9",fill:be,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:be,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:be,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,d.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:be,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function bs({size:a=14}){return(0,d.jsx)(bh,{label:"YML",size:a})}function bt({size:a=14}){return(0,d.jsx)(bh,{label:"TOM",size:a})}function bu({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:be,strokeWidth:"0.9",fill:be,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:be,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:be,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,d.jsx)("path",{d:"M7.5 10.5h2.5",stroke:be,strokeWidth:"0.95",strokeLinecap:"round"})]})}function bv({size:a=14}){return(0,d.jsx)(bh,{label:"RS",size:a})}function bw({size:a=14}){return(0,d.jsx)(bh,{label:"GO",size:a})}function bx({size:a=14}){return(0,d.jsx)(bh,{label:"SQL",size:a})}function by({size:a=14}){return(0,d.jsx)(bh,{label:"GQL",size:a})}function bz({size:a=14}){return(0,d.jsx)(bh,{label:"TF",size:a})}function bA({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:be,strokeWidth:"0.9",fill:be,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:be,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("rect",{x:"3.5",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:be,strokeWidth:"0.8"}),(0,d.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:be,strokeWidth:"0.8"}),(0,d.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:be,strokeWidth:"0.8"})]})}function bB({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:be,strokeWidth:"0.9",fill:be,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:be,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:be,strokeWidth:"0.9"}),(0,d.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:be,strokeWidth:"0.9",strokeLinecap:"round"})]})}function bC({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:be,strokeWidth:"0.9",fill:be,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:be,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:be,strokeWidth:"0.85"}),(0,d.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:be,strokeWidth:"0.85"}),(0,d.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:be,strokeWidth:"0.85"}),(0,d.jsx)("path",{d:"M5 7.5V9",stroke:be,strokeWidth:"0.85",strokeLinecap:"round"}),(0,d.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:be,strokeWidth:"0.85",strokeLinecap:"round",fill:"none"})]})}function bD({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:be,strokeWidth:"0.9",fill:be,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:be,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("rect",{x:"4.5",y:"8.5",width:"5",height:"3",rx:"0.6",stroke:be,strokeWidth:"0.9"}),(0,d.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:be,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}function bE({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:be,strokeWidth:"0.9",fill:be,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:be,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:be,strokeWidth:"0.9"}),(0,d.jsx)("path",{d:"M7 6.5v.7M7 10.3v.7M5 8.5h.7M8.3 8.5H9M5.5 6.9l.5.5M8.5 9.6l-.5-.5M5.5 10.1l.5-.5M8.5 7.4l-.5.5",stroke:be,strokeWidth:"0.8",strokeLinecap:"round"})]})}function bF(a,b=14){let c=a.toLowerCase(),e=c.split(".").pop()??"";if("dockerfile"===c||c.startsWith("dockerfile."))return(0,d.jsx)(bA,{size:b});if(".env"===c||c.startsWith(".env."))return(0,d.jsx)(bB,{size:b});if(".gitignore"===c||".gitattributes"===c||".gitmodules"===c)return(0,d.jsx)(bC,{size:b});if("package-lock.json"===c||"yarn.lock"===c||"bun.lock"===c||"pnpm-lock.yaml"===c||"cargo.lock"===c)return(0,d.jsx)(bD,{size:b});if(c.endsWith(".config.ts")||c.endsWith(".config.js")||c.endsWith(".config.mjs")||c.endsWith(".config.cjs")||[".eslintrc",".eslintrc.js",".eslintrc.json",".eslintrc.yml","eslint.config.mjs","eslint.config.js"].includes(c))return(0,d.jsx)(bE,{size:b});switch(e){case"ts":return(0,d.jsx)(bi,{size:b});case"tsx":return(0,d.jsx)(bj,{size:b});case"js":case"mjs":case"cjs":return(0,d.jsx)(bk,{size:b});case"jsx":return(0,d.jsx)(bl,{size:b});case"py":return(0,d.jsx)(bm,{size:b});case"json":case"jsonl":return(0,d.jsx)(bn,{size:b});case"css":case"less":return(0,d.jsx)(bo,{size:b});case"scss":return(0,d.jsx)(bp,{size:b});case"html":case"htm":return(0,d.jsx)(bq,{size:b});case"md":case"mdx":return(0,d.jsx)(br,{size:b});case"yaml":case"yml":return(0,d.jsx)(bs,{size:b});case"toml":return(0,d.jsx)(bt,{size:b});case"sh":case"bash":case"zsh":case"fish":return(0,d.jsx)(bu,{size:b});case"rs":return(0,d.jsx)(bv,{size:b});case"go":return(0,d.jsx)(bw,{size:b});case"sql":return(0,d.jsx)(bx,{size:b});case"graphql":case"gql":return(0,d.jsx)(by,{size:b});case"tf":case"hcl":return(0,d.jsx)(bz,{size:b});case"lock":return(0,d.jsx)(bD,{size:b});default:return(0,d.jsx)(bg,{size:b})}}let bG=f().memo(function({node:a,depth:b,isExpanded:c,isLoading:g,isSelected:h,isRenaming:i,isUploadTarget:j,onClick:k,onDoubleClick:l,onContextMenu:m,onRenameSubmit:n,onRenameCancel:o,onDragEnter:p,onDragOver:q,onDragLeave:r,onDrop:s}){var t;let u=!!(t=a.name).startsWith(".")||bd.has(t),[v,w]=f().useState(!1),[x,y]=f().useState(a.name),z=f().useRef(null);f().useEffect(()=>{if(i&&z.current){let b=a.name.lastIndexOf(".");"file"===a.type&&b>0?z.current.setSelectionRange(0,b):z.current.select(),z.current.focus()}},[i,a.name,a.type]);let A=(0,e.useCallback)(()=>{i||k(a.path,"folder"===a.type)},[i,a.path,a.type,k]),B=(0,e.useCallback)(()=>{i||l(a.path)},[i,a.path,l]),C=(0,e.useCallback)(b=>{i||m(b,a.path)},[i,a.path,m]),D=(0,e.useCallback)(b=>{if("Enter"===b.key){b.preventDefault();let c=x.trim();c&&c!==a.name?n(a.path,c):o()}else"Escape"===b.key&&(b.preventDefault(),o())},[x,a.name,a.path,n,o]),E=(0,e.useCallback)(()=>{let b=x.trim();b&&b!==a.name?n(a.path,b):o()},[x,a.name,a.path,n,o]);return(0,d.jsxs)("div",{onClick:A,onDoubleClick:B,onContextMenu:C,onMouseEnter:()=>w(!0),onMouseLeave:()=>w(!1),onDragEnter:p,onDragOver:q,onDragLeave:r,onDrop:s,style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*b,paddingRight:8,height:26,cursor:"pointer",background:j?"rgba(37,99,235,0.14)":h?"var(--bg-selected)":v?"var(--bg-hover)":"transparent",outline:j?"1px solid rgba(37,99,235,0.42)":"none",outlineOffset:-1,borderRadius:4,userSelect:"none",transition:"background 0.08s",opacity:u?.65:1},children:["folder"===a.type?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:c?"rotate(90deg)":"none",transition:"transform 0.1s"},children:(0,d.jsx)("polyline",{points:"3 2 7 5 3 8"})}):(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),g?(0,d.jsx)("span",{style:{flexShrink:0,width:14,height:14,display:"flex",alignItems:"center"},children:(0,d.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",style:{animation:"spin 1s linear infinite"},children:(0,d.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})})}):(0,d.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:"folder"===a.type?(0,d.jsx)(bf,{size:14,open:c}):bF(a.name,14)}),i?(0,d.jsx)("input",{ref:z,value:x,onChange:a=>y(a.target.value),onKeyDown:D,onBlur:E,style:{flex:1,minWidth:0,height:22,padding:"0 4px",fontSize:12,fontFamily:"inherit",color:"var(--text)",background:"var(--bg-input, var(--bg))",border:"1px solid var(--accent)",borderRadius:3,outline:"none"},onClick:a=>a.stopPropagation(),onDoubleClick:a=>a.stopPropagation(),onContextMenu:a=>a.stopPropagation()}):(0,d.jsx)("span",{style:{fontSize:12,color:u?"var(--text-dim)":"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:a.path,children:a.name})]})});function bH({x:a,y:b,actions:c,onClose:g}){let h=(0,e.useRef)(null),[i,j]=f().useState(a),[k,l]=f().useState(b);return 0===c.length?null:(0,d.jsx)("div",{ref:h,style:{position:"fixed",left:i,top:k,zIndex:1e3,minWidth:190,padding:"4px 0",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 8px 24px rgba(0,0,0,0.18)",fontSize:12},children:c.map((a,b)=>(0,d.jsxs)(f().Fragment,{children:[a.separator&&b>0&&(0,d.jsx)("div",{style:{height:1,margin:"4px 8px",background:"var(--border)"}}),(0,d.jsxs)("div",{onClick:b=>{b.stopPropagation(),a.onClick(),g()},style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 12px",cursor:"pointer",color:a.danger?"#ef4444":"var(--text)"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="transparent"},children:[(0,d.jsx)("span",{children:a.label}),a.shortcut&&(0,d.jsx)("span",{style:{marginLeft:24,fontSize:10,color:"var(--text-dim)"},children:a.shortcut})]})]},b))})}async function bI(a){let b=(0,ap.HG)(a),c=await fetch(`/api/files/${b}?type=list`);return c.ok?(await c.json()).entries??[]:[]}function bJ(a,b,c,d){let e=(0,ap.e_)(b,a.name);return{id:e,name:a.name,path:e,relativePath:(0,ap.qP)(e,c),type:a.isDir?"folder":"file",extension:a.isDir?"":a.name.includes(".")?a.name.split(".").pop()?.toLowerCase()??"":"",size:a.size,modified:a.modified,depth:d,children:a.isDir?[]:void 0,childrenLoaded:!a.isDir}}function bK(a,b){return a===b?".":(0,ap.qP)(a,b)}function bL(a){return!!Array.from(a.types).includes("Files")||Array.from(a.items).some(a=>"file"===a.kind)}function bM(a){return Array.from(a.files).filter(a=>!!a.name)}function bN({cwd:a,onOpenFile:b,onExploreFile:c,refreshKey:f,onAtMention:g,searchQuery:h=""}){let i,j,k,l,m=function(){let a=(0,e.useRef)(a6("")),[b,c]=(0,e.useState)(0),[d,f]=(0,e.useState)(""),[g,h]=(0,e.useState)(!1),[i,j]=(0,e.useState)(!1),[k,l]=(0,e.useState)(new Set),[m,n]=(0,e.useState)(new Set),[o,p]=(0,e.useState)(new Set),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)([]);(0,e.useCallback)(()=>{let b=a.current;t(function a(b,c,d,e){let f=[];for(let g of b){let b="folder"===g.type&&c.has(g.path);if(f.push({node:g,depth:d,isExpanded:b}),b){let b=e.get(g.path)??[];f.push(...a(b,c,d+1,e))}}return f}(b.dirCache.get(b.workspaceRoot)??[],m,0,b.dirCache))},[m]);let u=(0,e.useCallback)(async b=>{h(!1),j(!1);let d=a6(b);a.current=d;try{let a=(await bI(b)).map(a=>bJ(a,b,b,0));a.sort(bc),a9(d,b,a),f(b),h(!0),c(a=>a+1)}catch{j(!0),h(!0)}},[]),v=(0,e.useCallback)(async b=>{let d=a.current;if(!d.loadedDirs.has(b)){l(a=>new Set(a).add(b));try{let a=(await bI(b)).map(a=>bJ(a,b,d.workspaceRoot,0));a.sort(bc),d.loadedDirs.has(b)||(a9(d,b,a),c(a=>a+1))}catch{}finally{l(a=>{let c=new Set(a);return c.delete(b),c})}}},[]),w=(0,e.useCallback)(b=>{n(a=>{let c=new Set(a);return c.has(b)?c.delete(b):c.add(b),c}),a.current.loadedDirs.has(b)||v(b)},[v]),x=(0,e.useCallback)((a,b)=>{p(c=>{if(b){let b=new Set(c);return b.has(a)?b.delete(a):b.add(a),b}return new Set([a])})},[]),y=(0,e.useCallback)(()=>{p(new Set)},[]),z=(0,e.useCallback)(a=>{r(a)},[]),A=(0,e.useCallback)(()=>{r(null)},[]),B=(0,e.useCallback)(async b=>{var c;(c=a.current).dirCache.clear(),c.pathIndex.clear(),c.loadedDirs.clear(),n(new Set),await u(b)},[u]),C=(0,e.useCallback)(b=>a.current.pathIndex.get(b),[]),D=(0,e.useCallback)(b=>a.current.dirCache.get(b),[]),E=(0,e.useCallback)((b,d)=>{ba(a.current,b,d),c(a=>a+1)},[]),F=(0,e.useCallback)((b,d,e)=>{let f=a.current,g=f.pathIndex.get(b);if(!g)return;let h=f.workspaceRoot===b?f.workspaceRoot:b.substring(0,Math.max(b.lastIndexOf("/"),b.lastIndexOf("\\")));bb(f,h,b);let i={...g,id:d,name:e,path:d,relativePath:(0,ap.qP)(d,f.workspaceRoot),extension:"file"===g.type&&e.includes(".")?e.split(".").pop()?.toLowerCase()??"":""};ba(f,h,i),c(a=>a+1)},[]),G=(0,e.useCallback)(b=>{let d=a.current,e=d.workspaceRoot===b?d.workspaceRoot:b.substring(0,Math.max(b.lastIndexOf("/"),b.lastIndexOf("\\")));bb(d,e,b),c(a=>a+1)},[]);return{revision:b,workspaceRoot:d,hasLoaded:g,loadFailed:i,loadingPaths:k,expandedPaths:m,selectedPaths:o,renamingPath:q,flatNodes:s,loadRoot:u,loadChildren:v,toggleExpand:w,select:x,deselectAll:y,startRename:z,stopRename:A,refresh:B,getNode:C,getChildren:D,onFileCreated:E,onFileRenamed:F,onFileDeleted:G,invalidateDir:(0,e.useCallback)(b=>{let c=a.current;c.loadedDirs.delete(b),c.dirCache.delete(b)},[]),applyWatcherEvent:(0,e.useCallback)(b=>{(function(a,b){let c=!1;for(let{dirPath:d,children:e}of b){if(!a.loadedDirs.has(d))continue;let b=e.map(b=>{let c=d===a.workspaceRoot?`${a.workspaceRoot}/${b.name}`:`${d}/${b.name}`;return{id:c,name:b.name,path:c,relativePath:c.startsWith(a.workspaceRoot+"/")?c.slice(a.workspaceRoot.length+1):b.name,type:b.isDir?"folder":"file",extension:b.isDir?"":b.name.includes(".")?b.name.split(".").pop()?.toLowerCase()??"":"",size:b.size,modified:b.modified,depth:0,children:b.isDir?[]:void 0,childrenLoaded:!b.isDir}});b.sort(bc);let f=a8(b,a.dirCache.get(d),a.pathIndex);a.dirCache.set(d,f),c=!0}return c})(a.current,b)&&c(a=>a+1)},[])}}(),n=(i=(0,e.useCallback)(async(b,c)=>{try{let d=b===a?`${a}/${c}`:`${b}/${c}`,e=await fetch("/api/file-tree/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:d,content:""})});if(!e.ok){let a=await e.json().catch(()=>({}));return{success:!1,error:a.error??`HTTP ${e.status}`}}return{success:!0,resolvedPath:d}}catch(a){return{success:!1,error:String(a)}}},[a]),j=(0,e.useCallback)(async(b,c)=>{try{let d=b===a?`${a}/${c}`:`${b}/${c}`,e=await fetch("/api/file-tree/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:d})});if(!e.ok){let a=await e.json().catch(()=>({}));return{success:!1,error:a.error??`HTTP ${e.status}`}}return{success:!0,resolvedPath:d}}catch(a){return{success:!1,error:String(a)}}},[a]),k=(0,e.useCallback)(async(b,c)=>{try{let d=Math.max(b.lastIndexOf("/"),b.lastIndexOf("\\")),e=d>0?b.slice(0,d):a,f=`${e}/${c}`,g=await fetch("/api/file-tree/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPath:b,newPath:f})});if(!g.ok){let a=await g.json().catch(()=>({}));return{success:!1,error:a.error??`HTTP ${g.status}`}}return{success:!0,resolvedPath:f}}catch(a){return{success:!1,error:String(a)}}},[a]),l=(0,e.useCallback)(async a=>{try{let b=await fetch("/api/file-tree/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a})});if(!b.ok){let a=await b.json().catch(()=>({}));return{success:!1,error:a.error??`HTTP ${b.status}`}}return{success:!0,resolvedPath:a}}catch(a){return{success:!1,error:String(a)}}},[]),{createFile:i,createFolder:j,renameFile:k,deleteFile:l,moveFile:(0,e.useCallback)(async(a,b)=>{try{let c=a.slice(Math.max(a.lastIndexOf("/"),a.lastIndexOf("\\"))+1),d=`${b}/${c}`,e=await fetch("/api/file-tree/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPath:a,newPath:d})});if(!e.ok){let a=await e.json().catch(()=>({}));return{success:!1,error:a.error??`HTTP ${e.status}`}}return{success:!0,resolvedPath:d}}catch(a){return{success:!1,error:String(a)}}},[]),revealInFinder:(0,e.useCallback)(async a=>{try{await fetch("/api/file-tree/reveal",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a})})}catch{}},[])}),o=(0,e.useRef)(null);(0,e.useRef)(null);let p=(0,e.useRef)(null),q=(0,e.useRef)(0),[r,s]=(0,e.useState)(!1),[t,u]=(0,e.useState)(null),[v,w]=(0,e.useState)(null),[x,y]=(0,e.useState)(null),[z,A]=(0,e.useState)(-1),[B,C]=(0,e.useState)(null),D=h.trim().length>0,E=(()=>{if(D){let a=m.getChildren(m.workspaceRoot);return a?function a(b,c,d){let e=c.trim().toLowerCase(),f=[];for(let g of b){let b=g.name.toLowerCase().includes(e),h=(g.children??[]).some(a=>(function a(b,c){let d=c.trim().toLowerCase();return!!(!d||b.name.toLowerCase().includes(d))||(b.children??[]).some(b=>a(b,d))})(a,e));(b||h)&&(f.push({node:g,depth:d,isExpanded:!0}),g.children&&h&&f.push(...a(g.children,c,d+1)))}return f}(a,h,0):[]}return m.flatNodes})(),[F,G]=(0,e.useState)(0),[H,I]=(0,e.useState)(0),J=(0,e.useCallback)(a=>{G(a.currentTarget.scrollTop)},[]),K=(0,e.useMemo)(()=>{let a=26*E.length,b=Math.max(0,Math.floor(F/26)-10),c=Math.min(E.length,Math.ceil((F+H)/26)+10),d=[];for(let a=b;a<c;a++)d.push({index:a,top:26*a});return{items:d,totalHeight:a,startIndex:b}},[E,F,H]),L=(0,e.useCallback)((a,c)=>{if(c)m.toggleExpand(a);else{let c=m.getNode(a);c&&b(a,c.name)}m.select(a),A(E.findIndex(b=>b.node.path===a))},[m,b,E]),M=(0,e.useCallback)(a=>{let c=m.getNode(a);c&&"file"===c.type&&b(a,c.name)},[m,b]),N=(0,e.useCallback)((a,b)=>{a.preventDefault(),y({x:a.clientX,y:a.clientY,targetPath:b}),m.select(b),A(E.findIndex(a=>a.node.path===b))},[m,E]),O=(0,e.useMemo)(()=>{if(!x)return[];let b=m.getNode(x.targetPath);if(!b)return[];let d=[{label:"folder"===b.type?"Expand / Collapse":"Open",shortcut:"folder"===b.type?"→":"Enter",onClick:()=>L(b.path,"folder"===b.type)}];return c&&"file"===b.type&&b.name.toLowerCase().endsWith(".h5ad")&&d.push({label:"Explore H5AD",shortcut:"@explore",onClick:()=>c(b.path,b.name)}),g&&d.push({label:"Mention in Chat",shortcut:"@",onClick:()=>g((0,ap.qP)(b.path,a))}),d.push({label:"",onClick:()=>{},separator:!0}),d.push({label:"Rename",shortcut:"F2",onClick:()=>m.startRename(b.path)}),d.push({label:"Delete",shortcut:"Del",onClick:async()=>{if(!window.confirm(`Are you sure you want to delete "${b.name}"?`))return;let a=await n.deleteFile(b.path);a.success?(m.onFileDeleted(b.path),C(`Deleted "${b.name}"`)):a.error&&C(a.error)},danger:!0}),d.push({label:"",onClick:()=>{},separator:!0}),d.push({label:"Copy Path",onClick:()=>{navigator.clipboard.writeText(b.path).catch(()=>{}),C("Copied path")}}),d.push({label:"Copy Relative Path",onClick:()=>{let c=(0,ap.qP)(b.path,a);navigator.clipboard.writeText(c).catch(()=>{}),C("Copied relative path")}}),d.push({label:"Reveal in Finder",onClick:()=>n.revealInFinder(b.path)}),d},[x,m,n,L,g,c,a]),P=(0,e.useCallback)(async(a,b)=>{m.stopRename();let c=m.getNode(a);if(!c||b===c.name)return;let d=await n.renameFile(a,b);d.success&&d.resolvedPath?(m.onFileRenamed(a,d.resolvedPath,b),C(`Renamed to "${b}"`)):d.error&&C(d.error)},[m,n]),Q=(0,e.useCallback)(async()=>{let b=[...m.selectedPaths].map(a=>m.getNode(a)).filter(Boolean),c=b.find(a=>"folder"===a.type)?.path??a,d="untitled.txt",e=await n.createFile(c,d);if(e.success&&e.resolvedPath){let b={id:e.resolvedPath,name:d,path:e.resolvedPath,relativePath:(0,ap.qP)(e.resolvedPath,a),type:"file",extension:"txt",depth:0,childrenLoaded:!0,isOptimistic:!0};m.onFileCreated(c,b),m.expandedPaths.has(c)||m.toggleExpand(c),setTimeout(()=>m.startRename(e.resolvedPath),50)}else e.error&&C(e.error)},[m,n,a]),R=(0,e.useCallback)(async()=>{let b=[...m.selectedPaths].map(a=>m.getNode(a)).filter(Boolean),c=b.find(a=>"folder"===a.type)?.path??a,d="new-folder",e=await n.createFolder(c,d);if(e.success&&e.resolvedPath){let b={id:e.resolvedPath,name:d,path:e.resolvedPath,relativePath:(0,ap.qP)(e.resolvedPath,a),type:"folder",extension:"",depth:0,children:[],childrenLoaded:!0,isOptimistic:!0};m.onFileCreated(c,b),m.expandedPaths.has(c)||m.toggleExpand(c),setTimeout(()=>m.startRename(e.resolvedPath),50)}else e.error&&C(e.error)},[m,n,a]),S=(0,e.useCallback)(a=>{let b=a.target;if("INPUT"!==b.tagName&&"TEXTAREA"!==b.tagName){if("ArrowDown"===a.key)a.preventDefault(),A(a=>Math.min(a+1,E.length-1));else if("ArrowUp"===a.key)a.preventDefault(),A(a=>Math.max(a-1,0));else if("ArrowRight"===a.key){a.preventDefault();let b=E[z]?.node;b?.type!=="folder"||m.expandedPaths.has(b.path)||(m.toggleExpand(b.path),m.select(b.path))}else if("ArrowLeft"===a.key){a.preventDefault();let b=E[z]?.node;b?.type==="folder"&&m.expandedPaths.has(b.path)&&m.toggleExpand(b.path)}else if("Enter"===a.key){a.preventDefault();let b=E[z]?.node;b&&L(b.path,"folder"===b.type)}else if("F2"===a.key){a.preventDefault();let b=E[z]?.node;b&&(m.select(b.path),m.startRename(b.path))}else if("Delete"===a.key||"Backspace"===a.key){a.preventDefault();let b=E[z]?.node;b&&window.confirm(`Delete "${b.name}"?`)&&n.deleteFile(b.path).then(a=>{a.success&&(m.onFileDeleted(b.path),C(`Deleted "${b.name}"`))})}}},[E,z,m,L,n]),T=(0,e.useCallback)(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>w(null),5e3)},[]),U=(0,e.useCallback)((b,c)=>{if(0===b.length)return;q.current=0,s(!1),p.current&&clearTimeout(p.current);let d=b.reduce((a,b)=>a+b.size,0),e=bK(c,a);u(c),w({phase:"uploading",targetPath:c,fileCount:b.length,loaded:0,total:d,message:`Uploading ${b.length} file${1===b.length?"":"s"} to ${e}`});let f=new FormData;b.forEach(a=>f.append("files",a,a.name));let g=new XMLHttpRequest,h=(0,ap.HG)(c);g.open("POST",`/api/files/${h}?type=upload`),g.upload.onprogress=a=>{a.lengthComputable&&w(b=>b?{...b,loaded:a.loaded,total:a.total}:b)},g.onload=()=>{u(null);let a={};try{a=JSON.parse(g.responseText)}catch{a={}}if(g.status>=200&&g.status<300){let f=a.uploaded??[],g=a.failed??[],h=[...f.filter(a=>a.name!==a.originalName).slice(0,3).map(a=>`${a.originalName} saved as ${a.name}`),...g.slice(0,3).map(a=>`${a.name}: ${a.error}`)];w({phase:g.length>0?"warning":"success",targetPath:c,fileCount:b.length,loaded:d,total:d,message:g.length>0?`Uploaded ${f.length}, ${g.length} failed`:`Uploaded ${f.length} file${1===f.length?"":"s"} to ${e}`,details:h}),m.invalidateDir(c),m.expandedPaths.has(c)&&m.loadChildren(c),T()}else{let e=a.error??`Upload failed (HTTP ${g.status})`;w({phase:"error",targetPath:c,fileCount:b.length,loaded:0,total:d,message:e}),T()}},g.onerror=()=>{u(null),w({phase:"error",targetPath:c,fileCount:b.length,loaded:0,total:d,message:"Upload failed due to a network error"}),T()},g.onabort=()=>{u(null),w({phase:"error",targetPath:c,fileCount:b.length,loaded:0,total:d,message:"Upload canceled"}),T()},g.send(f)},[a,m,T]),V=(0,e.useCallback)(a=>{bL(a.dataTransfer)&&(a.preventDefault(),q.current+=1,s(!0))},[]),W=(0,e.useCallback)(a=>{bL(a.dataTransfer)&&(a.preventDefault(),a.dataTransfer.dropEffect="copy")},[]),X=(0,e.useCallback)(()=>{q.current-=1,q.current<=0&&(q.current=0,s(!1))},[]),Y=(0,e.useCallback)(b=>{if(!bL(b.dataTransfer))return;b.preventDefault(),q.current=0,s(!1);let c=bM(b.dataTransfer);c.length>0&&U(c,a)},[a,U]),Z=(0,e.useCallback)(a=>b=>{if(!bL(b.dataTransfer))return;b.preventDefault(),b.stopPropagation();let c=bM(b.dataTransfer);c.length>0&&(U(c,a),m.expandedPaths.has(a)||m.toggleExpand(a))},[U,m]),$=v&&v.total>0?Math.max(0,Math.min(100,Math.round(v.loaded/v.total*100))):v?.phase==="uploading"?8:100,_=v?.phase==="success"?"#22c55e":v?.phase==="warning"?"#f59e0b":v?.phase==="error"?"#ef4444":"var(--accent)";return m.loadFailed?(0,d.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Could not load files"}):(0,d.jsxs)("div",{onDragEnter:V,onDragOver:W,onDragLeave:X,onDrop:Y,onKeyDown:S,tabIndex:0,style:{position:"relative",display:"flex",flexDirection:"column",height:"100%",outline:r?"1px solid rgba(37,99,235,0.45)":"none",outlineOffset:-1,background:r?"rgba(37,99,235,0.04)":void 0,transition:"background 0.12s, outline-color 0.12s"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:2,padding:"4px 6px",borderBottom:"1px solid var(--border)",flexShrink:0,minHeight:30},children:[(0,d.jsx)("button",{onClick:Q,title:"New File",style:bO,children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,d.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,d.jsx)("line",{x1:"12",y1:"18",x2:"12",y2:"12"}),(0,d.jsx)("line",{x1:"9",y1:"15",x2:"15",y2:"15"})]})}),(0,d.jsx)("button",{onClick:R,title:"New Folder",style:bO,children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"}),(0,d.jsx)("line",{x1:"12",y1:"11",x2:"12",y2:"17"}),(0,d.jsx)("line",{x1:"9",y1:"14",x2:"15",y2:"14"})]})}),(0,d.jsx)("button",{onClick:()=>m.refresh(a),title:"Refresh",style:bO,children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("polyline",{points:"23 4 23 10 17 10"}),(0,d.jsx)("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),(0,d.jsx)("button",{onClick:()=>{m.deselectAll()},title:"Collapse All",style:bO,children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,d.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,d.jsx)("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),(0,d.jsx)("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}),(0,d.jsx)("div",{style:{flex:1}}),(0,d.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",paddingRight:4},children:[E.length," items"]})]}),B&&(0,d.jsx)("div",{style:{padding:"4px 10px",fontSize:11,color:"var(--text)",background:"var(--bg-selected)",borderBottom:"1px solid var(--border)"},children:B}),(0,d.jsxs)("div",{ref:o,onScroll:J,style:{flex:1,overflow:"auto",position:"relative"},children:[m.hasLoaded?0===E.length?(0,d.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:D?"No matching files":"No files found"}):(0,d.jsx)("div",{style:{height:K.totalHeight,position:"relative"},children:K.items.map(a=>{let{index:b,top:c}=a,{node:e,depth:f,isExpanded:g}=E[b],h=b===z;return(0,d.jsx)("div",{style:{position:"absolute",top:c,left:0,right:0,height:26,outline:h?"1px solid var(--accent)":"none",outlineOffset:-1,borderRadius:4},children:(0,d.jsx)(bG,{node:e,depth:f,isExpanded:g,isLoading:m.loadingPaths.has(e.path),isSelected:m.selectedPaths.has(e.path),isRenaming:m.renamingPath===e.path,isUploadTarget:t===e.path,onClick:L,onDoubleClick:M,onContextMenu:N,onRenameSubmit:P,onRenameCancel:()=>m.stopRename(),onDrop:"folder"===e.type?Z(e.path):void 0})},e.id)})}):(0,d.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."}),r&&(0,d.jsx)("div",{style:{pointerEvents:"none",position:"absolute",inset:6,top:0,border:"1px dashed rgba(37,99,235,0.62)",borderRadius:8,background:"rgba(37,99,235,0.07)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:2},children:(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontSize:12,boxShadow:"0 8px 24px rgba(0,0,0,0.16)"},children:[(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,d.jsx)("polyline",{points:"17 8 12 3 7 8"}),(0,d.jsx)("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),"Drop to upload into ",bK(a,a)]})})]}),v&&(0,d.jsxs)("div",{style:{margin:"6px",padding:"7px 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",boxShadow:"0 8px 24px rgba(0,0,0,0.12)",flexShrink:0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,d.jsx)("span",{style:{width:8,height:8,borderRadius:999,background:_,flexShrink:0}}),(0,d.jsx)("span",{title:v.message,style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11,fontWeight:600},children:v.message}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,flexShrink:0},children:"uploading"===v.phase?`${$}%`:function(a){if(!Number.isFinite(a)||a<=0)return"0 B";let b=["B","KB","MB","GB"],c=a,d=0;for(;c>=1024&&d<b.length-1;)c/=1024,d+=1;return`${c>=10||0===d?Math.round(c):c.toFixed(1)} ${b[d]}`}(v.total)})]}),(0,d.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,background:"var(--bg)",overflow:"hidden"},children:(0,d.jsx)("div",{style:{width:`${$}%`,height:"100%",borderRadius:999,background:_,transition:"width 0.15s ease"}})}),v.details&&v.details.length>0&&(0,d.jsx)("div",{style:{marginTop:5,display:"grid",gap:2},children:v.details.map(a=>(0,d.jsx)("div",{title:a,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:a},a))})]}),x&&(0,d.jsx)(bH,{x:x.x,y:x.y,actions:O,onClose:()=>y(null)})]})}let bO={display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,border:"none",borderRadius:4,background:"transparent",color:"var(--text-dim)",cursor:"pointer",flexShrink:0,transition:"background 0.08s, color 0.08s"};function bP({cwd:a,refreshKey:b=0,onOpenFile:c,onExploreFile:f,onAtMention:g}){let[h,i]=(0,e.useState)("");return(0,d.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",background:"var(--bg)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,d.jsx)("div",{style:{display:"flex",alignItems:"center",gap:8},children:(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Files"}),(0,d.jsx)("div",{title:a??"",style:{marginTop:1,fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:a??"No project selected"})]})}),(0,d.jsxs)("div",{style:{position:"relative",marginTop:7},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{position:"absolute",left:8,top:"50%",transform:"translateY(-50%)",color:"var(--text-dim)",pointerEvents:"none"},"aria-hidden":"true",children:[(0,d.jsx)("circle",{cx:"7",cy:"7",r:"4.4"}),(0,d.jsx)("path",{d:"M10.4 10.4 13.2 13.2"})]}),(0,d.jsx)("input",{value:h,onChange:a=>i(a.target.value),placeholder:"Filter files...",disabled:!a,style:{width:"100%",height:28,boxSizing:"border-box",padding:"0 28px 0 26px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none",opacity:a?1:.6}}),h&&(0,d.jsx)("button",{type:"button",onClick:()=>i(""),title:"Clear filter",style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",width:20,height:20,display:"flex",alignItems:"center",justifyContent:"center",border:"none",borderRadius:4,background:"transparent",color:"var(--text-dim)",cursor:"pointer",padding:0},children:(0,d.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[(0,d.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,d.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]})]}),(0,d.jsx)("div",{style:{flex:1,minHeight:0,overflow:"hidden"},children:a?(0,d.jsx)(bN,{cwd:a,onOpenFile:c,onExploreFile:f,refreshKey:b,onAtMention:g,searchQuery:h}):(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:18,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"Select a project to browse files."})})]})}var bQ=c(32492),bR=c(2857);let bS={__soul__:{apiPath:"/api/soul",title:"SOUL.md"},__harness__:{apiPath:"/api/harness",title:"HARNESS.md"}};function bT({filePath:a}){let b=bS[a],{isDark:c}=(0,bR.D)(),[f,g]=(0,e.useState)(""),[h,i]=(0,e.useState)(!0),[j,k]=(0,e.useState)(null),[l,m]=(0,e.useState)(!1),[n,o]=(0,e.useState)(!1),p=(0,e.useCallback)(async()=>{if(b){m(!0);try{await fetch(b.apiPath,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:f})}),o(!0),setTimeout(()=>o(!1),2e3)}catch(a){k(String(a))}finally{m(!1)}}},[b,f]);return b?h?(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading…"}):j?(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:j}):(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,d.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:600,color:"var(--text)"},children:b.title}),(0,d.jsx)("span",{style:{marginLeft:"auto",fontSize:10,color:"var(--text-dim)"},children:"Global"}),n&&(0,d.jsx)("span",{style:{color:"#4ade80",fontWeight:600,animation:"saved-pop 0.3s ease"},children:"✓ Saved"}),(0,d.jsx)("button",{onClick:p,disabled:l,title:"Save (Ctrl+S)",style:{padding:"2px 10px",fontSize:11,cursor:l?"not-allowed":"pointer",background:"var(--accent)",color:"#fff",border:"1px solid var(--accent)",borderRadius:5,fontWeight:600,opacity:l?.6:1},children:l?"Saving…":"Save"})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,d.jsx)(bQ.g,{initialContent:f,language:"markdown",isDark:c,onChange:g,onSave:p})})]}):null}function bU({side:a,onResize:b,onResizeStart:c,onResizeEnd:f,ariaLabel:g}){let h=(0,e.useRef)(null),i=(0,e.useRef)(!1),j=(0,e.useRef)(0),[k,l]=(0,e.useState)(!1),m=(0,e.useCallback)(a=>{if(!i.current)return;i.current=!1,l(!1);let b=h.current;b&&void 0!==a&&b.hasPointerCapture(a)&&b.releasePointerCapture(a),document.body.style.cursor="",document.body.style.userSelect="",f?.()},[f]),n=(0,e.useCallback)(a=>{0===a.button&&a.isPrimary&&(a.preventDefault(),i.current=!0,j.current=a.clientX,l(!0),c?.(),a.currentTarget.setPointerCapture(a.pointerId),document.body.style.cursor="col-resize",document.body.style.userSelect="none")},[c]),o=(0,e.useCallback)(a=>{if(!i.current)return;a.preventDefault();let c=a.clientX-j.current;j.current=a.clientX,b(c)},[b]),p=(0,e.useCallback)(a=>{a.preventDefault(),m(a.pointerId)},[m]),q=(0,e.useCallback)(a=>{m(a.pointerId)},[m]);return(0,d.jsx)("div",{ref:h,role:"separator","aria-label":g??"Resize panel","aria-orientation":"vertical",className:`resize-handle${k?" resize-handle-dragging":""}`,"data-side":a,onPointerDown:n,onPointerMove:o,onPointerUp:p,onPointerCancel:q,style:{alignSelf:"stretch",cursor:"col-resize",display:"flex",flexShrink:0,justifyContent:"center",marginLeft:-5,marginRight:-5,position:"relative",touchAction:"none",width:10,zIndex:250},children:(0,d.jsx)("div",{className:"resize-handle-line"})})}function bV(a){return"running"===a?"#22c55e":"starting"===a?"rgba(234,179,8,0.95)":"error"===a?"#ef4444":"var(--text-dim)"}function bW(a){return"h5adexp"===a?"H5AD Exp":"stexp"}function bX(a,b,c){return Math.min(Math.max(a,b),c)}function bY(a){if(!a||"object"!=typeof a||!("app"in a))return null;let b=a.app;return b&&"object"==typeof b&&"id"in b?b:null}function bZ({appType:a,filePath:b,cwd:c,sessionId:f,appId:g,onClose:h,onAppChanged:i,onOpenTools:j}){var k;let[l,m]=(0,e.useState)(null),[n,o]=(0,e.useState)(null),[p,q]=(0,e.useState)(!1),[r,s]=(0,e.useState)(!1),[t,u]=(0,e.useState)(0),[v,w]=(0,e.useState)(()=>({left:34,top:34,width:Math.min(1280,Math.max(360,1212)),height:Math.min(880,Math.max(320,832)),maximized:!1})),[x,y]=(0,e.useState)(!1),[z,A]=(0,e.useState)(!1),B=(0,e.useRef)(null),C=(0,e.useRef)(null),D=(0,e.useRef)(null),E=!!b||!!g,F=b?(0,ap.WP)(b):l?(0,ap.WP)(l.filePath):"",G=b&&c?(0,ap.qP)(b,c):l?.filePath&&l.cwd?(0,ap.qP)(l.filePath,l.cwd):b??l?.filePath??"",H=l?.status??"idle",I=(0,e.useMemo)(()=>l?.logs?.join("\n")??"",[l?.logs]),J=l?.appType==="h5adexp"?l.url:l?.directUrl??l?.url??"",K=(0,e.useCallback)(a=>{m(a),i?.(a)},[i]);(0,e.useCallback)(async a=>{let b=await fetch(`/api/apps?appId=${encodeURIComponent(a)}`),c=await b.json(),d=bY(c);if(!b.ok||!d)throw Error(c&&"object"==typeof c&&"error"in c?String(c.error):`HTTP ${b.status}`);return K(d),d},[K]);let L=(0,e.useCallback)(async()=>{if(b&&c&&!p){q(!0),o(null);try{let d=await fetch("/api/apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"start",appType:a,filePath:b,cwd:c,sessionId:f})}),e=await d.json(),g=bY(e);if(!d.ok||!g){let a=e&&"object"==typeof e&&"error"in e?String(e.error):`HTTP ${d.status}`;throw Error(a)}K(g),u(a=>a+1)}catch(a){o(a instanceof Error?a.message:String(a))}finally{q(!1)}}},[a,K,p,c,b,f]),M=(0,e.useCallback)(async()=>{if(l?.id&&!p){q(!0),o(null);try{let a=await fetch("/api/apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"stop",appId:l.id})}),b=await a.json(),c=bY(b);if(!a.ok||!c){let c=b&&"object"==typeof b&&"error"in b?String(b.error):`HTTP ${a.status}`;throw Error(c)}K(c)}catch(a){o(a instanceof Error?a.message:String(a))}finally{q(!1)}}},[l?.id,K,p]),N=(0,e.useCallback)(a=>{0!==a.button||v.maximized||(a.preventDefault(),a.currentTarget.setPointerCapture(a.pointerId),C.current={pointerId:a.pointerId,startX:a.clientX,startY:a.clientY,left:v.left,top:v.top},y(!0))},[v.left,v.maximized,v.top]),O=(0,e.useCallback)(a=>{let b=C.current;if(!b||b.pointerId!==a.pointerId)return;let c=b.left+a.clientX-b.startX,d=b.top+a.clientY-b.startY;w(a=>({...a,left:bX(c,8,Math.max(8,window.innerWidth-120)),top:bX(d,8,Math.max(8,window.innerHeight-48))}))},[]),P=(0,e.useCallback)(a=>{let b=C.current;b?.pointerId===a.pointerId&&(a.currentTarget.releasePointerCapture(a.pointerId),C.current=null,y(!1))},[]),Q=(0,e.useCallback)(a=>{0!==a.button||v.maximized||(a.preventDefault(),a.stopPropagation(),a.currentTarget.setPointerCapture(a.pointerId),D.current={pointerId:a.pointerId,startX:a.clientX,startY:a.clientY,width:v.width,height:v.height},A(!0))},[v.height,v.maximized,v.width]),R=(0,e.useCallback)(a=>{let b=D.current;if(!b||b.pointerId!==a.pointerId)return;let c=b.width+a.clientX-b.startX,d=b.height+a.clientY-b.startY;w(a=>({...a,width:bX(c,420,Math.max(420,window.innerWidth-a.left-8)),height:bX(d,340,Math.max(340,window.innerHeight-a.top-8))}))},[]),S=(0,e.useCallback)(a=>{let b=D.current;b?.pointerId===a.pointerId&&(a.currentTarget.releasePointerCapture(a.pointerId),D.current=null,A(!1))},[]),T=(0,e.useCallback)(()=>{j?.(),h()},[h,j]),U=(0,e.useCallback)(()=>{w(a=>({...a,maximized:!a.maximized}))},[]);if(!E)return null;let V=v.maximized?{position:"fixed",inset:12,zIndex:900}:{position:"fixed",left:v.left,top:v.top,width:v.width,height:v.height,zIndex:900};return(0,d.jsxs)("div",{ref:B,role:"dialog","aria-label":`${l?.title??bW(a)} window`,tabIndex:-1,onKeyDown:a=>{"Escape"===a.key&&T()},style:{...V,display:"flex",flexDirection:"column",minWidth:v.maximized?void 0:420,minHeight:v.maximized?void 0:340,background:"var(--bg)",border:"1px solid rgba(37,99,235,0.5)",borderRadius:8,boxShadow:"0 18px 60px rgba(0,0,0,0.26)",overflow:"hidden",outline:"none"},children:[(0,d.jsxs)("div",{onPointerDown:N,onPointerMove:O,onPointerUp:P,onPointerCancel:P,style:{display:"flex",alignItems:"center",gap:8,padding:"8px 9px 8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0,userSelect:"none",cursor:v.maximized?"default":x?"grabbing":"grab"},children:[(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,d.jsx)("span",{style:{fontSize:13,fontWeight:700,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l?.title??bW(a)}),(0,d.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:bV(H),flexShrink:0}}),(0,d.jsx)("span",{style:{fontSize:11,color:bV(H),textTransform:"capitalize",flexShrink:0},children:H}),l?.pid&&(0,d.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0},children:["pid ",l.pid]}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0},children:(k=l?.rssBytes)&&Number.isFinite(k)?k<1048576?`${(k/1024).toFixed(0)}K`:k<0x40000000?`${(k/1024/1024).toFixed(1)}M`:`${(k/1024/1024/1024).toFixed(1)}G`:"-"})]}),(0,d.jsx)("div",{title:b??l?.filePath??"",style:{marginTop:2,fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:G||F})]}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:()=>u(a=>a+1),disabled:!J||l?.status==="stopped",style:b$,title:"Reload",children:"Reload"}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:()=>s(a=>!a),style:{...b$,background:r?"var(--bg-selected)":"var(--bg)",color:r?"var(--text)":"var(--text-muted)"},title:"Toggle logs",children:"Logs"}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:T,style:b$,title:"Show in Tools",children:"Tools"}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:()=>void M(),disabled:!l||"stopped"===l.status||p,style:{...b$,border:"1px solid rgba(239,68,68,0.35)",background:"rgba(239,68,68,0.08)",color:"#ef4444",opacity:!l||"stopped"===l.status||p?.55:1},title:"Stop process",children:"Stop"}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:T,"aria-label":"Minimize",title:"Minimize",style:b_,children:(0,d.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round","aria-hidden":"true",children:(0,d.jsx)("line",{x1:"4",y1:"11",x2:"12",y2:"11"})})}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:U,"aria-label":v.maximized?"Restore":"Maximize",title:v.maximized?"Restore":"Maximize",style:b_,children:v.maximized?(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,d.jsx)("path",{d:"M6 3.5h6.5V10"}),(0,d.jsx)("path",{d:"M3.5 6H10v6.5H3.5z"})]}):(0,d.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,d.jsx)("path",{d:"M4 4h8v8H4z"})})}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:h,"aria-label":"Close window",title:"Close window",style:b_,children:(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round","aria-hidden":"true",children:[(0,d.jsx)("line",{x1:"4",y1:"4",x2:"12",y2:"12"}),(0,d.jsx)("line",{x1:"12",y1:"4",x2:"4",y2:"12"})]})})]}),(n||l?.error)&&(0,d.jsx)("div",{style:{padding:"8px 12px",borderBottom:"1px solid rgba(248,113,113,0.25)",background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:12},children:n??l?.error}),(0,d.jsxs)("div",{style:{flex:1,minHeight:0,display:"flex",background:"var(--bg)"},children:[(0,d.jsx)("div",{style:{flex:1,minWidth:0,position:"relative"},children:p&&!l?.url?(0,d.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:["Starting ",bW(a),"..."]}):J&&l?.status!=="stopped"?(0,d.jsx)("iframe",{src:J,title:`${l?.title??bW(a)} - ${F}`,style:{width:"100%",height:"100%",border:"none",display:"block",background:"#fff"}},`${J}:${t}`):(0,d.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:10,color:"var(--text-muted)",fontSize:13},children:[(0,d.jsxs)("div",{children:[bW(a)," is stopped."]}),b&&c&&(0,d.jsx)("button",{type:"button",onClick:()=>void L(),disabled:p,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:p?"not-allowed":"pointer",fontSize:12,fontWeight:650},children:"Start again"})]})}),r&&(0,d.jsxs)("div",{style:{width:360,borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",display:"flex",flexDirection:"column",minHeight:0},children:[(0,d.jsx)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-muted)",fontWeight:650},children:"Process Logs"}),(0,d.jsx)("pre",{style:{flex:1,margin:0,padding:10,overflow:"auto",fontSize:11,lineHeight:1.45,color:"var(--text-muted)",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap"},children:I||"No logs yet."})]})]}),!v.maximized&&(0,d.jsx)("div",{role:"separator","aria-orientation":"horizontal","aria-label":"Resize explore window",title:"Resize",onPointerDown:Q,onPointerMove:R,onPointerUp:S,onPointerCancel:S,style:{position:"absolute",right:0,bottom:0,width:18,height:18,cursor:"nwse-resize",background:"linear-gradient(135deg, transparent 0 48%, rgba(127,127,127,0.22) 48% 52%, transparent 52% 100%)"}})]})}let b$={height:30,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,flexShrink:0},b_={width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,padding:0};function b0(a){return"running"===a?"#22c55e":"starting"===a?"rgba(234,179,8,0.95)":"error"===a?"#ef4444":"var(--text-dim)"}function b1(a){return"waiting_model"===a?"rgba(234,179,8,0.95)":"running_tools"===a?"#38bdf8":"streaming"===a?"#22c55e":"compacting"===a?"#a78bfa":"var(--text-dim)"}function b2(a){return a&&Number.isFinite(a)?a<1048576?`${(a/1024).toFixed(0)}K`:a<0x40000000?`${(a/1024/1024).toFixed(1)}M`:`${(a/1024/1024/1024).toFixed(1)}G`:"-"}function b3(a){if(!a||!Number.isFinite(a))return"-";let b=Math.max(0,Math.floor(a/1e3)),c=Math.floor(b/3600),d=Math.floor(b%3600/60),e=b%60;return c>0?`${c}h ${d}m`:d>0?`${d}m ${e}s`:`${e}s`}function b4({refreshKey:a=0,visibleAppId:b,cwd:c,onOpenApp:f,onAppChanged:g,onAppsChanged:h,agentRuntimeExtra:i}){let[j,k]=(0,e.useState)([]),[l,m]=(0,e.useState)(null),[n,o]=(0,e.useState)(null),[p,q]=(0,e.useState)(null),[r,s]=(0,e.useState)(null),[t,u]=(0,e.useState)(null),[v,w]=(0,e.useState)(null),[x,y]=(0,e.useState)(null),[z,A]=(0,e.useState)(null),[B,C]=(0,e.useState)(null),D=(0,e.useMemo)(()=>[...j].sort((a,b)=>{let c=+!!a.running,d=+!!b.running;return c!==d?d-c:Date.parse(b.lastActivity)-Date.parse(a.lastActivity)}),[j]),E=(0,e.useCallback)(async()=>{try{let a=await fetch("/api/apps",{cache:"no-store"}),b=await a.json();if(!a.ok||!Array.isArray(b.apps))throw Error(b.error??`HTTP ${a.status}`);k(b.apps),h?.(b.apps),q(null)}catch(a){q(a instanceof Error?a.message:String(a))}},[h]),F=(0,e.useCallback)(async()=>{try{let a=new URLSearchParams;c&&a.set("cwd",c);let b=await fetch(`/api/agent/runtime${a.toString()?`?${a}`:""}`,{cache:"no-store"}),d=await b.json();if(!b.ok||!Array.isArray(d.sessions))throw Error(d.error??`HTTP ${b.status}`);m(d),o(d.memory??null),s(null)}catch(a){s(a instanceof Error?a.message:String(a))}},[c]),G=(0,e.useCallback)(async a=>{y(a.id),q(null);try{let b=await fetch("/api/apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"stop",appId:a.id})}),c=await b.json();if(!b.ok||!c.app)throw Error(c.error??`HTTP ${b.status}`);k(a=>a.map(a=>a.id===c.app.id?c.app:a)),g?.(c.app),await E()}catch(a){q(a instanceof Error?a.message:String(a))}finally{y(null)}},[E,g]),H=(0,e.useCallback)(async a=>{A(a.sessionId),s(null);try{let b=await fetch(`/api/agent/${encodeURIComponent(a.sessionId)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"abort"})}),c=await b.json().catch(()=>({}));if(!b.ok||c.error)throw Error(c.error??`HTTP ${b.status}`);await F()}catch(a){s(a instanceof Error?a.message:String(a))}finally{A(null)}},[F]),I=(0,e.useCallback)(async(a,b)=>{if(c){w(`${a}:${b}`),u(null);try{let d=await fetch("/api/memory/promote",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:c,memoryId:a,target:b})}),e=await d.json().catch(()=>({}));if(!d.ok)throw Error(e.error??`HTTP ${d.status}`);await F()}catch(a){u(a instanceof Error?a.message:String(a))}finally{w(null)}}},[c,F]),J=(0,e.useCallback)(async a=>{if(c){w(`dismiss:${a}`),u(null);try{let b=await fetch("/api/memory/dismiss",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:c,memoryId:a})}),d=await b.json().catch(()=>({}));if(!b.ok)throw Error(d.error??`HTTP ${b.status}`);await F()}catch(a){u(a instanceof Error?a.message:String(a))}finally{w(null)}}},[c,F]),K=j.filter(a=>a.running).length,L=j.reduce((a,b)=>a+(b.running?b.rssBytes??0:0),0),M=l?.sessions??[],N=M.filter(a=>a.busy),O=N.filter(a=>"waiting_model"===a.phase);return(0,d.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",background:"var(--bg)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:"10px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Status"}),(0,d.jsxs)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)"},children:[N.length," agent running \xb7 ",K," explore \xb7 ",b2(L)]})]}),(0,d.jsx)("button",{type:"button",onClick:()=>{E(),F()},style:b9,title:"Refresh status",children:"Refresh"})]}),p&&(0,d.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:p}),r&&(0,d.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:r}),t&&(0,d.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:t})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"auto",padding:10},children:(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[(0,d.jsxs)("section",{children:[(0,d.jsx)(b5,{title:"Agent Runtime",subtitle:O.length>0?`${O.length} waiting for model first token`:`${N.length} active chat${1===N.length?"":"s"}`}),i,0===M.length?(0,d.jsx)(b6,{label:"No agent runtime is active."}):(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:M.map(a=>{var b;let c=a.model?`${a.model.provider}/${a.model.id}`:"-",e=a.cwd?(0,ap.WP)(a.cwd)||a.cwd:"-",f=a.activeTools.map(a=>a.name).join(", ");return(0,d.jsxs)("div",{style:{border:`1px solid ${a.busy?"rgba(37,99,235,0.35)":"var(--border)"}`,borderRadius:8,background:a.busy?"var(--bg-selected)":"var(--bg-panel)",padding:10},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,d.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:b1(a.phase),marginTop:5,flexShrink:0}}),(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,d.jsx)("span",{style:{fontSize:12,fontWeight:700,color:b1(a.phase),textTransform:"uppercase",flexShrink:0},children:"waiting_model"===(b=a.phase)?"waiting model":"running_tools"===b?"running tools":"streaming"===b?"streaming":"compacting"===b?"compacting":"idle"}),(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:c,children:c})]}),(0,d.jsxs)("div",{title:a.cwd??void 0,style:{marginTop:3,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[e," \xb7 ",a.sessionId.slice(0,8)]})]})]}),(0,d.jsxs)("div",{style:{marginTop:9,display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"5px 10px",fontSize:11,color:"var(--text-muted)"},children:[(0,d.jsx)(b7,{label:"uptime",value:b3(a.uptimeMs)}),(0,d.jsx)(b7,{label:"wait",value:b3(a.waitingForModelMs),color:"waiting_model"===a.phase?b1(a.phase):void 0}),(0,d.jsx)(b7,{label:"pending",value:null===a.pendingMessageCount?"-":String(a.pendingMessageCount)}),(0,d.jsx)(b7,{label:"event",value:a.lastEventType??"-"}),(0,d.jsx)(b7,{label:"tools",value:f||"-"}),(0,d.jsx)(b7,{label:"ops",value:a.operations.join(", ")||"-"})]}),"waiting_model"===a.phase&&(a.waitingForModelMs??0)>8e3&&(0,d.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,background:"rgba(234,179,8,0.08)",color:"rgba(234,179,8,0.95)",fontSize:11,lineHeight:1.45},children:"Waiting before the first model token. If another chat uses the same provider or gateway, the upstream may be queueing requests."}),a.errorMessage&&(0,d.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11,lineHeight:1.45},children:a.errorMessage}),(0,d.jsx)("div",{style:{marginTop:10,display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:(0,d.jsx)("button",{type:"button",onClick:()=>void H(a),disabled:!a.busy||z===a.sessionId,style:{...b9,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:a.busy&&z!==a.sessionId?1:.55},children:"Abort"})})]},a.sessionId)})})]}),(0,d.jsxs)("section",{children:[(0,d.jsx)(b5,{title:"Memory",subtitle:n?`${n.count} stored \xb7 ${n.candidateCount} candidates`:c?"loading":"No project selected"}),c?n?(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:10},children:[(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"5px 10px",fontSize:11,color:"var(--text-muted)"},children:[(0,d.jsx)(b7,{label:"fact",value:String(n.byType.fact)}),(0,d.jsx)(b7,{label:"context",value:String(n.byType.context)}),(0,d.jsx)(b7,{label:"decision",value:String(n.byType.decision)}),(0,d.jsx)(b7,{label:"preference",value:String(n.byType.preference)}),(0,d.jsx)(b7,{label:"note",value:String(n.byType.note)}),(0,d.jsx)(b7,{label:"candidates",value:String(n.candidateCount),color:n.candidateCount>0?"var(--accent)":void 0})]}),(0,d.jsx)("div",{title:n.filePath,style:{marginTop:8,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(0,ap.qP)(n.filePath,c)})]}),(0,d.jsx)(b8,{title:"Promotion Candidates",emptyLabel:"No promotion candidates yet.",items:n.topCandidates,onPromote:I,onDismiss:J,busyAction:v}),(0,d.jsx)(b8,{title:"Recent Memory",emptyLabel:"No memory stored for this project.",items:n.recent})]}):(0,d.jsx)(b6,{label:"Memory status unavailable."}):(0,d.jsx)(b6,{label:"Select a project to inspect memory status."})]}),(0,d.jsxs)("section",{children:[(0,d.jsx)(b5,{title:"Explore Tools",subtitle:`${K} running \xb7 ${b2(L)}`}),0===D.length?(0,d.jsx)(b6,{label:"No explore tools are running."}):(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:D.map(a=>{let e,g=b===a.id,h=B===a.id;return(0,d.jsxs)("div",{style:{border:`1px solid ${g?"rgba(37,99,235,0.5)":"var(--border)"}`,borderRadius:8,background:g?"var(--bg-selected)":"var(--bg-panel)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:10},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,d.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:b0(a.status),marginTop:5,flexShrink:0}}),(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,d.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)",textTransform:"uppercase",flexShrink:0},children:a.appType}),(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:a.filePath,children:(0,ap.WP)(a.filePath)})]}),(0,d.jsx)("div",{title:a.filePath,style:{marginTop:3,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(e=c&&a.filePath.startsWith(c)?c:a.cwd,(0,ap.qP)(a.filePath,e))})]})]}),(0,d.jsxs)("div",{style:{marginTop:9,display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"5px 10px",fontSize:11,color:"var(--text-muted)"},children:[(0,d.jsx)(b7,{label:"status",value:a.status,color:b0(a.status)}),(0,d.jsx)(b7,{label:"pid",value:a.pid?String(a.pid):"-"}),(0,d.jsx)(b7,{label:"memory",value:b2(a.rssBytes)}),(0,d.jsx)(b7,{label:"uptime",value:b3(a.uptimeMs)}),(0,d.jsx)(b7,{label:"port",value:String(a.port)}),(0,d.jsx)(b7,{label:"session",value:a.sessionId?a.sessionId.slice(0,8):"-"})]}),(0,d.jsxs)("div",{style:{marginTop:10,display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[(0,d.jsx)("button",{type:"button",onClick:()=>f(a),style:b9,children:"Open"}),(0,d.jsx)("button",{type:"button",onClick:()=>C(b=>b===a.id?null:a.id),style:{...b9,background:h?"var(--bg-selected)":"var(--bg)"},children:"Logs"}),(0,d.jsx)("button",{type:"button",onClick:()=>void G(a),disabled:!a.running||x===a.id,style:{...b9,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:a.running&&x!==a.id?1:.55},children:"Stop"})]})]}),h&&(0,d.jsx)("pre",{style:{maxHeight:220,overflow:"auto",margin:0,padding:10,borderTop:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",fontSize:11,lineHeight:1.45,fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap"},children:a.logs.join("\n")||"No logs yet."})]},a.id)})})]})]})})]})}function b5({title:a,subtitle:b}){return(0,d.jsxs)("div",{style:{marginBottom:8,display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:10},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:a}),(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b})]})}function b6({label:a}){return(0,d.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:"18px 10px",color:"var(--text-dim)",fontSize:12,textAlign:"center"},children:a})}function b7({label:a,value:b,color:c}){return(0,d.jsxs)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:5},children:[(0,d.jsx)("span",{style:{color:"var(--text-dim)",flexShrink:0},children:a}),(0,d.jsx)("span",{style:{color:c??"var(--text-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:b})]})}function b8({title:a,emptyLabel:b,items:c,onPromote:e,onDismiss:f,busyAction:g}){return(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,d.jsx)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",fontSize:12,fontWeight:700,color:"var(--text)"},children:a}),0===c.length?(0,d.jsx)("div",{style:{padding:"14px 10px",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:b}):(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:c.map((a,b)=>(0,d.jsxs)("div",{style:{padding:"9px 10px",borderTop:0===b?"none":"1px solid var(--border)",display:"flex",flexDirection:"column",gap:5},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},children:[(0,d.jsx)("span",{style:{fontSize:10,color:"project_memory"===a.candidate?"#f59e0b":"spark"===a.candidate?"var(--accent)":"var(--text-dim)",fontWeight:700,textTransform:"uppercase",flexShrink:0},children:"none"===a.candidate?a.memoryType:a.candidate}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",flexShrink:0},children:a.importance.toFixed(2)}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:new Date(a.timestamp).toLocaleString()})]}),(0,d.jsx)("div",{title:a.content,style:{fontSize:12,color:"var(--text)",lineHeight:1.45,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},children:a.content}),(e||f)&&(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[e&&(0,d.jsx)("button",{type:"button",disabled:a.promotedTo.includes("memory")||g===`${a.id}:memory`,onClick:()=>void e(a.id,"memory"),style:{...b9,height:24,padding:"0 8px",opacity:a.promotedTo.includes("memory")||g===`${a.id}:memory`?.55:1},children:a.promotedTo.includes("memory")?"In MEMORY.md":g===`${a.id}:memory`?"Saving...":"To MEMORY.md"}),f&&(0,d.jsx)("button",{type:"button",disabled:g===`dismiss:${a.id}`||g===`${a.id}:memory`,onClick:()=>void f(a.id),style:{...b9,height:24,padding:"0 8px",opacity:g===`dismiss:${a.id}`||g===`${a.id}:memory`?.55:1,borderColor:"var(--text-dim)",color:"var(--text-dim)"},children:g===`dismiss:${a.id}`?"Dismissing…":"Ignore"})]})]},a.id))})]})}let b9={height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:550};function ca({tabs:a,activeTabId:b,onSelectTab:c,onCloseTab:f,onAskAI:g}){let[h,i]=(0,e.useState)(null);return(0,d.jsx)("div",{style:{display:"flex",alignItems:"flex-end",background:"var(--bg-panel)",overflowX:"auto",flexShrink:0,height:36},children:a.map(a=>{let e=a.id===b,j=!1!==a.closable;return(0,d.jsxs)("div",{onClick:()=>c(a.id),style:{display:"flex",alignItems:"center",gap:6,height:36,paddingLeft:12,paddingRight:6,borderRight:"1px solid var(--border)",background:e?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:e?"var(--text)":"var(--text-muted)",whiteSpace:"nowrap",maxWidth:180,minWidth:80,flexShrink:0,userSelect:"none",transition:"background 0.1s, color 0.1s"},children:[(0,d.jsx)("span",{style:{flexShrink:0,opacity:e?1:.7,display:"flex",alignItems:"center"},children:"files"===a.icon?(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M3 7.5V6a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v1.5"}),(0,d.jsx)("path",{d:"M3 7.5h18l-1.6 9.6A2 2 0 0 1 17.4 19H6.6a2 2 0 0 1-2-1.9z"})]}):"report"===a.icon?(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,d.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,d.jsx)("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),(0,d.jsx)("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]}):"tools"===a.icon?(0,d.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.1-3.1a6 6 0 0 1-7.9 7.9l-5.7 5.7a2.1 2.1 0 0 1-3-3l5.7-5.7a6 6 0 0 1 7.9-7.9z"})}):bF(a.filePath??a.label,13)}),(0,d.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:e?500:400},title:a.filePath??a.label,children:a.label}),j&&(0,d.jsxs)(d.Fragment,{children:[e&&g&&a.filePath&&!a.icon&&(0,d.jsx)("button",{onClick:b=>{b.stopPropagation(),g(a.filePath)},title:`Ask AI about ${a.label}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:"transparent",border:"none",borderRadius:3,color:"var(--accent)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s"},children:(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M15 18H3"}),(0,d.jsx)("path",{d:"M17 6H3"}),(0,d.jsx)("path",{d:"M21 12H3"})]})}),(0,d.jsx)("button",{onClick:b=>{b.stopPropagation(),f(a.id)},onMouseEnter:()=>i(a.id),onMouseLeave:()=>i(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:h===a.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:3,color:h===a.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:"Close",children:(0,d.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,d.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,d.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]})]},a.id)})})}function cb(a){return"python"===a?"#3572A5":"#198CE7"}let cc=new Set(["png","jpg","jpeg","webp","gif","svg"]);function cd(a){let b=a.split("/").filter(Boolean).map(encodeURIComponent);return`/api/files/${b.join("/")}?type=read&raw=1`}function ce(a){return!Number.isFinite(a)||a<=0?"0.0G":`${(a/1024/1024/1024).toFixed(1)}G`}function cf({active:a,label:b,count:c,onClick:e}){return(0,d.jsxs)("button",{type:"button",onClick:e,style:{height:26,padding:"0 9px",border:`1px solid ${a?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:5,background:a?"var(--bg-selected)":"var(--bg)",color:a?"var(--accent)":"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[b,"number"==typeof c?` (${c})`:""]})}let cg={height:24,padding:"0 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:10,fontWeight:600,whiteSpace:"nowrap"};function ch({status:a}){return(0,d.jsx)("span",{style:{color:"succeeded"===a?"#34d399":"failed"===a?"#f87171":"var(--text-dim)",fontSize:10,fontWeight:700,fontFamily:"var(--font-mono)"},children:"succeeded"===a?"✅":"failed"===a?"❌":"⬜"})}function ci({sessionId:a,cwd:b,onAskAboutCell:c,onAskAboutArtifact:f,onEditArtifact:g,onOpenArtifact:h}){let[i,j]=(0,e.useState)(null),[k,l]=(0,e.useState)(!0),[m,n]=(0,e.useState)(null),[o,p]=(0,e.useState)(new Set),[q,r]=(0,e.useState)("runs"),[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)(!1),[w,x]=(0,e.useState)(null),[y,z]=(0,e.useState)(!1);(0,e.useCallback)(async()=>{if(a)try{let c=new URLSearchParams;c.set("sessionId",a),b&&c.set("cwd",b);let d=await fetch(`/api/plot-kernels/status?${c}`),e=await d.json();if(!d.ok||e.error)throw Error(e.error??`HTTP ${d.status}`);t(e)}catch{}},[a,b]);let A=(0,e.useCallback)(async()=>{if(!u&&a){v(!0),x(null);try{let b=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:a})}),c=await b.json();if(!b.ok||!c.success)throw Error(c.error??`HTTP ${b.status}`);t(null)}catch(a){x(a instanceof Error?a.message:String(a))}finally{v(!1)}}},[a,u]),B=(0,e.useCallback)(async()=>{if(a){z(!0);try{let b=await fetch(`/api/sessions/${encodeURIComponent(a)}/workbench-review`),c=await b.json();if(!b.ok||c.error)throw Error(c.error??`HTTP ${b.status}`);j(a=>a?{...a,review:c}:a)}catch{}finally{z(!1)}}},[a]),C=(0,e.useCallback)(()=>{if(!i||0===i.cells.length)return;let b="r"===i.language?"R":"python",c=new Blob([JSON.stringify({nbformat:4,nbformat_minor:5,metadata:{kernelspec:{display_name:"R"===b?"R":"Python 3",language:b.toLowerCase(),name:"R"===b?"ir":"python3"},language_info:{name:b.toLowerCase()}},cells:i.cells.map(a=>{let b=[];for(let c of(a.stdoutPreview&&b.push({output_type:"stream",name:"stdout",text:a.stdoutPreview}),a.stderrPreview&&b.push({output_type:"stream",name:"stderr",text:a.stderrPreview}),a.artifacts)){let a=c.path.split(".").pop()?.toLowerCase();b.push(a&&cc.has(a)?{output_type:"display_data",data:{"image/png":""},metadata:{"annovibe-artifact":c.path}}:{output_type:"display_data",data:{"text/plain":c.path},metadata:{"annovibe-artifact":c.path}})}return{cell_type:"code",metadata:{},source:a.code.split("\n").map(a=>a+"\n"),outputs:b,execution_count:null}})},null,2)],{type:"application/x-ipynb+json"}),d=URL.createObjectURL(c),e=document.createElement("a");e.href=d,e.download=`workbench_${a.slice(0,8)}.ipynb`,document.body.appendChild(e),e.click(),document.body.removeChild(e),URL.revokeObjectURL(d)},[i,a]),D=(0,e.useCallback)(()=>{if(!i?.notes)return;let a=i.notes.map(a=>`#${a.cellIndex} ${a.title}
44
- ${a.summary}`).join("\n\n");navigator.clipboard.writeText(a)},[i]),E=(0,e.useMemo)(()=>i?.artifacts??[],[i]),F=(0,e.useMemo)(()=>{if(!i)return null;let a="python"===i.language?"Python":"r"===i.language?"R":"?",b=[a,i.kernelId,`${i.totalRuns} runs`].filter(Boolean).join(" \xb7 ");return{langLabel:a,subtitle:b}},[i]),G=(0,e.useMemo)(()=>s?.kernels?s.kernels.filter(b=>b.sessionId===a):[],[s,a]);if(k)return(0,d.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"Loading workbench state..."});if(m)return m.includes("no kernel state found")||m.includes("404")?(0,d.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No workbench runs yet."}):(0,d.jsxs)("div",{style:{padding:24,textAlign:"center",color:"#f87171",fontSize:12},children:["Failed to load workbench state: ",m]});if(!i||0===i.cells.length)return(0,d.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No workbench runs yet."});let{cells:H}=i,I=i.review?.issues.length??0;return(0,d.jsxs)("div",{style:{height:"100%",overflow:"auto",background:"var(--bg)",fontSize:12},children:[s&&s.currentSessionBytes>0&&(0,d.jsxs)("div",{style:{margin:10,padding:12,borderRadius:8,border:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Runtime Memory"}),(0,d.jsx)("div",{style:{marginTop:3,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:(0,d.jsxs)("span",{style:{fontSize:12,color:"var(--text)",fontVariantNumeric:"tabular-nums"},children:[(0,d.jsx)("span",{style:{color:"var(--accent)",fontWeight:600},children:ce(s.currentSessionBytes)}),s.totalBytes!==s.currentSessionBytes&&(0,d.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" / ",ce(s.totalBytes)," total"]})]})}),G.length>0&&(0,d.jsx)("div",{style:{marginTop:8,display:"flex",flexDirection:"column",gap:4},children:G.map((a,b)=>(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:[(0,d.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:cb(a.language),flexShrink:0}}),(0,d.jsx)("span",{style:{color:cb(a.language),fontWeight:600},children:a.language.toUpperCase()}),(0,d.jsx)("span",{children:ce(a.rssBytes)}),(0,d.jsxs)("span",{style:{color:"var(--text-dim)",fontSize:10},children:["PID ",a.pid]}),a.lastActivity&&(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto"},children:new Date(a.lastActivity).toLocaleString()})]},a.pid||b))})]}),(0,d.jsx)("button",{type:"button",onClick:A,disabled:u,style:{flexShrink:0,height:30,padding:"0 12px",border:"1px solid rgba(239,68,68,0.35)",borderRadius:6,background:u?"var(--bg)":"rgba(239,68,68,0.08)",color:u?"var(--text-dim)":"#ef4444",cursor:u?"default":"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap",opacity:u?.55:1},children:u?"Releasing...":"Release Memory"})]}),w&&(0,d.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:w})]}),F&&(0,d.jsxs)("div",{style:{padding:"10px 14px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Workbench"}),(0,d.jsxs)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)"},children:[F.subtitle," \xb7 ","live"===i.freshness?"live inspected":"inferred from executed cells"]}),i.review&&(0,d.jsxs)("div",{style:{marginTop:6,fontSize:10,color:i.review.issueCounts.error>0?"#f87171":i.review.issueCounts.warning>0?"#fbbf24":"#34d399"},children:["Review: ",0===I?"no issues":`${I} traceability issues`]})]}),(0,d.jsxs)("div",{style:{display:"flex",gap:6,flexShrink:0,flexWrap:"wrap",justifyContent:"flex-end"},children:["notes"===q&&(0,d.jsx)("button",{type:"button",onClick:D,style:cg,children:"Copy"}),"review"===q&&(0,d.jsx)("button",{type:"button",onClick:B,disabled:y,style:{...cg,opacity:y?.55:1},children:y?"Reviewing...":"Refresh"}),(0,d.jsx)("button",{type:"button",onClick:C,title:"Export as Jupyter notebook",style:cg,children:"Export .ipynb"})]})]}),(0,d.jsxs)("div",{style:{marginTop:10,display:"flex",gap:6,overflowX:"auto",paddingBottom:1},children:[(0,d.jsx)(cf,{active:"runs"===q,label:"Runs",count:H.length,onClick:()=>r("runs")}),(0,d.jsx)(cf,{active:"artifacts"===q,label:"Artifacts",count:E.length,onClick:()=>r("artifacts")}),(0,d.jsx)(cf,{active:"notes"===q,label:"Notes",count:i.notes?.length??H.length,onClick:()=>r("notes")}),(0,d.jsx)(cf,{active:"review"===q,label:"Review",count:I,onClick:()=>r("review")})]}),i.imports.length>0&&"runs"===q&&(0,d.jsxs)("div",{style:{marginTop:8},children:[(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginBottom:3},children:"Historically imported:"}),(0,d.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:3},children:[i.imports.slice(0,12).map(a=>(0,d.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:3,background:"var(--bg-selected)",color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:a.length<=30?a:a.slice(0,30)+"..."},a)),i.imports.length>12&&(0,d.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)"},children:["+",i.imports.length-12," more"]})]})]}),("live"===i.freshness?i.liveObjects.length>0:i.loadedObjects.length>0)&&"runs"===q&&(0,d.jsxs)("div",{style:{marginTop:6},children:[(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginBottom:3},children:"live"===i.freshness?"Live objects:":"Historically loaded:"}),(0,d.jsx)("div",{children:("live"===i.freshness?i.liveObjects:i.loadedObjects).slice(0,6).map(a=>(0,d.jsx)("span",{style:{fontSize:10,padding:"1px 6px",marginRight:4,borderRadius:3,background:"rgba(37,99,235,0.1)",color:"var(--accent)",fontFamily:"var(--font-mono)"},title:"live"===i.freshness&&"type"in a?`${a.type}${a.shape?` (${a.shape})`:""}`:void 0,children:a.name},a.name))})]})]}),"artifacts"===q&&(0,d.jsx)("div",{style:{padding:10},children:0===E.length?(0,d.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No generated artifacts yet."}):(0,d.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(150px, 1fr))",gap:8},children:E.map(a=>(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:"var(--bg-panel)"},children:["image"===a.kind?(0,d.jsx)("button",{type:"button",onClick:()=>h?.(a.path),style:{display:"block",width:"100%",padding:0,border:"none",background:"transparent",cursor:"pointer"},children:(0,d.jsx)("img",{src:cd(a.path),alt:a.fileName,loading:"lazy",style:{width:"100%",height:118,objectFit:"cover",display:"block"}})}):(0,d.jsx)("button",{type:"button",onClick:()=>h?.(a.path),style:{width:"100%",height:118,border:"none",background:"var(--bg)",color:"var(--text-muted)",fontSize:11,cursor:"pointer",textTransform:"uppercase"},children:a.kind}),(0,d.jsxs)("div",{style:{padding:8},children:[(0,d.jsx)("div",{title:a.path,style:{fontSize:10,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.fileName}),(0,d.jsxs)("div",{style:{marginTop:5,display:"flex",alignItems:"center",gap:5,color:"var(--text-dim)",fontSize:10},children:[(0,d.jsxs)("span",{children:["#",a.provenance.cellIndex]}),(0,d.jsx)(ch,{status:a.provenance.status}),(0,d.jsx)("span",{children:a.provenance.language})]}),(0,d.jsxs)("div",{style:{marginTop:7,display:"flex",gap:5,flexWrap:"wrap"},children:[(0,d.jsx)("button",{type:"button",onClick:()=>f?.(a),style:cg,children:"Ask"}),(0,d.jsx)("button",{type:"button",onClick:()=>g?.(a),style:cg,children:"Edit"}),(0,d.jsx)("button",{type:"button",onClick:()=>h?.(a.path),style:cg,children:"Open"})]})]})]},a.id))})}),"notes"===q&&(0,d.jsx)("div",{style:{padding:12},children:0===(i.notes??[]).length?(0,d.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No research notes yet."}):(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:(i.notes??[]).map(a=>(0,d.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",paddingBottom:9},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11},children:[(0,d.jsxs)("span",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",minWidth:28},children:["#",a.cellIndex]}),(0,d.jsx)(ch,{status:a.status}),(0,d.jsx)("span",{style:{color:"var(--text)",fontWeight:650,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.title})]}),(0,d.jsx)("div",{style:{marginTop:5,color:"var(--text-muted)",fontSize:12,lineHeight:1.45},children:a.summary})]},a.id))})}),"review"===q&&(0,d.jsx)("div",{style:{padding:12},children:i.review&&0!==i.review.issues.length?(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:i.review.issues.map(a=>(0,d.jsxs)("div",{style:{padding:10,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,d.jsx)("span",{style:{color:"error"===a.severity?"#f87171":"warning"===a.severity?"#fbbf24":"var(--text-dim)",fontSize:11,fontWeight:700},children:a.severity.toUpperCase()}),a.cellIndex&&(0,d.jsxs)("span",{style:{color:"var(--text-dim)",fontSize:10},children:["Cell #",a.cellIndex]})]}),(0,d.jsx)("div",{style:{marginTop:5,color:"var(--text)",fontSize:12,fontWeight:650},children:a.title}),(0,d.jsx)("div",{style:{marginTop:4,color:"var(--text-muted)",fontSize:11,lineHeight:1.45},children:a.detail})]},a.id))}):(0,d.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No deterministic traceability issues found."})}),"runs"===q&&(0,d.jsx)("div",{children:H.map(a=>{let b,e=o.has(a.index),f="failed"===a.status;return(0,d.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:0,background:e?"var(--bg-selected)":"transparent",transition:"background 0.1s"},children:[(0,d.jsxs)("button",{type:"button",onClick:()=>{var b;return b=a.index,void p(a=>{let c=new Set(a);return c.has(b)?c.delete(b):c.add(b),c})},style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0,padding:"6px 14px",border:"none",background:"transparent",cursor:"pointer",fontSize:11,color:"var(--text)",textAlign:"left"},children:[(0,d.jsx)("span",{style:{flexShrink:0,fontSize:10},children:e?"v":">"}),(0,d.jsxs)("span",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",minWidth:24},children:["#",a.index]}),(0,d.jsx)(ch,{status:a.status}),(0,d.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:a.title||"kernel_plot_run"}),(0,d.jsx)("span",{style:{flexShrink:0,fontSize:9,padding:"1px 5px",borderRadius:3,background:"var(--bg-hover)",color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:a.runtime??"kernel-lite"}),a.language&&(0,d.jsx)("span",{style:{flexShrink:0,fontSize:9,padding:"1px 5px",borderRadius:3,background:cb(a.language)+"18",color:cb(a.language),fontFamily:"var(--font-mono)"},children:a.language})]}),c&&(0,d.jsx)("button",{type:"button",onClick:b=>{b.stopPropagation(),c(a.code,a.index)},title:"Ask about this cell in chat",style:{...cg,marginRight:10,height:22},children:"Ask"})]}),e&&(0,d.jsxs)("div",{style:{padding:"0 14px 10px"},children:[(0,d.jsx)("pre",{style:{margin:"8px 0 0",padding:10,borderRadius:6,background:"var(--bg-panel)",border:"1px solid var(--border)",fontSize:11,lineHeight:1.5,color:"var(--text)",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:400,overflow:"auto"},children:a.code}),(a.stdoutPreview||a.stderrPreview)&&(0,d.jsxs)("div",{style:{marginTop:6,display:"grid",gap:4},children:[a.stdoutPreview&&(0,d.jsx)("pre",{style:{margin:0,padding:8,borderRadius:4,background:"var(--bg-panel)",border:"1px solid var(--border)",fontSize:10,lineHeight:1.45,color:f?"#fbbf24":"var(--text-muted)",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:a.stdoutPreview}),a.stderrPreview&&(0,d.jsx)("pre",{style:{margin:0,padding:8,borderRadius:4,background:"rgba(248,113,113,0.08)",border:"1px solid rgba(248,113,113,0.2)",fontSize:10,lineHeight:1.45,color:"#f87171",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:a.stderrPreview})]}),a.artifacts.length>0&&(0,d.jsxs)("div",{style:{marginTop:6},children:[(0,d.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",marginBottom:4},children:["Artifacts (",a.artifacts.length,"):"]}),(0,d.jsx)("div",{style:{display:"grid",gap:2},children:a.artifacts.map((a,b)=>(0,d.jsx)("div",{style:{fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-muted)",padding:"2px 0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:a.path,children:a.path},b))})]}),0===(b=a.artifacts.filter(a=>{let b=a.path.split(".").pop()?.toLowerCase();return b&&cc.has(b)})).length?null:(0,d.jsxs)("div",{style:{marginTop:8},children:[(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginBottom:4},children:"Previews:"}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(120px, 1fr))",gap:6},children:[b.slice(0,8).map((a,b)=>(0,d.jsx)("button",{type:"button",onClick:()=>h?.(a.path),title:a.path.split("/").pop()||a.path,style:{display:"block",border:"1px solid var(--border)",borderRadius:6,overflow:"hidden",background:"var(--bg-panel)",padding:0,cursor:"pointer"},children:(0,d.jsx)("img",{src:cd(a.path),alt:a.path.split("/").pop()||`Output ${b+1}`,loading:"lazy",style:{width:"100%",height:100,objectFit:"cover",display:"block"}})},b)),b.length>8&&(0,d.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",padding:8,textAlign:"center"},children:["+",b.length-8," more"]})]})]})]})]},a.toolCallId)})})]})}function cj(a){let b=a,c=0;for(;1===b.children.length;)b=b.children[0],c++;return{node:b,skipped:c}}function ck({node:a,activePathIds:b,depth:c,isLast:e,parentLines:f,onSelect:g}){let{node:h,skipped:i}=cj(a),j=b.has(h.entry.id),k=b.has(a.entry.id)||b.has(h.entry.id),l=function(a){if("message"===a.type&&"message"in a){let b=a.message,c=b.content,d="";if("string"==typeof c?d=c:Array.isArray(c)&&(d=c.filter(a=>"text"===a.type).map(a=>a.text).join(" ")),d.length>40&&(d=d.slice(0,40)+"…"),d)return d;if("assistant"===b.role)return"[assistant]"}return a.type}(h.entry),m="message"===h.entry.type&&"message"in h.entry?h.entry.message.role:null;return(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>g(h.entry.id),children:[f.map((a,b)=>(0,d.jsx)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:a&&(0,d.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:0,width:1,background:"var(--border)"}})},b)),(0,d.jsxs)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:[(0,d.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:e?"50%":0,width:1,background:"var(--border)"}}),(0,d.jsx)("div",{style:{position:"absolute",left:7,top:"50%",width:9,height:1,background:"var(--border)"}})]}),(0,d.jsx)("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:j?"var(--accent)":k?"var(--text-muted)":"var(--border)",border:j?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),m&&(0,d.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===m?"var(--accent)":"var(--text-dim)",background:"user"===m?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===m?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===m?"U":"A"}),i>0&&(0,d.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",i]}),(0,d.jsx)("span",{style:{fontSize:11,color:j?"var(--text)":k?"var(--text-muted)":"var(--text-dim)",fontWeight:j?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:l})]}),h.children.map((a,i)=>(0,d.jsx)(ck,{node:a,activePathIds:b,depth:c+1,isLast:i===h.children.length-1,parentLines:[...f,!e],onSelect:g},a.entry.id))]})}function cl({tree:a,activeLeafId:b,onLeafChange:c,inline:f,containerRef:g,open:h,onToggle:i,hasSession:j,embedded:k}){let[l,m]=(0,e.useState)(!1),n=void 0!==h?h:l,o=(0,e.useRef)(null),[p,q]=(0,e.useState)(null),r=(0,e.useMemo)(()=>b?new Set(function a(c,d){for(let e of c){let c=[...d,e.entry.id];if(e.entry.id===b)return c;let f=a(e.children,c);if(f)return f}return null}(a,[])??[]):new Set,[a,b]),s=(0,e.useCallback)(a=>{c(a)},[c]),t=j?!function a(b){for(let c of b)if(c.children.length>1||a(c.children))return!0;return!1}(a)?"This session has no branches":null:"No active session",u=a.length>0?cj(a[0]):null,v=u?.node??null,w=!t&&v&&v.children.length>1,x=(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:w?"var(--accent)":"var(--text-dim)",flexShrink:0},children:[(0,d.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,d.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,d.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,d.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),y=(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{marginLeft:2,transform:n?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,d.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})});return k?(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"8px 10px",borderBottom:w?"1px solid var(--border)":"none"},children:[x,(0,d.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:"Branches"})]}),w&&v?(0,d.jsx)("div",{style:{padding:"4px 10px 8px",maxHeight:260,overflowY:"auto"},children:v.children.map((a,b)=>(0,d.jsx)(ck,{node:a,activePathIds:r,depth:0,isLast:b===v.children.length-1,parentLines:[],onSelect:s},a.entry.id))}):(0,d.jsx)("div",{style:{padding:"0 10px 10px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:t??"This session has no branches"})]}):f?(0,d.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,d.jsxs)("button",{ref:o,className:"topbar-branches-button",onClick:()=>i?i():m(a=>!a),title:"Branches","aria-label":"Branches",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:n?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${n?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:n?"var(--text)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, border-color 0.1s"},onMouseEnter:a=>{a.currentTarget.style.color="var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color=n?"var(--text)":"var(--text-muted)",a.currentTarget.style.background=n?"var(--bg-selected)":"var(--bg-panel)"},children:[(0,d.jsx)("span",{className:"topbar-branches-icon",children:x}),(0,d.jsx)("span",{className:"topbar-branches-label",children:"Branches"})]}),n&&p&&(0,d.jsx)("div",{style:{position:"fixed",top:p.top,left:p.left,width:p.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:w&&v?(0,d.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:v.children.map((a,b)=>(0,d.jsx)(ck,{node:a,activePathIds:r,depth:0,isLast:b===v.children.length-1,parentLines:[],onSelect:s},a.entry.id))}):(0,d.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:t})})]}):(0,d.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,d.jsxs)("button",{onClick:()=>m(a=>!a),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 12px",background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:11,textAlign:"left"},children:[x,(0,d.jsx)("span",{style:{color:"var(--text-muted)"},children:"Branches"}),y]}),n&&(0,d.jsx)("div",{style:{position:"absolute",top:"100%",left:0,right:0,background:"var(--bg)",borderBottom:"1px solid var(--border)",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100},children:w&&v?(0,d.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:v.children.map((a,b)=>(0,d.jsx)(ck,{node:a,activePathIds:r,depth:0,isLast:b===v.children.length-1,parentLines:[],onSelect:s},a.entry.id))}):(0,d.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:t??"This session has no branches"})})]})}function cm(a,b="0 0 24 24"){let c=({size:c=24,style:e})=>(0,d.jsx)("svg",{width:c,height:c,viewBox:b,fill:"none",style:e,children:a});return c.displayName="ProviderIcon",c}let cn=cm((0,d.jsx)("path",{d:"M17.5 3H6.5L3 21h4l1.2-6h7.6l1.2 6h4L17.5 3zm-2.3 9H8.8L12 5.5 15.2 12z",fill:"currentColor"})),co=cm((0,d.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round"})),cp=cm((0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 01-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z",fill:"#4285F4"}),(0,d.jsx)("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),(0,d.jsx)("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),(0,d.jsx)("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]})),cq=cm((0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#4D6BFE"}),(0,d.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"10",fontWeight:"bold",fontFamily:"sans-serif",children:"DS"})]})),cr=cm((0,d.jsx)("path",{d:"M4 4h16v16H4z",fill:"#F55036"}),"0 0 24 24"),cs=cm((0,d.jsx)("path",{d:"M4 4h5v5H4zm5.5 0h5v5h-5zM15 4h5v5h-5zM4 9.5h5v5H4zm5.5 5.5h5v5h-5zM15 9.5h5v5h-5z",fill:"#FA6F00"})),ct=cm((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),cu=cm((0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#00D4AA"}),(0,d.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"MM"})]})),cv=cm((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#FF5722"}),"0 0 24 24"),cw=cm((0,d.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 5h2v3h-2V7zm0 4h2v2h-2v-2zm3 5H7v-2h7v2z",fill:"#FFD21E"})),cx=cm((0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#E84026"}),(0,d.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"CB"})]})),cy=cm((0,d.jsx)("path",{d:"M12 2l9 5v10l-9 5-9-5V7l9-5z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})),cz=cm((0,d.jsx)("path",{d:"M4 4l8 8 8-8M4 20l8-8 8 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})),cA=cm((0,d.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 5l4 3-4 3V7z",fill:"#F38020"})),cB={anthropic:{Icon:cn,hasColor:!1},openai:{Icon:co,hasColor:!1},"openai-codex":{Icon:co,hasColor:!1},google:{Icon:cp,hasColor:!0},"google-vertex":{Icon:cp,hasColor:!0},deepseek:{Icon:cq,hasColor:!0},groq:{Icon:cr,hasColor:!1},mistral:{Icon:cs,hasColor:!0},moonshotai:{Icon:ct,hasColor:!1},"moonshotai-cn":{Icon:ct,hasColor:!1},moonshot:{Icon:ct,hasColor:!1},minimax:{Icon:cu,hasColor:!0},"minimax-cn":{Icon:cu,hasColor:!0},fireworks:{Icon:cv,hasColor:!0},huggingface:{Icon:cw,hasColor:!0},cerebras:{Icon:cx,hasColor:!0},openrouter:{Icon:cy,hasColor:!1},xai:{Icon:cz,hasColor:!1},"cloudflare-ai-gateway":{Icon:cA,hasColor:!0},"cloudflare-workers-ai":{Icon:cA,hasColor:!0},"vercel-ai-gateway":{Icon:cm((0,d.jsx)("path",{d:"M12 2L22 20H2L12 2z",fill:"currentColor"})),hasColor:!1},"github-copilot":{Icon:cm((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),hasColor:!1},"amazon-bedrock":{Icon:cm((0,d.jsx)("path",{d:"M3 15h2l1-3h2l1 3h2V9H9v3L8 9H6l-1 3V9H3v6zm9 0h2v-2h2v-2h-2V9h-2v2h-2v2h2v2z",fill:"#FF9900"})),hasColor:!0},"azure-openai-responses":{Icon:cm((0,d.jsx)("path",{d:"M12 2L3 18h5l4-6 4 6h5L12 2z",fill:"#0078D4"})),hasColor:!0},"kimi-coding":{Icon:cm((0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#6C5CE7"}),(0,d.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"10",fontWeight:"bold",fontFamily:"sans-serif",children:"Ki"})]})),hasColor:!0},qwen:{Icon:cm((0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#615CED"}),(0,d.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"QW"})]})),hasColor:!0},zai:{Icon:cm((0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#3859FF"}),(0,d.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"ZP"})]})),hasColor:!0},cohere:{Icon:cm((0,d.jsx)("path",{d:"M4 8h16v2H4zm0 4h12v2H4zm0 4h8v2H4z",fill:"#3059B1"})),hasColor:!0},perplexity:{Icon:cm((0,d.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"#1DB954",strokeWidth:"1.5",fill:"none",strokeLinejoin:"round"})),hasColor:!0},together:{Icon:cm((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#0F6CBD"}),"0 0 24 24"),hasColor:!0},grok:{Icon:cm((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),hasColor:!1}},cC=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],cD="openai-completions",cE={off:"none",xhigh:"xhigh"};function cF(a){return a?.toLowerCase().replace(/\s+/g,"-")??""}function cG(a){return/(^|[^a-z0-9])gpt-5($|[.-])/.test(cF(a))}function cH(a){return/[.-](minimal|low|medium|high|xhigh)$/.test(cF(a))}function cI(a){return cG(a.id)||cG(a.name)}function cJ(a,b=cD){if(!cI(a))return a;let c=a.api??("openai-responses"===b?void 0:"openai-responses");if(cI(a)&&(cH(a.id)||cH(a.name))){let{reasoning:b,thinkingLevelMap:d,...e}=a;return{...e,api:c}}return{...a,api:c,reasoning:a.reasoning??!0,thinkingLevelMap:a.thinkingLevelMap??cE}}function cK({label:a,children:b}){return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,d.jsx)("label",{style:{fontSize:11,color:"var(--text-muted)",fontWeight:500},children:a}),b]})}let cL={padding:"6px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",width:"100%",boxSizing:"border-box"};function cM({value:a,onChange:b,placeholder:c,mono:e}){return(0,d.jsx)("input",{value:a,onChange:a=>b(a.target.value),placeholder:c,style:{...cL,fontFamily:e?"var(--font-mono)":"inherit"}})}function cN({value:a,onChange:b,placeholder:c,mono:f,onKeyDown:g,autoComplete:h="off",spellCheck:i=!1,style:j}){let[k,l]=(0,e.useState)(!1);return(0,d.jsxs)("div",{style:{position:"relative",width:"100%",...j},children:[(0,d.jsx)("input",{type:k?"text":"password",value:a,onChange:a=>b(a.target.value),onKeyDown:g,placeholder:c,style:{...cL,paddingRight:34,fontFamily:f?"var(--font-mono)":"inherit"},autoComplete:h,spellCheck:i}),(0,d.jsx)("button",{type:"button",onClick:()=>l(a=>!a),"aria-label":k?"Hide API key":"Show API key",title:k?"Hide API key":"Show API key",style:{position:"absolute",right:5,top:"50%",transform:"translateY(-50%)",width:24,height:24,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:k?(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20C7 20 2.73 16.89 1 12a18.45 18.45 0 0 1 5.06-6.94"}),(0,d.jsx)("path",{d:"M9.9 4.24A10.94 10.94 0 0 1 12 4c5 0 9.27 3.11 11 8a18.5 18.5 0 0 1-2.16 3.19"}),(0,d.jsx)("path",{d:"M14.12 14.12A3 3 0 0 1 9.88 9.88"}),(0,d.jsx)("path",{d:"M1 1l22 22"})]}):(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8S1 12 1 12Z"}),(0,d.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]})}function cO({value:a,onChange:b,placeholder:c}){return(0,d.jsx)("input",{type:"number",value:a,onChange:a=>b(a.target.value),placeholder:c,style:cL})}function cP({value:a,onChange:b,options:c,required:e}){return(0,d.jsxs)("select",{value:a,onChange:a=>b(a.target.value),style:{...cL,color:a?"var(--text)":"var(--text-dim)"},children:[!e&&(0,d.jsx)("option",{value:"",children:"— inherit / none —"}),c.map(a=>(0,d.jsx)("option",{value:a,children:a},a))]})}function cQ({label:a,checked:b,onChange:c}){return(0,d.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,cursor:"pointer",fontSize:12,color:"var(--text-muted)"},children:[(0,d.jsx)("input",{type:"checkbox",checked:b,onChange:a=>c(a.target.checked),style:{width:13,height:13,accentColor:"var(--accent)",cursor:"pointer"}}),a]})}function cR({children:a}){return(0,d.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:2},children:a})}function cS({name:a,provider:b,onChange:c,onRename:f,onDelete:g}){let[h,i]=(0,e.useState)(a),j=(a,d)=>c({...b,[a]:d});return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,d.jsx)(cR,{children:"Provider"}),(0,d.jsx)("button",{onClick:g,style:{padding:"3px 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11},children:"Delete"})]}),(0,d.jsxs)(cK,{label:"Provider name",children:[(0,d.jsx)(cM,{value:h,onChange:i,placeholder:"provider-name",mono:!0}),h!==a&&h.trim()&&(0,d.jsx)("button",{onClick:()=>f(h.trim()),style:{marginTop:4,padding:"3px 10px",background:"var(--accent)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:11,alignSelf:"flex-start"},children:"Rename"})]}),(0,d.jsx)(cK,{label:"Base URL",children:(0,d.jsx)(cM,{value:b.baseUrl??"",onChange:a=>j("baseUrl",a||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,d.jsxs)(cK,{label:"API Key",children:[(0,d.jsx)(cN,{value:b.apiKey??"",onChange:a=>j("apiKey",a||void 0),placeholder:"ENV_VAR_NAME, !shell-command, or literal key",mono:!0}),(0,d.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:["Prefix with ",(0,d.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"!"})," to run a shell command, or use an env var name"]})]}),(0,d.jsx)(cK,{label:"API",children:(0,d.jsx)(cP,{value:b.api??"openai-completions",onChange:a=>j("api",a),options:cC,required:!0})})]})}let cT=["off","minimal","low","medium","high","xhigh"],cU={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c"};function cV({value:a,onChange:b}){let c=a??{},e=(a,d)=>{let e={...c};"omit"===d?delete e[a]:e[a]=d,b(Object.keys(e).length?e:void 0)};return(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:cT.map(a=>{let b=c[a],f=a in c?null===b?"null":"string":"omit",g="string"==typeof b?b:"",h=cU[a],i={padding:"4px 10px",fontSize:10,border:"none",cursor:"pointer",fontWeight:400,transition:"background 0.1s, color 0.1s",whiteSpace:"nowrap",background:"var(--bg-panel)",color:"var(--text-dim)"},j={background:"var(--accent)",color:"#fff",fontWeight:600};return(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 4px",borderRadius:6,background:"transparent",border:"1px solid transparent"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,width:68,flexShrink:0},children:[(0,d.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:h,flexShrink:0,opacity:"null"===f?.3:1}}),(0,d.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===f?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===f?"line-through":"none"},children:a})]}),(0,d.jsxs)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",flexShrink:0},children:[(0,d.jsx)("button",{onClick:()=>e(a,"omit"),style:{...i,..."omit"===f?j:{}},children:"Default"}),(0,d.jsx)("button",{onClick:()=>e(a,null),style:{...i,borderLeft:"1px solid var(--border)",..."null"===f?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:"Disabled"})]}),(0,d.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===f?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,d.jsx)("button",{onClick:()=>e(a,g||a),style:{...i,..."string"===f?j:{},borderRight:"1px solid var(--border)",flexShrink:0},children:"Custom"}),(0,d.jsx)("input",{value:g,onChange:b=>e(a,b.target.value),onFocus:()=>{"string"!==f&&e(a,g||a)},placeholder:a,maxLength:10,style:{width:"12ch",background:"string"===f?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===f?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},a)})})}let cW={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function cX({providerName:a,provider:b,model:c,onChange:f,onDelete:g}){let[h,i]=(0,e.useState)({phase:"idle"}),j=(a,b)=>f({...c,[a]:b}),k=a=>{f(cJ(a,b.api??cD))},l=(()=>{if("idle"===h.phase)return null;if("testing"===h.phase)return"Testing model connection...";let a=[void 0!==h.latencyMs?`${h.latencyMs}ms`:null,void 0!==h.status?`HTTP ${h.status}`:null].filter(Boolean);return"success"===h.phase?["Connected",...a,h.responseText||null].filter(Boolean).join(" \xb7 "):["Failed",...a,h.message].filter(Boolean).join(" \xb7 ")})(),m=(0,e.useCallback)(async()=>{if(c.id.trim()&&"testing"!==h.phase){i({phase:"testing"});try{let d=await fetch("/api/models-config/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:a,provider:b,model:c})}),e=await d.json();if(!d.ok||!e.ok)return void i({phase:"error",message:e.error??`HTTP ${d.status}`,latencyMs:e.latencyMs,status:e.status});i({phase:"success",latencyMs:e.latencyMs,status:e.status,responseText:e.responseText})}catch(a){i({phase:"error",message:a instanceof Error?a.message:String(a)})}}},[c,b,a,h.phase]);return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,d.jsx)(cR,{children:"Model"}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[l&&(0,d.jsx)("span",{title:l,style:{maxWidth:260,height:24,padding:"0 8px",border:`1px solid ${"error"===h.phase?"#fecaca":"success"===h.phase?"#bbf7d0":"var(--border)"}`,borderRadius:4,background:"error"===h.phase?"#fee2e2":"success"===h.phase?"#dcfce7":"#e5e7eb",color:"#111827",fontSize:11,display:"inline-flex",alignItems:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",boxSizing:"border-box"},children:l}),(0,d.jsxs)("button",{onClick:m,disabled:!c.id.trim()||"testing"===h.phase,title:"Test model connection",style:{height:24,padding:"0 8px",background:"success"===h.phase?"#16a34a":"none",border:`1px solid ${"success"===h.phase?"#16a34a":"var(--border)"}`,borderRadius:4,color:"success"===h.phase?"#fff":c.id.trim()&&"testing"!==h.phase?"var(--text-muted)":"var(--text-dim)",cursor:c.id.trim()&&"testing"!==h.phase?"pointer":"not-allowed",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",gap:5},children:["success"===h.phase&&(0,d.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("polyline",{points:"20 6 9 17 4 12"})}),"testing"===h.phase?"Testing…":"success"===h.phase?"OK":"Test"]}),(0,d.jsx)("button",{onClick:g,style:{height:24,padding:"0 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,boxSizing:"border-box"},children:"Remove"})]})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,d.jsx)(cK,{label:"ID *",children:(0,d.jsx)(cM,{value:c.id,onChange:a=>k({...c,id:a}),placeholder:"model-id",mono:!0})}),(0,d.jsx)(cK,{label:"Name",children:(0,d.jsx)(cM,{value:c.name??"",onChange:a=>k({...c,name:a||void 0}),placeholder:"Display name"})})]}),(0,d.jsx)(cK,{label:"API override",children:(0,d.jsx)(cP,{value:c.api??"",onChange:a=>j("api",a||void 0),options:cC})}),(0,d.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,d.jsx)(cQ,{label:"Reasoning / thinking",checked:c.reasoning??!1,onChange:a=>j("reasoning",a||void 0)}),(0,d.jsx)(cQ,{label:"Image input",checked:c.input?.includes("image")??!1,onChange:a=>j("input",a?["text","image"]:["text"])})]}),c.reasoning&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(cQ,{label:"DeepSeek thinking compat",checked:c.compat?.thinkingFormat==="deepseek",onChange:a=>f(function(a,b){if(b)return{...a,compat:{...a.compat??{},...cW}};if(!a.compat)return a;let c={...a.compat};return delete c.thinkingFormat,delete c.requiresReasoningContentOnAssistantMessages,{...a,compat:Object.keys(c).length?c:void 0}}(c,a))}),(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[(0,d.jsx)(cR,{children:"Thinking level map"}),c.thinkingLevelMap&&(0,d.jsx)("button",{onClick:()=>j("thinkingLevelMap",void 0),style:{fontSize:10,padding:"2px 7px",background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-dim)",cursor:"pointer"},children:"clear all"})]}),(0,d.jsx)(cV,{value:c.thinkingLevelMap,onChange:a=>j("thinkingLevelMap",a)})]})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,d.jsx)(cK,{label:"Context window (tokens)",children:(0,d.jsx)(cO,{value:void 0!==c.contextWindow?String(c.contextWindow):"",onChange:a=>j("contextWindow",a?parseInt(a):void 0),placeholder:"128000"})}),(0,d.jsx)(cK,{label:"Max output tokens",children:(0,d.jsx)(cO,{value:void 0!==c.maxTokens?String(c.maxTokens):"",onChange:a=>j("maxTokens",a?parseInt(a):void 0),placeholder:"16384"})})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(cR,{children:"Cost (per million tokens)"}),(0,d.jsx)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:8},children:["input","output","cacheRead","cacheWrite"].map(a=>(0,d.jsx)(cK,{label:a,children:(0,d.jsx)(cO,{value:c.cost?.[a]!==void 0?String(c.cost[a]):"",onChange:b=>{let d;return d=parseFloat(b),void f({...c,cost:{...c.cost??{},[a]:isNaN(d)?void 0:d}})},placeholder:"0"})},a))})]})]})}function cY({provider:a,onRefresh:b}){let[c,f]=(0,e.useState)({phase:"idle"}),[g,h]=(0,e.useState)(""),i=(0,e.useRef)(null),j=(0,e.useRef)(null),k=(0,e.useCallback)(()=>{i.current?.close(),f({phase:"connecting"}),h("");let c=new EventSource(`/api/auth/login/${encodeURIComponent(a.id)}`);i.current=c,c.onmessage=a=>{let d=JSON.parse(a.data);"auth"===d.type?(f({phase:"auth",url:d.url,instructions:d.instructions??null,token:d.token}),window.open(d.url,"_blank","noopener,noreferrer")):"device_code"===d.type?(f({phase:"device_code",userCode:d.userCode,verificationUri:d.verificationUri,intervalSeconds:d.intervalSeconds??null,expiresInSeconds:d.expiresInSeconds??null}),window.open(d.verificationUri,"_blank","noopener,noreferrer")):"prompt_request"===d.type?f({phase:"prompt",message:d.message,placeholder:d.placeholder??null,token:d.token}):"select_request"===d.type?f({phase:"select",message:d.message,options:d.options??[],token:d.token}):"progress"===d.type?f({phase:"progress",message:d.message}):"success"===d.type?(c.close(),f({phase:"success"}),b()):"error"===d.type?(c.close(),f({phase:"error",message:d.message})):"cancelled"===d.type&&(c.close(),f({phase:"idle"}))},c.onerror=()=>{c.close(),f(a=>"success"===a.phase?a:{phase:"error",message:"Connection lost"})}},[a.id,b]),l=(0,e.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(a.id)}`,{method:"POST"}),f({phase:"idle"}),b()},[a.id,b]),m=(0,e.useCallback)(async(b,c)=>{if(c.trim()){f({phase:"progress",message:"Verifying…"});try{let d=await fetch(`/api/auth/login/${encodeURIComponent(a.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:b,code:c.trim()})});if(!d.ok){let a=await d.json().catch(()=>({}));f({phase:"error",message:a.error??`Server error ${d.status}`});return}h("")}catch(a){f({phase:"error",message:a instanceof Error?a.message:"Network error"})}}},[a.id]),n=(0,e.useCallback)(async(b,c)=>{f({phase:"progress",message:"Continuing…"});try{let d=await fetch(`/api/auth/login/${encodeURIComponent(a.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:b,code:c})});if(!d.ok){let a=await d.json().catch(()=>({}));f({phase:"error",message:a.error??`Server error ${d.status}`})}}catch(a){f({phase:"error",message:a instanceof Error?a.message:"Network error"})}},[a.id]),o="connecting"===c.phase||"progress"===c.phase||"auth"===c.phase||"device_code"===c.phase||"prompt"===c.phase||"select"===c.phase;return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,d.jsx)(cR,{children:"Subscription"}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,d.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:a.loggedIn?"#4ade80":"var(--border)",display:"inline-block"}}),(0,d.jsx)("span",{style:{fontSize:11,color:a.loggedIn?"#4ade80":"var(--text-dim)"},children:a.loggedIn?"connected":"not connected"})]})]}),(0,d.jsxs)("div",{style:{minHeight:48},children:["idle"===c.phase&&(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:a.loggedIn?"Already connected. You can re-login or disconnect.":`Connect your ${a.name} account.`}),"connecting"===c.phase&&(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:"Opening browser…"}),"select"===c.phase&&(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:c.message}),(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:c.options.map(a=>(0,d.jsx)("button",{onClick:()=>n(c.token,a.id),style:{padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left"},children:a.label},a.id))})]}),("auth"===c.phase||"prompt"===c.phase)&&(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"auth"===c.phase?"Complete sign-in in the browser, then copy the redirect URL from the address bar and paste it below.":c.message}),"auth"===c.phase&&(0,d.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:["If the browser window did not open,"," ",(0,d.jsx)("a",{href:c.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:"click here to open the login page"}),"."]}),(0,d.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,d.jsx)("input",{ref:j,value:g,onChange:a=>h(a.target.value),onKeyDown:a=>{"Enter"===a.key&&m(c.token,g)},placeholder:"auth"===c.phase?"http://localhost:1455/auth/callback?code=…":c.placeholder??"Enter value…",style:{flex:1,padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)",boxSizing:"border-box"}}),(0,d.jsx)("button",{onClick:()=>m(c.token,g),disabled:!g.trim(),style:{padding:"6px 12px",background:g.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:g.trim()?"#fff":"var(--text-dim)",cursor:g.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:"Submit"})]})]}),"device_code"===c.phase&&(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Open the verification page and enter this code:"}),(0,d.jsx)("div",{style:{padding:"8px 10px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:16,fontWeight:700,fontFamily:"var(--font-mono)",letterSpacing:0},children:c.userCode}),(0,d.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,d.jsx)("a",{href:c.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:c.verificationUri}),c.expiresInSeconds?` Expires in ${Math.ceil(c.expiresInSeconds/60)} minutes.`:""]})]}),"progress"===c.phase&&(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:c.message}),"success"===c.phase&&(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:"Connected successfully."}),"error"===c.phase&&(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:c.message})]}),(0,d.jsx)("div",{style:{display:"flex",gap:8},children:o?(0,d.jsx)("button",{onClick:()=>{i.current?.close(),f({phase:"idle"})},style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("button",{onClick:k,style:{padding:"5px 14px",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:a.loggedIn?"Re-login":"Login"}),a.loggedIn&&(0,d.jsx)("button",{onClick:l,style:{padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12},children:"Disconnect"})]})})]})}function cZ({provider:a,onRefresh:b}){let[c,f]=(0,e.useState)(""),[g,h]=(0,e.useState)(!1),[i,j]=(0,e.useState)(!1),[k,l]=(0,e.useState)(null),[m,n]=(0,e.useState)(!1),o=(0,e.useCallback)(async()=>{if(c.trim()){h(!0),l(null),n(!1);try{let d=await fetch(`/api/auth/api-key/${encodeURIComponent(a.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:c.trim()})}),e=await d.json();!d.ok||e.error?l(e.error??`HTTP ${d.status}`):(f(""),n(!0),setTimeout(()=>n(!1),2e3),b())}catch(a){l(String(a))}finally{h(!1)}}},[c,a.id,b]),p=(0,e.useCallback)(async()=>{j(!0),l(null);try{let c=await fetch(`/api/auth/api-key/${encodeURIComponent(a.id)}`,{method:"DELETE"}),d=await c.json();!c.ok||d.error?l(d.error??`HTTP ${c.status}`):b()}catch(a){l(String(a))}finally{j(!1)}},[a.id,b]);return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,d.jsx)(cR,{children:"API Key"}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,d.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:a.configured?"#4ade80":"var(--border)",display:"inline-block"}}),(0,d.jsx)("span",{style:{fontSize:11,color:a.configured?"#4ade80":"var(--text-dim)"},children:a.configured?"configured":"not configured"})]})]}),(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:a.configured?"API key is stored. Enter a new key below to replace it, or disconnect to remove it.":`Enter your ${a.displayName} API key to enable ${a.modelCount} model${1!==a.modelCount?"s":""}.`}),(0,d.jsx)(cK,{label:"API Key",children:(0,d.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,d.jsx)(cN,{value:c,onChange:f,onKeyDown:a=>{"Enter"===a.key&&c.trim()&&o()},placeholder:a.configured?"Enter new key to replace…":"sk-…",style:{flex:1},autoComplete:"off",spellCheck:!1,mono:!0}),(0,d.jsxs)("button",{onClick:o,disabled:g||!c.trim()||m,style:{padding:"6px 12px",background:m?"#16a34a":c.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:c.trim()||m?"#fff":"var(--text-dim)",cursor:g||!c.trim()||m?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[m&&(0,d.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("polyline",{points:"20 6 9 17 4 12"})}),m?"Saved":g?"Saving…":"Save"]})]})}),k&&(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:k}),a.configured&&(0,d.jsx)("button",{onClick:p,disabled:i,style:{alignSelf:"flex-start",padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:i?"not-allowed":"pointer",fontSize:12},children:i?"Removing…":"Disconnect"})]})}function c$({id:a,size:b}){let c=cB[a];return c?c.hasColor?(0,d.jsx)(c.Icon,{size:b}):(0,d.jsx)(c.Icon,{size:b,style:{color:"var(--text-muted)"}}):null}function c_({oauthProviders:a,apiKeyProviders:b,onSelectOAuth:c,onSelectApiKey:f,onAddCustom:g,onDiscover:h,onClose:i}){let[j,k]=(0,e.useState)(""),l=(0,e.useRef)(null),m=j.trim().toLowerCase(),n=a.filter(a=>!a.loggedIn&&(!m||a.name.toLowerCase().includes(m))),o=b.filter(a=>!a.configured&&(!m||a.displayName.toLowerCase().includes(m)||a.id.toLowerCase().includes(m))),p=!m||"custom".includes(m)||"openai-compatible".includes(m)||"anthropic-compatible".includes(m),q=!m||"discover".includes(m)||"base url".includes(m)||"model import".includes(m),r=n.length+o.length+ +!!p+ +!!q,s={display:"flex",flexDirection:"row",alignItems:"center",gap:8,padding:"10px 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,boxSizing:"border-box",cursor:"pointer",minWidth:0,textAlign:"left",transition:"border-color 0.12s, background 0.12s",width:"100%"};return(0,d.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1100,background:"rgba(0,0,0,0.4)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:a=>{a.target===a.currentTarget&&i()},children:(0,d.jsxs)("div",{style:{width:820,maxWidth:"calc(100vw - 32px)",maxHeight:"min(72vh, calc(100vh - 32px))",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.22)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:"10px 14px",borderBottom:"1px solid var(--border)",flexShrink:0,display:"flex",alignItems:"center",gap:8},children:[(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,d.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,d.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,d.jsx)("input",{ref:l,value:j,onChange:a=>k(a.target.value),onKeyDown:a=>{"Escape"===a.key&&i()},placeholder:"Search providers…",style:{flex:1,background:"none",border:"none",outline:"none",color:"var(--text)",fontSize:13,boxSizing:"border-box"}})]}),(0,d.jsx)("div",{style:{flex:1,overflowY:"auto",padding:14},children:0===r?(0,d.jsx)("div",{style:{padding:"20px 0",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:"No providers match"}):(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(240px, 100%), 1fr))",gap:8},children:[p&&(0,d.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Custom"}),p&&(0,d.jsxs)("button",{onClick:()=>{g(),i()},style:s,onMouseEnter:a=>{a.currentTarget.style.borderColor="var(--accent)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.borderColor="var(--border)",a.currentTarget.style.background="var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"OpenAI / Anthropic compatible"}),(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"Custom endpoint format"})]}),(0,d.jsx)("span",{style:{width:26,height:26,borderRadius:5,background:"var(--bg-hover)",border:"1px dashed var(--border)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)"},children:[(0,d.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,d.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),q&&(0,d.jsxs)("button",{onClick:()=>{h(),i()},style:s,onMouseEnter:a=>{a.currentTarget.style.borderColor="var(--accent)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.borderColor="var(--border)",a.currentTarget.style.background="var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"Discover models from Base URL"}),(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OpenAI-compatible / Ollama catalog"})]}),(0,d.jsx)("span",{style:{width:26,height:26,borderRadius:5,background:"var(--bg-hover)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-muted)"},children:[(0,d.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,d.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})})]}),n.length>0&&(0,d.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!p,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Subscriptions"}),n.map(a=>(0,d.jsxs)("button",{onClick:()=>{c(a.id),i()},style:s,onMouseEnter:a=>{a.currentTarget.style.borderColor="var(--accent)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.borderColor="var(--border)",a.currentTarget.style.background="var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name}),(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OAuth"})]}),(0,d.jsx)(c$,{id:a.id,size:28})]},a.id)),o.length>0&&(0,d.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(n.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"API Key"}),o.map(a=>(0,d.jsxs)("button",{onClick:()=>{f(a.id),i()},style:s,onMouseEnter:a=>{a.currentTarget.style.borderColor="var(--accent)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.borderColor="var(--border)",a.currentTarget.style.background="var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.displayName}),(0,d.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:[a.modelCount," models"]})]}),(0,d.jsx)(c$,{id:a.id,size:28})]},a.id))]})})]})})}function c0({existingProviders:a,onImport:b,onClose:c}){let[f,g]=(0,e.useState)(""),[h,i]=(0,e.useState)(""),[j,k]=(0,e.useState)("custom-provider"),[l,m]=(0,e.useState)(new Set),[n,o]=(0,e.useState)({phase:"idle"}),p=(0,e.useCallback)(async()=>{let a=f.trim();if(a&&"loading"!==n.phase){o({phase:"loading"});try{let b=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:a,apiKey:h,provider:j,enrich:!1})}),c=await b.json();if(!b.ok||!c.ok||!c.models||!c.piModels||!c.endpoint)return void o({phase:"error",message:c.error??`HTTP ${b.status}`});o({phase:"success",endpoint:c.endpoint,models:c.models,piModels:c.piModels}),m(new Set(c.piModels.map(a=>a.id)))}catch(a){o({phase:"error",message:a instanceof Error?a.message:String(a)})}}},[h,f,j,n.phase]),q="success"===n.phase?n:null,r=l.size,s=!!(q&&j.trim()&&r>0);return(0,d.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1100,background:"rgba(0,0,0,0.4)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:a=>{a.target===a.currentTarget&&c()},children:(0,d.jsxs)("div",{style:{width:880,maxWidth:"calc(100vw - 32px)",height:"min(78vh, calc(100vh - 32px))",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.22)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:"Discover models"}),(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:2},children:"Fetch model catalog from a Base URL and import selected models."})]}),(0,d.jsx)("button",{onClick:c,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,d.jsxs)("div",{style:{padding:16,borderBottom:"1px solid var(--border)",display:"grid",gridTemplateColumns:"1.4fr 1fr 0.9fr auto",gap:10,alignItems:"end",flexShrink:0},children:[(0,d.jsx)(cK,{label:"Base URL",children:(0,d.jsx)(cM,{value:f,onChange:g,placeholder:"https://api.example.com",mono:!0})}),(0,d.jsx)(cK,{label:"API Key",children:(0,d.jsx)(cN,{value:h,onChange:i,placeholder:"optional for local providers",mono:!0})}),(0,d.jsx)(cK,{label:"Provider name",children:(0,d.jsx)(cM,{value:j,onChange:k,placeholder:"provider-name",mono:!0})}),(0,d.jsx)("button",{onClick:p,disabled:!f.trim()||"loading"===n.phase,style:{height:31,padding:"0 14px",background:f.trim()&&"loading"!==n.phase?"var(--accent)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:f.trim()&&"loading"!==n.phase?"#fff":"var(--text-dim)",cursor:f.trim()&&"loading"!==n.phase?"pointer":"not-allowed",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:"loading"===n.phase?"Fetching...":"Fetch models"})]}),(0,d.jsxs)("div",{style:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column"},children:["idle"===n.phase&&(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Enter a Base URL to discover available models."}),"loading"===n.phase&&(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Fetching model catalog..."}),"error"===n.phase&&(0,d.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12,lineHeight:1.6},children:n.message}),q&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 16px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,d.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[q.piModels.length," models from ",q.endpoint]}),(0,d.jsx)("button",{onClick:()=>{if(q){if(l.size===q.piModels.length)return void m(new Set);m(new Set(q.piModels.map(a=>a.id)))}},style:{padding:"2px 8px",fontSize:11,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer"},children:l.size===q.piModels.length?"Clear":"Select all"})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"auto"},children:q.piModels.map((a,b)=>{let c=q.models[b],e=l.has(a.id);return(0,d.jsxs)("label",{style:{display:"grid",gridTemplateColumns:"24px minmax(0, 1fr) 90px 90px 90px 70px",gap:10,alignItems:"center",padding:"8px 16px",borderBottom:"1px solid rgba(127,127,127,0.12)",background:e?"var(--bg-subtle)":"transparent",cursor:"pointer"},children:[(0,d.jsx)("input",{type:"checkbox",checked:e,onChange:()=>{var b;return b=a.id,void m(a=>{let c=new Set(a);return c.has(b)?c.delete(b):c.add(b),c})},style:{width:14,height:14,accentColor:"var(--accent)"}}),(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.id}),(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c?.ownedBy??"unknown"})]}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:a.contextWindow}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:a.maxTokens}),(0,d.jsx)("span",{style:{fontSize:10,color:a.reasoning?"var(--accent)":"var(--text-dim)"},children:a.reasoning?"reasoning":""}),(0,d.jsx)("span",{style:{fontSize:10,color:a.input?.includes("image")?"var(--accent)":"var(--text-dim)"},children:a.input?.includes("image")?"image":""})]},a.id)})})]})]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10,padding:"10px 16px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,d.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:[r," selected"]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,d.jsx)("button",{onClick:c,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Cancel"}),(0,d.jsx)("button",{onClick:()=>{if(!q||!s)return;let d=f.trim().replace(/\/+$/,""),e=h.trim(),g=Object.entries(a).find(([,a])=>(a.baseUrl??"").replace(/\/+$/,"")===d&&(a.apiKey??"")===e),i=g?.[0]??j.trim(),k=a[i],m=new Map((k?.models??[]).map(a=>[a.id,a])),n=k?.api??cD,o=0;for(let a of q.piModels)l.has(a.id)&&!m.has(a.id)&&(m.set(a.id,cJ(a,n)),o+=1);b(i,{...k??{},baseUrl:d,api:n,...e?{apiKey:e}:{},models:Array.from(m.values())},o),c()},disabled:!s,style:{padding:"6px 16px",background:s?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:6,color:s?"#fff":"var(--text-dim)",cursor:s?"pointer":"not-allowed",fontSize:13,fontWeight:600},children:"Import selected"})]})]})]})})}function c1({onClose:a,embedded:b=!1}){let[c,f]=(0,e.useState)({providers:{}}),[g,h]=(0,e.useState)(!0),[i,j]=(0,e.useState)(!1),[k,l]=(0,e.useState)(null),[m,n]=(0,e.useState)(null),[o,p]=(0,e.useState)(!1),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)([]),[u,v]=(0,e.useState)([]),[w,x]=(0,e.useState)(!1),[y,z]=(0,e.useState)(!1),A=(0,e.useCallback)(()=>{fetch("/api/auth/providers").then(a=>a.json()).then(a=>t(a.providers)).catch(()=>{})},[]),B=(0,e.useCallback)(()=>{fetch("/api/auth/all-providers").then(a=>a.json()).then(a=>v(a.providers)).catch(()=>{})},[]),C=(0,e.useCallback)(()=>{let a="new-provider",b=1;for(;c.providers?.[a];)a=`new-provider-${b++}`;f(b=>({...b,providers:{...b.providers??{},[a]:{api:"openai-completions"}}})),r({type:"provider",name:a})},[c.providers]),D=(0,e.useCallback)((a,b)=>{f(c=>({...c,providers:{...c.providers??{},[a]:b}}))},[]),E=(0,e.useCallback)((a,b)=>{f(c=>{let d=Object.entries(c.providers??{}),e=d.findIndex(([b])=>b===a);return -1===e?c:(d[e]=[b,d[e][1]],{...c,providers:Object.fromEntries(d)})}),r(c=>c?"provider"===c.type&&c.name===a?{type:"provider",name:b}:"model"===c.type&&c.providerName===a?{...c,providerName:b}:c:c)},[]),F=(0,e.useCallback)(a=>{f(b=>{let c={...b.providers??{}};return delete c[a],{...b,providers:c}}),f(a=>{let b=Object.keys(a.providers??{});return r(b.length>0?{type:"provider",name:b[0]}:null),a})},[]),G=(0,e.useCallback)(a=>{f(b=>{let c=b.providers?.[a]??{},d=[...c.models??[],{id:""}];return{...b,providers:{...b.providers??{},[a]:{...c,models:d}}}}),f(b=>{let c=(b.providers?.[a]?.models?.length??1)-1;return r({type:"model",providerName:a,index:c}),b})},[]),H=(0,e.useCallback)((a,b,c)=>{f(d=>{let e=d.providers?.[a]??{},f=[...e.models??[]];return f[b]=c,{...d,providers:{...d.providers??{},[a]:{...e,models:f}}}})},[]),I=(0,e.useCallback)((a,b)=>{f(c=>{let d=c.providers?.[a]??{},e=[...d.models??[]];return e.splice(b,1),{...c,providers:{...c.providers??{},[a]:{...d,models:e.length?e:void 0}}}}),r({type:"provider",name:a})},[]),J=(0,e.useCallback)((a,b,c)=>{f(c=>({...c,providers:{...c.providers??{},[a]:b}})),r({type:"provider",name:a}),p(!1),l(null),n(`${c} model${1===c?"":"s"} imported. Click Save to write models.json.`)},[]),K=(0,e.useCallback)(async()=>{j(!0),l(null),n(null),p(!1);try{let a=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)}),b=await a.json();!a.ok||b.error?l(b.error??`HTTP ${a.status}`):(p(!0),setTimeout(()=>p(!1),2e3))}catch(a){l(String(a))}finally{j(!1)}},[c]),L=Object.entries(c.providers??{}),M=s.filter(a=>a.loggedIn),N=u.filter(a=>a.configured),O=(()=>{if(!q)return null;if("oauth"===q.type){let a=s.find(a=>a.id===q.providerId);return a?(0,d.jsx)(cY,{provider:a,onRefresh:A},a.id):null}if("apikey"===q.type){let a=u.find(a=>a.id===q.providerId);return a?(0,d.jsx)(cZ,{provider:a,onRefresh:B},a.id):null}if("provider"===q.type){let a=c.providers?.[q.name];return a?(0,d.jsx)(cS,{name:q.name,provider:a,onChange:a=>D(q.name,a),onRename:a=>E(q.name,a),onDelete:()=>F(q.name)},q.name):null}let a=c.providers?.[q.providerName],b=a?.models?.[q.index];return b?(0,d.jsx)(cX,{providerName:q.providerName,provider:a,model:b,onChange:a=>H(q.providerName,q.index,a),onDelete:()=>I(q.providerName,q.index)},`${q.providerName}-${q.index}`):null})();return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{style:b?{height:"100%",minHeight:0,display:"flex",alignItems:"stretch",justifyContent:"stretch"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:c=>{b||c.target!==c.currentTarget||a()},children:(0,d.jsxs)("div",{style:{width:b?"100%":860,height:b?"100%":"78vh",background:"var(--bg)",border:b?"none":"1px solid var(--border)",borderRadius:10*!b,display:"flex",flexDirection:"column",boxShadow:b?"none":"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!b&&(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,d.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Models"}),(0,d.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:"~/.pi/agent/models.json"})]}),(0,d.jsx)("button",{onClick:a,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,d.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{width:210,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:[M.map(a=>{let b=q?.type==="oauth"&&q.providerId===a.id;return(0,d.jsxs)("div",{onClick:()=>r({type:"oauth",providerId:a.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:b?"var(--bg-selected)":"none"},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="none")},children:[(0,d.jsx)(c$,{id:a.id,size:16}),(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name})]},a.id)}),N.map(a=>{let b=q?.type==="apikey"&&q.providerId===a.id;return(0,d.jsxs)("div",{onClick:()=>r({type:"apikey",providerId:a.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:b?"var(--bg-selected)":"none"},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="none")},children:[(0,d.jsx)(c$,{id:a.id,size:16}),(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.displayName})]},a.id)}),(M.length>0||N.length>0)&&L.length>0&&(0,d.jsx)("div",{style:{margin:"4px 8px",borderTop:"1px solid var(--border)"}}),g?(0,d.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):L.map(([a,b])=>{let c=q?.type==="provider"&&q.name===a,e=b.models??[];return(0,d.jsxs)("div",{style:{marginBottom:2},children:[(0,d.jsxs)("div",{onClick:()=>r({type:"provider",name:a}),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:c?"var(--bg-selected)":"none"},onMouseEnter:a=>{c||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{c||(a.currentTarget.style.background="none")},children:[(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,d.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,d.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,d.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,d.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,d.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,d.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,d.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,d.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,d.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,d.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,d.jsx)("span",{style:{fontSize:12,fontWeight:c?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a})]}),e.map((b,c)=>{let e=q?.type==="model"&&q.providerName===a&&q.index===c;return(0,d.jsxs)("div",{onClick:()=>r({type:"model",providerName:a,index:c}),style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px 5px 26px",borderRadius:5,cursor:"pointer",background:e?"var(--bg-selected)":"none"},onMouseEnter:a=>{e||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{e||(a.currentTarget.style.background="none")},children:[(0,d.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:b.id?"var(--text-muted)":"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b.id||"new model"}),b.reasoning&&(0,d.jsx)("span",{style:{fontSize:9,padding:"1px 4px",background:"rgba(99,102,241,0.12)",color:"rgba(99,102,241,0.8)",borderRadius:3,flexShrink:0},children:"T"})]},c)}),(0,d.jsx)("div",{onClick:b=>{b.stopPropagation(),G(a)},style:{display:"flex",alignItems:"center",gap:4,padding:"4px 8px 4px 26px",borderRadius:5,cursor:"pointer",color:"var(--text-dim)"},onMouseEnter:a=>{a.currentTarget.style.color="var(--accent)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color="var(--text-dim)",a.currentTarget.style.background="none"},children:(0,d.jsx)("span",{style:{fontSize:11},children:"+ model"})})]},a)})]}),(0,d.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,d.jsx)("button",{onClick:()=>x(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,width:"100%",padding:"6px 0",background:"none",border:"1px dashed var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},onMouseEnter:a=>{a.currentTarget.style.borderColor="var(--accent)",a.currentTarget.style.color="var(--accent)"},onMouseLeave:a=>{a.currentTarget.style.borderColor="var(--border)",a.currentTarget.style.color="var(--text-muted)"},children:"+ Add provider"})})]}),(0,d.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:g?null:O??(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a provider or model"})})]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:10,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[k?(0,d.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:k}):m?(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",flex:1},children:m}):null,(0,d.jsx)("button",{onClick:a,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Cancel"}),(0,d.jsxs)("button",{onClick:K,disabled:i||o,style:{position:"relative",padding:"6px 16px",minWidth:92,background:o?"#16a34a":i?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:o?"#fff":i?"var(--text-muted)":"#fff",cursor:i||o?"default":"pointer",fontSize:13,fontWeight:600,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,transition:"background-color 0.2s ease, color 0.2s ease",animation:o?"saved-pop 0.45s ease":void 0},children:[o&&(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:18,animation:"saved-check-draw 0.35s ease forwards",flexShrink:0},children:(0,d.jsx)("polyline",{points:"20 6 9 17 4 12"})}),(0,d.jsx)("span",{children:o?"Saved":i?"Saving…":"Save"})]})]})]})}),w&&(0,d.jsx)(c_,{oauthProviders:s,apiKeyProviders:u,onSelectOAuth:a=>r({type:"oauth",providerId:a}),onSelectApiKey:a=>r({type:"apikey",providerId:a}),onAddCustom:C,onDiscover:()=>z(!0),onClose:()=>x(!1)}),y&&(0,d.jsx)(c0,{existingProviders:c.providers??{},onImport:J,onClose:()=>z(!1)})]})}function c2(a){return a.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function c3(a){let b=a.sourceInfo?.source,c=a.sourceInfo?.scope;return"user"===c||"user"===b?"global":"project"===c||"project"===b?"project":"path"}function c4({enabled:a,loading:b,onToggle:c}){return(0,d.jsx)("button",{onClick:c,disabled:b,title:a?"Visible in model prompt — click to disable":"Hidden from model prompt — click to enable",style:{flexShrink:0,width:40,height:22,borderRadius:11,border:"none",padding:0,cursor:b?"wait":"pointer",background:a?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",outline:"none"},children:(0,d.jsx)("span",{style:{position:"absolute",top:3,left:a?21:3,width:16,height:16,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function c5({skill:a,cwd:b,onToggle:c,toggling:e,saveError:f}){let g=c3(a),h=!a.disableModelInvocation;return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7},children:[(0,d.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===g?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===g?"rgba(99,102,241,0.8)":"var(--text-dim)"},children:g}),(0,d.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(a){if("project"===g&&a.startsWith(b)){let c=a.slice(b.length).replace(/^[/\\]/,"");return`./${c}`}return c2(a)}(a.filePath)}),(0,d.jsx)(c4,{enabled:h,loading:e,onToggle:()=>c(a)}),f&&(0,d.jsx)("span",{style:{fontSize:12,color:"#f87171",flexShrink:0},children:f})]}),(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Name"}),(0,d.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:14,color:"var(--text)"},children:a.name})]}),(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Description"}),(0,d.jsx)("span",{style:{fontSize:14,color:"var(--text-muted)",lineHeight:1.6},children:a.description})]})]})}function c6({cwd:a,onInstalled:b}){let[c,f]=(0,e.useState)(""),[g,h]=(0,e.useState)([]),[i,j]=(0,e.useState)(!1),[k,l]=(0,e.useState)(null),[m,n]=(0,e.useState)(null),[o,p]=(0,e.useState)(null),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)([]),[u,v]=(0,e.useState)(new Set),[w,x]=(0,e.useState)("global"),y=(0,e.useRef)(null),z=(0,e.useRef)(null),A=(0,e.useCallback)(async a=>{if(a.trim()){j(!0),l(null),h([]);try{let b=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:a.trim()})}),c=await b.json();if(c.error)return void l(c.error);h(c.results??[]),0===(c.results??[]).length&&l("No skills found")}catch(a){l(String(a))}finally{j(!1)}}},[]),B=(0,e.useCallback)(async c=>{let d=new AbortController;z.current=d,n(c),p(null),r("Starting installer"),t(["Starting installer"]);try{let e=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:c,scope:w,cwd:a,stream:!0}),signal:d.signal});if(!e.ok||!e.body){let a=await e.json().catch(()=>null);p(a?.error??`HTTP ${e.status}`);return}let f=e.body.getReader(),g=new TextDecoder,h="",i=!1,j=a=>{"progress"===a.type?(a.stage&&r(a.stage),a.line&&t(b=>(b.at(-1)===a.line?b:[...b,a.line]).slice(-8))):"done"===a.type&&a.success?(i=!0,r("Installed"),t(a=>[...a,"Installed"].slice(-8))):"error"===a.type&&p(a.error??"Install failed")};for(;;){let{value:a,done:b}=await f.read(),c=(h+=g.decode(a??new Uint8Array,{stream:!b})).split("\n");for(let a of(h=c.pop()??"",c))a.trim()&&j(JSON.parse(a));if(b)break}h.trim()&&j(JSON.parse(h)),i&&(v(a=>new Set(a).add(c)),b())}catch(a){d.signal.aborted?(r("Canceled"),t(a=>[...a,"Canceled"].slice(-8))):p(String(a))}finally{z.current===d&&(z.current=null),n(null)}},[b,w,a]),C=(0,e.useCallback)(()=>{z.current?.abort()},[]),D="global"===w?"~/.pi/agent/skills/":`${c2(a)}/.pi/agent/skills/`;return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:20},children:[(0,d.jsx)("div",{style:{fontSize:14,fontWeight:600,color:"var(--text)"},children:"Add Skill"}),(0,d.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,d.jsx)("input",{ref:y,value:c,onChange:a=>f(a.target.value),onKeyDown:a=>{"Enter"===a.key&&A(c)},placeholder:"e.g. react, testing, deploy",style:{flex:1,padding:"7px 10px",fontSize:13,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,d.jsx)("button",{onClick:()=>A(c),disabled:i||!c.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:i||!c.trim()?"not-allowed":"pointer",opacity:i||!c.trim()?.5:1,flexShrink:0},children:i?"Searching…":"Search"})]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,d.jsx)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",fontSize:12,flexShrink:0},children:["global","project"].map(a=>(0,d.jsx)("button",{onClick:()=>x(a),style:{padding:"3px 10px",border:"none",cursor:"pointer",background:w===a?"var(--bg-selected)":"none",color:w===a?"var(--text)":"var(--text-dim)",fontWeight:w===a?600:400,borderRight:"global"===a?"1px solid var(--border)":"none"},children:a},a))}),(0,d.jsxs)("span",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["→ ",D]})]}),k&&(0,d.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:k}),o&&(0,d.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:o}),m&&(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:10,display:"flex",flexDirection:"column",gap:8},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,d.jsx)("div",{style:{width:10,height:10,borderRadius:"50%",border:"2px solid var(--border)",borderTopColor:"var(--accent)",animation:"spin 0.8s linear infinite",flexShrink:0}}),(0,d.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:q??"Installing"}),(0,d.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m})]}),(0,d.jsx)("button",{onClick:C,style:{padding:"4px 9px",fontSize:12,borderRadius:5,border:"1px solid var(--border)",background:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0},children:"Cancel"})]}),s.length>0&&(0,d.jsx)("div",{style:{maxHeight:120,overflow:"auto",fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.6,color:"var(--text-dim)",borderTop:"1px solid var(--border)",paddingTop:8},children:s.map((a,b)=>(0,d.jsx)("div",{children:a},`${b}-${a}`))})]})]}),g.length>0?(0,d.jsx)("div",{style:{flex:1,overflowY:"auto"},children:g.map(a=>{let b=u.has(a.package),c=m===a.package,e=a.package.indexOf("@"),f=e>-1?a.package.slice(0,e):a.package,g=e>-1?a.package.slice(e+1):null;return(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"12px 0",borderBottom:"1px solid var(--border)"},children:[(0,d.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:3},children:g??f}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,d.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:f}),(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:a.installs}),a.url&&(0,d.jsx)("a",{href:a.url,target:"_blank",rel:"noreferrer",style:{fontSize:12,color:"var(--accent)",textDecoration:"none"},children:"skills.sh ↗"})]})]}),(0,d.jsx)("button",{onClick:()=>{b||null!==m||B(a.package)},disabled:b||null!==m,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:c?"wait":b||null!==m?"not-allowed":"pointer",background:b?"rgba(34,197,94,0.1)":c?"rgba(59,130,246,0.08)":"none",color:b?"#16a34a":c?"var(--accent)":"var(--text-muted)",transition:"color 0.12s"},children:b?"✓ Installed":c?"Installing":"Install"})]},a.package)})}):!k&&!i&&(0,d.jsxs)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:["Search"," ",(0,d.jsx)("a",{href:"https://skills.sh",target:"_blank",rel:"noreferrer",style:{color:"var(--accent)",textDecoration:"none"},children:"skills.sh"})," ","to discover and install skills for your agent."]})]})}function c7({cwd:a,onClose:b,embedded:c=!1}){let[f,g]=(0,e.useState)([]),[h,i]=(0,e.useState)(!0),[j,k]=(0,e.useState)(null),[l,m]=(0,e.useState)(null),[n,o]=(0,e.useState)(new Set),[p,q]=(0,e.useState)(null),[r,s]=(0,e.useState)(!1),t=(0,e.useCallback)(()=>{i(!0),k(null),fetch(`/api/skills?cwd=${encodeURIComponent(a)}`).then(a=>a.json()).then(a=>{if(a.error)return void k(a.error);let b=a.skills??[];g(b),b.length>0&&!l&&m(b[0].filePath)}).catch(a=>k(String(a))).finally(()=>i(!1))},[a,l]),u=(0,e.useCallback)(async a=>{let b=!a.disableModelInvocation;o(b=>new Set(b).add(a.filePath)),q(null);try{let c=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:a.filePath,disableModelInvocation:b})}),d=await c.json();if(!c.ok||d.error)return void q(d.error??`HTTP ${c.status}`);g(c=>c.map(c=>c.filePath===a.filePath?{...c,disableModelInvocation:b}:c))}catch(a){q(String(a))}finally{o(b=>{let c=new Set(b);return c.delete(a.filePath),c})}},[]),v=f.find(a=>a.filePath===l)??null;return(0,d.jsx)("div",{style:c?{height:"100%",minHeight:0,display:"flex",alignItems:"stretch",justifyContent:"stretch"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:a=>{c||a.target!==a.currentTarget||b()},children:(0,d.jsxs)("div",{style:{width:c?"100%":860,height:c?"100%":"78vh",background:"var(--bg)",border:c?"none":"1px solid var(--border)",borderRadius:10*!c,display:"flex",flexDirection:"column",boxShadow:c?"none":"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!c&&(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,d.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Skills"}),(0,d.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c2(a)})]}),(0,d.jsx)("button",{onClick:b,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,d.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{width:210,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,d.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:h?(0,d.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):j?(0,d.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:j}):0===f.length?(0,d.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No skills found"}):(()=>{let a=[];for(let b of["project","global","path"]){let c=f.filter(a=>c3(a)===b);c.length>0&&a.push({label:b,skills:c})}return a.map(({label:a,skills:b})=>(0,d.jsxs)("div",{style:{marginBottom:6},children:[(0,d.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em"},children:a}),b.map(a=>{let b=!r&&l===a.filePath,c=a.disableModelInvocation;return(0,d.jsxs)("div",{onClick:()=>{m(a.filePath),s(!1)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:b?"var(--bg-selected)":"none"},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="none")},children:[(0,d.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:c?"var(--border)":"var(--accent)",boxShadow:c?"none":"0 0 4px var(--accent)",transition:"background 0.15s, box-shadow 0.15s"}}),(0,d.jsx)("span",{style:{fontSize:12,fontWeight:b?600:400,color:c?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name})]},a.filePath)})]},a))})()}),(0,d.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,d.jsxs)("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:r?"var(--bg-selected)":"none",color:r?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:a=>{r||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{r||(a.currentTarget.style.background="none")},children:[(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,d.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add skill"]})})]}),(0,d.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:r?(0,d.jsx)(c6,{cwd:a,onInstalled:()=>{t()}}):h?null:v?(0,d.jsx)(c5,{skill:v,cwd:a,onToggle:u,toggling:n.has(v.filePath),saveError:p},v.filePath):(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a skill"})})]}),(0,d.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,d.jsx)("button",{onClick:b,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Close"})})]})})}let c8=[{label:"30m",value:18e5},{label:"2h",value:72e5},{label:"6h",value:216e5},{label:"24h",value:864e5},{label:"48h",value:1728e5},{label:"Never",value:0}];function c9(a){return a?a.replace(/^\/(?:Users|home)\/[^/]+/,"~"):""}function da(a){if(a<=0)return"never";let b=a/60/1e3;if(b<60)return`${Math.round(b)}m`;let c=b/60;return Number.isInteger(c)?`${c}h`:`${c.toFixed(1)}h`}function db(a){return{id:"",language:a,displayName:"",command:"python"===a?"python3":"R",argsText:JSON.stringify("python"===a?["-u"]:["--slave","--vanilla"]),envText:"{}"}}function dc(a){return{id:a.id,language:a.language,displayName:a.displayName,command:a.command,argsText:JSON.stringify(a.args),envText:JSON.stringify(a.env,null,2)}}let dd={height:30,padding:"0 11px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,whiteSpace:"nowrap"},de={width:"100%",minWidth:0,padding:"7px 9px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)"};function df({label:a,children:b}){return(0,d.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:5,minWidth:0},children:[(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontWeight:500},children:a}),b]})}function dg({cwd:a}){let[b,c]=(0,e.useState)("python"),[f,g]=(0,e.useState)(null),[h,i]=(0,e.useState)(!0),[j,k]=(0,e.useState)(null),[l,m]=(0,e.useState)(null),[n,o]=(0,e.useState)(null),[p,q]=(0,e.useState)([]),[r,s]=(0,e.useState)(null),[t,u]=(0,e.useState)("view"),[v,w]=(0,e.useState)(()=>db("python")),[x,y]=(0,e.useState)(1728e5),[z,A]=(0,e.useState)("pdf"),[B,C]=(0,e.useState)(300),[D,E]=(0,e.useState)(800),[F,G]=(0,e.useState)(600),[H,I]=(0,e.useState)(!1);(0,e.useCallback)(async()=>{i(!0),m(null);try{let c=a?`?cwd=${encodeURIComponent(a)}`:"",d=await fetch(`/api/plot-kernels${c}`),e=await d.json();if(!d.ok||e.error)throw Error(e.error??`HTTP ${d.status}`);g(e),q([]),o(null),s(a=>{if(a&&e.kernels.some(b=>b.id===a))return a;let c=e.kernels.find(a=>a.language===b&&a.isEffective);return c?.id??e.kernels.find(a=>a.language===b)?.id??null})}catch(a){m(a instanceof Error?a.message:String(a))}finally{i(!1)}},[a,b]);let J=(0,e.useMemo)(()=>(f?.kernels??[]).filter(a=>a.language===b),[b,f?.kernels]),K=J.find(a=>a.id===r)??null,L=(0,e.useCallback)(async(b,c)=>{k(c),m(null),o(null),q([]);try{let c=await fetch("/api/plot-kernels",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,...b})}),d=await c.json();if(!c.ok||d.error)throw Error(d.error??`HTTP ${c.status}`);return g(d),q(d.errors??[]),d}catch(a){return m(a instanceof Error?a.message:String(a)),null}finally{k(null)}},[a]),M=(0,e.useCallback)(async a=>{let b=await L({action:"scan",..."all"===a?{}:{language:a}},"scan");b&&o(`Scan added ${b.added?.length??0} kernel${(b.added?.length??0)===1?"":"s"}${b.skipped?`, skipped ${b.skipped} existing`:""}.`)},[L]),N=(0,e.useCallback)(async a=>{await L({action:"select",language:a.language,kernelId:a.id},"select")&&o(`Selected ${a.displayName} for this project.`)},[L]),O=(0,e.useCallback)(async a=>{await L({action:"setDefault",language:a.language,kernelId:a.id},"default")&&o(`Set ${a.displayName} as global default.`)},[L]),P=(0,e.useCallback)(async()=>{let a=v.id.trim();if(!a)return void m("Kernel ID is required");try{let b=function(a){let b=JSON.parse(a.argsText||"[]"),c=JSON.parse(a.envText||"{}");if(!Array.isArray(b))throw Error("Args must be a JSON array");if(!c||"object"!=typeof c||Array.isArray(c))throw Error("Env must be a JSON object");return{language:a.language,command:a.command.trim(),displayName:a.displayName.trim(),args:b.map(a=>String(a)),env:Object.fromEntries(Object.entries(c).map(([a,b])=>[a,String(b)]))}}(v);if(!b.command)throw Error("Command is required");if(!await L({action:"new"===t?"add":"edit",kernelId:a,kernel:b},"save"))return;s(a),u("view"),o("new"===t?"Kernel added.":"Kernel saved.")}catch(a){m(a instanceof Error?a.message:String(a))}},[v,t,L]),Q=(0,e.useCallback)(async a=>{let c=await L({action:"delete",kernelId:a.id},"delete");if(!c)return;let d=c.kernels.find(a=>a.language===b&&a.isEffective)??c.kernels.find(a=>a.language===b)??null;s(d?.id??null),u(d?"view":"new"),o("Kernel deleted.")},[b,L]),R=()=>{u("new"),s(null),w(db(b)),m(null),o(null)},S=(0,e.useCallback)(async a=>{y(a),I(!0),m(null);try{let b=await fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:{plotIdleTimeoutMs:a}})}),c=await b.json();if(!b.ok||c.error)throw Error(c.error??`HTTP ${b.status}`);"number"==typeof c.settings?.plotIdleTimeoutMs&&(y(c.settings.plotIdleTimeoutMs),o(`Workbench idle timeout set to ${da(c.settings.plotIdleTimeoutMs)}.`))}catch(a){y(x),m(a instanceof Error?a.message:String(a))}finally{I(!1)}},[x]),T=(0,e.useCallback)(async()=>{I(!0),m(null);try{let a=await fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:{saveFormat:z,saveDpi:B,saveWidth:D,saveHeight:F}})}),b=await a.json();if(!a.ok||b.error)throw Error(b.error??`HTTP ${a.status}`);o("Save defaults updated.")}catch(a){m(a instanceof Error?a.message:String(a))}finally{I(!1)}},[z,B,D,F]);return(0,d.jsxs)("div",{style:{height:"100%",minHeight:0,display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{flexShrink:0,padding:"12px 16px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,d.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:"Workbench Runtime"}),(0,d.jsx)("div",{style:{marginTop:4,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Manage the warm R/Python kernels used by Workbench sessions and iterative analysis turns."})]}),(0,d.jsxs)("div",{style:{flexShrink:0,display:"flex",alignItems:"center",gap:10,padding:"12px 16px",borderBottom:"1px solid var(--border)",flexWrap:"wrap"},children:[(0,d.jsx)("div",{style:{display:"flex",padding:2,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:["python","r"].map(a=>{let e=b===a;return(0,d.jsx)("button",{type:"button",onClick:()=>c(a),style:{height:26,padding:"0 12px",border:"none",borderRadius:5,background:e?"var(--bg)":"transparent",color:e?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:e?600:500},children:"python"===a?"Python":"R"},a)})}),(0,d.jsxs)("button",{type:"button",onClick:()=>void M(b),disabled:!!j,style:{...dd,opacity:j?.55:1},children:[(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M21 12a9 9 0 0 1-15.3 6.4"}),(0,d.jsx)("path",{d:"M3 12A9 9 0 0 1 18.3 5.6"}),(0,d.jsx)("path",{d:"M18 2v4h4"}),(0,d.jsx)("path",{d:"M6 22v-4H2"})]}),"scan"===j?"Scanning...":`Scan ${"python"===b?"Python":"R"}`]}),(0,d.jsx)("button",{type:"button",onClick:()=>void M("all"),disabled:!!j,style:{...dd,opacity:j?.55:1},children:"Scan all"}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginLeft:"auto"},children:[(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"Idle"}),(0,d.jsx)("div",{style:{display:"flex",padding:2,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:c8.map(a=>{let b=x===a.value;return(0,d.jsx)("button",{type:"button",onClick:()=>{b||S(a.value)},disabled:H,title:`Close inactive Workbench kernels after ${da(a.value)}`,style:{height:24,padding:"0 8px",border:"none",borderRadius:5,background:b?"var(--bg)":"transparent",color:b?"var(--accent)":"var(--text-muted)",cursor:H?"default":"pointer",fontSize:11,fontWeight:b?700:500,opacity:H?.65:1},children:a.label},a.label)})})]}),(0,d.jsxs)("button",{type:"button",onClick:R,style:{...dd,marginLeft:"auto",color:"var(--accent)"},children:[(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,d.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add kernel"]})]}),(0,d.jsxs)("div",{style:{flexShrink:0,padding:"10px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,d.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:"Save defaults"}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"Format"}),(0,d.jsx)("div",{style:{display:"flex",padding:2,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:["pdf","png","svg"].map(a=>{let b=z===a;return(0,d.jsx)("button",{type:"button",onClick:()=>A(a),style:{height:24,padding:"0 8px",border:"none",borderRadius:5,background:b?"var(--bg)":"transparent",color:b?"var(--accent)":"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:b?700:500},children:a.toUpperCase()},a)})}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"DPI"}),(0,d.jsx)("input",{type:"number",value:B,onChange:a=>C(Number(a.target.value)||300),min:72,max:1200,style:{width:60,height:26,padding:"0 6px",fontSize:11,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)"}}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"W"}),(0,d.jsx)("input",{type:"number",value:D,onChange:a=>E(Number(a.target.value)||800),min:100,max:8e3,style:{width:65,height:26,padding:"0 6px",fontSize:11,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)"}}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"H"}),(0,d.jsx)("input",{type:"number",value:F,onChange:a=>G(Number(a.target.value)||600),min:100,max:8e3,style:{width:65,height:26,padding:"0 6px",fontSize:11,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)"}}),(0,d.jsx)("button",{type:"button",onClick:()=>void T(),disabled:H,style:{...dd,background:"var(--accent)",borderColor:"var(--accent)",color:"#fff",opacity:H?.6:1},children:H?"Saving...":"Save"})]}),(l||n||p.length>0)&&(0,d.jsxs)("div",{style:{flexShrink:0,padding:"8px 16px",borderBottom:"1px solid var(--border)",fontSize:12,lineHeight:1.5},children:[l&&(0,d.jsx)("div",{style:{color:"#f87171"},children:l}),n&&(0,d.jsx)("div",{style:{color:"var(--text-muted)"},children:n}),p.map(a=>(0,d.jsx)("div",{style:{color:"rgba(234,179,8,0.95)"},children:a},a))]}),(0,d.jsxs)("div",{style:{flex:1,minHeight:0,display:"flex",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{width:290,flexShrink:0,borderRight:"1px solid var(--border)",background:"var(--bg-panel)",display:"flex",flexDirection:"column",minHeight:0},children:[(0,d.jsxs)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,d.jsxs)("div",{children:["Global: ",(0,d.jsx)("code",{style:{fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:c9(f?.paths.global??"")})]}),a&&(0,d.jsxs)("div",{children:["Project: ",(0,d.jsx)("code",{style:{fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:c9(f?.paths.project??"")})]}),!a&&(0,d.jsx)("div",{children:"Project selection requires an active cwd."})]}),(0,d.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",padding:"8px 6px"},children:h?(0,d.jsx)("div",{style:{padding:"10px 8px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}):0===J.length?(0,d.jsx)("div",{style:{padding:"10px 8px",color:"var(--text-dim)",fontSize:12},children:"No kernels found"}):J.map(a=>{let b=r===a.id&&"new"!==t;return(0,d.jsxs)("button",{type:"button",onClick:()=>{s(a.id),u("view"),w(dc(a)),m(null),o(null)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"8px 9px",border:"none",borderRadius:6,background:b?"var(--bg-selected)":"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="transparent")},children:[(0,d.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:a.isEffective?"var(--accent)":"var(--border)",flexShrink:0}}),(0,d.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,d.jsx)("span",{style:{display:"block",color:"var(--text)",fontSize:12,fontWeight:b?600:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.displayName}),(0,d.jsx)("span",{style:{display:"block",color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.id})]}),(a.isProjectSelected||a.isDefault)&&(0,d.jsxs)("span",{style:{flexShrink:0,display:"flex",gap:3},children:[a.isProjectSelected&&(0,d.jsx)("span",{title:"Project selected",style:{fontSize:9,color:"var(--accent)",border:"1px solid rgba(37,99,235,0.35)",borderRadius:4,padding:"1px 4px"},children:"P"}),a.isDefault&&(0,d.jsx)("span",{title:"Global default",style:{fontSize:9,color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:4,padding:"1px 4px"},children:"D"})]})]},a.id)})}),(0,d.jsxs)("div",{style:{padding:"8px 10px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:["Last scan: ",function(a){if(!a)return"never";let b=new Date(a);return Number.isNaN(b.getTime())?a:b.toLocaleString()}(f?.scanCache?.lastScan)]})]}),(0,d.jsx)("div",{style:{flex:1,minWidth:0,minHeight:0,overflowY:"auto",padding:18},children:"view"===t&&K?(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16,maxWidth:760},children:[(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,d.jsx)("h3",{style:{margin:0,color:"var(--text)",fontSize:15,lineHeight:1.3},children:K.displayName}),K.isEffective&&(0,d.jsx)("span",{style:{fontSize:10,color:"var(--accent)",border:"1px solid rgba(37,99,235,0.35)",borderRadius:4,padding:"1px 5px"},children:"active"})]}),(0,d.jsx)("div",{style:{marginTop:5,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:K.id})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,d.jsx)(df,{label:"Command",children:(0,d.jsx)("input",{readOnly:!0,value:K.command,style:{...de,color:"var(--text-muted)"}})}),(0,d.jsx)(df,{label:"Args",children:(0,d.jsx)("input",{readOnly:!0,value:JSON.stringify(K.args),style:{...de,color:"var(--text-muted)"}})})]}),(0,d.jsx)(df,{label:"Environment",children:(0,d.jsx)("textarea",{readOnly:!0,value:JSON.stringify(K.env,null,2),rows:5,style:{...de,resize:"vertical",color:"var(--text-muted)"}})}),(0,d.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,d.jsx)("button",{type:"button",onClick:()=>a&&void N(K),disabled:!a||"select"===j,style:{...dd,background:a?"var(--accent)":"var(--bg-panel)",color:a?"#fff":"var(--text-dim)",opacity:"select"===j?.6:1},children:"Use for project"}),(0,d.jsx)("button",{type:"button",onClick:()=>void O(K),disabled:"default"===j,style:{...dd,opacity:"default"===j?.6:1},children:"Set default"}),(0,d.jsx)("button",{type:"button",onClick:()=>{u("edit"),s(K.id),w(dc(K)),m(null),o(null)},style:dd,children:"Edit"}),!K.id.startsWith("default-")&&(0,d.jsx)("button",{type:"button",onClick:()=>void Q(K),disabled:"delete"===j,style:{...dd,color:"#f87171",opacity:"delete"===j?.6:1},children:"Delete"})]})]}):(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:14,maxWidth:760},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:8},children:[(0,d.jsx)("h3",{style:{margin:0,color:"var(--text)",fontSize:15},children:"new"===t?"Add Kernel":"Edit Kernel"}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"python"===b?"Python":"R"})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,d.jsx)(df,{label:"Kernel ID",children:(0,d.jsx)("input",{value:v.id,readOnly:"edit"===t,onChange:a=>w(b=>({...b,id:a.target.value})),placeholder:"python"===b?"my-python":"my-r",style:{...de,color:"edit"===t?"var(--text-muted)":"var(--text)"}})}),(0,d.jsx)(df,{label:"Display name",children:(0,d.jsx)("input",{value:v.displayName,onChange:a=>w(b=>({...b,displayName:a.target.value})),placeholder:"python"===b?"Python 3 (Project)":"R (Project)",style:de})})]}),(0,d.jsx)(df,{label:"Command",children:(0,d.jsx)("input",{value:v.command,onChange:a=>w(b=>({...b,command:a.target.value})),placeholder:"/usr/bin/python3",style:de})}),(0,d.jsx)(df,{label:"Args JSON",children:(0,d.jsx)("input",{value:v.argsText,onChange:a=>w(b=>({...b,argsText:a.target.value})),style:de})}),(0,d.jsx)(df,{label:"Env JSON",children:(0,d.jsx)("textarea",{value:v.envText,onChange:a=>w(b=>({...b,envText:a.target.value})),rows:6,style:{...de,resize:"vertical"}})}),(0,d.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,d.jsx)("button",{type:"button",onClick:()=>void P(),disabled:"save"===j,style:{...dd,background:"var(--accent)",borderColor:"var(--accent)",color:"#fff",opacity:"save"===j?.6:1},children:"save"===j?"Saving...":"Save"}),(0,d.jsx)("button",{type:"button",onClick:()=>{let a=K??J.find(a=>a.isEffective)??J[0]??null;a?(s(a.id),w(dc(a)),u("view")):R(),m(null)},style:dd,children:"Cancel"})]})]})})]})]})}var dh=c(39868);function di({text:a,label:b="Copy",title:c,onCopied:f,onError:g}){let[h,i]=(0,e.useState)(!1),j=(0,e.useCallback)(async()=>{try{await (0,dh.D)(a),i(!0),f?.()}catch(a){g?.(a instanceof Error?a:Error(String(a)))}},[f,g,a]);return(0,d.jsx)("button",{type:"button",onClick:()=>void j(),title:c??(h?"Copied":b),style:{height:24,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-hover)",color:h?"#22c55e":"var(--text-muted)",fontSize:10,fontWeight:600,cursor:"pointer",flexShrink:0},children:h?"Copied":b})}let dj="annovibe-im-gateway";function dk({cwd:a,embedded:b=!1}){let[c,f]=(0,e.useState)(null),[g,h]=(0,e.useState)(null),[i,j]=(0,e.useState)(null),[k,l]=(0,e.useState)(""),[m,n]=(0,e.useState)(""),[o,p]=(0,e.useState)(!1),[q,r]=(0,e.useState)(""),[s,t]=(0,e.useState)(""),[u,v]=(0,e.useState)(!1),[w,x]=(0,e.useState)(!1),[y,z]=(0,e.useState)(!1),[A,B]=(0,e.useState)(null),[C,D]=(0,e.useState)(null),E=(0,e.useCallback)((a,b)=>{"success"===b?(D(a),B(null),setTimeout(()=>D(null),4500)):(B(a),D(null))},[]);(0,e.useCallback)(async()=>{try{let a=await fetch("/api/im/gateway-status",{cache:"no-store"}),b=await a.json();if(!a.ok||!b.gateway)return;j(b.gateway)}catch{}},[]),(0,e.useCallback)(async()=>{v(!0),B(null);try{let b=await fetch(`/api/im/project?cwd=${encodeURIComponent(a)}`,{cache:"no-store"}),c=await b.json();if(!b.ok||!("enabled"in c))throw Error(c.error??`HTTP ${b.status}`);f(c),h(c.gatewayToken??null),l(c.botId),p(c.requireMentionInGroup),r(c.boundChatId??""),t(c.allowedUsers.join("\n")),n("")}catch(a){E(a instanceof Error?a.message:String(a),"error")}finally{v(!1)}},[a,E]);let F=(0,e.useCallback)(async b=>{x(!0),B(null),D(null);try{let c=await fetch("/api/im/project",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,config:b})}),d=await c.json();if(!c.ok||!("enabled"in d))throw Error(d.error??`HTTP ${c.status}`);f(d),h(d.gatewayToken??null),n(""),E("IM settings saved.","success")}catch(a){E(a instanceof Error?a.message:String(a),"error")}finally{x(!1)}},[a,E]),G=(0,e.useCallback)(a=>{F({enabled:a,botId:k.trim(),botSecret:m.trim()||void 0,requireMentionInGroup:o,boundChatId:q.trim()||null,allowedUsers:dp(s)})},[k,m,o,q,s,F]),H=(0,e.useCallback)(()=>{F({enabled:c?.enabled??!1,botId:k.trim(),botSecret:m.trim()||void 0,requireMentionInGroup:o,boundChatId:q.trim()||null,allowedUsers:dp(s)})},[c?.enabled,k,m,o,q,s,F]),I=(0,e.useCallback)(()=>{F({regeneratePairingCode:!0})},[F]),J=(0,e.useCallback)(async()=>{if(c?.sessionId&&window.confirm("Reset the IM thread for this project?\n\nThis clears the stored WeCom session. Pairing and bot settings are kept. The next IM message starts a fresh session.")){z(!0);try{let b=await fetch(`/api/im/session-ids?cwd=${encodeURIComponent(a)}`,{method:"DELETE"}),c=await b.json();if(!b.ok||!c.ok)throw Error(c.error??`HTTP ${b.status}`);f(a=>a?{...a,sessionId:null}:null),E("IM thread reset.","success")}catch(a){E(a instanceof Error?a.message:String(a),"error")}finally{z(!1)}}},[c?.sessionId,a,E]);if(u&&!c)return(0,d.jsx)(ds,{label:"Loading IM settings..."});let K=c?.enabled??!1;return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,paddingTop:12*!!b},children:[(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",padding:12,display:"flex",flexDirection:"column",gap:12},children:[(0,d.jsx)(dn,{label:"WeCom bot for this project",description:K?"启动 im-gateway 后即可通过企业微信 AI bot 与此项目交互。":"关闭 — 开启后可绑定企业微信 bot 到此项目。",checked:K,disabled:w,onChange:G}),K?(0,d.jsxs)(d.Fragment,{children:[i?(0,d.jsx)(dl,{status:i}):null,(0,d.jsx)(dq,{label:"Bot ID",value:k,onChange:l,placeholder:"从企业微信 AI bot 控制台获取"}),(0,d.jsx)(dq,{label:c?.hasSecret?"Bot Secret(留空则不修改)":"Bot Secret",value:m,onChange:n,placeholder:c?.hasSecret?"留空保留现有 secret":"从企业微信 AI bot 控制台获取",secret:!0}),(0,d.jsx)(dn,{label:"群聊中需要 @提及 bot 才响应",description:"开启后,群聊中用户必须 @bot 才会被处理。",checked:o,disabled:w,compact:!0,onChange:p}),(0,d.jsx)(dq,{label:"绑定群聊 ID(可选)",value:q,onChange:r,placeholder:"限制仅此群聊可交互"}),(0,d.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:11,color:"var(--text-muted)"},children:[(0,d.jsx)("span",{children:"允许用户 ID(一行一个)"}),(0,d.jsx)("textarea",{value:s,onChange:a=>t(a.target.value),rows:3,style:dv,placeholder:"用户也可通过配对码自助授权"})]}),(0,d.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[(0,d.jsx)(dr,{primary:!0,disabled:w,onClick:H,children:w?"保存中…":"保存 IM 配置"}),(0,d.jsx)(dr,{disabled:w,onClick:I,children:"重新生成配对码"})]})]}):null]}),K&&c?(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",padding:12,fontSize:11,color:"var(--text-muted)",display:"flex",flexDirection:"column",gap:8},children:[(0,d.jsx)(dm,{label:"配对码",value:c.pairingCode,copyLabel:"复制配对码"}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,flexWrap:"wrap"},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("strong",{style:{color:"var(--text)"},children:"IM session:"})," ",c.sessionId?`${c.sessionId.slice(0,12)}…`:"尚未启动"]}),c.sessionId?(0,d.jsx)(dr,{danger:!0,disabled:w||y,onClick:()=>void J(),children:y?"重置中…":"重置 IM thread"}):null]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("strong",{style:{color:"var(--text)"},children:"Gateway token:"})," ",g?`${g.slice(0,8)}…`:"保存时生成"]}),(0,d.jsx)(dm,{label:"Gateway 启动命令",value:dj,copyLabel:"复制命令",mono:!0}),(0,d.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["启动 ",(0,d.jsx)("code",{style:dt,children:"annovibe"})," 后,在",(0,d.jsx)("strong",{style:{color:"var(--text-muted)",fontWeight:600},children:"同一 Linux 账户"}),"中运行"," ",(0,d.jsx)("code",{style:dt,children:dj}),"。 Gateway 通过本地 API 读取已启用的项目配置和 bot secret —— 无需手动复制文件。"]}),(0,d.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["配置文件: ",(0,d.jsxs)("code",{style:dt,children:["<project>","/.annovibe/im.json"]})," \xb7 Secrets: ",(0,d.jsx)("code",{style:dt,children:"~/.pi/agent/im-secrets/"})]}),A&&(0,d.jsx)("div",{style:{padding:"6px 10px",background:"rgba(239,68,68,0.08)",borderRadius:6,border:"1px solid rgba(239,68,68,0.3)",color:"#ef4444",fontSize:12},children:A}),C&&(0,d.jsx)("div",{style:{padding:"6px 10px",background:"rgba(34,197,94,0.08)",borderRadius:6,border:"1px solid rgba(34,197,94,0.3)",color:"#22c55e",fontSize:12},children:C})]}):null]})}function dl({status:a}){var b,c,e,f;let g=function(a){if(!a)return null;let b=new Date(a);return Number.isNaN(b.getTime())?a:b.toLocaleString()}(a.startedAt),h=a.alive&&a.pid?`pid ${a.pid}${g?` \xb7 since ${g}`:""}`:g?`last started ${g}`:"在同一个 Linux 账户下运行 annovibe-im-gateway";return(0,d.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"8px 10px",borderRadius:8,border:`1px solid ${"running"===(b=a.tone)?"rgba(34,197,94,0.28)":"stale"===b?"rgba(245,158,11,0.28)":"rgba(248,113,113,0.28)"}`,background:"running"===(c=a.tone)?"rgba(34,197,94,0.08)":"stale"===c?"rgba(245,158,11,0.08)":"rgba(248,113,113,0.08)"},children:[(0,d.jsx)("span",{"aria-hidden":!0,style:{width:8,height:8,borderRadius:"50%",marginTop:4,flexShrink:0,background:"running"===(e=a.tone)?"#22c55e":"stale"===e?"#f59e0b":"#f87171"}}),(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:11,fontWeight:650,color:"running"===(f=a.tone)?"#22c55e":"stale"===f?"#f59e0b":"#f87171"},children:a.label}),(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:3,lineHeight:1.45},children:h})]})]})}function dm({label:a,value:b,copyLabel:c,mono:e}){return(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsxs)("strong",{style:{color:"var(--text)"},children:[a,":"]})," ",(0,d.jsx)("code",{style:{...dt,...e?{wordBreak:"break-all"}:{}},children:b})]}),(0,d.jsx)(di,{text:b,label:c})]})}function dn({label:a,description:b,checked:c,disabled:e,compact:f,onChange:g}){return(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:f?"2px 0":"10px 12px",borderRadius:8*!f,border:f?"none":`1px solid ${c?"color-mix(in srgb, var(--accent) 35%, var(--border))":"var(--border)"}`,background:f?"transparent":c?"color-mix(in srgb, var(--accent) 8%, var(--bg-panel))":"var(--bg)"},children:[(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:f?11:13,fontWeight:f?500:650,color:"var(--text)"},children:a}),b?(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:4,lineHeight:1.45},children:b}):null]}),(0,d.jsx)("button",{type:"button",role:"switch","aria-checked":c,disabled:e,onClick:()=>g(!c),style:{position:"relative",width:44,height:26,borderRadius:999,border:"none",flexShrink:0,background:c?"var(--accent)":"color-mix(in srgb, var(--text-dim) 35%, var(--border))",cursor:e?"default":"pointer",opacity:e?.55:1,transition:"background 0.15s",padding:0},children:(0,d.jsx)("span",{style:{position:"absolute",top:3,left:c?21:3,width:20,height:20,borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.18)",transition:"left 0.15s"}})})]})}function dp(a){return a.split(/\r?\n/).map(a=>a.trim()).filter(Boolean)}function dq({label:a,value:b,onChange:c,placeholder:e,secret:f}){return(0,d.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:11,color:"var(--text-muted)"},children:[(0,d.jsx)("span",{children:a}),(0,d.jsx)("input",{type:f?"password":"text",value:b,onChange:a=>c(a.target.value),placeholder:e,style:du})]})}function dr({children:a,disabled:b,primary:c,danger:e,onClick:f}){return(0,d.jsx)("button",{type:"button",disabled:b,onClick:f,style:{height:28,padding:"0 10px",borderRadius:6,border:c?"none":e?"1px solid rgba(248,113,113,0.45)":"1px solid var(--border)",background:c?"var(--accent)":e?"rgba(248,113,113,0.08)":"var(--bg-hover)",color:c?"#fff":e?"#f87171":"var(--text)",fontSize:11,fontWeight:c?600:400,cursor:b?"default":"pointer",opacity:b?.55:1},children:a})}function ds({label:a}){return(0,d.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:"18px 10px",color:"var(--text-dim)",fontSize:12,textAlign:"center"},children:a})}let dt={fontFamily:"var(--font-mono)",fontSize:"0.95em"},du={height:30,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"},dv={padding:"8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",resize:"vertical"},dw={border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)"},dx={height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12};function dy({cwd:a}){let[b,c]=(0,e.useState)(null),[f,g]=(0,e.useState)(!0),[h,i]=(0,e.useState)(null),[j,k]=(0,e.useState)(null);(0,e.useCallback)(async()=>{g(!0),k(null);try{let b=await fetch(`/api/plot-kernels?cwd=${encodeURIComponent(a)}`),d=await b.json().catch(()=>({}));if(!b.ok||d.error||!Array.isArray(d.kernels))throw Error(d.error??`HTTP ${b.status}`);c(d)}catch(a){c(null),k(a instanceof Error?a.message:String(a))}finally{g(!1)}},[a]);let l=(0,e.useCallback)(async(b,d)=>{i(b),k(null);try{let e=await fetch("/api/plot-kernels",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"select",cwd:a,language:b,kernelId:d})}),f=await e.json().catch(()=>({}));if(!e.ok||f.error||!Array.isArray(f.kernels))throw Error(f.error??`HTTP ${e.status}`);c(f)}catch(a){k(a instanceof Error?a.message:String(a))}finally{i(null)}},[a]),m=a=>{let c=b?.kernels.filter(b=>b.language===a)??[],e=c.find(a=>a.isEffective)??c[0]??null;return(0,d.jsxs)("label",{style:{display:"grid",gap:6},children:[(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:"r"===a?"Default R kernel":"Default Python kernel"}),(0,d.jsx)("select",{value:e?.id??"",disabled:f||h===a||0===c.length,onChange:b=>{b.target.value&&l(a,b.target.value)},style:{height:32,padding:"0 9px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12},children:0===c.length?(0,d.jsx)("option",{value:"",children:f?"Loading...":"No configured kernel"}):c.map(a=>(0,d.jsxs)("option",{value:a.id,children:[a.displayName,a.isProjectSelected?" \xb7 project":a.isDefault?" \xb7 global":""," — ",a.command," ",(a.args??[]).join(" ")]},a.id))})]})};return(0,d.jsxs)("section",{style:{...dw,padding:14,display:"grid",gap:12},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Default kernels"}),(0,d.jsx)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)",lineHeight:1.45},children:"Used as the default R/Python kernels for Workbench sessions. Normal chats also use these when they call Workbench kernel tools for analysis."})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr)",gap:10},children:[m("r"),m("python")]}),j&&(0,d.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:j})]})}function dz({activeCwd:a,onSelectProject:b,onProjectsChanged:c}){let[f,g]=(0,e.useState)([]),[h,i]=(0,e.useState)(a),[j,l]=(0,e.useState)(null),[m,n]=(0,e.useState)(!0),[o,p]=(0,e.useState)(null),[q,r]=(0,e.useState)(""),[s,t]=(0,e.useState)(!1),[u,v]=(0,e.useState)(null),[w,x]=(0,e.useState)(null),[y,z]=(0,e.useState)(""),[A,B]=(0,e.useState)(null),[C,D]=(0,e.useState)(null),E=(0,e.useRef)(null),F=f.find(a=>a.cwd===h)??f.find(b=>b.cwd===a)??f[0]??null,G=(0,e.useCallback)(async()=>{try{n(!0);let b=await fetch("/api/projects"),c=await b.json();if(!b.ok||c.error)throw Error(c.error??`HTTP ${b.status}`);let d=c.projects??[];g(d),i(b=>b&&d.some(a=>a.cwd===b)?b:a&&d.some(b=>b.cwd===a)?a:d[0]?.cwd??null),p(null)}catch(a){p(a instanceof Error?a.message:String(a))}finally{n(!1)}},[a]),H=(0,e.useMemo)(()=>({projects:f.length,chats:f.reduce((a,b)=>a+b.chatCount,0)}),[f]),I=(0,e.useCallback)(async()=>{let a=q.trim();if(a){v("add"),p(null);try{let d=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a})}),e=await d.json();if(!d.ok||e.error)throw Error(e.error??`HTTP ${d.status}`);r(""),i(a),c?.(),b?.(a),G()}catch(a){p(a instanceof Error?a.message:String(a))}finally{v(null)}}},[G,c,b,q]),J=(0,e.useCallback)(async a=>{v("add"),p(null);try{let d=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a})}),e=await d.json();if(!d.ok||e.error)throw Error(e.error??`HTTP ${d.status}`);r(""),t(!1),i(a),c?.(),b?.(a),G()}catch(a){p(a instanceof Error?a.message:String(a))}finally{v(null)}},[G,c,b]),K=(0,e.useCallback)(async a=>{v(`rename:${a}`),p(null);try{let b=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,name:y})}),d=await b.json();if(!b.ok||d.error)throw Error(d.error??`HTTP ${b.status}`);x(null),z(""),await G(),c?.()}catch(a){p(a instanceof Error?a.message:String(a))}finally{v(null)}},[G,c,y]),L=(0,e.useCallback)(async a=>{if(window.confirm("Remove this project from AnnoVibe? Sessions on disk will not be deleted.")){v(`remove:${a}`),p(null);try{let b=await fetch("/api/projects",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a})}),d=await b.json();if(!b.ok||d.error)throw Error(d.error??`HTTP ${b.status}`);i(b=>b===a?null:b),await G(),c?.()}catch(a){p(a instanceof Error?a.message:String(a))}finally{v(null)}}},[G,c]),M=(0,e.useCallback)(a=>{x(a.cwd),z(a.displayName),requestAnimationFrame(()=>E.current?.focus())},[]),N=(0,e.useCallback)(async a=>{try{let b=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:a})});if(!b.ok)throw Error(`HTTP ${b.status}`);c?.()}catch{G()}},[G,c]),O=(0,e.useCallback)((a,b)=>{"reorder"!==u&&(B(a),b.dataTransfer.effectAllowed="move",b.dataTransfer.setData("text/project-cwd",a))},[u]),P=(0,e.useCallback)((a,b)=>{b.preventDefault(),b.dataTransfer.dropEffect="move",D(a)},[]),Q=(0,e.useCallback)(a=>{if(D(null),!A||A===a)return void B(null);let b=f.map(a=>a.cwd).filter(Boolean),c=b.indexOf(A),d=b.indexOf(a);c<0||d<0?B(null):(b.splice(c,1),b.splice(d,0,A),g(a=>{let c=new Map(a.map(a=>[a.cwd,a]));return b.map(a=>c.get(a)).filter(Boolean)}),B(null),N(b))},[A,N,f]),R=(0,e.useCallback)(()=>{B(null),D(null)},[]);return(0,d.jsxs)("div",{style:{height:"100%",overflow:"hidden",display:"flex",flexDirection:"column"},children:[o&&(0,d.jsx)("div",{style:{marginBottom:12,padding:"10px 12px",borderRadius:8,border:"1px solid rgba(248,113,113,0.35)",background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:12},children:o}),(0,d.jsxs)("div",{style:{display:"flex",gap:8,marginBottom:14,flexShrink:0},children:[(0,d.jsx)("div",{style:{position:"relative",flex:1,minWidth:0},children:(0,d.jsx)("input",{type:"text",value:q,onChange:a=>r(a.target.value),onKeyDown:a=>{"Enter"===a.key&&I()},placeholder:"/path/to/project",style:{width:"100%",height:30,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",outline:"none"}})}),(0,d.jsx)("button",{type:"button",disabled:"add"===u,onClick:()=>void I(),style:{height:30,padding:"0 11px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12,fontWeight:500},children:"Add"}),(0,d.jsx)("button",{type:"button",onClick:()=>t(!0),style:{...dx,height:30},children:"Browse…"})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(220px, 34%) minmax(0, 1fr)",gap:14,minHeight:0,flex:1},children:[(0,d.jsxs)("aside",{style:{...dw,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"},children:[(0,d.jsxs)("div",{style:{padding:"10px 12px",borderBottom:"1px solid var(--border)"},children:[(0,d.jsxs)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:700},children:[H.projects," Projects"]}),(0,d.jsxs)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11},children:[H.chats," chats total"]})]}),(0,d.jsx)("div",{style:{overflow:"auto",padding:8,display:"grid",gap:6},children:m?(0,d.jsx)("div",{style:{padding:12,color:"var(--text-muted)",fontSize:12},children:"Loading projects..."}):0===f.length?(0,d.jsx)("div",{style:{padding:12,color:"var(--text-muted)",fontSize:12},children:"No projects yet."}):f.map(b=>{var c;let e,f=b.cwd===a,g=b.cwd===F?.cwd,h=A===b.cwd,k=C===b.cwd&&A!==b.cwd,m=j===b.cwd&&!g;return(0,d.jsxs)("button",{type:"button",draggable:!0,onClick:()=>i(b.cwd),onDragStart:a=>O(b.cwd,a),onDragOver:a=>P(b.cwd,a),onDrop:()=>Q(b.cwd),onDragEnd:R,onMouseEnter:()=>l(b.cwd),onMouseLeave:()=>l(null),style:{display:"grid",gap:4,width:"100%",textAlign:"left",padding:"9px 10px",border:`1px solid ${k?"rgba(37,99,235,0.45)":g?"color-mix(in srgb, var(--accent) 45%, var(--border))":"transparent"}`,borderRadius:8,background:k?"rgba(37,99,235,0.06)":g?"color-mix(in srgb, var(--accent) 8%, var(--bg-panel))":"transparent",color:"var(--text)",cursor:"pointer",opacity:h?.55:1},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,d.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12.5,fontWeight:g?750:600},children:b.displayName}),f&&(0,d.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontWeight:700},children:"current"}),m&&(0,d.jsx)("span",{onClick:a=>{a.stopPropagation(),L(b.cwd)},style:{color:"#f87171",fontSize:11,fontWeight:650},children:"remove"})]}),(0,d.jsx)("div",{style:{color:"var(--text-dim)",fontSize:10.5,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:b.cwd,children:(e=(c=b.cwd).split(/[\\/]/).filter(Boolean)).length<=3?c:`.../${e.slice(-3).join("/")}`})]},b.cwd)})})]}),(0,d.jsx)("main",{style:{minHeight:0,overflow:"auto"},children:F?(0,d.jsxs)("div",{style:{display:"grid",gap:14},children:[(0,d.jsx)("section",{style:{...dw,padding:14,display:"grid",gap:12},children:(0,d.jsxs)("div",{style:{display:"flex",gap:12,alignItems:"flex-start"},children:[(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[w===F.cwd?(0,d.jsx)("input",{ref:E,value:y,onChange:a=>z(a.target.value),onKeyDown:a=>{"Enter"===a.key&&K(F.cwd),"Escape"===a.key&&x(null)},style:{width:"min(420px, 100%)",height:32,padding:"0 9px",border:"1px solid var(--accent)",borderRadius:6,background:"var(--bg)",color:"var(--text)",fontSize:13,outline:"none"}}):(0,d.jsx)("div",{style:{color:"var(--text)",fontSize:16,fontWeight:750},children:F.displayName}),(0,d.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:F.cwd}),(0,d.jsxs)("div",{style:{marginTop:7,color:"var(--text-muted)",fontSize:11},children:[F.chatCount," chats / last ",function(a){if(!a)return"Never";let b=new Date(a),c=new Date().getTime()-b.getTime(),d=Math.floor(c/6e4),e=Math.floor(c/36e5),f=Math.floor(c/864e5);return d<1?"just now":d<60?`${d}m ago`:e<24?`${e}h ago`:f<7?`${f}d ago`:b.toLocaleDateString()}(F.lastAccessed??F.created??null),F.exists?"":" / path missing"]})]}),(0,d.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",justifyContent:"flex-end"},children:w===F.cwd?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("button",{type:"button",disabled:u===`rename:${F.cwd}`,onClick:()=>void K(F.cwd),style:{...dx,border:"none",background:"var(--accent)",color:"#fff"},children:"Save"}),(0,d.jsx)("button",{type:"button",onClick:()=>x(null),style:dx,children:"Cancel"})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("button",{type:"button",onClick:()=>b?.(F.cwd),style:{...dx,background:F.cwd===a?"var(--accent)":"var(--bg-panel)",color:F.cwd===a?"#fff":"var(--text-muted)"},children:F.cwd===a?"Current":"Switch"}),(0,d.jsx)("button",{type:"button",onClick:()=>M(F),style:dx,children:"Rename"}),(0,d.jsx)("button",{type:"button",disabled:u===`remove:${F.cwd}`,onClick:()=>void L(F.cwd),style:{...dx,border:"1px solid rgba(248,113,113,0.35)",background:"transparent",color:"#f87171"},children:"Remove"})]})})]})}),(0,d.jsx)(dy,{cwd:F.cwd}),(0,d.jsxs)("section",{style:{...dw,padding:14,display:"grid",gap:12},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"WeCom IM"}),(0,d.jsx)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)"},children:"Project notification and chat gateway settings."})]}),(0,d.jsx)(dk,{cwd:F.cwd,embedded:!0})]})]}):(0,d.jsx)("div",{style:{...dw,padding:18,color:"var(--text-muted)",fontSize:12},children:"Select a project to edit settings."})})]}),(0,d.jsx)(k,{open:s,initialPath:a,onClose:()=>t(!1),onSelect:a=>void J(a)})]})}var dA=c(49998);let dB=["127.0.0.0/8","::1","10.0.0.0/8","172.16.0.0/12","192.168.0.0/16"];function dC({checked:a,onChange:b}){return(0,d.jsx)("button",{type:"button",onClick:b,"aria-pressed":a,style:{width:44,height:24,borderRadius:999,border:"none",padding:0,cursor:"pointer",background:a?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",flexShrink:0},children:(0,d.jsx)("span",{style:{position:"absolute",top:3,left:a?23:3,width:18,height:18,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function dD({label:a,description:b,checked:c,onChange:e}){return(0,d.jsxs)("label",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"10px 12px",borderRadius:8,border:`1px solid ${c?"var(--accent)":"var(--border)"}`,background:c?"rgba(37,99,235,0.04)":"var(--bg)",cursor:"pointer",fontSize:12},children:[(0,d.jsx)("input",{type:"radio",checked:c,onChange:e,style:{marginTop:2,accentColor:"var(--accent)"}}),(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontWeight:600,color:"var(--text)",lineHeight:1.4},children:a}),(0,d.jsx)("div",{style:{color:"var(--text-dim)",lineHeight:1.5,marginTop:2},children:b})]})]})}function dE(){let[a,b]=(0,e.useState)(null),[c,f]=(0,e.useState)(!0),[g,h]=(0,e.useState)(null),[i,j]=(0,e.useState)(null),[k,l]=(0,e.useState)(""),[m,n]=(0,e.useState)(""),[o,p]=(0,e.useState)(null),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)(!1),[w,x]=(0,e.useState)("always"),[y,z]=(0,e.useState)(dB),[A,B]=(0,e.useState)("");(0,e.useCallback)(async()=>{try{let a=await fetch("/api/auth/totp"),c=await a.json();b(c),x(c.requireMode??"always"),z(c.trustedNetworks??dB)}catch{}finally{f(!1)}},[]);let C=async()=>{if(a){if(p(null),"enabled"===a.status){if(!m||!/^\d{6}$/.test(m))return void p("Enter your 6-digit authenticator code to disable");v(!0);try{let a=await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"disable",code:m})}),c=await a.json();a.ok?(b({status:"disabled",enabled:!1,requireMode:"always",trustedNetworks:dB}),n(""),h(null),j(null),t(null),r("Two-factor authentication disabled")):p(c.error??"Failed to disable")}catch{p("Network error")}finally{v(!1)}return}v(!0);try{let a=await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"setup"})}),c=await a.json();if(a.ok&&c.uri){j(c.uri);let a=await dA.toDataURL(c.uri,{width:200,margin:1});h(a),b({status:"pending",enabled:!1,requireMode:w,trustedNetworks:y}),r(null)}else p(c.error??"Failed to start setup")}catch{p("Network error")}finally{v(!1)}}},D=async()=>{if(!k||!/^\d{6}$/.test(k))return void p("Enter the 6-digit code from your authenticator app");v(!0),p(null);try{let a=await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"verify-setup",code:k})}),c=await a.json();a.ok&&c.success?(await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-require-mode",requireMode:w})}),await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-trusted-networks",trustedNetworks:y})}),b({status:"enabled",enabled:!0,requireMode:w,trustedNetworks:y}),l(""),h(null),j(null),c.recoveryCodes&&t(c.recoveryCodes),r("Two-factor authentication enabled!")):p(c.error??"Invalid code")}catch{p("Network error")}finally{v(!1)}},E=async()=>{h(null),j(null),l(""),p(null);try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"disable"})}),b({status:"disabled",enabled:!1,requireMode:"always",trustedNetworks:dB})}catch{}},F=(0,e.useCallback)(async c=>{if(x(c),a?.status==="enabled")try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-require-mode",requireMode:c})}),b(a=>a?{...a,requireMode:c}:a)}catch{x(a.requireMode)}},[a]),G=(0,e.useCallback)(async()=>{let c=A.trim();if(!c||y.includes(c))return;let d=c.split("/");if(2!==d.length)return void p("Invalid CIDR format (e.g. 192.168.1.0/24)");let e=parseInt(d[1],10);if(isNaN(e)||e<0||e>128)return void p("Invalid CIDR prefix length");p(null);let f=[...y,c];if(z(f),B(""),a?.status==="enabled")try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-trusted-networks",trustedNetworks:f})}),b(a=>a?{...a,trustedNetworks:f}:a)}catch{z(y)}},[A,y,a]),H=(0,e.useCallback)(async c=>{let d=y.filter(a=>a!==c);if(z(d),a?.status==="enabled")try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-trusted-networks",trustedNetworks:d})}),b(a=>a?{...a,trustedNetworks:d}:a)}catch{z(y)}},[y,a]);return c?(0,d.jsx)("div",{style:{padding:20,fontSize:13,color:"var(--text-muted)"},children:"Loading…"}):(0,d.jsx)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:(0,d.jsxs)("div",{style:{maxWidth:600,display:"flex",flexDirection:"column",gap:16},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)",lineHeight:1.35},children:"Two-Factor Authentication"}),(0,d.jsx)("div",{style:{marginTop:4,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Require a time-based one-time code in addition to your password."})]}),(0,d.jsx)(dC,{checked:a?.status==="enabled",onChange:()=>{}})]}),a&&(0,d.jsx)("div",{style:{fontSize:11,padding:"4px 10px",borderRadius:999,background:"enabled"===a.status?"rgba(34,197,94,0.12)":"pending"===a.status?"rgba(250,204,21,0.12)":"var(--bg-hover)",color:"enabled"===a.status?"#16a34a":"pending"===a.status?"#ca8a04":"var(--text-dim)",display:"inline-flex",alignSelf:"flex-start",fontWeight:600},children:"enabled"===a.status?"● Active":"pending"===a.status?"◐ Setup in progress":"○ Inactive"}),o&&(0,d.jsx)("div",{style:{fontSize:12,color:"#ef4444",padding:"8px 12px",background:"rgba(239,68,68,0.06)",borderRadius:6},children:o}),q&&!o&&(0,d.jsx)("div",{style:{fontSize:12,color:"#16a34a",padding:"8px 12px",background:"rgba(34,197,94,0.06)",borderRadius:6},children:q}),a?.status==="pending"&&g&&(0,d.jsxs)("div",{style:{padding:20,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",display:"flex",flexDirection:"column",alignItems:"center",gap:14},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:"Scan with your authenticator app"}),(0,d.jsx)("div",{style:{background:"#fff",padding:12,borderRadius:8,border:"1px solid var(--border)"},children:(0,d.jsx)("img",{src:g,alt:"TOTP QR Code",style:{display:"block",width:200,height:200}})}),i&&(0,d.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)",textAlign:"center",maxWidth:280},children:[(0,d.jsx)("div",{style:{marginBottom:4},children:"Or enter this key manually:"}),(0,d.jsx)("code",{style:{fontSize:11,fontFamily:"var(--font-mono), monospace",wordBreak:"break-all",background:"var(--bg)",padding:"4px 8px",borderRadius:4},children:i.split("secret=")[1]?.split("&")[0]??"—"})]}),(0,d.jsxs)("div",{style:{width:"100%",maxWidth:260},children:[(0,d.jsx)("label",{style:{fontSize:12,color:"var(--text-dim)",display:"block",marginBottom:6},children:"Enter the 6-digit code to verify"}),(0,d.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,d.jsx)("input",{type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:k,onChange:a=>l(a.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000 000",style:{flex:1,padding:"8px 12px",fontSize:16,fontFamily:"var(--font-mono), monospace",letterSpacing:"0.12em",textAlign:"center",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,d.jsx)("button",{type:"button",disabled:u||6!==k.length,onClick:D,style:{padding:"8px 16px",fontSize:13,fontWeight:600,background:6===k.length?"var(--accent)":"var(--bg-hover)",color:6===k.length?"#fff":"var(--text-dim)",border:"none",borderRadius:6,cursor:6===k.length?"pointer":"not-allowed"},children:u?"…":"Verify"})]})]}),(0,d.jsx)("button",{type:"button",onClick:E,style:{fontSize:12,color:"var(--text-dim)",background:"none",border:"none",cursor:"pointer"},children:"Cancel setup"})]}),s&&s.length>0&&(0,d.jsxs)("div",{style:{padding:20,border:"1px solid rgba(34,197,94,0.3)",borderRadius:8,background:"rgba(34,197,94,0.04)"},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)",marginBottom:6},children:"Recovery codes"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:12,lineHeight:1.55},children:"Save these codes in a safe place. Each can be used once to sign in if you lose access to your authenticator app. They will not be shown again."}),(0,d.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:6,fontFamily:"var(--font-mono), monospace",fontSize:12,color:"var(--text)"},children:s.map((a,b)=>(0,d.jsx)("code",{style:{padding:"6px 10px",background:"var(--bg)",borderRadius:4,border:"1px solid var(--border)"},children:a},b))}),(0,d.jsx)("button",{type:"button",onClick:()=>{t(null),r(null)},style:{marginTop:14,padding:"8px 18px",fontSize:13,fontWeight:600,background:"var(--accent)",color:"#fff",border:"none",borderRadius:6,cursor:"pointer"},children:"I've saved these codes"})]}),(a?.status==="enabled"||a?.status==="pending")&&!s&&(0,d.jsxs)("div",{style:{padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)",marginBottom:12},children:"Scope"}),(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:14},children:[(0,d.jsx)(dD,{label:"Require on all networks",description:"TOTP code is always required during login, even from localhost or LAN.",checked:"always"===w,onChange:()=>F("always")}),(0,d.jsx)(dD,{label:"Skip on trusted networks",description:"TOTP code is only required when signing in from outside localhost or LAN.",checked:"untrusted"===w,onChange:()=>F("untrusted")})]}),"untrusted"===w&&(0,d.jsxs)("div",{style:{padding:"10px 12px",background:"var(--bg)",borderRadius:8,border:"1px solid var(--border)"},children:[(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",marginBottom:8,lineHeight:1.5},children:"Trusted CIDR blocks (TOTP will be skipped for requests from these IP ranges):"}),(0,d.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:y.map(a=>(0,d.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 8px",borderRadius:999,background:"var(--bg-panel)",border:"1px solid var(--border)",fontSize:11,fontFamily:"var(--font-mono), monospace",color:"var(--text)"},children:[a,(0,d.jsx)("button",{type:"button",onClick:()=>H(a),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-dim)",fontSize:13,lineHeight:1,padding:0},title:"Remove",children:"\xd7"})]},a))}),(0,d.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,d.jsx)("input",{type:"text",value:A,onChange:a=>B(a.target.value),onKeyDown:a=>{"Enter"===a.key&&G()},placeholder:"e.g. 192.168.1.0/24",style:{flex:1,padding:"6px 10px",fontSize:12,fontFamily:"var(--font-mono), monospace",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,d.jsx)("button",{type:"button",onClick:G,style:{padding:"6px 12px",fontSize:12,fontWeight:600,background:A.trim()?"var(--accent)":"var(--bg-hover)",color:A.trim()?"#fff":"var(--text-dim)",border:"none",borderRadius:6,cursor:A.trim()?"pointer":"not-allowed"},children:"Add"})]})]})]}),a?.status==="enabled"&&!s&&(0,d.jsxs)("div",{style:{padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:8},children:"Disable two-factor authentication"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:12,lineHeight:1.5},children:"Enter your current authenticator code to disable 2FA. This will make your account less secure."}),(0,d.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,d.jsx)("input",{type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:m,onChange:a=>n(a.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000 000",style:{flex:1,padding:"8px 12px",fontSize:16,fontFamily:"var(--font-mono), monospace",letterSpacing:"0.12em",textAlign:"center",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,d.jsx)("button",{type:"button",disabled:u||6!==m.length,onClick:C,style:{padding:"8px 16px",fontSize:13,fontWeight:600,background:6===m.length?"rgba(239,68,68,0.85)":"var(--bg-hover)",color:6===m.length?"#fff":"var(--text-dim)",border:"none",borderRadius:6,cursor:6===m.length?"pointer":"not-allowed"},children:u?"…":"Disable 2FA"})]})]}),a?.status==="disabled"&&(0,d.jsxs)("div",{style:{padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"When enabled, you'll need to enter a 6-digit code from your authenticator app (Google Authenticator, Authy, 1Password, etc.) each time you sign in from a new browser or after your session expires."}),(0,d.jsx)("button",{type:"button",disabled:u,onClick:C,style:{marginTop:14,padding:"8px 18px",fontSize:13,fontWeight:600,background:"var(--accent)",color:"#fff",border:"none",borderRadius:6,cursor:"pointer",opacity:u?.6:1},children:u?"Setting up…":"Set up authenticator"})]})]})})}function dF({checked:a,onChange:b}){return(0,d.jsx)("button",{type:"button",onClick:b,"aria-pressed":a,style:{width:44,height:24,borderRadius:999,border:"none",padding:0,cursor:"pointer",background:a?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",flexShrink:0},children:(0,d.jsx)("span",{style:{position:"absolute",top:3,left:a?23:3,width:18,height:18,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function dG(){return(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.38a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.51a2 2 0 0 1 1-1.72l.15-.1a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2Z"}),(0,d.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}function dH(a){return"projects"===a?(0,d.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}):"models"===a?(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,d.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,d.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,d.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,d.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,d.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"})]}):"skills"===a?(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,d.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,d.jsx)("path",{d:"M2 12l10 5 10-5"})]}):"authenticator"===a?(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),(0,d.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"}),(0,d.jsx)("circle",{cx:"12",cy:"16",r:"1"})]}):"generative-ui"===a?(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,d.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,d.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,d.jsx)("path",{d:"M16 17h5"}),(0,d.jsx)("path",{d:"M18.5 14.5v5"})]}):(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M3 3v18h18"}),(0,d.jsx)("path",{d:"m19 9-5 5-4-4-3 3"}),(0,d.jsx)("path",{d:"M14 9h5v5"})]})}function dI({cwd:a,generativeUI:b,initialTab:c="projects",onGenerativeUIToggle:f,onClose:g,onModelsChanged:h,onProjectSelect:i,onProjectsChanged:j}){let[k,l]=(0,e.useState)(c),m=[{id:"projects",label:"Project",description:a?"Overview and paths":"Add or select a project",icon:dH("projects")},{id:"models",label:"Models",description:"~/.pi/agent/models.json",icon:dH("models")},{id:"authenticator",label:"Authenticator",description:"Two-factor authentication",icon:dH("authenticator")},{id:"skills",label:"Skills",description:a?"Project and global skills":"Select a project first",disabled:!a,icon:dH("skills")},{id:"generative-ui",label:"Generative UI",description:b?"Enabled":"Disabled",icon:dH("generative-ui")},{id:"workbench-runtime",label:"Kernels",description:a?"Project R / Python kernels":"Global R / Python kernels",icon:dH("workbench-runtime")}],n=m.find(a=>a.id===k)??m[0];return(0,d.jsx)("div",{className:"settings-dialog-backdrop",onClick:a=>{a.target===a.currentTarget&&g()},children:(0,d.jsxs)("div",{className:"settings-dialog-shell",children:[(0,d.jsxs)("div",{className:"settings-dialog-header",children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:9,minWidth:0},children:[(0,d.jsx)("span",{style:{color:"var(--text-muted)",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,d.jsx)(dG,{})}),(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:15,fontWeight:700,color:"var(--text)",lineHeight:1.25},children:"Settings"}),(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n.label})]})]}),(0,d.jsx)("button",{type:"button",onClick:g,title:"Close settings","aria-label":"Close settings",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.background="transparent",a.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,d.jsxs)("div",{className:"settings-dialog-body",children:[(0,d.jsx)("div",{className:"settings-dialog-tabs",children:m.map(a=>{let b=k===a.id;return(0,d.jsxs)("button",{type:"button",disabled:a.disabled,onClick:()=>l(a.id),className:"settings-dialog-tab",style:{background:b?"var(--bg-selected)":"transparent",color:b?"var(--text)":"var(--text-muted)",opacity:a.disabled?.45:1,cursor:a.disabled?"not-allowed":"pointer"},onMouseEnter:c=>{b||a.disabled||(c.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="transparent")},children:[(0,d.jsx)("span",{style:{flexShrink:0,color:b?"var(--accent)":"currentColor",display:"flex"},children:a.icon}),(0,d.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,d.jsx)("span",{style:{display:"block",fontSize:12,fontWeight:b?700:600,lineHeight:1.25},children:a.label}),(0,d.jsx)("span",{style:{display:"block",marginTop:2,fontSize:10,color:"var(--text-dim)",lineHeight:1.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.description})]})]},a.id)})}),(0,d.jsxs)("div",{className:"settings-dialog-panel",children:["projects"===k&&(0,d.jsx)(dz,{activeCwd:a,onSelectProject:i,onProjectsChanged:j}),"models"===k&&(0,d.jsx)(c1,{embedded:!0,onClose:()=>{h?.(),g()}}),"authenticator"===k&&(0,d.jsx)(dE,{}),"skills"===k&&a&&(0,d.jsx)(c7,{cwd:a,embedded:!0,onClose:g}),"generative-ui"===k&&(0,d.jsx)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:(0,d.jsxs)("div",{style:{maxWidth:720,display:"flex",flexDirection:"column",gap:18},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:18,padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)",lineHeight:1.35},children:"Generative UI"}),(0,d.jsx)("div",{style:{marginTop:5,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Render structured widgets and safe visual code blocks directly in chat when the assistant produces UI content."})]}),(0,d.jsx)(dF,{checked:b,onChange:f})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,d.jsxs)("div",{style:{padding:14,border:"1px solid var(--border)",borderRadius:8},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",marginBottom:5},children:"When enabled"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:"The agent prompt favors compact visual artifacts for icons, forms, dashboards, and small interactive UI when useful."})]}),(0,d.jsxs)("div",{style:{padding:14,border:"1px solid var(--border)",borderRadius:8},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",marginBottom:5},children:"Fallback rendering"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:"Assistant SVG and safe HTML code blocks can be previewed instead of appearing only as source text."})]})]})]})}),"workbench-runtime"===k&&(0,d.jsx)(dg,{cwd:a})]})]})]})})}function dJ(a){return a?a.replace(/^\/(?:Users|home)\/[^/]+/,"~"):""}function dK(a){return!Number.isFinite(a)||a<=0?"0.0G":`${(a/1024/1024/1024).toFixed(1)}G`}let dL={height:32,padding:"0 12px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12};function dM({cwd:a,runtime:b,runtimeError:c,busy:f=!1,onClose:g,onLaunch:h,onReleaseCurrentRuntime:i,onOpenSettings:j}){let[k,l]=(0,e.useState)("r"),[m,n]=(0,e.useState)(!1),[o,p]=(0,e.useState)(null),[q,r]=(0,e.useState)([]),[s,t]=(0,e.useState)(!1),[u,v]=(0,e.useState)(null),[w,x]=(0,e.useState)(""),[y,z]=(0,e.useState)(""),[A,B]=(0,e.useState)(!1),[C,D]=(0,e.useState)([]),[E,F]=(0,e.useState)(""),[G,H]=(0,e.useState)(!1),[I,J]=(0,e.useState)(null),K=(0,e.useMemo)(()=>q.filter(a=>a.language===k),[k,q]),L=(0,e.useMemo)(()=>K.find(a=>a.id===o)??K.find(a=>a.isEffective)??K[0]??null,[o,K]),M=(0,e.useCallback)(async a=>{if(a){H(!0),J(null);try{let b=a.split("/").filter(Boolean).map(encodeURIComponent).join("/"),c=await fetch(`/api/files/${b}?type=list`);if(!c.ok){let a=await c.json().catch(()=>({}));throw Error(a.error??`HTTP ${c.status}`)}let d=await c.json();D(d.entries),F(d.path)}catch(a){J(a instanceof Error?a.message:String(a)),D([])}finally{H(!1)}}},[]),N=(0,e.useCallback)(()=>{a&&(B(!0),M(a))},[a,M]),O=(0,e.useCallback)(a=>{M(E?`${E.replace(/\/+$/,"")}/${a}`:a)},[E,M]),P=(0,e.useCallback)(a=>{x(E?`${E.replace(/\/+$/,"")}/${a}`:a),B(!1)},[E]),Q="r"===k?[".rds",".qs"]:"python"===k?[".h5ad"]:[];return(0,d.jsx)("div",{className:"settings-dialog-backdrop",onClick:a=>{a.target!==a.currentTarget||f||g()},children:(0,d.jsxs)("div",{style:{width:"min(720px, calc(100vw - 40px))",maxHeight:"min(760px, calc(100vh - 40px))",overflow:"auto",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 24px 80px rgba(0,0,0,0.28)"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:16,padding:"18px 18px 14px",borderBottom:"1px solid var(--border)"},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:18,fontWeight:700,color:"var(--text)"},children:"Workbench"}),(0,d.jsxs)("div",{style:{marginTop:6,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:["Starts a dedicated top-level Workbench session in the current project.",a?` Project: ${dJ(a)}`:""]})]}),(0,d.jsx)("button",{type:"button",onClick:g,disabled:f,style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:f?"not-allowed":"pointer",fontSize:20,lineHeight:1,opacity:f?.5:1},children:"x"})]}),(0,d.jsxs)("div",{style:{padding:18,display:"grid",gap:18},children:[(0,d.jsxs)("section",{style:{display:"grid",gap:10},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Kernel"}),(0,d.jsx)("div",{style:{display:"flex",gap:8},children:[{id:"r",label:"R",desc:"Seurat, rds, qs, Bioconductor workflows"},{id:"python",label:"Python",desc:"AnnData, h5ad, pandas, scanpy workflows"}].map(a=>{let b=k===a.id;return(0,d.jsxs)("button",{type:"button",onClick:()=>l(a.id),style:{flex:1,textAlign:"left",padding:"12px 13px",borderRadius:10,border:`1px solid ${b?"rgba(37,99,235,0.45)":"var(--border)"}`,background:b?"var(--bg-selected)":"var(--bg-panel)",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer"},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700},children:a.label}),(0,d.jsx)("div",{style:{marginTop:4,fontSize:11,lineHeight:1.5},children:a.desc})]},a.id)})})]}),(0,d.jsxs)("section",{style:{display:"grid",gap:10},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Mode"}),(0,d.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 13px",borderRadius:10,border:`1px solid ${m?"rgba(37,99,235,0.45)":"var(--border)"}`,background:m?"var(--bg-selected)":"var(--bg-panel)",cursor:"pointer"},children:[(0,d.jsx)("input",{type:"checkbox",checked:m,onChange:a=>n(a.target.checked),style:{accentColor:"var(--accent)"}}),(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:700,color:m?"var(--text)":"var(--text-muted)"},children:"I describe, you code"}),(0,d.jsx)("div",{style:{marginTop:2,fontSize:11,color:"var(--text-dim)",lineHeight:1.45},children:"Describe the analysis in domain terms. The agent will plan the approach, suggest methods, and write the code."})]})]})]}),(0,d.jsxs)("section",{style:{display:"grid",gap:10},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Kernel runtime"}),(0,d.jsxs)("label",{style:{display:"grid",gap:6},children:[(0,d.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["Specific ","r"===k?"R":"Python"," kernel"]}),(0,d.jsx)("select",{value:L?.id??"",onChange:a=>p(a.target.value||null),disabled:f||s||0===K.length,style:{height:34,padding:"0 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",fontSize:12},children:0===K.length?(0,d.jsx)("option",{value:"",children:s?"Loading kernels...":"No configured kernel"}):K.map(a=>(0,d.jsxs)("option",{value:a.id,children:[a.displayName,a.isEffective?" \xb7 current":""," — ",a.command," ",(a.args??[]).join(" ")]},a.id))}),u&&(0,d.jsx)("span",{style:{fontSize:11,color:"#f87171"},children:u}),(0,d.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.45},children:"Launching will select this kernel for the current project before starting the Workbench session."})]})]}),(0,d.jsxs)("section",{style:{display:"grid",gap:10},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Sources"}),(0,d.jsxs)("label",{style:{display:"grid",gap:6},children:[(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:"Primary object or dataset path"}),(0,d.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,d.jsx)("input",{value:w,onChange:a=>x(a.target.value),placeholder:"r"===k?"e.g. ./data/sample.rds or ./objects/integrated.qs":"e.g. ./data/sample.h5ad",style:{flex:1,height:34,padding:"0 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"}}),(0,d.jsx)("button",{type:"button",onClick:N,disabled:!a||f,title:"Browse project files",style:{...dL,whiteSpace:"nowrap",opacity:!a||f?.5:1,cursor:!a||f?"not-allowed":"pointer"},children:A?"Collapse":"Browse"})]})]}),A&&a&&(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",maxHeight:260,overflow:"auto",fontSize:12},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"6px 10px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:[(0,d.jsx)("button",{type:"button",onClick:()=>{B(!1)},style:{border:"none",background:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:11,padding:0},children:"✕"}),(0,d.jsx)("span",{style:{color:"var(--text-dim)"},children:"|"}),E?(()=>{let a=E.replace(/^\/+/,"").split("/"),b=[];for(let c=0;c<a.length;c++){let d="/"+a.slice(0,c+1).join("/");b.push({label:0===c?dJ(d):a[c],dir:d})}return b.map((b,c)=>(0,d.jsxs)("span",{children:[c>0&&(0,d.jsx)("span",{style:{margin:"0 2px",color:"var(--text-dim)"},children:"/"}),(0,d.jsx)("button",{type:"button",onClick:()=>M(b.dir),style:{border:"none",background:"none",color:c===a.length-1?"var(--text)":"var(--text-muted)",cursor:c===a.length-1?"default":"pointer",fontSize:11,padding:"2px 1px",fontWeight:c===a.length-1?600:400},children:b.label})]},b.dir))})():(0,d.jsx)("span",{style:{color:"var(--text-muted)"},children:"Loading..."})]}),G?(0,d.jsx)("div",{style:{padding:"16px 10px",color:"var(--text-dim)",textAlign:"center"},children:"Loading..."}):I?(0,d.jsx)("div",{style:{padding:"16px 10px",color:"#f87171",textAlign:"center"},children:I}):0===C.length?(0,d.jsx)("div",{style:{padding:"16px 10px",color:"var(--text-dim)",textAlign:"center"},children:"empty directory"}):(0,d.jsxs)("div",{children:[E!==a&&(0,d.jsxs)("div",{onClick:()=>{M(E.replace(/\/+$/,"").split("/").slice(0,-1).join("/")||"/")},style:{display:"flex",alignItems:"center",gap:6,padding:"5px 10px",cursor:"pointer",color:"var(--text-muted)"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="transparent"},children:[(0,d.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",children:(0,d.jsx)("path",{d:"M10 3L5 8l5 5",stroke:"var(--text-dim)",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,d.jsx)("span",{style:{fontSize:11},children:".."})]}),C.map(a=>{let b,c=!a.isDir&&(b=a.name.toLowerCase(),Q.some(a=>b.endsWith(a)));return(0,d.jsxs)("div",{onClick:()=>{a.isDir?O(a.name):P(a.name)},style:{display:"flex",alignItems:"center",gap:6,padding:"5px 10px",cursor:(a.isDir,"pointer"),color:a.isDir?"var(--text)":c?"var(--accent)":"var(--text-muted)",fontWeight:c?600:400},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="transparent"},children:[a.isDir?(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:(0,d.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5H14a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4.5Z",stroke:"var(--text-dim)",strokeWidth:"1",fill:"var(--text-dim)",fillOpacity:"0.1"})}):(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:[(0,d.jsx)("path",{d:"M3 2h7l3 3v9H3V2Z",stroke:c?"var(--accent)":"var(--text-dim)",strokeWidth:"1",fill:c?"var(--accent)":"var(--text-dim)",fillOpacity:"0.08"}),(0,d.jsx)("path",{d:"M10 2v3h3",stroke:c?"var(--accent)":"var(--text-dim)",strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]}),(0,d.jsx)("span",{style:{fontSize:12},children:a.name}),c&&(0,d.jsx)("span",{style:{fontSize:10,color:"var(--accent)",background:"rgba(37,99,235,0.1)",padding:"0 5px",borderRadius:3,lineHeight:"16px"},children:a.name.split(".").pop()})]},a.name)})]})]}),(0,d.jsxs)("label",{style:{display:"grid",gap:6,marginTop:4},children:[(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:"Notes or extra file hints"}),(0,d.jsx)("textarea",{value:y,onChange:a=>z(a.target.value),placeholder:"Optional: metadata table paths, desired comparison, object name hints, or initialization notes.",rows:5,style:{width:"100%",resize:"vertical",minHeight:96,padding:"10px",borderRadius:8,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",fontSize:12,lineHeight:1.55}})]})]}),(0,d.jsxs)("section",{style:{display:"grid",gap:10,padding:14,border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)"},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Runtime"}),(0,d.jsxs)("div",{style:{display:"flex",gap:16,flexWrap:"wrap",fontSize:12,color:"var(--text-muted)"},children:[(0,d.jsxs)("span",{children:["Total memory ",dK(b.totalBytes)]}),(0,d.jsxs)("span",{children:["Current session ",dK(b.currentSessionBytes)]}),(0,d.jsxs)("span",{children:["Idle timeout ",b.idleTimeoutLabel]})]}),(0,d.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[i&&(0,d.jsx)("button",{type:"button",onClick:i,style:dL,children:"Release current chat"}),j&&(0,d.jsx)("button",{type:"button",onClick:j,style:dL,children:"Runtime settings"})]}),c&&(0,d.jsx)("div",{style:{fontSize:12,color:"#f87171",lineHeight:1.5},children:c})]})]}),(0,d.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"0 18px 18px"},children:[(0,d.jsx)("button",{type:"button",onClick:g,disabled:f,style:dL,children:"Cancel"}),(0,d.jsx)("button",{type:"button",onClick:()=>void h({kernel:k,kernelId:L?.id??null,kernelDisplayName:L?.displayName??null,sourcePath:w.trim(),notes:y.trim(),isDescribeMode:m}),disabled:f||!a||0===K.length,style:{...dL,border:"1px solid rgba(37,99,235,0.45)",background:"rgba(37,99,235,0.12)",color:"var(--accent)",opacity:f||!a?.55:1,cursor:f||!a?"not-allowed":"pointer"},children:f?"Launching...":"Launch Workbench"})]})]})})}function dN(a){return a&&Number.isFinite(a)&&!(a<=0)?a<1048576?`${(a/1024).toFixed(0)}K`:a<0x40000000?`${(a/1024/1024).toFixed(1)}M`:`${(a/1024/1024/1024).toFixed(1)}G`:"0.0G"}function dO(a){return[...a].sort((a,b)=>b.totalBytes-a.totalBytes||a.id.localeCompare(b.id))}function dP(a){let b=new Map;for(let c of a){let a=c.sessionId?`session:${c.sessionId}`:`process:${c.pid}`;b.set(a,[...b.get(a)??[],c])}return[...b.entries()].map(([a,b])=>({id:a,kind:b[0]?.sessionId?"session":"process",sessionId:b[0]?.sessionId??null,cwd:b[0]?.cwd??null,kernels:b,totalBytes:b.reduce((a,b)=>a+b.rssBytes,0),lastActivity:function(a){let b=0;for(let c of a){if(!c.lastActivity)continue;let a=new Date(c.lastActivity).getTime();Number.isFinite(a)&&(b=Math.max(b,a))}return b>0?new Date(b).toISOString():null}(b)}))}let dQ={height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},dR={...dQ,color:"#ef4444",border:"1px solid rgba(239,68,68,0.35)",background:"rgba(239,68,68,0.08)"};function dS({open:a,anchorRef:b,status:c,error:f,currentSessionId:g,currentCwd:h,idleTimeoutLabel:i,busyPid:j,onClose:k,onRefresh:l,onReleaseKernels:m,onOpenSettings:n,onOpenStatus:o}){let p=function(){let[a,b]=(0,e.useState)(!1);return a}(),q=function(){let[a,b]=(0,e.useState)({top:56,left:12});return a}(),r=(0,e.useMemo)(()=>c?.kernels??[],[c?.kernels]),s=(0,e.useMemo)(()=>dP(r),[r]),t=(0,e.useMemo)(()=>(function(a,b,c){let d=[],e=[],f=[],g=[];for(let i of dP(a))if(b&&i.sessionId===b)d.push(i);else if("process"===i.kind)g.push(i);else{var h;c&&(h=i.cwd,h&&c&&h.replace(/\/+$/,"")===c.replace(/\/+$/,""))?e.push(i):f.push(i)}return[{id:"current",title:"Current session",subtitle:`${dN(d.reduce((a,b)=>a+b.totalBytes,0))} retained`,groups:dO(d)},{id:"project",title:"Other sessions in this project",subtitle:`${e.length} session${1===e.length?"":"s"}`,groups:dO(e)},{id:"other",title:"Other projects",subtitle:`${dN(f.reduce((a,b)=>a+b.totalBytes,0))}`,groups:dO(f)},{id:"untracked",title:"Unattributed",subtitle:`${g.length} process${1===g.length?"":"es"}`,groups:dO(g)}].filter(a=>a.groups.length>0)})(r,g,h),[h,g,r]),u=c?.totalBytes??0,v=c?.currentSessionBytes??0;if(!a)return null;let w=p?{position:"fixed",left:0,right:0,bottom:0,maxHeight:"82dvh",borderRadius:"12px 12px 0 0"}:{position:"fixed",top:q.top,left:q.left,width:"min(620px, calc(100vw - 24px))",maxHeight:"min(680px, calc(100vh - 72px))",borderRadius:10};return(0,d.jsx)("div",{onMouseDown:k,style:{position:"fixed",inset:0,zIndex:900,background:p?"rgba(0,0,0,0.34)":"transparent"},children:(0,d.jsxs)("div",{onMouseDown:a=>a.stopPropagation(),role:"dialog","aria-modal":p?"true":"false","aria-label":"Workbench runtime",style:{...w,overflow:"hidden",border:"1px solid var(--border)",background:"var(--bg)",boxShadow:"0 18px 60px rgba(0,0,0,0.26)",display:"flex",flexDirection:"column"},children:[(0,d.jsxs)("div",{style:{padding:"12px 14px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12},children:[(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0,flexWrap:"wrap"},children:[(0,d.jsx)("span",{style:{fontSize:13,fontWeight:750,color:"var(--text)"},children:"Workbench Runtime"}),(0,d.jsxs)("span",{style:{fontSize:11,color:v>0?"var(--accent)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums"},children:[dN(v)," current / ",dN(u)," total"]})]}),(0,d.jsxs)("div",{style:{marginTop:4,display:"flex",gap:10,flexWrap:"wrap",fontSize:11,color:"var(--text-dim)"},children:[(0,d.jsxs)("span",{children:[s.length," session",1===s.length?"":"s"]}),(0,d.jsxs)("span",{children:[r.length," kernel",1===r.length?"":"s"]}),(0,d.jsxs)("span",{children:["idle timeout ",i]}),c?.generatedAt&&(0,d.jsxs)("span",{children:["updated ",new Date(c.generatedAt).toLocaleTimeString()]})]})]}),(0,d.jsx)("button",{type:"button",onClick:k,title:"Close","aria-label":"Close",style:{...dQ,width:28,padding:0,fontSize:18,lineHeight:1},children:"x"})]}),(0,d.jsxs)("div",{style:{marginTop:10,display:"flex",gap:7,flexWrap:"wrap"},children:[(0,d.jsx)("button",{type:"button",onClick:l,style:dQ,children:"Refresh"}),o&&(0,d.jsx)("button",{type:"button",onClick:o,style:dQ,children:"Open Status"}),(0,d.jsx)("button",{type:"button",onClick:n,style:dQ,children:"Runtime Settings"})]}),f&&(0,d.jsx)("div",{style:{marginTop:9,border:"1px solid rgba(248,113,113,0.25)",borderRadius:7,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11,lineHeight:1.45,padding:"7px 8px"},children:f})]}),(0,d.jsx)("div",{style:{overflow:"auto",padding:10},children:0===t.length?(0,d.jsx)("div",{style:{padding:"28px 12px",textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No active Workbench runtime."}):(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:t.map(a=>(0,d.jsxs)("section",{children:[(0,d.jsxs)("div",{style:{marginBottom:7,display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:10},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:750,color:"var(--text)"},children:a.title}),(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums"},children:a.subtitle})]}),(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:a.groups.map(a=>{var b;let c=!!g&&a.sessionId===g,e=a.kernels.some(a=>j===a.pid),f=a.kernels.map(a=>a.pid).join(", ");return(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:p?"1fr":"minmax(0, 1fr) auto",gap:p?9:12,alignItems:"center",border:`1px solid ${c?"rgba(37,99,235,0.42)":"var(--border)"}`,borderRadius:8,background:c?"var(--bg-selected)":"var(--bg-panel)",padding:10},children:[(0,d.jsxs)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:10},children:[(0,d.jsx)("span",{style:{minWidth:42,height:28,padding:"0 7px",display:"inline-flex",alignItems:"center",justifyContent:"center",borderRadius:6,border:"1px solid rgba(37,99,235,0.28)",background:"rgba(37,99,235,0.08)",color:"var(--accent)",fontSize:11,fontWeight:800,fontFamily:"var(--font-mono)",flexShrink:0},children:[...new Set(a.kernels.map(a=>"r"===a.language?"R":"Python"))].join(" + ")}),(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:8,minWidth:0},children:[(0,d.jsx)("span",{style:{fontSize:15,fontWeight:760,color:c?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums",flexShrink:0},children:dN(a.totalBytes)}),(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:a.sessionId??void 0,children:c?"Current session":"session"===a.kind?`Session ${(b=a.sessionId)?b.slice(0,8):"untracked"}`:"Unattributed kernel"})]}),(0,d.jsxs)("div",{style:{marginTop:4,display:"flex",alignItems:"center",gap:8,minWidth:0,color:"var(--text-dim)",fontSize:11},children:[(0,d.jsx)("span",{title:a.cwd??void 0,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(a){if(!a)return"Unknown project";let b=a.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean);return b[b.length-1]||a}(a.cwd)}),(0,d.jsxs)("span",{title:`pid ${f}`,style:{flexShrink:0},children:["pid ",f]}),(0,d.jsx)("span",{style:{flexShrink:0},children:function(a){if(!a)return"activity unknown";let b=new Date(a).getTime();if(!Number.isFinite(b))return"activity unknown";let c=Math.floor(Math.max(0,Date.now()-b)/6e4);if(c<1)return"active now";if(c<60)return`${c}m idle`;let d=Math.floor(c/60);return d<24?`${d}h idle`:`${Math.floor(d/24)}d idle`}(a.lastActivity)})]}),(0,d.jsx)("div",{title:a.cwd??void 0,style:{marginTop:3,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(a){if(!a)return"-";let b=a.replace(/\/+$/,"").replace(/^\/(?:Users|home)\/[^/]+/,"~");if(b.length<=44)return b;let c=b.split("/").filter(Boolean);return c.length<=2?b:`${b.startsWith("/")?"/":""}${c[0]}/.../${c[c.length-1]}`}(a.cwd)})]})]}),(0,d.jsx)("button",{type:"button",onClick:()=>{window.confirm("Release this Workbench runtime?\n\nWarm variables and loaded data will be cleared. Saved files and chat history stay.")&&m(a.kernels)},disabled:e,title:"Release this Workbench runtime",style:{...dR,justifySelf:p?"stretch":"end",opacity:e?.55:1,cursor:e?"not-allowed":"pointer"},children:e?"Releasing...":"Release"})]},a.id)})})]},a.id))})})]})})}function dT({initialWidth:a,minWidth:b,maxWidth:c,storageKey:d,direction:f="right"}){let[g,h]=(0,e.useState)(a),[i,j]=(0,e.useState)(!1),k=(0,e.useRef)(a),l=(0,e.useCallback)(a=>{let e=Math.max(b,Math.min(c,a));h(e),k.current=e,document.documentElement.style.setProperty(d,`${e}px`)},[b,c,d]),m=(0,e.useCallback)(()=>{j(!0)},[]),n=(0,e.useCallback)(a=>{let b="left"===f?-1:1;l(k.current+a*b)},[l,f]);return{beginResize:m,endResize:(0,e.useCallback)(()=>{j(!1);try{localStorage.setItem(d,String(k.current))}catch{}},[d]),isResizing:i,resizeBy:n,width:g,widthRef:k}}function dU(a,b){return a.length<=b?a:`${a.slice(0,b)}
45
- ...`}function dV(a){return[`Explain this Workbench artifact: ${a.path}`,`Generated by cell #${a.provenance.cellIndex}: ${a.provenance.title}`,`Status: ${a.provenance.status}`,`Runtime: ${a.provenance.runtime??"unknown"}; language: ${a.provenance.language}`,"","Code:","```",dU(a.provenance.code,4e3),"```",a.provenance.stdoutPreview?`
23
+ ${e}`)},[P,aA]);return K?(0,d.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:"Loading session..."}):L?(0,d.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:L}):(0,d.jsxs)("div",{className:"relative flex h-full flex-col overflow-hidden",onDragEnter:aT,onDragOver:aU,onDragLeave:aV,onDrop:aW,children:[aS&&(0,d.jsxs)("div",{className:"pointer-events-none absolute inset-0 z-50 flex animate-[drop-zone-in_0.15s_ease_both] items-center justify-center bg-[rgba(37,99,235,0.06)] backdrop-blur-[1px]",children:[(0,d.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:[0,.8,1.6].map(a=>(0,d.jsx)("div",{className:"absolute h-[720px] w-[720px] rounded-full border-[1.5px] border-solid border-[rgba(37,99,235,0.5)] animate-[drop-ripple_2.4s_ease-out_infinite_backwards]",style:{transformOrigin:"center",animationDelay:`${a}s`}},a))}),(0,d.jsxs)("svg",{width:"280",height:"280",viewBox:"0 0 140 140",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"drop-shadow-[0_6px_18px_rgba(37,99,235,0.18)]",children:[(0,d.jsx)("rect",{x:"28",y:"44",width:"84",height:"60",rx:"8",fill:"rgba(37,99,235,0.08)",stroke:"rgba(37,99,235,0.50)",strokeWidth:"1.8"}),(0,d.jsx)("path",{d:"M36 100 L54 72 L68 88 L80 74 L104 100Z",fill:"rgba(37,99,235,0.16)",stroke:"rgba(37,99,235,0.40)",strokeWidth:"1.4",strokeLinejoin:"round"}),(0,d.jsx)("circle",{cx:"96",cy:"58",r:"8",fill:"rgba(37,99,235,0.22)",stroke:"rgba(37,99,235,0.55)",strokeWidth:"1.6"}),(0,d.jsxs)("g",{stroke:"rgba(37,99,235,0.45)",strokeWidth:"1.4",strokeLinecap:"round",children:[(0,d.jsx)("line",{x1:"96",y1:"46",x2:"96",y2:"43"}),(0,d.jsx)("line",{x1:"96",y1:"70",x2:"96",y2:"73"}),(0,d.jsx)("line",{x1:"84",y1:"58",x2:"81",y2:"58"}),(0,d.jsx)("line",{x1:"108",y1:"58",x2:"111",y2:"58"}),(0,d.jsx)("line",{x1:"87.5",y1:"49.5",x2:"85.4",y2:"47.4"}),(0,d.jsx)("line",{x1:"104.5",y1:"66.5",x2:"106.6",y2:"68.6"}),(0,d.jsx)("line",{x1:"104.5",y1:"49.5",x2:"106.6",y2:"47.4"}),(0,d.jsx)("line",{x1:"87.5",y1:"66.5",x2:"85.4",y2:"68.6"})]})]})]}),!a8&&(0,d.jsx)(ad,{sessionKind:bf,toolPreset:W,initialSourcePath:J?.sessionMeta?.initialSourcePath??null,initialKernel:J?.sessionMeta?.initialKernel??null,isNew:as,isStreaming:P,onResume:bc,onDismiss:()=>a9(!0)}),a2?(0,d.jsx)("div",{className:"flex flex-1 flex-col items-center justify-center overflow-y-auto px-4 py-8",children:(0,d.jsxs)("div",{className:"w-full max-w-[820px]",children:[(0,d.jsxs)("div",{className:"mb-3",style:{display:"flex",flexDirection:"column",alignItems:"stretch",justifyContent:"flex-start",gap:10,marginLeft:16,marginRight:16,fontFamily:"var(--font-mono)"},children:[a4&&(0,d.jsxs)("div",{style:{padding:a5?"7px 9px":"9px 12px",border:"1px solid var(--border)",borderRadius:a5?9:10,background:"linear-gradient(180deg, var(--bg-panel), rgba(127,127,127,0.03))",minWidth:0,display:"flex",alignItems:"flex-start",gap:a5?8:10,boxShadow:a5?"0 2px 10px rgba(0,0,0,0.04)":"none"},children:[(0,d.jsx)("div",{"aria-hidden":!0,style:{flex:"0 0 auto",width:a5?18:20,height:a5?18:20,borderRadius:6,marginTop:1,background:"rgba(37,99,235,0.10)",border:"1px solid rgba(37,99,235,0.20)",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--accent)"},children:(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M3 7.5 12 4l9 3.5-9 3.5-9-3.5Z"}),(0,d.jsx)("path",{d:"M7 10v4.5c0 .8 2.2 2 5 2s5-1.2 5-2V10"})]})}),(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsx)("div",{style:{fontSize:9,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.08em",marginBottom:2},children:"Current Project"}),(0,d.jsx)("div",{style:{fontSize:a5?12.5:14,color:"var(--text)",fontWeight:700,lineHeight:1.3,wordBreak:"break-word"},children:a4}),a3&&(0,d.jsx)("div",{title:a3,style:{fontSize:10.5,color:"var(--text-dim)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a3})]})]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10,minWidth:0,flex:1,lineHeight:1.4},children:[(0,d.jsx)("span",{style:{fontSize:23,color:"var(--text)",fontWeight:750,letterSpacing:0},children:l}),(0,d.jsx)("span",{style:{fontSize:14,minWidth:0,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:(0,d.jsx)(am,{phrases:al})})]})]}),bk]})}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{className:"relative flex flex-1 overflow-hidden",children:[(0,d.jsx)("div",{ref:ay,className:"flex-1 overflow-y-auto pt-4 [scrollbar-width:none]",children:(0,d.jsxs)("div",{className:"mx-auto max-w-[820px] px-4",style:a5?{paddingBottom:"calc(env(safe-area-inset-bottom, 0px) + 128px)"}:void 0,children:[(0,d.jsx)(aj,{goal:J?.sessionMeta?.goal??null,planTasks:x,isRunning:P,onExecutePlan:v&&x.length>0?bn:void 0,onContinuePlanning:v&&x.length>0?bl:void 0,onEditPlan:v&&x.length>0?bm:void 0}),(()=>{let c=-1;for(let a=M.length-1;a>=0;a--)if("user"===M[a].role){c=a;break}let e=0;return(0,d.jsxs)(d.Fragment,{children:[au&&M.length>0&&(0,d.jsx)("div",{style:{textAlign:"center",padding:"8px 0 4px"},children:(0,d.jsxs)("button",{onClick:()=>at(),style:{padding:"6px 16px",fontSize:11,color:"var(--accent)",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,cursor:"pointer",transition:"background 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="var(--bg-panel)"},children:["Load ",av-aw," earlier message",av-aw==1?"":"s"]})}),M.map((f,g)=>{let h="user"===f.role&&g>0&&"assistant"===M[g-1].role?N[g-1]:void 0,j="user"===f.role||"assistant"===f.role,k=j?e++:-1,l=!1;if("assistant"===f.role){l=!0;for(let a=g+1;a<M.length;a++){let b=M[a].role;if("user"===b)break;if("assistant"===b){l=!1;break}}l&&O.isStreaming&&g===M.length-1&&(l=!1)}let m=(0,d.jsx)(B.D,{message:f,toolResults:a1,modelNames:Q,entryId:N[g],onFork:P||as||0===g&&"user"===f.role?void 0:aC,forking:ab===N[g],onNavigate:P?void 0:aD,prevAssistantEntryId:P?void 0:h,onEditContent:a=>i?.current?.insertIfEmpty(a),onSendMessage:bo,showTimestamp:l,prevTimestamp:g>0?M[g-1].timestamp:void 0,renderVisualCodeBlocks:!!o,cwd:J?.info?.cwd??a?.cwd??b??void 0,onOpenImage:aR,activeFilePath:H,agentRunning:P,onApplyToFile:bp,onRunCode:bq,onOpenFileAtLine:q,onAcceptDiff:br},g);return j?(0,d.jsx)("div",{ref:a=>{a0.current[k]=a,g===c&&(az.current=a)},style:{contentVisibility:"auto",containIntrinsicSize:"auto 100px"},children:m},g):m})]})})(),P&&(0,d.jsx)(ah,{agentPhase:aq,startedAt:t}),O.isStreaming&&O.streamingMessage&&(0,d.jsx)(B.D,{message:O.streamingMessage,isStreaming:!0,toolResults:a1,modelNames:Q,onSendMessage:bo,renderVisualCodeBlocks:!!o,cwd:J?.info?.cwd??a?.cwd??b??void 0,activeFilePath:H,agentRunning:P,onApplyToFile:bp,onRunCode:bq,onOpenFileAtLine:q,onAcceptDiff:br}),P&&!O.streamingMessage&&(0,d.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,d.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:function(a){if(a?.kind==="running_tools"){let b=a.tools.map(a=>a.name);return 0===b.length?"Running tool...":1===b.length?`Running ${b[0]}...`:b.length<=3?`Running ${b.join(", ")}...`:`Running ${b.slice(0,2).join(", ")} (+${b.length-2})...`}return a?.kind==="waiting_model"?"Waiting for model...":"Thinking..."}(aq)})}),J?.info?.cwd&&!1===J.info.cwdExists&&(0,d.jsxs)("div",{className:"my-3 rounded-[7px] border border-[rgba(248,113,113,0.35)] bg-[rgba(248,113,113,0.07)] px-3 py-2 text-[12px] leading-relaxed text-red-400",children:["Project directory no longer exists: ",(0,d.jsx)("code",{className:"font-mono",children:J.info.cwd})]}),ar&&(0,d.jsx)("div",{className:"my-3 rounded-[7px] border border-[rgba(248,113,113,0.35)] bg-[rgba(248,113,113,0.07)] px-3 py-2 text-[12px] leading-relaxed text-red-400",children:ar}),P&&(0,d.jsx)("div",{style:{height:ay.current?ay.current.clientHeight:"80vh"}}),(0,d.jsx)("div",{ref:ax})]})}),!a5&&(0,d.jsx)(U,{messages:M,streamingMessage:O.streamingMessage,scrollContainer:ay,messageRefs:a0}),ba.length>0&&(0,d.jsxs)("button",{onClick:()=>a7(a=>!a),title:a6?"Hide subagent runs":"Show subagent runs",style:{position:"absolute",right:a5?8:a6?260:40,top:8,minWidth:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:bb>0||ba.length>1?"0 8px":0,background:a6?"var(--bg-selected)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:a6?"var(--accent)":"var(--text-dim)",cursor:"pointer",zIndex:30,fontSize:12,transition:"right 0.2s ease, background 0.12s"},onMouseEnter:a=>{a6||(a.currentTarget.style.color="var(--text)")},onMouseLeave:a=>{a6||(a.currentTarget.style.color="var(--text-dim)")},children:[(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,d.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,d.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,d.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),(bb>0||ba.length>1)&&(0,d.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,fontSize:10,fontWeight:700,color:bb>0?"var(--accent)":"var(--text-dim)"},children:[bb>0&&(0,d.jsxs)("span",{children:[bb," active"]}),(0,d.jsx)("span",{children:ba.length})]})]}),a6&&ba.length>0&&(0,d.jsxs)("div",{style:{position:"absolute",right:a5?8:48,top:4,bottom:4,width:a5?"calc(100vw - 16px)":250,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"-2px 0 12px rgba(0,0,0,0.08)",zIndex:25,overflow:"hidden"},children:[(0,d.jsx)("div",{style:{padding:"6px 12px",fontSize:11,fontWeight:600,color:"var(--text-dim)",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Subagents"}),(0,d.jsx)($,{runs:ba})]})]}),(0,d.jsx)("div",{className:"relative",children:bk})]}),aZ&&(0,d.jsxs)("div",{style:{position:"fixed",inset:0,zIndex:100,background:"rgba(0,0,0,0.85)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"zoom-out"},onClick:()=>a$(null),children:[aZ.gallery&&aZ.gallery.length>1&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("button",{style:{position:"absolute",left:16,top:"50%",transform:"translateY(-50%)",background:"rgba(255,255,255,0.15)",border:"none",borderRadius:8,color:"#fff",fontSize:28,width:44,height:44,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:101},onClick:a=>{a.stopPropagation();let b=((aZ.index??0)-1+aZ.gallery.length)%aZ.gallery.length;a$({...aZ,src:aZ.gallery[b].src,index:b})},children:"←"}),(0,d.jsx)("button",{style:{position:"absolute",right:16,top:"50%",transform:"translateY(-50%)",background:"rgba(255,255,255,0.15)",border:"none",borderRadius:8,color:"#fff",fontSize:28,width:44,height:44,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",zIndex:101},onClick:a=>{a.stopPropagation();let b=((aZ.index??0)+1)%aZ.gallery.length;a$({...aZ,src:aZ.gallery[b].src,index:b})},children:"→"})]}),(0,d.jsx)("img",{src:aZ.src,alt:"",style:{maxWidth:"95vw",maxHeight:"95vh",objectFit:"contain",borderRadius:8,boxShadow:"0 8px 40px rgba(0,0,0,0.5)"}}),(0,d.jsx)("div",{style:{position:"absolute",bottom:16,left:"50%",transform:"translateX(-50%)",background:"rgba(0,0,0,0.5)",color:"rgba(255,255,255,0.7)",borderRadius:6,padding:"4px 12px",fontSize:12},children:aZ.gallery&&aZ.gallery.length>1?`${(aZ.index??0)+1} / ${aZ.gallery.length}`:"Click anywhere to close"})]})]})}var ap=c(90707),aq=c(52515);class ar extends f().Component{static getDerivedStateFromError(a){return{hasError:!0,message:a instanceof Error?a.message:String(a)}}componentDidCatch(a,b){console.error("File viewer crashed",{filePath:this.props.filePath,error:a,componentStack:b.componentStack})}componentDidUpdate(a){a.filePath!==this.props.filePath&&this.state.hasError&&this.setState({hasError:!1,message:null})}render(){return this.state.hasError?(0,d.jsx)(aq.fj,{style:{background:"var(--bg)"},children:(0,d.jsx)(aq.nG,{tone:"error",children:(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,alignItems:"center",textAlign:"center"},children:[(0,d.jsx)("div",{children:"Preview crashed for this file."}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",maxWidth:560,wordBreak:"break-word"},children:this.props.filePath}),this.state.message&&(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",maxWidth:560,wordBreak:"break-word"},children:this.state.message})]})})}):this.props.children}constructor(...a){super(...a),this.state={hasError:!1,message:null}}}function as(a,b,c){return Math.min(Math.max(a,b),c)}function at({id:a,filePath:b,fileName:c,cwd:f,active:g,stackIndex:h,zIndex:i,onClose:j,onFocus:k,onOpenFile:l}){let[m,n]=(0,e.useState)(()=>{let a,b,c;return b=Math.max(320,1208-(a=h%6*28)),c=Math.max(260,828-a),{left:36+a,top:36+a,width:Math.min(1180,b),height:Math.min(820,c),maximized:!1}}),[o,p]=(0,e.useState)(!1),[q,r]=(0,e.useState)(!1),s=(0,e.useRef)(null),t=(0,e.useRef)(null),u=(0,e.useRef)(null),v=(0,e.useCallback)(b=>{k(a),0!==b.button||m.maximized||(b.preventDefault(),b.currentTarget.setPointerCapture(b.pointerId),t.current={pointerId:b.pointerId,startX:b.clientX,startY:b.clientY,left:m.left,top:m.top},p(!0))},[m.left,m.maximized,m.top,a,k]),w=(0,e.useCallback)(a=>{let b=t.current;if(!b||b.pointerId!==a.pointerId)return;let c=b.left+a.clientX-b.startX,d=b.top+a.clientY-b.startY;n(a=>({...a,left:as(c,8,Math.max(8,window.innerWidth-120)),top:as(d,8,Math.max(8,window.innerHeight-48))}))},[]),x=(0,e.useCallback)(a=>{let b=t.current;b?.pointerId===a.pointerId&&(a.currentTarget.releasePointerCapture(a.pointerId),t.current=null,p(!1))},[]),y=(0,e.useCallback)(()=>{k(a),n(a=>({...a,maximized:!a.maximized}))},[a,k]),z=(0,e.useCallback)(b=>{k(a),0!==b.button||m.maximized||(b.preventDefault(),b.stopPropagation(),b.currentTarget.setPointerCapture(b.pointerId),u.current={pointerId:b.pointerId,startX:b.clientX,startY:b.clientY,width:m.width,height:m.height},r(!0))},[m.height,m.maximized,m.width,a,k]),A=(0,e.useCallback)(a=>{let b=u.current;if(!b||b.pointerId!==a.pointerId)return;let c=b.width+a.clientX-b.startX,d=b.height+a.clientY-b.startY;n(a=>({...a,width:as(c,360,Math.max(360,window.innerWidth-a.left-8)),height:as(d,280,Math.max(280,window.innerHeight-a.top-8))}))},[]),B=(0,e.useCallback)(a=>{let b=u.current;b?.pointerId===a.pointerId&&(a.currentTarget.releasePointerCapture(a.pointerId),u.current=null,r(!1))},[]),C=m.maximized?{position:"fixed",inset:12,zIndex:i}:{position:"fixed",left:m.left,top:m.top,width:m.width,height:m.height,zIndex:i};return(0,d.jsxs)("div",{ref:s,role:"dialog","aria-label":`Preview ${c}`,tabIndex:-1,onPointerDown:()=>k(a),onKeyDown:b=>{"Escape"===b.key&&j(a)},style:{...C,display:"flex",flexDirection:"column",minWidth:m.maximized?void 0:360,minHeight:m.maximized?void 0:280,background:"var(--bg)",border:g?"1px solid rgba(37,99,235,0.55)":"1px solid var(--border)",borderRadius:8,boxShadow:g?"0 18px 60px rgba(0,0,0,0.26)":"0 10px 34px rgba(0,0,0,0.20)",overflow:"hidden",outline:"none"},children:[(0,d.jsxs)("div",{onPointerDown:v,onPointerMove:w,onPointerUp:x,onPointerCancel:x,style:{height:34,display:"flex",alignItems:"center",gap:8,padding:"0 8px 0 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",cursor:m.maximized?"default":o?"grabbing":"grab",flexShrink:0,userSelect:"none"},children:[(0,d.jsx)("div",{style:{minWidth:0,flex:1},children:(0,d.jsx)("div",{title:b,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontWeight:650,color:"var(--text)"},children:c})}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:y,title:m.maximized?"Restore preview":"Maximize preview","aria-label":m.maximized?"Restore preview":"Maximize preview",style:au,children:m.maximized?(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,d.jsx)("path",{d:"M6 3.5h6.5V10"}),(0,d.jsx)("path",{d:"M3.5 6H10v6.5H3.5z"})]}):(0,d.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,d.jsx)("path",{d:"M4 4h8v8H4z"})})}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:()=>j(a),title:"Close preview","aria-label":"Close preview",style:au,children:(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round","aria-hidden":"true",children:[(0,d.jsx)("line",{x1:"4",y1:"4",x2:"12",y2:"12"}),(0,d.jsx)("line",{x1:"12",y1:"4",x2:"4",y2:"12"})]})})]}),(0,d.jsx)("div",{style:{flex:1,minHeight:0,overflow:"hidden",background:"var(--bg)"},children:(0,d.jsx)(ar,{filePath:b,children:(0,d.jsx)(ap.h,{filePath:b,cwd:f,onOpenFile:l})})}),!m.maximized&&(0,d.jsx)("div",{role:"separator","aria-orientation":"horizontal","aria-label":"Resize preview",title:"Resize preview",onPointerDown:z,onPointerMove:A,onPointerUp:B,onPointerCancel:B,style:{position:"absolute",right:0,bottom:0,width:18,height:18,cursor:"nwse-resize",color:"var(--text-dim)",display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:3,background:"linear-gradient(135deg, transparent 0 48%, rgba(127,127,127,0.18) 48% 52%, transparent 52% 100%)"}})]})}let au={width:26,height:24,padding:0,border:"1px solid transparent",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0};function av(a){return{dirCache:new Map,pathIndex:new Map,loadedDirs:new Set,revision:0,workspaceRoot:a}}function aw(a,b){if(b.delete(a.path),a.children)for(let c of a.children)aw(c,b)}function ax(a,b,c){let d=new Map;if(b)for(let a of b)d.set(a.path,a);if(b){let d=new Set(a.map(a=>a.path));for(let a of b)d.has(a.path)||aw(a,c)}return a.map(a=>{let b=d.get(a.path);return b&&(a.id=b.id,b.childrenLoaded&&b.children?(a.children=b.children,a.childrenLoaded=!0):b.childrenLoaded&&!b.children&&(a.childrenLoaded=!0)),c.set(a.path,a),a})}function ay(a,b,c){let d=ax(c,a.dirCache.get(b),a.pathIndex);a.dirCache.set(b,d),a.loadedDirs.add(b)}function az(a,b,c){let d=a.dirCache.get(b);if(!d)return;let e=d.findIndex(a=>a.path===c.path);if(-1!==e){let a=d[e];"folder"===a.type&&"folder"===c.type&&(c.children=a.children,c.childrenLoaded=a.childrenLoaded),d[e]=c}else d.push(c),d.sort(aB);a.pathIndex.set(c.path,c)}function aA(a,b,c){let d=a.dirCache.get(b);d&&a.dirCache.set(b,d.filter(a=>a.path!==c));let e=a.pathIndex.get(c);e&&aw(e,a.pathIndex),a.dirCache.delete(c),a.loadedDirs.delete(c)}function aB(a,b){return"folder"===a.type&&"folder"!==b.type?-1:"folder"!==a.type&&"folder"===b.type?1:a.name.localeCompare(b.name)}let aC=new Set(["node_modules","vendor","venv",".venv","Pods","dist","build","out","target",".output","bin","obj",".next",".nuxt",".cache",".turbo",".parcel-cache",".git",".svn",".hg",".idea",".vscode",".vs","coverage",".nyc_output","__pycache__",".pytest_cache",".mypy_cache",".tox","logs","tmp","temp",".annodex-uploads"]),aD="var(--text-dim)";function aE({size:a=14,open:b=!1}){return b?(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 16 16",fill:"none",children:[(0,d.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5h7.5v1H1V4.5Z",fill:aD}),(0,d.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:aD,strokeWidth:"1",fill:aD,fillOpacity:"0.12"})]}):(0,d.jsx)("svg",{width:a,height:a,viewBox:"0 0 16 16",fill:"none",children:(0,d.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5H14a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4.5Z",stroke:aD,strokeWidth:"1",fill:aD,fillOpacity:"0.1"})})}function aF({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 16 16",fill:"none",children:[(0,d.jsx)("path",{d:"M3 2h7l3 3v9H3V2Z",stroke:aD,strokeWidth:"1",fill:aD,fillOpacity:"0.08"}),(0,d.jsx)("path",{d:"M10 2v3h3",stroke:aD,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function aG({label:a,size:b=14}){let c=b/14;return(0,d.jsxs)("svg",{width:b,height:b,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:aD,strokeWidth:"0.9",fill:aD,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aD,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("text",{x:"7",y:"9.5",textAnchor:"middle",fontSize:3.4*c,fontFamily:"var(--font-mono), monospace",fontWeight:"600",fill:aD,letterSpacing:"0",children:a})]})}function aH({size:a=14}){return(0,d.jsx)(aG,{label:"TS",size:a})}function aI({size:a=14}){return(0,d.jsx)(aG,{label:"TSX",size:a})}function aJ({size:a=14}){return(0,d.jsx)(aG,{label:"JS",size:a})}function aK({size:a=14}){return(0,d.jsx)(aG,{label:"JSX",size:a})}function aL({size:a=14}){return(0,d.jsx)(aG,{label:"PY",size:a})}function aM({size:a=14}){return(0,d.jsx)(aG,{label:"{}",size:a})}function aN({size:a=14}){return(0,d.jsx)(aG,{label:"CSS",size:a})}function aO({size:a=14}){return(0,d.jsx)(aG,{label:"SC",size:a})}function aP({size:a=14}){return(0,d.jsx)(aG,{label:"HTM",size:a})}function aQ({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:aD,strokeWidth:"0.9",fill:aD,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aD,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:aD,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,d.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:aD,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function aR({size:a=14}){return(0,d.jsx)(aG,{label:"YML",size:a})}function aS({size:a=14}){return(0,d.jsx)(aG,{label:"TOM",size:a})}function aT({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:aD,strokeWidth:"0.9",fill:aD,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aD,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:aD,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,d.jsx)("path",{d:"M7.5 10.5h2.5",stroke:aD,strokeWidth:"0.95",strokeLinecap:"round"})]})}function aU({size:a=14}){return(0,d.jsx)(aG,{label:"RS",size:a})}function aV({size:a=14}){return(0,d.jsx)(aG,{label:"GO",size:a})}function aW({size:a=14}){return(0,d.jsx)(aG,{label:"SQL",size:a})}function aX({size:a=14}){return(0,d.jsx)(aG,{label:"GQL",size:a})}function aY({size:a=14}){return(0,d.jsx)(aG,{label:"TF",size:a})}function aZ({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:aD,strokeWidth:"0.9",fill:aD,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aD,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("rect",{x:"3.5",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:aD,strokeWidth:"0.8"}),(0,d.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:aD,strokeWidth:"0.8"}),(0,d.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:aD,strokeWidth:"0.8"})]})}function a$({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:aD,strokeWidth:"0.9",fill:aD,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aD,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:aD,strokeWidth:"0.9"}),(0,d.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:aD,strokeWidth:"0.9",strokeLinecap:"round"})]})}function a_({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:aD,strokeWidth:"0.9",fill:aD,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aD,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:aD,strokeWidth:"0.85"}),(0,d.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:aD,strokeWidth:"0.85"}),(0,d.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:aD,strokeWidth:"0.85"}),(0,d.jsx)("path",{d:"M5 7.5V9",stroke:aD,strokeWidth:"0.85",strokeLinecap:"round"}),(0,d.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:aD,strokeWidth:"0.85",strokeLinecap:"round",fill:"none"})]})}function a0({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:aD,strokeWidth:"0.9",fill:aD,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aD,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("rect",{x:"4.5",y:"8.5",width:"5",height:"3",rx:"0.6",stroke:aD,strokeWidth:"0.9"}),(0,d.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:aD,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}function a1({size:a=14}){return(0,d.jsxs)("svg",{width:a,height:a,viewBox:"0 0 14 14",fill:"none",children:[(0,d.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:aD,strokeWidth:"0.9",fill:aD,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aD,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:aD,strokeWidth:"0.9"}),(0,d.jsx)("path",{d:"M7 6.5v.7M7 10.3v.7M5 8.5h.7M8.3 8.5H9M5.5 6.9l.5.5M8.5 9.6l-.5-.5M5.5 10.1l.5-.5M8.5 7.4l-.5.5",stroke:aD,strokeWidth:"0.8",strokeLinecap:"round"})]})}function a2(a,b=14){let c=a.toLowerCase(),e=c.split(".").pop()??"";if("dockerfile"===c||c.startsWith("dockerfile."))return(0,d.jsx)(aZ,{size:b});if(".env"===c||c.startsWith(".env."))return(0,d.jsx)(a$,{size:b});if(".gitignore"===c||".gitattributes"===c||".gitmodules"===c)return(0,d.jsx)(a_,{size:b});if("package-lock.json"===c||"yarn.lock"===c||"bun.lock"===c||"pnpm-lock.yaml"===c||"cargo.lock"===c)return(0,d.jsx)(a0,{size:b});if(c.endsWith(".config.ts")||c.endsWith(".config.js")||c.endsWith(".config.mjs")||c.endsWith(".config.cjs")||[".eslintrc",".eslintrc.js",".eslintrc.json",".eslintrc.yml","eslint.config.mjs","eslint.config.js"].includes(c))return(0,d.jsx)(a1,{size:b});switch(e){case"ts":return(0,d.jsx)(aH,{size:b});case"tsx":return(0,d.jsx)(aI,{size:b});case"js":case"mjs":case"cjs":return(0,d.jsx)(aJ,{size:b});case"jsx":return(0,d.jsx)(aK,{size:b});case"py":return(0,d.jsx)(aL,{size:b});case"json":case"jsonl":return(0,d.jsx)(aM,{size:b});case"css":case"less":return(0,d.jsx)(aN,{size:b});case"scss":return(0,d.jsx)(aO,{size:b});case"html":case"htm":return(0,d.jsx)(aP,{size:b});case"md":case"mdx":return(0,d.jsx)(aQ,{size:b});case"yaml":case"yml":return(0,d.jsx)(aR,{size:b});case"toml":return(0,d.jsx)(aS,{size:b});case"sh":case"bash":case"zsh":case"fish":return(0,d.jsx)(aT,{size:b});case"rs":return(0,d.jsx)(aU,{size:b});case"go":return(0,d.jsx)(aV,{size:b});case"sql":return(0,d.jsx)(aW,{size:b});case"graphql":case"gql":return(0,d.jsx)(aX,{size:b});case"tf":case"hcl":return(0,d.jsx)(aY,{size:b});case"lock":return(0,d.jsx)(a0,{size:b});default:return(0,d.jsx)(aF,{size:b})}}let a3=f().memo(function({node:a,depth:b,isExpanded:c,isLoading:g,isSelected:h,isRenaming:i,isUploadTarget:j,onClick:k,onDoubleClick:l,onContextMenu:m,onRenameSubmit:n,onRenameCancel:o,onDragEnter:p,onDragOver:q,onDragLeave:r,onDrop:s}){var t;let u=!!(t=a.name).startsWith(".")||aC.has(t),[v,w]=f().useState(!1),[x,y]=f().useState(a.name),z=f().useRef(null);f().useEffect(()=>{if(i&&z.current){let b=a.name.lastIndexOf(".");"file"===a.type&&b>0?z.current.setSelectionRange(0,b):z.current.select(),z.current.focus()}},[i,a.name,a.type]);let A=(0,e.useCallback)(()=>{i||k(a.path,"folder"===a.type)},[i,a.path,a.type,k]),B=(0,e.useCallback)(()=>{i||l(a.path)},[i,a.path,l]),C=(0,e.useCallback)(b=>{i||m(b,a.path)},[i,a.path,m]),D=(0,e.useCallback)(b=>{if("Enter"===b.key){b.preventDefault();let c=x.trim();c&&c!==a.name?n(a.path,c):o()}else"Escape"===b.key&&(b.preventDefault(),o())},[x,a.name,a.path,n,o]),E=(0,e.useCallback)(()=>{let b=x.trim();b&&b!==a.name?n(a.path,b):o()},[x,a.name,a.path,n,o]);return(0,d.jsxs)("div",{onClick:A,onDoubleClick:B,onContextMenu:C,onMouseEnter:()=>w(!0),onMouseLeave:()=>w(!1),onDragEnter:p,onDragOver:q,onDragLeave:r,onDrop:s,style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*b,paddingRight:8,height:26,cursor:"pointer",background:j?"rgba(37,99,235,0.14)":h?"var(--bg-selected)":v?"var(--bg-hover)":"transparent",outline:j?"1px solid rgba(37,99,235,0.42)":"none",outlineOffset:-1,borderRadius:4,userSelect:"none",transition:"background 0.08s",opacity:u?.65:1},children:["folder"===a.type?(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:c?"rotate(90deg)":"none",transition:"transform 0.1s"},children:(0,d.jsx)("polyline",{points:"3 2 7 5 3 8"})}):(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),g?(0,d.jsx)("span",{style:{flexShrink:0,width:14,height:14,display:"flex",alignItems:"center"},children:(0,d.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",style:{animation:"spin 1s linear infinite"},children:(0,d.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})})}):(0,d.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:"folder"===a.type?(0,d.jsx)(aE,{size:14,open:c}):a2(a.name,14)}),i?(0,d.jsx)("input",{ref:z,value:x,onChange:a=>y(a.target.value),onKeyDown:D,onBlur:E,style:{flex:1,minWidth:0,height:22,padding:"0 4px",fontSize:12,fontFamily:"inherit",color:"var(--text)",background:"var(--bg-input, var(--bg))",border:"1px solid var(--accent)",borderRadius:3,outline:"none"},onClick:a=>a.stopPropagation(),onDoubleClick:a=>a.stopPropagation(),onContextMenu:a=>a.stopPropagation()}):(0,d.jsx)("span",{style:{fontSize:12,color:u?"var(--text-dim)":"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:a.path,children:a.name})]})});function a4({x:a,y:b,actions:c,onClose:g}){let h=(0,e.useRef)(null),[i,j]=f().useState(a),[k,l]=f().useState(b);return 0===c.length?null:(0,d.jsx)("div",{ref:h,style:{position:"fixed",left:i,top:k,zIndex:1e3,minWidth:190,padding:"4px 0",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:8,boxShadow:"0 8px 24px rgba(0,0,0,0.18)",fontSize:12},children:c.map((a,b)=>(0,d.jsxs)(f().Fragment,{children:[a.separator&&b>0&&(0,d.jsx)("div",{style:{height:1,margin:"4px 8px",background:"var(--border)"}}),(0,d.jsxs)("div",{onClick:b=>{b.stopPropagation(),a.onClick(),g()},style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 12px",cursor:"pointer",color:a.danger?"#ef4444":"var(--text)"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="transparent"},children:[(0,d.jsx)("span",{children:a.label}),a.shortcut&&(0,d.jsx)("span",{style:{marginLeft:24,fontSize:10,color:"var(--text-dim)"},children:a.shortcut})]})]},b))})}var a5=c(31343);async function a6(a){let b=(0,a5.HG)(a),c=await fetch(`/api/files/${b}?type=list`);return c.ok?(await c.json()).entries??[]:[]}function a7(a,b,c,d){let e=(0,a5.e_)(b,a.name);return{id:e,name:a.name,path:e,relativePath:(0,a5.qP)(e,c),type:a.isDir?"folder":"file",extension:a.isDir?"":a.name.includes(".")?a.name.split(".").pop()?.toLowerCase()??"":"",size:a.size,modified:a.modified,depth:d,children:a.isDir?[]:void 0,childrenLoaded:!a.isDir}}function a8(a,b){return a===b?".":(0,a5.qP)(a,b)}function a9(a){return!!Array.from(a.types).includes("Files")||Array.from(a.items).some(a=>"file"===a.kind)}function ba(a){return Array.from(a.files).filter(a=>!!a.name)}function bb({cwd:a,onOpenFile:b,onExploreFile:c,refreshKey:f,onAtMention:g,searchQuery:h=""}){let i,j,k,l,m=function(){let a=(0,e.useRef)(av("")),[b,c]=(0,e.useState)(0),[d,f]=(0,e.useState)(""),[g,h]=(0,e.useState)(!1),[i,j]=(0,e.useState)(!1),[k,l]=(0,e.useState)(new Set),[m,n]=(0,e.useState)(new Set),[o,p]=(0,e.useState)(new Set),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)([]);(0,e.useCallback)(()=>{let b=a.current;t(function a(b,c,d,e){let f=[];for(let g of b){let b="folder"===g.type&&c.has(g.path);if(f.push({node:g,depth:d,isExpanded:b}),b){let b=e.get(g.path)??[];f.push(...a(b,c,d+1,e))}}return f}(b.dirCache.get(b.workspaceRoot)??[],m,0,b.dirCache))},[m]);let u=(0,e.useCallback)(async b=>{h(!1),j(!1);let d=av(b);a.current=d;try{let a=(await a6(b)).map(a=>a7(a,b,b,0));a.sort(aB),ay(d,b,a),f(b),h(!0),c(a=>a+1)}catch{j(!0),h(!0)}},[]),v=(0,e.useCallback)(async b=>{let d=a.current;if(!d.loadedDirs.has(b)){l(a=>new Set(a).add(b));try{let a=(await a6(b)).map(a=>a7(a,b,d.workspaceRoot,0));a.sort(aB),d.loadedDirs.has(b)||(ay(d,b,a),c(a=>a+1))}catch{}finally{l(a=>{let c=new Set(a);return c.delete(b),c})}}},[]),w=(0,e.useCallback)(b=>{n(a=>{let c=new Set(a);return c.has(b)?c.delete(b):c.add(b),c}),a.current.loadedDirs.has(b)||v(b)},[v]),x=(0,e.useCallback)((a,b)=>{p(c=>{if(b){let b=new Set(c);return b.has(a)?b.delete(a):b.add(a),b}return new Set([a])})},[]),y=(0,e.useCallback)(()=>{p(new Set)},[]),z=(0,e.useCallback)(a=>{r(a)},[]),A=(0,e.useCallback)(()=>{r(null)},[]),B=(0,e.useCallback)(async b=>{var c;(c=a.current).dirCache.clear(),c.pathIndex.clear(),c.loadedDirs.clear(),n(new Set),await u(b)},[u]),C=(0,e.useCallback)(b=>a.current.pathIndex.get(b),[]),D=(0,e.useCallback)(b=>a.current.dirCache.get(b),[]),E=(0,e.useCallback)((b,d)=>{az(a.current,b,d),c(a=>a+1)},[]),F=(0,e.useCallback)((b,d,e)=>{let f=a.current,g=f.pathIndex.get(b);if(!g)return;let h=f.workspaceRoot===b?f.workspaceRoot:b.substring(0,Math.max(b.lastIndexOf("/"),b.lastIndexOf("\\")));aA(f,h,b);let i={...g,id:d,name:e,path:d,relativePath:(0,a5.qP)(d,f.workspaceRoot),extension:"file"===g.type&&e.includes(".")?e.split(".").pop()?.toLowerCase()??"":""};az(f,h,i),c(a=>a+1)},[]),G=(0,e.useCallback)(b=>{let d=a.current,e=d.workspaceRoot===b?d.workspaceRoot:b.substring(0,Math.max(b.lastIndexOf("/"),b.lastIndexOf("\\")));aA(d,e,b),c(a=>a+1)},[]);return{revision:b,workspaceRoot:d,hasLoaded:g,loadFailed:i,loadingPaths:k,expandedPaths:m,selectedPaths:o,renamingPath:q,flatNodes:s,loadRoot:u,loadChildren:v,toggleExpand:w,select:x,deselectAll:y,startRename:z,stopRename:A,refresh:B,getNode:C,getChildren:D,onFileCreated:E,onFileRenamed:F,onFileDeleted:G,invalidateDir:(0,e.useCallback)(b=>{let c=a.current;c.loadedDirs.delete(b),c.dirCache.delete(b)},[]),applyWatcherEvent:(0,e.useCallback)(b=>{(function(a,b){let c=!1;for(let{dirPath:d,children:e}of b){if(!a.loadedDirs.has(d))continue;let b=e.map(b=>{let c=d===a.workspaceRoot?`${a.workspaceRoot}/${b.name}`:`${d}/${b.name}`;return{id:c,name:b.name,path:c,relativePath:c.startsWith(a.workspaceRoot+"/")?c.slice(a.workspaceRoot.length+1):b.name,type:b.isDir?"folder":"file",extension:b.isDir?"":b.name.includes(".")?b.name.split(".").pop()?.toLowerCase()??"":"",size:b.size,modified:b.modified,depth:0,children:b.isDir?[]:void 0,childrenLoaded:!b.isDir}});b.sort(aB);let f=ax(b,a.dirCache.get(d),a.pathIndex);a.dirCache.set(d,f),c=!0}return c})(a.current,b)&&c(a=>a+1)},[])}}(),n=(i=(0,e.useCallback)(async(b,c)=>{try{let d=b===a?`${a}/${c}`:`${b}/${c}`,e=await fetch("/api/file-tree/write",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:d,content:""})});if(!e.ok){let a=await e.json().catch(()=>({}));return{success:!1,error:a.error??`HTTP ${e.status}`}}return{success:!0,resolvedPath:d}}catch(a){return{success:!1,error:String(a)}}},[a]),j=(0,e.useCallback)(async(b,c)=>{try{let d=b===a?`${a}/${c}`:`${b}/${c}`,e=await fetch("/api/file-tree/mkdir",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:d})});if(!e.ok){let a=await e.json().catch(()=>({}));return{success:!1,error:a.error??`HTTP ${e.status}`}}return{success:!0,resolvedPath:d}}catch(a){return{success:!1,error:String(a)}}},[a]),k=(0,e.useCallback)(async(b,c)=>{try{let d=Math.max(b.lastIndexOf("/"),b.lastIndexOf("\\")),e=d>0?b.slice(0,d):a,f=`${e}/${c}`,g=await fetch("/api/file-tree/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPath:b,newPath:f})});if(!g.ok){let a=await g.json().catch(()=>({}));return{success:!1,error:a.error??`HTTP ${g.status}`}}return{success:!0,resolvedPath:f}}catch(a){return{success:!1,error:String(a)}}},[a]),l=(0,e.useCallback)(async a=>{try{let b=await fetch("/api/file-tree/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a})});if(!b.ok){let a=await b.json().catch(()=>({}));return{success:!1,error:a.error??`HTTP ${b.status}`}}return{success:!0,resolvedPath:a}}catch(a){return{success:!1,error:String(a)}}},[]),{createFile:i,createFolder:j,renameFile:k,deleteFile:l,moveFile:(0,e.useCallback)(async(a,b)=>{try{let c=a.slice(Math.max(a.lastIndexOf("/"),a.lastIndexOf("\\"))+1),d=`${b}/${c}`,e=await fetch("/api/file-tree/rename",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldPath:a,newPath:d})});if(!e.ok){let a=await e.json().catch(()=>({}));return{success:!1,error:a.error??`HTTP ${e.status}`}}return{success:!0,resolvedPath:d}}catch(a){return{success:!1,error:String(a)}}},[]),revealInFinder:(0,e.useCallback)(async a=>{try{await fetch("/api/file-tree/reveal",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a})})}catch{}},[])}),o=(0,e.useRef)(null);(0,e.useRef)(null);let p=(0,e.useRef)(null),q=(0,e.useRef)(0),[r,s]=(0,e.useState)(!1),[t,u]=(0,e.useState)(null),[v,w]=(0,e.useState)(null),[x,y]=(0,e.useState)(null),[z,A]=(0,e.useState)(-1),[B,C]=(0,e.useState)(null),D=h.trim().length>0,E=(()=>{if(D){let a=m.getChildren(m.workspaceRoot);return a?function a(b,c,d){let e=c.trim().toLowerCase(),f=[];for(let g of b){let b=g.name.toLowerCase().includes(e),h=(g.children??[]).some(a=>(function a(b,c){let d=c.trim().toLowerCase();return!!(!d||b.name.toLowerCase().includes(d))||(b.children??[]).some(b=>a(b,d))})(a,e));(b||h)&&(f.push({node:g,depth:d,isExpanded:!0}),g.children&&h&&f.push(...a(g.children,c,d+1)))}return f}(a,h,0):[]}return m.flatNodes})(),[F,G]=(0,e.useState)(0),[H,I]=(0,e.useState)(0),J=(0,e.useCallback)(a=>{G(a.currentTarget.scrollTop)},[]),K=(0,e.useMemo)(()=>{let a=26*E.length,b=Math.max(0,Math.floor(F/26)-10),c=Math.min(E.length,Math.ceil((F+H)/26)+10),d=[];for(let a=b;a<c;a++)d.push({index:a,top:26*a});return{items:d,totalHeight:a,startIndex:b}},[E,F,H]),L=(0,e.useCallback)((a,c)=>{if(c)m.toggleExpand(a);else{let c=m.getNode(a);c&&b(a,c.name)}m.select(a),A(E.findIndex(b=>b.node.path===a))},[m,b,E]),M=(0,e.useCallback)(a=>{let c=m.getNode(a);c&&"file"===c.type&&b(a,c.name)},[m,b]),N=(0,e.useCallback)((a,b)=>{a.preventDefault(),y({x:a.clientX,y:a.clientY,targetPath:b}),m.select(b),A(E.findIndex(a=>a.node.path===b))},[m,E]),O=(0,e.useMemo)(()=>{if(!x)return[];let b=m.getNode(x.targetPath);if(!b)return[];let d=[{label:"folder"===b.type?"Expand / Collapse":"Open",shortcut:"folder"===b.type?"→":"Enter",onClick:()=>L(b.path,"folder"===b.type)}];return c&&"file"===b.type&&b.name.toLowerCase().endsWith(".h5ad")&&d.push({label:"Explore H5AD",shortcut:"@explore",onClick:()=>c(b.path,b.name)}),g&&d.push({label:"Mention in Chat",shortcut:"@",onClick:()=>g((0,a5.qP)(b.path,a))}),d.push({label:"",onClick:()=>{},separator:!0}),d.push({label:"Rename",shortcut:"F2",onClick:()=>m.startRename(b.path)}),d.push({label:"Delete",shortcut:"Del",onClick:async()=>{if(!window.confirm(`Are you sure you want to delete "${b.name}"?`))return;let a=await n.deleteFile(b.path);a.success?(m.onFileDeleted(b.path),C(`Deleted "${b.name}"`)):a.error&&C(a.error)},danger:!0}),d.push({label:"",onClick:()=>{},separator:!0}),d.push({label:"Copy Path",onClick:()=>{navigator.clipboard.writeText(b.path).catch(()=>{}),C("Copied path")}}),d.push({label:"Copy Relative Path",onClick:()=>{let c=(0,a5.qP)(b.path,a);navigator.clipboard.writeText(c).catch(()=>{}),C("Copied relative path")}}),d.push({label:"Reveal in Finder",onClick:()=>n.revealInFinder(b.path)}),d},[x,m,n,L,g,c,a]),P=(0,e.useCallback)(async(a,b)=>{m.stopRename();let c=m.getNode(a);if(!c||b===c.name)return;let d=await n.renameFile(a,b);d.success&&d.resolvedPath?(m.onFileRenamed(a,d.resolvedPath,b),C(`Renamed to "${b}"`)):d.error&&C(d.error)},[m,n]),Q=(0,e.useCallback)(async()=>{let b=[...m.selectedPaths].map(a=>m.getNode(a)).filter(Boolean),c=b.find(a=>"folder"===a.type)?.path??a,d="untitled.txt",e=await n.createFile(c,d);if(e.success&&e.resolvedPath){let b={id:e.resolvedPath,name:d,path:e.resolvedPath,relativePath:(0,a5.qP)(e.resolvedPath,a),type:"file",extension:"txt",depth:0,childrenLoaded:!0,isOptimistic:!0};m.onFileCreated(c,b),m.expandedPaths.has(c)||m.toggleExpand(c),setTimeout(()=>m.startRename(e.resolvedPath),50)}else e.error&&C(e.error)},[m,n,a]),R=(0,e.useCallback)(async()=>{let b=[...m.selectedPaths].map(a=>m.getNode(a)).filter(Boolean),c=b.find(a=>"folder"===a.type)?.path??a,d="new-folder",e=await n.createFolder(c,d);if(e.success&&e.resolvedPath){let b={id:e.resolvedPath,name:d,path:e.resolvedPath,relativePath:(0,a5.qP)(e.resolvedPath,a),type:"folder",extension:"",depth:0,children:[],childrenLoaded:!0,isOptimistic:!0};m.onFileCreated(c,b),m.expandedPaths.has(c)||m.toggleExpand(c),setTimeout(()=>m.startRename(e.resolvedPath),50)}else e.error&&C(e.error)},[m,n,a]),S=(0,e.useCallback)(a=>{let b=a.target;if("INPUT"!==b.tagName&&"TEXTAREA"!==b.tagName){if("ArrowDown"===a.key)a.preventDefault(),A(a=>Math.min(a+1,E.length-1));else if("ArrowUp"===a.key)a.preventDefault(),A(a=>Math.max(a-1,0));else if("ArrowRight"===a.key){a.preventDefault();let b=E[z]?.node;b?.type!=="folder"||m.expandedPaths.has(b.path)||(m.toggleExpand(b.path),m.select(b.path))}else if("ArrowLeft"===a.key){a.preventDefault();let b=E[z]?.node;b?.type==="folder"&&m.expandedPaths.has(b.path)&&m.toggleExpand(b.path)}else if("Enter"===a.key){a.preventDefault();let b=E[z]?.node;b&&L(b.path,"folder"===b.type)}else if("F2"===a.key){a.preventDefault();let b=E[z]?.node;b&&(m.select(b.path),m.startRename(b.path))}else if("Delete"===a.key||"Backspace"===a.key){a.preventDefault();let b=E[z]?.node;b&&window.confirm(`Delete "${b.name}"?`)&&n.deleteFile(b.path).then(a=>{a.success&&(m.onFileDeleted(b.path),C(`Deleted "${b.name}"`))})}}},[E,z,m,L,n]),T=(0,e.useCallback)(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>w(null),5e3)},[]),U=(0,e.useCallback)((b,c)=>{if(0===b.length)return;q.current=0,s(!1),p.current&&clearTimeout(p.current);let d=b.reduce((a,b)=>a+b.size,0),e=a8(c,a);u(c),w({phase:"uploading",targetPath:c,fileCount:b.length,loaded:0,total:d,message:`Uploading ${b.length} file${1===b.length?"":"s"} to ${e}`});let f=new FormData;b.forEach(a=>f.append("files",a,a.name));let g=new XMLHttpRequest,h=(0,a5.HG)(c);g.open("POST",`/api/files/${h}?type=upload`),g.upload.onprogress=a=>{a.lengthComputable&&w(b=>b?{...b,loaded:a.loaded,total:a.total}:b)},g.onload=()=>{u(null);let a={};try{a=JSON.parse(g.responseText)}catch{a={}}if(g.status>=200&&g.status<300){let f=a.uploaded??[],g=a.failed??[],h=[...f.filter(a=>a.name!==a.originalName).slice(0,3).map(a=>`${a.originalName} saved as ${a.name}`),...g.slice(0,3).map(a=>`${a.name}: ${a.error}`)];w({phase:g.length>0?"warning":"success",targetPath:c,fileCount:b.length,loaded:d,total:d,message:g.length>0?`Uploaded ${f.length}, ${g.length} failed`:`Uploaded ${f.length} file${1===f.length?"":"s"} to ${e}`,details:h}),m.invalidateDir(c),m.expandedPaths.has(c)&&m.loadChildren(c),T()}else{let e=a.error??`Upload failed (HTTP ${g.status})`;w({phase:"error",targetPath:c,fileCount:b.length,loaded:0,total:d,message:e}),T()}},g.onerror=()=>{u(null),w({phase:"error",targetPath:c,fileCount:b.length,loaded:0,total:d,message:"Upload failed due to a network error"}),T()},g.onabort=()=>{u(null),w({phase:"error",targetPath:c,fileCount:b.length,loaded:0,total:d,message:"Upload canceled"}),T()},g.send(f)},[a,m,T]),V=(0,e.useCallback)(a=>{a9(a.dataTransfer)&&(a.preventDefault(),q.current+=1,s(!0))},[]),W=(0,e.useCallback)(a=>{a9(a.dataTransfer)&&(a.preventDefault(),a.dataTransfer.dropEffect="copy")},[]),X=(0,e.useCallback)(()=>{q.current-=1,q.current<=0&&(q.current=0,s(!1))},[]),Y=(0,e.useCallback)(b=>{if(!a9(b.dataTransfer))return;b.preventDefault(),q.current=0,s(!1);let c=ba(b.dataTransfer);c.length>0&&U(c,a)},[a,U]),Z=(0,e.useCallback)(a=>b=>{if(!a9(b.dataTransfer))return;b.preventDefault(),b.stopPropagation();let c=ba(b.dataTransfer);c.length>0&&(U(c,a),m.expandedPaths.has(a)||m.toggleExpand(a))},[U,m]),$=v&&v.total>0?Math.max(0,Math.min(100,Math.round(v.loaded/v.total*100))):v?.phase==="uploading"?8:100,_=v?.phase==="success"?"#22c55e":v?.phase==="warning"?"#f59e0b":v?.phase==="error"?"#ef4444":"var(--accent)";return m.loadFailed?(0,d.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Could not load files"}):(0,d.jsxs)("div",{onDragEnter:V,onDragOver:W,onDragLeave:X,onDrop:Y,onKeyDown:S,tabIndex:0,style:{position:"relative",display:"flex",flexDirection:"column",height:"100%",outline:r?"1px solid rgba(37,99,235,0.45)":"none",outlineOffset:-1,background:r?"rgba(37,99,235,0.04)":void 0,transition:"background 0.12s, outline-color 0.12s"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:2,padding:"4px 6px",borderBottom:"1px solid var(--border)",flexShrink:0,minHeight:30},children:[(0,d.jsx)("button",{onClick:Q,title:"New File",style:bc,children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,d.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,d.jsx)("line",{x1:"12",y1:"18",x2:"12",y2:"12"}),(0,d.jsx)("line",{x1:"9",y1:"15",x2:"15",y2:"15"})]})}),(0,d.jsx)("button",{onClick:R,title:"New Folder",style:bc,children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"}),(0,d.jsx)("line",{x1:"12",y1:"11",x2:"12",y2:"17"}),(0,d.jsx)("line",{x1:"9",y1:"14",x2:"15",y2:"14"})]})}),(0,d.jsx)("button",{onClick:()=>m.refresh(a),title:"Refresh",style:bc,children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("polyline",{points:"23 4 23 10 17 10"}),(0,d.jsx)("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),(0,d.jsx)("button",{onClick:()=>{m.deselectAll()},title:"Collapse All",style:bc,children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("polyline",{points:"4 14 10 14 10 20"}),(0,d.jsx)("polyline",{points:"20 10 14 10 14 4"}),(0,d.jsx)("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),(0,d.jsx)("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}),(0,d.jsx)("div",{style:{flex:1}}),(0,d.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",paddingRight:4},children:[E.length," items"]})]}),B&&(0,d.jsx)("div",{style:{padding:"4px 10px",fontSize:11,color:"var(--text)",background:"var(--bg-selected)",borderBottom:"1px solid var(--border)"},children:B}),(0,d.jsxs)("div",{ref:o,onScroll:J,style:{flex:1,overflow:"auto",position:"relative"},children:[m.hasLoaded?0===E.length?(0,d.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:D?"No matching files":"No files found"}):(0,d.jsx)("div",{style:{height:K.totalHeight,position:"relative"},children:K.items.map(a=>{let{index:b,top:c}=a,{node:e,depth:f,isExpanded:g}=E[b],h=b===z;return(0,d.jsx)("div",{style:{position:"absolute",top:c,left:0,right:0,height:26,outline:h?"1px solid var(--accent)":"none",outlineOffset:-1,borderRadius:4},children:(0,d.jsx)(a3,{node:e,depth:f,isExpanded:g,isLoading:m.loadingPaths.has(e.path),isSelected:m.selectedPaths.has(e.path),isRenaming:m.renamingPath===e.path,isUploadTarget:t===e.path,onClick:L,onDoubleClick:M,onContextMenu:N,onRenameSubmit:P,onRenameCancel:()=>m.stopRename(),onDrop:"folder"===e.type?Z(e.path):void 0})},e.id)})}):(0,d.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."}),r&&(0,d.jsx)("div",{style:{pointerEvents:"none",position:"absolute",inset:6,top:0,border:"1px dashed rgba(37,99,235,0.62)",borderRadius:8,background:"rgba(37,99,235,0.07)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:2},children:(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"7px 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",fontSize:12,boxShadow:"0 8px 24px rgba(0,0,0,0.16)"},children:[(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,d.jsx)("polyline",{points:"17 8 12 3 7 8"}),(0,d.jsx)("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),"Drop to upload into ",a8(a,a)]})})]}),v&&(0,d.jsxs)("div",{style:{margin:"6px",padding:"7px 8px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",boxShadow:"0 8px 24px rgba(0,0,0,0.12)",flexShrink:0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,d.jsx)("span",{style:{width:8,height:8,borderRadius:999,background:_,flexShrink:0}}),(0,d.jsx)("span",{title:v.message,style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11,fontWeight:600},children:v.message}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,flexShrink:0},children:"uploading"===v.phase?`${$}%`:function(a){if(!Number.isFinite(a)||a<=0)return"0 B";let b=["B","KB","MB","GB"],c=a,d=0;for(;c>=1024&&d<b.length-1;)c/=1024,d+=1;return`${c>=10||0===d?Math.round(c):c.toFixed(1)} ${b[d]}`}(v.total)})]}),(0,d.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,background:"var(--bg)",overflow:"hidden"},children:(0,d.jsx)("div",{style:{width:`${$}%`,height:"100%",borderRadius:999,background:_,transition:"width 0.15s ease"}})}),v.details&&v.details.length>0&&(0,d.jsx)("div",{style:{marginTop:5,display:"grid",gap:2},children:v.details.map(a=>(0,d.jsx)("div",{title:a,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:10},children:a},a))})]}),x&&(0,d.jsx)(a4,{x:x.x,y:x.y,actions:O,onClose:()=>y(null)})]})}let bc={display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,border:"none",borderRadius:4,background:"transparent",color:"var(--text-dim)",cursor:"pointer",flexShrink:0,transition:"background 0.08s, color 0.08s"};function bd({cwd:a,refreshKey:b=0,onOpenFile:c,onExploreFile:f,onAtMention:g}){let[h,i]=(0,e.useState)("");return(0,d.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",background:"var(--bg)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:"7px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,d.jsx)("div",{style:{display:"flex",alignItems:"center",gap:8},children:(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Files"}),(0,d.jsx)("div",{title:a??"",style:{marginTop:1,fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:a??"No project selected"})]})}),(0,d.jsxs)("div",{style:{position:"relative",marginTop:7},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",style:{position:"absolute",left:8,top:"50%",transform:"translateY(-50%)",color:"var(--text-dim)",pointerEvents:"none"},"aria-hidden":"true",children:[(0,d.jsx)("circle",{cx:"7",cy:"7",r:"4.4"}),(0,d.jsx)("path",{d:"M10.4 10.4 13.2 13.2"})]}),(0,d.jsx)("input",{value:h,onChange:a=>i(a.target.value),placeholder:"Filter files...",disabled:!a,style:{width:"100%",height:28,boxSizing:"border-box",padding:"0 28px 0 26px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none",opacity:a?1:.6}}),h&&(0,d.jsx)("button",{type:"button",onClick:()=>i(""),title:"Clear filter",style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",width:20,height:20,display:"flex",alignItems:"center",justifyContent:"center",border:"none",borderRadius:4,background:"transparent",color:"var(--text-dim)",cursor:"pointer",padding:0},children:(0,d.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[(0,d.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,d.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]})]}),(0,d.jsx)("div",{style:{flex:1,minHeight:0,overflow:"hidden"},children:a?(0,d.jsx)(bb,{cwd:a,onOpenFile:c,onExploreFile:f,refreshKey:b,onAtMention:g,searchQuery:h}):(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:18,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"Select a project to browse files."})})]})}var be=c(32492),bf=c(2857);let bg={__soul__:{apiPath:"/api/soul",title:"SOUL.md"},__harness__:{apiPath:"/api/harness",title:"HARNESS.md"}};function bh({filePath:a}){let b=bg[a],{isDark:c}=(0,bf.D)(),[f,g]=(0,e.useState)(""),[h,i]=(0,e.useState)(!0),[j,k]=(0,e.useState)(null),[l,m]=(0,e.useState)(!1),[n,o]=(0,e.useState)(!1),p=(0,e.useCallback)(async()=>{if(b){m(!0);try{await fetch(b.apiPath,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:f})}),o(!0),setTimeout(()=>o(!1),2e3)}catch(a){k(String(a))}finally{m(!1)}}},[b,f]);return b?h?(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Loading…"}):j?(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"#f87171",fontSize:13},children:j}):(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0},children:[(0,d.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontWeight:600,color:"var(--text)"},children:b.title}),(0,d.jsx)("span",{style:{marginLeft:"auto",fontSize:10,color:"var(--text-dim)"},children:"Global"}),n&&(0,d.jsx)("span",{style:{color:"#4ade80",fontWeight:600,animation:"saved-pop 0.3s ease"},children:"✓ Saved"}),(0,d.jsx)("button",{onClick:p,disabled:l,title:"Save (Ctrl+S)",style:{padding:"2px 10px",fontSize:11,cursor:l?"not-allowed":"pointer",background:"var(--accent)",color:"#fff",border:"1px solid var(--accent)",borderRadius:5,fontWeight:600,opacity:l?.6:1},children:l?"Saving…":"Save"})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,d.jsx)(be.g,{initialContent:f,language:"markdown",isDark:c,onChange:g,onSave:p})})]}):null}function bi({side:a,onResize:b,onResizeStart:c,onResizeEnd:f,ariaLabel:g}){let h=(0,e.useRef)(null),i=(0,e.useRef)(!1),j=(0,e.useRef)(0),[k,l]=(0,e.useState)(!1),m=(0,e.useCallback)(a=>{if(!i.current)return;i.current=!1,l(!1);let b=h.current;b&&void 0!==a&&b.hasPointerCapture(a)&&b.releasePointerCapture(a),document.body.style.cursor="",document.body.style.userSelect="",f?.()},[f]),n=(0,e.useCallback)(a=>{0===a.button&&a.isPrimary&&(a.preventDefault(),i.current=!0,j.current=a.clientX,l(!0),c?.(),a.currentTarget.setPointerCapture(a.pointerId),document.body.style.cursor="col-resize",document.body.style.userSelect="none")},[c]),o=(0,e.useCallback)(a=>{if(!i.current)return;a.preventDefault();let c=a.clientX-j.current;j.current=a.clientX,b(c)},[b]),p=(0,e.useCallback)(a=>{a.preventDefault(),m(a.pointerId)},[m]),q=(0,e.useCallback)(a=>{m(a.pointerId)},[m]);return(0,d.jsx)("div",{ref:h,role:"separator","aria-label":g??"Resize panel","aria-orientation":"vertical",className:`resize-handle${k?" resize-handle-dragging":""}`,"data-side":a,onPointerDown:n,onPointerMove:o,onPointerUp:p,onPointerCancel:q,style:{alignSelf:"stretch",cursor:"col-resize",display:"flex",flexShrink:0,justifyContent:"center",marginLeft:-5,marginRight:-5,position:"relative",touchAction:"none",width:10,zIndex:250},children:(0,d.jsx)("div",{className:"resize-handle-line"})})}function bj(a){return"running"===a?"#22c55e":"starting"===a?"rgba(234,179,8,0.95)":"error"===a?"#ef4444":"var(--text-dim)"}function bk(a){return"h5adexp"===a?"H5AD Exp":"stexp"}function bl(a,b,c){return Math.min(Math.max(a,b),c)}function bm(a){if(!a||"object"!=typeof a||!("app"in a))return null;let b=a.app;return b&&"object"==typeof b&&"id"in b?b:null}function bn({appType:a,filePath:b,cwd:c,sessionId:f,appId:g,onClose:h,onAppChanged:i,onOpenTools:j}){var k;let[l,m]=(0,e.useState)(null),[n,o]=(0,e.useState)(null),[p,q]=(0,e.useState)(!1),[r,s]=(0,e.useState)(!1),[t,u]=(0,e.useState)(0),[v,w]=(0,e.useState)(()=>({left:34,top:34,width:Math.min(1280,Math.max(360,1212)),height:Math.min(880,Math.max(320,832)),maximized:!1})),[x,y]=(0,e.useState)(!1),[z,A]=(0,e.useState)(!1),B=(0,e.useRef)(null),C=(0,e.useRef)(null),D=(0,e.useRef)(null),E=!!b||!!g,F=b?(0,a5.WP)(b):l?(0,a5.WP)(l.filePath):"",G=b&&c?(0,a5.qP)(b,c):l?.filePath&&l.cwd?(0,a5.qP)(l.filePath,l.cwd):b??l?.filePath??"",H=l?.status??"idle",I=(0,e.useMemo)(()=>l?.logs?.join("\n")??"",[l?.logs]),J=l?.appType==="h5adexp"?l.url:l?.directUrl??l?.url??"",K=(0,e.useCallback)(a=>{m(a),i?.(a)},[i]);(0,e.useCallback)(async a=>{let b=await fetch(`/api/apps?appId=${encodeURIComponent(a)}`),c=await b.json(),d=bm(c);if(!b.ok||!d)throw Error(c&&"object"==typeof c&&"error"in c?String(c.error):`HTTP ${b.status}`);return K(d),d},[K]);let L=(0,e.useCallback)(async()=>{if(b&&c&&!p){q(!0),o(null);try{let d=await fetch("/api/apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"start",appType:a,filePath:b,cwd:c,sessionId:f})}),e=await d.json(),g=bm(e);if(!d.ok||!g){let a=e&&"object"==typeof e&&"error"in e?String(e.error):`HTTP ${d.status}`;throw Error(a)}K(g),u(a=>a+1)}catch(a){o(a instanceof Error?a.message:String(a))}finally{q(!1)}}},[a,K,p,c,b,f]),M=(0,e.useCallback)(async()=>{if(l?.id&&!p){q(!0),o(null);try{let a=await fetch("/api/apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"stop",appId:l.id})}),b=await a.json(),c=bm(b);if(!a.ok||!c){let c=b&&"object"==typeof b&&"error"in b?String(b.error):`HTTP ${a.status}`;throw Error(c)}K(c)}catch(a){o(a instanceof Error?a.message:String(a))}finally{q(!1)}}},[l?.id,K,p]),N=(0,e.useCallback)(a=>{0!==a.button||v.maximized||(a.preventDefault(),a.currentTarget.setPointerCapture(a.pointerId),C.current={pointerId:a.pointerId,startX:a.clientX,startY:a.clientY,left:v.left,top:v.top},y(!0))},[v.left,v.maximized,v.top]),O=(0,e.useCallback)(a=>{let b=C.current;if(!b||b.pointerId!==a.pointerId)return;let c=b.left+a.clientX-b.startX,d=b.top+a.clientY-b.startY;w(a=>({...a,left:bl(c,8,Math.max(8,window.innerWidth-120)),top:bl(d,8,Math.max(8,window.innerHeight-48))}))},[]),P=(0,e.useCallback)(a=>{let b=C.current;b?.pointerId===a.pointerId&&(a.currentTarget.releasePointerCapture(a.pointerId),C.current=null,y(!1))},[]),Q=(0,e.useCallback)(a=>{0!==a.button||v.maximized||(a.preventDefault(),a.stopPropagation(),a.currentTarget.setPointerCapture(a.pointerId),D.current={pointerId:a.pointerId,startX:a.clientX,startY:a.clientY,width:v.width,height:v.height},A(!0))},[v.height,v.maximized,v.width]),R=(0,e.useCallback)(a=>{let b=D.current;if(!b||b.pointerId!==a.pointerId)return;let c=b.width+a.clientX-b.startX,d=b.height+a.clientY-b.startY;w(a=>({...a,width:bl(c,420,Math.max(420,window.innerWidth-a.left-8)),height:bl(d,340,Math.max(340,window.innerHeight-a.top-8))}))},[]),S=(0,e.useCallback)(a=>{let b=D.current;b?.pointerId===a.pointerId&&(a.currentTarget.releasePointerCapture(a.pointerId),D.current=null,A(!1))},[]),T=(0,e.useCallback)(()=>{j?.(),h()},[h,j]),U=(0,e.useCallback)(()=>{w(a=>({...a,maximized:!a.maximized}))},[]);if(!E)return null;let V=v.maximized?{position:"fixed",inset:12,zIndex:900}:{position:"fixed",left:v.left,top:v.top,width:v.width,height:v.height,zIndex:900};return(0,d.jsxs)("div",{ref:B,role:"dialog","aria-label":`${l?.title??bk(a)} window`,tabIndex:-1,onKeyDown:a=>{"Escape"===a.key&&T()},style:{...V,display:"flex",flexDirection:"column",minWidth:v.maximized?void 0:420,minHeight:v.maximized?void 0:340,background:"var(--bg)",border:"1px solid rgba(37,99,235,0.5)",borderRadius:8,boxShadow:"0 18px 60px rgba(0,0,0,0.26)",overflow:"hidden",outline:"none"},children:[(0,d.jsxs)("div",{onPointerDown:N,onPointerMove:O,onPointerUp:P,onPointerCancel:P,style:{display:"flex",alignItems:"center",gap:8,padding:"8px 9px 8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0,userSelect:"none",cursor:v.maximized?"default":x?"grabbing":"grab"},children:[(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,d.jsx)("span",{style:{fontSize:13,fontWeight:700,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l?.title??bk(a)}),(0,d.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:bj(H),flexShrink:0}}),(0,d.jsx)("span",{style:{fontSize:11,color:bj(H),textTransform:"capitalize",flexShrink:0},children:H}),l?.pid&&(0,d.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0},children:["pid ",l.pid]}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",flexShrink:0},children:(k=l?.rssBytes)&&Number.isFinite(k)?k<1048576?`${(k/1024).toFixed(0)}K`:k<0x40000000?`${(k/1024/1024).toFixed(1)}M`:`${(k/1024/1024/1024).toFixed(1)}G`:"-"})]}),(0,d.jsx)("div",{title:b??l?.filePath??"",style:{marginTop:2,fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:G||F})]}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:()=>u(a=>a+1),disabled:!J||l?.status==="stopped",style:bo,title:"Reload",children:"Reload"}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:()=>s(a=>!a),style:{...bo,background:r?"var(--bg-selected)":"var(--bg)",color:r?"var(--text)":"var(--text-muted)"},title:"Toggle logs",children:"Logs"}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:T,style:bo,title:"Show in Tools",children:"Tools"}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:()=>void M(),disabled:!l||"stopped"===l.status||p,style:{...bo,border:"1px solid rgba(239,68,68,0.35)",background:"rgba(239,68,68,0.08)",color:"#ef4444",opacity:!l||"stopped"===l.status||p?.55:1},title:"Stop process",children:"Stop"}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:T,"aria-label":"Minimize",title:"Minimize",style:bp,children:(0,d.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round","aria-hidden":"true",children:(0,d.jsx)("line",{x1:"4",y1:"11",x2:"12",y2:"11"})})}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:U,"aria-label":v.maximized?"Restore":"Maximize",title:v.maximized?"Restore":"Maximize",style:bp,children:v.maximized?(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,d.jsx)("path",{d:"M6 3.5h6.5V10"}),(0,d.jsx)("path",{d:"M3.5 6H10v6.5H3.5z"})]}):(0,d.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:(0,d.jsx)("path",{d:"M4 4h8v8H4z"})})}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:h,"aria-label":"Close window",title:"Close window",style:bp,children:(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round","aria-hidden":"true",children:[(0,d.jsx)("line",{x1:"4",y1:"4",x2:"12",y2:"12"}),(0,d.jsx)("line",{x1:"12",y1:"4",x2:"4",y2:"12"})]})})]}),(n||l?.error)&&(0,d.jsx)("div",{style:{padding:"8px 12px",borderBottom:"1px solid rgba(248,113,113,0.25)",background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:12},children:n??l?.error}),(0,d.jsxs)("div",{style:{flex:1,minHeight:0,display:"flex",background:"var(--bg)"},children:[(0,d.jsx)("div",{style:{flex:1,minWidth:0,position:"relative"},children:p&&!l?.url?(0,d.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:["Starting ",bk(a),"..."]}):J&&l?.status!=="stopped"?(0,d.jsx)("iframe",{src:J,title:`${l?.title??bk(a)} - ${F}`,style:{width:"100%",height:"100%",border:"none",display:"block",background:"#fff"}},`${J}:${t}`):(0,d.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:10,color:"var(--text-muted)",fontSize:13},children:[(0,d.jsxs)("div",{children:[bk(a)," is stopped."]}),b&&c&&(0,d.jsx)("button",{type:"button",onClick:()=>void L(),disabled:p,style:{height:32,padding:"0 12px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:p?"not-allowed":"pointer",fontSize:12,fontWeight:650},children:"Start again"})]})}),r&&(0,d.jsxs)("div",{style:{width:360,borderLeft:"1px solid var(--border)",background:"var(--bg-panel)",display:"flex",flexDirection:"column",minHeight:0},children:[(0,d.jsx)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-muted)",fontWeight:650},children:"Process Logs"}),(0,d.jsx)("pre",{style:{flex:1,margin:0,padding:10,overflow:"auto",fontSize:11,lineHeight:1.45,color:"var(--text-muted)",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap"},children:I||"No logs yet."})]})]}),!v.maximized&&(0,d.jsx)("div",{role:"separator","aria-orientation":"horizontal","aria-label":"Resize explore window",title:"Resize",onPointerDown:Q,onPointerMove:R,onPointerUp:S,onPointerCancel:S,style:{position:"absolute",right:0,bottom:0,width:18,height:18,cursor:"nwse-resize",background:"linear-gradient(135deg, transparent 0 48%, rgba(127,127,127,0.22) 48% 52%, transparent 52% 100%)"}})]})}let bo={height:30,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,flexShrink:0},bp={width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,padding:0};function bq(a){return"running"===a?"#22c55e":"starting"===a?"rgba(234,179,8,0.95)":"error"===a?"#ef4444":"var(--text-dim)"}function br(a){return"waiting_model"===a?"rgba(234,179,8,0.95)":"running_tools"===a?"#38bdf8":"streaming"===a?"#22c55e":"compacting"===a?"#a78bfa":"var(--text-dim)"}function bs(a){return a&&Number.isFinite(a)?a<1048576?`${(a/1024).toFixed(0)}K`:a<0x40000000?`${(a/1024/1024).toFixed(1)}M`:`${(a/1024/1024/1024).toFixed(1)}G`:"-"}function bt(a){if(!a||!Number.isFinite(a))return"-";let b=Math.max(0,Math.floor(a/1e3)),c=Math.floor(b/3600),d=Math.floor(b%3600/60),e=b%60;return c>0?`${c}h ${d}m`:d>0?`${d}m ${e}s`:`${e}s`}function bu({refreshKey:a=0,visibleAppId:b,cwd:c,onOpenApp:f,onAppChanged:g,onAppsChanged:h,agentRuntimeExtra:i}){let[j,k]=(0,e.useState)([]),[l,m]=(0,e.useState)(null),[n,o]=(0,e.useState)(null),[p,q]=(0,e.useState)(null),[r,s]=(0,e.useState)(null),[t,u]=(0,e.useState)(null),[v,w]=(0,e.useState)(null),[x,y]=(0,e.useState)(null),[z,A]=(0,e.useState)(null),[B,C]=(0,e.useState)(null),D=(0,e.useMemo)(()=>[...j].sort((a,b)=>{let c=+!!a.running,d=+!!b.running;return c!==d?d-c:Date.parse(b.lastActivity)-Date.parse(a.lastActivity)}),[j]),E=(0,e.useCallback)(async()=>{try{let a=await fetch("/api/apps",{cache:"no-store"}),b=await a.json();if(!a.ok||!Array.isArray(b.apps))throw Error(b.error??`HTTP ${a.status}`);k(b.apps),h?.(b.apps),q(null)}catch(a){q(a instanceof Error?a.message:String(a))}},[h]),F=(0,e.useCallback)(async()=>{try{let a=new URLSearchParams;c&&a.set("cwd",c);let b=await fetch(`/api/agent/runtime${a.toString()?`?${a}`:""}`,{cache:"no-store"}),d=await b.json();if(!b.ok||!Array.isArray(d.sessions))throw Error(d.error??`HTTP ${b.status}`);m(d),o(d.memory??null),s(null)}catch(a){s(a instanceof Error?a.message:String(a))}},[c]),G=(0,e.useCallback)(async a=>{y(a.id),q(null);try{let b=await fetch("/api/apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"stop",appId:a.id})}),c=await b.json();if(!b.ok||!c.app)throw Error(c.error??`HTTP ${b.status}`);k(a=>a.map(a=>a.id===c.app.id?c.app:a)),g?.(c.app),await E()}catch(a){q(a instanceof Error?a.message:String(a))}finally{y(null)}},[E,g]),H=(0,e.useCallback)(async a=>{A(a.sessionId),s(null);try{let b=await fetch(`/api/agent/${encodeURIComponent(a.sessionId)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"abort"})}),c=await b.json().catch(()=>({}));if(!b.ok||c.error)throw Error(c.error??`HTTP ${b.status}`);await F()}catch(a){s(a instanceof Error?a.message:String(a))}finally{A(null)}},[F]),I=(0,e.useCallback)(async(a,b)=>{if(c){w(`${a}:${b}`),u(null);try{let d=await fetch("/api/memory/promote",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:c,memoryId:a,target:b})}),e=await d.json().catch(()=>({}));if(!d.ok)throw Error(e.error??`HTTP ${d.status}`);await F()}catch(a){u(a instanceof Error?a.message:String(a))}finally{w(null)}}},[c,F]),J=(0,e.useCallback)(async a=>{if(c){w(`dismiss:${a}`),u(null);try{let b=await fetch("/api/memory/dismiss",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:c,memoryId:a})}),d=await b.json().catch(()=>({}));if(!b.ok)throw Error(d.error??`HTTP ${b.status}`);await F()}catch(a){u(a instanceof Error?a.message:String(a))}finally{w(null)}}},[c,F]),K=j.filter(a=>a.running).length,L=j.reduce((a,b)=>a+(b.running?b.rssBytes??0:0),0),M=l?.sessions??[],N=M.filter(a=>a.busy),O=N.filter(a=>"waiting_model"===a.phase);return(0,d.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",background:"var(--bg)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:"10px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Status"}),(0,d.jsxs)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)"},children:[N.length," agent running \xb7 ",K," explore \xb7 ",bs(L)]})]}),(0,d.jsx)("button",{type:"button",onClick:()=>{E(),F()},style:bz,title:"Refresh status",children:"Refresh"})]}),p&&(0,d.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:p}),r&&(0,d.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:r}),t&&(0,d.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:t})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"auto",padding:10},children:(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[(0,d.jsxs)("section",{children:[(0,d.jsx)(bv,{title:"Agent Runtime",subtitle:O.length>0?`${O.length} waiting for model first token`:`${N.length} active chat${1===N.length?"":"s"}`}),i,0===M.length?(0,d.jsx)(bw,{label:"No agent runtime is active."}):(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:M.map(a=>{var b;let c=a.model?`${a.model.provider}/${a.model.id}`:"-",e=a.cwd?(0,a5.WP)(a.cwd)||a.cwd:"-",f=a.activeTools.map(a=>a.name).join(", ");return(0,d.jsxs)("div",{style:{border:`1px solid ${a.busy?"rgba(37,99,235,0.35)":"var(--border)"}`,borderRadius:8,background:a.busy?"var(--bg-selected)":"var(--bg-panel)",padding:10},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,d.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:br(a.phase),marginTop:5,flexShrink:0}}),(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,d.jsx)("span",{style:{fontSize:12,fontWeight:700,color:br(a.phase),textTransform:"uppercase",flexShrink:0},children:"waiting_model"===(b=a.phase)?"waiting model":"running_tools"===b?"running tools":"streaming"===b?"streaming":"compacting"===b?"compacting":"idle"}),(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:c,children:c})]}),(0,d.jsxs)("div",{title:a.cwd??void 0,style:{marginTop:3,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[e," \xb7 ",a.sessionId.slice(0,8)]})]})]}),(0,d.jsxs)("div",{style:{marginTop:9,display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"5px 10px",fontSize:11,color:"var(--text-muted)"},children:[(0,d.jsx)(bx,{label:"uptime",value:bt(a.uptimeMs)}),(0,d.jsx)(bx,{label:"wait",value:bt(a.waitingForModelMs),color:"waiting_model"===a.phase?br(a.phase):void 0}),(0,d.jsx)(bx,{label:"pending",value:null===a.pendingMessageCount?"-":String(a.pendingMessageCount)}),(0,d.jsx)(bx,{label:"event",value:a.lastEventType??"-"}),(0,d.jsx)(bx,{label:"tools",value:f||"-"}),(0,d.jsx)(bx,{label:"ops",value:a.operations.join(", ")||"-"})]}),"waiting_model"===a.phase&&(a.waitingForModelMs??0)>8e3&&(0,d.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,background:"rgba(234,179,8,0.08)",color:"rgba(234,179,8,0.95)",fontSize:11,lineHeight:1.45},children:"Waiting before the first model token. If another chat uses the same provider or gateway, the upstream may be queueing requests."}),a.errorMessage&&(0,d.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11,lineHeight:1.45},children:a.errorMessage}),(0,d.jsx)("div",{style:{marginTop:10,display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:(0,d.jsx)("button",{type:"button",onClick:()=>void H(a),disabled:!a.busy||z===a.sessionId,style:{...bz,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:a.busy&&z!==a.sessionId?1:.55},children:"Abort"})})]},a.sessionId)})})]}),(0,d.jsxs)("section",{children:[(0,d.jsx)(bv,{title:"Memory",subtitle:n?`${n.count} stored \xb7 ${n.candidateCount} candidates`:c?"loading":"No project selected"}),c?n?(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:10},children:[(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"5px 10px",fontSize:11,color:"var(--text-muted)"},children:[(0,d.jsx)(bx,{label:"fact",value:String(n.byType.fact)}),(0,d.jsx)(bx,{label:"context",value:String(n.byType.context)}),(0,d.jsx)(bx,{label:"decision",value:String(n.byType.decision)}),(0,d.jsx)(bx,{label:"preference",value:String(n.byType.preference)}),(0,d.jsx)(bx,{label:"note",value:String(n.byType.note)}),(0,d.jsx)(bx,{label:"candidates",value:String(n.candidateCount),color:n.candidateCount>0?"var(--accent)":void 0})]}),(0,d.jsx)("div",{title:n.filePath,style:{marginTop:8,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(0,a5.qP)(n.filePath,c)})]}),(0,d.jsx)(by,{title:"Promotion Candidates",emptyLabel:"No promotion candidates yet.",items:n.topCandidates,onPromote:I,onDismiss:J,busyAction:v}),(0,d.jsx)(by,{title:"Recent Memory",emptyLabel:"No memory stored for this project.",items:n.recent})]}):(0,d.jsx)(bw,{label:"Memory status unavailable."}):(0,d.jsx)(bw,{label:"Select a project to inspect memory status."})]}),(0,d.jsxs)("section",{children:[(0,d.jsx)(bv,{title:"Explore Tools",subtitle:`${K} running \xb7 ${bs(L)}`}),0===D.length?(0,d.jsx)(bw,{label:"No explore tools are running."}):(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:D.map(a=>{let e,g=b===a.id,h=B===a.id;return(0,d.jsxs)("div",{style:{border:`1px solid ${g?"rgba(37,99,235,0.5)":"var(--border)"}`,borderRadius:8,background:g?"var(--bg-selected)":"var(--bg-panel)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:10},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:8},children:[(0,d.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:bq(a.status),marginTop:5,flexShrink:0}}),(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[(0,d.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)",textTransform:"uppercase",flexShrink:0},children:a.appType}),(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:a.filePath,children:(0,a5.WP)(a.filePath)})]}),(0,d.jsx)("div",{title:a.filePath,style:{marginTop:3,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(e=c&&a.filePath.startsWith(c)?c:a.cwd,(0,a5.qP)(a.filePath,e))})]})]}),(0,d.jsxs)("div",{style:{marginTop:9,display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"5px 10px",fontSize:11,color:"var(--text-muted)"},children:[(0,d.jsx)(bx,{label:"status",value:a.status,color:bq(a.status)}),(0,d.jsx)(bx,{label:"pid",value:a.pid?String(a.pid):"-"}),(0,d.jsx)(bx,{label:"memory",value:bs(a.rssBytes)}),(0,d.jsx)(bx,{label:"uptime",value:bt(a.uptimeMs)}),(0,d.jsx)(bx,{label:"port",value:String(a.port)}),(0,d.jsx)(bx,{label:"session",value:a.sessionId?a.sessionId.slice(0,8):"-"})]}),(0,d.jsxs)("div",{style:{marginTop:10,display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[(0,d.jsx)("button",{type:"button",onClick:()=>f(a),style:bz,children:"Open"}),(0,d.jsx)("button",{type:"button",onClick:()=>C(b=>b===a.id?null:a.id),style:{...bz,background:h?"var(--bg-selected)":"var(--bg)"},children:"Logs"}),(0,d.jsx)("button",{type:"button",onClick:()=>void G(a),disabled:!a.running||x===a.id,style:{...bz,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:a.running&&x!==a.id?1:.55},children:"Stop"})]})]}),h&&(0,d.jsx)("pre",{style:{maxHeight:220,overflow:"auto",margin:0,padding:10,borderTop:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",fontSize:11,lineHeight:1.45,fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap"},children:a.logs.join("\n")||"No logs yet."})]},a.id)})})]})]})})]})}function bv({title:a,subtitle:b}){return(0,d.jsxs)("div",{style:{marginBottom:8,display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:10},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:a}),(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b})]})}function bw({label:a}){return(0,d.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:"18px 10px",color:"var(--text-dim)",fontSize:12,textAlign:"center"},children:a})}function bx({label:a,value:b,color:c}){return(0,d.jsxs)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:5},children:[(0,d.jsx)("span",{style:{color:"var(--text-dim)",flexShrink:0},children:a}),(0,d.jsx)("span",{style:{color:c??"var(--text-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:b})]})}function by({title:a,emptyLabel:b,items:c,onPromote:e,onDismiss:f,busyAction:g}){return(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,d.jsx)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",fontSize:12,fontWeight:700,color:"var(--text)"},children:a}),0===c.length?(0,d.jsx)("div",{style:{padding:"14px 10px",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:b}):(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column"},children:c.map((a,b)=>(0,d.jsxs)("div",{style:{padding:"9px 10px",borderTop:0===b?"none":"1px solid var(--border)",display:"flex",flexDirection:"column",gap:5},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0},children:[(0,d.jsx)("span",{style:{fontSize:10,color:"project_memory"===a.candidate?"#f59e0b":"spark"===a.candidate?"var(--accent)":"var(--text-dim)",fontWeight:700,textTransform:"uppercase",flexShrink:0},children:"none"===a.candidate?a.memoryType:a.candidate}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",flexShrink:0},children:a.importance.toFixed(2)}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:new Date(a.timestamp).toLocaleString()})]}),(0,d.jsx)("div",{title:a.content,style:{fontSize:12,color:"var(--text)",lineHeight:1.45,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},children:a.content}),(e||f)&&(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[e&&(0,d.jsx)("button",{type:"button",disabled:a.promotedTo.includes("memory")||g===`${a.id}:memory`,onClick:()=>void e(a.id,"memory"),style:{...bz,height:24,padding:"0 8px",opacity:a.promotedTo.includes("memory")||g===`${a.id}:memory`?.55:1},children:a.promotedTo.includes("memory")?"In MEMORY.md":g===`${a.id}:memory`?"Saving...":"To MEMORY.md"}),f&&(0,d.jsx)("button",{type:"button",disabled:g===`dismiss:${a.id}`||g===`${a.id}:memory`,onClick:()=>void f(a.id),style:{...bz,height:24,padding:"0 8px",opacity:g===`dismiss:${a.id}`||g===`${a.id}:memory`?.55:1,borderColor:"var(--text-dim)",color:"var(--text-dim)"},children:g===`dismiss:${a.id}`?"Dismissing…":"Ignore"})]})]},a.id))})]})}let bz={height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:550};function bA({tabs:a,activeTabId:b,onSelectTab:c,onCloseTab:f,onAskAI:g}){let[h,i]=(0,e.useState)(null);return(0,d.jsx)("div",{style:{display:"flex",alignItems:"flex-end",background:"var(--bg-panel)",overflowX:"auto",flexShrink:0,height:36},children:a.map(a=>{let e=a.id===b,j=!1!==a.closable;return(0,d.jsxs)("div",{onClick:()=>c(a.id),style:{display:"flex",alignItems:"center",gap:6,height:36,paddingLeft:12,paddingRight:6,borderRight:"1px solid var(--border)",background:e?"var(--bg)":"var(--bg-panel)",cursor:"pointer",fontSize:12,color:e?"var(--text)":"var(--text-muted)",whiteSpace:"nowrap",maxWidth:180,minWidth:80,flexShrink:0,userSelect:"none",transition:"background 0.1s, color 0.1s"},children:[(0,d.jsx)("span",{style:{flexShrink:0,opacity:e?1:.7,display:"flex",alignItems:"center"},children:"files"===a.icon?(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M3 7.5V6a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v1.5"}),(0,d.jsx)("path",{d:"M3 7.5h18l-1.6 9.6A2 2 0 0 1 17.4 19H6.6a2 2 0 0 1-2-1.9z"})]}):"report"===a.icon?(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,d.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,d.jsx)("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),(0,d.jsx)("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]}):"tools"===a.icon?(0,d.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.1-3.1a6 6 0 0 1-7.9 7.9l-5.7 5.7a2.1 2.1 0 0 1-3-3l5.7-5.7a6 6 0 0 1 7.9-7.9z"})}):a2(a.filePath??a.label,13)}),(0,d.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",flex:1,fontWeight:e?500:400},title:a.filePath??a.label,children:a.label}),j&&(0,d.jsxs)(d.Fragment,{children:[e&&g&&a.filePath&&!a.icon&&(0,d.jsx)("button",{onClick:b=>{b.stopPropagation(),g(a.filePath)},title:`Ask AI about ${a.label}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:"transparent",border:"none",borderRadius:3,color:"var(--accent)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s"},children:(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M15 18H3"}),(0,d.jsx)("path",{d:"M17 6H3"}),(0,d.jsx)("path",{d:"M21 12H3"})]})}),(0,d.jsx)("button",{onClick:b=>{b.stopPropagation(),f(a.id)},onMouseEnter:()=>i(a.id),onMouseLeave:()=>i(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:h===a.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:3,color:h===a.id?"var(--text)":"var(--text-dim)",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.1s, color 0.1s"},title:"Close",children:(0,d.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,d.jsx)("line",{x1:"2",y1:"2",x2:"8",y2:"8"}),(0,d.jsx)("line",{x1:"8",y1:"2",x2:"2",y2:"8"})]})})]})]},a.id)})})}function bB(a){return"python"===a?"#3572A5":"#198CE7"}let bC=new Set(["png","jpg","jpeg","webp","gif","svg"]);function bD(a){let b=a.split("/").filter(Boolean).map(encodeURIComponent);return`/api/files/${b.join("/")}?type=read&raw=1`}function bE(a){return!Number.isFinite(a)||a<=0?"0.0G":`${(a/1024/1024/1024).toFixed(1)}G`}function bF({active:a,label:b,count:c,onClick:e}){return(0,d.jsxs)("button",{type:"button",onClick:e,style:{height:26,padding:"0 9px",border:`1px solid ${a?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:5,background:a?"var(--bg-selected)":"var(--bg)",color:a?"var(--accent)":"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[b,"number"==typeof c?` (${c})`:""]})}let bG={height:24,padding:"0 8px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:10,fontWeight:600,whiteSpace:"nowrap"};function bH({status:a}){return(0,d.jsx)("span",{style:{color:"succeeded"===a?"#34d399":"failed"===a?"#f87171":"var(--text-dim)",fontSize:10,fontWeight:700,fontFamily:"var(--font-mono)"},children:"succeeded"===a?"✅":"failed"===a?"❌":"⬜"})}function bI({sessionId:a,cwd:b,onAskAboutCell:c,onAskAboutArtifact:f,onEditArtifact:g,onOpenArtifact:h}){let[i,j]=(0,e.useState)(null),[k,l]=(0,e.useState)(!0),[m,n]=(0,e.useState)(null),[o,p]=(0,e.useState)(new Set),[q,r]=(0,e.useState)("runs"),[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)(!1),[w,x]=(0,e.useState)(null),[y,z]=(0,e.useState)(!1);(0,e.useCallback)(async()=>{if(a)try{let c=new URLSearchParams;c.set("sessionId",a),b&&c.set("cwd",b);let d=await fetch(`/api/plot-kernels/status?${c}`),e=await d.json();if(!d.ok||e.error)throw Error(e.error??`HTTP ${d.status}`);t(e)}catch{}},[a,b]);let A=(0,e.useCallback)(async()=>{if(!u&&a){v(!0),x(null);try{let b=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:a})}),c=await b.json();if(!b.ok||!c.success)throw Error(c.error??`HTTP ${b.status}`);t(null)}catch(a){x(a instanceof Error?a.message:String(a))}finally{v(!1)}}},[a,u]),B=(0,e.useCallback)(async()=>{if(a){z(!0);try{let b=await fetch(`/api/sessions/${encodeURIComponent(a)}/workbench-review`),c=await b.json();if(!b.ok||c.error)throw Error(c.error??`HTTP ${b.status}`);j(a=>a?{...a,review:c}:a)}catch{}finally{z(!1)}}},[a]),C=(0,e.useCallback)(()=>{if(!i||0===i.cells.length)return;let b="r"===i.language?"R":"python",c=new Blob([JSON.stringify({nbformat:4,nbformat_minor:5,metadata:{kernelspec:{display_name:"R"===b?"R":"Python 3",language:b.toLowerCase(),name:"R"===b?"ir":"python3"},language_info:{name:b.toLowerCase()}},cells:i.cells.map(a=>{let b=[];for(let c of(a.stdoutPreview&&b.push({output_type:"stream",name:"stdout",text:a.stdoutPreview}),a.stderrPreview&&b.push({output_type:"stream",name:"stderr",text:a.stderrPreview}),a.artifacts)){let a=c.path.split(".").pop()?.toLowerCase();b.push(a&&bC.has(a)?{output_type:"display_data",data:{"image/png":""},metadata:{"annovibe-artifact":c.path}}:{output_type:"display_data",data:{"text/plain":c.path},metadata:{"annovibe-artifact":c.path}})}return{cell_type:"code",metadata:{},source:a.code.split("\n").map(a=>a+"\n"),outputs:b,execution_count:null}})},null,2)],{type:"application/x-ipynb+json"}),d=URL.createObjectURL(c),e=document.createElement("a");e.href=d,e.download=`workbench_${a.slice(0,8)}.ipynb`,document.body.appendChild(e),e.click(),document.body.removeChild(e),URL.revokeObjectURL(d)},[i,a]),D=(0,e.useCallback)(()=>{if(!i?.notes)return;let a=i.notes.map(a=>`#${a.cellIndex} ${a.title}
24
+ ${a.summary}`).join("\n\n");navigator.clipboard.writeText(a)},[i]),E=(0,e.useMemo)(()=>i?.artifacts??[],[i]),F=(0,e.useMemo)(()=>{if(!i)return null;let a="python"===i.language?"Python":"r"===i.language?"R":"?",b=[a,i.kernelId,`${i.totalRuns} runs`].filter(Boolean).join(" \xb7 ");return{langLabel:a,subtitle:b}},[i]),G=(0,e.useMemo)(()=>s?.kernels?s.kernels.filter(b=>b.sessionId===a):[],[s,a]);if(k)return(0,d.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"Loading workbench state..."});if(m)return m.includes("no kernel state found")||m.includes("404")?(0,d.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No workbench runs yet."}):(0,d.jsxs)("div",{style:{padding:24,textAlign:"center",color:"#f87171",fontSize:12},children:["Failed to load workbench state: ",m]});if(!i||0===i.cells.length)return(0,d.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No workbench runs yet."});let{cells:H}=i,I=i.review?.issues.length??0;return(0,d.jsxs)("div",{style:{height:"100%",overflow:"auto",background:"var(--bg)",fontSize:12},children:[s&&s.currentSessionBytes>0&&(0,d.jsxs)("div",{style:{margin:10,padding:12,borderRadius:8,border:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Runtime Memory"}),(0,d.jsx)("div",{style:{marginTop:3,display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:(0,d.jsxs)("span",{style:{fontSize:12,color:"var(--text)",fontVariantNumeric:"tabular-nums"},children:[(0,d.jsx)("span",{style:{color:"var(--accent)",fontWeight:600},children:bE(s.currentSessionBytes)}),s.totalBytes!==s.currentSessionBytes&&(0,d.jsxs)("span",{style:{color:"var(--text-dim)"},children:[" / ",bE(s.totalBytes)," total"]})]})}),G.length>0&&(0,d.jsx)("div",{style:{marginTop:8,display:"flex",flexDirection:"column",gap:4},children:G.map((a,b)=>(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:[(0,d.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:bB(a.language),flexShrink:0}}),(0,d.jsx)("span",{style:{color:bB(a.language),fontWeight:600},children:a.language.toUpperCase()}),(0,d.jsx)("span",{children:bE(a.rssBytes)}),(0,d.jsxs)("span",{style:{color:"var(--text-dim)",fontSize:10},children:["PID ",a.pid]}),a.lastActivity&&(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,marginLeft:"auto"},children:new Date(a.lastActivity).toLocaleString()})]},a.pid||b))})]}),(0,d.jsx)("button",{type:"button",onClick:A,disabled:u,style:{flexShrink:0,height:30,padding:"0 12px",border:"1px solid rgba(239,68,68,0.35)",borderRadius:6,background:u?"var(--bg)":"rgba(239,68,68,0.08)",color:u?"var(--text-dim)":"#ef4444",cursor:u?"default":"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap",opacity:u?.55:1},children:u?"Releasing...":"Release Memory"})]}),w&&(0,d.jsx)("div",{style:{marginTop:8,padding:"7px 8px",border:"1px solid rgba(248,113,113,0.25)",borderRadius:6,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11},children:w})]}),F&&(0,d.jsxs)("div",{style:{padding:"10px 14px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Workbench"}),(0,d.jsxs)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)"},children:[F.subtitle," \xb7 ","live"===i.freshness?"live inspected":"inferred from executed cells"]}),i.review&&(0,d.jsxs)("div",{style:{marginTop:6,fontSize:10,color:i.review.issueCounts.error>0?"#f87171":i.review.issueCounts.warning>0?"#fbbf24":"#34d399"},children:["Review: ",0===I?"no issues":`${I} traceability issues`]})]}),(0,d.jsxs)("div",{style:{display:"flex",gap:6,flexShrink:0,flexWrap:"wrap",justifyContent:"flex-end"},children:["notes"===q&&(0,d.jsx)("button",{type:"button",onClick:D,style:bG,children:"Copy"}),"review"===q&&(0,d.jsx)("button",{type:"button",onClick:B,disabled:y,style:{...bG,opacity:y?.55:1},children:y?"Reviewing...":"Refresh"}),(0,d.jsx)("button",{type:"button",onClick:C,title:"Export as Jupyter notebook",style:bG,children:"Export .ipynb"})]})]}),(0,d.jsxs)("div",{style:{marginTop:10,display:"flex",gap:6,overflowX:"auto",paddingBottom:1},children:[(0,d.jsx)(bF,{active:"runs"===q,label:"Runs",count:H.length,onClick:()=>r("runs")}),(0,d.jsx)(bF,{active:"artifacts"===q,label:"Artifacts",count:E.length,onClick:()=>r("artifacts")}),(0,d.jsx)(bF,{active:"notes"===q,label:"Notes",count:i.notes?.length??H.length,onClick:()=>r("notes")}),(0,d.jsx)(bF,{active:"review"===q,label:"Review",count:I,onClick:()=>r("review")})]}),i.imports.length>0&&"runs"===q&&(0,d.jsxs)("div",{style:{marginTop:8},children:[(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginBottom:3},children:"Historically imported:"}),(0,d.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:3},children:[i.imports.slice(0,12).map(a=>(0,d.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:3,background:"var(--bg-selected)",color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:a.length<=30?a:a.slice(0,30)+"..."},a)),i.imports.length>12&&(0,d.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)"},children:["+",i.imports.length-12," more"]})]})]}),("live"===i.freshness?i.liveObjects.length>0:i.loadedObjects.length>0)&&"runs"===q&&(0,d.jsxs)("div",{style:{marginTop:6},children:[(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginBottom:3},children:"live"===i.freshness?"Live objects:":"Historically loaded:"}),(0,d.jsx)("div",{children:("live"===i.freshness?i.liveObjects:i.loadedObjects).slice(0,6).map(a=>(0,d.jsx)("span",{style:{fontSize:10,padding:"1px 6px",marginRight:4,borderRadius:3,background:"rgba(37,99,235,0.1)",color:"var(--accent)",fontFamily:"var(--font-mono)"},title:"live"===i.freshness&&"type"in a?`${a.type}${a.shape?` (${a.shape})`:""}`:void 0,children:a.name},a.name))})]})]}),"artifacts"===q&&(0,d.jsx)("div",{style:{padding:10},children:0===E.length?(0,d.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No generated artifacts yet."}):(0,d.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(150px, 1fr))",gap:8},children:E.map(a=>(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,overflow:"hidden",background:"var(--bg-panel)"},children:["image"===a.kind?(0,d.jsx)("button",{type:"button",onClick:()=>h?.(a.path),style:{display:"block",width:"100%",padding:0,border:"none",background:"transparent",cursor:"pointer"},children:(0,d.jsx)("img",{src:bD(a.path),alt:a.fileName,loading:"lazy",style:{width:"100%",height:118,objectFit:"cover",display:"block"}})}):(0,d.jsx)("button",{type:"button",onClick:()=>h?.(a.path),style:{width:"100%",height:118,border:"none",background:"var(--bg)",color:"var(--text-muted)",fontSize:11,cursor:"pointer",textTransform:"uppercase"},children:a.kind}),(0,d.jsxs)("div",{style:{padding:8},children:[(0,d.jsx)("div",{title:a.path,style:{fontSize:10,color:"var(--text)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.fileName}),(0,d.jsxs)("div",{style:{marginTop:5,display:"flex",alignItems:"center",gap:5,color:"var(--text-dim)",fontSize:10},children:[(0,d.jsxs)("span",{children:["#",a.provenance.cellIndex]}),(0,d.jsx)(bH,{status:a.provenance.status}),(0,d.jsx)("span",{children:a.provenance.language})]}),(0,d.jsxs)("div",{style:{marginTop:7,display:"flex",gap:5,flexWrap:"wrap"},children:[(0,d.jsx)("button",{type:"button",onClick:()=>f?.(a),style:bG,children:"Ask"}),(0,d.jsx)("button",{type:"button",onClick:()=>g?.(a),style:bG,children:"Edit"}),(0,d.jsx)("button",{type:"button",onClick:()=>h?.(a.path),style:bG,children:"Open"})]})]})]},a.id))})}),"notes"===q&&(0,d.jsx)("div",{style:{padding:12},children:0===(i.notes??[]).length?(0,d.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No research notes yet."}):(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:(i.notes??[]).map(a=>(0,d.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",paddingBottom:9},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11},children:[(0,d.jsxs)("span",{style:{color:"var(--text-dim)",fontFamily:"var(--font-mono)",minWidth:28},children:["#",a.cellIndex]}),(0,d.jsx)(bH,{status:a.status}),(0,d.jsx)("span",{style:{color:"var(--text)",fontWeight:650,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.title})]}),(0,d.jsx)("div",{style:{marginTop:5,color:"var(--text-muted)",fontSize:12,lineHeight:1.45},children:a.summary})]},a.id))})}),"review"===q&&(0,d.jsx)("div",{style:{padding:12},children:i.review&&0!==i.review.issues.length?(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:i.review.issues.map(a=>(0,d.jsxs)("div",{style:{padding:10,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,d.jsx)("span",{style:{color:"error"===a.severity?"#f87171":"warning"===a.severity?"#fbbf24":"var(--text-dim)",fontSize:11,fontWeight:700},children:a.severity.toUpperCase()}),a.cellIndex&&(0,d.jsxs)("span",{style:{color:"var(--text-dim)",fontSize:10},children:["Cell #",a.cellIndex]})]}),(0,d.jsx)("div",{style:{marginTop:5,color:"var(--text)",fontSize:12,fontWeight:650},children:a.title}),(0,d.jsx)("div",{style:{marginTop:4,color:"var(--text-muted)",fontSize:11,lineHeight:1.45},children:a.detail})]},a.id))}):(0,d.jsx)("div",{style:{padding:24,textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No deterministic traceability issues found."})}),"runs"===q&&(0,d.jsx)("div",{children:H.map(a=>{let b,e=o.has(a.index),f="failed"===a.status;return(0,d.jsxs)("div",{style:{borderBottom:"1px solid var(--border)"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:0,background:e?"var(--bg-selected)":"transparent",transition:"background 0.1s"},children:[(0,d.jsxs)("button",{type:"button",onClick:()=>{var b;return b=a.index,void p(a=>{let c=new Set(a);return c.has(b)?c.delete(b):c.add(b),c})},style:{display:"flex",alignItems:"center",gap:6,flex:1,minWidth:0,padding:"6px 14px",border:"none",background:"transparent",cursor:"pointer",fontSize:11,color:"var(--text)",textAlign:"left"},children:[(0,d.jsx)("span",{style:{flexShrink:0,fontSize:10},children:e?"v":">"}),(0,d.jsxs)("span",{style:{fontSize:10,fontWeight:600,color:"var(--text-dim)",minWidth:24},children:["#",a.index]}),(0,d.jsx)(bH,{status:a.status}),(0,d.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:a.title||"kernel_plot_run"}),(0,d.jsx)("span",{style:{flexShrink:0,fontSize:9,padding:"1px 5px",borderRadius:3,background:"var(--bg-hover)",color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:a.runtime??"kernel-lite"}),a.language&&(0,d.jsx)("span",{style:{flexShrink:0,fontSize:9,padding:"1px 5px",borderRadius:3,background:bB(a.language)+"18",color:bB(a.language),fontFamily:"var(--font-mono)"},children:a.language})]}),c&&(0,d.jsx)("button",{type:"button",onClick:b=>{b.stopPropagation(),c(a.code,a.index)},title:"Ask about this cell in chat",style:{...bG,marginRight:10,height:22},children:"Ask"})]}),e&&(0,d.jsxs)("div",{style:{padding:"0 14px 10px"},children:[(0,d.jsx)("pre",{style:{margin:"8px 0 0",padding:10,borderRadius:6,background:"var(--bg-panel)",border:"1px solid var(--border)",fontSize:11,lineHeight:1.5,color:"var(--text)",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:400,overflow:"auto"},children:a.code}),(a.stdoutPreview||a.stderrPreview)&&(0,d.jsxs)("div",{style:{marginTop:6,display:"grid",gap:4},children:[a.stdoutPreview&&(0,d.jsx)("pre",{style:{margin:0,padding:8,borderRadius:4,background:"var(--bg-panel)",border:"1px solid var(--border)",fontSize:10,lineHeight:1.45,color:f?"#fbbf24":"var(--text-muted)",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:a.stdoutPreview}),a.stderrPreview&&(0,d.jsx)("pre",{style:{margin:0,padding:8,borderRadius:4,background:"rgba(248,113,113,0.08)",border:"1px solid rgba(248,113,113,0.2)",fontSize:10,lineHeight:1.45,color:"#f87171",fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:160,overflow:"auto"},children:a.stderrPreview})]}),a.artifacts.length>0&&(0,d.jsxs)("div",{style:{marginTop:6},children:[(0,d.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",marginBottom:4},children:["Artifacts (",a.artifacts.length,"):"]}),(0,d.jsx)("div",{style:{display:"grid",gap:2},children:a.artifacts.map((a,b)=>(0,d.jsx)("div",{style:{fontSize:10,fontFamily:"var(--font-mono)",color:"var(--text-muted)",padding:"2px 0",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:a.path,children:a.path},b))})]}),0===(b=a.artifacts.filter(a=>{let b=a.path.split(".").pop()?.toLowerCase();return b&&bC.has(b)})).length?null:(0,d.jsxs)("div",{style:{marginTop:8},children:[(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginBottom:4},children:"Previews:"}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(120px, 1fr))",gap:6},children:[b.slice(0,8).map((a,b)=>(0,d.jsx)("button",{type:"button",onClick:()=>h?.(a.path),title:a.path.split("/").pop()||a.path,style:{display:"block",border:"1px solid var(--border)",borderRadius:6,overflow:"hidden",background:"var(--bg-panel)",padding:0,cursor:"pointer"},children:(0,d.jsx)("img",{src:bD(a.path),alt:a.path.split("/").pop()||`Output ${b+1}`,loading:"lazy",style:{width:"100%",height:100,objectFit:"cover",display:"block"}})},b)),b.length>8&&(0,d.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",padding:8,textAlign:"center"},children:["+",b.length-8," more"]})]})]})]})]},a.toolCallId)})})]})}function bJ(a){let b=a,c=0;for(;1===b.children.length;)b=b.children[0],c++;return{node:b,skipped:c}}function bK({node:a,activePathIds:b,depth:c,isLast:e,parentLines:f,onSelect:g}){let{node:h,skipped:i}=bJ(a),j=b.has(h.entry.id),k=b.has(a.entry.id)||b.has(h.entry.id),l=function(a){if("message"===a.type&&"message"in a){let b=a.message,c=b.content,d="";if("string"==typeof c?d=c:Array.isArray(c)&&(d=c.filter(a=>"text"===a.type).map(a=>a.text).join(" ")),d.length>40&&(d=d.slice(0,40)+"…"),d)return d;if("assistant"===b.role)return"[assistant]"}return a.type}(h.entry),m="message"===h.entry.type&&"message"in h.entry?h.entry.message.role:null;return(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",height:24,cursor:"pointer"},onClick:()=>g(h.entry.id),children:[f.map((a,b)=>(0,d.jsx)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:a&&(0,d.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:0,width:1,background:"var(--border)"}})},b)),(0,d.jsxs)("div",{style:{width:16,flexShrink:0,position:"relative",height:"100%",alignSelf:"stretch"},children:[(0,d.jsx)("div",{style:{position:"absolute",left:7,top:0,bottom:e?"50%":0,width:1,background:"var(--border)"}}),(0,d.jsx)("div",{style:{position:"absolute",left:7,top:"50%",width:9,height:1,background:"var(--border)"}})]}),(0,d.jsx)("div",{style:{width:7,height:7,borderRadius:"50%",flexShrink:0,background:j?"var(--accent)":k?"var(--text-muted)":"var(--border)",border:j?"none":"1px solid var(--text-dim)",marginRight:6,transition:"background 0.12s"}}),m&&(0,d.jsx)("span",{style:{fontSize:9,fontFamily:"var(--font-mono)",color:"user"===m?"var(--accent)":"var(--text-dim)",background:"user"===m?"rgba(37,99,235,0.08)":"var(--bg-hover)",border:`1px solid ${"user"===m?"rgba(37,99,235,0.2)":"var(--border)"}`,borderRadius:3,padding:"0 4px",marginRight:5,flexShrink:0,lineHeight:"16px"},children:"user"===m?"U":"A"}),i>0&&(0,d.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginRight:5,flexShrink:0},children:["+",i]}),(0,d.jsx)("span",{style:{fontSize:11,color:j?"var(--text)":k?"var(--text-muted)":"var(--text-dim)",fontWeight:j?500:400,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:l})]}),h.children.map((a,i)=>(0,d.jsx)(bK,{node:a,activePathIds:b,depth:c+1,isLast:i===h.children.length-1,parentLines:[...f,!e],onSelect:g},a.entry.id))]})}function bL({tree:a,activeLeafId:b,onLeafChange:c,inline:f,containerRef:g,open:h,onToggle:i,hasSession:j,embedded:k}){let[l,m]=(0,e.useState)(!1),n=void 0!==h?h:l,o=(0,e.useRef)(null),[p,q]=(0,e.useState)(null),r=(0,e.useMemo)(()=>b?new Set(function a(c,d){for(let e of c){let c=[...d,e.entry.id];if(e.entry.id===b)return c;let f=a(e.children,c);if(f)return f}return null}(a,[])??[]):new Set,[a,b]),s=(0,e.useCallback)(a=>{c(a)},[c]),t=j?!function a(b){for(let c of b)if(c.children.length>1||a(c.children))return!0;return!1}(a)?"This session has no branches":null:"No active session",u=a.length>0?bJ(a[0]):null,v=u?.node??null,w=!t&&v&&v.children.length>1,x=(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:w?"var(--accent)":"var(--text-dim)",flexShrink:0},children:[(0,d.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,d.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,d.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,d.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]}),y=(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"var(--text-dim)",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",style:{marginLeft:2,transform:n?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,d.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})});return k?(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"8px 10px",borderBottom:w?"1px solid var(--border)":"none"},children:[x,(0,d.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:"Branches"})]}),w&&v?(0,d.jsx)("div",{style:{padding:"4px 10px 8px",maxHeight:260,overflowY:"auto"},children:v.children.map((a,b)=>(0,d.jsx)(bK,{node:a,activePathIds:r,depth:0,isLast:b===v.children.length-1,parentLines:[],onSelect:s},a.entry.id))}):(0,d.jsx)("div",{style:{padding:"0 10px 10px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:t??"This session has no branches"})]}):f?(0,d.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,d.jsxs)("button",{ref:o,className:"topbar-branches-button",onClick:()=>i?i():m(a=>!a),title:"Branches","aria-label":"Branches",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:n?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${n?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:n?"var(--text)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s, border-color 0.1s"},onMouseEnter:a=>{a.currentTarget.style.color="var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color=n?"var(--text)":"var(--text-muted)",a.currentTarget.style.background=n?"var(--bg-selected)":"var(--bg-panel)"},children:[(0,d.jsx)("span",{className:"topbar-branches-icon",children:x}),(0,d.jsx)("span",{className:"topbar-branches-label",children:"Branches"})]}),n&&p&&(0,d.jsx)("div",{style:{position:"fixed",top:p.top,left:p.left,width:p.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:w&&v?(0,d.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:v.children.map((a,b)=>(0,d.jsx)(bK,{node:a,activePathIds:r,depth:0,isLast:b===v.children.length-1,parentLines:[],onSelect:s},a.entry.id))}):(0,d.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:t})})]}):(0,d.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,d.jsxs)("button",{onClick:()=>m(a=>!a),style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 12px",background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",fontSize:11,textAlign:"left"},children:[x,(0,d.jsx)("span",{style:{color:"var(--text-muted)"},children:"Branches"}),y]}),n&&(0,d.jsx)("div",{style:{position:"absolute",top:"100%",left:0,right:0,background:"var(--bg)",borderBottom:"1px solid var(--border)",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100},children:w&&v?(0,d.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:v.children.map((a,b)=>(0,d.jsx)(bK,{node:a,activePathIds:r,depth:0,isLast:b===v.children.length-1,parentLines:[],onSelect:s},a.entry.id))}):(0,d.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:t??"This session has no branches"})})]})}function bM(a,b="0 0 24 24"){let c=({size:c=24,style:e})=>(0,d.jsx)("svg",{width:c,height:c,viewBox:b,fill:"none",style:e,children:a});return c.displayName="ProviderIcon",c}let bN=bM((0,d.jsx)("path",{d:"M17.5 3H6.5L3 21h4l1.2-6h7.6l1.2 6h4L17.5 3zm-2.3 9H8.8L12 5.5 15.2 12z",fill:"currentColor"})),bO=bM((0,d.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round"})),bP=bM((0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 01-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z",fill:"#4285F4"}),(0,d.jsx)("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),(0,d.jsx)("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),(0,d.jsx)("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]})),bQ=bM((0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#4D6BFE"}),(0,d.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"10",fontWeight:"bold",fontFamily:"sans-serif",children:"DS"})]})),bR=bM((0,d.jsx)("path",{d:"M4 4h16v16H4z",fill:"#F55036"}),"0 0 24 24"),bS=bM((0,d.jsx)("path",{d:"M4 4h5v5H4zm5.5 0h5v5h-5zM15 4h5v5h-5zM4 9.5h5v5H4zm5.5 5.5h5v5h-5zM15 9.5h5v5h-5z",fill:"#FA6F00"})),bT=bM((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),bU=bM((0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#00D4AA"}),(0,d.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"MM"})]})),bV=bM((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#FF5722"}),"0 0 24 24"),bW=bM((0,d.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 5h2v3h-2V7zm0 4h2v2h-2v-2zm3 5H7v-2h7v2z",fill:"#FFD21E"})),bX=bM((0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#E84026"}),(0,d.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"CB"})]})),bY=bM((0,d.jsx)("path",{d:"M12 2l9 5v10l-9 5-9-5V7l9-5z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})),bZ=bM((0,d.jsx)("path",{d:"M4 4l8 8 8-8M4 20l8-8 8 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})),b$=bM((0,d.jsx)("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 5l4 3-4 3V7z",fill:"#F38020"})),b_={anthropic:{Icon:bN,hasColor:!1},openai:{Icon:bO,hasColor:!1},"openai-codex":{Icon:bO,hasColor:!1},google:{Icon:bP,hasColor:!0},"google-vertex":{Icon:bP,hasColor:!0},deepseek:{Icon:bQ,hasColor:!0},groq:{Icon:bR,hasColor:!1},mistral:{Icon:bS,hasColor:!0},moonshotai:{Icon:bT,hasColor:!1},"moonshotai-cn":{Icon:bT,hasColor:!1},moonshot:{Icon:bT,hasColor:!1},minimax:{Icon:bU,hasColor:!0},"minimax-cn":{Icon:bU,hasColor:!0},fireworks:{Icon:bV,hasColor:!0},huggingface:{Icon:bW,hasColor:!0},cerebras:{Icon:bX,hasColor:!0},openrouter:{Icon:bY,hasColor:!1},xai:{Icon:bZ,hasColor:!1},"cloudflare-ai-gateway":{Icon:b$,hasColor:!0},"cloudflare-workers-ai":{Icon:b$,hasColor:!0},"vercel-ai-gateway":{Icon:bM((0,d.jsx)("path",{d:"M12 2L22 20H2L12 2z",fill:"currentColor"})),hasColor:!1},"github-copilot":{Icon:bM((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),hasColor:!1},"amazon-bedrock":{Icon:bM((0,d.jsx)("path",{d:"M3 15h2l1-3h2l1 3h2V9H9v3L8 9H6l-1 3V9H3v6zm9 0h2v-2h2v-2h-2V9h-2v2h-2v2h2v2z",fill:"#FF9900"})),hasColor:!0},"azure-openai-responses":{Icon:bM((0,d.jsx)("path",{d:"M12 2L3 18h5l4-6 4 6h5L12 2z",fill:"#0078D4"})),hasColor:!0},"kimi-coding":{Icon:bM((0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#6C5CE7"}),(0,d.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"10",fontWeight:"bold",fontFamily:"sans-serif",children:"Ki"})]})),hasColor:!0},qwen:{Icon:bM((0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#615CED"}),(0,d.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"QW"})]})),hasColor:!0},zai:{Icon:bM((0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"3",fill:"#3859FF"}),(0,d.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"white",fontSize:"9",fontWeight:"bold",fontFamily:"sans-serif",children:"ZP"})]})),hasColor:!0},cohere:{Icon:bM((0,d.jsx)("path",{d:"M4 8h16v2H4zm0 4h12v2H4zm0 4h8v2H4z",fill:"#3059B1"})),hasColor:!0},perplexity:{Icon:bM((0,d.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"#1DB954",strokeWidth:"1.5",fill:"none",strokeLinejoin:"round"})),hasColor:!0},together:{Icon:bM((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#0F6CBD"}),"0 0 24 24"),hasColor:!0},grok:{Icon:bM((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),hasColor:!1}},b0=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],b1="openai-completions",b2={off:"none",xhigh:"xhigh"};function b3(a){return a?.toLowerCase().replace(/\s+/g,"-")??""}function b4(a){return/(^|[^a-z0-9])gpt-5($|[.-])/.test(b3(a))}function b5(a){return/[.-](minimal|low|medium|high|xhigh)$/.test(b3(a))}function b6(a){return b4(a.id)||b4(a.name)}function b7(a,b=b1){if(!b6(a))return a;let c=a.api??("openai-responses"===b?void 0:"openai-responses");if(b6(a)&&(b5(a.id)||b5(a.name))){let{reasoning:b,thinkingLevelMap:d,...e}=a;return{...e,api:c}}return{...a,api:c,reasoning:a.reasoning??!0,thinkingLevelMap:a.thinkingLevelMap??b2}}function b8({label:a,children:b}){return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,d.jsx)("label",{style:{fontSize:11,color:"var(--text-muted)",fontWeight:500},children:a}),b]})}let b9={padding:"6px 9px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",width:"100%",boxSizing:"border-box"};function ca({value:a,onChange:b,placeholder:c,mono:e}){return(0,d.jsx)("input",{value:a,onChange:a=>b(a.target.value),placeholder:c,style:{...b9,fontFamily:e?"var(--font-mono)":"inherit"}})}function cb({value:a,onChange:b,placeholder:c,mono:f,onKeyDown:g,autoComplete:h="off",spellCheck:i=!1,style:j}){let[k,l]=(0,e.useState)(!1);return(0,d.jsxs)("div",{style:{position:"relative",width:"100%",...j},children:[(0,d.jsx)("input",{type:k?"text":"password",value:a,onChange:a=>b(a.target.value),onKeyDown:g,placeholder:c,style:{...b9,paddingRight:34,fontFamily:f?"var(--font-mono)":"inherit"},autoComplete:h,spellCheck:i}),(0,d.jsx)("button",{type:"button",onClick:()=>l(a=>!a),"aria-label":k?"Hide API key":"Show API key",title:k?"Hide API key":"Show API key",style:{position:"absolute",right:5,top:"50%",transform:"translateY(-50%)",width:24,height:24,padding:0,border:"none",background:"transparent",color:"var(--text-dim)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:k?(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20C7 20 2.73 16.89 1 12a18.45 18.45 0 0 1 5.06-6.94"}),(0,d.jsx)("path",{d:"M9.9 4.24A10.94 10.94 0 0 1 12 4c5 0 9.27 3.11 11 8a18.5 18.5 0 0 1-2.16 3.19"}),(0,d.jsx)("path",{d:"M14.12 14.12A3 3 0 0 1 9.88 9.88"}),(0,d.jsx)("path",{d:"M1 1l22 22"})]}):(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8S1 12 1 12Z"}),(0,d.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]})}function cc({value:a,onChange:b,placeholder:c}){return(0,d.jsx)("input",{type:"number",value:a,onChange:a=>b(a.target.value),placeholder:c,style:b9})}function cd({value:a,onChange:b,options:c,required:e}){return(0,d.jsxs)("select",{value:a,onChange:a=>b(a.target.value),style:{...b9,color:a?"var(--text)":"var(--text-dim)"},children:[!e&&(0,d.jsx)("option",{value:"",children:"— inherit / none —"}),c.map(a=>(0,d.jsx)("option",{value:a,children:a},a))]})}function ce({label:a,checked:b,onChange:c}){return(0,d.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,cursor:"pointer",fontSize:12,color:"var(--text-muted)"},children:[(0,d.jsx)("input",{type:"checkbox",checked:b,onChange:a=>c(a.target.checked),style:{width:13,height:13,accentColor:"var(--accent)",cursor:"pointer"}}),a]})}function cf({children:a}){return(0,d.jsx)("div",{style:{fontSize:11,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em",marginBottom:2},children:a})}function cg({name:a,provider:b,onChange:c,onRename:f,onDelete:g}){let[h,i]=(0,e.useState)(a),j=(a,d)=>c({...b,[a]:d});return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,d.jsx)(cf,{children:"Provider"}),(0,d.jsx)("button",{onClick:g,style:{padding:"3px 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11},children:"Delete"})]}),(0,d.jsxs)(b8,{label:"Provider name",children:[(0,d.jsx)(ca,{value:h,onChange:i,placeholder:"provider-name",mono:!0}),h!==a&&h.trim()&&(0,d.jsx)("button",{onClick:()=>f(h.trim()),style:{marginTop:4,padding:"3px 10px",background:"var(--accent)",border:"none",borderRadius:4,color:"#fff",cursor:"pointer",fontSize:11,alignSelf:"flex-start"},children:"Rename"})]}),(0,d.jsx)(b8,{label:"Base URL",children:(0,d.jsx)(ca,{value:b.baseUrl??"",onChange:a=>j("baseUrl",a||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,d.jsxs)(b8,{label:"API Key",children:[(0,d.jsx)(cb,{value:b.apiKey??"",onChange:a=>j("apiKey",a||void 0),placeholder:"ENV_VAR_NAME, !shell-command, or literal key",mono:!0}),(0,d.jsxs)("span",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:["Prefix with ",(0,d.jsx)("code",{style:{fontFamily:"var(--font-mono)"},children:"!"})," to run a shell command, or use an env var name"]})]}),(0,d.jsx)(b8,{label:"API",children:(0,d.jsx)(cd,{value:b.api??"openai-completions",onChange:a=>j("api",a),options:b0,required:!0})})]})}let ch=["off","minimal","low","medium","high","xhigh"],ci={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c"};function cj({value:a,onChange:b}){let c=a??{},e=(a,d)=>{let e={...c};"omit"===d?delete e[a]:e[a]=d,b(Object.keys(e).length?e:void 0)};return(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:ch.map(a=>{let b=c[a],f=a in c?null===b?"null":"string":"omit",g="string"==typeof b?b:"",h=ci[a],i={padding:"4px 10px",fontSize:10,border:"none",cursor:"pointer",fontWeight:400,transition:"background 0.1s, color 0.1s",whiteSpace:"nowrap",background:"var(--bg-panel)",color:"var(--text-dim)"},j={background:"var(--accent)",color:"#fff",fontWeight:600};return(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 4px",borderRadius:6,background:"transparent",border:"1px solid transparent"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:5,width:68,flexShrink:0},children:[(0,d.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:h,flexShrink:0,opacity:"null"===f?.3:1}}),(0,d.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"null"===f?"var(--text-dim)":"var(--text-muted)",textDecoration:"null"===f?"line-through":"none"},children:a})]}),(0,d.jsxs)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",flexShrink:0},children:[(0,d.jsx)("button",{onClick:()=>e(a,"omit"),style:{...i,..."omit"===f?j:{}},children:"Default"}),(0,d.jsx)("button",{onClick:()=>e(a,null),style:{...i,borderLeft:"1px solid var(--border)",..."null"===f?{background:"#ef4444",color:"#fff",fontWeight:600}:{}},children:"Disabled"})]}),(0,d.jsxs)("div",{style:{display:"flex",borderRadius:5,border:`1px solid ${"string"===f?"var(--accent)":"var(--border)"}`,overflow:"hidden",transition:"border-color 0.1s"},children:[(0,d.jsx)("button",{onClick:()=>e(a,g||a),style:{...i,..."string"===f?j:{},borderRight:"1px solid var(--border)",flexShrink:0},children:"Custom"}),(0,d.jsx)("input",{value:g,onChange:b=>e(a,b.target.value),onFocus:()=>{"string"!==f&&e(a,g||a)},placeholder:a,maxLength:10,style:{width:"12ch",background:"string"===f?"var(--bg)":"var(--bg-panel)",border:"none",outline:"none",color:"string"===f?"var(--text)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11,padding:"4px 7px",transition:"background 0.1s, color 0.1s"}})]})]},a)})})}let ck={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function cl({providerName:a,provider:b,model:c,onChange:f,onDelete:g}){let[h,i]=(0,e.useState)({phase:"idle"}),j=(a,b)=>f({...c,[a]:b}),k=a=>{f(b7(a,b.api??b1))},l=(()=>{if("idle"===h.phase)return null;if("testing"===h.phase)return"Testing model connection...";let a=[void 0!==h.latencyMs?`${h.latencyMs}ms`:null,void 0!==h.status?`HTTP ${h.status}`:null].filter(Boolean);return"success"===h.phase?["Connected",...a,h.responseText||null].filter(Boolean).join(" \xb7 "):["Failed",...a,h.message].filter(Boolean).join(" \xb7 ")})(),m=(0,e.useCallback)(async()=>{if(c.id.trim()&&"testing"!==h.phase){i({phase:"testing"});try{let d=await fetch("/api/models-config/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerName:a,provider:b,model:c})}),e=await d.json();if(!d.ok||!e.ok)return void i({phase:"error",message:e.error??`HTTP ${d.status}`,latencyMs:e.latencyMs,status:e.status});i({phase:"success",latencyMs:e.latencyMs,status:e.status,responseText:e.responseText})}catch(a){i({phase:"error",message:a instanceof Error?a.message:String(a)})}}},[c,b,a,h.phase]);return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,d.jsx)(cf,{children:"Model"}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[l&&(0,d.jsx)("span",{title:l,style:{maxWidth:260,height:24,padding:"0 8px",border:`1px solid ${"error"===h.phase?"#fecaca":"success"===h.phase?"#bbf7d0":"var(--border)"}`,borderRadius:4,background:"error"===h.phase?"#fee2e2":"success"===h.phase?"#dcfce7":"#e5e7eb",color:"#111827",fontSize:11,display:"inline-flex",alignItems:"center",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",boxSizing:"border-box"},children:l}),(0,d.jsxs)("button",{onClick:m,disabled:!c.id.trim()||"testing"===h.phase,title:"Test model connection",style:{height:24,padding:"0 8px",background:"success"===h.phase?"#16a34a":"none",border:`1px solid ${"success"===h.phase?"#16a34a":"var(--border)"}`,borderRadius:4,color:"success"===h.phase?"#fff":c.id.trim()&&"testing"!==h.phase?"var(--text-muted)":"var(--text-dim)",cursor:c.id.trim()&&"testing"!==h.phase?"pointer":"not-allowed",fontSize:11,display:"inline-flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box",gap:5},children:["success"===h.phase&&(0,d.jsx)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("polyline",{points:"20 6 9 17 4 12"})}),"testing"===h.phase?"Testing…":"success"===h.phase?"OK":"Test"]}),(0,d.jsx)("button",{onClick:g,style:{height:24,padding:"0 8px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:4,color:"#ef4444",cursor:"pointer",fontSize:11,boxSizing:"border-box"},children:"Remove"})]})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,d.jsx)(b8,{label:"ID *",children:(0,d.jsx)(ca,{value:c.id,onChange:a=>k({...c,id:a}),placeholder:"model-id",mono:!0})}),(0,d.jsx)(b8,{label:"Name",children:(0,d.jsx)(ca,{value:c.name??"",onChange:a=>k({...c,name:a||void 0}),placeholder:"Display name"})})]}),(0,d.jsx)(b8,{label:"API override",children:(0,d.jsx)(cd,{value:c.api??"",onChange:a=>j("api",a||void 0),options:b0})}),(0,d.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,d.jsx)(ce,{label:"Reasoning / thinking",checked:c.reasoning??!1,onChange:a=>j("reasoning",a||void 0)}),(0,d.jsx)(ce,{label:"Image input",checked:c.input?.includes("image")??!1,onChange:a=>j("input",a?["text","image"]:["text"])})]}),c.reasoning&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(ce,{label:"DeepSeek thinking compat",checked:c.compat?.thinkingFormat==="deepseek",onChange:a=>f(function(a,b){if(b)return{...a,compat:{...a.compat??{},...ck}};if(!a.compat)return a;let c={...a.compat};return delete c.thinkingFormat,delete c.requiresReasoningContentOnAssistantMessages,{...a,compat:Object.keys(c).length?c:void 0}}(c,a))}),(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[(0,d.jsx)(cf,{children:"Thinking level map"}),c.thinkingLevelMap&&(0,d.jsx)("button",{onClick:()=>j("thinkingLevelMap",void 0),style:{fontSize:10,padding:"2px 7px",background:"none",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-dim)",cursor:"pointer"},children:"clear all"})]}),(0,d.jsx)(cj,{value:c.thinkingLevelMap,onChange:a=>j("thinkingLevelMap",a)})]})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,d.jsx)(b8,{label:"Context window (tokens)",children:(0,d.jsx)(cc,{value:void 0!==c.contextWindow?String(c.contextWindow):"",onChange:a=>j("contextWindow",a?parseInt(a):void 0),placeholder:"128000"})}),(0,d.jsx)(b8,{label:"Max output tokens",children:(0,d.jsx)(cc,{value:void 0!==c.maxTokens?String(c.maxTokens):"",onChange:a=>j("maxTokens",a?parseInt(a):void 0),placeholder:"16384"})})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)(cf,{children:"Cost (per million tokens)"}),(0,d.jsx)("div",{style:{marginTop:8,display:"grid",gridTemplateColumns:"1fr 1fr 1fr 1fr",gap:8},children:["input","output","cacheRead","cacheWrite"].map(a=>(0,d.jsx)(b8,{label:a,children:(0,d.jsx)(cc,{value:c.cost?.[a]!==void 0?String(c.cost[a]):"",onChange:b=>{let d;return d=parseFloat(b),void f({...c,cost:{...c.cost??{},[a]:isNaN(d)?void 0:d}})},placeholder:"0"})},a))})]})]})}function cm({provider:a,onRefresh:b}){let[c,f]=(0,e.useState)({phase:"idle"}),[g,h]=(0,e.useState)(""),i=(0,e.useRef)(null),j=(0,e.useRef)(null),k=(0,e.useCallback)(()=>{i.current?.close(),f({phase:"connecting"}),h("");let c=new EventSource(`/api/auth/login/${encodeURIComponent(a.id)}`);i.current=c,c.onmessage=a=>{let d=JSON.parse(a.data);"auth"===d.type?(f({phase:"auth",url:d.url,instructions:d.instructions??null,token:d.token}),window.open(d.url,"_blank","noopener,noreferrer")):"device_code"===d.type?(f({phase:"device_code",userCode:d.userCode,verificationUri:d.verificationUri,intervalSeconds:d.intervalSeconds??null,expiresInSeconds:d.expiresInSeconds??null}),window.open(d.verificationUri,"_blank","noopener,noreferrer")):"prompt_request"===d.type?f({phase:"prompt",message:d.message,placeholder:d.placeholder??null,token:d.token}):"select_request"===d.type?f({phase:"select",message:d.message,options:d.options??[],token:d.token}):"progress"===d.type?f({phase:"progress",message:d.message}):"success"===d.type?(c.close(),f({phase:"success"}),b()):"error"===d.type?(c.close(),f({phase:"error",message:d.message})):"cancelled"===d.type&&(c.close(),f({phase:"idle"}))},c.onerror=()=>{c.close(),f(a=>"success"===a.phase?a:{phase:"error",message:"Connection lost"})}},[a.id,b]),l=(0,e.useCallback)(async()=>{await fetch(`/api/auth/logout/${encodeURIComponent(a.id)}`,{method:"POST"}),f({phase:"idle"}),b()},[a.id,b]),m=(0,e.useCallback)(async(b,c)=>{if(c.trim()){f({phase:"progress",message:"Verifying…"});try{let d=await fetch(`/api/auth/login/${encodeURIComponent(a.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:b,code:c.trim()})});if(!d.ok){let a=await d.json().catch(()=>({}));f({phase:"error",message:a.error??`Server error ${d.status}`});return}h("")}catch(a){f({phase:"error",message:a instanceof Error?a.message:"Network error"})}}},[a.id]),n=(0,e.useCallback)(async(b,c)=>{f({phase:"progress",message:"Continuing…"});try{let d=await fetch(`/api/auth/login/${encodeURIComponent(a.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:b,code:c})});if(!d.ok){let a=await d.json().catch(()=>({}));f({phase:"error",message:a.error??`Server error ${d.status}`})}}catch(a){f({phase:"error",message:a instanceof Error?a.message:"Network error"})}},[a.id]),o="connecting"===c.phase||"progress"===c.phase||"auth"===c.phase||"device_code"===c.phase||"prompt"===c.phase||"select"===c.phase;return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,d.jsx)(cf,{children:"Subscription"}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,d.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:a.loggedIn?"#4ade80":"var(--border)",display:"inline-block"}}),(0,d.jsx)("span",{style:{fontSize:11,color:a.loggedIn?"#4ade80":"var(--text-dim)"},children:a.loggedIn?"connected":"not connected"})]})]}),(0,d.jsxs)("div",{style:{minHeight:48},children:["idle"===c.phase&&(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:a.loggedIn?"Already connected. You can re-login or disconnect.":`Connect your ${a.name} account.`}),"connecting"===c.phase&&(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:"Opening browser…"}),"select"===c.phase&&(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:c.message}),(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:c.options.map(a=>(0,d.jsx)("button",{onClick:()=>n(c.token,a.id),style:{padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",cursor:"pointer",fontSize:12,textAlign:"left"},children:a.label},a.id))})]}),("auth"===c.phase||"prompt"===c.phase)&&(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"auth"===c.phase?"Complete sign-in in the browser, then copy the redirect URL from the address bar and paste it below.":c.message}),"auth"===c.phase&&(0,d.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:["If the browser window did not open,"," ",(0,d.jsx)("a",{href:c.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:"click here to open the login page"}),"."]}),(0,d.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,d.jsx)("input",{ref:j,value:g,onChange:a=>h(a.target.value),onKeyDown:a=>{"Enter"===a.key&&m(c.token,g)},placeholder:"auth"===c.phase?"http://localhost:1455/auth/callback?code=…":c.placeholder??"Enter value…",style:{flex:1,padding:"6px 9px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)",boxSizing:"border-box"}}),(0,d.jsx)("button",{onClick:()=>m(c.token,g),disabled:!g.trim(),style:{padding:"6px 12px",background:g.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:g.trim()?"#fff":"var(--text-dim)",cursor:g.trim()?"pointer":"not-allowed",fontSize:12,fontWeight:600,flexShrink:0},children:"Submit"})]})]}),"device_code"===c.phase&&(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Open the verification page and enter this code:"}),(0,d.jsx)("div",{style:{padding:"8px 10px",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text)",fontSize:16,fontWeight:700,fontFamily:"var(--font-mono)",letterSpacing:0},children:c.userCode}),(0,d.jsxs)("p",{style:{margin:0,fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,d.jsx)("a",{href:c.verificationUri,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent)",wordBreak:"break-all"},children:c.verificationUri}),c.expiresInSeconds?` Expires in ${Math.ceil(c.expiresInSeconds/60)} minutes.`:""]})]}),"progress"===c.phase&&(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)"},children:c.message}),"success"===c.phase&&(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"#4ade80"},children:"Connected successfully."}),"error"===c.phase&&(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:c.message})]}),(0,d.jsx)("div",{style:{display:"flex",gap:8},children:o?(0,d.jsx)("button",{onClick:()=>{i.current?.close(),f({phase:"idle"})},style:{padding:"5px 12px",background:"none",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("button",{onClick:k,style:{padding:"5px 14px",background:"var(--accent)",border:"none",borderRadius:5,color:"#fff",cursor:"pointer",fontSize:12,fontWeight:600},children:a.loggedIn?"Re-login":"Login"}),a.loggedIn&&(0,d.jsx)("button",{onClick:l,style:{padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:"pointer",fontSize:12},children:"Disconnect"})]})})]})}function cn({provider:a,onRefresh:b}){let[c,f]=(0,e.useState)(""),[g,h]=(0,e.useState)(!1),[i,j]=(0,e.useState)(!1),[k,l]=(0,e.useState)(null),[m,n]=(0,e.useState)(!1),o=(0,e.useCallback)(async()=>{if(c.trim()){h(!0),l(null),n(!1);try{let d=await fetch(`/api/auth/api-key/${encodeURIComponent(a.id)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:c.trim()})}),e=await d.json();!d.ok||e.error?l(e.error??`HTTP ${d.status}`):(f(""),n(!0),setTimeout(()=>n(!1),2e3),b())}catch(a){l(String(a))}finally{h(!1)}}},[c,a.id,b]),p=(0,e.useCallback)(async()=>{j(!0),l(null);try{let c=await fetch(`/api/auth/api-key/${encodeURIComponent(a.id)}`,{method:"DELETE"}),d=await c.json();!c.ok||d.error?l(d.error??`HTTP ${c.status}`):b()}catch(a){l(String(a))}finally{j(!1)}},[a.id,b]);return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,d.jsx)(cf,{children:"API Key"}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,d.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:a.configured?"#4ade80":"var(--border)",display:"inline-block"}}),(0,d.jsx)("span",{style:{fontSize:11,color:a.configured?"#4ade80":"var(--text-dim)"},children:a.configured?"configured":"not configured"})]})]}),(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:a.configured?"API key is stored. Enter a new key below to replace it, or disconnect to remove it.":`Enter your ${a.displayName} API key to enable ${a.modelCount} model${1!==a.modelCount?"s":""}.`}),(0,d.jsx)(b8,{label:"API Key",children:(0,d.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,d.jsx)(cb,{value:c,onChange:f,onKeyDown:a=>{"Enter"===a.key&&c.trim()&&o()},placeholder:a.configured?"Enter new key to replace…":"sk-…",style:{flex:1},autoComplete:"off",spellCheck:!1,mono:!0}),(0,d.jsxs)("button",{onClick:o,disabled:g||!c.trim()||m,style:{padding:"6px 12px",background:m?"#16a34a":c.trim()?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:5,color:c.trim()||m?"#fff":"var(--text-dim)",cursor:g||!c.trim()||m?"not-allowed":"pointer",fontSize:12,fontWeight:600,flexShrink:0,display:"flex",alignItems:"center",gap:5},children:[m&&(0,d.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("polyline",{points:"20 6 9 17 4 12"})}),m?"Saved":g?"Saving…":"Save"]})]})}),k&&(0,d.jsx)("p",{style:{margin:0,fontSize:12,color:"#f87171"},children:k}),a.configured&&(0,d.jsx)("button",{onClick:p,disabled:i,style:{alignSelf:"flex-start",padding:"5px 12px",background:"none",border:"1px solid rgba(239,68,68,0.3)",borderRadius:5,color:"#ef4444",cursor:i?"not-allowed":"pointer",fontSize:12},children:i?"Removing…":"Disconnect"})]})}function co({id:a,size:b}){let c=b_[a];return c?c.hasColor?(0,d.jsx)(c.Icon,{size:b}):(0,d.jsx)(c.Icon,{size:b,style:{color:"var(--text-muted)"}}):null}function cp({oauthProviders:a,apiKeyProviders:b,onSelectOAuth:c,onSelectApiKey:f,onAddCustom:g,onDiscover:h,onClose:i}){let[j,k]=(0,e.useState)(""),l=(0,e.useRef)(null),m=j.trim().toLowerCase(),n=a.filter(a=>!a.loggedIn&&(!m||a.name.toLowerCase().includes(m))),o=b.filter(a=>!a.configured&&(!m||a.displayName.toLowerCase().includes(m)||a.id.toLowerCase().includes(m))),p=!m||"custom".includes(m)||"openai-compatible".includes(m)||"anthropic-compatible".includes(m),q=!m||"discover".includes(m)||"base url".includes(m)||"model import".includes(m),r=n.length+o.length+ +!!p+ +!!q,s={display:"flex",flexDirection:"row",alignItems:"center",gap:8,padding:"10px 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,boxSizing:"border-box",cursor:"pointer",minWidth:0,textAlign:"left",transition:"border-color 0.12s, background 0.12s",width:"100%"};return(0,d.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1100,background:"rgba(0,0,0,0.4)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:a=>{a.target===a.currentTarget&&i()},children:(0,d.jsxs)("div",{style:{width:820,maxWidth:"calc(100vw - 32px)",maxHeight:"min(72vh, calc(100vh - 32px))",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.22)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:"10px 14px",borderBottom:"1px solid var(--border)",flexShrink:0,display:"flex",alignItems:"center",gap:8},children:[(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,d.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,d.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),(0,d.jsx)("input",{ref:l,value:j,onChange:a=>k(a.target.value),onKeyDown:a=>{"Escape"===a.key&&i()},placeholder:"Search providers…",style:{flex:1,background:"none",border:"none",outline:"none",color:"var(--text)",fontSize:13,boxSizing:"border-box"}})]}),(0,d.jsx)("div",{style:{flex:1,overflowY:"auto",padding:14},children:0===r?(0,d.jsx)("div",{style:{padding:"20px 0",fontSize:12,color:"var(--text-dim)",textAlign:"center"},children:"No providers match"}):(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(240px, 100%), 1fr))",gap:8},children:[p&&(0,d.jsx)("div",{style:{gridColumn:"1 / -1",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Custom"}),p&&(0,d.jsxs)("button",{onClick:()=>{g(),i()},style:s,onMouseEnter:a=>{a.currentTarget.style.borderColor="var(--accent)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.borderColor="var(--border)",a.currentTarget.style.background="var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"OpenAI / Anthropic compatible"}),(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"Custom endpoint format"})]}),(0,d.jsx)("span",{style:{width:26,height:26,borderRadius:5,background:"var(--bg-hover)",border:"1px dashed var(--border)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)"},children:[(0,d.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,d.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}),q&&(0,d.jsxs)("button",{onClick:()=>{h(),i()},style:s,onMouseEnter:a=>{a.currentTarget.style.borderColor="var(--accent)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.borderColor="var(--border)",a.currentTarget.style.background="var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"Discover models from Base URL"}),(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OpenAI-compatible / Ollama catalog"})]}),(0,d.jsx)("span",{style:{width:26,height:26,borderRadius:5,background:"var(--bg-hover)",border:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-muted)"},children:[(0,d.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,d.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})})]}),n.length>0&&(0,d.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*!!p,fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"Subscriptions"}),n.map(a=>(0,d.jsxs)("button",{onClick:()=>{c(a.id),i()},style:s,onMouseEnter:a=>{a.currentTarget.style.borderColor="var(--accent)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.borderColor="var(--border)",a.currentTarget.style.background="var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name}),(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:"OAuth"})]}),(0,d.jsx)(co,{id:a.id,size:28})]},a.id)),o.length>0&&(0,d.jsx)("div",{style:{gridColumn:"1 / -1",paddingTop:6*(n.length>0),fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em"},children:"API Key"}),o.map(a=>(0,d.jsxs)("button",{onClick:()=>{f(a.id),i()},style:s,onMouseEnter:a=>{a.currentTarget.style.borderColor="var(--accent)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.borderColor="var(--border)",a.currentTarget.style.background="var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.displayName}),(0,d.jsxs)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:2},children:[a.modelCount," models"]})]}),(0,d.jsx)(co,{id:a.id,size:28})]},a.id))]})})]})})}function cq({existingProviders:a,onImport:b,onClose:c}){let[f,g]=(0,e.useState)(""),[h,i]=(0,e.useState)(""),[j,k]=(0,e.useState)("custom-provider"),[l,m]=(0,e.useState)(new Set),[n,o]=(0,e.useState)({phase:"idle"}),p=(0,e.useCallback)(async()=>{let a=f.trim();if(a&&"loading"!==n.phase){o({phase:"loading"});try{let b=await fetch("/api/models-config/discover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:a,apiKey:h,provider:j,enrich:!1})}),c=await b.json();if(!b.ok||!c.ok||!c.models||!c.piModels||!c.endpoint)return void o({phase:"error",message:c.error??`HTTP ${b.status}`});o({phase:"success",endpoint:c.endpoint,models:c.models,piModels:c.piModels}),m(new Set(c.piModels.map(a=>a.id)))}catch(a){o({phase:"error",message:a instanceof Error?a.message:String(a)})}}},[h,f,j,n.phase]),q="success"===n.phase?n:null,r=l.size,s=!!(q&&j.trim()&&r>0);return(0,d.jsx)("div",{style:{position:"fixed",inset:0,zIndex:1100,background:"rgba(0,0,0,0.4)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:a=>{a.target===a.currentTarget&&c()},children:(0,d.jsxs)("div",{style:{width:880,maxWidth:"calc(100vw - 32px)",height:"min(78vh, calc(100vh - 32px))",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:10,display:"flex",flexDirection:"column",boxShadow:"0 8px 32px rgba(0,0,0,0.22)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:"12px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:"Discover models"}),(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:2},children:"Fetch model catalog from a Base URL and import selected models."})]}),(0,d.jsx)("button",{onClick:c,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,d.jsxs)("div",{style:{padding:16,borderBottom:"1px solid var(--border)",display:"grid",gridTemplateColumns:"1.4fr 1fr 0.9fr auto",gap:10,alignItems:"end",flexShrink:0},children:[(0,d.jsx)(b8,{label:"Base URL",children:(0,d.jsx)(ca,{value:f,onChange:g,placeholder:"https://api.example.com",mono:!0})}),(0,d.jsx)(b8,{label:"API Key",children:(0,d.jsx)(cb,{value:h,onChange:i,placeholder:"optional for local providers",mono:!0})}),(0,d.jsx)(b8,{label:"Provider name",children:(0,d.jsx)(ca,{value:j,onChange:k,placeholder:"provider-name",mono:!0})}),(0,d.jsx)("button",{onClick:p,disabled:!f.trim()||"loading"===n.phase,style:{height:31,padding:"0 14px",background:f.trim()&&"loading"!==n.phase?"var(--accent)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:5,color:f.trim()&&"loading"!==n.phase?"#fff":"var(--text-dim)",cursor:f.trim()&&"loading"!==n.phase?"pointer":"not-allowed",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},children:"loading"===n.phase?"Fetching...":"Fetch models"})]}),(0,d.jsxs)("div",{style:{flex:1,overflow:"hidden",display:"flex",flexDirection:"column"},children:["idle"===n.phase&&(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Enter a Base URL to discover available models."}),"loading"===n.phase&&(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:"Fetching model catalog..."}),"error"===n.phase&&(0,d.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12,lineHeight:1.6},children:n.message}),q&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 16px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,d.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[q.piModels.length," models from ",q.endpoint]}),(0,d.jsx)("button",{onClick:()=>{if(q){if(l.size===q.piModels.length)return void m(new Set);m(new Set(q.piModels.map(a=>a.id)))}},style:{padding:"2px 8px",fontSize:11,background:"var(--bg-hover)",border:"1px solid var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer"},children:l.size===q.piModels.length?"Clear":"Select all"})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"auto"},children:q.piModels.map((a,b)=>{let c=q.models[b],e=l.has(a.id);return(0,d.jsxs)("label",{style:{display:"grid",gridTemplateColumns:"24px minmax(0, 1fr) 90px 90px 90px 70px",gap:10,alignItems:"center",padding:"8px 16px",borderBottom:"1px solid rgba(127,127,127,0.12)",background:e?"var(--bg-subtle)":"transparent",cursor:"pointer"},children:[(0,d.jsx)("input",{type:"checkbox",checked:e,onChange:()=>{var b;return b=a.id,void m(a=>{let c=new Set(a);return c.has(b)?c.delete(b):c.add(b),c})},style:{width:14,height:14,accentColor:"var(--accent)"}}),(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.id}),(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c?.ownedBy??"unknown"})]}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:a.contextWindow}),(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:a.maxTokens}),(0,d.jsx)("span",{style:{fontSize:10,color:a.reasoning?"var(--accent)":"var(--text-dim)"},children:a.reasoning?"reasoning":""}),(0,d.jsx)("span",{style:{fontSize:10,color:a.input?.includes("image")?"var(--accent)":"var(--text-dim)"},children:a.input?.includes("image")?"image":""})]},a.id)})})]})]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10,padding:"10px 16px",borderTop:"1px solid var(--border)",flexShrink:0},children:[(0,d.jsxs)("span",{style:{fontSize:11,color:"var(--text-dim)"},children:[r," selected"]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,d.jsx)("button",{onClick:c,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Cancel"}),(0,d.jsx)("button",{onClick:()=>{if(!q||!s)return;let d=f.trim().replace(/\/+$/,""),e=h.trim(),g=Object.entries(a).find(([,a])=>(a.baseUrl??"").replace(/\/+$/,"")===d&&(a.apiKey??"")===e),i=g?.[0]??j.trim(),k=a[i],m=new Map((k?.models??[]).map(a=>[a.id,a])),n=k?.api??b1,o=0;for(let a of q.piModels)l.has(a.id)&&!m.has(a.id)&&(m.set(a.id,b7(a,n)),o+=1);b(i,{...k??{},baseUrl:d,api:n,...e?{apiKey:e}:{},models:Array.from(m.values())},o),c()},disabled:!s,style:{padding:"6px 16px",background:s?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:6,color:s?"#fff":"var(--text-dim)",cursor:s?"pointer":"not-allowed",fontSize:13,fontWeight:600},children:"Import selected"})]})]})]})})}function cr({onClose:a,embedded:b=!1}){let[c,f]=(0,e.useState)({providers:{}}),[g,h]=(0,e.useState)(!0),[i,j]=(0,e.useState)(!1),[k,l]=(0,e.useState)(null),[m,n]=(0,e.useState)(null),[o,p]=(0,e.useState)(!1),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)([]),[u,v]=(0,e.useState)([]),[w,x]=(0,e.useState)(!1),[y,z]=(0,e.useState)(!1),A=(0,e.useCallback)(()=>{fetch("/api/auth/providers").then(a=>a.json()).then(a=>t(a.providers)).catch(()=>{})},[]),B=(0,e.useCallback)(()=>{fetch("/api/auth/all-providers").then(a=>a.json()).then(a=>v(a.providers)).catch(()=>{})},[]),C=(0,e.useCallback)(()=>{let a="new-provider",b=1;for(;c.providers?.[a];)a=`new-provider-${b++}`;f(b=>({...b,providers:{...b.providers??{},[a]:{api:"openai-completions"}}})),r({type:"provider",name:a})},[c.providers]),D=(0,e.useCallback)((a,b)=>{f(c=>({...c,providers:{...c.providers??{},[a]:b}}))},[]),E=(0,e.useCallback)((a,b)=>{f(c=>{let d=Object.entries(c.providers??{}),e=d.findIndex(([b])=>b===a);return -1===e?c:(d[e]=[b,d[e][1]],{...c,providers:Object.fromEntries(d)})}),r(c=>c?"provider"===c.type&&c.name===a?{type:"provider",name:b}:"model"===c.type&&c.providerName===a?{...c,providerName:b}:c:c)},[]),F=(0,e.useCallback)(a=>{f(b=>{let c={...b.providers??{}};return delete c[a],{...b,providers:c}}),f(a=>{let b=Object.keys(a.providers??{});return r(b.length>0?{type:"provider",name:b[0]}:null),a})},[]),G=(0,e.useCallback)(a=>{f(b=>{let c=b.providers?.[a]??{},d=[...c.models??[],{id:""}];return{...b,providers:{...b.providers??{},[a]:{...c,models:d}}}}),f(b=>{let c=(b.providers?.[a]?.models?.length??1)-1;return r({type:"model",providerName:a,index:c}),b})},[]),H=(0,e.useCallback)((a,b,c)=>{f(d=>{let e=d.providers?.[a]??{},f=[...e.models??[]];return f[b]=c,{...d,providers:{...d.providers??{},[a]:{...e,models:f}}}})},[]),I=(0,e.useCallback)((a,b)=>{f(c=>{let d=c.providers?.[a]??{},e=[...d.models??[]];return e.splice(b,1),{...c,providers:{...c.providers??{},[a]:{...d,models:e.length?e:void 0}}}}),r({type:"provider",name:a})},[]),J=(0,e.useCallback)((a,b,c)=>{f(c=>({...c,providers:{...c.providers??{},[a]:b}})),r({type:"provider",name:a}),p(!1),l(null),n(`${c} model${1===c?"":"s"} imported. Click Save to write models.json.`)},[]),K=(0,e.useCallback)(async()=>{j(!0),l(null),n(null),p(!1);try{let a=await fetch("/api/models-config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)}),b=await a.json();!a.ok||b.error?l(b.error??`HTTP ${a.status}`):(p(!0),setTimeout(()=>p(!1),2e3))}catch(a){l(String(a))}finally{j(!1)}},[c]),L=Object.entries(c.providers??{}),M=s.filter(a=>a.loggedIn),N=u.filter(a=>a.configured),O=(()=>{if(!q)return null;if("oauth"===q.type){let a=s.find(a=>a.id===q.providerId);return a?(0,d.jsx)(cm,{provider:a,onRefresh:A},a.id):null}if("apikey"===q.type){let a=u.find(a=>a.id===q.providerId);return a?(0,d.jsx)(cn,{provider:a,onRefresh:B},a.id):null}if("provider"===q.type){let a=c.providers?.[q.name];return a?(0,d.jsx)(cg,{name:q.name,provider:a,onChange:a=>D(q.name,a),onRename:a=>E(q.name,a),onDelete:()=>F(q.name)},q.name):null}let a=c.providers?.[q.providerName],b=a?.models?.[q.index];return b?(0,d.jsx)(cl,{providerName:q.providerName,provider:a,model:b,onChange:a=>H(q.providerName,q.index,a),onDelete:()=>I(q.providerName,q.index)},`${q.providerName}-${q.index}`):null})();return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{style:b?{height:"100%",minHeight:0,display:"flex",alignItems:"stretch",justifyContent:"stretch"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:c=>{b||c.target!==c.currentTarget||a()},children:(0,d.jsxs)("div",{style:{width:b?"100%":860,height:b?"100%":"78vh",background:"var(--bg)",border:b?"none":"1px solid var(--border)",borderRadius:10*!b,display:"flex",flexDirection:"column",boxShadow:b?"none":"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!b&&(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,d.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Models"}),(0,d.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:"~/.pi/agent/models.json"})]}),(0,d.jsx)("button",{onClick:a,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,d.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{width:210,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:[M.map(a=>{let b=q?.type==="oauth"&&q.providerId===a.id;return(0,d.jsxs)("div",{onClick:()=>r({type:"oauth",providerId:a.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:b?"var(--bg-selected)":"none"},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="none")},children:[(0,d.jsx)(co,{id:a.id,size:16}),(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name})]},a.id)}),N.map(a=>{let b=q?.type==="apikey"&&q.providerId===a.id;return(0,d.jsxs)("div",{onClick:()=>r({type:"apikey",providerId:a.id}),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 8px",borderRadius:5,cursor:"pointer",background:b?"var(--bg-selected)":"none"},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="none")},children:[(0,d.jsx)(co,{id:a.id,size:16}),(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.displayName})]},a.id)}),(M.length>0||N.length>0)&&L.length>0&&(0,d.jsx)("div",{style:{margin:"4px 8px",borderTop:"1px solid var(--border)"}}),g?(0,d.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):L.map(([a,b])=>{let c=q?.type==="provider"&&q.name===a,e=b.models??[];return(0,d.jsxs)("div",{style:{marginBottom:2},children:[(0,d.jsxs)("div",{onClick:()=>r({type:"provider",name:a}),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:c?"var(--bg-selected)":"none"},onMouseEnter:a=>{c||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{c||(a.currentTarget.style.background="none")},children:[(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--text-dim)",flexShrink:0},children:[(0,d.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,d.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,d.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,d.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,d.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,d.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"}),(0,d.jsx)("line",{x1:"20",y1:"9",x2:"23",y2:"9"}),(0,d.jsx)("line",{x1:"20",y1:"14",x2:"23",y2:"14"}),(0,d.jsx)("line",{x1:"1",y1:"9",x2:"4",y2:"9"}),(0,d.jsx)("line",{x1:"1",y1:"14",x2:"4",y2:"14"})]}),(0,d.jsx)("span",{style:{fontSize:12,fontWeight:c?600:400,color:"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a})]}),e.map((b,c)=>{let e=q?.type==="model"&&q.providerName===a&&q.index===c;return(0,d.jsxs)("div",{onClick:()=>r({type:"model",providerName:a,index:c}),style:{display:"flex",alignItems:"center",gap:6,padding:"5px 8px 5px 26px",borderRadius:5,cursor:"pointer",background:e?"var(--bg-selected)":"none"},onMouseEnter:a=>{e||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{e||(a.currentTarget.style.background="none")},children:[(0,d.jsx)("span",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:b.id?"var(--text-muted)":"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b.id||"new model"}),b.reasoning&&(0,d.jsx)("span",{style:{fontSize:9,padding:"1px 4px",background:"rgba(99,102,241,0.12)",color:"rgba(99,102,241,0.8)",borderRadius:3,flexShrink:0},children:"T"})]},c)}),(0,d.jsx)("div",{onClick:b=>{b.stopPropagation(),G(a)},style:{display:"flex",alignItems:"center",gap:4,padding:"4px 8px 4px 26px",borderRadius:5,cursor:"pointer",color:"var(--text-dim)"},onMouseEnter:a=>{a.currentTarget.style.color="var(--accent)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color="var(--text-dim)",a.currentTarget.style.background="none"},children:(0,d.jsx)("span",{style:{fontSize:11},children:"+ model"})})]},a)})]}),(0,d.jsx)("div",{style:{borderTop:"1px solid var(--border)",padding:"8px 6px"},children:(0,d.jsx)("button",{onClick:()=>x(!0),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:5,width:"100%",padding:"6px 0",background:"none",border:"1px dashed var(--border)",borderRadius:5,color:"var(--text-muted)",cursor:"pointer",fontSize:12},onMouseEnter:a=>{a.currentTarget.style.borderColor="var(--accent)",a.currentTarget.style.color="var(--accent)"},onMouseLeave:a=>{a.currentTarget.style.borderColor="var(--border)",a.currentTarget.style.color="var(--text-muted)"},children:"+ Add provider"})})]}),(0,d.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:g?null:O??(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a provider or model"})})]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:10,padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:[k?(0,d.jsx)("span",{style:{fontSize:12,color:"#f87171",flex:1},children:k}):m?(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",flex:1},children:m}):null,(0,d.jsx)("button",{onClick:a,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Cancel"}),(0,d.jsxs)("button",{onClick:K,disabled:i||o,style:{position:"relative",padding:"6px 16px",minWidth:92,background:o?"#16a34a":i?"var(--bg-panel)":"var(--accent)",border:"none",borderRadius:6,color:o?"#fff":i?"var(--text-muted)":"#fff",cursor:i||o?"default":"pointer",fontSize:13,fontWeight:600,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,transition:"background-color 0.2s ease, color 0.2s ease",animation:o?"saved-pop 0.45s ease":void 0},children:[o&&(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:18,animation:"saved-check-draw 0.35s ease forwards",flexShrink:0},children:(0,d.jsx)("polyline",{points:"20 6 9 17 4 12"})}),(0,d.jsx)("span",{children:o?"Saved":i?"Saving…":"Save"})]})]})]})}),w&&(0,d.jsx)(cp,{oauthProviders:s,apiKeyProviders:u,onSelectOAuth:a=>r({type:"oauth",providerId:a}),onSelectApiKey:a=>r({type:"apikey",providerId:a}),onAddCustom:C,onDiscover:()=>z(!0),onClose:()=>x(!1)}),y&&(0,d.jsx)(cq,{existingProviders:c.providers??{},onImport:J,onClose:()=>z(!1)})]})}function cs(a){return a.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function ct(a){let b=a.sourceInfo?.source,c=a.sourceInfo?.scope;return"user"===c||"user"===b?"global":"project"===c||"project"===b?"project":"path"}function cu({enabled:a,loading:b,onToggle:c}){return(0,d.jsx)("button",{onClick:c,disabled:b,title:a?"Visible in model prompt — click to disable":"Hidden from model prompt — click to enable",style:{flexShrink:0,width:40,height:22,borderRadius:11,border:"none",padding:0,cursor:b?"wait":"pointer",background:a?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",outline:"none"},children:(0,d.jsx)("span",{style:{position:"absolute",top:3,left:a?21:3,width:16,height:16,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function cv({skill:a,cwd:b,onToggle:c,toggling:e,saveError:f}){let g=ct(a),h=!a.disableModelInvocation;return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:7},children:[(0,d.jsx)("span",{style:{fontSize:10,padding:"1px 5px",borderRadius:3,flexShrink:0,background:"project"===g?"rgba(99,102,241,0.12)":"rgba(120,120,120,0.12)",color:"project"===g?"rgba(99,102,241,0.8)":"var(--text-dim)"},children:g}),(0,d.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(a){if("project"===g&&a.startsWith(b)){let c=a.slice(b.length).replace(/^[/\\]/,"");return`./${c}`}return cs(a)}(a.filePath)}),(0,d.jsx)(cu,{enabled:h,loading:e,onToggle:()=>c(a)}),f&&(0,d.jsx)("span",{style:{fontSize:12,color:"#f87171",flexShrink:0},children:f})]}),(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Name"}),(0,d.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:14,color:"var(--text)"},children:a.name})]}),(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:"Description"}),(0,d.jsx)("span",{style:{fontSize:14,color:"var(--text-muted)",lineHeight:1.6},children:a.description})]})]})}function cw({cwd:a,onInstalled:b}){let[c,f]=(0,e.useState)(""),[g,h]=(0,e.useState)([]),[i,j]=(0,e.useState)(!1),[k,l]=(0,e.useState)(null),[m,n]=(0,e.useState)(null),[o,p]=(0,e.useState)(null),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)([]),[u,v]=(0,e.useState)(new Set),[w,x]=(0,e.useState)("global"),y=(0,e.useRef)(null),z=(0,e.useRef)(null),A=(0,e.useCallback)(async a=>{if(a.trim()){j(!0),l(null),h([]);try{let b=await fetch("/api/skills/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:a.trim()})}),c=await b.json();if(c.error)return void l(c.error);h(c.results??[]),0===(c.results??[]).length&&l("No skills found")}catch(a){l(String(a))}finally{j(!1)}}},[]),B=(0,e.useCallback)(async c=>{let d=new AbortController;z.current=d,n(c),p(null),r("Starting installer"),t(["Starting installer"]);try{let e=await fetch("/api/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:c,scope:w,cwd:a,stream:!0}),signal:d.signal});if(!e.ok||!e.body){let a=await e.json().catch(()=>null);p(a?.error??`HTTP ${e.status}`);return}let f=e.body.getReader(),g=new TextDecoder,h="",i=!1,j=a=>{"progress"===a.type?(a.stage&&r(a.stage),a.line&&t(b=>(b.at(-1)===a.line?b:[...b,a.line]).slice(-8))):"done"===a.type&&a.success?(i=!0,r("Installed"),t(a=>[...a,"Installed"].slice(-8))):"error"===a.type&&p(a.error??"Install failed")};for(;;){let{value:a,done:b}=await f.read(),c=(h+=g.decode(a??new Uint8Array,{stream:!b})).split("\n");for(let a of(h=c.pop()??"",c))a.trim()&&j(JSON.parse(a));if(b)break}h.trim()&&j(JSON.parse(h)),i&&(v(a=>new Set(a).add(c)),b())}catch(a){d.signal.aborted?(r("Canceled"),t(a=>[...a,"Canceled"].slice(-8))):p(String(a))}finally{z.current===d&&(z.current=null),n(null)}},[b,w,a]),C=(0,e.useCallback)(()=>{z.current?.abort()},[]),D="global"===w?"~/.pi/agent/skills/":`${cs(a)}/.pi/agent/skills/`;return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%"},children:[(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,marginBottom:20},children:[(0,d.jsx)("div",{style:{fontSize:14,fontWeight:600,color:"var(--text)"},children:"Add Skill"}),(0,d.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,d.jsx)("input",{ref:y,value:c,onChange:a=>f(a.target.value),onKeyDown:a=>{"Enter"===a.key&&A(c)},placeholder:"e.g. react, testing, deploy",style:{flex:1,padding:"7px 10px",fontSize:13,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,d.jsx)("button",{onClick:()=>A(c),disabled:i||!c.trim(),style:{padding:"7px 16px",fontSize:13,borderRadius:6,border:"none",background:"var(--accent)",color:"#fff",cursor:i||!c.trim()?"not-allowed":"pointer",opacity:i||!c.trim()?.5:1,flexShrink:0},children:i?"Searching…":"Search"})]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,d.jsx)("div",{style:{display:"flex",borderRadius:5,border:"1px solid var(--border)",overflow:"hidden",fontSize:12,flexShrink:0},children:["global","project"].map(a=>(0,d.jsx)("button",{onClick:()=>x(a),style:{padding:"3px 10px",border:"none",cursor:"pointer",background:w===a?"var(--bg-selected)":"none",color:w===a?"var(--text)":"var(--text-dim)",fontWeight:w===a?600:400,borderRight:"global"===a?"1px solid var(--border)":"none"},children:a},a))}),(0,d.jsxs)("span",{style:{fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["→ ",D]})]}),k&&(0,d.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:k}),o&&(0,d.jsx)("div",{style:{fontSize:12,color:"#f87171",wordBreak:"break-word"},children:o}),m&&(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",padding:10,display:"flex",flexDirection:"column",gap:8},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,d.jsx)("div",{style:{width:10,height:10,borderRadius:"50%",border:"2px solid var(--border)",borderTopColor:"var(--accent)",animation:"spin 0.8s linear infinite",flexShrink:0}}),(0,d.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:600,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:q??"Installing"}),(0,d.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m})]}),(0,d.jsx)("button",{onClick:C,style:{padding:"4px 9px",fontSize:12,borderRadius:5,border:"1px solid var(--border)",background:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0},children:"Cancel"})]}),s.length>0&&(0,d.jsx)("div",{style:{maxHeight:120,overflow:"auto",fontFamily:"var(--font-mono)",fontSize:11,lineHeight:1.6,color:"var(--text-dim)",borderTop:"1px solid var(--border)",paddingTop:8},children:s.map((a,b)=>(0,d.jsx)("div",{children:a},`${b}-${a}`))})]})]}),g.length>0?(0,d.jsx)("div",{style:{flex:1,overflowY:"auto"},children:g.map(a=>{let b=u.has(a.package),c=m===a.package,e=a.package.indexOf("@"),f=e>-1?a.package.slice(0,e):a.package,g=e>-1?a.package.slice(e+1):null;return(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"12px 0",borderBottom:"1px solid var(--border)"},children:[(0,d.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:3},children:g??f}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,d.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:f}),(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)",fontWeight:500},children:a.installs}),a.url&&(0,d.jsx)("a",{href:a.url,target:"_blank",rel:"noreferrer",style:{fontSize:12,color:"var(--accent)",textDecoration:"none"},children:"skills.sh ↗"})]})]}),(0,d.jsx)("button",{onClick:()=>{b||null!==m||B(a.package)},disabled:b||null!==m,style:{flexShrink:0,padding:"5px 14px",fontSize:12,fontWeight:500,borderRadius:5,border:"1px solid var(--border)",cursor:c?"wait":b||null!==m?"not-allowed":"pointer",background:b?"rgba(34,197,94,0.1)":c?"rgba(59,130,246,0.08)":"none",color:b?"#16a34a":c?"var(--accent)":"var(--text-muted)",transition:"color 0.12s"},children:b?"✓ Installed":c?"Installing":"Install"})]},a.package)})}):!k&&!i&&(0,d.jsxs)("div",{style:{fontSize:13,color:"var(--text-dim)",lineHeight:1.8},children:["Search"," ",(0,d.jsx)("a",{href:"https://skills.sh",target:"_blank",rel:"noreferrer",style:{color:"var(--accent)",textDecoration:"none"},children:"skills.sh"})," ","to discover and install skills for your agent."]})]})}function cx({cwd:a,onClose:b,embedded:c=!1}){let[f,g]=(0,e.useState)([]),[h,i]=(0,e.useState)(!0),[j,k]=(0,e.useState)(null),[l,m]=(0,e.useState)(null),[n,o]=(0,e.useState)(new Set),[p,q]=(0,e.useState)(null),[r,s]=(0,e.useState)(!1),t=(0,e.useCallback)(()=>{i(!0),k(null),fetch(`/api/skills?cwd=${encodeURIComponent(a)}`).then(a=>a.json()).then(a=>{if(a.error)return void k(a.error);let b=a.skills??[];g(b),b.length>0&&!l&&m(b[0].filePath)}).catch(a=>k(String(a))).finally(()=>i(!1))},[a,l]),u=(0,e.useCallback)(async a=>{let b=!a.disableModelInvocation;o(b=>new Set(b).add(a.filePath)),q(null);try{let c=await fetch("/api/skills",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:a.filePath,disableModelInvocation:b})}),d=await c.json();if(!c.ok||d.error)return void q(d.error??`HTTP ${c.status}`);g(c=>c.map(c=>c.filePath===a.filePath?{...c,disableModelInvocation:b}:c))}catch(a){q(String(a))}finally{o(b=>{let c=new Set(b);return c.delete(a.filePath),c})}},[]),v=f.find(a=>a.filePath===l)??null;return(0,d.jsx)("div",{style:c?{height:"100%",minHeight:0,display:"flex",alignItems:"stretch",justifyContent:"stretch"}:{position:"fixed",inset:0,zIndex:1e3,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center"},onClick:a=>{c||a.target!==a.currentTarget||b()},children:(0,d.jsxs)("div",{style:{width:c?"100%":860,height:c?"100%":"78vh",background:"var(--bg)",border:c?"none":"1px solid var(--border)",borderRadius:10*!c,display:"flex",flexDirection:"column",boxShadow:c?"none":"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden"},children:[!c&&(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 18px",borderBottom:"1px solid var(--border)",flexShrink:0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:10},children:[(0,d.jsx)("span",{style:{fontSize:15,fontWeight:700,color:"var(--text)"},children:"Skills"}),(0,d.jsx)("code",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)",maxWidth:320,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:cs(a)})]}),(0,d.jsx)("button",{onClick:b,style:{background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1,padding:"2px 6px"},children:"\xd7"})]}),(0,d.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{width:210,borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,background:"var(--bg-panel)"},children:[(0,d.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"8px 6px"},children:h?(0,d.jsx)("div",{style:{padding:"10px 8px",fontSize:12,color:"var(--text-muted)"},children:"Loading…"}):j?(0,d.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"#f87171"},children:j}):0===f.length?(0,d.jsx)("div",{style:{padding:"10px 8px",fontSize:11,color:"var(--text-dim)"},children:"No skills found"}):(()=>{let a=[];for(let b of["project","global","path"]){let c=f.filter(a=>ct(a)===b);c.length>0&&a.push({label:b,skills:c})}return a.map(({label:a,skills:b})=>(0,d.jsxs)("div",{style:{marginBottom:6},children:[(0,d.jsx)("div",{style:{padding:"4px 8px 3px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.06em"},children:a}),b.map(a=>{let b=!r&&l===a.filePath,c=a.disableModelInvocation;return(0,d.jsxs)("div",{onClick:()=>{m(a.filePath),s(!1)},style:{display:"flex",alignItems:"center",gap:7,padding:"8px 8px",borderRadius:5,cursor:"pointer",background:b?"var(--bg-selected)":"none"},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="none")},children:[(0,d.jsx)("span",{style:{flexShrink:0,width:7,height:7,borderRadius:"50%",background:c?"var(--border)":"var(--accent)",boxShadow:c?"none":"0 0 4px var(--accent)",transition:"background 0.15s, box-shadow 0.15s"}}),(0,d.jsx)("span",{style:{fontSize:12,fontWeight:b?600:400,color:c?"var(--text-dim)":"var(--text)",fontFamily:"var(--font-mono)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.name})]},a.filePath)})]},a))})()}),(0,d.jsx)("div",{style:{padding:"8px 6px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,d.jsxs)("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:6,padding:"7px 8px",borderRadius:5,cursor:"pointer",background:r?"var(--bg-selected)":"none",color:r?"var(--accent)":"var(--text-dim)",fontSize:12},onMouseEnter:a=>{r||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{r||(a.currentTarget.style.background="none")},children:[(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,d.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add skill"]})})]}),(0,d.jsx)("div",{style:{flex:1,overflowY:"auto",padding:20},children:r?(0,d.jsx)(cw,{cwd:a,onInstalled:()=>{t()}}):h?null:v?(0,d.jsx)(cv,{skill:v,cwd:a,onToggle:u,toggling:n.has(v.filePath),saveError:p},v.filePath):(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:13},children:"Select a skill"})})]}),(0,d.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",padding:"10px 18px",borderTop:"1px solid var(--border)",flexShrink:0},children:(0,d.jsx)("button",{onClick:b,style:{padding:"6px 14px",background:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-muted)",cursor:"pointer",fontSize:13},children:"Close"})})]})})}let cy=[{label:"30m",value:18e5},{label:"2h",value:72e5},{label:"6h",value:216e5},{label:"24h",value:864e5},{label:"48h",value:1728e5},{label:"Never",value:0}];function cz(a){return a?a.replace(/^\/(?:Users|home)\/[^/]+/,"~"):""}function cA(a){if(a<=0)return"never";let b=a/60/1e3;if(b<60)return`${Math.round(b)}m`;let c=b/60;return Number.isInteger(c)?`${c}h`:`${c.toFixed(1)}h`}function cB(a){return{id:"",language:a,displayName:"",command:"python"===a?"python3":"R",argsText:JSON.stringify("python"===a?["-u"]:["--slave","--vanilla"]),envText:"{}"}}function cC(a){return{id:a.id,language:a.language,displayName:a.displayName,command:a.command,argsText:JSON.stringify(a.args),envText:JSON.stringify(a.env,null,2)}}let cD={height:30,padding:"0 11px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,whiteSpace:"nowrap"},cE={width:"100%",minWidth:0,padding:"7px 9px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none",fontFamily:"var(--font-mono)"};function cF({label:a,children:b}){return(0,d.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:5,minWidth:0},children:[(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)",fontWeight:500},children:a}),b]})}function cG({cwd:a}){let[b,c]=(0,e.useState)("python"),[f,g]=(0,e.useState)(null),[h,i]=(0,e.useState)(!0),[j,k]=(0,e.useState)(null),[l,m]=(0,e.useState)(null),[n,o]=(0,e.useState)(null),[p,q]=(0,e.useState)([]),[r,s]=(0,e.useState)(null),[t,u]=(0,e.useState)("view"),[v,w]=(0,e.useState)(()=>cB("python")),[x,y]=(0,e.useState)(1728e5),[z,A]=(0,e.useState)("pdf"),[B,C]=(0,e.useState)(300),[D,E]=(0,e.useState)(800),[F,G]=(0,e.useState)(600),[H,I]=(0,e.useState)(!1);(0,e.useCallback)(async()=>{i(!0),m(null);try{let c=a?`?cwd=${encodeURIComponent(a)}`:"",d=await fetch(`/api/plot-kernels${c}`),e=await d.json();if(!d.ok||e.error)throw Error(e.error??`HTTP ${d.status}`);g(e),q([]),o(null),s(a=>{if(a&&e.kernels.some(b=>b.id===a))return a;let c=e.kernels.find(a=>a.language===b&&a.isEffective);return c?.id??e.kernels.find(a=>a.language===b)?.id??null})}catch(a){m(a instanceof Error?a.message:String(a))}finally{i(!1)}},[a,b]);let J=(0,e.useMemo)(()=>(f?.kernels??[]).filter(a=>a.language===b),[b,f?.kernels]),K=J.find(a=>a.id===r)??null,L=(0,e.useCallback)(async(b,c)=>{k(c),m(null),o(null),q([]);try{let c=await fetch("/api/plot-kernels",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,...b})}),d=await c.json();if(!c.ok||d.error)throw Error(d.error??`HTTP ${c.status}`);return g(d),q(d.errors??[]),d}catch(a){return m(a instanceof Error?a.message:String(a)),null}finally{k(null)}},[a]),M=(0,e.useCallback)(async a=>{let b=await L({action:"scan",..."all"===a?{}:{language:a}},"scan");b&&o(`Scan added ${b.added?.length??0} kernel${(b.added?.length??0)===1?"":"s"}${b.skipped?`, skipped ${b.skipped} existing`:""}.`)},[L]),N=(0,e.useCallback)(async a=>{await L({action:"select",language:a.language,kernelId:a.id},"select")&&o(`Selected ${a.displayName} for this project.`)},[L]),O=(0,e.useCallback)(async a=>{await L({action:"setDefault",language:a.language,kernelId:a.id},"default")&&o(`Set ${a.displayName} as global default.`)},[L]),P=(0,e.useCallback)(async()=>{let a=v.id.trim();if(!a)return void m("Kernel ID is required");try{let b=function(a){let b=JSON.parse(a.argsText||"[]"),c=JSON.parse(a.envText||"{}");if(!Array.isArray(b))throw Error("Args must be a JSON array");if(!c||"object"!=typeof c||Array.isArray(c))throw Error("Env must be a JSON object");return{language:a.language,command:a.command.trim(),displayName:a.displayName.trim(),args:b.map(a=>String(a)),env:Object.fromEntries(Object.entries(c).map(([a,b])=>[a,String(b)]))}}(v);if(!b.command)throw Error("Command is required");if(!await L({action:"new"===t?"add":"edit",kernelId:a,kernel:b},"save"))return;s(a),u("view"),o("new"===t?"Kernel added.":"Kernel saved.")}catch(a){m(a instanceof Error?a.message:String(a))}},[v,t,L]),Q=(0,e.useCallback)(async a=>{let c=await L({action:"delete",kernelId:a.id},"delete");if(!c)return;let d=c.kernels.find(a=>a.language===b&&a.isEffective)??c.kernels.find(a=>a.language===b)??null;s(d?.id??null),u(d?"view":"new"),o("Kernel deleted.")},[b,L]),R=()=>{u("new"),s(null),w(cB(b)),m(null),o(null)},S=(0,e.useCallback)(async a=>{y(a),I(!0),m(null);try{let b=await fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:{plotIdleTimeoutMs:a}})}),c=await b.json();if(!b.ok||c.error)throw Error(c.error??`HTTP ${b.status}`);"number"==typeof c.settings?.plotIdleTimeoutMs&&(y(c.settings.plotIdleTimeoutMs),o(`Workbench idle timeout set to ${cA(c.settings.plotIdleTimeoutMs)}.`))}catch(a){y(x),m(a instanceof Error?a.message:String(a))}finally{I(!1)}},[x]),T=(0,e.useCallback)(async()=>{I(!0),m(null);try{let a=await fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:{saveFormat:z,saveDpi:B,saveWidth:D,saveHeight:F}})}),b=await a.json();if(!a.ok||b.error)throw Error(b.error??`HTTP ${a.status}`);o("Save defaults updated.")}catch(a){m(a instanceof Error?a.message:String(a))}finally{I(!1)}},[z,B,D,F]);return(0,d.jsxs)("div",{style:{height:"100%",minHeight:0,display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{flexShrink:0,padding:"12px 16px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,d.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)"},children:"Workbench Runtime"}),(0,d.jsx)("div",{style:{marginTop:4,fontSize:12,color:"var(--text-muted)",lineHeight:1.5},children:"Manage the warm R/Python kernels used by Workbench sessions and iterative analysis turns."})]}),(0,d.jsxs)("div",{style:{flexShrink:0,display:"flex",alignItems:"center",gap:10,padding:"12px 16px",borderBottom:"1px solid var(--border)",flexWrap:"wrap"},children:[(0,d.jsx)("div",{style:{display:"flex",padding:2,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:["python","r"].map(a=>{let e=b===a;return(0,d.jsx)("button",{type:"button",onClick:()=>c(a),style:{height:26,padding:"0 12px",border:"none",borderRadius:5,background:e?"var(--bg)":"transparent",color:e?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:e?600:500},children:"python"===a?"Python":"R"},a)})}),(0,d.jsxs)("button",{type:"button",onClick:()=>void M(b),disabled:!!j,style:{...cD,opacity:j?.55:1},children:[(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M21 12a9 9 0 0 1-15.3 6.4"}),(0,d.jsx)("path",{d:"M3 12A9 9 0 0 1 18.3 5.6"}),(0,d.jsx)("path",{d:"M18 2v4h4"}),(0,d.jsx)("path",{d:"M6 22v-4H2"})]}),"scan"===j?"Scanning...":`Scan ${"python"===b?"Python":"R"}`]}),(0,d.jsx)("button",{type:"button",onClick:()=>void M("all"),disabled:!!j,style:{...cD,opacity:j?.55:1},children:"Scan all"}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginLeft:"auto"},children:[(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"Idle"}),(0,d.jsx)("div",{style:{display:"flex",padding:2,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:cy.map(a=>{let b=x===a.value;return(0,d.jsx)("button",{type:"button",onClick:()=>{b||S(a.value)},disabled:H,title:`Close inactive Workbench kernels after ${cA(a.value)}`,style:{height:24,padding:"0 8px",border:"none",borderRadius:5,background:b?"var(--bg)":"transparent",color:b?"var(--accent)":"var(--text-muted)",cursor:H?"default":"pointer",fontSize:11,fontWeight:b?700:500,opacity:H?.65:1},children:a.label},a.label)})})]}),(0,d.jsxs)("button",{type:"button",onClick:R,style:{...cD,marginLeft:"auto",color:"var(--accent)"},children:[(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,d.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add kernel"]})]}),(0,d.jsxs)("div",{style:{flexShrink:0,padding:"10px 16px",borderBottom:"1px solid var(--border)",display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[(0,d.jsx)("span",{style:{fontSize:12,fontWeight:700,color:"var(--text)"},children:"Save defaults"}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"Format"}),(0,d.jsx)("div",{style:{display:"flex",padding:2,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)"},children:["pdf","png","svg"].map(a=>{let b=z===a;return(0,d.jsx)("button",{type:"button",onClick:()=>A(a),style:{height:24,padding:"0 8px",border:"none",borderRadius:5,background:b?"var(--bg)":"transparent",color:b?"var(--accent)":"var(--text-muted)",cursor:"pointer",fontSize:11,fontWeight:b?700:500},children:a.toUpperCase()},a)})}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"DPI"}),(0,d.jsx)("input",{type:"number",value:B,onChange:a=>C(Number(a.target.value)||300),min:72,max:1200,style:{width:60,height:26,padding:"0 6px",fontSize:11,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)"}}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"W"}),(0,d.jsx)("input",{type:"number",value:D,onChange:a=>E(Number(a.target.value)||800),min:100,max:8e3,style:{width:65,height:26,padding:"0 6px",fontSize:11,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)"}}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"H"}),(0,d.jsx)("input",{type:"number",value:F,onChange:a=>G(Number(a.target.value)||600),min:100,max:8e3,style:{width:65,height:26,padding:"0 6px",fontSize:11,border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-panel)",color:"var(--text)"}}),(0,d.jsx)("button",{type:"button",onClick:()=>void T(),disabled:H,style:{...cD,background:"var(--accent)",borderColor:"var(--accent)",color:"#fff",opacity:H?.6:1},children:H?"Saving...":"Save"})]}),(l||n||p.length>0)&&(0,d.jsxs)("div",{style:{flexShrink:0,padding:"8px 16px",borderBottom:"1px solid var(--border)",fontSize:12,lineHeight:1.5},children:[l&&(0,d.jsx)("div",{style:{color:"#f87171"},children:l}),n&&(0,d.jsx)("div",{style:{color:"var(--text-muted)"},children:n}),p.map(a=>(0,d.jsx)("div",{style:{color:"rgba(234,179,8,0.95)"},children:a},a))]}),(0,d.jsxs)("div",{style:{flex:1,minHeight:0,display:"flex",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{width:290,flexShrink:0,borderRight:"1px solid var(--border)",background:"var(--bg-panel)",display:"flex",flexDirection:"column",minHeight:0},children:[(0,d.jsxs)("div",{style:{padding:"8px 10px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",lineHeight:1.5},children:[(0,d.jsxs)("div",{children:["Global: ",(0,d.jsx)("code",{style:{fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:cz(f?.paths.global??"")})]}),a&&(0,d.jsxs)("div",{children:["Project: ",(0,d.jsx)("code",{style:{fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:cz(f?.paths.project??"")})]}),!a&&(0,d.jsx)("div",{children:"Project selection requires an active cwd."})]}),(0,d.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",padding:"8px 6px"},children:h?(0,d.jsx)("div",{style:{padding:"10px 8px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}):0===J.length?(0,d.jsx)("div",{style:{padding:"10px 8px",color:"var(--text-dim)",fontSize:12},children:"No kernels found"}):J.map(a=>{let b=r===a.id&&"new"!==t;return(0,d.jsxs)("button",{type:"button",onClick:()=>{s(a.id),u("view"),w(cC(a)),m(null),o(null)},style:{width:"100%",display:"flex",alignItems:"center",gap:8,padding:"8px 9px",border:"none",borderRadius:6,background:b?"var(--bg-selected)":"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:a=>{b||(a.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="transparent")},children:[(0,d.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",background:a.isEffective?"var(--accent)":"var(--border)",flexShrink:0}}),(0,d.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,d.jsx)("span",{style:{display:"block",color:"var(--text)",fontSize:12,fontWeight:b?600:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.displayName}),(0,d.jsx)("span",{style:{display:"block",color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.id})]}),(a.isProjectSelected||a.isDefault)&&(0,d.jsxs)("span",{style:{flexShrink:0,display:"flex",gap:3},children:[a.isProjectSelected&&(0,d.jsx)("span",{title:"Project selected",style:{fontSize:9,color:"var(--accent)",border:"1px solid rgba(37,99,235,0.35)",borderRadius:4,padding:"1px 4px"},children:"P"}),a.isDefault&&(0,d.jsx)("span",{title:"Global default",style:{fontSize:9,color:"var(--text-muted)",border:"1px solid var(--border)",borderRadius:4,padding:"1px 4px"},children:"D"})]})]},a.id)})}),(0,d.jsxs)("div",{style:{padding:"8px 10px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:["Last scan: ",function(a){if(!a)return"never";let b=new Date(a);return Number.isNaN(b.getTime())?a:b.toLocaleString()}(f?.scanCache?.lastScan)]})]}),(0,d.jsx)("div",{style:{flex:1,minWidth:0,minHeight:0,overflowY:"auto",padding:18},children:"view"===t&&K?(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16,maxWidth:760},children:[(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,d.jsx)("h3",{style:{margin:0,color:"var(--text)",fontSize:15,lineHeight:1.3},children:K.displayName}),K.isEffective&&(0,d.jsx)("span",{style:{fontSize:10,color:"var(--accent)",border:"1px solid rgba(37,99,235,0.35)",borderRadius:4,padding:"1px 5px"},children:"active"})]}),(0,d.jsx)("div",{style:{marginTop:5,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-dim)"},children:K.id})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,d.jsx)(cF,{label:"Command",children:(0,d.jsx)("input",{readOnly:!0,value:K.command,style:{...cE,color:"var(--text-muted)"}})}),(0,d.jsx)(cF,{label:"Args",children:(0,d.jsx)("input",{readOnly:!0,value:JSON.stringify(K.args),style:{...cE,color:"var(--text-muted)"}})})]}),(0,d.jsx)(cF,{label:"Environment",children:(0,d.jsx)("textarea",{readOnly:!0,value:JSON.stringify(K.env,null,2),rows:5,style:{...cE,resize:"vertical",color:"var(--text-muted)"}})}),(0,d.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,d.jsx)("button",{type:"button",onClick:()=>a&&void N(K),disabled:!a||"select"===j,style:{...cD,background:a?"var(--accent)":"var(--bg-panel)",color:a?"#fff":"var(--text-dim)",opacity:"select"===j?.6:1},children:"Use for project"}),(0,d.jsx)("button",{type:"button",onClick:()=>void O(K),disabled:"default"===j,style:{...cD,opacity:"default"===j?.6:1},children:"Set default"}),(0,d.jsx)("button",{type:"button",onClick:()=>{u("edit"),s(K.id),w(cC(K)),m(null),o(null)},style:cD,children:"Edit"}),!K.id.startsWith("default-")&&(0,d.jsx)("button",{type:"button",onClick:()=>void Q(K),disabled:"delete"===j,style:{...cD,color:"#f87171",opacity:"delete"===j?.6:1},children:"Delete"})]})]}):(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:14,maxWidth:760},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:8},children:[(0,d.jsx)("h3",{style:{margin:0,color:"var(--text)",fontSize:15},children:"new"===t?"Add Kernel":"Edit Kernel"}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:"python"===b?"Python":"R"})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,d.jsx)(cF,{label:"Kernel ID",children:(0,d.jsx)("input",{value:v.id,readOnly:"edit"===t,onChange:a=>w(b=>({...b,id:a.target.value})),placeholder:"python"===b?"my-python":"my-r",style:{...cE,color:"edit"===t?"var(--text-muted)":"var(--text)"}})}),(0,d.jsx)(cF,{label:"Display name",children:(0,d.jsx)("input",{value:v.displayName,onChange:a=>w(b=>({...b,displayName:a.target.value})),placeholder:"python"===b?"Python 3 (Project)":"R (Project)",style:cE})})]}),(0,d.jsx)(cF,{label:"Command",children:(0,d.jsx)("input",{value:v.command,onChange:a=>w(b=>({...b,command:a.target.value})),placeholder:"/usr/bin/python3",style:cE})}),(0,d.jsx)(cF,{label:"Args JSON",children:(0,d.jsx)("input",{value:v.argsText,onChange:a=>w(b=>({...b,argsText:a.target.value})),style:cE})}),(0,d.jsx)(cF,{label:"Env JSON",children:(0,d.jsx)("textarea",{value:v.envText,onChange:a=>w(b=>({...b,envText:a.target.value})),rows:6,style:{...cE,resize:"vertical"}})}),(0,d.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,d.jsx)("button",{type:"button",onClick:()=>void P(),disabled:"save"===j,style:{...cD,background:"var(--accent)",borderColor:"var(--accent)",color:"#fff",opacity:"save"===j?.6:1},children:"save"===j?"Saving...":"Save"}),(0,d.jsx)("button",{type:"button",onClick:()=>{let a=K??J.find(a=>a.isEffective)??J[0]??null;a?(s(a.id),w(cC(a)),u("view")):R(),m(null)},style:cD,children:"Cancel"})]})]})})]})]})}var cH=c(39868);function cI({text:a,label:b="Copy",title:c,onCopied:f,onError:g}){let[h,i]=(0,e.useState)(!1),j=(0,e.useCallback)(async()=>{try{await (0,cH.D)(a),i(!0),f?.()}catch(a){g?.(a instanceof Error?a:Error(String(a)))}},[f,g,a]);return(0,d.jsx)("button",{type:"button",onClick:()=>void j(),title:c??(h?"Copied":b),style:{height:24,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-hover)",color:h?"#22c55e":"var(--text-muted)",fontSize:10,fontWeight:600,cursor:"pointer",flexShrink:0},children:h?"Copied":b})}let cJ="annovibe-im-gateway";function cK({cwd:a,embedded:b=!1}){let[c,f]=(0,e.useState)(null),[g,h]=(0,e.useState)(null),[i,j]=(0,e.useState)(null),[k,l]=(0,e.useState)(""),[m,n]=(0,e.useState)(""),[o,p]=(0,e.useState)(!1),[q,r]=(0,e.useState)(""),[s,t]=(0,e.useState)(""),[u,v]=(0,e.useState)(!1),[w,x]=(0,e.useState)(!1),[y,z]=(0,e.useState)(!1),[A,B]=(0,e.useState)(null),[C,D]=(0,e.useState)(null),E=(0,e.useCallback)((a,b)=>{"success"===b?(D(a),B(null),setTimeout(()=>D(null),4500)):(B(a),D(null))},[]);(0,e.useCallback)(async()=>{try{let a=await fetch("/api/im/gateway-status",{cache:"no-store"}),b=await a.json();if(!a.ok||!b.gateway)return;j(b.gateway)}catch{}},[]),(0,e.useCallback)(async()=>{v(!0),B(null);try{let b=await fetch(`/api/im/project?cwd=${encodeURIComponent(a)}`,{cache:"no-store"}),c=await b.json();if(!b.ok||!("enabled"in c))throw Error(c.error??`HTTP ${b.status}`);f(c),h(c.gatewayToken??null),l(c.botId),p(c.requireMentionInGroup),r(c.boundChatId??""),t(c.allowedUsers.join("\n")),n("")}catch(a){E(a instanceof Error?a.message:String(a),"error")}finally{v(!1)}},[a,E]);let F=(0,e.useCallback)(async b=>{x(!0),B(null),D(null);try{let c=await fetch("/api/im/project",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,config:b})}),d=await c.json();if(!c.ok||!("enabled"in d))throw Error(d.error??`HTTP ${c.status}`);f(d),h(d.gatewayToken??null),n(""),E("IM settings saved.","success")}catch(a){E(a instanceof Error?a.message:String(a),"error")}finally{x(!1)}},[a,E]),G=(0,e.useCallback)(a=>{F({enabled:a,botId:k.trim(),botSecret:m.trim()||void 0,requireMentionInGroup:o,boundChatId:q.trim()||null,allowedUsers:cO(s)})},[k,m,o,q,s,F]),H=(0,e.useCallback)(()=>{F({enabled:c?.enabled??!1,botId:k.trim(),botSecret:m.trim()||void 0,requireMentionInGroup:o,boundChatId:q.trim()||null,allowedUsers:cO(s)})},[c?.enabled,k,m,o,q,s,F]),I=(0,e.useCallback)(()=>{F({regeneratePairingCode:!0})},[F]),J=(0,e.useCallback)(async()=>{if(c?.sessionId&&window.confirm("Reset the IM thread for this project?\n\nThis clears the stored WeCom session. Pairing and bot settings are kept. The next IM message starts a fresh session.")){z(!0);try{let b=await fetch(`/api/im/session-ids?cwd=${encodeURIComponent(a)}`,{method:"DELETE"}),c=await b.json();if(!b.ok||!c.ok)throw Error(c.error??`HTTP ${b.status}`);f(a=>a?{...a,sessionId:null}:null),E("IM thread reset.","success")}catch(a){E(a instanceof Error?a.message:String(a),"error")}finally{z(!1)}}},[c?.sessionId,a,E]);if(u&&!c)return(0,d.jsx)(cR,{label:"Loading IM settings..."});let K=c?.enabled??!1;return(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,paddingTop:12*!!b},children:[(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",padding:12,display:"flex",flexDirection:"column",gap:12},children:[(0,d.jsx)(cN,{label:"WeCom bot for this project",description:K?"启动 im-gateway 后即可通过企业微信 AI bot 与此项目交互。":"关闭 — 开启后可绑定企业微信 bot 到此项目。",checked:K,disabled:w,onChange:G}),K?(0,d.jsxs)(d.Fragment,{children:[i?(0,d.jsx)(cL,{status:i}):null,(0,d.jsx)(cP,{label:"Bot ID",value:k,onChange:l,placeholder:"从企业微信 AI bot 控制台获取"}),(0,d.jsx)(cP,{label:c?.hasSecret?"Bot Secret(留空则不修改)":"Bot Secret",value:m,onChange:n,placeholder:c?.hasSecret?"留空保留现有 secret":"从企业微信 AI bot 控制台获取",secret:!0}),(0,d.jsx)(cN,{label:"群聊中需要 @提及 bot 才响应",description:"开启后,群聊中用户必须 @bot 才会被处理。",checked:o,disabled:w,compact:!0,onChange:p}),(0,d.jsx)(cP,{label:"绑定群聊 ID(可选)",value:q,onChange:r,placeholder:"限制仅此群聊可交互"}),(0,d.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:11,color:"var(--text-muted)"},children:[(0,d.jsx)("span",{children:"允许用户 ID(一行一个)"}),(0,d.jsx)("textarea",{value:s,onChange:a=>t(a.target.value),rows:3,style:cU,placeholder:"用户也可通过配对码自助授权"})]}),(0,d.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[(0,d.jsx)(cQ,{primary:!0,disabled:w,onClick:H,children:w?"保存中…":"保存 IM 配置"}),(0,d.jsx)(cQ,{disabled:w,onClick:I,children:"重新生成配对码"})]})]}):null]}),K&&c?(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)",padding:12,fontSize:11,color:"var(--text-muted)",display:"flex",flexDirection:"column",gap:8},children:[(0,d.jsx)(cM,{label:"配对码",value:c.pairingCode,copyLabel:"复制配对码"}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,flexWrap:"wrap"},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("strong",{style:{color:"var(--text)"},children:"IM session:"})," ",c.sessionId?`${c.sessionId.slice(0,12)}…`:"尚未启动"]}),c.sessionId?(0,d.jsx)(cQ,{danger:!0,disabled:w||y,onClick:()=>void J(),children:y?"重置中…":"重置 IM thread"}):null]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("strong",{style:{color:"var(--text)"},children:"Gateway token:"})," ",g?`${g.slice(0,8)}…`:"保存时生成"]}),(0,d.jsx)(cM,{label:"Gateway 启动命令",value:cJ,copyLabel:"复制命令",mono:!0}),(0,d.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["启动 ",(0,d.jsx)("code",{style:cS,children:"annovibe"})," 后,在",(0,d.jsx)("strong",{style:{color:"var(--text-muted)",fontWeight:600},children:"同一 Linux 账户"}),"中运行"," ",(0,d.jsx)("code",{style:cS,children:cJ}),"。 Gateway 通过本地 API 读取已启用的项目配置和 bot secret —— 无需手动复制文件。"]}),(0,d.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["配置文件: ",(0,d.jsxs)("code",{style:cS,children:["<project>","/.annovibe/im.json"]})," \xb7 Secrets: ",(0,d.jsx)("code",{style:cS,children:"~/.pi/agent/im-secrets/"})]}),A&&(0,d.jsx)("div",{style:{padding:"6px 10px",background:"rgba(239,68,68,0.08)",borderRadius:6,border:"1px solid rgba(239,68,68,0.3)",color:"#ef4444",fontSize:12},children:A}),C&&(0,d.jsx)("div",{style:{padding:"6px 10px",background:"rgba(34,197,94,0.08)",borderRadius:6,border:"1px solid rgba(34,197,94,0.3)",color:"#22c55e",fontSize:12},children:C})]}):null]})}function cL({status:a}){var b,c,e,f;let g=function(a){if(!a)return null;let b=new Date(a);return Number.isNaN(b.getTime())?a:b.toLocaleString()}(a.startedAt),h=a.alive&&a.pid?`pid ${a.pid}${g?` \xb7 since ${g}`:""}`:g?`last started ${g}`:"在同一个 Linux 账户下运行 annovibe-im-gateway";return(0,d.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"8px 10px",borderRadius:8,border:`1px solid ${"running"===(b=a.tone)?"rgba(34,197,94,0.28)":"stale"===b?"rgba(245,158,11,0.28)":"rgba(248,113,113,0.28)"}`,background:"running"===(c=a.tone)?"rgba(34,197,94,0.08)":"stale"===c?"rgba(245,158,11,0.08)":"rgba(248,113,113,0.08)"},children:[(0,d.jsx)("span",{"aria-hidden":!0,style:{width:8,height:8,borderRadius:"50%",marginTop:4,flexShrink:0,background:"running"===(e=a.tone)?"#22c55e":"stale"===e?"#f59e0b":"#f87171"}}),(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:11,fontWeight:650,color:"running"===(f=a.tone)?"#22c55e":"stale"===f?"#f59e0b":"#f87171"},children:a.label}),(0,d.jsx)("div",{style:{fontSize:10,color:"var(--text-dim)",marginTop:3,lineHeight:1.45},children:h})]})]})}function cM({label:a,value:b,copyLabel:c,mono:e}){return(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsxs)("strong",{style:{color:"var(--text)"},children:[a,":"]})," ",(0,d.jsx)("code",{style:{...cS,...e?{wordBreak:"break-all"}:{}},children:b})]}),(0,d.jsx)(cI,{text:b,label:c})]})}function cN({label:a,description:b,checked:c,disabled:e,compact:f,onChange:g}){return(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:f?"2px 0":"10px 12px",borderRadius:8*!f,border:f?"none":`1px solid ${c?"color-mix(in srgb, var(--accent) 35%, var(--border))":"var(--border)"}`,background:f?"transparent":c?"color-mix(in srgb, var(--accent) 8%, var(--bg-panel))":"var(--bg)"},children:[(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:f?11:13,fontWeight:f?500:650,color:"var(--text)"},children:a}),b?(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",marginTop:4,lineHeight:1.45},children:b}):null]}),(0,d.jsx)("button",{type:"button",role:"switch","aria-checked":c,disabled:e,onClick:()=>g(!c),style:{position:"relative",width:44,height:26,borderRadius:999,border:"none",flexShrink:0,background:c?"var(--accent)":"color-mix(in srgb, var(--text-dim) 35%, var(--border))",cursor:e?"default":"pointer",opacity:e?.55:1,transition:"background 0.15s",padding:0},children:(0,d.jsx)("span",{style:{position:"absolute",top:3,left:c?21:3,width:20,height:20,borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.18)",transition:"left 0.15s"}})})]})}function cO(a){return a.split(/\r?\n/).map(a=>a.trim()).filter(Boolean)}function cP({label:a,value:b,onChange:c,placeholder:e,secret:f}){return(0,d.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4,fontSize:11,color:"var(--text-muted)"},children:[(0,d.jsx)("span",{children:a}),(0,d.jsx)("input",{type:f?"password":"text",value:b,onChange:a=>c(a.target.value),placeholder:e,style:cT})]})}function cQ({children:a,disabled:b,primary:c,danger:e,onClick:f}){return(0,d.jsx)("button",{type:"button",disabled:b,onClick:f,style:{height:28,padding:"0 10px",borderRadius:6,border:c?"none":e?"1px solid rgba(248,113,113,0.45)":"1px solid var(--border)",background:c?"var(--accent)":e?"rgba(248,113,113,0.08)":"var(--bg-hover)",color:c?"#fff":e?"#f87171":"var(--text)",fontSize:11,fontWeight:c?600:400,cursor:b?"default":"pointer",opacity:b?.55:1},children:a})}function cR({label:a}){return(0,d.jsx)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",padding:"18px 10px",color:"var(--text-dim)",fontSize:12,textAlign:"center"},children:a})}let cS={fontFamily:"var(--font-mono)",fontSize:"0.95em"},cT={height:30,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"},cU={padding:"8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",resize:"vertical"},cV={border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)"},cW={height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12};function cX({cwd:a}){let[b,c]=(0,e.useState)(null),[f,g]=(0,e.useState)(!0),[h,i]=(0,e.useState)(null),[j,k]=(0,e.useState)(null);(0,e.useCallback)(async()=>{g(!0),k(null);try{let b=await fetch(`/api/plot-kernels?cwd=${encodeURIComponent(a)}`),d=await b.json().catch(()=>({}));if(!b.ok||d.error||!Array.isArray(d.kernels))throw Error(d.error??`HTTP ${b.status}`);c(d)}catch(a){c(null),k(a instanceof Error?a.message:String(a))}finally{g(!1)}},[a]);let l=(0,e.useCallback)(async(b,d)=>{i(b),k(null);try{let e=await fetch("/api/plot-kernels",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"select",cwd:a,language:b,kernelId:d})}),f=await e.json().catch(()=>({}));if(!e.ok||f.error||!Array.isArray(f.kernels))throw Error(f.error??`HTTP ${e.status}`);c(f)}catch(a){k(a instanceof Error?a.message:String(a))}finally{i(null)}},[a]),m=a=>{let c=b?.kernels.filter(b=>b.language===a)??[],e=c.find(a=>a.isEffective)??c[0]??null;return(0,d.jsxs)("label",{style:{display:"grid",gap:6},children:[(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:"r"===a?"Default R kernel":"Default Python kernel"}),(0,d.jsx)("select",{value:e?.id??"",disabled:f||h===a||0===c.length,onChange:b=>{b.target.value&&l(a,b.target.value)},style:{height:32,padding:"0 9px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12},children:0===c.length?(0,d.jsx)("option",{value:"",children:f?"Loading...":"No configured kernel"}):c.map(a=>(0,d.jsxs)("option",{value:a.id,children:[a.displayName,a.isProjectSelected?" \xb7 project":a.isDefault?" \xb7 global":""," — ",a.command," ",(a.args??[]).join(" ")]},a.id))})]})};return(0,d.jsxs)("section",{style:{...cV,padding:14,display:"grid",gap:12},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Default kernels"}),(0,d.jsx)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)",lineHeight:1.45},children:"Used as the default R/Python kernels for Workbench sessions. Normal chats also use these when they call Workbench kernel tools for analysis."})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr)",gap:10},children:[m("r"),m("python")]}),j&&(0,d.jsx)("div",{style:{fontSize:12,color:"#f87171"},children:j})]})}function cY({activeCwd:a,onSelectProject:b,onProjectsChanged:c}){let[f,g]=(0,e.useState)([]),[h,i]=(0,e.useState)(a),[j,l]=(0,e.useState)(null),[m,n]=(0,e.useState)(!0),[o,p]=(0,e.useState)(null),[q,r]=(0,e.useState)(""),[s,t]=(0,e.useState)(!1),[u,v]=(0,e.useState)(null),[w,x]=(0,e.useState)(null),[y,z]=(0,e.useState)(""),[A,B]=(0,e.useState)(null),[C,D]=(0,e.useState)(null),E=(0,e.useRef)(null),F=f.find(a=>a.cwd===h)??f.find(b=>b.cwd===a)??f[0]??null,G=(0,e.useCallback)(async()=>{try{n(!0);let b=await fetch("/api/projects"),c=await b.json();if(!b.ok||c.error)throw Error(c.error??`HTTP ${b.status}`);let d=c.projects??[];g(d),i(b=>b&&d.some(a=>a.cwd===b)?b:a&&d.some(b=>b.cwd===a)?a:d[0]?.cwd??null),p(null)}catch(a){p(a instanceof Error?a.message:String(a))}finally{n(!1)}},[a]),H=(0,e.useMemo)(()=>({projects:f.length,chats:f.reduce((a,b)=>a+b.chatCount,0)}),[f]),I=(0,e.useCallback)(async()=>{let a=q.trim();if(a){v("add"),p(null);try{let d=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a})}),e=await d.json();if(!d.ok||e.error)throw Error(e.error??`HTTP ${d.status}`);r(""),i(a),c?.(),b?.(a),G()}catch(a){p(a instanceof Error?a.message:String(a))}finally{v(null)}}},[G,c,b,q]),J=(0,e.useCallback)(async a=>{v("add"),p(null);try{let d=await fetch("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a})}),e=await d.json();if(!d.ok||e.error)throw Error(e.error??`HTTP ${d.status}`);r(""),t(!1),i(a),c?.(),b?.(a),G()}catch(a){p(a instanceof Error?a.message:String(a))}finally{v(null)}},[G,c,b]),K=(0,e.useCallback)(async a=>{v(`rename:${a}`),p(null);try{let b=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,name:y})}),d=await b.json();if(!b.ok||d.error)throw Error(d.error??`HTTP ${b.status}`);x(null),z(""),await G(),c?.()}catch(a){p(a instanceof Error?a.message:String(a))}finally{v(null)}},[G,c,y]),L=(0,e.useCallback)(async a=>{if(window.confirm("Remove this project from AnnoVibe? Sessions on disk will not be deleted.")){v(`remove:${a}`),p(null);try{let b=await fetch("/api/projects",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a})}),d=await b.json();if(!b.ok||d.error)throw Error(d.error??`HTTP ${b.status}`);i(b=>b===a?null:b),await G(),c?.()}catch(a){p(a instanceof Error?a.message:String(a))}finally{v(null)}}},[G,c]),M=(0,e.useCallback)(a=>{x(a.cwd),z(a.displayName),requestAnimationFrame(()=>E.current?.focus())},[]),N=(0,e.useCallback)(async a=>{try{let b=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:a})});if(!b.ok)throw Error(`HTTP ${b.status}`);c?.()}catch{G()}},[G,c]),O=(0,e.useCallback)((a,b)=>{"reorder"!==u&&(B(a),b.dataTransfer.effectAllowed="move",b.dataTransfer.setData("text/project-cwd",a))},[u]),P=(0,e.useCallback)((a,b)=>{b.preventDefault(),b.dataTransfer.dropEffect="move",D(a)},[]),Q=(0,e.useCallback)(a=>{if(D(null),!A||A===a)return void B(null);let b=f.map(a=>a.cwd).filter(Boolean),c=b.indexOf(A),d=b.indexOf(a);c<0||d<0?B(null):(b.splice(c,1),b.splice(d,0,A),g(a=>{let c=new Map(a.map(a=>[a.cwd,a]));return b.map(a=>c.get(a)).filter(Boolean)}),B(null),N(b))},[A,N,f]),R=(0,e.useCallback)(()=>{B(null),D(null)},[]);return(0,d.jsxs)("div",{style:{height:"100%",overflow:"hidden",display:"flex",flexDirection:"column"},children:[o&&(0,d.jsx)("div",{style:{marginBottom:12,padding:"10px 12px",borderRadius:8,border:"1px solid rgba(248,113,113,0.35)",background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:12},children:o}),(0,d.jsxs)("div",{style:{display:"flex",gap:8,marginBottom:14,flexShrink:0},children:[(0,d.jsx)("div",{style:{position:"relative",flex:1,minWidth:0},children:(0,d.jsx)("input",{type:"text",value:q,onChange:a=>r(a.target.value),onKeyDown:a=>{"Enter"===a.key&&I()},placeholder:"/path/to/project",style:{width:"100%",height:30,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",outline:"none"}})}),(0,d.jsx)("button",{type:"button",disabled:"add"===u,onClick:()=>void I(),style:{height:30,padding:"0 11px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12,fontWeight:500},children:"Add"}),(0,d.jsx)("button",{type:"button",onClick:()=>t(!0),style:{...cW,height:30},children:"Browse…"})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"minmax(220px, 34%) minmax(0, 1fr)",gap:14,minHeight:0,flex:1},children:[(0,d.jsxs)("aside",{style:{...cV,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"},children:[(0,d.jsxs)("div",{style:{padding:"10px 12px",borderBottom:"1px solid var(--border)"},children:[(0,d.jsxs)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:700},children:[H.projects," Projects"]}),(0,d.jsxs)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11},children:[H.chats," chats total"]})]}),(0,d.jsx)("div",{style:{overflow:"auto",padding:8,display:"grid",gap:6},children:m?(0,d.jsx)("div",{style:{padding:12,color:"var(--text-muted)",fontSize:12},children:"Loading projects..."}):0===f.length?(0,d.jsx)("div",{style:{padding:12,color:"var(--text-muted)",fontSize:12},children:"No projects yet."}):f.map(b=>{var c;let e,f=b.cwd===a,g=b.cwd===F?.cwd,h=A===b.cwd,k=C===b.cwd&&A!==b.cwd,m=j===b.cwd&&!g;return(0,d.jsxs)("button",{type:"button",draggable:!0,onClick:()=>i(b.cwd),onDragStart:a=>O(b.cwd,a),onDragOver:a=>P(b.cwd,a),onDrop:()=>Q(b.cwd),onDragEnd:R,onMouseEnter:()=>l(b.cwd),onMouseLeave:()=>l(null),style:{display:"grid",gap:4,width:"100%",textAlign:"left",padding:"9px 10px",border:`1px solid ${k?"rgba(37,99,235,0.45)":g?"color-mix(in srgb, var(--accent) 45%, var(--border))":"transparent"}`,borderRadius:8,background:k?"rgba(37,99,235,0.06)":g?"color-mix(in srgb, var(--accent) 8%, var(--bg-panel))":"transparent",color:"var(--text)",cursor:"pointer",opacity:h?.55:1},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[(0,d.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12.5,fontWeight:g?750:600},children:b.displayName}),f&&(0,d.jsx)("span",{style:{fontSize:10,color:"var(--accent)",fontWeight:700},children:"current"}),m&&(0,d.jsx)("span",{onClick:a=>{a.stopPropagation(),L(b.cwd)},style:{color:"#f87171",fontSize:11,fontWeight:650},children:"remove"})]}),(0,d.jsx)("div",{style:{color:"var(--text-dim)",fontSize:10.5,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:b.cwd,children:(e=(c=b.cwd).split(/[\\/]/).filter(Boolean)).length<=3?c:`.../${e.slice(-3).join("/")}`})]},b.cwd)})})]}),(0,d.jsx)("main",{style:{minHeight:0,overflow:"auto"},children:F?(0,d.jsxs)("div",{style:{display:"grid",gap:14},children:[(0,d.jsx)("section",{style:{...cV,padding:14,display:"grid",gap:12},children:(0,d.jsxs)("div",{style:{display:"flex",gap:12,alignItems:"flex-start"},children:[(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[w===F.cwd?(0,d.jsx)("input",{ref:E,value:y,onChange:a=>z(a.target.value),onKeyDown:a=>{"Enter"===a.key&&K(F.cwd),"Escape"===a.key&&x(null)},style:{width:"min(420px, 100%)",height:32,padding:"0 9px",border:"1px solid var(--accent)",borderRadius:6,background:"var(--bg)",color:"var(--text)",fontSize:13,outline:"none"}}):(0,d.jsx)("div",{style:{color:"var(--text)",fontSize:16,fontWeight:750},children:F.displayName}),(0,d.jsx)("div",{style:{marginTop:5,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:F.cwd}),(0,d.jsxs)("div",{style:{marginTop:7,color:"var(--text-muted)",fontSize:11},children:[F.chatCount," chats / last ",function(a){if(!a)return"Never";let b=new Date(a),c=new Date().getTime()-b.getTime(),d=Math.floor(c/6e4),e=Math.floor(c/36e5),f=Math.floor(c/864e5);return d<1?"just now":d<60?`${d}m ago`:e<24?`${e}h ago`:f<7?`${f}d ago`:b.toLocaleDateString()}(F.lastAccessed??F.created??null),F.exists?"":" / path missing"]})]}),(0,d.jsx)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",justifyContent:"flex-end"},children:w===F.cwd?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("button",{type:"button",disabled:u===`rename:${F.cwd}`,onClick:()=>void K(F.cwd),style:{...cW,border:"none",background:"var(--accent)",color:"#fff"},children:"Save"}),(0,d.jsx)("button",{type:"button",onClick:()=>x(null),style:cW,children:"Cancel"})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("button",{type:"button",onClick:()=>b?.(F.cwd),style:{...cW,background:F.cwd===a?"var(--accent)":"var(--bg-panel)",color:F.cwd===a?"#fff":"var(--text-muted)"},children:F.cwd===a?"Current":"Switch"}),(0,d.jsx)("button",{type:"button",onClick:()=>M(F),style:cW,children:"Rename"}),(0,d.jsx)("button",{type:"button",disabled:u===`remove:${F.cwd}`,onClick:()=>void L(F.cwd),style:{...cW,border:"1px solid rgba(248,113,113,0.35)",background:"transparent",color:"#f87171"},children:"Remove"})]})})]})}),(0,d.jsx)(cX,{cwd:F.cwd}),(0,d.jsxs)("section",{style:{...cV,padding:14,display:"grid",gap:12},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"WeCom IM"}),(0,d.jsx)("div",{style:{marginTop:3,fontSize:11,color:"var(--text-dim)"},children:"Project notification and chat gateway settings."})]}),(0,d.jsx)(cK,{cwd:F.cwd,embedded:!0})]})]}):(0,d.jsx)("div",{style:{...cV,padding:18,color:"var(--text-muted)",fontSize:12},children:"Select a project to edit settings."})})]}),(0,d.jsx)(k,{open:s,initialPath:a,onClose:()=>t(!1),onSelect:a=>void J(a)})]})}var cZ=c(49998);let c$=["127.0.0.0/8","::1","10.0.0.0/8","172.16.0.0/12","192.168.0.0/16"];function c_({checked:a,onChange:b}){return(0,d.jsx)("button",{type:"button",onClick:b,"aria-pressed":a,style:{width:44,height:24,borderRadius:999,border:"none",padding:0,cursor:"pointer",background:a?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",flexShrink:0},children:(0,d.jsx)("span",{style:{position:"absolute",top:3,left:a?23:3,width:18,height:18,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function c0({label:a,description:b,checked:c,onChange:e}){return(0,d.jsxs)("label",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"10px 12px",borderRadius:8,border:`1px solid ${c?"var(--accent)":"var(--border)"}`,background:c?"rgba(37,99,235,0.04)":"var(--bg)",cursor:"pointer",fontSize:12},children:[(0,d.jsx)("input",{type:"radio",checked:c,onChange:e,style:{marginTop:2,accentColor:"var(--accent)"}}),(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontWeight:600,color:"var(--text)",lineHeight:1.4},children:a}),(0,d.jsx)("div",{style:{color:"var(--text-dim)",lineHeight:1.5,marginTop:2},children:b})]})]})}function c1(){let[a,b]=(0,e.useState)(null),[c,f]=(0,e.useState)(!0),[g,h]=(0,e.useState)(null),[i,j]=(0,e.useState)(null),[k,l]=(0,e.useState)(""),[m,n]=(0,e.useState)(""),[o,p]=(0,e.useState)(null),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)(!1),[w,x]=(0,e.useState)("always"),[y,z]=(0,e.useState)(c$),[A,B]=(0,e.useState)("");(0,e.useCallback)(async()=>{try{let a=await fetch("/api/auth/totp"),c=await a.json();b(c),x(c.requireMode??"always"),z(c.trustedNetworks??c$)}catch{}finally{f(!1)}},[]);let C=async()=>{if(a){if(p(null),"enabled"===a.status){if(!m||!/^\d{6}$/.test(m))return void p("Enter your 6-digit authenticator code to disable");v(!0);try{let a=await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"disable",code:m})}),c=await a.json();a.ok?(b({status:"disabled",enabled:!1,requireMode:"always",trustedNetworks:c$}),n(""),h(null),j(null),t(null),r("Two-factor authentication disabled")):p(c.error??"Failed to disable")}catch{p("Network error")}finally{v(!1)}return}v(!0);try{let a=await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"setup"})}),c=await a.json();if(a.ok&&c.uri){j(c.uri);let a=await cZ.toDataURL(c.uri,{width:200,margin:1});h(a),b({status:"pending",enabled:!1,requireMode:w,trustedNetworks:y}),r(null)}else p(c.error??"Failed to start setup")}catch{p("Network error")}finally{v(!1)}}},D=async()=>{if(!k||!/^\d{6}$/.test(k))return void p("Enter the 6-digit code from your authenticator app");v(!0),p(null);try{let a=await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"verify-setup",code:k})}),c=await a.json();a.ok&&c.success?(await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-require-mode",requireMode:w})}),await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-trusted-networks",trustedNetworks:y})}),b({status:"enabled",enabled:!0,requireMode:w,trustedNetworks:y}),l(""),h(null),j(null),c.recoveryCodes&&t(c.recoveryCodes),r("Two-factor authentication enabled!")):p(c.error??"Invalid code")}catch{p("Network error")}finally{v(!1)}},E=async()=>{h(null),j(null),l(""),p(null);try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"disable"})}),b({status:"disabled",enabled:!1,requireMode:"always",trustedNetworks:c$})}catch{}},F=(0,e.useCallback)(async c=>{if(x(c),a?.status==="enabled")try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-require-mode",requireMode:c})}),b(a=>a?{...a,requireMode:c}:a)}catch{x(a.requireMode)}},[a]),G=(0,e.useCallback)(async()=>{let c=A.trim();if(!c||y.includes(c))return;let d=c.split("/");if(2!==d.length)return void p("Invalid CIDR format (e.g. 192.168.1.0/24)");let e=parseInt(d[1],10);if(isNaN(e)||e<0||e>128)return void p("Invalid CIDR prefix length");p(null);let f=[...y,c];if(z(f),B(""),a?.status==="enabled")try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-trusted-networks",trustedNetworks:f})}),b(a=>a?{...a,trustedNetworks:f}:a)}catch{z(y)}},[A,y,a]),H=(0,e.useCallback)(async c=>{let d=y.filter(a=>a!==c);if(z(d),a?.status==="enabled")try{await fetch("/api/auth/totp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"set-trusted-networks",trustedNetworks:d})}),b(a=>a?{...a,trustedNetworks:d}:a)}catch{z(y)}},[y,a]);return c?(0,d.jsx)("div",{style:{padding:20,fontSize:13,color:"var(--text-muted)"},children:"Loading…"}):(0,d.jsx)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:(0,d.jsxs)("div",{style:{maxWidth:600,display:"flex",flexDirection:"column",gap:16},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)",lineHeight:1.35},children:"Two-Factor Authentication"}),(0,d.jsx)("div",{style:{marginTop:4,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Require a time-based one-time code in addition to your password."})]}),(0,d.jsx)(c_,{checked:a?.status==="enabled",onChange:()=>{}})]}),a&&(0,d.jsx)("div",{style:{fontSize:11,padding:"4px 10px",borderRadius:999,background:"enabled"===a.status?"rgba(34,197,94,0.12)":"pending"===a.status?"rgba(250,204,21,0.12)":"var(--bg-hover)",color:"enabled"===a.status?"#16a34a":"pending"===a.status?"#ca8a04":"var(--text-dim)",display:"inline-flex",alignSelf:"flex-start",fontWeight:600},children:"enabled"===a.status?"● Active":"pending"===a.status?"◐ Setup in progress":"○ Inactive"}),o&&(0,d.jsx)("div",{style:{fontSize:12,color:"#ef4444",padding:"8px 12px",background:"rgba(239,68,68,0.06)",borderRadius:6},children:o}),q&&!o&&(0,d.jsx)("div",{style:{fontSize:12,color:"#16a34a",padding:"8px 12px",background:"rgba(34,197,94,0.06)",borderRadius:6},children:q}),a?.status==="pending"&&g&&(0,d.jsxs)("div",{style:{padding:20,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",display:"flex",flexDirection:"column",alignItems:"center",gap:14},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)"},children:"Scan with your authenticator app"}),(0,d.jsx)("div",{style:{background:"#fff",padding:12,borderRadius:8,border:"1px solid var(--border)"},children:(0,d.jsx)("img",{src:g,alt:"TOTP QR Code",style:{display:"block",width:200,height:200}})}),i&&(0,d.jsxs)("div",{style:{fontSize:11,color:"var(--text-dim)",textAlign:"center",maxWidth:280},children:[(0,d.jsx)("div",{style:{marginBottom:4},children:"Or enter this key manually:"}),(0,d.jsx)("code",{style:{fontSize:11,fontFamily:"var(--font-mono), monospace",wordBreak:"break-all",background:"var(--bg)",padding:"4px 8px",borderRadius:4},children:i.split("secret=")[1]?.split("&")[0]??"—"})]}),(0,d.jsxs)("div",{style:{width:"100%",maxWidth:260},children:[(0,d.jsx)("label",{style:{fontSize:12,color:"var(--text-dim)",display:"block",marginBottom:6},children:"Enter the 6-digit code to verify"}),(0,d.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,d.jsx)("input",{type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:k,onChange:a=>l(a.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000 000",style:{flex:1,padding:"8px 12px",fontSize:16,fontFamily:"var(--font-mono), monospace",letterSpacing:"0.12em",textAlign:"center",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,d.jsx)("button",{type:"button",disabled:u||6!==k.length,onClick:D,style:{padding:"8px 16px",fontSize:13,fontWeight:600,background:6===k.length?"var(--accent)":"var(--bg-hover)",color:6===k.length?"#fff":"var(--text-dim)",border:"none",borderRadius:6,cursor:6===k.length?"pointer":"not-allowed"},children:u?"…":"Verify"})]})]}),(0,d.jsx)("button",{type:"button",onClick:E,style:{fontSize:12,color:"var(--text-dim)",background:"none",border:"none",cursor:"pointer"},children:"Cancel setup"})]}),s&&s.length>0&&(0,d.jsxs)("div",{style:{padding:20,border:"1px solid rgba(34,197,94,0.3)",borderRadius:8,background:"rgba(34,197,94,0.04)"},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)",marginBottom:6},children:"Recovery codes"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:12,lineHeight:1.55},children:"Save these codes in a safe place. Each can be used once to sign in if you lose access to your authenticator app. They will not be shown again."}),(0,d.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:6,fontFamily:"var(--font-mono), monospace",fontSize:12,color:"var(--text)"},children:s.map((a,b)=>(0,d.jsx)("code",{style:{padding:"6px 10px",background:"var(--bg)",borderRadius:4,border:"1px solid var(--border)"},children:a},b))}),(0,d.jsx)("button",{type:"button",onClick:()=>{t(null),r(null)},style:{marginTop:14,padding:"8px 18px",fontSize:13,fontWeight:600,background:"var(--accent)",color:"#fff",border:"none",borderRadius:6,cursor:"pointer"},children:"I've saved these codes"})]}),(a?.status==="enabled"||a?.status==="pending")&&!s&&(0,d.jsxs)("div",{style:{padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)",marginBottom:12},children:"Scope"}),(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:14},children:[(0,d.jsx)(c0,{label:"Require on all networks",description:"TOTP code is always required during login, even from localhost or LAN.",checked:"always"===w,onChange:()=>F("always")}),(0,d.jsx)(c0,{label:"Skip on trusted networks",description:"TOTP code is only required when signing in from outside localhost or LAN.",checked:"untrusted"===w,onChange:()=>F("untrusted")})]}),"untrusted"===w&&(0,d.jsxs)("div",{style:{padding:"10px 12px",background:"var(--bg)",borderRadius:8,border:"1px solid var(--border)"},children:[(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-dim)",marginBottom:8,lineHeight:1.5},children:"Trusted CIDR blocks (TOTP will be skipped for requests from these IP ranges):"}),(0,d.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:y.map(a=>(0,d.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 8px",borderRadius:999,background:"var(--bg-panel)",border:"1px solid var(--border)",fontSize:11,fontFamily:"var(--font-mono), monospace",color:"var(--text)"},children:[a,(0,d.jsx)("button",{type:"button",onClick:()=>H(a),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-dim)",fontSize:13,lineHeight:1,padding:0},title:"Remove",children:"\xd7"})]},a))}),(0,d.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,d.jsx)("input",{type:"text",value:A,onChange:a=>B(a.target.value),onKeyDown:a=>{"Enter"===a.key&&G()},placeholder:"e.g. 192.168.1.0/24",style:{flex:1,padding:"6px 10px",fontSize:12,fontFamily:"var(--font-mono), monospace",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,d.jsx)("button",{type:"button",onClick:G,style:{padding:"6px 12px",fontSize:12,fontWeight:600,background:A.trim()?"var(--accent)":"var(--bg-hover)",color:A.trim()?"#fff":"var(--text-dim)",border:"none",borderRadius:6,cursor:A.trim()?"pointer":"not-allowed"},children:"Add"})]})]})]}),a?.status==="enabled"&&!s&&(0,d.jsxs)("div",{style:{padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"var(--text)",marginBottom:8},children:"Disable two-factor authentication"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",marginBottom:12,lineHeight:1.5},children:"Enter your current authenticator code to disable 2FA. This will make your account less secure."}),(0,d.jsxs)("div",{style:{display:"flex",gap:8},children:[(0,d.jsx)("input",{type:"text",inputMode:"numeric",pattern:"[0-9]{6}",maxLength:6,value:m,onChange:a=>n(a.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000 000",style:{flex:1,padding:"8px 12px",fontSize:16,fontFamily:"var(--font-mono), monospace",letterSpacing:"0.12em",textAlign:"center",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:6,color:"var(--text)",outline:"none"}}),(0,d.jsx)("button",{type:"button",disabled:u||6!==m.length,onClick:C,style:{padding:"8px 16px",fontSize:13,fontWeight:600,background:6===m.length?"rgba(239,68,68,0.85)":"var(--bg-hover)",color:6===m.length?"#fff":"var(--text-dim)",border:"none",borderRadius:6,cursor:6===m.length?"pointer":"not-allowed"},children:u?"…":"Disable 2FA"})]})]}),a?.status==="disabled"&&(0,d.jsxs)("div",{style:{padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"When enabled, you'll need to enter a 6-digit code from your authenticator app (Google Authenticator, Authy, 1Password, etc.) each time you sign in from a new browser or after your session expires."}),(0,d.jsx)("button",{type:"button",disabled:u,onClick:C,style:{marginTop:14,padding:"8px 18px",fontSize:13,fontWeight:600,background:"var(--accent)",color:"#fff",border:"none",borderRadius:6,cursor:"pointer",opacity:u?.6:1},children:u?"Setting up…":"Set up authenticator"})]})]})})}function c2({checked:a,onChange:b}){return(0,d.jsx)("button",{type:"button",onClick:b,"aria-pressed":a,style:{width:44,height:24,borderRadius:999,border:"none",padding:0,cursor:"pointer",background:a?"var(--accent)":"var(--border)",position:"relative",transition:"background 0.18s",flexShrink:0},children:(0,d.jsx)("span",{style:{position:"absolute",top:3,left:a?23:3,width:18,height:18,borderRadius:"50%",background:"var(--bg)",boxShadow:"0 1px 4px rgba(0,0,0,0.22)",transition:"left 0.18s cubic-bezier(.4,0,.2,1)"}})})}function c3(){return(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.38a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.51a2 2 0 0 1 1-1.72l.15-.1a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2Z"}),(0,d.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}function c4(a){return"projects"===a?(0,d.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M3 6.5A2.5 2.5 0 0 1 5.5 4H10l2 2.5h6.5A2.5 2.5 0 0 1 21 9v8.5A2.5 2.5 0 0 1 18.5 20h-13A2.5 2.5 0 0 1 3 17.5v-11Z"})}):"models"===a?(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"}),(0,d.jsx)("rect",{x:"9",y:"9",width:"6",height:"6"}),(0,d.jsx)("line",{x1:"9",y1:"1",x2:"9",y2:"4"}),(0,d.jsx)("line",{x1:"15",y1:"1",x2:"15",y2:"4"}),(0,d.jsx)("line",{x1:"9",y1:"20",x2:"9",y2:"23"}),(0,d.jsx)("line",{x1:"15",y1:"20",x2:"15",y2:"23"})]}):"skills"===a?(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,d.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,d.jsx)("path",{d:"M2 12l10 5 10-5"})]}):"authenticator"===a?(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),(0,d.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"}),(0,d.jsx)("circle",{cx:"12",cy:"16",r:"1"})]}):"generative-ui"===a?(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,d.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,d.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,d.jsx)("path",{d:"M16 17h5"}),(0,d.jsx)("path",{d:"M18.5 14.5v5"})]}):(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M3 3v18h18"}),(0,d.jsx)("path",{d:"m19 9-5 5-4-4-3 3"}),(0,d.jsx)("path",{d:"M14 9h5v5"})]})}function c5({cwd:a,generativeUI:b,initialTab:c="projects",onGenerativeUIToggle:f,onClose:g,onModelsChanged:h,onProjectSelect:i,onProjectsChanged:j}){let[k,l]=(0,e.useState)(c),m=[{id:"projects",label:"Project",description:a?"Overview and paths":"Add or select a project",icon:c4("projects")},{id:"models",label:"Models",description:"~/.pi/agent/models.json",icon:c4("models")},{id:"authenticator",label:"Authenticator",description:"Two-factor authentication",icon:c4("authenticator")},{id:"skills",label:"Skills",description:a?"Project and global skills":"Select a project first",disabled:!a,icon:c4("skills")},{id:"generative-ui",label:"Generative UI",description:b?"Enabled":"Disabled",icon:c4("generative-ui")},{id:"workbench-runtime",label:"Kernels",description:a?"Project R / Python kernels":"Global R / Python kernels",icon:c4("workbench-runtime")}],n=m.find(a=>a.id===k)??m[0];return(0,d.jsx)("div",{className:"settings-dialog-backdrop",onClick:a=>{a.target===a.currentTarget&&g()},children:(0,d.jsxs)("div",{className:"settings-dialog-shell",children:[(0,d.jsxs)("div",{className:"settings-dialog-header",children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:9,minWidth:0},children:[(0,d.jsx)("span",{style:{color:"var(--text-muted)",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,d.jsx)(c3,{})}),(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:15,fontWeight:700,color:"var(--text)",lineHeight:1.25},children:"Settings"}),(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n.label})]})]}),(0,d.jsx)("button",{type:"button",onClick:g,title:"Close settings","aria-label":"Close settings",style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:"pointer",fontSize:20,lineHeight:1},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.background="transparent",a.currentTarget.style.color="var(--text-muted)"},children:"x"})]}),(0,d.jsxs)("div",{className:"settings-dialog-body",children:[(0,d.jsx)("div",{className:"settings-dialog-tabs",children:m.map(a=>{let b=k===a.id;return(0,d.jsxs)("button",{type:"button",disabled:a.disabled,onClick:()=>l(a.id),className:"settings-dialog-tab",style:{background:b?"var(--bg-selected)":"transparent",color:b?"var(--text)":"var(--text-muted)",opacity:a.disabled?.45:1,cursor:a.disabled?"not-allowed":"pointer"},onMouseEnter:c=>{b||a.disabled||(c.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:a=>{b||(a.currentTarget.style.background="transparent")},children:[(0,d.jsx)("span",{style:{flexShrink:0,color:b?"var(--accent)":"currentColor",display:"flex"},children:a.icon}),(0,d.jsxs)("span",{style:{minWidth:0,flex:1},children:[(0,d.jsx)("span",{style:{display:"block",fontSize:12,fontWeight:b?700:600,lineHeight:1.25},children:a.label}),(0,d.jsx)("span",{style:{display:"block",marginTop:2,fontSize:10,color:"var(--text-dim)",lineHeight:1.25,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a.description})]})]},a.id)})}),(0,d.jsxs)("div",{className:"settings-dialog-panel",children:["projects"===k&&(0,d.jsx)(cY,{activeCwd:a,onSelectProject:i,onProjectsChanged:j}),"models"===k&&(0,d.jsx)(cr,{embedded:!0,onClose:()=>{h?.(),g()}}),"authenticator"===k&&(0,d.jsx)(c1,{}),"skills"===k&&a&&(0,d.jsx)(cx,{cwd:a,embedded:!0,onClose:g}),"generative-ui"===k&&(0,d.jsx)("div",{style:{height:"100%",overflowY:"auto",padding:20},children:(0,d.jsxs)("div",{style:{maxWidth:720,display:"flex",flexDirection:"column",gap:18},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:18,padding:16,border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:[(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsx)("div",{style:{fontSize:14,fontWeight:700,color:"var(--text)",lineHeight:1.35},children:"Generative UI"}),(0,d.jsx)("div",{style:{marginTop:5,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:"Render structured widgets and safe visual code blocks directly in chat when the assistant produces UI content."})]}),(0,d.jsx)(c2,{checked:b,onChange:f})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:12},children:[(0,d.jsxs)("div",{style:{padding:14,border:"1px solid var(--border)",borderRadius:8},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",marginBottom:5},children:"When enabled"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:"The agent prompt favors compact visual artifacts for icons, forms, dashboards, and small interactive UI when useful."})]}),(0,d.jsxs)("div",{style:{padding:14,border:"1px solid var(--border)",borderRadius:8},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:700,color:"var(--text)",marginBottom:5},children:"Fallback rendering"}),(0,d.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:"Assistant SVG and safe HTML code blocks can be previewed instead of appearing only as source text."})]})]})]})}),"workbench-runtime"===k&&(0,d.jsx)(cG,{cwd:a})]})]})]})})}function c6(a){return a?a.replace(/^\/(?:Users|home)\/[^/]+/,"~"):""}function c7(a){return!Number.isFinite(a)||a<=0?"0.0G":`${(a/1024/1024/1024).toFixed(1)}G`}let c8={height:32,padding:"0 12px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12};function c9({cwd:a,runtime:b,runtimeError:c,busy:f=!1,onClose:g,onLaunch:h,onReleaseCurrentRuntime:i,onOpenSettings:j}){let[k,l]=(0,e.useState)("r"),[m,n]=(0,e.useState)(!1),[o,p]=(0,e.useState)(null),[q,r]=(0,e.useState)([]),[s,t]=(0,e.useState)(!1),[u,v]=(0,e.useState)(null),[w,x]=(0,e.useState)(""),[y,z]=(0,e.useState)(""),[A,B]=(0,e.useState)(!1),[C,D]=(0,e.useState)([]),[E,F]=(0,e.useState)(""),[G,H]=(0,e.useState)(!1),[I,J]=(0,e.useState)(null),K=(0,e.useMemo)(()=>q.filter(a=>a.language===k),[k,q]),L=(0,e.useMemo)(()=>K.find(a=>a.id===o)??K.find(a=>a.isEffective)??K[0]??null,[o,K]),M=(0,e.useCallback)(async a=>{if(a){H(!0),J(null);try{let b=a.split("/").filter(Boolean).map(encodeURIComponent).join("/"),c=await fetch(`/api/files/${b}?type=list`);if(!c.ok){let a=await c.json().catch(()=>({}));throw Error(a.error??`HTTP ${c.status}`)}let d=await c.json();D(d.entries),F(d.path)}catch(a){J(a instanceof Error?a.message:String(a)),D([])}finally{H(!1)}}},[]),N=(0,e.useCallback)(()=>{a&&(B(!0),M(a))},[a,M]),O=(0,e.useCallback)(a=>{M(E?`${E.replace(/\/+$/,"")}/${a}`:a)},[E,M]),P=(0,e.useCallback)(a=>{x(E?`${E.replace(/\/+$/,"")}/${a}`:a),B(!1)},[E]),Q="r"===k?[".rds",".qs"]:"python"===k?[".h5ad"]:[];return(0,d.jsx)("div",{className:"settings-dialog-backdrop",onClick:a=>{a.target!==a.currentTarget||f||g()},children:(0,d.jsxs)("div",{style:{width:"min(720px, calc(100vw - 40px))",maxHeight:"min(760px, calc(100vh - 40px))",overflow:"auto",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 24px 80px rgba(0,0,0,0.28)"},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:16,padding:"18px 18px 14px",borderBottom:"1px solid var(--border)"},children:[(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:18,fontWeight:700,color:"var(--text)"},children:"Workbench"}),(0,d.jsxs)("div",{style:{marginTop:6,fontSize:12,color:"var(--text-muted)",lineHeight:1.55},children:["Starts a dedicated top-level Workbench session in the current project.",a?` Project: ${c6(a)}`:""]})]}),(0,d.jsx)("button",{type:"button",onClick:g,disabled:f,style:{width:30,height:30,border:"none",borderRadius:6,background:"transparent",color:"var(--text-muted)",cursor:f?"not-allowed":"pointer",fontSize:20,lineHeight:1,opacity:f?.5:1},children:"x"})]}),(0,d.jsxs)("div",{style:{padding:18,display:"grid",gap:18},children:[(0,d.jsxs)("section",{style:{display:"grid",gap:10},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Kernel"}),(0,d.jsx)("div",{style:{display:"flex",gap:8},children:[{id:"r",label:"R",desc:"Seurat, rds, qs, Bioconductor workflows"},{id:"python",label:"Python",desc:"AnnData, h5ad, pandas, scanpy workflows"}].map(a=>{let b=k===a.id;return(0,d.jsxs)("button",{type:"button",onClick:()=>l(a.id),style:{flex:1,textAlign:"left",padding:"12px 13px",borderRadius:10,border:`1px solid ${b?"rgba(37,99,235,0.45)":"var(--border)"}`,background:b?"var(--bg-selected)":"var(--bg-panel)",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer"},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700},children:a.label}),(0,d.jsx)("div",{style:{marginTop:4,fontSize:11,lineHeight:1.5},children:a.desc})]},a.id)})})]}),(0,d.jsxs)("section",{style:{display:"grid",gap:10},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Mode"}),(0,d.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 13px",borderRadius:10,border:`1px solid ${m?"rgba(37,99,235,0.45)":"var(--border)"}`,background:m?"var(--bg-selected)":"var(--bg-panel)",cursor:"pointer"},children:[(0,d.jsx)("input",{type:"checkbox",checked:m,onChange:a=>n(a.target.checked),style:{accentColor:"var(--accent)"}}),(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:700,color:m?"var(--text)":"var(--text-muted)"},children:"I describe, you code"}),(0,d.jsx)("div",{style:{marginTop:2,fontSize:11,color:"var(--text-dim)",lineHeight:1.45},children:"Describe the analysis in domain terms. The agent will plan the approach, suggest methods, and write the code."})]})]})]}),(0,d.jsxs)("section",{style:{display:"grid",gap:10},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Kernel runtime"}),(0,d.jsxs)("label",{style:{display:"grid",gap:6},children:[(0,d.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:["Specific ","r"===k?"R":"Python"," kernel"]}),(0,d.jsx)("select",{value:L?.id??"",onChange:a=>p(a.target.value||null),disabled:f||s||0===K.length,style:{height:34,padding:"0 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",fontSize:12},children:0===K.length?(0,d.jsx)("option",{value:"",children:s?"Loading kernels...":"No configured kernel"}):K.map(a=>(0,d.jsxs)("option",{value:a.id,children:[a.displayName,a.isEffective?" \xb7 current":""," — ",a.command," ",(a.args??[]).join(" ")]},a.id))}),u&&(0,d.jsx)("span",{style:{fontSize:11,color:"#f87171"},children:u}),(0,d.jsx)("span",{style:{fontSize:10,color:"var(--text-dim)",lineHeight:1.45},children:"Launching will select this kernel for the current project before starting the Workbench session."})]})]}),(0,d.jsxs)("section",{style:{display:"grid",gap:10},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Sources"}),(0,d.jsxs)("label",{style:{display:"grid",gap:6},children:[(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:"Primary object or dataset path"}),(0,d.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,d.jsx)("input",{value:w,onChange:a=>x(a.target.value),placeholder:"r"===k?"e.g. ./data/sample.rds or ./objects/integrated.qs":"e.g. ./data/sample.h5ad",style:{flex:1,height:34,padding:"0 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"}}),(0,d.jsx)("button",{type:"button",onClick:N,disabled:!a||f,title:"Browse project files",style:{...c8,whiteSpace:"nowrap",opacity:!a||f?.5:1,cursor:!a||f?"not-allowed":"pointer"},children:A?"Collapse":"Browse"})]})]}),A&&a&&(0,d.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",maxHeight:260,overflow:"auto",fontSize:12},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"6px 10px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:[(0,d.jsx)("button",{type:"button",onClick:()=>{B(!1)},style:{border:"none",background:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:11,padding:0},children:"✕"}),(0,d.jsx)("span",{style:{color:"var(--text-dim)"},children:"|"}),E?(()=>{let a=E.replace(/^\/+/,"").split("/"),b=[];for(let c=0;c<a.length;c++){let d="/"+a.slice(0,c+1).join("/");b.push({label:0===c?c6(d):a[c],dir:d})}return b.map((b,c)=>(0,d.jsxs)("span",{children:[c>0&&(0,d.jsx)("span",{style:{margin:"0 2px",color:"var(--text-dim)"},children:"/"}),(0,d.jsx)("button",{type:"button",onClick:()=>M(b.dir),style:{border:"none",background:"none",color:c===a.length-1?"var(--text)":"var(--text-muted)",cursor:c===a.length-1?"default":"pointer",fontSize:11,padding:"2px 1px",fontWeight:c===a.length-1?600:400},children:b.label})]},b.dir))})():(0,d.jsx)("span",{style:{color:"var(--text-muted)"},children:"Loading..."})]}),G?(0,d.jsx)("div",{style:{padding:"16px 10px",color:"var(--text-dim)",textAlign:"center"},children:"Loading..."}):I?(0,d.jsx)("div",{style:{padding:"16px 10px",color:"#f87171",textAlign:"center"},children:I}):0===C.length?(0,d.jsx)("div",{style:{padding:"16px 10px",color:"var(--text-dim)",textAlign:"center"},children:"empty directory"}):(0,d.jsxs)("div",{children:[E!==a&&(0,d.jsxs)("div",{onClick:()=>{M(E.replace(/\/+$/,"").split("/").slice(0,-1).join("/")||"/")},style:{display:"flex",alignItems:"center",gap:6,padding:"5px 10px",cursor:"pointer",color:"var(--text-muted)"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="transparent"},children:[(0,d.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",children:(0,d.jsx)("path",{d:"M10 3L5 8l5 5",stroke:"var(--text-dim)",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,d.jsx)("span",{style:{fontSize:11},children:".."})]}),C.map(a=>{let b,c=!a.isDir&&(b=a.name.toLowerCase(),Q.some(a=>b.endsWith(a)));return(0,d.jsxs)("div",{onClick:()=>{a.isDir?O(a.name):P(a.name)},style:{display:"flex",alignItems:"center",gap:6,padding:"5px 10px",cursor:(a.isDir,"pointer"),color:a.isDir?"var(--text)":c?"var(--accent)":"var(--text-muted)",fontWeight:c?600:400},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.background="transparent"},children:[a.isDir?(0,d.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:(0,d.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5H14a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4.5Z",stroke:"var(--text-dim)",strokeWidth:"1",fill:"var(--text-dim)",fillOpacity:"0.1"})}):(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:[(0,d.jsx)("path",{d:"M3 2h7l3 3v9H3V2Z",stroke:c?"var(--accent)":"var(--text-dim)",strokeWidth:"1",fill:c?"var(--accent)":"var(--text-dim)",fillOpacity:"0.08"}),(0,d.jsx)("path",{d:"M10 2v3h3",stroke:c?"var(--accent)":"var(--text-dim)",strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]}),(0,d.jsx)("span",{style:{fontSize:12},children:a.name}),c&&(0,d.jsx)("span",{style:{fontSize:10,color:"var(--accent)",background:"rgba(37,99,235,0.1)",padding:"0 5px",borderRadius:3,lineHeight:"16px"},children:a.name.split(".").pop()})]},a.name)})]})]}),(0,d.jsxs)("label",{style:{display:"grid",gap:6,marginTop:4},children:[(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:"Notes or extra file hints"}),(0,d.jsx)("textarea",{value:y,onChange:a=>z(a.target.value),placeholder:"Optional: metadata table paths, desired comparison, object name hints, or initialization notes.",rows:5,style:{width:"100%",resize:"vertical",minHeight:96,padding:"10px",borderRadius:8,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",fontSize:12,lineHeight:1.55}})]})]}),(0,d.jsxs)("section",{style:{display:"grid",gap:10,padding:14,border:"1px solid var(--border)",borderRadius:10,background:"var(--bg-panel)"},children:[(0,d.jsx)("div",{style:{fontSize:13,fontWeight:700,color:"var(--text)"},children:"Runtime"}),(0,d.jsxs)("div",{style:{display:"flex",gap:16,flexWrap:"wrap",fontSize:12,color:"var(--text-muted)"},children:[(0,d.jsxs)("span",{children:["Total memory ",c7(b.totalBytes)]}),(0,d.jsxs)("span",{children:["Current session ",c7(b.currentSessionBytes)]}),(0,d.jsxs)("span",{children:["Idle timeout ",b.idleTimeoutLabel]})]}),(0,d.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[i&&(0,d.jsx)("button",{type:"button",onClick:i,style:c8,children:"Release current chat"}),j&&(0,d.jsx)("button",{type:"button",onClick:j,style:c8,children:"Runtime settings"})]}),c&&(0,d.jsx)("div",{style:{fontSize:12,color:"#f87171",lineHeight:1.5},children:c})]})]}),(0,d.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"0 18px 18px"},children:[(0,d.jsx)("button",{type:"button",onClick:g,disabled:f,style:c8,children:"Cancel"}),(0,d.jsx)("button",{type:"button",onClick:()=>void h({kernel:k,kernelId:L?.id??null,kernelDisplayName:L?.displayName??null,sourcePath:w.trim(),notes:y.trim(),isDescribeMode:m}),disabled:f||!a||0===K.length,style:{...c8,border:"1px solid rgba(37,99,235,0.45)",background:"rgba(37,99,235,0.12)",color:"var(--accent)",opacity:f||!a?.55:1,cursor:f||!a?"not-allowed":"pointer"},children:f?"Launching...":"Launch Workbench"})]})]})})}function da(a){return a&&Number.isFinite(a)&&!(a<=0)?a<1048576?`${(a/1024).toFixed(0)}K`:a<0x40000000?`${(a/1024/1024).toFixed(1)}M`:`${(a/1024/1024/1024).toFixed(1)}G`:"0.0G"}function db(a){return[...a].sort((a,b)=>b.totalBytes-a.totalBytes||a.id.localeCompare(b.id))}function dc(a){let b=new Map;for(let c of a){let a=c.sessionId?`session:${c.sessionId}`:`process:${c.pid}`;b.set(a,[...b.get(a)??[],c])}return[...b.entries()].map(([a,b])=>({id:a,kind:b[0]?.sessionId?"session":"process",sessionId:b[0]?.sessionId??null,cwd:b[0]?.cwd??null,kernels:b,totalBytes:b.reduce((a,b)=>a+b.rssBytes,0),lastActivity:function(a){let b=0;for(let c of a){if(!c.lastActivity)continue;let a=new Date(c.lastActivity).getTime();Number.isFinite(a)&&(b=Math.max(b,a))}return b>0?new Date(b).toISOString():null}(b)}))}let dd={height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,fontWeight:600,whiteSpace:"nowrap"},de={...dd,color:"#ef4444",border:"1px solid rgba(239,68,68,0.35)",background:"rgba(239,68,68,0.08)"};function df({open:a,anchorRef:b,status:c,error:f,currentSessionId:g,currentCwd:h,idleTimeoutLabel:i,busyPid:j,onClose:k,onRefresh:l,onReleaseKernels:m,onOpenSettings:n,onOpenStatus:o}){let p=function(){let[a,b]=(0,e.useState)(!1);return a}(),q=function(){let[a,b]=(0,e.useState)({top:56,left:12});return a}(),r=(0,e.useMemo)(()=>c?.kernels??[],[c?.kernels]),s=(0,e.useMemo)(()=>dc(r),[r]),t=(0,e.useMemo)(()=>(function(a,b,c){let d=[],e=[],f=[],g=[];for(let i of dc(a))if(b&&i.sessionId===b)d.push(i);else if("process"===i.kind)g.push(i);else{var h;c&&(h=i.cwd,h&&c&&h.replace(/\/+$/,"")===c.replace(/\/+$/,""))?e.push(i):f.push(i)}return[{id:"current",title:"Current session",subtitle:`${da(d.reduce((a,b)=>a+b.totalBytes,0))} retained`,groups:db(d)},{id:"project",title:"Other sessions in this project",subtitle:`${e.length} session${1===e.length?"":"s"}`,groups:db(e)},{id:"other",title:"Other projects",subtitle:`${da(f.reduce((a,b)=>a+b.totalBytes,0))}`,groups:db(f)},{id:"untracked",title:"Unattributed",subtitle:`${g.length} process${1===g.length?"":"es"}`,groups:db(g)}].filter(a=>a.groups.length>0)})(r,g,h),[h,g,r]),u=c?.totalBytes??0,v=c?.currentSessionBytes??0;if(!a)return null;let w=p?{position:"fixed",left:0,right:0,bottom:0,maxHeight:"82dvh",borderRadius:"12px 12px 0 0"}:{position:"fixed",top:q.top,left:q.left,width:"min(620px, calc(100vw - 24px))",maxHeight:"min(680px, calc(100vh - 72px))",borderRadius:10};return(0,d.jsx)("div",{onMouseDown:k,style:{position:"fixed",inset:0,zIndex:900,background:p?"rgba(0,0,0,0.34)":"transparent"},children:(0,d.jsxs)("div",{onMouseDown:a=>a.stopPropagation(),role:"dialog","aria-modal":p?"true":"false","aria-label":"Workbench runtime",style:{...w,overflow:"hidden",border:"1px solid var(--border)",background:"var(--bg)",boxShadow:"0 18px 60px rgba(0,0,0,0.26)",display:"flex",flexDirection:"column"},children:[(0,d.jsxs)("div",{style:{padding:"12px 14px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12},children:[(0,d.jsxs)("div",{style:{minWidth:0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0,flexWrap:"wrap"},children:[(0,d.jsx)("span",{style:{fontSize:13,fontWeight:750,color:"var(--text)"},children:"Workbench Runtime"}),(0,d.jsxs)("span",{style:{fontSize:11,color:v>0?"var(--accent)":"var(--text-dim)",fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums"},children:[da(v)," current / ",da(u)," total"]})]}),(0,d.jsxs)("div",{style:{marginTop:4,display:"flex",gap:10,flexWrap:"wrap",fontSize:11,color:"var(--text-dim)"},children:[(0,d.jsxs)("span",{children:[s.length," session",1===s.length?"":"s"]}),(0,d.jsxs)("span",{children:[r.length," kernel",1===r.length?"":"s"]}),(0,d.jsxs)("span",{children:["idle timeout ",i]}),c?.generatedAt&&(0,d.jsxs)("span",{children:["updated ",new Date(c.generatedAt).toLocaleTimeString()]})]})]}),(0,d.jsx)("button",{type:"button",onClick:k,title:"Close","aria-label":"Close",style:{...dd,width:28,padding:0,fontSize:18,lineHeight:1},children:"x"})]}),(0,d.jsxs)("div",{style:{marginTop:10,display:"flex",gap:7,flexWrap:"wrap"},children:[(0,d.jsx)("button",{type:"button",onClick:l,style:dd,children:"Refresh"}),o&&(0,d.jsx)("button",{type:"button",onClick:o,style:dd,children:"Open Status"}),(0,d.jsx)("button",{type:"button",onClick:n,style:dd,children:"Runtime Settings"})]}),f&&(0,d.jsx)("div",{style:{marginTop:9,border:"1px solid rgba(248,113,113,0.25)",borderRadius:7,background:"rgba(248,113,113,0.08)",color:"#f87171",fontSize:11,lineHeight:1.45,padding:"7px 8px"},children:f})]}),(0,d.jsx)("div",{style:{overflow:"auto",padding:10},children:0===t.length?(0,d.jsx)("div",{style:{padding:"28px 12px",textAlign:"center",color:"var(--text-dim)",fontSize:12},children:"No active Workbench runtime."}):(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:12},children:t.map(a=>(0,d.jsxs)("section",{children:[(0,d.jsxs)("div",{style:{marginBottom:7,display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:10},children:[(0,d.jsx)("div",{style:{fontSize:12,fontWeight:750,color:"var(--text)"},children:a.title}),(0,d.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums"},children:a.subtitle})]}),(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:7},children:a.groups.map(a=>{var b;let c=!!g&&a.sessionId===g,e=a.kernels.some(a=>j===a.pid),f=a.kernels.map(a=>a.pid).join(", ");return(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:p?"1fr":"minmax(0, 1fr) auto",gap:p?9:12,alignItems:"center",border:`1px solid ${c?"rgba(37,99,235,0.42)":"var(--border)"}`,borderRadius:8,background:c?"var(--bg-selected)":"var(--bg-panel)",padding:10},children:[(0,d.jsxs)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:10},children:[(0,d.jsx)("span",{style:{minWidth:42,height:28,padding:"0 7px",display:"inline-flex",alignItems:"center",justifyContent:"center",borderRadius:6,border:"1px solid rgba(37,99,235,0.28)",background:"rgba(37,99,235,0.08)",color:"var(--accent)",fontSize:11,fontWeight:800,fontFamily:"var(--font-mono)",flexShrink:0},children:[...new Set(a.kernels.map(a=>"r"===a.language?"R":"Python"))].join(" + ")}),(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:8,minWidth:0},children:[(0,d.jsx)("span",{style:{fontSize:15,fontWeight:760,color:c?"var(--accent)":"var(--text)",fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums",flexShrink:0},children:da(a.totalBytes)}),(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:a.sessionId??void 0,children:c?"Current session":"session"===a.kind?`Session ${(b=a.sessionId)?b.slice(0,8):"untracked"}`:"Unattributed kernel"})]}),(0,d.jsxs)("div",{style:{marginTop:4,display:"flex",alignItems:"center",gap:8,minWidth:0,color:"var(--text-dim)",fontSize:11},children:[(0,d.jsx)("span",{title:a.cwd??void 0,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(a){if(!a)return"Unknown project";let b=a.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean);return b[b.length-1]||a}(a.cwd)}),(0,d.jsxs)("span",{title:`pid ${f}`,style:{flexShrink:0},children:["pid ",f]}),(0,d.jsx)("span",{style:{flexShrink:0},children:function(a){if(!a)return"activity unknown";let b=new Date(a).getTime();if(!Number.isFinite(b))return"activity unknown";let c=Math.floor(Math.max(0,Date.now()-b)/6e4);if(c<1)return"active now";if(c<60)return`${c}m idle`;let d=Math.floor(c/60);return d<24?`${d}h idle`:`${Math.floor(d/24)}d idle`}(a.lastActivity)})]}),(0,d.jsx)("div",{title:a.cwd??void 0,style:{marginTop:3,color:"var(--text-dim)",fontSize:10,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:function(a){if(!a)return"-";let b=a.replace(/\/+$/,"").replace(/^\/(?:Users|home)\/[^/]+/,"~");if(b.length<=44)return b;let c=b.split("/").filter(Boolean);return c.length<=2?b:`${b.startsWith("/")?"/":""}${c[0]}/.../${c[c.length-1]}`}(a.cwd)})]})]}),(0,d.jsx)("button",{type:"button",onClick:()=>{window.confirm("Release this Workbench runtime?\n\nWarm variables and loaded data will be cleared. Saved files and chat history stay.")&&m(a.kernels)},disabled:e,title:"Release this Workbench runtime",style:{...de,justifySelf:p?"stretch":"end",opacity:e?.55:1,cursor:e?"not-allowed":"pointer"},children:e?"Releasing...":"Release"})]},a.id)})})]},a.id))})})]})})}function dg({initialWidth:a,minWidth:b,maxWidth:c,storageKey:d,direction:f="right"}){let[g,h]=(0,e.useState)(a),[i,j]=(0,e.useState)(!1),k=(0,e.useRef)(a),l=(0,e.useCallback)(a=>{let e=Math.max(b,Math.min(c,a));h(e),k.current=e,document.documentElement.style.setProperty(d,`${e}px`)},[b,c,d]),m=(0,e.useCallback)(()=>{j(!0)},[]),n=(0,e.useCallback)(a=>{let b="left"===f?-1:1;l(k.current+a*b)},[l,f]);return{beginResize:m,endResize:(0,e.useCallback)(()=>{j(!1);try{localStorage.setItem(d,String(k.current))}catch{}},[d]),isResizing:i,resizeBy:n,width:g,widthRef:k}}function dh(a,b){return a.length<=b?a:`${a.slice(0,b)}
25
+ ...`}function di(a){return[`Explain this Workbench artifact: ${a.path}`,`Generated by cell #${a.provenance.cellIndex}: ${a.provenance.title}`,`Status: ${a.provenance.status}`,`Runtime: ${a.provenance.runtime??"unknown"}; language: ${a.provenance.language}`,"","Code:","```",dh(a.provenance.code,4e3),"```",a.provenance.stdoutPreview?`
46
26
  Stdout excerpt:
47
27
  \`\`\`
48
- ${dU(a.provenance.stdoutPreview,1500)}
28
+ ${dh(a.provenance.stdoutPreview,1500)}
49
29
  \`\`\``:"",a.provenance.stderrPreview?`
50
30
  Stderr excerpt:
51
31
  \`\`\`
52
- ${dU(a.provenance.stderrPreview,1500)}
53
- \`\`\``:""].filter(Boolean).join("\n")}function dW(a){return[`Revise this Workbench artifact: ${a.path}`,`It was generated by cell #${a.provenance.cellIndex}: ${a.provenance.title}.`,"Edit the generating code or create a new follow-up cell, save a new artifact instead of silently overwriting the original, and briefly explain what changed.","Requested change:","","Original code:","```",dU(a.provenance.code,4e3),"```",a.provenance.stdoutPreview?`
32
+ ${dh(a.provenance.stderrPreview,1500)}
33
+ \`\`\``:""].filter(Boolean).join("\n")}function dj(a){return[`Revise this Workbench artifact: ${a.path}`,`It was generated by cell #${a.provenance.cellIndex}: ${a.provenance.title}.`,"Edit the generating code or create a new follow-up cell, save a new artifact instead of silently overwriting the original, and briefly explain what changed.","Requested change:","","Original code:","```",dh(a.provenance.code,4e3),"```",a.provenance.stdoutPreview?`
54
34
  Stdout excerpt:
55
35
  \`\`\`
56
- ${dU(a.provenance.stdoutPreview,1500)}
36
+ ${dh(a.provenance.stdoutPreview,1500)}
57
37
  \`\`\``:"",a.provenance.stderrPreview?`
58
38
  Stderr excerpt:
59
39
  \`\`\`
60
- ${dU(a.provenance.stderrPreview,1500)}
61
- \`\`\``:""].filter(Boolean).join("\n")}let dX=new Set(["pdf","png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]);function dY(a){return!Number.isFinite(a)||a<=0?"0.0G":`${(a/1024/1024/1024).toFixed(1)}G`}function dZ(a){if(a<=0)return"never";let b=a/60/60/1e3;return b>=24&&Number.isInteger(b/24)?`${b/24}d`:Number.isInteger(b)?`${b}h`:`${Math.round(a/60/1e3)}m`}function d$(a){let b=a.toLowerCase();return b.endsWith(".rds")||b.endsWith(".qs")}function d_(a){return a.toLowerCase().endsWith(".h5ad")}function d0(a){let b=(a.split(/[\\/]/).pop()??a).toLowerCase().split(".").pop()??"";return dX.has(b)}function d1(){let a=(0,g.useRouter)(),b=(0,g.useSearchParams)(),{isDark:c,toggleTheme:f}=(0,bR.D)(),h=function(){let[a,b]=(0,e.useState)(!1);return a}(),[i,j]=(0,e.useState)(null),[k,l]=(0,e.useState)(null),[m,n]=(0,e.useState)(0),[o,p]=(0,e.useState)(0),[q,r]=(0,e.useState)(0),[s,t]=(0,e.useState)(0),[v,w]=(0,e.useState)(!1),[x,y]=(0,e.useState)("projects"),[z,A]=(0,e.useState)({generativeUI:!0,plotIdleTimeoutMs:1728e5}),[B,C]=(0,e.useState)(!0),D=dT({initialWidth:260,minWidth:180,maxWidth:500,storageKey:"--pi-sidebar-width"}),E=dT({initialWidth:500,minWidth:300,maxWidth:1200,storageKey:"--pi-right-panel-width",direction:"left"}),F=(0,e.useRef)(null),G=(0,e.useRef)(null),H=(0,e.useRef)(null),[I,J]=(0,e.useState)([]),[L,M]=(0,e.useState)(null),N=(0,e.useRef)(null),O=(0,e.useCallback)((a,b,c)=>{J(a),M(b),N.current=c},[]),P=(0,e.useCallback)(a=>{N.current?.(a)},[]),[Q,R]=(0,e.useState)(!1),[S,T]=(0,e.useState)(""),U=(0,e.useRef)(null),V=(0,e.useRef)(!1),W=(0,e.useCallback)(a=>a?a.name||a.firstMessage.slice(0,80)||a.id.slice(0,12):"",[]),X=(0,e.useCallback)(()=>{i&&(V.current=!1,T(i.name||W(i)),R(!0),setTimeout(()=>U.current?.select(),0))},[W,i]),Y=(0,e.useCallback)(async()=>{if(V.current){V.current=!1,R(!1);return}if(!i)return void R(!1);let a=S.trim(),b=W(i);if(R(!1),a!==(i.name??"")&&(i.name||a!==b))try{(await fetch(`/api/sessions/${encodeURIComponent(i.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:a})})).ok&&(j(b=>b&&b.id===i.id?{...b,name:a}:b),n(a=>a+1))}catch{}},[W,i,S]),Z=(0,e.useCallback)(a=>{"Enter"===a.key?(a.preventDefault(),Y()):"Escape"===a.key&&(V.current=!0,R(!1))},[Y]),$=(0,e.useCallback)(()=>{let a=!z.generativeUI;A(b=>({...b,generativeUI:a})),fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:{generativeUI:a}})}).then(a=>a.ok?a.json():Promise.reject(Error(`HTTP ${a.status}`))).then(a=>{A(b=>({...b,..."boolean"==typeof a.settings?.generativeUI?{generativeUI:a.settings.generativeUI}:{},..."number"==typeof a.settings?.plotIdleTimeoutMs?{plotIdleTimeoutMs:a.settings.plotIdleTimeoutMs}:{}}))}).catch(()=>A(a=>({...a,generativeUI:!a.generativeUI})))},[z.generativeUI]),[_,aa]=(0,e.useState)(null),ab=(0,e.useCallback)(a=>{aa(a)},[]),[ac,ad]=(0,e.useState)(null),ae=(0,e.useCallback)(a=>{ad(a)},[]),[af,ag]=(0,e.useState)(!1),[ah,ai]=(0,e.useState)(!1),[aj,ak]=(0,e.useState)(null),[al,am]=(0,e.useState)(!1),[an,ao]=(0,e.useState)(!1),[ap,aq]=(0,e.useState)(null),ar=ap?.updateAvailable&&ap.latest?{label:`Update ${ap.latest}`,title:`Current: v${ap.current}
62
- Latest: v${ap.latest}
63
- Run: ${ap.updateCommand}`}:null,[as,at]=(0,e.useState)([]),[au,av]=(0,e.useState)("files"),[aw,ax]=(0,e.useState)(!1),[ay,az]=(0,e.useState)(null),[aA,aB]=(0,e.useState)(0),[aC,aD]=(0,e.useState)([]),aE=(0,e.useCallback)(a=>{F.current?.insertText("`"+a+"`")},[]),[aF]=(0,e.useState)(()=>b.get("session")),[aG,aH]=(0,e.useState)(null),[aI,aJ]=(0,e.useState)(()=>!b.get("session")),aK=(0,e.useRef)(!1),aL=(0,e.useCallback)(b=>{aH(b),az(null),ag(!1),ak(null),b&&!aK.current&&(j(a=>a&&a.cwd!==b?null:a),l(a=>a&&a!==b?null:a),p(a=>a+1),r(a=>a+1),J([]),M(null),a.replace("/",{scroll:!1}))},[a]),aM=(0,e.useCallback)((a,b)=>{aL(a),b?.closeDialog!==!1&&w(!1),n(a=>a+1)},[aL]),aN=(0,e.useCallback)((b,c=!1)=>{l(null),aH(b.cwd),j(b),ag(!1),ak(null),p(a=>a+1),aJ(!0),c&&(aK.current=!0,setTimeout(()=>{aK.current=!1},0)),c||a.replace(`?session=${encodeURIComponent(b.id)}`,{scroll:!1})},[a]),aO=(0,e.useCallback)((b,c)=>{j(null),l(c),aH(c),ag(!1),ak(null),p(a=>a+1),J([]),M(null),a.replace("/",{scroll:!1})},[a]),aP=(0,e.useCallback)(b=>{l(null),aH(b.cwd),j(b),ag(!1),ak(null),n(a=>a+1),a.replace(`?session=${encodeURIComponent(b.id)}`,{scroll:!1}),window.dispatchEvent(new CustomEvent("session-created"))},[a]),aQ=(0,e.useCallback)(()=>{n(a=>a+1),r(a=>a+1)},[]),aR=(0,e.useCallback)(b=>{n(a=>a+1),p(a=>a+1),l(null),j(a=>({...a??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:b})),a.replace(`?session=${encodeURIComponent(b)}`,{scroll:!1})},[a]),aS=(0,e.useCallback)(()=>{aJ(!0)},[]),aT=(0,e.useCallback)(b=>{if(n(a=>a+1),i?.id===b){let b=i.cwd;j(null),l(b??null),ag(!1),ak(null),p(a=>a+1),J([]),M(null),a.replace("/",{scroll:!1})}},[i,a]),aU=i?.cwd??k??aG??null,[aV,aW]=(0,e.useState)(null),aX=(0,e.useCallback)((a,b)=>{if(d$(a)||d$(b))return void az({mode:"start",appType:"stexp",filePath:a,cwd:aU,appId:null});if(d0(a)||d0(b)){let c=`preview:${a}`;aD(d=>{let e=d.find(a=>a.id===c),f=d.filter(a=>a.id!==c);return f.push(e?{...e,filePath:a,fileName:b}:{id:c,filePath:a,fileName:b}),f});return}let c=`file:${a}`;at(d=>d.find(a=>a.id===c)?d:[...d,{id:c,label:b,filePath:a}]),av(c),ax(!0)},[aU]),aY=(0,e.useCallback)((a,b,c)=>{c&&c>0&&aW(c),aX(a,b)},[aX]),aZ=(0,e.useCallback)((a,b)=>{(d_(a)||d_(b))&&az({mode:"start",appType:"h5adexp",filePath:a,cwd:aU,appId:null})},[aU]),a$=(0,e.useCallback)(a=>{ak(a),ag(!0)},[]),a1=(0,e.useCallback)(()=>{ag(!1),ak(null)},[]),a3=(0,e.useCallback)(()=>{av("tools"),ax(!0),aB(a=>a+1)},[]),a5=(0,e.useCallback)(a=>{az({mode:"existing",appType:a.appType,filePath:a.filePath,cwd:a.cwd,appId:a.id}),aB(a=>a+1)},[]),a6=(0,e.useCallback)(a=>{aB(a=>a+1),az(b=>b&&(b.appId===a.id||b.appType===a.appType&&b.filePath===a.filePath&&b.cwd===a.cwd)?"stopped"===a.status||"error"===a.status?null:{mode:"existing",appType:a.appType,filePath:a.filePath,cwd:a.cwd,appId:a.id}:b)},[]),a7=(0,e.useCallback)(a=>{aD(b=>b.filter(b=>b.id!==a))},[]),a8=(0,e.useCallback)(a=>{aD(b=>{let c=b.findIndex(b=>b.id===a);if(c<0||c===b.length-1)return b;let d=[...b],[e]=d.splice(c,1);return d.push(e),d})},[]),a9=(0,e.useCallback)(a=>{"files"!==a&&(at(b=>b.filter(b=>b.id!==a)),av(b=>{if(b!==a)return b;let c=as.filter(b=>b.id!==a);return c.length>0?c[c.length-1].id:"files"}))},[as]),ba=k??(null===i&&aG?aG:null),bb=null!==i||null!==ba,bc=aI&&!bb,bd=[{id:"files",label:"Files",closable:!1,icon:"files"},{id:"tools",label:"Status",closable:!1,icon:"tools"},...i?.sessionKind==="workbench"?[{id:"workbench",label:"Workbench",closable:!1,icon:"report"}]:[],...as],be=as.find(a=>a.id===au)??null,bf=i?W(i):ba?"New chat":"No session",bg=i?.cwd??ba??aG??"",bh=bg?bg.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean).pop()||bg:"",bi=i?.id??null,bj=aj??aU,bk=(0,e.useCallback)((a="projects")=>{y(a),w(!0)},[]),[bl,bm]=(0,e.useState)(null),[bn,bo]=(0,e.useState)(null),[bp,bq]=(0,e.useState)(null),br=bl?.totalBytes??0,bs=bl?.currentSessionBytes??0,bt=(0,e.useCallback)(async()=>{let a=new URLSearchParams;aU&&a.set("cwd",aU),bi&&a.set("sessionId",bi);try{let b=await fetch(`/api/plot-kernels/status${a.toString()?`?${a}`:""}`),c=await b.json();if(!b.ok||!("totalBytes"in c)||!("kernels"in c))throw Error(c.error??`HTTP ${b.status}`);bm(c),bo(null)}catch(a){bo(a instanceof Error?a.message:String(a))}},[bi,aU]),bu=(0,e.useCallback)(async()=>{if(bi&&!bp){bq("all"),bo(null);try{let a=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:bi})}),b=await a.json();if(!a.ok||b.error)throw Error(b.error??`HTTP ${a.status}`);window.setTimeout(()=>{bt()},600)}catch(a){bo(a instanceof Error?a.message:String(a))}finally{bq(null)}}},[bt,bp,bi]),bv=(0,e.useCallback)(async a=>{if(!bp&&0!==a.length){bq(a[0].pid),bo(null);try{for(let b of a){let a=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:b.pid,cwd:b.cwd,sessionId:b.sessionId,language:b.language})}),c=await a.json();if(!a.ok||c.error)throw Error(c.error??`HTTP ${a.status}`)}window.setTimeout(()=>{bt()},600)}catch(a){bo(a instanceof Error?a.message:String(a))}finally{bq(null)}}},[bt,bp]),bw=(0,e.useCallback)(()=>{ai(a=>!a),bt()},[bt]),bx=(0,e.useCallback)(()=>{ai(!1),a3()},[a3]),by=(0,e.useCallback)(()=>{ai(!1),ag(!1),ak(null),bk("workbench-runtime")},[bk]),bz=(0,e.useCallback)(async b=>{let c,d,e;if(!bj||al)return;am(!0),bo(null);let f=new Date().toISOString(),g=`Workbench \xb7 ${"r"===b.kernel?"R":"Python"}`,h=(c=["Workbench session start.","",`Kernel: ${"r"===b.kernel?"R":"Python"}`],b.kernelId&&c.push(`Kernel ID: ${b.kernelId}${b.kernelDisplayName?` (${b.kernelDisplayName})`:""}`),b.sourcePath?c.push(`Primary source: ${b.sourcePath}`):c.push("Primary source: none selected"),b.notes&&(c.push("Notes:"),c.push(b.notes)),d=b.kernelId?`When calling \`kernel_plot_run\` or \`kernel_plot_render\`, pass kernelId: ${JSON.stringify(b.kernelId)}.`:"Use the current project/default Workbench kernel for tool calls.",e=b.sourcePath?'Initialize this workbench for analysis. Prefer the warm runtime tools (`kernel_plot_run`, `kernel_plot_render`, `kernel_plot_artifacts`, `kernel_plot_stop`) for loading data, inspecting object structure, and generating figures or tables. Use `kernel_plot_render` for quick iterative plots that appear inline. Use `kernel_plot_run` + `runtime: "kernel-lite"` when working with data already in warm memory or when saving final artifacts — this keeps loaded data persistent. First, verify the provided input path, load or inspect only that explicit source plus any files mentioned in Notes, and prepare the session for iterative analysis. Keep the first response concise and operational.':"Quick-start this workbench without loading data. Prefer the warm runtime tools (`kernel_plot_run`, `kernel_plot_render`, `kernel_plot_artifacts`, `kernel_plot_stop`) when the user later asks for analysis, plots, or saved artifacts. Do not search the project for `.rds`, `.qs`, `.h5ad`, or other dataset files unless the user explicitly asks. For now, only confirm the selected kernel/runtime is ready and ask what data or task to use next. Keep the first response concise and operational.",c.push("",d,"","CRITICAL — runtime mode:",'- ALWAYS pass `runtime: "kernel-lite"` to every `kernel_plot_run` call. This keeps loaded data, imported packages (library/import), and variables in warm memory across turns. If you use `runtime: "worker"` (one-shot), all loaded state is lost between calls and the analysis restarts from scratch on the next turn.','- Only use `runtime: "worker"` for quick one-shot scripts where memory persistence is not needed.',"- `kernel_plot_render` is always one-shot and does not share memory — use `kernel_plot_run` with `kernel-lite` for iterative work.",...b.isDescribeMode?["","DESCRIBE MODE — the user is a domain expert, not necessarily a coder:",'- The user will describe what they want in high-level terms (e.g. "compare gene expression between clusters", "make a circos plot").',"- Proactively suggest analysis approaches and explain your reasoning in plain language before writing code.","- After each result, summarize what was found in domain terms and suggest logical next steps.","- When the user mentions a figure type (heatmap, volcano, UMAP, circos, dotplot, etc.), pick the appropriate library and parameters without asking for low-level details.","- If you need a parameter the user didn't specify (e.g. which genes to plot), ask clearly and concisely.","- Always confirm what the output means for the user's research question."]:[],"",e),c.join("\n"));try{if(b.kernelId){let a=await fetch("/api/plot-kernels",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"select",cwd:bj,language:b.kernel,kernelId:b.kernelId})}),c=await a.json().catch(()=>({}));if(!a.ok||c.error)throw Error(c.error??`HTTP ${a.status}`)}let c=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:bj,type:"prompt",message:h,toolNames:K("workbench"),sessionName:g,workbenchMeta:{sourcePath:b.sourcePath,kernel:b.kernel,kernelId:b.kernelId,kernelDisplayName:b.kernelDisplayName}})}),d=await c.json().catch(()=>({}));if(!c.ok||d.error||!d.sessionId)throw Error(d.error??`HTTP ${c.status}`);a1(),l(null),aH(bj),j({id:d.sessionId,path:"",cwd:bj,name:g,created:f,modified:f,messageCount:1,firstMessage:h,sessionKind:"workbench",createdBy:"launcher",sessionMeta:{sessionKind:"workbench",lastToolNames:K("workbench"),createdBy:"launcher",createdAt:f,initialSourcePath:b.sourcePath||void 0,initialKernel:b.kernel}}),av("workbench"),ax(!0),J([]),M(null),p(a=>a+1),n(a=>a+1),a.replace(`?session=${encodeURIComponent(d.sessionId)}`,{scroll:!1}),window.setTimeout(()=>{bt()},600)}catch(a){bo(a instanceof Error?a.message:String(a))}finally{am(!1)}},[a1,bt,a,al,bj]),bA=(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(u,{selectedSessionId:i?.id??null,onSelectSession:aN,onNewSession:aO,onNewWorkbench:a$,initialSessionId:aF,onInitialRestoreDone:aS,refreshKey:m,onSessionDeleted:aT,selectedCwd:i?.cwd??k??aG??null,onCwdChange:aL}),(0,d.jsx)("div",{style:{padding:"8px",flexShrink:0},children:(0,d.jsx)("button",{type:"button",onClick:()=>bk("projects"),title:"Settings","aria-label":"Settings",style:{width:34,display:"flex",alignItems:"center",justifyContent:"center",height:34,padding:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:"pointer",fontSize:12,transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.background="none",a.currentTarget.style.color="var(--text-muted)"},children:(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.38a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.51a2 2 0 0 1 1-1.72l.15-.1a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2Z"}),(0,d.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})})]});return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{style:{display:"flex",height:"100dvh",overflow:"hidden",background:"var(--bg)"},children:[(0,d.jsx)("div",{className:"sidebar-overlay-backdrop",onClick:()=>C(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!B,pointerEvents:B?"auto":"none",transition:"opacity 0.25s ease"}}),(0,d.jsx)("div",{className:`sidebar-container${B?" sidebar-open":" sidebar-closed"}`,style:{background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,zIndex:200,width:D.width,minWidth:D.width,transition:B||D.isResizing?"none":void 0},children:bA}),B&&(0,d.jsx)(bU,{side:"right",ariaLabel:"Resize sidebar",onResizeStart:D.beginResize,onResize:D.resizeBy,onResizeEnd:D.endResize}),(0,d.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,d.jsxs)("div",{ref:G,className:"app-topbar",style:{display:"flex",alignItems:"center",gap:8,flexShrink:0,borderBottom:"1px solid var(--border)",height:48,padding:"0 8px",background:"var(--bg)"},children:[(0,d.jsx)("button",{className:"topbar-sidebar-toggle",onClick:()=>C(a=>!a),title:B?"Hide sidebar":"Show sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:a=>{a.currentTarget.style.color="var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color="var(--text-muted)",a.currentTarget.style.background="var(--bg-panel)"},children:B?(0,d.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,d.jsx)("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}):(0,d.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,d.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,d.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),(0,d.jsxs)("div",{className:"topbar-title-area",style:{display:"flex",alignItems:"center",gap:7,minWidth:0,flex:1},children:[(0,d.jsx)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:6},children:Q&&i?(0,d.jsx)("input",{ref:U,value:S,onChange:a=>T(a.target.value),onKeyDown:Z,onBlur:()=>void Y(),style:{width:"min(360px, 34vw)",height:28,boxSizing:"border-box",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",padding:"0 8px",fontSize:13,fontWeight:500,outline:"none"}}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:"topbar-session-title",title:bf,style:{minWidth:0,maxWidth:"min(420px, 36vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:bb?"var(--text)":"var(--text-muted)",fontSize:14,fontWeight:600,lineHeight:1.2},children:bf}),i&&(0,d.jsx)("button",{type:"button",className:"topbar-rename-button",onClick:X,title:"Rename session",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-dim)",cursor:"pointer",flexShrink:0},onMouseEnter:a=>{a.currentTarget.style.color="var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color="var(--text-dim)",a.currentTarget.style.background="transparent"},children:(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 20h9"}),(0,d.jsx)("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"})]})})]})}),bh&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("span",{className:"topbar-project-crumb",style:{color:"var(--text-dim)",fontSize:12,flexShrink:0},children:"/"}),(0,d.jsx)("span",{className:"topbar-project-crumb",title:bg||bh,style:{minWidth:0,maxWidth:"min(280px, 24vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:12,lineHeight:1.2},children:bh})]})]}),bb&&!h&&(0,d.jsx)("div",{className:"topbar-chat-tools",style:{display:"flex",alignItems:"center",gap:6,height:28,flexShrink:0},children:(0,d.jsxs)("button",{type:"button",className:"topbar-plot-button",ref:H,onClick:bw,title:br>0?`Open Workbench runtime \xb7 ${dY(br)}${bs>0?` (this session: ${dY(bs)})`:""}`:"Open Workbench runtime status","aria-label":br>0?`Open Workbench runtime \xb7 ${dY(br)}${bs>0?` (this session: ${dY(bs)})`:""}`:"Open Workbench runtime status",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:ah?"var(--bg-selected)":br>0||an?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${ah||br>0||an?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:br>0||an?"var(--accent)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s",fontVariantNumeric:"tabular-nums"},onMouseEnter:a=>{a.currentTarget.style.color=br>0||an?"var(--accent)":"var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color=br>0||an?"var(--accent)":"var(--text-muted)",a.currentTarget.style.background=ah?"var(--bg-selected)":br>0||an?"rgba(37,99,235,0.08)":"var(--bg-panel)"},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M4 19V5"}),(0,d.jsx)("path",{d:"M4 19h16"}),(0,d.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,d.jsx)("span",{className:"topbar-plot-label",children:"Workbench"}),br>0&&(0,d.jsx)("span",{className:"topbar-plot-memory",children:bs>0&&bs!==br?`${dY(bs)} / ${dY(br)}`:dY(br)})]})}),ar&&(0,d.jsx)("button",{type:"button",className:"topbar-update-button",title:ar.title,onClick:()=>navigator.clipboard?.writeText(ap?.updateCommand??"").catch(()=>{}),style:{height:28,padding:"0 9px",borderRadius:7,border:"1px solid rgba(34,197,94,0.35)",background:"rgba(34,197,94,0.10)",color:"rgba(34,197,94,0.95)",cursor:"pointer",fontSize:11,fontWeight:650,whiteSpace:"nowrap",flexShrink:0},children:ar.label}),bb&&h&&(0,d.jsxs)("button",{type:"button",className:"topbar-plot-button",ref:H,onClick:bw,title:br>0?`Open Workbench runtime \xb7 ${dY(br)}${bs>0?` (this session: ${dY(bs)})`:""}`:"Open Workbench runtime status","aria-label":br>0?`Open Workbench runtime \xb7 ${dY(br)}${bs>0?` (this session: ${dY(bs)})`:""}`:"Open Workbench runtime status",style:{display:"flex",alignItems:"center",gap:4,height:28,padding:"0 7px",flexShrink:0,background:ah?"var(--bg-selected)":br>0||an?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${ah||br>0||an?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:br>0||an?"var(--accent)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M4 19V5"}),(0,d.jsx)("path",{d:"M4 19h16"}),(0,d.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,d.jsx)("span",{className:"topbar-plot-label",children:"WB"}),br>0&&(0,d.jsx)("span",{className:"topbar-plot-memory",children:bs>0&&bs!==br?`${dY(bs)} / ${dY(br)}`:dY(br)})]}),bb&&(_||ac)&&(()=>{let a=_?.tokens,b=_?.cost??0,c=a=>a>=1e6?`${(a/1e6).toFixed(1)}M`:a>=1e3?`${(a/1e3).toFixed(0)}k`:String(a),e=b>0?b>=.01?`$${b.toFixed(2)}`:"<$0.01":null,f="var(--text-muted)",g=null;if(ac?.contextWindow){let a=ac.percent;null!==a&&a>90?f="#ef4444":null!==a&&a>70&&(f="rgba(234,179,8,0.95)"),g=null!==a?`${a.toFixed(0)}% / ${c(ac.contextWindow)}`:`? / ${c(ac.contextWindow)}`}let h=[];if(a&&(h.push(`in: ${a.input.toLocaleString()}`),h.push(`out: ${a.output.toLocaleString()}`),h.push(`cache read: ${a.cacheRead.toLocaleString()}`),h.push(`cache write: ${a.cacheWrite.toLocaleString()}`),b>0&&h.push(`cost: $${b.toFixed(4)}`)),ac?.contextWindow){let a=ac.percent;h.push(`context: ${null!==a?a.toFixed(1)+"%":"unknown"} of ${ac.contextWindow.toLocaleString()} tokens`)}let i=h.join(" | ");return(0,d.jsxs)("div",{className:"topbar-session-stats",title:i,style:{display:"flex",alignItems:"center",gap:10,padding:"0 8px",height:28,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:"default",fontVariantNumeric:"tabular-nums"},children:[a&&a.input>0&&(0,d.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,d.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),c(a.input)]}),a&&a.output>0&&(0,d.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,d.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),c(a.output)]}),a&&a.cacheRead>0&&(0,d.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M8.5 5a3.5 3.5 0 1 1-1-2.45"}),(0,d.jsx)("polyline",{points:"6.5 1.5 8.5 2.5 7.5 4.5"})]}),c(a.cacheRead)]}),e&&(0,d.jsx)("span",{style:{display:"flex",alignItems:"center",color:"var(--text)",fontWeight:500},children:e}),g&&(0,d.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:f},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M1 9 L1 5 Q1 1 5 1 Q9 1 9 5 L9 9"}),(0,d.jsx)("line",{x1:"1",y1:"9",x2:"9",y2:"9"})]}),g]})]})})(),(0,d.jsx)("button",{type:"button",className:"topbar-icon-button topbar-generate-ui-toggle",onClick:$,title:`生成式 UI: ${z.generativeUI?"on":"off"}`,"aria-label":`生成式 UI: ${z.generativeUI?"on":"off"}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:z.generativeUI?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${z.generativeUI?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:z.generativeUI?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:a=>{a.currentTarget.style.color=z.generativeUI?"var(--accent)":"var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color=z.generativeUI?"var(--accent)":"var(--text-muted)",a.currentTarget.style.background=z.generativeUI?"var(--bg-selected)":"var(--bg-panel)"},children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,d.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,d.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,d.jsx)("path",{d:"M16 17h5"}),(0,d.jsx)("path",{d:"M18.5 14.5v5"})]})}),(0,d.jsx)("button",{className:"topbar-icon-button topbar-theme-toggle",onClick:a=>{let b=a.currentTarget.getBoundingClientRect();f({x:b.left+b.width/2,y:b.top+b.height/2})},title:c?"Switch to light mode":"Switch to dark mode","aria-label":c?"Switch to light mode":"Switch to dark mode","aria-pressed":c,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:a=>{a.currentTarget.style.color="var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color="var(--text-muted)",a.currentTarget.style.background="var(--bg-panel)"},children:c?(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"5"}),(0,d.jsx)("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),(0,d.jsx)("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),(0,d.jsx)("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),(0,d.jsx)("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),(0,d.jsx)("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),(0,d.jsx)("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),(0,d.jsx)("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),(0,d.jsx)("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):(0,d.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}),(0,d.jsx)("button",{className:"topbar-icon-button topbar-right-panel-toggle",onClick:()=>ax(a=>!a),title:aw?"Hide right panel":"Show right panel","aria-label":aw?"Hide right panel":"Show right panel",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:aw?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${aw?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:aw?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:a=>{a.currentTarget.style.color=aw?"var(--accent)":"var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color=aw?"var(--accent)":"var(--text-muted)",a.currentTarget.style.background=aw?"var(--bg-selected)":"var(--bg-panel)"},children:(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,d.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:bb?(0,d.jsx)(a_,{session:i,newSessionCwd:ba,onAgentEnd:aQ,onSessionCreated:aP,onSessionForked:aR,modelsRefreshKey:s,chatInputRef:F,onBranchDataChange:O,onSessionStatsChange:ab,onContextUsageChange:ae,onToolPresetActive:ao,generativeUI:z.generativeUI,activeFilePath:be?.filePath??null,onOpenFileAtLine:aY},o):bc?aG?(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:15},children:"Select a session from the sidebar"}):(0,d.jsxs)("div",{style:{position:"absolute",top:12,left:12,display:"flex",alignItems:"flex-start",gap:8,userSelect:"none",pointerEvents:"none"},children:[(0,d.jsxs)("svg",{width:"44",height:"44",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.7,flexShrink:0},children:[(0,d.jsx)("line",{x1:"20",y1:"12",x2:"4",y2:"12"}),(0,d.jsx)("polyline",{points:"10 6 4 12 10 18"})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:18,fontWeight:600,color:"var(--text)",marginBottom:8},children:"Get Started"}),(0,d.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.8},children:[(0,d.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"1."}),"Select a project directory from the sidebar",(0,d.jsx)("br",{}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"2."}),"Add models via the ",(0,d.jsx)("strong",{style:{color:"var(--text)"},children:"Models"})," button at the bottom"]})]})]}):null})]}),aw&&(0,d.jsx)(bU,{side:"left",ariaLabel:"Resize right panel",onResizeStart:E.beginResize,onResize:E.resizeBy,onResizeEnd:E.endResize}),(0,d.jsxs)("div",{className:`right-panel-container${aw?" right-panel-open":" right-panel-closed"}`,style:{display:aw?"flex":"none",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,width:E.width,minWidth:E.width,transition:E.isResizing?"none":void 0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",height:36},children:[(0,d.jsxs)("button",{type:"button",className:"right-panel-back-button",onClick:()=>ax(!1),title:"Back to chat","aria-label":"Back to chat",style:{height:36,padding:"0 10px",border:"none",borderRight:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,alignItems:"center",gap:6,flexShrink:0},children:[(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,d.jsx)("line",{x1:"19",y1:"12",x2:"5",y2:"12"}),(0,d.jsx)("polyline",{points:"12 19 5 12 12 5"})]}),(0,d.jsx)("span",{children:"Chat"})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,d.jsx)(ca,{tabs:bd,activeTabId:au,onSelectTab:av,onCloseTab:a9,onAskAI:a=>{let b=`I'm looking at \`${a}\`. `;F?.current?.insertIfEmpty(b)}})})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"hidden"},children:"files"===au?(0,d.jsx)(bP,{cwd:aG??i?.cwd??k??null,refreshKey:q,onOpenFile:aX,onExploreFile:aZ,onAtMention:aE}):"tools"===au?(0,d.jsx)(b4,{refreshKey:aA,visibleAppId:ay?.appId??null,cwd:aG??i?.cwd??k??null,onOpenApp:a5,onAppChanged:a6,agentRuntimeExtra:(0,d.jsx)(cl,{tree:I,activeLeafId:L,onLeafChange:P,hasSession:!!i,embedded:!0})}):"workbench"===au&&i?(0,d.jsx)(ci,{sessionId:i.id,cwd:i.cwd,onAskAboutCell:(a,b)=>{let c=a.length>400?a.slice(0,400)+"...":a;F?.current?.insertText(`Explain the code in workbench cell #${b}:
40
+ ${dh(a.provenance.stderrPreview,1500)}
41
+ \`\`\``:""].filter(Boolean).join("\n")}let dk=new Set(["pdf","png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]);function dl(a){return!Number.isFinite(a)||a<=0?"0.0G":`${(a/1024/1024/1024).toFixed(1)}G`}function dm(a){if(a<=0)return"never";let b=a/60/60/1e3;return b>=24&&Number.isInteger(b/24)?`${b/24}d`:Number.isInteger(b)?`${b}h`:`${Math.round(a/60/1e3)}m`}function dn(a){let b=a.toLowerCase();return b.endsWith(".rds")||b.endsWith(".qs")}function dp(a){return a.toLowerCase().endsWith(".h5ad")}function dq(a){let b=(a.split(/[\\/]/).pop()??a).toLowerCase().split(".").pop()??"";return dk.has(b)}function dr(){let a=(0,g.useRouter)(),b=(0,g.useSearchParams)(),{isDark:c,toggleTheme:f}=(0,bf.D)(),h=function(){let[a,b]=(0,e.useState)(!1);return a}(),[i,j]=(0,e.useState)(null),[k,l]=(0,e.useState)(null),[m,n]=(0,e.useState)(0),[o,p]=(0,e.useState)(0),[q,r]=(0,e.useState)(0),[s,t]=(0,e.useState)(0),[v,w]=(0,e.useState)(!1),[x,y]=(0,e.useState)("projects"),[z,A]=(0,e.useState)({generativeUI:!0,plotIdleTimeoutMs:1728e5}),[B,D]=(0,e.useState)(!0),E=dg({initialWidth:260,minWidth:180,maxWidth:500,storageKey:"--pi-sidebar-width"}),F=dg({initialWidth:500,minWidth:300,maxWidth:1200,storageKey:"--pi-right-panel-width",direction:"left"}),G=(0,e.useRef)(null),H=(0,e.useRef)(null),I=(0,e.useRef)(null),[J,K]=(0,e.useState)([]),[L,M]=(0,e.useState)(null),N=(0,e.useRef)(null),O=(0,e.useCallback)((a,b,c)=>{K(a),M(b),N.current=c},[]),P=(0,e.useCallback)(a=>{N.current?.(a)},[]),[Q,R]=(0,e.useState)(!1),[S,T]=(0,e.useState)(""),U=(0,e.useRef)(null),V=(0,e.useRef)(!1),W=(0,e.useCallback)(a=>a?a.name||a.firstMessage.slice(0,80)||a.id.slice(0,12):"",[]),X=(0,e.useCallback)(()=>{i&&(V.current=!1,T(i.name||W(i)),R(!0),setTimeout(()=>U.current?.select(),0))},[W,i]),Y=(0,e.useCallback)(async()=>{if(V.current){V.current=!1,R(!1);return}if(!i)return void R(!1);let a=S.trim(),b=W(i);if(R(!1),a!==(i.name??"")&&(i.name||a!==b))try{(await fetch(`/api/sessions/${encodeURIComponent(i.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:a})})).ok&&(j(b=>b&&b.id===i.id?{...b,name:a}:b),n(a=>a+1))}catch{}},[W,i,S]),Z=(0,e.useCallback)(a=>{"Enter"===a.key?(a.preventDefault(),Y()):"Escape"===a.key&&(V.current=!0,R(!1))},[Y]),$=(0,e.useCallback)(()=>{let a=!z.generativeUI;A(b=>({...b,generativeUI:a})),fetch("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({settings:{generativeUI:a}})}).then(a=>a.ok?a.json():Promise.reject(Error(`HTTP ${a.status}`))).then(a=>{A(b=>({...b,..."boolean"==typeof a.settings?.generativeUI?{generativeUI:a.settings.generativeUI}:{},..."number"==typeof a.settings?.plotIdleTimeoutMs?{plotIdleTimeoutMs:a.settings.plotIdleTimeoutMs}:{}}))}).catch(()=>A(a=>({...a,generativeUI:!a.generativeUI})))},[z.generativeUI]),[_,aa]=(0,e.useState)(null),ab=(0,e.useCallback)(a=>{aa(a)},[]),[ac,ad]=(0,e.useState)(null),ae=(0,e.useCallback)(a=>{ad(a)},[]),[af,ag]=(0,e.useState)(!1),[ah,ai]=(0,e.useState)(!1),[aj,ak]=(0,e.useState)(null),[al,am]=(0,e.useState)(!1),[an,aq]=(0,e.useState)(!1),[as,au]=(0,e.useState)(null),av=as?.updateAvailable&&as.latest?{label:`Update ${as.latest}`,title:`Current: v${as.current}
42
+ Latest: v${as.latest}
43
+ Run: ${as.updateCommand}`}:null,[aw,ax]=(0,e.useState)([]),[ay,az]=(0,e.useState)("files"),[aA,aB]=(0,e.useState)(!1),[aC,aD]=(0,e.useState)(null),[aE,aF]=(0,e.useState)(0),[aG,aH]=(0,e.useState)([]),aI=(0,e.useCallback)(a=>{G.current?.insertText("`"+a+"`")},[]),[aJ]=(0,e.useState)(()=>b.get("session")),[aK,aL]=(0,e.useState)(null),[aM,aN]=(0,e.useState)(()=>!b.get("session")),aO=(0,e.useRef)(!1),aP=(0,e.useCallback)(b=>{aL(b),aD(null),ag(!1),ak(null),b&&!aO.current&&(j(a=>a&&a.cwd!==b?null:a),l(a=>a&&a!==b?null:a),p(a=>a+1),r(a=>a+1),K([]),M(null),a.replace("/",{scroll:!1}))},[a]),aQ=(0,e.useCallback)((a,b)=>{aP(a),b?.closeDialog!==!1&&w(!1),n(a=>a+1)},[aP]),aR=(0,e.useCallback)((b,c=!1)=>{l(null),aL(b.cwd),j(b),ag(!1),ak(null),p(a=>a+1),aN(!0),c&&(aO.current=!0,setTimeout(()=>{aO.current=!1},0)),c||a.replace(`?session=${encodeURIComponent(b.id)}`,{scroll:!1})},[a]),aS=(0,e.useCallback)((b,c)=>{j(null),l(c),aL(c),ag(!1),ak(null),p(a=>a+1),K([]),M(null),a.replace("/",{scroll:!1})},[a]),aT=(0,e.useCallback)(b=>{l(null),aL(b.cwd),j(b),ag(!1),ak(null),n(a=>a+1),a.replace(`?session=${encodeURIComponent(b.id)}`,{scroll:!1}),window.dispatchEvent(new CustomEvent("session-created"))},[a]),aU=(0,e.useCallback)(()=>{n(a=>a+1),r(a=>a+1)},[]),aV=(0,e.useCallback)(b=>{n(a=>a+1),p(a=>a+1),l(null),j(a=>({...a??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:b})),a.replace(`?session=${encodeURIComponent(b)}`,{scroll:!1})},[a]),aW=(0,e.useCallback)(()=>{aN(!0)},[]),aX=(0,e.useCallback)(b=>{if(n(a=>a+1),i?.id===b){let b=i.cwd;j(null),l(b??null),ag(!1),ak(null),p(a=>a+1),K([]),M(null),a.replace("/",{scroll:!1})}},[i,a]),aY=i?.cwd??k??aK??null,[aZ,a$]=(0,e.useState)(null),a_=(0,e.useCallback)((a,b)=>{if(dn(a)||dn(b))return void aD({mode:"start",appType:"stexp",filePath:a,cwd:aY,appId:null});if(dq(a)||dq(b)){let c=`preview:${a}`;aH(d=>{let e=d.find(a=>a.id===c),f=d.filter(a=>a.id!==c);return f.push(e?{...e,filePath:a,fileName:b}:{id:c,filePath:a,fileName:b}),f});return}let c=`file:${a}`;ax(d=>d.find(a=>a.id===c)?d:[...d,{id:c,label:b,filePath:a}]),az(c),aB(!0)},[aY]),a0=(0,e.useCallback)((a,b,c)=>{c&&c>0&&a$(c),a_(a,b)},[a_]),a1=(0,e.useCallback)((a,b)=>{(dp(a)||dp(b))&&aD({mode:"start",appType:"h5adexp",filePath:a,cwd:aY,appId:null})},[aY]),a2=(0,e.useCallback)(a=>{ak(a),ag(!0)},[]),a3=(0,e.useCallback)(()=>{ag(!1),ak(null)},[]),a4=(0,e.useCallback)(()=>{az("tools"),aB(!0),aF(a=>a+1)},[]),a5=(0,e.useCallback)(a=>{aD({mode:"existing",appType:a.appType,filePath:a.filePath,cwd:a.cwd,appId:a.id}),aF(a=>a+1)},[]),a6=(0,e.useCallback)(a=>{aF(a=>a+1),aD(b=>b&&(b.appId===a.id||b.appType===a.appType&&b.filePath===a.filePath&&b.cwd===a.cwd)?"stopped"===a.status||"error"===a.status?null:{mode:"existing",appType:a.appType,filePath:a.filePath,cwd:a.cwd,appId:a.id}:b)},[]),a7=(0,e.useCallback)(a=>{aH(b=>b.filter(b=>b.id!==a))},[]),a8=(0,e.useCallback)(a=>{aH(b=>{let c=b.findIndex(b=>b.id===a);if(c<0||c===b.length-1)return b;let d=[...b],[e]=d.splice(c,1);return d.push(e),d})},[]),a9=(0,e.useCallback)(a=>{"files"!==a&&(ax(b=>b.filter(b=>b.id!==a)),az(b=>{if(b!==a)return b;let c=aw.filter(b=>b.id!==a);return c.length>0?c[c.length-1].id:"files"}))},[aw]),ba=k??(null===i&&aK?aK:null),bb=null!==i||null!==ba,bc=aM&&!bb,be=[{id:"files",label:"Files",closable:!1,icon:"files"},{id:"tools",label:"Status",closable:!1,icon:"tools"},...i?.sessionKind==="workbench"?[{id:"workbench",label:"Workbench",closable:!1,icon:"report"}]:[],...aw],bg=aw.find(a=>a.id===ay)??null,bj=i?W(i):ba?"New chat":"No session",bk=i?.cwd??ba??aK??"",bl=bk?bk.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean).pop()||bk:"",bm=i?.id??null,bo=aj??aY,bp=(0,e.useCallback)((a="projects")=>{y(a),w(!0)},[]),[bq,br]=(0,e.useState)(null),[bs,bt]=(0,e.useState)(null),[bv,bw]=(0,e.useState)(null),bx=bq?.totalBytes??0,by=bq?.currentSessionBytes??0,bz=(0,e.useCallback)(async()=>{let a=new URLSearchParams;aY&&a.set("cwd",aY),bm&&a.set("sessionId",bm);try{let b=await fetch(`/api/plot-kernels/status${a.toString()?`?${a}`:""}`),c=await b.json();if(!b.ok||!("totalBytes"in c)||!("kernels"in c))throw Error(c.error??`HTTP ${b.status}`);br(c),bt(null)}catch(a){bt(a instanceof Error?a.message:String(a))}},[bm,aY]),bB=(0,e.useCallback)(async()=>{if(bm&&!bv){bw("all"),bt(null);try{let a=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:bm})}),b=await a.json();if(!a.ok||b.error)throw Error(b.error??`HTTP ${a.status}`);window.setTimeout(()=>{bz()},600)}catch(a){bt(a instanceof Error?a.message:String(a))}finally{bw(null)}}},[bz,bv,bm]),bC=(0,e.useCallback)(async a=>{if(!bv&&0!==a.length){bw(a[0].pid),bt(null);try{for(let b of a){let a=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pid:b.pid,cwd:b.cwd,sessionId:b.sessionId,language:b.language})}),c=await a.json();if(!a.ok||c.error)throw Error(c.error??`HTTP ${a.status}`)}window.setTimeout(()=>{bz()},600)}catch(a){bt(a instanceof Error?a.message:String(a))}finally{bw(null)}}},[bz,bv]),bD=(0,e.useCallback)(()=>{ai(a=>!a),bz()},[bz]),bE=(0,e.useCallback)(()=>{ai(!1),a4()},[a4]),bF=(0,e.useCallback)(()=>{ai(!1),ag(!1),ak(null),bp("workbench-runtime")},[bp]),bG=(0,e.useCallback)(async b=>{let c,d,e;if(!bo||al)return;am(!0),bt(null);let f=new Date().toISOString(),g=`Workbench \xb7 ${"r"===b.kernel?"R":"Python"}`,h=(c=["Workbench session start.","",`Kernel: ${"r"===b.kernel?"R":"Python"}`],b.kernelId&&c.push(`Kernel ID: ${b.kernelId}${b.kernelDisplayName?` (${b.kernelDisplayName})`:""}`),b.sourcePath?c.push(`Primary source: ${b.sourcePath}`):c.push("Primary source: none selected"),b.notes&&(c.push("Notes:"),c.push(b.notes)),d=b.kernelId?`When calling \`kernel_plot_run\` or \`kernel_plot_render\`, pass kernelId: ${JSON.stringify(b.kernelId)}.`:"Use the current project/default Workbench kernel for tool calls.",e=b.sourcePath?'Initialize this workbench for analysis. Prefer the warm runtime tools (`kernel_plot_run`, `kernel_plot_render`, `kernel_plot_artifacts`, `kernel_plot_stop`) for loading data, inspecting object structure, and generating figures or tables. Use `kernel_plot_render` for quick iterative plots that appear inline. Use `kernel_plot_run` + `runtime: "kernel-lite"` when working with data already in warm memory or when saving final artifacts — this keeps loaded data persistent. First, verify the provided input path, load or inspect only that explicit source plus any files mentioned in Notes, and prepare the session for iterative analysis. Keep the first response concise and operational.':"Quick-start this workbench without loading data. Prefer the warm runtime tools (`kernel_plot_run`, `kernel_plot_render`, `kernel_plot_artifacts`, `kernel_plot_stop`) when the user later asks for analysis, plots, or saved artifacts. Do not search the project for `.rds`, `.qs`, `.h5ad`, or other dataset files unless the user explicitly asks. For now, only confirm the selected kernel/runtime is ready and ask what data or task to use next. Keep the first response concise and operational.",c.push("",d,"","CRITICAL — runtime mode:",'- ALWAYS pass `runtime: "kernel-lite"` to every `kernel_plot_run` call. This keeps loaded data, imported packages (library/import), and variables in warm memory across turns. If you use `runtime: "worker"` (one-shot), all loaded state is lost between calls and the analysis restarts from scratch on the next turn.','- Only use `runtime: "worker"` for quick one-shot scripts where memory persistence is not needed.',"- `kernel_plot_render` is always one-shot and does not share memory — use `kernel_plot_run` with `kernel-lite` for iterative work.",...b.isDescribeMode?["","DESCRIBE MODE — the user is a domain expert, not necessarily a coder:",'- The user will describe what they want in high-level terms (e.g. "compare gene expression between clusters", "make a circos plot").',"- Proactively suggest analysis approaches and explain your reasoning in plain language before writing code.","- After each result, summarize what was found in domain terms and suggest logical next steps.","- When the user mentions a figure type (heatmap, volcano, UMAP, circos, dotplot, etc.), pick the appropriate library and parameters without asking for low-level details.","- If you need a parameter the user didn't specify (e.g. which genes to plot), ask clearly and concisely.","- Always confirm what the output means for the user's research question."]:[],"",e),c.join("\n"));try{if(b.kernelId){let a=await fetch("/api/plot-kernels",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"select",cwd:bo,language:b.kernel,kernelId:b.kernelId})}),c=await a.json().catch(()=>({}));if(!a.ok||c.error)throw Error(c.error??`HTTP ${a.status}`)}let c=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:bo,type:"prompt",message:h,toolNames:(0,C.xG)("workbench"),sessionName:g,workbenchMeta:{sourcePath:b.sourcePath,kernel:b.kernel,kernelId:b.kernelId,kernelDisplayName:b.kernelDisplayName}})}),d=await c.json().catch(()=>({}));if(!c.ok||d.error||!d.sessionId)throw Error(d.error??`HTTP ${c.status}`);a3(),l(null),aL(bo),j({id:d.sessionId,path:"",cwd:bo,name:g,created:f,modified:f,messageCount:1,firstMessage:h,sessionKind:"workbench",createdBy:"launcher",sessionMeta:{sessionKind:"workbench",lastToolNames:(0,C.xG)("workbench"),createdBy:"launcher",createdAt:f,initialSourcePath:b.sourcePath||void 0,initialKernel:b.kernel}}),az("workbench"),aB(!0),K([]),M(null),p(a=>a+1),n(a=>a+1),a.replace(`?session=${encodeURIComponent(d.sessionId)}`,{scroll:!1}),window.setTimeout(()=>{bz()},600)}catch(a){bt(a instanceof Error?a.message:String(a))}finally{am(!1)}},[a3,bz,a,al,bo]),bH=(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(u,{selectedSessionId:i?.id??null,onSelectSession:aR,onNewSession:aS,onNewWorkbench:a2,initialSessionId:aJ,onInitialRestoreDone:aW,refreshKey:m,onSessionDeleted:aX,selectedCwd:i?.cwd??k??aK??null,onCwdChange:aP}),(0,d.jsx)("div",{style:{padding:"8px",flexShrink:0},children:(0,d.jsx)("button",{type:"button",onClick:()=>bp("projects"),title:"Settings","aria-label":"Settings",style:{width:34,display:"flex",alignItems:"center",justifyContent:"center",height:34,padding:0,background:"none",border:"none",borderRadius:9,color:"var(--text-muted)",cursor:"pointer",fontSize:12,transition:"background 0.12s, color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="var(--bg-hover)",a.currentTarget.style.color="var(--text)"},onMouseLeave:a=>{a.currentTarget.style.background="none",a.currentTarget.style.color="var(--text-muted)"},children:(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.38a2 2 0 0 0-.73-2.73l-.15-.09a2 2 0 0 1-1-1.74v-.51a2 2 0 0 1 1-1.72l.15-.1a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2Z"}),(0,d.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})})]});return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{style:{display:"flex",height:"100dvh",overflow:"hidden",background:"var(--bg)"},children:[(0,d.jsx)("div",{className:"sidebar-overlay-backdrop",onClick:()=>D(!1),style:{position:"fixed",inset:0,zIndex:199,background:"rgba(0,0,0,0.4)",opacity:+!!B,pointerEvents:B?"auto":"none",transition:"opacity 0.25s ease"}}),(0,d.jsx)("div",{className:`sidebar-container${B?" sidebar-open":" sidebar-closed"}`,style:{background:"var(--bg-panel)",borderRight:"1px solid var(--border)",display:"flex",flexDirection:"column",flexShrink:0,zIndex:200,width:E.width,minWidth:E.width,transition:B||E.isResizing?"none":void 0},children:bH}),B&&(0,d.jsx)(bi,{side:"right",ariaLabel:"Resize sidebar",onResizeStart:E.beginResize,onResize:E.resizeBy,onResizeEnd:E.endResize}),(0,d.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[(0,d.jsxs)("div",{ref:H,className:"app-topbar",style:{display:"flex",alignItems:"center",gap:8,flexShrink:0,borderBottom:"1px solid var(--border)",height:48,padding:"0 8px",background:"var(--bg)"},children:[(0,d.jsx)("button",{className:"topbar-sidebar-toggle",onClick:()=>D(a=>!a),title:B?"Hide sidebar":"Show sidebar",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:32,padding:0,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:a=>{a.currentTarget.style.color="var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color="var(--text-muted)",a.currentTarget.style.background="var(--bg-panel)"},children:B?(0,d.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,d.jsx)("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}):(0,d.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,d.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,d.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,d.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}),(0,d.jsxs)("div",{className:"topbar-title-area",style:{display:"flex",alignItems:"center",gap:7,minWidth:0,flex:1},children:[(0,d.jsx)("div",{style:{minWidth:0,display:"flex",alignItems:"center",gap:6},children:Q&&i?(0,d.jsx)("input",{ref:U,value:S,onChange:a=>T(a.target.value),onKeyDown:Z,onBlur:()=>void Y(),style:{width:"min(360px, 34vw)",height:28,boxSizing:"border-box",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text)",padding:"0 8px",fontSize:13,fontWeight:500,outline:"none"}}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{className:"topbar-session-title",title:bj,style:{minWidth:0,maxWidth:"min(420px, 36vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:bb?"var(--text)":"var(--text-muted)",fontSize:14,fontWeight:600,lineHeight:1.2},children:bj}),i&&(0,d.jsx)("button",{type:"button",className:"topbar-rename-button",onClick:X,title:"Rename session",style:{width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",padding:0,border:"none",borderRadius:5,background:"transparent",color:"var(--text-dim)",cursor:"pointer",flexShrink:0},onMouseEnter:a=>{a.currentTarget.style.color="var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color="var(--text-dim)",a.currentTarget.style.background="transparent"},children:(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M12 20h9"}),(0,d.jsx)("path",{d:"M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"})]})})]})}),bl&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("span",{className:"topbar-project-crumb",style:{color:"var(--text-dim)",fontSize:12,flexShrink:0},children:"/"}),(0,d.jsx)("span",{className:"topbar-project-crumb",title:bk||bl,style:{minWidth:0,maxWidth:"min(280px, 24vw)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-muted)",fontSize:12,lineHeight:1.2},children:bl})]})]}),bb&&!h&&(0,d.jsx)("div",{className:"topbar-chat-tools",style:{display:"flex",alignItems:"center",gap:6,height:28,flexShrink:0},children:(0,d.jsxs)("button",{type:"button",className:"topbar-plot-button",ref:I,onClick:bD,title:bx>0?`Open Workbench runtime \xb7 ${dl(bx)}${by>0?` (this session: ${dl(by)})`:""}`:"Open Workbench runtime status","aria-label":bx>0?`Open Workbench runtime \xb7 ${dl(bx)}${by>0?` (this session: ${dl(by)})`:""}`:"Open Workbench runtime status",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:ah?"var(--bg-selected)":bx>0||an?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${ah||bx>0||an?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:bx>0||an?"var(--accent)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s",fontVariantNumeric:"tabular-nums"},onMouseEnter:a=>{a.currentTarget.style.color=bx>0||an?"var(--accent)":"var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color=bx>0||an?"var(--accent)":"var(--text-muted)",a.currentTarget.style.background=ah?"var(--bg-selected)":bx>0||an?"rgba(37,99,235,0.08)":"var(--bg-panel)"},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M4 19V5"}),(0,d.jsx)("path",{d:"M4 19h16"}),(0,d.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,d.jsx)("span",{className:"topbar-plot-label",children:"Workbench"}),bx>0&&(0,d.jsx)("span",{className:"topbar-plot-memory",children:by>0&&by!==bx?`${dl(by)} / ${dl(bx)}`:dl(bx)})]})}),av&&(0,d.jsx)("button",{type:"button",className:"topbar-update-button",title:av.title,onClick:()=>navigator.clipboard?.writeText(as?.updateCommand??"").catch(()=>{}),style:{height:28,padding:"0 9px",borderRadius:7,border:"1px solid rgba(34,197,94,0.35)",background:"rgba(34,197,94,0.10)",color:"rgba(34,197,94,0.95)",cursor:"pointer",fontSize:11,fontWeight:650,whiteSpace:"nowrap",flexShrink:0},children:av.label}),bb&&h&&(0,d.jsxs)("button",{type:"button",className:"topbar-plot-button",ref:I,onClick:bD,title:bx>0?`Open Workbench runtime \xb7 ${dl(bx)}${by>0?` (this session: ${dl(by)})`:""}`:"Open Workbench runtime status","aria-label":bx>0?`Open Workbench runtime \xb7 ${dl(bx)}${by>0?` (this session: ${dl(by)})`:""}`:"Open Workbench runtime status",style:{display:"flex",alignItems:"center",gap:4,height:28,padding:"0 7px",flexShrink:0,background:ah?"var(--bg-selected)":bx>0||an?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${ah||bx>0||an?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:bx>0||an?"var(--accent)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,d.jsx)("path",{d:"M4 19V5"}),(0,d.jsx)("path",{d:"M4 19h16"}),(0,d.jsx)("path",{d:"m7 16 3-5 4 3 4-7"})]}),(0,d.jsx)("span",{className:"topbar-plot-label",children:"WB"}),bx>0&&(0,d.jsx)("span",{className:"topbar-plot-memory",children:by>0&&by!==bx?`${dl(by)} / ${dl(bx)}`:dl(bx)})]}),bb&&(_||ac)&&(()=>{let a=_?.tokens,b=_?.cost??0,c=a=>a>=1e6?`${(a/1e6).toFixed(1)}M`:a>=1e3?`${(a/1e3).toFixed(0)}k`:String(a),e=b>0?b>=.01?`$${b.toFixed(2)}`:"<$0.01":null,f="var(--text-muted)",g=null;if(ac?.contextWindow){let a=ac.percent;null!==a&&a>90?f="#ef4444":null!==a&&a>70&&(f="rgba(234,179,8,0.95)"),g=null!==a?`${a.toFixed(0)}% / ${c(ac.contextWindow)}`:`? / ${c(ac.contextWindow)}`}let h=[];if(a&&(h.push(`in: ${a.input.toLocaleString()}`),h.push(`out: ${a.output.toLocaleString()}`),h.push(`cache read: ${a.cacheRead.toLocaleString()}`),h.push(`cache write: ${a.cacheWrite.toLocaleString()}`),b>0&&h.push(`cost: $${b.toFixed(4)}`)),ac?.contextWindow){let a=ac.percent;h.push(`context: ${null!==a?a.toFixed(1)+"%":"unknown"} of ${ac.contextWindow.toLocaleString()} tokens`)}let i=h.join(" | ");return(0,d.jsxs)("div",{className:"topbar-session-stats",title:i,style:{display:"flex",alignItems:"center",gap:10,padding:"0 8px",height:28,border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",fontSize:11,color:"var(--text-muted)",whiteSpace:"nowrap",cursor:"default",fontVariantNumeric:"tabular-nums"},children:[a&&a.input>0&&(0,d.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("line",{x1:"5",y1:"8.5",x2:"5",y2:"1.5"}),(0,d.jsx)("polyline",{points:"2 4 5 1.5 8 4"})]}),c(a.input)]}),a&&a.output>0&&(0,d.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("line",{x1:"5",y1:"1.5",x2:"5",y2:"8.5"}),(0,d.jsx)("polyline",{points:"2 6 5 8.5 8 6"})]}),c(a.output)]}),a&&a.cacheRead>0&&(0,d.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M8.5 5a3.5 3.5 0 1 1-1-2.45"}),(0,d.jsx)("polyline",{points:"6.5 1.5 8.5 2.5 7.5 4.5"})]}),c(a.cacheRead)]}),e&&(0,d.jsx)("span",{style:{display:"flex",alignItems:"center",color:"var(--text)",fontWeight:500},children:e}),g&&(0,d.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,color:f},children:[(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("path",{d:"M1 9 L1 5 Q1 1 5 1 Q9 1 9 5 L9 9"}),(0,d.jsx)("line",{x1:"1",y1:"9",x2:"9",y2:"9"})]}),g]})]})})(),(0,d.jsx)("button",{type:"button",className:"topbar-icon-button topbar-generate-ui-toggle",onClick:$,title:`生成式 UI: ${z.generativeUI?"on":"off"}`,"aria-label":`生成式 UI: ${z.generativeUI?"on":"off"}`,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:z.generativeUI?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${z.generativeUI?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:z.generativeUI?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:a=>{a.currentTarget.style.color=z.generativeUI?"var(--accent)":"var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color=z.generativeUI?"var(--accent)":"var(--text-muted)",a.currentTarget.style.background=z.generativeUI?"var(--bg-selected)":"var(--bg-panel)"},children:(0,d.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1.5"}),(0,d.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1.5"}),(0,d.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1.5"}),(0,d.jsx)("path",{d:"M16 17h5"}),(0,d.jsx)("path",{d:"M18.5 14.5v5"})]})}),(0,d.jsx)("button",{className:"topbar-icon-button topbar-theme-toggle",onClick:a=>{let b=a.currentTarget.getBoundingClientRect();f({x:b.left+b.width/2,y:b.top+b.height/2})},title:c?"Switch to light mode":"Switch to dark mode","aria-label":c?"Switch to light mode":"Switch to dark mode","aria-pressed":c,style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:a=>{a.currentTarget.style.color="var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color="var(--text-muted)",a.currentTarget.style.background="var(--bg-panel)"},children:c?(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"5"}),(0,d.jsx)("line",{x1:"12",y1:"1",x2:"12",y2:"3"}),(0,d.jsx)("line",{x1:"12",y1:"21",x2:"12",y2:"23"}),(0,d.jsx)("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"}),(0,d.jsx)("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"}),(0,d.jsx)("line",{x1:"1",y1:"12",x2:"3",y2:"12"}),(0,d.jsx)("line",{x1:"21",y1:"12",x2:"23",y2:"12"}),(0,d.jsx)("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"}),(0,d.jsx)("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"})]}):(0,d.jsx)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,d.jsx)("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})})}),(0,d.jsx)("button",{className:"topbar-icon-button topbar-right-panel-toggle",onClick:()=>aB(a=>!a),title:aA?"Hide right panel":"Show right panel","aria-label":aA?"Hide right panel":"Show right panel",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:aA?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${aA?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:aA?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:a=>{a.currentTarget.style.color=aA?"var(--accent)":"var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color=aA?"var(--accent)":"var(--text-muted)",a.currentTarget.style.background=aA?"var(--bg-selected)":"var(--bg-panel)"},children:(0,d.jsxs)("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,d.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:bb?(0,d.jsx)(ao,{session:i,newSessionCwd:ba,onAgentEnd:aU,onSessionCreated:aT,onSessionForked:aV,modelsRefreshKey:s,chatInputRef:G,onBranchDataChange:O,onSessionStatsChange:ab,onContextUsageChange:ae,onToolPresetActive:aq,generativeUI:z.generativeUI,activeFilePath:bg?.filePath??null,onOpenFileAtLine:a0},o):bc?aK?(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:15},children:"Select a session from the sidebar"}):(0,d.jsxs)("div",{style:{position:"absolute",top:12,left:12,display:"flex",alignItems:"flex-start",gap:8,userSelect:"none",pointerEvents:"none"},children:[(0,d.jsxs)("svg",{width:"44",height:"44",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:.7,flexShrink:0},children:[(0,d.jsx)("line",{x1:"20",y1:"12",x2:"4",y2:"12"}),(0,d.jsx)("polyline",{points:"10 6 4 12 10 18"})]}),(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{fontSize:18,fontWeight:600,color:"var(--text)",marginBottom:8},children:"Get Started"}),(0,d.jsxs)("div",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.8},children:[(0,d.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"1."}),"Select a project directory from the sidebar",(0,d.jsx)("br",{}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",marginRight:6},children:"2."}),"Add models via the ",(0,d.jsx)("strong",{style:{color:"var(--text)"},children:"Models"})," button at the bottom"]})]})]}):null})]}),aA&&(0,d.jsx)(bi,{side:"left",ariaLabel:"Resize right panel",onResizeStart:F.beginResize,onResize:F.resizeBy,onResizeEnd:F.endResize}),(0,d.jsxs)("div",{className:`right-panel-container${aA?" right-panel-open":" right-panel-closed"}`,style:{display:aA?"flex":"none",flexDirection:"column",borderLeft:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,width:F.width,minWidth:F.width,transition:F.isResizing?"none":void 0},children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",flexShrink:0,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",height:36},children:[(0,d.jsxs)("button",{type:"button",className:"right-panel-back-button",onClick:()=>aB(!1),title:"Back to chat","aria-label":"Back to chat",style:{height:36,padding:"0 10px",border:"none",borderRight:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12,alignItems:"center",gap:6,flexShrink:0},children:[(0,d.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,d.jsx)("line",{x1:"19",y1:"12",x2:"5",y2:"12"}),(0,d.jsx)("polyline",{points:"12 19 5 12 12 5"})]}),(0,d.jsx)("span",{children:"Chat"})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"hidden"},children:(0,d.jsx)(bA,{tabs:be,activeTabId:ay,onSelectTab:az,onCloseTab:a9,onAskAI:a=>{let b=`I'm looking at \`${a}\`. `;G?.current?.insertIfEmpty(b)}})})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"hidden"},children:"files"===ay?(0,d.jsx)(bd,{cwd:aK??i?.cwd??k??null,refreshKey:q,onOpenFile:a_,onExploreFile:a1,onAtMention:aI}):"tools"===ay?(0,d.jsx)(bu,{refreshKey:aE,visibleAppId:aC?.appId??null,cwd:aK??i?.cwd??k??null,onOpenApp:a5,onAppChanged:a6,agentRuntimeExtra:(0,d.jsx)(bL,{tree:J,activeLeafId:L,onLeafChange:P,hasSession:!!i,embedded:!0})}):"workbench"===ay&&i?(0,d.jsx)(bI,{sessionId:i.id,cwd:i.cwd,onAskAboutCell:(a,b)=>{let c=a.length>400?a.slice(0,400)+"...":a;G?.current?.insertText(`Explain the code in workbench cell #${b}:
64
44
  \`\`\`
65
45
  ${c}
66
46
  \`\`\`
67
- `)},onAskAboutArtifact:a=>{F?.current?.insertText(dV(a))},onEditArtifact:a=>{F?.current?.insertText(dW(a))},onOpenArtifact:a=>{let b=a.split(/[\\/]/).pop()||a;aX(a,b)}}):be?.filePath?be.filePath.startsWith("__")?(0,d.jsx)(bT,{filePath:be.filePath}):(0,d.jsx)(a2,{filePath:be.filePath,children:(0,d.jsx)(a0.h,{filePath:be.filePath,cwd:aG??void 0,onOpenFile:aX,scrollToLine:aV,workbenchSessionId:i?.sessionKind==="workbench"?i.id:null,onAskAboutArtifact:a=>F?.current?.insertText(dV(a)),onEditArtifact:a=>F?.current?.insertText(dW(a))})}):(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:"No file open"})})]})]}),(0,d.jsx)(dS,{open:ah,anchorRef:H,status:bl,error:bn,currentSessionId:bi,currentCwd:aU,idleTimeoutLabel:dZ(z.plotIdleTimeoutMs),busyPid:"number"==typeof bp?bp:null,onClose:()=>ai(!1),onRefresh:()=>{bt()},onReleaseKernels:a=>{bv(a)},onOpenSettings:by,onOpenStatus:bx}),v&&(0,d.jsx)(dI,{cwd:aU,generativeUI:z.generativeUI,initialTab:x,onGenerativeUIToggle:$,onModelsChanged:()=>t(a=>a+1),onProjectSelect:aM,onProjectsChanged:()=>n(a=>a+1),onClose:()=>{w(!1),t(a=>a+1)}}),af&&(0,d.jsx)(dM,{cwd:bj,runtime:{totalBytes:br,currentSessionBytes:bs,idleTimeoutLabel:dZ(z.plotIdleTimeoutMs)},runtimeError:bn,busy:al,onClose:a1,onLaunch:a=>bz(a),onReleaseCurrentRuntime:i?.id&&i.cwd===bj?()=>{bu()}:void 0,onOpenSettings:by}),(0,d.jsx)(bZ,{appType:ay?.appType??"stexp",filePath:ay?.filePath??null,cwd:ay?.cwd??null,appId:ay?.appId??null,sessionId:i?.id??null,onClose:()=>az(null),onAppChanged:a6,onOpenTools:a3}),aC.map((a,b)=>(0,d.jsx)(a4,{id:a.id,filePath:a.filePath,fileName:a.fileName,cwd:aG??i?.cwd??k??void 0,active:b===aC.length-1,stackIndex:b,zIndex:700+b,onClose:a7,onFocus:a8,onOpenFile:aX},a.id))]})}},61345:(a,b)=>{b.render=function(a,b,c){let d=a.modules.size,e=a.modules.data,f="\x1b[47m \x1b[0m",g="",h=Array(d+3).join(f),i=[,,].join(f);g+=h+"\n";for(let a=0;a<d;++a){g+=f;for(let b=0;b<d;b++)g+=e[a*d+b]?"\x1b[40m \x1b[0m":f;g+=i+"\n"}return g+=h+"\n","function"==typeof c&&c(null,g),g}},63033:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},64323:(a,b)=>{let c="[0-9]+",d="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+",e="(?:(?![A-Z0-9 $%*+\\-./:]|"+(d=d.replace(/u/g,"\\u"))+")(?:.|[\r\n]))+";b.KANJI=RegExp(d,"g"),b.BYTE_KANJI=RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),b.BYTE=RegExp(e,"g"),b.NUMERIC=RegExp(c,"g"),b.ALPHANUMERIC=RegExp("[A-Z $%*+\\-./:]+","g");let f=RegExp("^"+d+"$"),g=RegExp("^"+c+"$"),h=RegExp("^[A-Z0-9 $%*+\\-./:]+$");b.testKanji=function(a){return f.test(a)},b.testNumeric=function(a){return g.test(a)},b.testAlphanumeric=function(a){return h.test(a)}},64424:(a,b,c)=>{let d=c(93669),e=c(58305);function f(a){this.mode=d.KANJI,this.data=a}f.getBitsLength=function(a){return 13*a},f.prototype.getLength=function(){return this.data.length},f.prototype.getBitsLength=function(){return f.getBitsLength(this.data.length)},f.prototype.write=function(a){let b;for(b=0;b<this.data.length;b++){let c=e.toSJIS(this.data[b]);if(c>=33088&&c<=40956)c-=33088;else if(c>=57408&&c<=60351)c-=49472;else throw Error("Invalid SJIS character: "+this.data[b]+"\nMake sure your charset is UTF-8");c=(c>>>8&255)*192+(255&c),a.put(c,13)}},a.exports=f},66530:(a,b,c)=>{let d=c(61345),e=c(86491);b.render=function(a,b,c){return b&&b.small?e.render(a,b,c):d.render(a,b,c)}},67269:a=>{"use strict";a.exports={PNG_SIGNATURE:[137,80,78,71,13,10,26,10],TYPE_IHDR:0x49484452,TYPE_IEND:0x49454e44,TYPE_IDAT:0x49444154,TYPE_PLTE:0x504c5445,TYPE_tRNS:0x74524e53,TYPE_gAMA:0x67414d41,COLORTYPE_GRAYSCALE:0,COLORTYPE_PALETTE:1,COLORTYPE_COLOR:2,COLORTYPE_ALPHA:4,COLORTYPE_PALETTE_COLOR:3,COLORTYPE_COLOR_ALPHA:6,COLORTYPE_TO_BPP_MAP:{0:1,2:3,3:1,4:2,6:4},GAMMA_DIVISION:1e5}},70722:a=>{"use strict";a.exports=require("next/dist/shared/lib/invariant-error")},72081:(a,b,c)=>{let d=c(88397),e={WW:" ",WB:"▄",BB:"█",BW:"▀"},f={BB:" ",BW:"▄",WW:"█",WB:"▀"};b.render=function(a,b,c){let g=d.getOptions(b),h=e;("#ffffff"===g.color.dark.hex||"#000000"===g.color.light.hex)&&(h=f);let i=a.modules.size,j=a.modules.data,k="",l=Array(i+2*g.margin+1).join(h.WW);l=Array(g.margin/2+1).join(l+"\n");let m=Array(g.margin+1).join(h.WW);k+=l;for(let a=0;a<i;a+=2){k+=m;for(let b=0;b<i;b++){var n;let c=j[a*i+b],d=j[(a+1)*i+b];k+=(n=h,c&&d?n.BB:c&&!d?n.BW:!c&&d?n.WB:n.WW)}k+=m+"\n"}return k+=l.slice(0,-1),"function"==typeof c&&c(null,k),k},b.renderToFile=function(a,d,e,f){void 0===f&&(f=e,e=void 0);let g=c(29021),h=b.render(d,e);g.writeFile(a,h,f)}},73136:a=>{"use strict";a.exports=require("node:url")},74075:a=>{"use strict";a.exports=require("zlib")},76708:a=>{a.exports=function(){return"function"==typeof Promise&&Promise.prototype&&Promise.prototype.then}},76760:a=>{"use strict";a.exports=require("node:path")},77068:a=>{"use strict";a.exports=require("next/dist/shared/lib/size-limit")},78908:a=>{"use strict";a.exports=import("shiki")},79428:a=>{"use strict";a.exports=require("buffer")},80183:(a,b,c)=>{"use strict";let d=c(12412).ok,e=c(74075),f=c(28354),g=c(79428).kMaxLength;function h(a){if(!(this instanceof h))return new h(a);a&&a.chunkSize<e.Z_MIN_CHUNK&&(a.chunkSize=e.Z_MIN_CHUNK),e.Inflate.call(this,a),this._offset=void 0===this._offset?this._outOffset:this._offset,this._buffer=this._buffer||this._outBuffer,a&&null!=a.maxLength&&(this._maxLength=a.maxLength)}function i(a,b){b&&process.nextTick(b),a._handle&&(a._handle.close(),a._handle=null)}function j(a,b){var c=new h(b),d=a;if("string"==typeof d&&(d=Buffer.from(d)),!(d instanceof Buffer))throw TypeError("Not a string or buffer");let f=c._finishFlushFlag;return null==f&&(f=e.Z_FINISH),c._processChunk(d,f)}h.prototype._processChunk=function(a,b,c){let f,h;if("function"==typeof c)return e.Inflate._processChunk.call(this,a,b,c);let j=this,k=a&&a.length,l=this._chunkSize-this._offset,m=this._maxLength,n=0,o=[],p=0;this.on("error",function(a){f=a}),d(this._handle,"zlib binding closed");do h=(h=this._handle.writeSync(b,a,n,k,this._buffer,this._offset,l))||this._writeState;while(!this._hadError&&function(a,b){if(j._hadError)return;let c=l-b;if(d(c>=0,"have should not go down"),c>0){let a=j._buffer.slice(j._offset,j._offset+c);if(j._offset+=c,a.length>m&&(a=a.slice(0,m)),o.push(a),p+=a.length,0==(m-=a.length))return!1}return(0===b||j._offset>=j._chunkSize)&&(l=j._chunkSize,j._offset=0,j._buffer=Buffer.allocUnsafe(j._chunkSize)),0===b&&(n+=k-a,k=a,!0)}(h[0],h[1]));if(this._hadError)throw f;if(p>=g)throw i(this),RangeError("Cannot create final Buffer. It would be larger than 0x"+g.toString(16)+" bytes");let q=Buffer.concat(o,p);return i(this),q},f.inherits(h,e.Inflate),a.exports=b=j,b.Inflate=h,b.createInflate=function(a){return new h(a)},b.inflateSync=j},80706:(a,b,c)=>{"use strict";let d=!0,e=c(74075);e.deflateSync||(d=!1);let f=c(67269),g=c(98052);a.exports=function(a,b){if(!d)throw Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let c=new g(b||{}),h=[];h.push(Buffer.from(f.PNG_SIGNATURE)),h.push(c.packIHDR(a.width,a.height)),a.gamma&&h.push(c.packGAMA(a.gamma));let i=c.filterData(a.data,a.width,a.height),j=e.deflateSync(i,c.getDeflateOptions());if(i=null,!j||!j.length)throw Error("bad png - invalid compressed data response");return h.push(c.packIDAT(j)),h.push(c.packIEND()),Buffer.concat(h)}},81754:(a,b)=>{let c=new Uint8Array(512),d=new Uint8Array(256),e=1;for(let a=0;a<255;a++)c[a]=e,d[e]=a,256&(e<<=1)&&(e^=285);for(let a=255;a<512;a++)c[a]=c[a-255];b.log=function(a){if(a<1)throw Error("log("+a+")");return d[a]},b.exp=function(a){return c[a]},b.mul=function(a,b){return 0===a||0===b?0:c[d[a]+d[b]]}},81769:a=>{"use strict";let b=a.exports=function(a){this._buffer=a,this._reads=[]};b.prototype.read=function(a,b){this._reads.push({length:Math.abs(a),allowLess:a<0,func:b})},b.prototype.process=function(){for(;this._reads.length>0&&this._buffer.length;){let a=this._reads[0];if(this._buffer.length&&(this._buffer.length>=a.length||a.allowLess)){this._reads.shift();let b=this._buffer;this._buffer=b.slice(a.length),a.func.call(this,b.slice(0,a.length))}else break}return this._reads.length>0?Error("There are some read requests waitng on finished stream"):this._buffer.length>0?Error("unrecognised content at end of stream"):void 0}},83670:a=>{"use strict";a.exports=function(a,b){let c=b.depth,d=b.width,e=b.height,f=b.colorType,g=b.transColor,h=b.palette,i=a;return 3===f?!function(a,b,c,d,e){let f=0;for(let g=0;g<d;g++)for(let d=0;d<c;d++){let c=e[a[f]];if(!c)throw Error("index "+a[f]+" not in palette");for(let a=0;a<4;a++)b[f+a]=c[a];f+=4}}(a,i,d,e,h):(g&&function(a,b,c,d,e){let f=0;for(let g=0;g<d;g++)for(let d=0;d<c;d++){let c=!1;if(1===e.length?e[0]===a[f]&&(c=!0):e[0]===a[f]&&e[1]===a[f+1]&&e[2]===a[f+2]&&(c=!0),c)for(let a=0;a<4;a++)b[f+a]=0;f+=4}}(a,i,d,e,g),8!==c&&(16===c&&(i=Buffer.alloc(d*e*4)),!function(a,b,c,d,e){let f=Math.pow(2,e)-1,g=0;for(let e=0;e<d;e++)for(let d=0;d<c;d++){for(let c=0;c<4;c++)b[g+c]=Math.floor(255*a[g+c]/f+.5);g+=4}}(a,i,d,e,c))),i}},83929:(a,b)=>{b.isValid=function(a){return!isNaN(a)&&a>=1&&a<=40}},84879:a=>{"use strict";var b={single_source_shortest_paths:function(a,c,d){var e,f,g,h,i,j,k,l={},m={};m[c]=0;var n=b.PriorityQueue.make();for(n.push(c,0);!n.empty();)for(g in f=(e=n.pop()).value,h=e.cost,i=a[f]||{})i.hasOwnProperty(g)&&(j=h+i[g],k=m[g],(void 0===m[g]||k>j)&&(m[g]=j,n.push(g,j),l[g]=f));if(void 0!==d&&void 0===m[d])throw Error("Could not find a path from "+c+" to "+d+".");return l},extract_shortest_path_from_predecessor_list:function(a,b){for(var c=[],d=b;d;)c.push(d),a[d],d=a[d];return c.reverse(),c},find_path:function(a,c,d){var e=b.single_source_shortest_paths(a,c,d);return b.extract_shortest_path_from_predecessor_list(e,d)},PriorityQueue:{make:function(a){var c,d=b.PriorityQueue,e={};for(c in a=a||{},d)d.hasOwnProperty(c)&&(e[c]=d[c]);return e.queue=[],e.sorter=a.sorter||d.default_sorter,e},default_sorter:function(a,b){return a.cost-b.cost},push:function(a,b){this.queue.push({value:a,cost:b}),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return 0===this.queue.length}}};a.exports=b},86439:a=>{"use strict";a.exports=require("next/dist/shared/lib/no-fallback-error.external")},86491:(a,b)=>{let c="\x1b[37m",d="\x1b[30m",e="\x1b[0m",f="\x1b[47m"+d,g="\x1b[40m"+c,h=function(a,b,c,d){let e=b+1;return c>=e||d>=e||d<-1||c<-1?"0":c>=b||d>=b||d<0||c<0?"1":a[d*b+c]?"2":"1"},i=function(a,b,c,d){return h(a,b,c,d)+h(a,b,c,d+1)};b.render=function(a,b,h){var j,k;let l=a.modules.size,m=a.modules.data,n=!!(b&&b.inverse),o=b&&b.inverse?g:f,p={"00":e+" "+o,"01":e+(j=n?d:c)+"▄"+o,"02":e+(k=n?c:d)+"▄"+o,10:e+j+"▀"+o,11:" ",12:"▄",20:e+k+"▀"+o,21:"▀",22:"█"},q=e+"\n"+o,r=o;for(let a=-1;a<l+1;a+=2){for(let b=-1;b<l;b++)r+=p[i(m,l,b,a)];r+=p[i(m,l,l,a)]+q}return r+=e,"function"==typeof h&&h(null,r),r}},88066:(a,b,c)=>{let d=c(58305).getSymbolSize;b.getRowColCoords=function(a){if(1===a)return[];let b=Math.floor(a/7)+2,c=d(a),e=145===c?26:2*Math.ceil((c-13)/(2*b-2)),f=[c-7];for(let a=1;a<b-1;a++)f[a]=f[a-1]-e;return f.push(6),f.reverse()},b.getPositions=function(a){let c=[],d=b.getRowColCoords(a),e=d.length;for(let a=0;a<e;a++)for(let b=0;b<e;b++)(0!==a||0!==b)&&(0!==a||b!==e-1)&&(a!==e-1||0!==b)&&c.push([d[a],d[b]]);return c}},88397:(a,b)=>{function c(a){if("number"==typeof a&&(a=a.toString()),"string"!=typeof a)throw Error("Color should be defined as hex string");let b=a.slice().replace("#","").split("");if(b.length<3||5===b.length||b.length>8)throw Error("Invalid hex color: "+a);(3===b.length||4===b.length)&&(b=Array.prototype.concat.apply([],b.map(function(a){return[a,a]}))),6===b.length&&b.push("F","F");let c=parseInt(b.join(""),16);return{r:c>>24&255,g:c>>16&255,b:c>>8&255,a:255&c,hex:"#"+b.slice(0,6).join("")}}b.getOptions=function(a){a||(a={}),a.color||(a.color={});let b=void 0===a.margin||null===a.margin||a.margin<0?4:a.margin,d=a.width&&a.width>=21?a.width:void 0,e=a.scale||4;return{width:d,scale:d?4:e,margin:b,color:{dark:c(a.color.dark||"#000000ff"),light:c(a.color.light||"#ffffffff")},type:a.type,rendererOpts:a.rendererOpts||{}}},b.getScale=function(a,b){return b.width&&b.width>=a+2*b.margin?b.width/(a+2*b.margin):b.scale},b.getImageWidth=function(a,c){let d=b.getScale(a,c);return Math.floor((a+2*c.margin)*d)},b.qrToImageData=function(a,c,d){let e=c.modules.size,f=c.modules.data,g=b.getScale(e,d),h=Math.floor((e+2*d.margin)*g),i=d.margin*g,j=[d.color.light,d.color.dark];for(let b=0;b<h;b++)for(let c=0;c<h;c++){let k=(b*h+c)*4,l=d.color.light;b>=i&&c>=i&&b<h-i&&c<h-i&&(l=j[+!!f[Math.floor((b-i)/g)*e+Math.floor((c-i)/g)]]),a[k++]=l.r,a[k++]=l.g,a[k++]=l.b,a[k]=l.a}}},90082:(a,b,c)=>{b.render=c(32835).render,b.renderToFile=function(a,d,e,f){void 0===f&&(f=e,e=void 0);let g=c(29021),h=b.render(d,e);g.writeFile(a,'<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'+h,f)}},91926:(a,b,c)=>{"use strict";c.r(b),c.d(b,{__next_app__:()=>M,handler:()=>O,routeModule:()=>N});var d=c(7553),e=c(84006),f=c(67798),g=c(34775),h=c(99373),i=c(73461),j=c(1020),k=c(26349),l=c(54365),m=c(16023),n=c(63747),o=c(24235),p=c(23938),q=c(261),r=c(66758),s=c(77243),t=c(26713),u=c(37527),v=c(22820),w=c(88216),x=c(47929),y=c(79551),z=c(71797),A=c(89125),B=c(86439),C=c(77068),D=c(27269),E=c(61287),F=c(81494),G=c(70722),H=c(70753),I=c(43954),J=c(17891),K={};for(let a in E)0>["default","__next_app__","routeModule","handler"].indexOf(a)&&(K[a]=()=>E[a]);c.d(b,K);let L={children:["",{children:["__PAGE__",{},{page:[()=>Promise.resolve().then(c.bind(c,99647)),"/home/runner/work/annovibe/annovibe/app/page.tsx"],metadata:{icon:[async a=>(await Promise.resolve().then(c.bind(c,86364))).default(a)],apple:[],openGraph:[],twitter:[],manifest:void 0}}]},{layout:[()=>Promise.resolve().then(c.bind(c,32056)),"/home/runner/work/annovibe/annovibe/app/layout.tsx"],"global-error":[()=>Promise.resolve().then(c.t.bind(c,95547,23)),"next/dist/client/components/builtin/global-error.js"],"not-found":[()=>Promise.resolve().then(c.t.bind(c,55091,23)),"next/dist/client/components/builtin/not-found.js"],forbidden:[()=>Promise.resolve().then(c.t.bind(c,45270,23)),"next/dist/client/components/builtin/forbidden.js"],unauthorized:[()=>Promise.resolve().then(c.t.bind(c,28193,23)),"next/dist/client/components/builtin/unauthorized.js"],metadata:{icon:[async a=>(await Promise.resolve().then(c.bind(c,86364))).default(a)],apple:[],openGraph:[],twitter:[],manifest:void 0}},[]]}.children,M={require:c,loadChunk:()=>Promise.resolve()},N=new d.AppPageRouteModule({definition:{kind:e.RouteKind.APP_PAGE,page:"/page",pathname:"/",bundlePath:"",filename:"",appPaths:[]},userland:{loaderTree:L},distDir:".next",relativeProjectDir:""});async function O(a,b,d){var K,P,Q,R,S;d.requestMeta&&(0,h.setRequestMeta)(a,d.requestMeta),N.isDev&&(0,h.addRequestMeta)(a,"devRequestTimingInternalsEnd",process.hrtime.bigint());let T=!!(0,h.getRequestMeta)(a,"minimalMode"),U="/page";"/index"===U&&(U="/");let V=await N.prepare(a,b,{srcPage:U,multiZoneDraftMode:!1});if(!V)return b.statusCode=400,b.end("Bad Request"),null==d.waitUntil||d.waitUntil.call(d,Promise.resolve()),null;let{buildId:W,query:X,params:Y,pageIsDynamic:Z,buildManifest:$,nextFontManifest:_,reactLoadableManifest:aa,serverActionsManifest:ab,clientReferenceManifest:ac,subresourceIntegrityManifest:ad,prerenderManifest:ae,isDraftMode:af,resolvedPathname:ag,revalidateOnlyGenerated:ah,routerServerContext:ai,nextConfig:aj,parsedUrl:ak,interceptionRoutePatterns:al,deploymentId:am,clientAssetToken:an}=V,ao=(0,q.normalizeAppPath)(U),{isOnDemandRevalidate:ap}=V,aq=aj.experimental.ppr&&!aj.cacheComponents&&(0,I.isInterceptionRouteAppPath)(ag)?null:N.match(ag,ae),ar=(null==aq?void 0:aq.route)??null,as=!!ae.routes[ag],at=a.headers["user-agent"]||"",au=(0,t.getBotType)(at),av=(0,p.isHtmlBotRequest)(a),aw=(0,h.getRequestMeta)(a,"isPrefetchRSCRequest")??"1"===a.headers[s.NEXT_ROUTER_PREFETCH_HEADER],ax=(0,h.getRequestMeta)(a,"isRSCRequest")??!!a.headers[s.RSC_HEADER],ay=(0,r.getIsPossibleServerAction)(a),az=(0,m.checkIsAppPPREnabled)(aj.experimental.ppr),aA=a.headers[x.NEXT_RESUME_STATE_LENGTH_HEADER];if(!(0,h.getRequestMeta)(a,"postponed")&&T&&az&&ay&&aA&&"string"==typeof aA){let e=parseInt(aA,10),{maxPostponedStateSize:f,maxPostponedStateSizeBytes:g}=(0,D.getMaxPostponedStateSize)(aj.experimental.maxPostponedStateSize);if(!isNaN(e)&&e>0){if(e>g)return b.statusCode=413,b.end((0,D.getPostponedStateExceededErrorMessage)(f)),null==d.waitUntil||d.waitUntil.call(d,Promise.resolve()),null;let i="1 MB",j=(null==(S=aj.experimental.serverActions)?void 0:S.bodySizeLimit)??i,k=e+(j!==i?c(95726).parse(j):1048576),l=await (0,D.readBodyWithSizeLimit)(a,k);if(null===l)return b.statusCode=413,b.end("Request body exceeded limit. To configure the body size limit for Server Actions, see: https://nextjs.org/docs/app/api-reference/next-config-js/serverActions#bodysizelimit"),null==d.waitUntil||d.waitUntil.call(d,Promise.resolve()),null;if(l.length>=e){let b=l.subarray(0,e).toString("utf8");(0,h.addRequestMeta)(a,"postponed",b);let c=l.subarray(e);(0,h.addRequestMeta)(a,"actionBody",c)}else throw Object.defineProperty(Error(`invariant: expected ${e} bytes of postponed state but only received ${l.length} bytes`),"__NEXT_ERROR_CODE",{value:"E979",enumerable:!1,configurable:!0})}}if(!(0,h.getRequestMeta)(a,"postponed")&&az&&"1"===a.headers[x.NEXT_RESUME_HEADER]&&"POST"===a.method){let{maxPostponedStateSize:c,maxPostponedStateSizeBytes:e}=(0,D.getMaxPostponedStateSize)(aj.experimental.maxPostponedStateSize),f=await (0,D.readBodyWithSizeLimit)(a,e);if(null===f)return b.statusCode=413,b.end((0,D.getPostponedStateExceededErrorMessage)(c)),null==d.waitUntil||d.waitUntil.call(d,Promise.resolve()),null;let g=f.toString("utf8");(0,h.addRequestMeta)(a,"postponed",g)}let aB=!0===N.isDev||!0===aj.experimental.exposeTestingApiInProductionBuild,aC=aB&&("1"===a.headers[s.NEXT_INSTANT_PREFETCH_HEADER]||void 0===a.headers[s.RSC_HEADER]&&"string"==typeof a.headers.cookie&&a.headers.cookie.includes(s.NEXT_INSTANT_TEST_COOKIE+"=")),aD=(az||aC)&&((null==(K=ae.routes[ao]??ae.dynamicRoutes[ao])?void 0:K.renderingMode)==="PARTIALLY_STATIC"||aC&&(aB||(null==ai?void 0:ai.experimentalTestProxy)===!0)),aE=aC&&aD,aF=aE&&!0===N.isDev,aG=!1,aH=aD?(0,h.getRequestMeta)(a,"postponed"):void 0,aI=null==(P=ae.routes[ag])?void 0:P.prefetchDataRoute,aJ=aD&&ax&&!aw&&!aI;T&&(aJ=aJ&&!!aH);let aK=(0,h.getRequestMeta)(a,"segmentPrefetchRSCRequest"),aL=(!au||!aD)&&(!at||(0,p.shouldServeStreamingMetadata)(at,aj.htmlLimitedBots)),aM=!!((ar||as||ae.routes[ao])&&!(au&&aD)),aN=aD&&!0===aj.cacheComponents,aO=!0===N.isDev||!aM||"string"==typeof aH||(aN&&(0,h.getRequestMeta)(a,"onCacheEntryV2")?aJ&&!T:aJ),aP=!!au&&aD,aQ=(null==ar?void 0:ar.remainingPrerenderableParams)??[],aR=(null==ar?void 0:ar.fallback)===null&&((null==(Q=ar.fallbackRootParams)?void 0:Q.length)??0)>0,aS=null;if(!af&&aM&&!aO&&!ay&&!aH&&!aJ){let a=aq?"string"==typeof(null==ar?void 0:ar.fallback)?ar.fallback:aq.source:null;if(!0===aj.experimental.partialFallbacks&&a&&(null==ar?void 0:ar.fallbackRouteParams)&&!aR){if(aQ.length>0){let b,c=(b=new Map(aQ.map(a=>[a.paramName,a])),a.split("/").map(a=>{let c=(0,J.getSegmentParam)(a);if(!c)return a;let d=b.get(c.paramName);if(!d)return a;let e=null==Y?void 0:Y[d.paramName];if(!e)return a;let f=Array.isArray(e)?e.map(a=>encodeURIComponent(a)).join("/"):encodeURIComponent(e);return a.replace(function(a){let{repeat:b,optional:c}=(0,J.getParamProperties)(a.paramType);return c?`[[...${a.paramName}]]`:b?`[...${a.paramName}]`:`[${a.paramName}]`}(d),f)}).join("/")||"/");aS=c!==a?c:null}}else aS=ag}let aT=aS;!aT&&(N.isDev||aM&&Z&&(null==ar?void 0:ar.fallbackRouteParams)&&!ay)&&(aT=ag),N.isDev||af||!aM||!ax||aJ||(0,k.d)(a.headers);let aU={...E,tree:L,handler:O,routeModule:N,__next_app__:M};ab&&ac&&(0,o.setManifestsSingleton)({page:U,clientReferenceManifest:ac,serverActionsManifest:ab});let aV=a.method||"GET",aW=(0,g.getTracer)(),aX=aW.getActiveScopeSpan(),aY=!!(null==ai?void 0:ai.isWrappedByNextServer),aZ=!0===aj.experimental.partialFallbacks&&aQ.length>0?(null==ar||null==(R=ar.fallbackRouteParams)?void 0:R.filter(a=>!aQ.some(b=>b.paramName===a.paramName)))??[]:[],a$=async()=>((null==ai?void 0:ai.render404)?await ai.render404(a,b,ak,!1):b.end("This page could not be found"),null);try{let f,k=N.getVaryHeader(ag,al);b.setHeader("Vary",k);let m=async(c,d)=>{let e=new l.NodeNextRequest(a),g=new l.NodeNextResponse(b);return N.render(e,g,d).finally(()=>{if(!c)return;c.setAttributes({"http.status_code":b.statusCode,"next.rsc":!1});let a=aW.getRootSpanAttributes();if(!a)return;if(a.get("next.span_type")!==i.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${a.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let d=a.get("next.route");if(d){let a=`${aV} ${d}`;c.setAttributes({"next.route":d,"http.route":d,"next.span_name":a}),c.updateName(a),f&&f!==c&&(f.setAttribute("http.route",d),f.updateName(a))}else c.updateName(`${aV} ${U}`)})},o=(0,h.getRequestMeta)(a,"incrementalCache")||await N.getIncrementalCache(a,aj,ae,T);null==o||o.resetRequestCache(),globalThis.__incrementalCache=o;let p=async({span:e,postponed:f,fallbackRouteParams:g,forceStaticRender:i})=>{let k={query:X,params:Y,page:ao,sharedContext:{buildId:W,deploymentId:am,clientAssetToken:an},serverComponentsHmrCache:(0,h.getRequestMeta)(a,"serverComponentsHmrCache"),fallbackRouteParams:g,renderOpts:{App:()=>null,Document:()=>null,pageConfig:{},ComponentMod:aU,Component:(0,j.T)(aU),params:Y,routeModule:N,page:U,postponed:f,shouldWaitOnAllReady:aP,serveStreamingMetadata:aL,supportsDynamicResponse:"string"==typeof f||aO,buildManifest:$,nextFontManifest:_,reactLoadableManifest:aa,subresourceIntegrityManifest:ad,setCacheStatus:null==ai?void 0:ai.setCacheStatus,setIsrStatus:null==ai?void 0:ai.setIsrStatus,setReactDebugChannel:null==ai?void 0:ai.setReactDebugChannel,sendErrorsToBrowser:null==ai?void 0:ai.sendErrorsToBrowser,dir:c(33873).join(process.cwd(),N.relativeProjectDir),isDraftMode:af,botType:au,isOnDemandRevalidate:ap,isPossibleServerAction:ay,assetPrefix:aj.assetPrefix,nextConfigOutput:aj.output,crossOrigin:aj.crossOrigin,trailingSlash:aj.trailingSlash,images:aj.images,previewProps:ae.preview,enableTainting:aj.experimental.taint,htmlLimitedBots:aj.htmlLimitedBots,reactMaxHeadersLength:aj.reactMaxHeadersLength,multiZoneDraftMode:!1,incrementalCache:o,cacheLifeProfiles:aj.cacheLife,basePath:aj.basePath,serverActions:aj.experimental.serverActions,logServerFunctions:"object"==typeof aj.logging&&!!aj.logging.serverFunctions,...aE||aF||aG?{isBuildTimePrerendering:!0,supportsDynamicResponse:!1,isStaticGeneration:!0,isDebugDynamicAccesses:aF}:{},cacheComponents:!!aj.cacheComponents,experimental:{isRoutePPREnabled:aD,expireTime:aj.expireTime,staleTimes:aj.experimental.staleTimes,dynamicOnHover:!!aj.experimental.dynamicOnHover,optimisticRouting:!!aj.experimental.optimisticRouting,inlineCss:!!aj.experimental.inlineCss,prefetchInlining:aj.experimental.prefetchInlining??!1,authInterrupts:!!aj.experimental.authInterrupts,cachedNavigations:!!aj.experimental.cachedNavigations,clientTraceMetadata:aj.experimental.clientTraceMetadata||[],clientParamParsingOrigins:aj.experimental.clientParamParsingOrigins,maxPostponedStateSizeBytes:(0,C.parseMaxPostponedStateSize)(aj.experimental.maxPostponedStateSize)},waitUntil:d.waitUntil,onClose:a=>{b.on("close",a)},onAfterTaskError:()=>{},onInstrumentationRequestError:(b,c,d,e)=>N.onRequestError(a,b,d,e,ai),err:(0,h.getRequestMeta)(a,"invokeError")}};i&&(k.renderOpts.supportsDynamicResponse=!1);let l=await m(e,k),{metadata:n}=l,{cacheControl:p,headers:q={},fetchTags:r,fetchMetrics:s}=n;if(r&&(q[x.NEXT_CACHE_TAGS_HEADER]=r),a.fetchMetrics=s,aM&&(null==p?void 0:p.revalidate)===0&&!N.isDev&&!aD){let a=n.staticBailoutInfo,b=Object.defineProperty(Error(`Page changed from static to dynamic at runtime ${ag}${(null==a?void 0:a.description)?`, reason: ${a.description}`:""}
68
- see more here https://nextjs.org/docs/messages/app-static-to-dynamic-error`),"__NEXT_ERROR_CODE",{value:"E132",enumerable:!1,configurable:!0});if(null==a?void 0:a.stack){let c=a.stack;b.stack=b.message+c.substring(c.indexOf("\n"))}throw b}return{value:{kind:u.CachedRouteKind.APP_PAGE,html:l,headers:q,rscData:n.flightData,postponed:n.postponed,status:n.statusCode,segmentData:n.segmentData},cacheControl:p}},q=async({hasResolved:c,previousCacheEntry:f,isRevalidating:g,span:i,forceStaticRender:j=!1})=>{let k,l=!1===N.isDev,m=c||b.writableEnded;if(ap&&ah&&!f&&!T)return(null==ai?void 0:ai.render404)?await ai.render404(a,b):(b.statusCode=404,b.end("This page could not be found")),null;if(ar&&(k=(0,v.parseFallbackField)(ar.fallback)),!0===aj.experimental.partialFallbacks&&(null==ar?void 0:ar.fallback)===null&&!aR&&aQ.length>0&&(k=v.FallbackMode.PRERENDER),k===v.FallbackMode.PRERENDER&&(0,t.isBot)(at)&&(!aD||av)&&(k=v.FallbackMode.BLOCKING_STATIC_RENDER),(null==f?void 0:f.isStale)===-1&&(ap=!0),ap&&(k!==v.FallbackMode.NOT_FOUND||f)&&(k=v.FallbackMode.BLOCKING_STATIC_RENDER),!T&&k!==v.FallbackMode.BLOCKING_STATIC_RENDER&&aT&&!m&&!af&&Z&&(l||!as)){if((l||ar)&&k===v.FallbackMode.NOT_FOUND){if(aj.adapterPath)return await a$();throw new B.NoFallbackError}if(aD&&(aj.cacheComponents?!aJ:!ax)){let b=l&&"string"==typeof(null==ar?void 0:ar.fallback)?ar.fallback:ao,f=(l||aE)&&(null==ar?void 0:ar.fallbackRouteParams)?(0,n.createOpaqueFallbackRouteParams)(ar.fallbackRouteParams):aG?(0,n.getFallbackRouteParams)(ao,N):null;aE&&f&&(0,h.addRequestMeta)(a,"fallbackParams",f);let g=await N.handleResponse({cacheKey:b,req:a,nextConfig:aj,routeKind:e.RouteKind.APP_PAGE,isFallback:!0,prerenderManifest:ae,isRoutePPREnabled:aD,responseGenerator:async()=>p({span:i,postponed:void 0,fallbackRouteParams:f,forceStaticRender:!0}),waitUntil:d.waitUntil,isMinimalMode:T});if(null===g)return null;if(g)return T||!aD||!(aQ.length>0)||!0!==aj.experimental.partialFallbacks||!aS||!o||ap||aG||aB||aC||aw||(0,H.scheduleOnNextTick)(async()=>{let b=N.getResponseCache(a);try{await b.revalidate(aS,o,aD,!1,a=>p({span:a.span,postponed:void 0,fallbackRouteParams:aZ.length>0?(0,n.createOpaqueFallbackRouteParams)(aZ):null,forceStaticRender:!0}),null,c,d.waitUntil)}catch(a){console.error("Error revalidating the page in the background",a)}}),delete g.cacheControl,g}}let r=ap||g||!aH?void 0:aH;if(aN&&!T&&o&&(aJ||ay)&&!j){let b=await o.get(ag,{kind:u.IncrementalCacheKind.APP_PAGE,isRoutePPREnabled:!0,isFallback:!1});b&&b.value&&b.value.kind===u.CachedRouteKind.APP_PAGE&&(r=b.value.postponed,b&&(-1===b.isStale||!0===b.isStale)&&(0,H.scheduleOnNextTick)(async()=>{let b=N.getResponseCache(a);try{await b.revalidate(ag,o,aD,!1,a=>q({...a,forceStaticRender:!0}),null,c,d.waitUntil)}catch(a){console.error("Error revalidating the page in the background",a)}}))}if((aE||aF)&&void 0!==r)return{cacheControl:{revalidate:1,expire:void 0},value:{kind:u.CachedRouteKind.PAGES,html:w.default.EMPTY,pageData:{},headers:void 0,status:void 0}};let s=(l&&(0,h.getRequestMeta)(a,"renderFallbackShell")||aE&&!as)&&(null==ar?void 0:ar.fallbackRouteParams)?(0,n.createOpaqueFallbackRouteParams)(ar.fallbackRouteParams):aG?(0,n.getFallbackRouteParams)(ao,N):null;if((l||aE)&&aj.cacheComponents&&!as&&(null==ar?void 0:ar.fallbackRouteParams)){let b=(0,n.createOpaqueFallbackRouteParams)(ar.fallbackRouteParams);b&&(0,h.addRequestMeta)(a,"fallbackParams",b)}return p({span:i,postponed:r,fallbackRouteParams:s,forceStaticRender:j})},r=async c=>{var f,g,i,j,k;let l,m=await N.handleResponse({cacheKey:aS,responseGenerator:a=>q({span:c,...a}),routeKind:e.RouteKind.APP_PAGE,isOnDemandRevalidate:ap,isRoutePPREnabled:aD,req:a,nextConfig:aj,prerenderManifest:ae,waitUntil:d.waitUntil,isMinimalMode:T});if(af&&b.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate"),N.isDev&&b.setHeader("Cache-Control","no-cache, must-revalidate"),!m){if(aS)throw Object.defineProperty(Error("invariant: cache entry required but not generated"),"__NEXT_ERROR_CODE",{value:"E62",enumerable:!1,configurable:!0});return null}if((null==(f=m.value)?void 0:f.kind)!==u.CachedRouteKind.APP_PAGE)throw Object.defineProperty(Error(`Invariant app-page handler received invalid cache entry ${null==(i=m.value)?void 0:i.kind}`),"__NEXT_ERROR_CODE",{value:"E707",enumerable:!1,configurable:!0});let n="string"==typeof m.value.postponed;ax&&!ay&&am&&b.setHeader(x.NEXT_NAV_DEPLOYMENT_ID_HEADER,am),aM&&!aJ&&(!n||aw)&&(T||b.setHeader("x-nextjs-cache",ap?"REVALIDATED":m.isMiss?"MISS":m.isStale?"STALE":"HIT"),b.setHeader(s.NEXT_IS_PRERENDER_HEADER,"1"));let{value:o}=m;if(aH)l={revalidate:0,expire:void 0};else if(aJ)l={revalidate:0,expire:void 0};else if(!N.isDev)if(af)l={revalidate:0,expire:void 0};else if(aM){if(m.cacheControl)if("number"==typeof m.cacheControl.revalidate){if(m.cacheControl.revalidate<1)throw Object.defineProperty(Error(`Invalid revalidate configuration provided: ${m.cacheControl.revalidate} < 1`),"__NEXT_ERROR_CODE",{value:"E22",enumerable:!1,configurable:!0});l={revalidate:m.cacheControl.revalidate,expire:(null==(j=m.cacheControl)?void 0:j.expire)??aj.expireTime}}else l={revalidate:x.CACHE_ONE_YEAR_SECONDS,expire:void 0}}else b.getHeader("Cache-Control")||(l={revalidate:0,expire:void 0});if(m.cacheControl=l,"string"==typeof aK&&(null==o?void 0:o.kind)===u.CachedRouteKind.APP_PAGE&&o.segmentData){b.setHeader(s.NEXT_DID_POSTPONE_HEADER,"2");let c=null==(k=o.headers)?void 0:k[x.NEXT_CACHE_TAGS_HEADER];T&&aM&&c&&"string"==typeof c&&b.setHeader(x.NEXT_CACHE_TAGS_HEADER,c);let d=o.segmentData.get(aK);return void 0!==d?(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:w.default.fromStatic(d,s.RSC_CONTENT_TYPE_HEADER),cacheControl:m.cacheControl}):(b.statusCode=204,(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:w.default.EMPTY,cacheControl:m.cacheControl}))}let r=aN?(0,h.getRequestMeta)(a,"onCacheEntryV2")??(0,h.getRequestMeta)(a,"onCacheEntry"):(0,h.getRequestMeta)(a,"onCacheEntry");if(r&&await r(m,{url:(0,h.getRequestMeta)(a,"initURL")??a.url}))return null;if(o.headers){let a={...o.headers};for(let[c,d]of(T&&aM||delete a[x.NEXT_CACHE_TAGS_HEADER],Object.entries(a)))if(void 0!==d)if(Array.isArray(d))for(let a of d)b.appendHeader(c,a);else"number"==typeof d&&(d=d.toString()),b.appendHeader(c,d)}let t=null==(g=o.headers)?void 0:g[x.NEXT_CACHE_TAGS_HEADER];if(T&&aM&&t&&"string"==typeof t&&b.setHeader(x.NEXT_CACHE_TAGS_HEADER,t),!o.status||ax&&aD||(b.statusCode=o.status),!T&&o.status&&F.RedirectStatusCode[o.status]&&ax&&(b.statusCode=200),n&&!aJ&&b.setHeader(s.NEXT_DID_POSTPONE_HEADER,"1"),ax&&!af){if(void 0===o.rscData){if(o.html.contentType!==s.RSC_CONTENT_TYPE_HEADER)if(aj.cacheComponents)return b.statusCode=404,(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:w.default.EMPTY,cacheControl:m.cacheControl});else throw Object.defineProperty(new G.InvariantError(`Expected RSC response, got ${o.html.contentType}`),"__NEXT_ERROR_CODE",{value:"E789",enumerable:!1,configurable:!0});return(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:o.html,cacheControl:m.cacheControl})}return(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:w.default.fromStatic(o.rscData,s.RSC_CONTENT_TYPE_HEADER),cacheControl:m.cacheControl})}let v=o.html;if(aC&&aE){let c=!0===N.isDev?crypto.randomUUID():null;return v.pipeThrough((0,z.createInstantTestScriptInsertionTransformStream)(c)),(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:v,cacheControl:{revalidate:0,expire:void 0}})}if(!n||T||ax)return(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:v,cacheControl:m.cacheControl});if(aE||aF)return v.push(new ReadableStream({start(a){a.enqueue(y.ENCODED_TAGS.CLOSED.BODY_AND_HTML),a.close()}})),(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:v,cacheControl:{revalidate:0,expire:void 0}});let B=new TransformStream;return v.push(B.readable),p({span:c,postponed:o.postponed,fallbackRouteParams:null,forceStaticRender:!1}).then(async a=>{var b,c;if(!a)throw Object.defineProperty(Error("Invariant: expected a result to be returned"),"__NEXT_ERROR_CODE",{value:"E463",enumerable:!1,configurable:!0});if((null==(b=a.value)?void 0:b.kind)!==u.CachedRouteKind.APP_PAGE)throw Object.defineProperty(Error(`Invariant: expected a page response, got ${null==(c=a.value)?void 0:c.kind}`),"__NEXT_ERROR_CODE",{value:"E305",enumerable:!1,configurable:!0});await a.value.html.pipeTo(B.writable)}).catch(a=>{B.writable.abort(a).catch(a=>{console.error("couldn't abort transformer",a)})}),(0,A.sendRenderResult)({req:a,res:b,generateEtags:aj.generateEtags,poweredByHeader:aj.poweredByHeader,result:v,cacheControl:{revalidate:0,expire:void 0}})};if(!aY||!aX)return f=aW.getActiveScopeSpan(),await aW.withPropagatedContext(a.headers,()=>aW.trace(i.BaseServerSpan.handleRequest,{spanName:`${aV} ${U}`,kind:g.SpanKind.SERVER,attributes:{"http.method":aV,"http.target":a.url}},r),void 0,!aY);await r(aX)}catch(b){throw b instanceof B.NoFallbackError||await N.onRequestError(a,b,{routerKind:"App Router",routePath:U,routeType:"render",revalidateReason:(0,f.c)({isStaticGeneration:aM,isOnDemandRevalidate:ap})},!1,ai),b}}},92858:(a,b,c)=>{"use strict";let d=c(59725),e=[function(){},function(a,b,c,d){if(d===b.length)throw Error("Ran out of data");let e=b[d];a[c]=e,a[c+1]=e,a[c+2]=e,a[c+3]=255},function(a,b,c,d){if(d+1>=b.length)throw Error("Ran out of data");let e=b[d];a[c]=e,a[c+1]=e,a[c+2]=e,a[c+3]=b[d+1]},function(a,b,c,d){if(d+2>=b.length)throw Error("Ran out of data");a[c]=b[d],a[c+1]=b[d+1],a[c+2]=b[d+2],a[c+3]=255},function(a,b,c,d){if(d+3>=b.length)throw Error("Ran out of data");a[c]=b[d],a[c+1]=b[d+1],a[c+2]=b[d+2],a[c+3]=b[d+3]}],f=[function(){},function(a,b,c,d){let e=b[0];a[c]=e,a[c+1]=e,a[c+2]=e,a[c+3]=d},function(a,b,c){let d=b[0];a[c]=d,a[c+1]=d,a[c+2]=d,a[c+3]=b[1]},function(a,b,c,d){a[c]=b[0],a[c+1]=b[1],a[c+2]=b[2],a[c+3]=d},function(a,b,c){a[c]=b[0],a[c+1]=b[1],a[c+2]=b[2],a[c+3]=b[3]}];b.dataToBitMap=function(a,b){let c,g,h,i,j,k,l=b.width,m=b.height,n=b.depth,o=b.bpp,p=b.interlace;8!==n&&(c=[],g=0,h={get:function(b){for(;c.length<b;)!function(){let b,d,e,f;if(g===a.length)throw Error("Ran out of data");let h=a[g];switch(g++,n){default:throw Error("unrecognised depth");case 16:e=a[g],g++,c.push((h<<8)+e);break;case 4:e=15&h,f=h>>4,c.push(f,e);break;case 2:b=3&h,d=h>>2&3,e=h>>4&3,f=h>>6&3,c.push(f,e,d,b);break;case 1:b=h>>4&1,d=h>>5&1,e=h>>6&1,f=h>>7&1,c.push(f,e,d,b,h>>3&1,h>>2&1,h>>1&1,1&h)}}();let d=c.slice(0,b);return c=c.slice(b),d},resetAfterLine:function(){c.length=0},end:function(){if(g!==a.length)throw Error("extra data found")}}),i=n<=8?Buffer.alloc(l*m*4):new Uint16Array(l*m*4);let q=Math.pow(2,n)-1,r=0;if(p)j=d.getImagePasses(l,m),k=d.getInterlaceIterator(l,m);else{let a=0;k=function(){let b=a;return a+=4,b},j=[{width:l,height:m}]}for(let b=0;b<j.length;b++)8===n?r=function(a,b,c,d,f,g){let h=a.width,i=a.height,j=a.index;for(let a=0;a<i;a++)for(let i=0;i<h;i++){let h=c(i,a,j);e[d](b,f,h,g),g+=d}return g}(j[b],i,k,o,a,r):function(a,b,c,d,e,g){let h=a.width,i=a.height,j=a.index;for(let a=0;a<i;a++){for(let i=0;i<h;i++){let h=e.get(d),k=c(i,a,j);f[d](b,h,k,g)}e.resetAfterLine()}}(j[b],i,k,o,h,q);if(8===n){if(r!==a.length)throw Error("extra data found")}else h.end();return i}},93669:(a,b,c)=>{let d=c(83929),e=c(64323);b.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},b.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},b.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},b.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},b.MIXED={bit:-1},b.getCharCountIndicator=function(a,b){if(!a.ccBits)throw Error("Invalid mode: "+a);if(!d.isValid(b))throw Error("Invalid version: "+b);return b>=1&&b<10?a.ccBits[0]:b<27?a.ccBits[1]:a.ccBits[2]},b.getBestModeForData=function(a){return e.testNumeric(a)?b.NUMERIC:e.testAlphanumeric(a)?b.ALPHANUMERIC:e.testKanji(a)?b.KANJI:b.BYTE},b.toString=function(a){if(a&&a.id)return a.id;throw Error("Invalid mode")},b.isValid=function(a){return a&&a.bit&&a.ccBits},b.from=function(a,c){if(b.isValid(a))return a;try{if("string"!=typeof a)throw Error("Param is not a string");switch(a.toLowerCase()){case"numeric":return b.NUMERIC;case"alphanumeric":return b.ALPHANUMERIC;case"kanji":return b.KANJI;case"byte":return b.BYTE;default:throw Error("Unknown mode: "+a)}}catch(a){return c}}},94165:(a,b,c)=>{"use strict";let d=c(67269);a.exports=function(a,b,c,e){let f=-1!==[d.COLORTYPE_COLOR_ALPHA,d.COLORTYPE_ALPHA].indexOf(e.colorType);if(e.colorType===e.inputColorType){let b,c=(new DataView(b=new ArrayBuffer(2)).setInt16(0,256,!0),256!==new Int16Array(b)[0]);if(8===e.bitDepth||16===e.bitDepth&&c)return a}let g=16!==e.bitDepth?a:new Uint16Array(a.buffer),h=255,i=d.COLORTYPE_TO_BPP_MAP[e.inputColorType];4!==i||e.inputHasAlpha||(i=3);let j=d.COLORTYPE_TO_BPP_MAP[e.colorType];16===e.bitDepth&&(h=65535,j*=2);let k=Buffer.alloc(b*c*j),l=0,m=0,n=e.bgColor||{};void 0===n.red&&(n.red=h),void 0===n.green&&(n.green=h),void 0===n.blue&&(n.blue=h);for(let a=0;a<c;a++)for(let a=0;a<b;a++){let a=function(){let a,b,c,i=h;switch(e.inputColorType){case d.COLORTYPE_COLOR_ALPHA:i=g[l+3],a=g[l],b=g[l+1],c=g[l+2];break;case d.COLORTYPE_COLOR:a=g[l],b=g[l+1],c=g[l+2];break;case d.COLORTYPE_ALPHA:i=g[l+1],b=a=g[l],c=a;break;case d.COLORTYPE_GRAYSCALE:b=a=g[l],c=a;break;default:throw Error("input color type:"+e.inputColorType+" is not supported at present")}return e.inputHasAlpha&&!f&&(i/=h,a=Math.min(Math.max(Math.round((1-i)*n.red+i*a),0),h),b=Math.min(Math.max(Math.round((1-i)*n.green+i*b),0),h),c=Math.min(Math.max(Math.round((1-i)*n.blue+i*c),0),h)),{red:a,green:b,blue:c,alpha:i}}();switch(e.colorType){case d.COLORTYPE_COLOR_ALPHA:case d.COLORTYPE_COLOR:8===e.bitDepth?(k[m]=a.red,k[m+1]=a.green,k[m+2]=a.blue,f&&(k[m+3]=a.alpha)):(k.writeUInt16BE(a.red,m),k.writeUInt16BE(a.green,m+2),k.writeUInt16BE(a.blue,m+4),f&&k.writeUInt16BE(a.alpha,m+6));break;case d.COLORTYPE_ALPHA:case d.COLORTYPE_GRAYSCALE:{let b=(a.red+a.green+a.blue)/3;8===e.bitDepth?(k[m]=b,f&&(k[m+1]=a.alpha)):(k.writeUInt16BE(b,m),f&&k.writeUInt16BE(a.alpha,m+2));break}default:throw Error("unrecognised color Type "+e.colorType)}l+=i,m+=j}return k}},94735:a=>{"use strict";a.exports=require("events")},95380:(a,b,c)=>{let d=c(58305),e=c(58856),f=c(52002),g=c(46349),h=c(88066),i=c(39477),j=c(12097),k=c(19477),l=c(98129),m=c(52324),n=c(55258),o=c(93669),p=c(39588);function q(a,b,c){let d,e,f=a.size,g=n.getEncodedBits(b,c);for(d=0;d<15;d++)e=(g>>d&1)==1,d<6?a.set(d,8,e,!0):d<8?a.set(d+1,8,e,!0):a.set(f-15+d,8,e,!0),d<8?a.set(8,f-d-1,e,!0):d<9?a.set(8,15-d-1+1,e,!0):a.set(8,15-d-1,e,!0);a.set(f-8,8,1,!0)}b.create=function(a,b){let c,n;if(void 0===a||""===a)throw Error("No input text");let r=e.M;return void 0!==b&&(r=e.from(b.errorCorrectionLevel,e.M),c=m.from(b.version),n=j.from(b.maskPattern),b.toSJISFunc&&d.setToSJISFunction(b.toSJISFunc)),function(a,b,c,e){let n;if(Array.isArray(a))n=p.fromArray(a);else if("string"==typeof a){let d=b;if(!d){let b=p.rawSplit(a);d=m.getBestVersionForData(b,c)}n=p.fromString(a,d||40)}else throw Error("Invalid data");let r=m.getBestVersionForData(n,c);if(!r)throw Error("The amount of data is too big to be stored in a QR Code");if(b){if(b<r)throw Error("\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: "+r+".\n")}else b=r;let s=function(a,b,c){let e=new f;c.forEach(function(b){e.put(b.mode.bit,4),e.put(b.getLength(),o.getCharCountIndicator(b.mode,a)),b.write(e)});let g=(d.getSymbolTotalCodewords(a)-k.getTotalCodewordsCount(a,b))*8;for(e.getLengthInBits()+4<=g&&e.put(0,4);e.getLengthInBits()%8!=0;)e.putBit(0);let h=(g-e.getLengthInBits())/8;for(let a=0;a<h;a++)e.put(a%2?17:236,8);return function(a,b,c){let e,f,g=d.getSymbolTotalCodewords(b),h=g-k.getTotalCodewordsCount(b,c),i=k.getBlocksCount(b,c),j=g%i,m=i-j,n=Math.floor(g/i),o=Math.floor(h/i),p=o+1,q=n-o,r=new l(q),s=0,t=Array(i),u=Array(i),v=0,w=new Uint8Array(a.buffer);for(let a=0;a<i;a++){let b=a<m?o:p;t[a]=w.slice(s,s+b),u[a]=r.encode(t[a]),s+=b,v=Math.max(v,b)}let x=new Uint8Array(g),y=0;for(e=0;e<v;e++)for(f=0;f<i;f++)e<t[f].length&&(x[y++]=t[f][e]);for(e=0;e<q;e++)for(f=0;f<i;f++)x[y++]=u[f][e];return x}(e,a,b)}(b,c,n),t=new g(d.getSymbolSize(b));!function(a,b){let c=a.size,d=i.getPositions(b);for(let b=0;b<d.length;b++){let e=d[b][0],f=d[b][1];for(let b=-1;b<=7;b++)if(!(e+b<=-1)&&!(c<=e+b))for(let d=-1;d<=7;d++)f+d<=-1||c<=f+d||(b>=0&&b<=6&&(0===d||6===d)||d>=0&&d<=6&&(0===b||6===b)||b>=2&&b<=4&&d>=2&&d<=4?a.set(e+b,f+d,!0,!0):a.set(e+b,f+d,!1,!0))}}(t,b);let u=t.size;for(let a=8;a<u-8;a++){let b=a%2==0;t.set(a,6,b,!0),t.set(6,a,b,!0)}return!function(a,b){let c=h.getPositions(b);for(let b=0;b<c.length;b++){let d=c[b][0],e=c[b][1];for(let b=-2;b<=2;b++)for(let c=-2;c<=2;c++)-2===b||2===b||-2===c||2===c||0===b&&0===c?a.set(d+b,e+c,!0,!0):a.set(d+b,e+c,!1,!0)}}(t,b),q(t,c,0),b>=7&&function(a,b){let c,d,e,f=a.size,g=m.getEncodedBits(b);for(let b=0;b<18;b++)c=Math.floor(b/3),d=b%3+f-8-3,e=(g>>b&1)==1,a.set(c,d,e,!0),a.set(d,c,e,!0)}(t,b),!function(a,b){let c=a.size,d=-1,e=c-1,f=7,g=0;for(let h=c-1;h>0;h-=2)for(6===h&&h--;;){for(let c=0;c<2;c++)if(!a.isReserved(e,h-c)){let d=!1;g<b.length&&(d=(b[g]>>>f&1)==1),a.set(e,h-c,d),-1==--f&&(g++,f=7)}if((e+=d)<0||c<=e){e-=d,d=-d;break}}}(t,s),isNaN(e)&&(e=j.getBestMask(t,q.bind(null,t,c))),j.applyMask(e,t),q(t,c,e),{modules:t,version:b,errorCorrectionLevel:c,maskPattern:e,segments:n}}(a,c,r,n)}},96277:(a,b,c)=>{"use strict";let d=c(67269),e=c(43894),f=a.exports=function(a,b){this._options=a,a.checkCRC=!1!==a.checkCRC,this._hasIHDR=!1,this._hasIEND=!1,this._emittedHeadersFinished=!1,this._palette=[],this._colorType=0,this._chunks={},this._chunks[d.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[d.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[d.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[d.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[d.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[d.TYPE_gAMA]=this._handleGAMA.bind(this),this.read=b.read,this.error=b.error,this.metadata=b.metadata,this.gamma=b.gamma,this.transColor=b.transColor,this.palette=b.palette,this.parsed=b.parsed,this.inflateData=b.inflateData,this.finished=b.finished,this.simpleTransparency=b.simpleTransparency,this.headersFinished=b.headersFinished||function(){}};f.prototype.start=function(){this.read(d.PNG_SIGNATURE.length,this._parseSignature.bind(this))},f.prototype._parseSignature=function(a){let b=d.PNG_SIGNATURE;for(let c=0;c<b.length;c++)if(a[c]!==b[c])return void this.error(Error("Invalid file signature"));this.read(8,this._parseChunkBegin.bind(this))},f.prototype._parseChunkBegin=function(a){let b=a.readUInt32BE(0),c=a.readUInt32BE(4),f="";for(let b=4;b<8;b++)f+=String.fromCharCode(a[b]);let g=!!(32&a[4]);return this._hasIHDR||c===d.TYPE_IHDR?(this._crc=new e,this._crc.write(Buffer.from(f)),this._chunks[c])?this._chunks[c](b):g?void this.read(b+4,this._skipChunk.bind(this)):void this.error(Error("Unsupported critical chunk type "+f)):void this.error(Error("Expected IHDR on beggining"))},f.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this))},f.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this))},f.prototype._parseChunkEnd=function(a){let b=a.readInt32BE(0),c=this._crc.crc32();this._options.checkCRC&&c!==b?this.error(Error("Crc error - "+b+" - "+c)):this._hasIEND||this.read(8,this._parseChunkBegin.bind(this))},f.prototype._handleIHDR=function(a){this.read(a,this._parseIHDR.bind(this))},f.prototype._parseIHDR=function(a){this._crc.write(a);let b=a.readUInt32BE(0),c=a.readUInt32BE(4),e=a[8],f=a[9],g=a[10],h=a[11],i=a[12];if(8!==e&&4!==e&&2!==e&&1!==e&&16!==e)return void this.error(Error("Unsupported bit depth "+e));if(!(f in d.COLORTYPE_TO_BPP_MAP))return void this.error(Error("Unsupported color type"));if(0!==g)return void this.error(Error("Unsupported compression method"));if(0!==h)return void this.error(Error("Unsupported filter method"));if(0!==i&&1!==i)return void this.error(Error("Unsupported interlace method"));this._colorType=f;let j=d.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=!0,this.metadata({width:b,height:c,depth:e,interlace:!!i,palette:!!(f&d.COLORTYPE_PALETTE),color:!!(f&d.COLORTYPE_COLOR),alpha:!!(f&d.COLORTYPE_ALPHA),bpp:j,colorType:f}),this._handleChunkEnd()},f.prototype._handlePLTE=function(a){this.read(a,this._parsePLTE.bind(this))},f.prototype._parsePLTE=function(a){this._crc.write(a);let b=Math.floor(a.length/3);for(let c=0;c<b;c++)this._palette.push([a[3*c],a[3*c+1],a[3*c+2],255]);this.palette(this._palette),this._handleChunkEnd()},f.prototype._handleTRNS=function(a){this.simpleTransparency(),this.read(a,this._parseTRNS.bind(this))},f.prototype._parseTRNS=function(a){if(this._crc.write(a),this._colorType===d.COLORTYPE_PALETTE_COLOR){if(0===this._palette.length)return void this.error(Error("Transparency chunk must be after palette"));if(a.length>this._palette.length)return void this.error(Error("More transparent colors than palette size"));for(let b=0;b<a.length;b++)this._palette[b][3]=a[b];this.palette(this._palette)}this._colorType===d.COLORTYPE_GRAYSCALE&&this.transColor([a.readUInt16BE(0)]),this._colorType===d.COLORTYPE_COLOR&&this.transColor([a.readUInt16BE(0),a.readUInt16BE(2),a.readUInt16BE(4)]),this._handleChunkEnd()},f.prototype._handleGAMA=function(a){this.read(a,this._parseGAMA.bind(this))},f.prototype._parseGAMA=function(a){this._crc.write(a),this.gamma(a.readUInt32BE(0)/d.GAMMA_DIVISION),this._handleChunkEnd()},f.prototype._handleIDAT=function(a){this._emittedHeadersFinished||(this._emittedHeadersFinished=!0,this.headersFinished()),this.read(-a,this._parseIDAT.bind(this,a))},f.prototype._parseIDAT=function(a,b){if(this._crc.write(b),this._colorType===d.COLORTYPE_PALETTE_COLOR&&0===this._palette.length)throw Error("Expected palette not found");this.inflateData(b);let c=a-b.length;c>0?this._handleIDAT(c):this._handleChunkEnd()},f.prototype._handleIEND=function(a){this.read(a,this._parseIEND.bind(this))},f.prototype._parseIEND=function(a){this._crc.write(a),this._hasIEND=!0,this._handleChunkEnd(),this.finished&&this.finished()}},98052:(a,b,c)=>{"use strict";let d=c(67269),e=c(43894),f=c(94165),g=c(31964),h=c(74075),i=a.exports=function(a){if(this._options=a,a.deflateChunkSize=a.deflateChunkSize||32768,a.deflateLevel=null!=a.deflateLevel?a.deflateLevel:9,a.deflateStrategy=null!=a.deflateStrategy?a.deflateStrategy:3,a.inputHasAlpha=null==a.inputHasAlpha||a.inputHasAlpha,a.deflateFactory=a.deflateFactory||h.createDeflate,a.bitDepth=a.bitDepth||8,a.colorType="number"==typeof a.colorType?a.colorType:d.COLORTYPE_COLOR_ALPHA,a.inputColorType="number"==typeof a.inputColorType?a.inputColorType:d.COLORTYPE_COLOR_ALPHA,-1===[d.COLORTYPE_GRAYSCALE,d.COLORTYPE_COLOR,d.COLORTYPE_COLOR_ALPHA,d.COLORTYPE_ALPHA].indexOf(a.colorType))throw Error("option color type:"+a.colorType+" is not supported at present");if(-1===[d.COLORTYPE_GRAYSCALE,d.COLORTYPE_COLOR,d.COLORTYPE_COLOR_ALPHA,d.COLORTYPE_ALPHA].indexOf(a.inputColorType))throw Error("option input color type:"+a.inputColorType+" is not supported at present");if(8!==a.bitDepth&&16!==a.bitDepth)throw Error("option bit depth:"+a.bitDepth+" is not supported at present")};i.prototype.getDeflateOptions=function(){return{chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}},i.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())},i.prototype.filterData=function(a,b,c){let e=f(a,b,c,this._options),h=d.COLORTYPE_TO_BPP_MAP[this._options.colorType];return g(e,b,c,this._options,h)},i.prototype._packChunk=function(a,b){let c=b?b.length:0,d=Buffer.alloc(c+12);return d.writeUInt32BE(c,0),d.writeUInt32BE(a,4),b&&b.copy(d,8),d.writeInt32BE(e.crc32(d.slice(4,d.length-4)),d.length-4),d},i.prototype.packGAMA=function(a){let b=Buffer.alloc(4);return b.writeUInt32BE(Math.floor(a*d.GAMMA_DIVISION),0),this._packChunk(d.TYPE_gAMA,b)},i.prototype.packIHDR=function(a,b){let c=Buffer.alloc(13);return c.writeUInt32BE(a,0),c.writeUInt32BE(b,4),c[8]=this._options.bitDepth,c[9]=this._options.colorType,c[10]=0,c[11]=0,c[12]=0,this._packChunk(d.TYPE_IHDR,c)},i.prototype.packIDAT=function(a){return this._packChunk(d.TYPE_IDAT,a)},i.prototype.packIEND=function(){return this._packChunk(d.TYPE_IEND,null)}},98129:(a,b,c)=>{let d=c(43144);function e(a){this.genPoly=void 0,this.degree=a,this.degree&&this.initialize(this.degree)}e.prototype.initialize=function(a){this.degree=a,this.genPoly=d.generateECPolynomial(this.degree)},e.prototype.encode=function(a){if(!this.genPoly)throw Error("Encoder not initialized");let b=new Uint8Array(a.length+this.degree);b.set(a);let c=d.mod(b,this.genPoly),e=this.degree-c.length;if(e>0){let a=new Uint8Array(this.degree);return a.set(c,e),a}return c},a.exports=e},99647:(a,b,c)=>{"use strict";c.r(b),c.d(b,{default:()=>g});var d=c(5735),e=c(91986),f=c(35790);function g(){return(0,d.jsx)(e.Suspense,{children:(0,d.jsx)(f.AppShell,{})})}}};var b=require("../webpack-runtime.js");b.C(a);var c=b.X(0,[4741,63,8304,9962,1494],()=>b(b.s=91926));module.exports=c})();
47
+ `)},onAskAboutArtifact:a=>{G?.current?.insertText(di(a))},onEditArtifact:a=>{G?.current?.insertText(dj(a))},onOpenArtifact:a=>{let b=a.split(/[\\/]/).pop()||a;a_(a,b)}}):bg?.filePath?bg.filePath.startsWith("__")?(0,d.jsx)(bh,{filePath:bg.filePath}):(0,d.jsx)(ar,{filePath:bg.filePath,children:(0,d.jsx)(ap.h,{filePath:bg.filePath,cwd:aK??void 0,onOpenFile:a_,scrollToLine:aZ,workbenchSessionId:i?.sessionKind==="workbench"?i.id:null,onAskAboutArtifact:a=>G?.current?.insertText(di(a)),onEditArtifact:a=>G?.current?.insertText(dj(a))})}):(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:"No file open"})})]})]}),(0,d.jsx)(df,{open:ah,anchorRef:I,status:bq,error:bs,currentSessionId:bm,currentCwd:aY,idleTimeoutLabel:dm(z.plotIdleTimeoutMs),busyPid:"number"==typeof bv?bv:null,onClose:()=>ai(!1),onRefresh:()=>{bz()},onReleaseKernels:a=>{bC(a)},onOpenSettings:bF,onOpenStatus:bE}),v&&(0,d.jsx)(c5,{cwd:aY,generativeUI:z.generativeUI,initialTab:x,onGenerativeUIToggle:$,onModelsChanged:()=>t(a=>a+1),onProjectSelect:aQ,onProjectsChanged:()=>n(a=>a+1),onClose:()=>{w(!1),t(a=>a+1)}}),af&&(0,d.jsx)(c9,{cwd:bo,runtime:{totalBytes:bx,currentSessionBytes:by,idleTimeoutLabel:dm(z.plotIdleTimeoutMs)},runtimeError:bs,busy:al,onClose:a3,onLaunch:a=>bG(a),onReleaseCurrentRuntime:i?.id&&i.cwd===bo?()=>{bB()}:void 0,onOpenSettings:bF}),(0,d.jsx)(bn,{appType:aC?.appType??"stexp",filePath:aC?.filePath??null,cwd:aC?.cwd??null,appId:aC?.appId??null,sessionId:i?.id??null,onClose:()=>aD(null),onAppChanged:a6,onOpenTools:a4}),aG.map((a,b)=>(0,d.jsx)(at,{id:a.id,filePath:a.filePath,fileName:a.fileName,cwd:aK??i?.cwd??k??void 0,active:b===aG.length-1,stackIndex:b,zIndex:700+b,onClose:a7,onFocus:a8,onOpenFile:a_},a.id))]})}},57949:(a,b,c)=>{"use strict";let d=c(28354),e=c(27910),f=a.exports=function(){e.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=!1,this._encoding="utf8",this.writable=!0};d.inherits(f,e),f.prototype.read=function(a,b){this._reads.push({length:Math.abs(a),allowLess:a<0,func:b}),process.nextTick((function(){this._process(),this._paused&&this._reads&&this._reads.length>0&&(this._paused=!1,this.emit("drain"))}).bind(this))},f.prototype.write=function(a,b){let c;return this.writable?(c=Buffer.isBuffer(a)?a:Buffer.from(a,b||this._encoding),this._buffers.push(c),this._buffered+=c.length,this._process(),this._reads&&0===this._reads.length&&(this._paused=!0),this.writable&&!this._paused):(this.emit("error",Error("Stream not writable")),!1)},f.prototype.end=function(a,b){a&&this.write(a,b),this.writable=!1,this._buffers&&(0===this._buffers.length?this._end():(this._buffers.push(null),this._process()))},f.prototype.destroySoon=f.prototype.end,f.prototype._end=function(){this._reads.length>0&&this.emit("error",Error("Unexpected end of input")),this.destroy()},f.prototype.destroy=function(){this._buffers&&(this.writable=!1,this._reads=null,this._buffers=null,this.emit("close"))},f.prototype._processReadAllowingLess=function(a){this._reads.shift();let b=this._buffers[0];b.length>a.length?(this._buffered-=a.length,this._buffers[0]=b.slice(a.length),a.func.call(this,b.slice(0,a.length))):(this._buffered-=b.length,this._buffers.shift(),a.func.call(this,b))},f.prototype._processRead=function(a){this._reads.shift();let b=0,c=0,d=Buffer.alloc(a.length);for(;b<a.length;){let e=this._buffers[c++],f=Math.min(e.length,a.length-b);e.copy(d,b,0,f),b+=f,f!==e.length&&(this._buffers[--c]=e.slice(f))}c>0&&this._buffers.splice(0,c),this._buffered-=a.length,a.func.call(this,d)},f.prototype._process=function(){try{for(;this._buffered>0&&this._reads&&this._reads.length>0;){let a=this._reads[0];if(a.allowLess)this._processReadAllowingLess(a);else if(this._buffered>=a.length)this._processRead(a);else break}this._buffers&&!this.writable&&this._end()}catch(a){this.emit("error",a)}}},58305:(a,b)=>{let c,d=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];b.getSymbolSize=function(a){if(!a)throw Error('"version" cannot be null or undefined');if(a<1||a>40)throw Error('"version" should be in range from 1 to 40');return 4*a+17},b.getSymbolTotalCodewords=function(a){return d[a]},b.getBCHDigit=function(a){let b=0;for(;0!==a;)b++,a>>>=1;return b},b.setToSJISFunction=function(a){if("function"!=typeof a)throw Error('"toSJISFunc" is not a valid function.');c=a},b.isKanjiModeEnabled=function(){return void 0!==c},b.toSJIS=function(a){return c(a)}},58856:(a,b)=>{b.L={bit:1},b.M={bit:0},b.Q={bit:3},b.H={bit:2},b.isValid=function(a){return a&&void 0!==a.bit&&a.bit>=0&&a.bit<4},b.from=function(a,c){if(b.isValid(a))return a;try{if("string"!=typeof a)throw Error("Param is not a string");switch(a.toLowerCase()){case"l":case"low":return b.L;case"m":case"medium":return b.M;case"q":case"quartile":return b.Q;case"h":case"high":return b.H;default:throw Error("Unknown EC Level: "+a)}}catch(a){return c}}},58879:(a,b,c)=>{"use strict";let d=c(9709),e=c(80706);b.read=function(a,b){return d(a,b||{})},b.write=function(a,b){return e(a,b)}},59725:(a,b)=>{"use strict";let c=[{x:[0],y:[0]},{x:[4],y:[0]},{x:[0,4],y:[4]},{x:[2,6],y:[0,4]},{x:[0,2,4,6],y:[2,6]},{x:[1,3,5,7],y:[0,2,4,6]},{x:[0,1,2,3,4,5,6,7],y:[1,3,5,7]}];b.getImagePasses=function(a,b){let d=[],e=a%8,f=b%8,g=(a-e)/8,h=(b-f)/8;for(let a=0;a<c.length;a++){let b=c[a],i=g*b.x.length,j=h*b.y.length;for(let a=0;a<b.x.length;a++)if(b.x[a]<e)i++;else break;for(let a=0;a<b.y.length;a++)if(b.y[a]<f)j++;else break;i>0&&j>0&&d.push({width:i,height:j,index:a})}return d},b.getInterlaceIterator=function(a){return function(b,d,e){let f=b%c[e].x.length,g=(b-f)/c[e].x.length*8+c[e].x[f],h=d%c[e].y.length;return 4*g+((d-h)/c[e].y.length*8+c[e].y[h])*a*4}}},61345:(a,b)=>{b.render=function(a,b,c){let d=a.modules.size,e=a.modules.data,f="\x1b[47m \x1b[0m",g="",h=Array(d+3).join(f),i=[,,].join(f);g+=h+"\n";for(let a=0;a<d;++a){g+=f;for(let b=0;b<d;b++)g+=e[a*d+b]?"\x1b[40m \x1b[0m":f;g+=i+"\n"}return g+=h+"\n","function"==typeof c&&c(null,g),g}},63033:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},64323:(a,b)=>{let c="[0-9]+",d="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+",e="(?:(?![A-Z0-9 $%*+\\-./:]|"+(d=d.replace(/u/g,"\\u"))+")(?:.|[\r\n]))+";b.KANJI=RegExp(d,"g"),b.BYTE_KANJI=RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),b.BYTE=RegExp(e,"g"),b.NUMERIC=RegExp(c,"g"),b.ALPHANUMERIC=RegExp("[A-Z $%*+\\-./:]+","g");let f=RegExp("^"+d+"$"),g=RegExp("^"+c+"$"),h=RegExp("^[A-Z0-9 $%*+\\-./:]+$");b.testKanji=function(a){return f.test(a)},b.testNumeric=function(a){return g.test(a)},b.testAlphanumeric=function(a){return h.test(a)}},64424:(a,b,c)=>{let d=c(93669),e=c(58305);function f(a){this.mode=d.KANJI,this.data=a}f.getBitsLength=function(a){return 13*a},f.prototype.getLength=function(){return this.data.length},f.prototype.getBitsLength=function(){return f.getBitsLength(this.data.length)},f.prototype.write=function(a){let b;for(b=0;b<this.data.length;b++){let c=e.toSJIS(this.data[b]);if(c>=33088&&c<=40956)c-=33088;else if(c>=57408&&c<=60351)c-=49472;else throw Error("Invalid SJIS character: "+this.data[b]+"\nMake sure your charset is UTF-8");c=(c>>>8&255)*192+(255&c),a.put(c,13)}},a.exports=f},66530:(a,b,c)=>{let d=c(61345),e=c(86491);b.render=function(a,b,c){return b&&b.small?e.render(a,b,c):d.render(a,b,c)}},67269:a=>{"use strict";a.exports={PNG_SIGNATURE:[137,80,78,71,13,10,26,10],TYPE_IHDR:0x49484452,TYPE_IEND:0x49454e44,TYPE_IDAT:0x49444154,TYPE_PLTE:0x504c5445,TYPE_tRNS:0x74524e53,TYPE_gAMA:0x67414d41,COLORTYPE_GRAYSCALE:0,COLORTYPE_PALETTE:1,COLORTYPE_COLOR:2,COLORTYPE_ALPHA:4,COLORTYPE_PALETTE_COLOR:3,COLORTYPE_COLOR_ALPHA:6,COLORTYPE_TO_BPP_MAP:{0:1,2:3,3:1,4:2,6:4},GAMMA_DIVISION:1e5}},70722:a=>{"use strict";a.exports=require("next/dist/shared/lib/invariant-error")},72081:(a,b,c)=>{let d=c(88397),e={WW:" ",WB:"▄",BB:"█",BW:"▀"},f={BB:" ",BW:"▄",WW:"█",WB:"▀"};b.render=function(a,b,c){let g=d.getOptions(b),h=e;("#ffffff"===g.color.dark.hex||"#000000"===g.color.light.hex)&&(h=f);let i=a.modules.size,j=a.modules.data,k="",l=Array(i+2*g.margin+1).join(h.WW);l=Array(g.margin/2+1).join(l+"\n");let m=Array(g.margin+1).join(h.WW);k+=l;for(let a=0;a<i;a+=2){k+=m;for(let b=0;b<i;b++){var n;let c=j[a*i+b],d=j[(a+1)*i+b];k+=(n=h,c&&d?n.BB:c&&!d?n.BW:!c&&d?n.WB:n.WW)}k+=m+"\n"}return k+=l.slice(0,-1),"function"==typeof c&&c(null,k),k},b.renderToFile=function(a,d,e,f){void 0===f&&(f=e,e=void 0);let g=c(29021),h=b.render(d,e);g.writeFile(a,h,f)}},73136:a=>{"use strict";a.exports=require("node:url")},74075:a=>{"use strict";a.exports=require("zlib")},76708:a=>{a.exports=function(){return"function"==typeof Promise&&Promise.prototype&&Promise.prototype.then}},76760:a=>{"use strict";a.exports=require("node:path")},77068:a=>{"use strict";a.exports=require("next/dist/shared/lib/size-limit")},78908:a=>{"use strict";a.exports=import("shiki")},79428:a=>{"use strict";a.exports=require("buffer")},80183:(a,b,c)=>{"use strict";let d=c(12412).ok,e=c(74075),f=c(28354),g=c(79428).kMaxLength;function h(a){if(!(this instanceof h))return new h(a);a&&a.chunkSize<e.Z_MIN_CHUNK&&(a.chunkSize=e.Z_MIN_CHUNK),e.Inflate.call(this,a),this._offset=void 0===this._offset?this._outOffset:this._offset,this._buffer=this._buffer||this._outBuffer,a&&null!=a.maxLength&&(this._maxLength=a.maxLength)}function i(a,b){b&&process.nextTick(b),a._handle&&(a._handle.close(),a._handle=null)}function j(a,b){var c=new h(b),d=a;if("string"==typeof d&&(d=Buffer.from(d)),!(d instanceof Buffer))throw TypeError("Not a string or buffer");let f=c._finishFlushFlag;return null==f&&(f=e.Z_FINISH),c._processChunk(d,f)}h.prototype._processChunk=function(a,b,c){let f,h;if("function"==typeof c)return e.Inflate._processChunk.call(this,a,b,c);let j=this,k=a&&a.length,l=this._chunkSize-this._offset,m=this._maxLength,n=0,o=[],p=0;this.on("error",function(a){f=a}),d(this._handle,"zlib binding closed");do h=(h=this._handle.writeSync(b,a,n,k,this._buffer,this._offset,l))||this._writeState;while(!this._hadError&&function(a,b){if(j._hadError)return;let c=l-b;if(d(c>=0,"have should not go down"),c>0){let a=j._buffer.slice(j._offset,j._offset+c);if(j._offset+=c,a.length>m&&(a=a.slice(0,m)),o.push(a),p+=a.length,0==(m-=a.length))return!1}return(0===b||j._offset>=j._chunkSize)&&(l=j._chunkSize,j._offset=0,j._buffer=Buffer.allocUnsafe(j._chunkSize)),0===b&&(n+=k-a,k=a,!0)}(h[0],h[1]));if(this._hadError)throw f;if(p>=g)throw i(this),RangeError("Cannot create final Buffer. It would be larger than 0x"+g.toString(16)+" bytes");let q=Buffer.concat(o,p);return i(this),q},f.inherits(h,e.Inflate),a.exports=b=j,b.Inflate=h,b.createInflate=function(a){return new h(a)},b.inflateSync=j},80706:(a,b,c)=>{"use strict";let d=!0,e=c(74075);e.deflateSync||(d=!1);let f=c(67269),g=c(98052);a.exports=function(a,b){if(!d)throw Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let c=new g(b||{}),h=[];h.push(Buffer.from(f.PNG_SIGNATURE)),h.push(c.packIHDR(a.width,a.height)),a.gamma&&h.push(c.packGAMA(a.gamma));let i=c.filterData(a.data,a.width,a.height),j=e.deflateSync(i,c.getDeflateOptions());if(i=null,!j||!j.length)throw Error("bad png - invalid compressed data response");return h.push(c.packIDAT(j)),h.push(c.packIEND()),Buffer.concat(h)}},81754:(a,b)=>{let c=new Uint8Array(512),d=new Uint8Array(256),e=1;for(let a=0;a<255;a++)c[a]=e,d[e]=a,256&(e<<=1)&&(e^=285);for(let a=255;a<512;a++)c[a]=c[a-255];b.log=function(a){if(a<1)throw Error("log("+a+")");return d[a]},b.exp=function(a){return c[a]},b.mul=function(a,b){return 0===a||0===b?0:c[d[a]+d[b]]}},81769:a=>{"use strict";let b=a.exports=function(a){this._buffer=a,this._reads=[]};b.prototype.read=function(a,b){this._reads.push({length:Math.abs(a),allowLess:a<0,func:b})},b.prototype.process=function(){for(;this._reads.length>0&&this._buffer.length;){let a=this._reads[0];if(this._buffer.length&&(this._buffer.length>=a.length||a.allowLess)){this._reads.shift();let b=this._buffer;this._buffer=b.slice(a.length),a.func.call(this,b.slice(0,a.length))}else break}return this._reads.length>0?Error("There are some read requests waitng on finished stream"):this._buffer.length>0?Error("unrecognised content at end of stream"):void 0}},83670:a=>{"use strict";a.exports=function(a,b){let c=b.depth,d=b.width,e=b.height,f=b.colorType,g=b.transColor,h=b.palette,i=a;return 3===f?!function(a,b,c,d,e){let f=0;for(let g=0;g<d;g++)for(let d=0;d<c;d++){let c=e[a[f]];if(!c)throw Error("index "+a[f]+" not in palette");for(let a=0;a<4;a++)b[f+a]=c[a];f+=4}}(a,i,d,e,h):(g&&function(a,b,c,d,e){let f=0;for(let g=0;g<d;g++)for(let d=0;d<c;d++){let c=!1;if(1===e.length?e[0]===a[f]&&(c=!0):e[0]===a[f]&&e[1]===a[f+1]&&e[2]===a[f+2]&&(c=!0),c)for(let a=0;a<4;a++)b[f+a]=0;f+=4}}(a,i,d,e,g),8!==c&&(16===c&&(i=Buffer.alloc(d*e*4)),!function(a,b,c,d,e){let f=Math.pow(2,e)-1,g=0;for(let e=0;e<d;e++)for(let d=0;d<c;d++){for(let c=0;c<4;c++)b[g+c]=Math.floor(255*a[g+c]/f+.5);g+=4}}(a,i,d,e,c))),i}},83929:(a,b)=>{b.isValid=function(a){return!isNaN(a)&&a>=1&&a<=40}},84879:a=>{"use strict";var b={single_source_shortest_paths:function(a,c,d){var e,f,g,h,i,j,k,l={},m={};m[c]=0;var n=b.PriorityQueue.make();for(n.push(c,0);!n.empty();)for(g in f=(e=n.pop()).value,h=e.cost,i=a[f]||{})i.hasOwnProperty(g)&&(j=h+i[g],k=m[g],(void 0===m[g]||k>j)&&(m[g]=j,n.push(g,j),l[g]=f));if(void 0!==d&&void 0===m[d])throw Error("Could not find a path from "+c+" to "+d+".");return l},extract_shortest_path_from_predecessor_list:function(a,b){for(var c=[],d=b;d;)c.push(d),a[d],d=a[d];return c.reverse(),c},find_path:function(a,c,d){var e=b.single_source_shortest_paths(a,c,d);return b.extract_shortest_path_from_predecessor_list(e,d)},PriorityQueue:{make:function(a){var c,d=b.PriorityQueue,e={};for(c in a=a||{},d)d.hasOwnProperty(c)&&(e[c]=d[c]);return e.queue=[],e.sorter=a.sorter||d.default_sorter,e},default_sorter:function(a,b){return a.cost-b.cost},push:function(a,b){this.queue.push({value:a,cost:b}),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return 0===this.queue.length}}};a.exports=b},86439:a=>{"use strict";a.exports=require("next/dist/shared/lib/no-fallback-error.external")},86491:(a,b)=>{let c="\x1b[37m",d="\x1b[30m",e="\x1b[0m",f="\x1b[47m"+d,g="\x1b[40m"+c,h=function(a,b,c,d){let e=b+1;return c>=e||d>=e||d<-1||c<-1?"0":c>=b||d>=b||d<0||c<0?"1":a[d*b+c]?"2":"1"},i=function(a,b,c,d){return h(a,b,c,d)+h(a,b,c,d+1)};b.render=function(a,b,h){var j,k;let l=a.modules.size,m=a.modules.data,n=!!(b&&b.inverse),o=b&&b.inverse?g:f,p={"00":e+" "+o,"01":e+(j=n?d:c)+"▄"+o,"02":e+(k=n?c:d)+"▄"+o,10:e+j+"▀"+o,11:" ",12:"▄",20:e+k+"▀"+o,21:"▀",22:"█"},q=e+"\n"+o,r=o;for(let a=-1;a<l+1;a+=2){for(let b=-1;b<l;b++)r+=p[i(m,l,b,a)];r+=p[i(m,l,l,a)]+q}return r+=e,"function"==typeof h&&h(null,r),r}},88066:(a,b,c)=>{let d=c(58305).getSymbolSize;b.getRowColCoords=function(a){if(1===a)return[];let b=Math.floor(a/7)+2,c=d(a),e=145===c?26:2*Math.ceil((c-13)/(2*b-2)),f=[c-7];for(let a=1;a<b-1;a++)f[a]=f[a-1]-e;return f.push(6),f.reverse()},b.getPositions=function(a){let c=[],d=b.getRowColCoords(a),e=d.length;for(let a=0;a<e;a++)for(let b=0;b<e;b++)(0!==a||0!==b)&&(0!==a||b!==e-1)&&(a!==e-1||0!==b)&&c.push([d[a],d[b]]);return c}},88397:(a,b)=>{function c(a){if("number"==typeof a&&(a=a.toString()),"string"!=typeof a)throw Error("Color should be defined as hex string");let b=a.slice().replace("#","").split("");if(b.length<3||5===b.length||b.length>8)throw Error("Invalid hex color: "+a);(3===b.length||4===b.length)&&(b=Array.prototype.concat.apply([],b.map(function(a){return[a,a]}))),6===b.length&&b.push("F","F");let c=parseInt(b.join(""),16);return{r:c>>24&255,g:c>>16&255,b:c>>8&255,a:255&c,hex:"#"+b.slice(0,6).join("")}}b.getOptions=function(a){a||(a={}),a.color||(a.color={});let b=void 0===a.margin||null===a.margin||a.margin<0?4:a.margin,d=a.width&&a.width>=21?a.width:void 0,e=a.scale||4;return{width:d,scale:d?4:e,margin:b,color:{dark:c(a.color.dark||"#000000ff"),light:c(a.color.light||"#ffffffff")},type:a.type,rendererOpts:a.rendererOpts||{}}},b.getScale=function(a,b){return b.width&&b.width>=a+2*b.margin?b.width/(a+2*b.margin):b.scale},b.getImageWidth=function(a,c){let d=b.getScale(a,c);return Math.floor((a+2*c.margin)*d)},b.qrToImageData=function(a,c,d){let e=c.modules.size,f=c.modules.data,g=b.getScale(e,d),h=Math.floor((e+2*d.margin)*g),i=d.margin*g,j=[d.color.light,d.color.dark];for(let b=0;b<h;b++)for(let c=0;c<h;c++){let k=(b*h+c)*4,l=d.color.light;b>=i&&c>=i&&b<h-i&&c<h-i&&(l=j[+!!f[Math.floor((b-i)/g)*e+Math.floor((c-i)/g)]]),a[k++]=l.r,a[k++]=l.g,a[k++]=l.b,a[k]=l.a}}},90082:(a,b,c)=>{b.render=c(32835).render,b.renderToFile=function(a,d,e,f){void 0===f&&(f=e,e=void 0);let g=c(29021),h=b.render(d,e);g.writeFile(a,'<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'+h,f)}},92858:(a,b,c)=>{"use strict";let d=c(59725),e=[function(){},function(a,b,c,d){if(d===b.length)throw Error("Ran out of data");let e=b[d];a[c]=e,a[c+1]=e,a[c+2]=e,a[c+3]=255},function(a,b,c,d){if(d+1>=b.length)throw Error("Ran out of data");let e=b[d];a[c]=e,a[c+1]=e,a[c+2]=e,a[c+3]=b[d+1]},function(a,b,c,d){if(d+2>=b.length)throw Error("Ran out of data");a[c]=b[d],a[c+1]=b[d+1],a[c+2]=b[d+2],a[c+3]=255},function(a,b,c,d){if(d+3>=b.length)throw Error("Ran out of data");a[c]=b[d],a[c+1]=b[d+1],a[c+2]=b[d+2],a[c+3]=b[d+3]}],f=[function(){},function(a,b,c,d){let e=b[0];a[c]=e,a[c+1]=e,a[c+2]=e,a[c+3]=d},function(a,b,c){let d=b[0];a[c]=d,a[c+1]=d,a[c+2]=d,a[c+3]=b[1]},function(a,b,c,d){a[c]=b[0],a[c+1]=b[1],a[c+2]=b[2],a[c+3]=d},function(a,b,c){a[c]=b[0],a[c+1]=b[1],a[c+2]=b[2],a[c+3]=b[3]}];b.dataToBitMap=function(a,b){let c,g,h,i,j,k,l=b.width,m=b.height,n=b.depth,o=b.bpp,p=b.interlace;8!==n&&(c=[],g=0,h={get:function(b){for(;c.length<b;)!function(){let b,d,e,f;if(g===a.length)throw Error("Ran out of data");let h=a[g];switch(g++,n){default:throw Error("unrecognised depth");case 16:e=a[g],g++,c.push((h<<8)+e);break;case 4:e=15&h,f=h>>4,c.push(f,e);break;case 2:b=3&h,d=h>>2&3,e=h>>4&3,f=h>>6&3,c.push(f,e,d,b);break;case 1:b=h>>4&1,d=h>>5&1,e=h>>6&1,f=h>>7&1,c.push(f,e,d,b,h>>3&1,h>>2&1,h>>1&1,1&h)}}();let d=c.slice(0,b);return c=c.slice(b),d},resetAfterLine:function(){c.length=0},end:function(){if(g!==a.length)throw Error("extra data found")}}),i=n<=8?Buffer.alloc(l*m*4):new Uint16Array(l*m*4);let q=Math.pow(2,n)-1,r=0;if(p)j=d.getImagePasses(l,m),k=d.getInterlaceIterator(l,m);else{let a=0;k=function(){let b=a;return a+=4,b},j=[{width:l,height:m}]}for(let b=0;b<j.length;b++)8===n?r=function(a,b,c,d,f,g){let h=a.width,i=a.height,j=a.index;for(let a=0;a<i;a++)for(let i=0;i<h;i++){let h=c(i,a,j);e[d](b,f,h,g),g+=d}return g}(j[b],i,k,o,a,r):function(a,b,c,d,e,g){let h=a.width,i=a.height,j=a.index;for(let a=0;a<i;a++){for(let i=0;i<h;i++){let h=e.get(d),k=c(i,a,j);f[d](b,h,k,g)}e.resetAfterLine()}}(j[b],i,k,o,h,q);if(8===n){if(r!==a.length)throw Error("extra data found")}else h.end();return i}},93669:(a,b,c)=>{let d=c(83929),e=c(64323);b.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},b.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},b.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},b.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},b.MIXED={bit:-1},b.getCharCountIndicator=function(a,b){if(!a.ccBits)throw Error("Invalid mode: "+a);if(!d.isValid(b))throw Error("Invalid version: "+b);return b>=1&&b<10?a.ccBits[0]:b<27?a.ccBits[1]:a.ccBits[2]},b.getBestModeForData=function(a){return e.testNumeric(a)?b.NUMERIC:e.testAlphanumeric(a)?b.ALPHANUMERIC:e.testKanji(a)?b.KANJI:b.BYTE},b.toString=function(a){if(a&&a.id)return a.id;throw Error("Invalid mode")},b.isValid=function(a){return a&&a.bit&&a.ccBits},b.from=function(a,c){if(b.isValid(a))return a;try{if("string"!=typeof a)throw Error("Param is not a string");switch(a.toLowerCase()){case"numeric":return b.NUMERIC;case"alphanumeric":return b.ALPHANUMERIC;case"kanji":return b.KANJI;case"byte":return b.BYTE;default:throw Error("Unknown mode: "+a)}}catch(a){return c}}},94165:(a,b,c)=>{"use strict";let d=c(67269);a.exports=function(a,b,c,e){let f=-1!==[d.COLORTYPE_COLOR_ALPHA,d.COLORTYPE_ALPHA].indexOf(e.colorType);if(e.colorType===e.inputColorType){let b,c=(new DataView(b=new ArrayBuffer(2)).setInt16(0,256,!0),256!==new Int16Array(b)[0]);if(8===e.bitDepth||16===e.bitDepth&&c)return a}let g=16!==e.bitDepth?a:new Uint16Array(a.buffer),h=255,i=d.COLORTYPE_TO_BPP_MAP[e.inputColorType];4!==i||e.inputHasAlpha||(i=3);let j=d.COLORTYPE_TO_BPP_MAP[e.colorType];16===e.bitDepth&&(h=65535,j*=2);let k=Buffer.alloc(b*c*j),l=0,m=0,n=e.bgColor||{};void 0===n.red&&(n.red=h),void 0===n.green&&(n.green=h),void 0===n.blue&&(n.blue=h);for(let a=0;a<c;a++)for(let a=0;a<b;a++){let a=function(){let a,b,c,i=h;switch(e.inputColorType){case d.COLORTYPE_COLOR_ALPHA:i=g[l+3],a=g[l],b=g[l+1],c=g[l+2];break;case d.COLORTYPE_COLOR:a=g[l],b=g[l+1],c=g[l+2];break;case d.COLORTYPE_ALPHA:i=g[l+1],b=a=g[l],c=a;break;case d.COLORTYPE_GRAYSCALE:b=a=g[l],c=a;break;default:throw Error("input color type:"+e.inputColorType+" is not supported at present")}return e.inputHasAlpha&&!f&&(i/=h,a=Math.min(Math.max(Math.round((1-i)*n.red+i*a),0),h),b=Math.min(Math.max(Math.round((1-i)*n.green+i*b),0),h),c=Math.min(Math.max(Math.round((1-i)*n.blue+i*c),0),h)),{red:a,green:b,blue:c,alpha:i}}();switch(e.colorType){case d.COLORTYPE_COLOR_ALPHA:case d.COLORTYPE_COLOR:8===e.bitDepth?(k[m]=a.red,k[m+1]=a.green,k[m+2]=a.blue,f&&(k[m+3]=a.alpha)):(k.writeUInt16BE(a.red,m),k.writeUInt16BE(a.green,m+2),k.writeUInt16BE(a.blue,m+4),f&&k.writeUInt16BE(a.alpha,m+6));break;case d.COLORTYPE_ALPHA:case d.COLORTYPE_GRAYSCALE:{let b=(a.red+a.green+a.blue)/3;8===e.bitDepth?(k[m]=b,f&&(k[m+1]=a.alpha)):(k.writeUInt16BE(b,m),f&&k.writeUInt16BE(a.alpha,m+2));break}default:throw Error("unrecognised color Type "+e.colorType)}l+=i,m+=j}return k}},94735:a=>{"use strict";a.exports=require("events")},95380:(a,b,c)=>{let d=c(58305),e=c(58856),f=c(52002),g=c(46349),h=c(88066),i=c(39477),j=c(12097),k=c(19477),l=c(98129),m=c(52324),n=c(55258),o=c(93669),p=c(39588);function q(a,b,c){let d,e,f=a.size,g=n.getEncodedBits(b,c);for(d=0;d<15;d++)e=(g>>d&1)==1,d<6?a.set(d,8,e,!0):d<8?a.set(d+1,8,e,!0):a.set(f-15+d,8,e,!0),d<8?a.set(8,f-d-1,e,!0):d<9?a.set(8,15-d-1+1,e,!0):a.set(8,15-d-1,e,!0);a.set(f-8,8,1,!0)}b.create=function(a,b){let c,n;if(void 0===a||""===a)throw Error("No input text");let r=e.M;return void 0!==b&&(r=e.from(b.errorCorrectionLevel,e.M),c=m.from(b.version),n=j.from(b.maskPattern),b.toSJISFunc&&d.setToSJISFunction(b.toSJISFunc)),function(a,b,c,e){let n;if(Array.isArray(a))n=p.fromArray(a);else if("string"==typeof a){let d=b;if(!d){let b=p.rawSplit(a);d=m.getBestVersionForData(b,c)}n=p.fromString(a,d||40)}else throw Error("Invalid data");let r=m.getBestVersionForData(n,c);if(!r)throw Error("The amount of data is too big to be stored in a QR Code");if(b){if(b<r)throw Error("\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: "+r+".\n")}else b=r;let s=function(a,b,c){let e=new f;c.forEach(function(b){e.put(b.mode.bit,4),e.put(b.getLength(),o.getCharCountIndicator(b.mode,a)),b.write(e)});let g=(d.getSymbolTotalCodewords(a)-k.getTotalCodewordsCount(a,b))*8;for(e.getLengthInBits()+4<=g&&e.put(0,4);e.getLengthInBits()%8!=0;)e.putBit(0);let h=(g-e.getLengthInBits())/8;for(let a=0;a<h;a++)e.put(a%2?17:236,8);return function(a,b,c){let e,f,g=d.getSymbolTotalCodewords(b),h=g-k.getTotalCodewordsCount(b,c),i=k.getBlocksCount(b,c),j=g%i,m=i-j,n=Math.floor(g/i),o=Math.floor(h/i),p=o+1,q=n-o,r=new l(q),s=0,t=Array(i),u=Array(i),v=0,w=new Uint8Array(a.buffer);for(let a=0;a<i;a++){let b=a<m?o:p;t[a]=w.slice(s,s+b),u[a]=r.encode(t[a]),s+=b,v=Math.max(v,b)}let x=new Uint8Array(g),y=0;for(e=0;e<v;e++)for(f=0;f<i;f++)e<t[f].length&&(x[y++]=t[f][e]);for(e=0;e<q;e++)for(f=0;f<i;f++)x[y++]=u[f][e];return x}(e,a,b)}(b,c,n),t=new g(d.getSymbolSize(b));!function(a,b){let c=a.size,d=i.getPositions(b);for(let b=0;b<d.length;b++){let e=d[b][0],f=d[b][1];for(let b=-1;b<=7;b++)if(!(e+b<=-1)&&!(c<=e+b))for(let d=-1;d<=7;d++)f+d<=-1||c<=f+d||(b>=0&&b<=6&&(0===d||6===d)||d>=0&&d<=6&&(0===b||6===b)||b>=2&&b<=4&&d>=2&&d<=4?a.set(e+b,f+d,!0,!0):a.set(e+b,f+d,!1,!0))}}(t,b);let u=t.size;for(let a=8;a<u-8;a++){let b=a%2==0;t.set(a,6,b,!0),t.set(6,a,b,!0)}return!function(a,b){let c=h.getPositions(b);for(let b=0;b<c.length;b++){let d=c[b][0],e=c[b][1];for(let b=-2;b<=2;b++)for(let c=-2;c<=2;c++)-2===b||2===b||-2===c||2===c||0===b&&0===c?a.set(d+b,e+c,!0,!0):a.set(d+b,e+c,!1,!0)}}(t,b),q(t,c,0),b>=7&&function(a,b){let c,d,e,f=a.size,g=m.getEncodedBits(b);for(let b=0;b<18;b++)c=Math.floor(b/3),d=b%3+f-8-3,e=(g>>b&1)==1,a.set(c,d,e,!0),a.set(d,c,e,!0)}(t,b),!function(a,b){let c=a.size,d=-1,e=c-1,f=7,g=0;for(let h=c-1;h>0;h-=2)for(6===h&&h--;;){for(let c=0;c<2;c++)if(!a.isReserved(e,h-c)){let d=!1;g<b.length&&(d=(b[g]>>>f&1)==1),a.set(e,h-c,d),-1==--f&&(g++,f=7)}if((e+=d)<0||c<=e){e-=d,d=-d;break}}}(t,s),isNaN(e)&&(e=j.getBestMask(t,q.bind(null,t,c))),j.applyMask(e,t),q(t,c,e),{modules:t,version:b,errorCorrectionLevel:c,maskPattern:e,segments:n}}(a,c,r,n)}},96277:(a,b,c)=>{"use strict";let d=c(67269),e=c(43894),f=a.exports=function(a,b){this._options=a,a.checkCRC=!1!==a.checkCRC,this._hasIHDR=!1,this._hasIEND=!1,this._emittedHeadersFinished=!1,this._palette=[],this._colorType=0,this._chunks={},this._chunks[d.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[d.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[d.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[d.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[d.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[d.TYPE_gAMA]=this._handleGAMA.bind(this),this.read=b.read,this.error=b.error,this.metadata=b.metadata,this.gamma=b.gamma,this.transColor=b.transColor,this.palette=b.palette,this.parsed=b.parsed,this.inflateData=b.inflateData,this.finished=b.finished,this.simpleTransparency=b.simpleTransparency,this.headersFinished=b.headersFinished||function(){}};f.prototype.start=function(){this.read(d.PNG_SIGNATURE.length,this._parseSignature.bind(this))},f.prototype._parseSignature=function(a){let b=d.PNG_SIGNATURE;for(let c=0;c<b.length;c++)if(a[c]!==b[c])return void this.error(Error("Invalid file signature"));this.read(8,this._parseChunkBegin.bind(this))},f.prototype._parseChunkBegin=function(a){let b=a.readUInt32BE(0),c=a.readUInt32BE(4),f="";for(let b=4;b<8;b++)f+=String.fromCharCode(a[b]);let g=!!(32&a[4]);return this._hasIHDR||c===d.TYPE_IHDR?(this._crc=new e,this._crc.write(Buffer.from(f)),this._chunks[c])?this._chunks[c](b):g?void this.read(b+4,this._skipChunk.bind(this)):void this.error(Error("Unsupported critical chunk type "+f)):void this.error(Error("Expected IHDR on beggining"))},f.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this))},f.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this))},f.prototype._parseChunkEnd=function(a){let b=a.readInt32BE(0),c=this._crc.crc32();this._options.checkCRC&&c!==b?this.error(Error("Crc error - "+b+" - "+c)):this._hasIEND||this.read(8,this._parseChunkBegin.bind(this))},f.prototype._handleIHDR=function(a){this.read(a,this._parseIHDR.bind(this))},f.prototype._parseIHDR=function(a){this._crc.write(a);let b=a.readUInt32BE(0),c=a.readUInt32BE(4),e=a[8],f=a[9],g=a[10],h=a[11],i=a[12];if(8!==e&&4!==e&&2!==e&&1!==e&&16!==e)return void this.error(Error("Unsupported bit depth "+e));if(!(f in d.COLORTYPE_TO_BPP_MAP))return void this.error(Error("Unsupported color type"));if(0!==g)return void this.error(Error("Unsupported compression method"));if(0!==h)return void this.error(Error("Unsupported filter method"));if(0!==i&&1!==i)return void this.error(Error("Unsupported interlace method"));this._colorType=f;let j=d.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=!0,this.metadata({width:b,height:c,depth:e,interlace:!!i,palette:!!(f&d.COLORTYPE_PALETTE),color:!!(f&d.COLORTYPE_COLOR),alpha:!!(f&d.COLORTYPE_ALPHA),bpp:j,colorType:f}),this._handleChunkEnd()},f.prototype._handlePLTE=function(a){this.read(a,this._parsePLTE.bind(this))},f.prototype._parsePLTE=function(a){this._crc.write(a);let b=Math.floor(a.length/3);for(let c=0;c<b;c++)this._palette.push([a[3*c],a[3*c+1],a[3*c+2],255]);this.palette(this._palette),this._handleChunkEnd()},f.prototype._handleTRNS=function(a){this.simpleTransparency(),this.read(a,this._parseTRNS.bind(this))},f.prototype._parseTRNS=function(a){if(this._crc.write(a),this._colorType===d.COLORTYPE_PALETTE_COLOR){if(0===this._palette.length)return void this.error(Error("Transparency chunk must be after palette"));if(a.length>this._palette.length)return void this.error(Error("More transparent colors than palette size"));for(let b=0;b<a.length;b++)this._palette[b][3]=a[b];this.palette(this._palette)}this._colorType===d.COLORTYPE_GRAYSCALE&&this.transColor([a.readUInt16BE(0)]),this._colorType===d.COLORTYPE_COLOR&&this.transColor([a.readUInt16BE(0),a.readUInt16BE(2),a.readUInt16BE(4)]),this._handleChunkEnd()},f.prototype._handleGAMA=function(a){this.read(a,this._parseGAMA.bind(this))},f.prototype._parseGAMA=function(a){this._crc.write(a),this.gamma(a.readUInt32BE(0)/d.GAMMA_DIVISION),this._handleChunkEnd()},f.prototype._handleIDAT=function(a){this._emittedHeadersFinished||(this._emittedHeadersFinished=!0,this.headersFinished()),this.read(-a,this._parseIDAT.bind(this,a))},f.prototype._parseIDAT=function(a,b){if(this._crc.write(b),this._colorType===d.COLORTYPE_PALETTE_COLOR&&0===this._palette.length)throw Error("Expected palette not found");this.inflateData(b);let c=a-b.length;c>0?this._handleIDAT(c):this._handleChunkEnd()},f.prototype._handleIEND=function(a){this.read(a,this._parseIEND.bind(this))},f.prototype._parseIEND=function(a){this._crc.write(a),this._hasIEND=!0,this._handleChunkEnd(),this.finished&&this.finished()}},98052:(a,b,c)=>{"use strict";let d=c(67269),e=c(43894),f=c(94165),g=c(31964),h=c(74075),i=a.exports=function(a){if(this._options=a,a.deflateChunkSize=a.deflateChunkSize||32768,a.deflateLevel=null!=a.deflateLevel?a.deflateLevel:9,a.deflateStrategy=null!=a.deflateStrategy?a.deflateStrategy:3,a.inputHasAlpha=null==a.inputHasAlpha||a.inputHasAlpha,a.deflateFactory=a.deflateFactory||h.createDeflate,a.bitDepth=a.bitDepth||8,a.colorType="number"==typeof a.colorType?a.colorType:d.COLORTYPE_COLOR_ALPHA,a.inputColorType="number"==typeof a.inputColorType?a.inputColorType:d.COLORTYPE_COLOR_ALPHA,-1===[d.COLORTYPE_GRAYSCALE,d.COLORTYPE_COLOR,d.COLORTYPE_COLOR_ALPHA,d.COLORTYPE_ALPHA].indexOf(a.colorType))throw Error("option color type:"+a.colorType+" is not supported at present");if(-1===[d.COLORTYPE_GRAYSCALE,d.COLORTYPE_COLOR,d.COLORTYPE_COLOR_ALPHA,d.COLORTYPE_ALPHA].indexOf(a.inputColorType))throw Error("option input color type:"+a.inputColorType+" is not supported at present");if(8!==a.bitDepth&&16!==a.bitDepth)throw Error("option bit depth:"+a.bitDepth+" is not supported at present")};i.prototype.getDeflateOptions=function(){return{chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}},i.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())},i.prototype.filterData=function(a,b,c){let e=f(a,b,c,this._options),h=d.COLORTYPE_TO_BPP_MAP[this._options.colorType];return g(e,b,c,this._options,h)},i.prototype._packChunk=function(a,b){let c=b?b.length:0,d=Buffer.alloc(c+12);return d.writeUInt32BE(c,0),d.writeUInt32BE(a,4),b&&b.copy(d,8),d.writeInt32BE(e.crc32(d.slice(4,d.length-4)),d.length-4),d},i.prototype.packGAMA=function(a){let b=Buffer.alloc(4);return b.writeUInt32BE(Math.floor(a*d.GAMMA_DIVISION),0),this._packChunk(d.TYPE_gAMA,b)},i.prototype.packIHDR=function(a,b){let c=Buffer.alloc(13);return c.writeUInt32BE(a,0),c.writeUInt32BE(b,4),c[8]=this._options.bitDepth,c[9]=this._options.colorType,c[10]=0,c[11]=0,c[12]=0,this._packChunk(d.TYPE_IHDR,c)},i.prototype.packIDAT=function(a){return this._packChunk(d.TYPE_IDAT,a)},i.prototype.packIEND=function(){return this._packChunk(d.TYPE_IEND,null)}},98129:(a,b,c)=>{let d=c(43144);function e(a){this.genPoly=void 0,this.degree=a,this.degree&&this.initialize(this.degree)}e.prototype.initialize=function(a){this.degree=a,this.genPoly=d.generateECPolynomial(this.degree)},e.prototype.encode=function(a){if(!this.genPoly)throw Error("Encoder not initialized");let b=new Uint8Array(a.length+this.degree);b.set(a);let c=d.mod(b,this.genPoly),e=this.degree-c.length;if(e>0){let a=new Uint8Array(this.degree);return a.set(c,e),a}return c},a.exports=e},99647:(a,b,c)=>{"use strict";c.r(b),c.d(b,{default:()=>g});var d=c(5735),e=c(91986),f=c(35790);function g(){return(0,d.jsx)(e.Suspense,{children:(0,d.jsx)(f.AppShell,{})})}}};var b=require("../webpack-runtime.js");b.C(a);var c=b.X(0,[4741,63,8304,9962,1494,6195],()=>b(b.s=55897));module.exports=c})();