@seqyuan/annovibe 0.8.59 → 0.8.61
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.
- package/.next/BUILD_ID +1 -1
- package/.next/app-path-routes-manifest.json +9 -9
- package/.next/build-manifest.json +2 -2
- package/.next/prerender-manifest.json +3 -3
- package/.next/required-server-files.js +1 -1
- package/.next/required-server-files.json +1 -1
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/api/agent/runtime/route.js +1 -1
- package/.next/server/app/api/internal/runtime/route.js +1 -1
- package/.next/server/app/api/version/route.js +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +2 -2
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/index.segments/_full.segment.rsc +2 -2
- package/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/.next/server/app/login.html +1 -1
- package/.next/server/app/login.rsc +1 -1
- package/.next/server/app/login.segments/_full.segment.rsc +1 -1
- package/.next/server/app/login.segments/_head.segment.rsc +1 -1
- package/.next/server/app/login.segments/_index.segment.rsc +1 -1
- package/.next/server/app/login.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/login.segments/login.segment.rsc +1 -1
- package/.next/server/app/page.js +9 -9
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app/smoke/page_client-reference-manifest.js +1 -1
- package/.next/server/app/smoke.html +1 -1
- package/.next/server/app/smoke.rsc +1 -1
- package/.next/server/app/smoke.segments/_full.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/_head.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/_index.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/smoke/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/smoke.segments/smoke.segment.rsc +1 -1
- package/.next/server/app-paths-manifest.json +9 -9
- package/.next/server/chunks/1494.js +2 -2
- package/.next/server/chunks/7601.js +18 -6
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/middleware.js +3 -3
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/chunks/app/page-76fb62bb085c3bcb.js +27 -0
- package/package.json +1 -1
- package/.next/static/chunks/app/page-9d8d8e997bb13130.js +0 -27
- /package/.next/static/{yn2_Hx9KhiJl_-xJx-jLp → VeYC1tzffq6omBdSMpZGj}/_buildManifest.js +0 -0
- /package/.next/static/{yn2_Hx9KhiJl_-xJx-jLp → VeYC1tzffq6omBdSMpZGj}/_ssgManifest.js +0 -0
package/.next/server/app/page.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
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,82877))},1708:a=>{"use strict";a.exports=require("node:process")},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))},10846:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},17891:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/get-segment-param")},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")},26713:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/is-bot")},27910:a=>{"use strict";a.exports=require("stream")},28354:a=>{"use strict";a.exports=require("util")},29294:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-async-storage.external.js")},33873:a=>{"use strict";a.exports=require("path")},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")},41025:a=>{"use strict";a.exports=require("next/dist/server/app-render/dynamic-access-async-storage.external.js")},43954:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/interception-routes")},63033:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},70722:a=>{"use strict";a.exports=require("next/dist/shared/lib/invariant-error")},71411:(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}}},73136:a=>{"use strict";a.exports=require("node:url")},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")},82877:(a,b,c)=>{"use strict";c.d(b,{AppShell:()=>c$});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..."})]})]})})}let k="AnnoVibe";function l(a){}async function m(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 n(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 o(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 p(a,b){if(!a)return"No Project";let c=a.replace(/[\\/]+$/,""),d=c.includes("/")?"/":"\\";return c.split(d).filter(Boolean).pop()||o(a,b)}function q(){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.59":k),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 r({selectedSessionId:a,onSelectSession:b,onNewSession:c,onNewWorkbench:f,initialSessionId:g,onInitialRestoreDone:h,refreshKey:i,onSessionDeleted:k,selectedCwd:n,onCwdChange:x}){let[y,z]=(0,e.useState)([]),[A,B]=(0,e.useState)([]),[C,D]=(0,e.useState)(!0),[E,F]=(0,e.useState)(null),[G,H]=(0,e.useState)(null),[I,J]=(0,e.useState)(""),[K,L]=(0,e.useState)(null),[M,N]=(0,e.useState)(!1),[O,P]=(0,e.useState)("project"),[Q,R]=(0,e.useState)(null),[S,T]=(0,e.useState)(!1),[U,V]=(0,e.useState)(!1),[W,X]=(0,e.useState)(()=>new Set),[Y,Z]=(0,e.useState)(()=>new Set),[$,_]=(0,e.useState)(null),[aa,ab]=(0,e.useState)(null),[ac,ad]=(0,e.useState)(null),[ae,af]=(0,e.useState)(!1),ag=(0,e.useRef)(null),[ah,ai]=(0,e.useState)(!1),aj=(0,e.useRef)(!1),ak=(0,e.useRef)(!1);(0,e.useRef)(!1);let al=(0,e.useCallback)(async(a=!1)=>{try{a&&(F(null),D(!0));let b=new AbortController,c=setTimeout(()=>b.abort(new DOMException("Loading timed out","TimeoutError")),3e4),[d,e]=await Promise.all([fetch("/api/sessions",{signal:b.signal}),fetch("/api/projects",{signal:b.signal})]);if(clearTimeout(c),!d.ok)throw Error(await m("sessions",d));if(!e.ok)throw Error(await m("projects",e));let f=await d.json(),g=await e.json();z(f.sessions),B(g.projects),F(null)}catch(a){F(a instanceof DOMException&&("AbortError"===a.name||"TimeoutError"===a.name)||a instanceof Error&&/aborted without reason|AbortError/i.test(a.message)?"Loading timed out. Codex may still be starting; try the refresh button.":a instanceof Error?a.message:String(a))}finally{a&&D(!1)}},[]);(0,e.useRef)(!1),(0,e.useRef)(!1);let am=(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 L(d.error??`HTTP ${c.status}`),!1;return al(!1),!0}catch(a){return L(a instanceof Error?a.message:String(a)),!1}},[al]),an=(0,e.useCallback)(a=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,touch:!0})}).catch(()=>{})},[]),ao=(0,e.useCallback)(a=>{ak.current=!0,H(a),L(null),Z(b=>{if(!b.has(a))return b;let c=new Set(b);return c.delete(a),l(c),c}),x?.(a),an(a)},[x,an]),ap=n??G,aq=(0,e.useCallback)(a=>{if(!a){P("agent"),N(!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]),ar=(0,e.useCallback)(a=>{if(!a){P("workbench"),N(!0);return}f?.(a)},[f]);(0,e.useCallback)(async a=>{await am(a,!0)&&(ao(a),N(!1),L(null),"agent"===O&&aq(a),"workbench"===O&&ar(a))},[ao,aq,ar,O,am]);let as=(0,e.useCallback)(a=>{R(a),T(!0)},[]),at=(0,e.useCallback)(()=>{T(!1),R(null)},[]),au=(0,e.useCallback)(a=>{let b=Q??ap;at(),"agent"===a?aq(b):ar(b)},[at,aq,ar,ap,Q]),av=(0,e.useCallback)(()=>{as(ap)},[ap,as]),aw=(0,e.useCallback)(()=>{P("project"),L(null),N(!0)},[]),ax=(0,e.useMemo)(()=>[...ap&&!A.some(a=>a.cwd===ap)?[{cwd:ap,displayName:p(ap,I),chatCount:y.filter(a=>a.cwd===ap).length,lastAccessed:null,created:null,pinned:!1,sortOrder:null,exists:!0,source:"manual"}]:[],...A].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"})}),[y,ap,I,A]),ay=(0,e.useMemo)(()=>{let a=new Map;for(let b of y){let c=b.cwd||"";a.has(c)||a.set(c,[]),a.get(c).push(b)}let b=b=>{let c=[...a.get(b.cwd)??[]].sort((a,b)=>(b.modified||"").localeCompare(a.modified||""));return{project:b,cwd:b.cwd,displayName:b.displayName||p(b.cwd,I),sessions:c,lastAccessed:(b.lastAccessed??b.created??"")||c[0]?.modified||""}},c=ax.filter(a=>!0===a.pinned).map(b);if(ap){let a=ax.find(a=>a.cwd===ap);a&&!0!==a.pinned&&c.push(b(a))}return c},[y,ap,I,ax]),az=(0,e.useCallback)((a,c=!1)=>{a.cwd!==ap&&(aj.current=!0,H(a.cwd)),Z(b=>{if(!b.has(a.cwd))return b;let c=new Set(b);return c.delete(a.cwd),l(c),c}),an(a.cwd),b(a,c)},[b,ap,an]),aA=(0,e.useCallback)(a=>{Z(b=>{let c=new Set(b);return c.has(a)?c.delete(a):c.add(a),l(c),c})},[]),aB=(0,e.useCallback)(a=>{X(b=>{let c=new Set(b);return c.has(a)?c.delete(a):c.add(a),c})},[]),aC=(0,e.useCallback)(async a=>{ad("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}`);B(c.projects??[]),F(null)}catch(a){F(a instanceof Error?a.message:String(a)),al(!1)}finally{ad(null)}},[al]),aD=(0,e.useCallback)(async(a,b)=>{ad(`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}`);B(d.projects??[]),F(null)}catch(a){F(a instanceof Error?a.message:String(a)),al(!1)}finally{ad(null)}},[al]),aE=(0,e.useCallback)((a,b)=>{if(!a||!b||a===b)return;let c=ax.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),aC(f)},[aC,ax]),aF=(0,e.useCallback)(async()=>{ai(!0);try{let a=ax.filter(a=>!0===a.pinned).map(a=>a.cwd);a.length>0?await Promise.all(a.map(a=>fetch(`/api/sessions?cwd=${encodeURIComponent(a)}`,{signal:AbortSignal.timeout(3e4)}).then(a=>a.ok?a.json():Promise.reject(Error(`HTTP ${a.status}`))).then(b=>{z(c=>[...c.filter(b=>b.cwd!==a),...b.sessions??[]])}).catch(()=>{}))):await al(!1)}finally{ai(!1)}},[al,ax]);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)(q,{}),(0,d.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,d.jsxs)("button",{onClick:av,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:ap?`New chat in ${ap}`:"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:()=>V(!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:U,cwd:ap,homeDir:I,onClose:()=>V(!1),onSelectSession:a=>{az(a)}}),(0,d.jsxs)("div",{ref:ag,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,d.jsxs)("button",{type:"button",onClick:()=>af(a=>!a),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:ap?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:ap?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:ap??"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:ap?"var(--text)":"var(--text-dim)"},children:ap?ax.find(a=>a.cwd===ap)?.displayName??o(ap,I):"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:ae?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,d.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),ap&&(0,d.jsx)(t,{pinned:ax.find(a=>a.cwd===ap)?.pinned===!0,onToggle:()=>void aD(ap,ax.find(a=>a.cwd===ap)?.pinned!==!0)}),ae&&(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===ax.length&&(0,d.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),ax.map(a=>{let b=a.cwd===ap;return(0,d.jsx)(u,{project:a,homeDir:I,isCurrent:b,onSelect:()=>{ao(a.cwd),af(!1)},onTogglePinned:()=>void aD(a.cwd,!0!==a.pinned)},a.cwd)}),(0,d.jsxs)("button",{type:"button",onClick:()=>{af(!1),aw()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:ax.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.jsx)("div",{style:{display:"flex",alignItems:"center",gap:4,marginLeft:"auto"},children:(0,d.jsx)("button",{type:"button",onClick:aF,disabled:ah,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:ah?"var(--accent)":"var(--text-dim)",cursor:ah?"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:ah?"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"})]})})})]}),K&&(0,d.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:K})]}),(0,d.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[C&&(0,d.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),E&&(0,d.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:E}),!C&&!E&&0===ay.length&&(0,d.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!C&&!E&&ay.map(b=>{let c=Y.has(b.cwd),e=b.cwd===ap,f=W.has(b.cwd),g=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),h=g.length,i=g;if(h>10&&!f){i=g.slice(0,10);let b=g.find(b=>(function a(b,c){return!!c&&(b.session.id===c||b.children.some(b=>a(b,c)))})(b,a));b&&!i.includes(b)&&(i=[...i,b])}let j=h-i.length;return(0,d.jsxs)("div",{style:{marginBottom:6,borderTop:aa===b.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(aa===b.cwd),opacity:$===b.cwd?.55:1},onDragOver:a=>{$&&$!==b.cwd&&(a.preventDefault(),a.dataTransfer.dropEffect="move",ab(b.cwd))},onDragLeave:()=>{aa===b.cwd&&ab(null)},onDrop:a=>{a.preventDefault();let c=a.dataTransfer.getData("text/project-cwd")||$;ab(null),_(null),c&&aE(c,b.cwd)},children:[(0,d.jsx)(v,{group:b,isCurrent:e,isCollapsed:c,isDragging:$===b.cwd,pinBusy:ac===`pin:${b.cwd}`,onToggle:()=>aA(b.cwd),onSelect:()=>ao(b.cwd),onTogglePinned:()=>void aD(b.cwd,!0!==b.project.pinned),onDragStart:a=>{_(b.cwd),a.dataTransfer.effectAllowed="move",a.dataTransfer.setData("text/project-cwd",b.cwd)},onDragEnd:()=>{_(null),ab(null)}}),!c&&(0,d.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[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."}):i.map(b=>(0,d.jsx)(w,{node:b,selectedSessionId:a,onSelectSession:az,onRenamed:al,onSessionDeleted:a=>{k?.(a),al()},depth:0},b.session.id)),(f||j>0)&&h>10&&(0,d.jsx)("button",{type:"button",onClick:()=>aB(b.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:f?"Show less":`Show ${Math.max(0,j)} more`})]})]},b.cwd||"__no_project")})]}),S&&(0,d.jsx)(s,{cwd:Q,onChoose:au,onClose:at})]})}function s({cwd:a,onChoose:b,onClose:c}){let e=a?p(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 t({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 u({project:a,homeDir:b,isCurrent:c,onSelect:f,onTogglePinned:g}){let[h,i]=(0,e.useState)(!1),j=a.displayName||p(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 v({group:a,isCurrent:b,isCollapsed:c,isDragging:f,pinBusy:g,onToggle:h,onSelect:i,onTogglePinned:j,onDragStart:k,onDragEnd:l}){let[m,o]=(0,e.useState)(!1),p=a.lastAccessed,q=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:()=>o(!0),onMouseLeave:()=>o(!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&&q>0&&(0,d.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[q," ",1===q?"chat":"chats"]}),!m&&p&&(0,d.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:n(p)}),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 w({node:a,selectedSessionId:b,onSelectSession:c,onRenamed:f,onSessionDeleted:g,depth:h}){let[i,j]=(0,e.useState)(!1),k=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)(x,{session:a.session,isSelected:a.session.id===b,onClick:()=>c(a.session),onRenamed:f,onDeleted:a=>g?.(a),depth:h,hasChildren:k,collapsed:i,onToggleCollapse:()=>j(a=>!a)})]}),k&&!i&&(0,d.jsx)("div",{children:a.children.map(a=>(0,d.jsx)(w,{node:a,selectedSessionId:b,onSelectSession:c,onRenamed:f,onSessionDeleted:g,depth:h+1},a.session.id))})]})}function x({session:a,isSelected:b,onClick:c,onRenamed:f,onDeleted:g,depth:h=0,hasChildren:i=!1,collapsed:j=!1,onToggleCollapse:k}){let[l,m]=(0,e.useState)(!1),[o,p]=(0,e.useState)(!1),[q,r]=(0,e.useState)(""),[s,t]=(0,e.useState)(!1),[u,v]=(0,e.useState)(!1),w=(0,e.useRef)(null),y=a.name||a.firstMessage.slice(0,50)||a.id.slice(0,12),z=(0,e.useCallback)(b=>{b.stopPropagation(),r(a.name??""),p(!0),setTimeout(()=>w.current?.select(),0)},[a.name]),A=(0,e.useCallback)(async()=>{let b=q.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{}},[q,a.id,a.name,f]),B=(0,e.useCallback)(a=>{a.stopPropagation(),t(!0)},[]),C=(0,e.useCallback)(async b=>{b.stopPropagation(),t(!1),v(!0);try{await fetch(`/api/sessions/${encodeURIComponent(a.id)}`,{method:"DELETE"}),g?.(a.id)}catch{v(!1)}},[a.id,g]),D=(0,e.useCallback)(a=>{a.stopPropagation(),t(!1)},[]),E="workbench"===a.sessionKind;return(0,d.jsx)("div",{onClick:s||o?void 0:c,onMouseEnter:()=>m(!0),onMouseLeave:()=>{m(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:h>0?12*h+14:14,paddingRight:8,cursor:s||o?"default":"pointer",background:s?"rgba(239,68,68,0.06)":b?"var(--bg-selected)":l?"var(--bg-hover)":"transparent",borderLeft:s?"2px solid #ef4444":b?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:u?.5:1,gap:6,overflow:"hidden"},children:s?(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:C,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:D,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:w,value:q,onChange:a=>r(a.target.value),onBlur:A,onKeyDown:a=>{"Enter"===a.key&&A(),"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:5,height:5,borderRadius:"50%",background:b?"var(--accent)":"var(--text-dim)",opacity:b?1:.35,flexShrink:0}}),E&&(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:E?"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:n(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"})})}),l&&(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:B,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 y=c(62418);let z="subagent",A=["retain","recall","reflect"],B=[],C=["read","bash","edit","write"],D=["bash","read","edit","write","grep","find","ls"],E=[...D,"kernel_plot_run","kernel_plot_render","kernel_plot_stop","kernel_plot_artifacts"],F=[...D,z];function G(a){return[...a].sort().join(",")}function H(a){switch(a){case"none":return B;case"default":return C;case"workbench":return E;case"agent":return F;default:return D}}function I(a,b){return[...new Set([...H(a),...b])]}let J=new Map,K=["off","default","full","agent"],L={off:"none",default:"default",full:"full",agent:"agent"},M={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},N={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},O=["auto","off","minimal","low","medium","high","xhigh"],P={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},Q=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function R({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 S(a){return a.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'")}async function T(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
|
|
4
|
-
${e}`}).join("\n\n")}async function
|
|
5
|
-
${c.join("\n")}`)}return f.join("\n\n")}async function
|
|
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}}},73136:a=>{"use strict";a.exports=require("node:url")},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")},82877:(a,b,c)=>{"use strict";c.d(b,{AppShell:()=>c$});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){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 p(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 q(a,b){if(!a)return"No Project";let c=a.replace(/[\\/]+$/,""),d=c.includes("/")?"/":"\\";return c.split(d).filter(Boolean).pop()||p(a,b)}function r(){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.61":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 s({selectedSessionId:a,onSelectSession:b,onNewSession:c,onNewWorkbench:f,initialSessionId:g,onInitialRestoreDone:h,refreshKey:i,onSessionDeleted:l,selectedCwd:o,onCwdChange:y}){let[z,A]=(0,e.useState)([]),[B,C]=(0,e.useState)([]),[D,E]=(0,e.useState)(!0),[F,G]=(0,e.useState)(null),[H,I]=(0,e.useState)(null),[J,K]=(0,e.useState)(""),[L,M]=(0,e.useState)(null),[N,O]=(0,e.useState)(!1),[P,Q]=(0,e.useState)("project"),[R,S]=(0,e.useState)(null),[T,U]=(0,e.useState)(!1),[V,W]=(0,e.useState)(!1),[X,Y]=(0,e.useState)(()=>new Set),[Z,$]=(0,e.useState)(()=>new Set),[_,aa]=(0,e.useState)(null),[ab,ac]=(0,e.useState)(null),[ad,ae]=(0,e.useState)(null),[af,ag]=(0,e.useState)(!1),ah=(0,e.useRef)(null),[ai,aj]=(0,e.useState)(!1),ak=(0,e.useRef)(!1),al=(0,e.useRef)(!1);(0,e.useRef)(!1);let am=(0,e.useCallback)(async(a=!1)=>{try{a&&(G(null),E(!0));let b=new AbortController,c=setTimeout(()=>b.abort(new DOMException("Loading timed out","TimeoutError")),3e4),[d,e]=await Promise.all([fetch("/api/sessions",{signal:b.signal}),fetch("/api/projects",{signal:b.signal})]);if(clearTimeout(c),!d.ok)throw Error(await n("sessions",d));if(!e.ok)throw Error(await n("projects",e));let f=await d.json(),g=await e.json();A(f.sessions),C(g.projects),G(null)}catch(a){G(a instanceof DOMException&&("AbortError"===a.name||"TimeoutError"===a.name)||a instanceof Error&&/aborted without reason|AbortError/i.test(a.message)?"Loading timed out. Codex may still be starting; try the refresh button.":a instanceof Error?a.message:String(a))}finally{a&&E(!1)}},[]);(0,e.useRef)(!1),(0,e.useRef)(!1);let an=(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 M(d.error??`HTTP ${c.status}`),!1;return am(!1),!0}catch(a){return M(a instanceof Error?a.message:String(a)),!1}},[am]),ao=(0,e.useCallback)(a=>{fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,touch:!0})}).catch(()=>{})},[]),ap=(0,e.useCallback)(a=>{al.current=!0,I(a),M(null),$(b=>{if(!b.has(a))return b;let c=new Set(b);return c.delete(a),m(c),c}),y?.(a),ao(a)},[y,ao]),aq=o??H,ar=(0,e.useCallback)(a=>{if(!a){Q("agent"),O(!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]),as=(0,e.useCallback)(a=>{if(!a){Q("workbench"),O(!0);return}f?.(a)},[f]),at=(0,e.useCallback)(async a=>{await an(a,!0)&&(ap(a),O(!1),M(null),"agent"===P&&ar(a),"workbench"===P&&as(a))},[ap,ar,as,P,an]),au=(0,e.useCallback)(a=>{S(a),U(!0)},[]),av=(0,e.useCallback)(()=>{U(!1),S(null)},[]),aw=(0,e.useCallback)(a=>{let b=R??aq;av(),"agent"===a?ar(b):as(b)},[av,ar,as,aq,R]),ax=(0,e.useCallback)(()=>{au(aq)},[aq,au]),ay=(0,e.useCallback)(()=>{Q("project"),M(null),O(!0)},[]),az=(0,e.useMemo)(()=>[...aq&&!B.some(a=>a.cwd===aq)?[{cwd:aq,displayName:q(aq,J),chatCount:z.filter(a=>a.cwd===aq).length,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"})}),[z,aq,J,B]),aA=(0,e.useMemo)(()=>{let a=new Map;for(let b of z){let c=b.cwd||"";a.has(c)||a.set(c,[]),a.get(c).push(b)}let b=b=>{let c=[...a.get(b.cwd)??[]].sort((a,b)=>(b.modified||"").localeCompare(a.modified||""));return{project:b,cwd:b.cwd,displayName:b.displayName||q(b.cwd,J),sessions:c,lastAccessed:(b.lastAccessed??b.created??"")||c[0]?.modified||""}},c=az.filter(a=>!0===a.pinned).map(b);if(aq){let a=az.find(a=>a.cwd===aq);a&&!0!==a.pinned&&c.push(b(a))}return c},[z,aq,J,az]),aB=(0,e.useCallback)((a,c=!1)=>{a.cwd!==aq&&(ak.current=!0,I(a.cwd)),$(b=>{if(!b.has(a.cwd))return b;let c=new Set(b);return c.delete(a.cwd),m(c),c}),ao(a.cwd),b(a,c)},[b,aq,ao]),aC=(0,e.useCallback)(a=>{$(b=>{let c=new Set(b);return c.has(a)?c.delete(a):c.add(a),m(c),c})},[]),aD=(0,e.useCallback)(a=>{Y(b=>{let c=new Set(b);return c.has(a)?c.delete(a):c.add(a),c})},[]),aE=(0,e.useCallback)(async a=>{ae("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??[]),G(null)}catch(a){G(a instanceof Error?a.message:String(a)),am(!1)}finally{ae(null)}},[am]),aF=(0,e.useCallback)(async(a,b)=>{ae(`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??[]),G(null)}catch(a){G(a instanceof Error?a.message:String(a)),am(!1)}finally{ae(null)}},[am]),aG=(0,e.useCallback)((a,b)=>{if(!a||!b||a===b)return;let c=az.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),aE(f)},[aE,az]),aH=(0,e.useCallback)(async()=>{aj(!0);try{let a=az.filter(a=>!0===a.pinned).map(a=>a.cwd);a.length>0?await Promise.all(a.map(a=>fetch(`/api/sessions?cwd=${encodeURIComponent(a)}`,{signal:AbortSignal.timeout(3e4)}).then(a=>a.ok?a.json():Promise.reject(Error(`HTTP ${a.status}`))).then(b=>{A(c=>[...c.filter(b=>b.cwd!==a),...b.sessions??[]])}).catch(()=>{}))):await am(!1)}finally{aj(!1)}},[am,az]);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)(r,{}),(0,d.jsxs)("div",{style:{display:"flex",gap:6,minWidth:0},children:[(0,d.jsxs)("button",{onClick:ax,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:aq?`New chat in ${aq}`:"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:()=>W(!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:V,cwd:aq,homeDir:J,onClose:()=>W(!1),onSelectSession:a=>{aB(a)}}),(0,d.jsxs)("div",{ref:ah,style:{position:"relative",marginTop:8,padding:"0 10px",display:"flex",alignItems:"stretch",gap:4},children:[(0,d.jsxs)("button",{type:"button",onClick:()=>ag(a=>!a),style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,padding:"6px 10px",background:aq?"var(--bg-hover)":"rgba(37,99,235,0.06)",border:aq?"1px solid var(--border)":"1px solid rgba(37,99,235,0.4)",borderRadius:7,cursor:"pointer",fontSize:12,color:"var(--text)",textAlign:"left"},title:aq??"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:aq?"var(--text)":"var(--text-dim)"},children:aq?az.find(a=>a.cwd===aq)?.displayName??p(aq,J):"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:af?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,d.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})})]}),aq&&(0,d.jsx)(u,{pinned:az.find(a=>a.cwd===aq)?.pinned===!0,onToggle:()=>void aF(aq,az.find(a=>a.cwd===aq)?.pinned!==!0)}),af&&(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===az.length&&(0,d.jsx)("div",{style:{padding:"10px 12px",color:"var(--text-dim)",fontSize:11},children:"No projects yet"}),az.map(a=>{let b=a.cwd===aq;return(0,d.jsx)(v,{project:a,homeDir:J,isCurrent:b,onSelect:()=>{ap(a.cwd),ag(!1)},onTogglePinned:()=>void aF(a.cwd,!0!==a.pinned)},a.cwd)}),(0,d.jsxs)("button",{type:"button",onClick:()=>{ag(!1),ay()},style:{display:"flex",alignItems:"center",gap:7,width:"100%",padding:"8px 10px",background:"none",border:"none",borderTop:az.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:aH,disabled:ai,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:ai?"var(--accent)":"var(--text-dim)",cursor:ai?"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:ai?"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:ay,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"]})]})]}),L&&(0,d.jsx)("div",{style:{marginTop:6,color:"#f87171",fontSize:11,lineHeight:1.4,overflowWrap:"anywhere"},children:L})]}),(0,d.jsxs)("div",{style:{flex:"1 1 auto",overflowY:"auto",padding:"6px 8px 8px",minHeight:80,scrollbarWidth:"thin",overscrollBehavior:"contain"},children:[D&&(0,d.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Loading..."}),F&&(0,d.jsx)("div",{style:{padding:"12px 14px",color:"#f87171",fontSize:12},children:F}),!D&&!F&&0===aA.length&&(0,d.jsx)("div",{style:{padding:"16px 14px",color:"var(--text-muted)",fontSize:12},children:"Open or create a project to start chatting."}),!D&&!F&&aA.map(b=>{let c=Z.has(b.cwd),e=b.cwd===aq,f=X.has(b.cwd),g=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),h=g.length,i=g;if(h>10&&!f){i=g.slice(0,10);let b=g.find(b=>(function a(b,c){return!!c&&(b.session.id===c||b.children.some(b=>a(b,c)))})(b,a));b&&!i.includes(b)&&(i=[...i,b])}let j=h-i.length;return(0,d.jsxs)("div",{style:{marginBottom:6,borderTop:ab===b.cwd?"2px solid var(--accent)":"2px solid transparent",paddingTop:2*(ab===b.cwd),opacity:_===b.cwd?.55:1},onDragOver:a=>{_&&_!==b.cwd&&(a.preventDefault(),a.dataTransfer.dropEffect="move",ac(b.cwd))},onDragLeave:()=>{ab===b.cwd&&ac(null)},onDrop:a=>{a.preventDefault();let c=a.dataTransfer.getData("text/project-cwd")||_;ac(null),aa(null),c&&aG(c,b.cwd)},children:[(0,d.jsx)(w,{group:b,isCurrent:e,isCollapsed:c,isDragging:_===b.cwd,pinBusy:ad===`pin:${b.cwd}`,onToggle:()=>aC(b.cwd),onSelect:()=>ap(b.cwd),onTogglePinned:()=>void aF(b.cwd,!0!==b.project.pinned),onDragStart:a=>{aa(b.cwd),a.dataTransfer.effectAllowed="move",a.dataTransfer.setData("text/project-cwd",b.cwd)},onDragEnd:()=>{aa(null),ac(null)}}),!c&&(0,d.jsxs)("div",{style:{marginTop:2,overflow:"hidden",borderRadius:7},children:[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."}):i.map(b=>(0,d.jsx)(x,{node:b,selectedSessionId:a,onSelectSession:aB,onRenamed:am,onSessionDeleted:a=>{l?.(a),am()},depth:0},b.session.id)),(f||j>0)&&h>10&&(0,d.jsx)("button",{type:"button",onClick:()=>aD(b.cwd),style:{width:"100%",padding:"6px 10px",background:"transparent",border:"none",color:"var(--text-dim)",cursor:"pointer",fontSize:11,textAlign:"center"},children:f?"Show less":`Show ${Math.max(0,j)} more`})]})]},b.cwd||"__no_project")})]}),T&&(0,d.jsx)(t,{cwd:R,onChoose:aw,onClose:av}),(0,d.jsx)(k,{open:N,initialPath:aq,onClose:()=>O(!1),onSelect:a=>at(a)})]})}function t({cwd:a,onChoose:b,onClose:c}){let e=a?q(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 u({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 v({project:a,homeDir:b,isCurrent:c,onSelect:f,onTogglePinned:g}){let[h,i]=(0,e.useState)(!1),j=a.displayName||q(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 w({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),p=a.lastAccessed,q=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&&q>0&&(0,d.jsxs)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:[q," ",1===q?"chat":"chats"]}),!m&&p&&(0,d.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",fontSize:10,whiteSpace:"nowrap"},children:o(p)}),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 x({node:a,selectedSessionId:b,onSelectSession:c,onRenamed:f,onSessionDeleted:g,depth:h}){let[i,j]=(0,e.useState)(!1),k=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)(y,{session:a.session,isSelected:a.session.id===b,onClick:()=>c(a.session),onRenamed:f,onDeleted:a=>g?.(a),depth:h,hasChildren:k,collapsed:i,onToggleCollapse:()=>j(a=>!a)})]}),k&&!i&&(0,d.jsx)("div",{children:a.children.map(a=>(0,d.jsx)(x,{node:a,selectedSessionId:b,onSelectSession:c,onRenamed:f,onSessionDeleted:g,depth:h+1},a.session.id))})]})}function y({session:a,isSelected:b,onClick:c,onRenamed:f,onDeleted:g,depth:h=0,hasChildren:i=!1,collapsed:j=!1,onToggleCollapse:k}){let[l,m]=(0,e.useState)(!1),[n,p]=(0,e.useState)(!1),[q,r]=(0,e.useState)(""),[s,t]=(0,e.useState)(!1),[u,v]=(0,e.useState)(!1),w=(0,e.useRef)(null),x=a.name||a.firstMessage.slice(0,50)||a.id.slice(0,12),z=(0,e.useCallback)(b=>{b.stopPropagation(),r(a.name??""),p(!0),setTimeout(()=>w.current?.select(),0)},[a.name]),A=(0,e.useCallback)(async()=>{let b=q.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{}},[q,a.id,a.name,f]),B=(0,e.useCallback)(a=>{a.stopPropagation(),t(!0)},[]),C=(0,e.useCallback)(async b=>{b.stopPropagation(),t(!1),v(!0);try{await fetch(`/api/sessions/${encodeURIComponent(a.id)}`,{method:"DELETE"}),g?.(a.id)}catch{v(!1)}},[a.id,g]),D=(0,e.useCallback)(a=>{a.stopPropagation(),t(!1)},[]),E="workbench"===a.sessionKind;return(0,d.jsx)("div",{onClick:s||n?void 0:c,onMouseEnter:()=>m(!0),onMouseLeave:()=>{m(!1)},style:{display:"flex",alignItems:"center",padding:"7px 8px",paddingLeft:h>0?12*h+14:14,paddingRight:8,cursor:s||n?"default":"pointer",background:s?"rgba(239,68,68,0.06)":b?"var(--bg-selected)":l?"var(--bg-hover)":"transparent",borderLeft:s?"2px solid #ef4444":b?"2px solid var(--accent)":"2px solid transparent",transition:"background 0.1s",opacity:u?.5:1,gap:6,overflow:"hidden"},children:s?(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:["“",x.slice(0,22),x.length>22?"…":"","”"]}),"?"]}),(0,d.jsxs)("div",{style:{display:"flex",gap:5,flexShrink:0},children:[(0,d.jsxs)("button",{onClick:C,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:D,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"})]})]}):n?(0,d.jsx)("input",{ref:w,value:q,onChange:a=>r(a.target.value),onBlur:A,onKeyDown:a=>{"Enter"===a.key&&A(),"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:5,height:5,borderRadius:"50%",background:b?"var(--accent)":"var(--text-dim)",opacity:b?1:.35,flexShrink:0}}),E&&(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:E?"var(--accent)":"var(--text)"},title:x,children:x}),(0,d.jsxs)("div",{style:{display:"flex",gap:8,color:"var(--text-dim)",fontSize:11},children:[(0,d.jsx)("span",{title:a.modified,children:o(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"})})}),l&&(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:B,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 z=c(62418);let A="subagent",B=["retain","recall","reflect"],C=[],D=["read","bash","edit","write"],E=["bash","read","edit","write","grep","find","ls"],F=[...E,"kernel_plot_run","kernel_plot_render","kernel_plot_stop","kernel_plot_artifacts"],G=[...E,A];function H(a){return[...a].sort().join(",")}function I(a){switch(a){case"none":return C;case"default":return D;case"workbench":return F;case"agent":return G;default:return E}}function J(a,b){return[...new Set([...I(a),...b])]}let K=new Map,L=["off","default","full","agent"],M={off:"none",default:"default",full:"full",agent:"agent"},N={off:"无工具,纯聊天",default:"4 项内置工具",full:"全部内置工具",agent:"High + 子代理"},O={retain:{label:"retain",description:"保存稳定事实或决策到项目记忆"},recall:{label:"recall",description:"检索项目记忆中的相关上下文"},reflect:{label:"reflect",description:"基于已存记忆做综合回应"}},P=["auto","off","minimal","low","medium","high","xhigh"],Q={auto:"沿用 pi 默认设置",off:"关闭推理",minimal:"最少推理",low:"低强度推理",medium:"中等推理",high:"高强度推理",xhigh:"最高强度推理"},R=[{command:"/compact",label:"/compact",description:"压缩当前上下文",kind:"native"},{command:"/init",label:"/init",description:"快捷插入,交给模型处理初始化任务",kind:"shortcut"},{command:"/memory",label:"/memory",description:"快捷插入,交给模型处理项目记忆任务",kind:"shortcut"}];function S({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 T(a){return a.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'")}async function U(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 V(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=>T(a[1])))}return f.join("").replace(/[ \t]+\n/g,"\n")}async function W(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 X(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=>T(a[1]).trim()).filter(Boolean);c.length&&f.push(`Slide ${b[1]}
|
|
5
|
+
${c.join("\n")}`)}return f.join("\n\n")}async function Y(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 U(b);else if("docx"===c)e=await V(b);else if("xlsx"===c)e=await W(b);else{if("pptx"!==c)return{extractionError:"Text extraction is not supported for this file type"};e=await X(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)}
|
|
6
6
|
|
|
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 Y=(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:B,cornerBadge:C,promptHistory:D,sessionHistoryKey:E},F){let G,H,I,[S,T]=(0,e.useState)(""),[U,V]=(0,e.useState)(!1),[W,Y]=(0,e.useState)(null),[Z,$]=(0,e.useState)(!1),[_,aa]=(0,e.useState)(!1),[ab,ac]=(0,e.useState)(!1),[ad,ae]=(0,e.useState)(!1),[af,ag]=(0,e.useState)(!1),[ah,ai]=(0,e.useState)(null),[aj,ak]=(0,e.useState)([]),[al,am]=(0,e.useState)([]),an=function(a=768){let[b,c]=(0,e.useState)(!1);return b}(),ao=an?{display:"none"}:void 0,ap=an?28:32,aq=an?"6px 8px":"8px 12px",ar=an?160:180,as=an&&!g,at=af?"var(--text)":"var(--text-muted)",au={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},av=an?{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},[aw,ax]=(0,e.useState)(null),ay=(0,e.useRef)(null),az=(0,e.useRef)(null),aA=(0,e.useRef)(null),aB=(0,e.useRef)(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.useCallback)(a=>{let b=ay.current;if(!b)return void T(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")?"":" ";T(e+g+a+f),requestAnimationFrame(()=>{let b=ay.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)(F,()=>({insertIfEmpty(a){let b=ay.current;(b?b.value:S).trim()||(T(a),requestAnimationFrame(()=>{b&&(b.focus(),b.style.height="auto",b.style.height=`${Math.min(b.scrollHeight,200)}px`)}))},insertText(a){aI(a)},addImages(a){aJ(a)},addFiles(a){aK(a)}}));let aJ=(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)})));ak(a=>[...a,...c])},[]),aK=(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&&aJ(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 X(a,c);b({data:c,fileName:a.name,mimeType:a.type||"application/octet-stream",size:a.size,...e})},d.onerror=c,d.readAsArrayBuffer(a)})));am(b=>[...b,...a])}},[aJ]),aL=(0,e.useCallback)(a=>{ak(b=>{let c=[...b];return URL.revokeObjectURL(c[a].previewUrl),c.splice(a,1),c})},[]),aM=(0,e.useCallback)(a=>{am(b=>{let c=[...b];return c.splice(a,1),c})},[]),aN=(0,e.useCallback)(()=>{ak(a=>(a.forEach(a=>URL.revokeObjectURL(a.previewUrl)),[])),am([])},[]),aO=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})),aP=[];for(let a of aO){let b=aP.find(b=>b.provider===a.provider);b?b.options.push(a):aP.push({provider:a.provider,options:[a]})}let aQ=h?aO.find(a=>a.modelId===h.modelId&&a.provider===h.provider)?.name??h.modelId:aO.length>0?aO[0].name:null,aR=h?aO.find(a=>a.modelId===h.modelId&&a.provider===h.provider):aO[0],aS=aR?.input?.includes("image")??!0,aT=aj.length>0&&aR?.input!==void 0&&!aS,aU=(!!S.trim()||aj.length>0||al.length>0)&&!aT,aV=l?Q:Q.filter(a=>"/compact"!==a.command),aW=aV.filter(a=>"native"===a.kind),aX=aV.filter(a=>"shortcut"===a.kind),aY=s??[],aZ=aY.length>0?`${aY.length} enabled`:"off",a$=aO.length>0&&!!aQ&&!!k,a_=!!v,a0=!!r&&"workbench"!==q,a1=aQ??"Default",a2=(()=>{let a=u??"auto";if("auto"===a||!x)return a;let b=x[a];return null!=b?b:a})(),a3=(p??"full")==="workbench"?"workbench":Object.entries(L).find(([,a])=>a===(p??"full"))?.[0]??"full",a4=an?26:32,a5=an?7:9,a6=an?3:6,a7={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)"},a8=an&&(U||Z||_||ab||ad||af);(0,e.useEffect)(()=>{aT||ax(null)},[aT]);let a9=(0,e.useCallback)(a=>{if(!S.trim()){T(a),requestAnimationFrame(()=>{let b=ay.current;b&&(b.focus(),b.setSelectionRange(a.length,a.length),b.style.height="auto",b.style.height=`${Math.min(b.scrollHeight,200)}px`)});return}aI(a)},[aI,S]),ba=(0,e.useCallback)(()=>{let b=S.trim();if(b||aj.length||al.length){if(aj.length&&!aS)return void ax("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!g){if("/compact"===b&&!aj.length&&!al.length&&l){n?m?.():l(),T(""),ay.current&&(ay.current.style.height="auto");return}a(b,aj.length?aj:void 0,al.length?al:void 0),T(""),aN(),ay.current&&(ay.current.style.height="auto")}}},[S,aj,al,aS,g,a,aN,l,m,n]),bb=(0,e.useCallback)(a=>{let b=S.trim();if(!b&&!aj.length&&!al.length)return;if(aj.length&&!aS)return void ax("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let d=aj.length?aj:void 0,e=al.length?al:void 0;"steer"===a&&c?c(b,d,e):"followup"===a&&f&&f(b,d,e),T(""),aN(),ay.current&&(ay.current.style.height="auto")},[S,aj,al,aS,c,f,aN]),bc=D??[],bd=E??null,be=(0,e.useCallback)(a=>{if("ArrowUp"===a.key&&!a.shiftKey&&!a.ctrlKey&&!a.metaKey&&bc.length>0){let b=ay.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=J.get(a))||(d={cursor:-1,draftSnapshot:""},J.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}(bd,b.value,bc);null!==d&&(T(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=J.get(a);return(b?.cursor??-1)>=0}(bd)){a.preventDefault();let b=function(a,b){if(!a)return null;let c=J.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}}(bd,bc);b&&(T(b.text),b.returnedToPresent&&requestAnimationFrame(()=>{let a=ay.current;a&&a.setSelectionRange(b.text.length,b.text.length)}));return}"Enter"===a.key&&!a.shiftKey&&!a.nativeEvent.isComposing&&(a.preventDefault(),bd&&J.set(bd,{cursor:-1,draftSnapshot:""}),g&&(c||f)?bb(c?"steer":"followup"):ba())},[g,c,f,bb,ba,bc,bd]),bf=(0,e.useCallback)(()=>{let a=ay.current;a&&(a.style.height="auto",a.style.height=`${Math.min(a.scrollHeight,200)}px`)},[]),bg=(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(),aK(b.map(a=>a.getAsFile()).filter(a=>null!==a)))},[aK]);return(0,e.useEffect)(()=>{if(!U&&!Z&&!_&&!ab&&!ad&&!af)return;let a=a=>{let b=a.target;if(!(b instanceof Node))return;let c=!!az.current?.contains(b),d=!!aA.current?.contains(b);c||d||V(!1),aB.current?.contains(b)||$(!1),aC.current?.contains(b)||aa(!1),aD.current?.contains(b)||ac(!1),aE.current?.contains(b)||ae(!1),aF.current?.contains(b)||ag(!1)};return document.addEventListener("pointerdown",a,!0),()=>{document.removeEventListener("pointerdown",a,!0)}},[U,Z,_,ab,ad,af]),(0,e.useEffect)(()=>{if(!r)return;let a=!1;return fetch("/api/subagents/status").then(a=>a.ok?a.json():null).then(b=>{a||ai(!!b?.ready)}).catch(()=>{a||ai(!1)}),()=>{a=!0}},[r]),(0,d.jsxs)("div",{style:av,children:[a8&&(0,d.jsx)("div",{"aria-hidden":!0,onClick:()=>{V(!1),$(!1),aa(!1),ac(!1),ae(!1),ag(!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:aG,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:a=>{aJ(Array.from(a.target.files??[])),a.target.value=""}}),(0,d.jsx)("input",{ref:aH,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=>{aK(Array.from(a.target.files??[])),a.target.value=""}}),(0,d.jsxs)("div",{style:{maxWidth:an?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:an?"0 8px":void 0,boxSizing:"border-box"},children:[C&&(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:C}),y&&(0,d.jsxs)("div",{style:{marginBottom:an?6:8,padding:an?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:an?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]})]}),(aj.length>0||al.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:[aj.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 ${aT?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,d.jsx)("button",{onClick:()=>aL(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}`)),al.map((a,b)=>(0,d.jsx)(R,{doc:a,onRemove:()=>aM(b)},`doc-${b}`))]}),(aT||aw)&&(0,d.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:an?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:aw??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,d.jsxs)("div",{style:{display:"flex",gap:an?4:8,alignItems:an?"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:an?13:14,padding:an?"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:ay,value:S,onChange:a=>T(a.target.value),onKeyDown:be,onInput:bf,onPaste:bg,placeholder:g&&(c||f)?"Steer 立即注入 / Follow-up 排队…":g?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:an?"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:+!!an,paddingBottom:+!!an}}),g?(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:an?4:6,flexShrink:0,alignSelf:"flex-end"},children:[c&&(0,d.jsxs)("button",{onClick:()=>bb("steer"),disabled:!aU,title:aT?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!an,padding:an?"6px 8px":"7px 12px",background:aU?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:aU?"rgba(180,130,0,1)":"var(--text-dim)",cursor:aU?"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"})]}),!an&&"Steer"]}),f&&(0,d.jsxs)("button",{onClick:()=>bb("followup"),disabled:!aU,title:aT?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!an,padding:an?"6px 8px":"7px 12px",background:aU?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:aU?"rgba(99,102,241,1)":"var(--text-dim)",cursor:aU?"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"})]}),!an&&"Follow-up"]})]}):(0,d.jsxs)("button",{onClick:ba,disabled:!aU,title:aT?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:an?3:6,padding:an?"5px 9px":"7px 14px",marginBottom:+!!an,background:aU?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:aU?"#fff":"var(--text-dim)",cursor:aU?"pointer":"not-allowed",fontSize:an?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:aU?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,d.jsxs)("svg",{width:an?13:14,height:an?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:an?5:8,display:"flex",alignItems:an?"flex-start":"center",gap:a6,flexWrap:an?"wrap":"nowrap"},children:[(0,d.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:an?"1 1 100%":"0 0 auto",width:an?"100%":void 0,display:"flex",alignItems:"center",gap:2*!an,flexWrap:an?"wrap":"nowrap",rowGap:4*!!an},children:[(0,d.jsx)("button",{onClick:()=>aG.current?.click(),disabled:g,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:a4,height:a4,padding:0,background:"none",border:"none",borderRadius:a5,color:aj.length||al.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=aj.length||al.length?"var(--accent)":"var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background="none",a.currentTarget.style.color=aj.length||al.length?"var(--accent)":"var(--text-muted)"},onContextMenu:a=>{a.preventDefault(),aH.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:aB,style:{position:"relative"},children:[(0,d.jsxs)("button",{onClick:()=>{g||($(a=>!a),aa(!1),V(!1),ac(!1),ae(!1),ag(!1))},disabled:g,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:a4,height:a4,padding:0,background:Z?"var(--bg-hover)":"none",border:"none",borderRadius:a5,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=Z?"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"}})]}),Z&&(0,d.jsxs)("div",{style:{...an?a7:{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}),aW.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"}),aW.map(a=>(0,d.jsxs)("button",{onClick:()=>{($(!1),"/compact"===a.command&&n)?m?.():a9(a.command)},style:{display:"flex",alignItems:"center",gap:an?6:8,width:"100%",padding:aq,background:"none",border:"none",color:"/compact"===a.command&&n?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:an?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))]}),aX.length>0&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{style:{marginTop:2*(aW.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:aW.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),aX.map(a=>(0,d.jsxs)("button",{onClick:()=>{$(!1),a9(a.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:aq,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:an?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:aC,style:{position:"relative"},children:[(0,d.jsxs)("button",{onClick:()=>{g||(aa(a=>!a),$(!1),V(!1),ac(!1),ae(!1),ag(!1))},disabled:g,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:ap,padding:0,background:_?"var(--bg-hover)":"none",border:"none",borderRadius:an?8:9,color:aY.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=aY.length>0?"var(--accent)":"var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background=_?"var(--bg-hover)":"none",a.currentTarget.style.color=aY.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),aY.length>0&&(0,d.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),_&&(0,d.jsxs)("div",{style:{...an?a7:{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"}),A.map(a=>{let b=aY.includes(a),c=N[a];return(0,d.jsxs)("button",{onClick:()=>{t(b?aY.filter(b=>b!==a):[...aY,a])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:aq,background:b?"var(--bg-selected)":"none",border:"none",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:an?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)})]})]}),a$&&(0,d.jsxs)("div",{ref:az,style:{position:"relative",flex:an?"1 1 160px":void 0,minWidth:0},children:[(0,d.jsxs)("button",{onClick:a=>{if(!an){let b=a.currentTarget.getBoundingClientRect();Y({top:b.top,left:b.left,width:b.width})}$(!1),aa(!1),ac(!1),ae(!1),ag(!1),V(a=>!a)},disabled:g,style:{display:"flex",alignItems:"center",gap:6,padding:aq,height:ap,width:an?"100%":void 0,maxWidth:an?"100%":220,overflow:"hidden",background:U?"var(--bg-hover)":"none",border:"none",borderRadius:an?8:9,color:"var(--text-muted)",cursor:g?"not-allowed":"pointer",fontSize:an?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=U?"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:aQ})]}),U&&(an?(0,d.jsxs)("div",{ref:aA,style:{...a7,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:aQ})]}),(0,d.jsx)("div",{style:{overflowY:"auto"},children:aP.map((a,b)=>(0,d.jsxs)("div",{children:[aP.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:()=>{V(!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))})]}):W&&(H=(G=window.visualViewport?.height??window.innerHeight)-W.top+6,I=Math.max(120,Math.min(W.top-8,.6*G)),(0,d.jsx)("div",{ref:aA,style:{position:"fixed",bottom:H,left:W.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:W.width,maxHeight:I,overflowY:"auto"},children:aP.map((a,b)=>(0,d.jsxs)("div",{children:[aP.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:()=>{V(!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))})))]})]}),(0,d.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:as?"none":void 0,flex:an?"0 0 auto":1,width:an?0:void 0,height:an?0:void 0}}),(0,d.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:an?"1 1 100%":"0 0 auto",width:an?"100%":void 0,display:"flex",alignItems:"center",justifyContent:an?"space-between":void 0,gap:an?4:2,marginLeft:an?0:"auto",marginTop:2*!!an},children:[as&&(0,d.jsxs)("div",{ref:aF,style:{position:"relative"},children:[(0,d.jsx)("button",{onClick:()=>{$(!1),aa(!1),V(!1),ac(!1),ae(!1),ag(a=>!a)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:af?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:at,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=af?"var(--bg-hover)":"none",a.currentTarget.style.color=af?"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"})]})}),af&&(0,d.jsxs)("div",{style:{...a7,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:[a$&&(0,d.jsxs)("button",{onClick:()=>{ag(!1),ae(!1),ac(!1),aa(!1),V(!0)},style:au,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:a1})]}),(a_||a0)&&(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[a_&&(0,d.jsxs)("button",{onClick:()=>{ag(!1),V(!1),ac(!1),aa(!1),ae(!0)},style:au,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:a2})]}),a0&&(0,d.jsxs)("button",{onClick:()=>{ag(!1),V(!1),ae(!1),aa(!1),ac(!0)},style:au,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:a3})]})]}),!!t&&(0,d.jsxs)("button",{onClick:()=>{ag(!1),V(!1),ae(!1),ac(!1),aa(!0)},style:au,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:aY.length>0?"var(--accent)":"var(--text)",marginTop:2},children:aZ})]})]})]})]}),(!as&&!g||an&&ad)&&v&&(0,d.jsxs)("div",{ref:aE,style:{position:"relative"},children:[!as&&!g&&(0,d.jsxs)("button",{onClick:()=>{g||($(!1),aa(!1),V(!1),ac(!1),ag(!1),ae(a=>!a))},disabled:g,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:an?3:5,padding:aq,height:ap,background:ad?"var(--bg-hover)":"none",border:"none",borderRadius:an?8:9,color:"var(--text-muted)",cursor:g?"not-allowed":"pointer",fontSize:an?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=ad?"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:ao,children:(()=>{let a=u??"auto";if("auto"===a||!x)return a;let b=x[a];return null!=b?b:a})()})]}),ad&&(0,d.jsx)("div",{style:{...an?a7:{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:ar},overflow:"hidden"},children:O.filter(a=>!w||"auto"===a||w.includes(a)).map(a=>{let b=(u??"auto")===a,c=P[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:()=>{ae(!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:an?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)})})]}),(!as&&!g||an&&ab)&&a0&&(0,d.jsxs)("div",{ref:aD,style:{position:"relative"},children:[!as&&!g&&(0,d.jsxs)("button",{onClick:()=>{g||($(!1),aa(!1),V(!1),ae(!1),ag(!1),ac(a=>!a))},disabled:g,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:an?3:5,padding:aq,height:ap,background:ab?"var(--bg-hover)":"none",border:"none",borderRadius:an?8:9,color:(p??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:g?"not-allowed":"pointer",fontSize:an?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=ab?"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:ao,children:a3})]}),ab&&(0,d.jsx)("div",{style:{...an?a7:{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:K.map(a=>{let b=L[a],c=(p??"full")===b,e="agent"===a&&!1===ah,f=e?"需安装 pi-subagents":M[a];return(0,d.jsxs)("button",{onClick:()=>{!e&&(ac(!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:an?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:ap,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:an?8:9,color:"#ef4444",cursor:"pointer",fontSize:an?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"]}),void 0!==B&&(0,d.jsx)("button",{onClick:B,title:z?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:an?28:32,height:an?28:32,padding:0,background:"none",border:"none",borderRadius:an?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 Z(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 $({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=Z(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=Z(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 _(a){return"object"==typeof a&&null!==a&&!Array.isArray(a)}function aa(a,b=220){if(!a)return;let c=a.trim();if(c)return c.length>b?`${c.slice(0,b)}...`:c}function ab(...a){for(let b of a)if("string"==typeof b&&b.trim())return b}function ac(...a){for(let b of a)if("number"==typeof b&&Number.isFinite(b))return b}function ad(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:aa(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(!_(b))return{...a,summary:aa(c)};let e=Array.isArray(b.results)?b.results.filter(_):[],f=e[0],g=f?.progressSummary,h=f&&(d=f.artifactPaths)?Object.values(d).filter(a=>"string"==typeof a&&a.trim().length>0):[],i=ab(f?.finalOutput,f?.output,c);return{...a,mode:ab(b.mode),runId:ab(b.runId),agent:ab(f?.agent,a.agent)??a.agent,task:ab(f?.task,a.task),summary:aa(i),model:ab(f?.model),durationMs:ac(g?.durationMs),toolCount:ac(g?.toolCount),tokens:ac(g?.tokens),outputPath:ab(f?.savedOutputPath,f?.artifactPaths?.outputPath),sessionFile:ab(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 _(b)&&Array.isArray(b.results)&&b.results.some(a=>_(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 ae({messages:a,runs:b}){let c=(0,e.useMemo)(()=>ad(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)(af,{title:`Active (${g.length})`,runs:g}),h.length>0&&(0,d.jsx)(af,{title:`Completed (${h.length})`,runs:h,compact:g.length>0})]})}function af({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)(ag,{run:a},a.id))]})}function ag({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)(ah,{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:aa(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)(ai,{run:a})]})]})}function ah({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 ai({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 aj({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 ak(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 al(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}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(a){if("user"!==a.role)return null;var b=a.content;if("string"==typeof b)return`text:${b}`;if(!Array.isArray(b))try{return`other:${JSON.stringify(b)}`}catch{return"other:"}let c=b.map(a=>{if(!a||"object"!=typeof a)return a;if("text"===a.type)return{type:"text",text:a.text};if("image"===a.type){let b=a.source&&"object"==typeof a.source?a.source:{};return{type:"image",mimeType:b.media_type??a.mimeType,data:b.data??a.data,url:b.url}}return a});try{return`blocks:${JSON.stringify(c)}`}catch{return"blocks:"}}function ao(a){if(!a.role)return null;try{return`${a.role}:${JSON.stringify(a)}`}catch{return null}}let ap=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function aq(a){return ap.some(b=>a.type.startsWith(b))}function ar({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.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 as(a){return a>=1e6?`${(a/1e6).toFixed(1)}M`:a>=1e3?`${(a/1e3).toFixed(1)}K`:String(a)}function at({goal:a,planTasks:b,isRunning:c,onExecutePlan:f}){let[g,h]=(0,e.useState)(!1),i=(0,e.useCallback)(()=>h(a=>!a),[]),j=a&&"dropped"!==a.status,k=b&&b.length>0;if(!j&&!k)return null;let l=(0,e.useMemo)(()=>!a?.tokenBudget||a.tokenBudget<=0?null:Math.min(100,Math.round(a.tokensUsed/a.tokenBudget*100)),[a?.tokenBudget,a?.tokensUsed]),m=b?.filter(a=>"completed"===a.status).length??0,n=!!b&&m===b.length;return(0,d.jsxs)("div",{style:{marginBottom:16,borderRadius:10,border:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"hidden"},children:[j&&(0,d.jsxs)("div",{style:{padding:"10px 14px",borderBottom:k?"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:[as(a.tokensUsed),a.tokenBudget?` / ${as(a.tokenBudget)} tokens`:" tokens"]}),null!=l&&(0,d.jsxs)("span",{children:[l,"%"]})]}),null!=l&&(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:l>=100?"rgba(239,68,68,0.6)":"rgba(37,99,235,0.5)",width:`${Math.min(l,100)}%`,transition:"width 0.3s"}})})]}),k&&(0,d.jsxs)("div",{style:{padding:"4px 14px 10px"},children:[(0,d.jsxs)("div",{onClick:i,role:"button",tabIndex:0,onKeyDown:a=>{("Enter"===a.key||" "===a.key)&&i()},"aria-expanded":!g,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," 步"]}),n&&(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:["已完成 ",m,"/",b.length]})]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[f&&n&&(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:g?"rotate(-90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:(0,d.jsx)("polyline",{points:"6 9 12 15 18 9"})})]})]}),!g&&(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 au=["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 av({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 aw({status:a}){let b=a?.current??"0.8.59"??"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 ax({session:a,newSessionCwd:b,onAgentEnd:c,onSessionCreated:f,onSessionForked:g,modelsRefreshKey:h,chatInputRef:i,onBranchDataChange:j,onSystemPromptChange:l,onSessionStatsChange:m,onContextUsageChange:n,onToolPresetActive:o,generativeUI:p}){var q;let r,[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)(!1),[w,x]=(0,e.useState)([]),{data:B,loading:H,error:J,messages:K,entryIds:L,streamState:M,agentRunning:N,modelNames:O,modelList:P,modelThinkingLevels:Q,modelThinkingLevelMaps:R,toolPreset:S,memoryTools:T,thinkingLevel:U,retryInfo:V,contextUsage:W,forkingEntryId:X,isCompacting:Z,compactError:_,displayModel:aa,sessionStats:ab,agentPhase:ac,agentError:af,isNew:ag,messagesEndRef:ah,scrollContainerRef:ai,lastUserMsgRef:ap,handleSend:as,handleAbort:ay,handleFork:az,handleNavigate:aA,handleModelChange:aB,handleCompact:aC,handleSteer:aD,handleFollowUp:aE,handleAbortCompaction:aF,handleToolPresetChange:aG,handleMemoryToolsChange:aH,handleThinkingLevelChange:aI,handleAgentEventRef:aJ}=function(a){let{session:b,newSessionCwd:c,onAgentEnd:d,onSessionCreated:f,onSessionForked:g,modelsRefreshKey:h,onBranchDataChange:i,onSystemPromptChange:j}=a,k=null===b&&null!==c,[l,m]=(0,e.useState)(null),[n,o]=(0,e.useState)(!k),[p,q]=(0,e.useState)(null),[r,s]=(0,e.useState)(null),[t,u]=(0,e.useState)([]),[v,w]=(0,e.useState)([]),[x,y]=(0,e.useReducer)(am,{isStreaming:!1,streamingMessage:null}),[B,H]=(0,e.useState)(!1),[J,K]=(0,e.useState)({}),[L,M]=(0,e.useState)([]),[N,O]=(0,e.useState)({}),[P,Q]=(0,e.useState)({}),[R,S]=(0,e.useState)(null),[T,U]=(0,e.useState)("full"),[V,W]=(0,e.useState)([...A]),[X,Y]=(0,e.useState)("auto"),[Z,$]=(0,e.useState)(null),[_,aa]=(0,e.useState)(null),[ab,ac]=(0,e.useState)(null),[ad,ae]=(0,e.useState)(null),[af,ag]=(0,e.useState)(null),[ah,ai]=(0,e.useState)(null),[aj,ap]=(0,e.useState)(!1),[aq,ar]=(0,e.useState)(null),[as,at]=(0,e.useState)(null),[au,av]=(0,e.useState)(null),aw=(0,e.useRef)(null),ax=(0,e.useRef)(b?.id??null),ay=(0,e.useRef)(!1),az=(0,e.useRef)(null),aA=(0,e.useRef)(!1),aB=(0,e.useRef)(null),aC=(0,e.useRef)(!1),aD=(0,e.useRef)(null),aE=(0,e.useRef)(null),aF=(0,e.useRef)(new Map),aG=(0,e.useRef)(new Set),aH=a.setNewSessionModel??S,aI=a.setToolPreset??U,aJ=a.setMemoryTools??W,aK=af??l?.context.model??ah??null,aL=k?R:aK,aM=(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
|
+
[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 Z=(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,cornerBadge:C,promptHistory:D,sessionHistoryKey:E},F){let G,H,I,[J,T]=(0,e.useState)(""),[U,V]=(0,e.useState)(!1),[W,X]=(0,e.useState)(null),[Z,$]=(0,e.useState)(!1),[_,aa]=(0,e.useState)(!1),[ab,ac]=(0,e.useState)(!1),[ad,ae]=(0,e.useState)(!1),[af,ag]=(0,e.useState)(!1),[ah,ai]=(0,e.useState)(null),[aj,ak]=(0,e.useState)([]),[al,am]=(0,e.useState)([]),an=function(a=768){let[b,c]=(0,e.useState)(!1);return b}(),ao=an?{display:"none"}:void 0,ap=an?28:32,aq=an?"6px 8px":"8px 12px",ar=an?160:180,as=an&&!g,at=af?"var(--text)":"var(--text-muted)",au={padding:"7px 8px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--border)",width:"100%",textAlign:"left",cursor:"pointer"},av=an?{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},[aw,ax]=(0,e.useState)(null),ay=(0,e.useRef)(null),az=(0,e.useRef)(null),aA=(0,e.useRef)(null),aB=(0,e.useRef)(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.useCallback)(a=>{let b=ay.current;if(!b)return void T(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")?"":" ";T(e+g+a+f),requestAnimationFrame(()=>{let b=ay.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)(F,()=>({insertIfEmpty(a){let b=ay.current;(b?b.value:J).trim()||(T(a),requestAnimationFrame(()=>{b&&(b.focus(),b.style.height="auto",b.style.height=`${Math.min(b.scrollHeight,200)}px`)}))},insertText(a){aI(a)},addImages(a){aJ(a)},addFiles(a){aK(a)}}));let aJ=(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)})));ak(a=>[...a,...c])},[]),aK=(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&&aJ(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 Y(a,c);b({data:c,fileName:a.name,mimeType:a.type||"application/octet-stream",size:a.size,...e})},d.onerror=c,d.readAsArrayBuffer(a)})));am(b=>[...b,...a])}},[aJ]),aL=(0,e.useCallback)(a=>{ak(b=>{let c=[...b];return URL.revokeObjectURL(c[a].previewUrl),c.splice(a,1),c})},[]),aM=(0,e.useCallback)(a=>{am(b=>{let c=[...b];return c.splice(a,1),c})},[]),aN=(0,e.useCallback)(()=>{ak(a=>(a.forEach(a=>URL.revokeObjectURL(a.previewUrl)),[])),am([])},[]),aO=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})),aP=[];for(let a of aO){let b=aP.find(b=>b.provider===a.provider);b?b.options.push(a):aP.push({provider:a.provider,options:[a]})}let aQ=h?aO.find(a=>a.modelId===h.modelId&&a.provider===h.provider)?.name??h.modelId:aO.length>0?aO[0].name:null,aR=h?aO.find(a=>a.modelId===h.modelId&&a.provider===h.provider):aO[0],aS=aR?.input?.includes("image")??!0,aT=aj.length>0&&aR?.input!==void 0&&!aS,aU=(!!J.trim()||aj.length>0||al.length>0)&&!aT,aV=l?R:R.filter(a=>"/compact"!==a.command),aW=aV.filter(a=>"native"===a.kind),aX=aV.filter(a=>"shortcut"===a.kind),aY=s??[],aZ=aY.length>0?`${aY.length} enabled`:"off",a$=aO.length>0&&!!aQ&&!!k,a_=!!v,a0=!!r&&"workbench"!==q,a1=aQ??"Default",a2=(()=>{let a=u??"auto";if("auto"===a||!x)return a;let b=x[a];return null!=b?b:a})(),a3=(p??"full")==="workbench"?"workbench":Object.entries(M).find(([,a])=>a===(p??"full"))?.[0]??"full",a4=an?26:32,a5=an?7:9,a6=an?3:6,a7={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)"},a8=an&&(U||Z||_||ab||ad||af);(0,e.useEffect)(()=>{aT||ax(null)},[aT]);let a9=(0,e.useCallback)(a=>{if(!J.trim()){T(a),requestAnimationFrame(()=>{let b=ay.current;b&&(b.focus(),b.setSelectionRange(a.length,a.length),b.style.height="auto",b.style.height=`${Math.min(b.scrollHeight,200)}px`)});return}aI(a)},[aI,J]),ba=(0,e.useCallback)(()=>{let b=J.trim();if(b||aj.length||al.length){if(aj.length&&!aS)return void ax("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");if(!g){if("/compact"===b&&!aj.length&&!al.length&&l){n?m?.():l(),T(""),ay.current&&(ay.current.style.height="auto");return}a(b,aj.length?aj:void 0,al.length?al:void 0),T(""),aN(),ay.current&&(ay.current.style.height="auto")}}},[J,aj,al,aS,g,a,aN,l,m,n]),bb=(0,e.useCallback)(a=>{let b=J.trim();if(!b&&!aj.length&&!al.length)return;if(aj.length&&!aS)return void ax("当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。");let d=aj.length?aj:void 0,e=al.length?al:void 0;"steer"===a&&c?c(b,d,e):"followup"===a&&f&&f(b,d,e),T(""),aN(),ay.current&&(ay.current.style.height="auto")},[J,aj,al,aS,c,f,aN]),bc=D??[],bd=E??null,be=(0,e.useCallback)(a=>{if("ArrowUp"===a.key&&!a.shiftKey&&!a.ctrlKey&&!a.metaKey&&bc.length>0){let b=ay.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=K.get(a))||(d={cursor:-1,draftSnapshot:""},K.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}(bd,b.value,bc);null!==d&&(T(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=K.get(a);return(b?.cursor??-1)>=0}(bd)){a.preventDefault();let b=function(a,b){if(!a)return null;let c=K.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}}(bd,bc);b&&(T(b.text),b.returnedToPresent&&requestAnimationFrame(()=>{let a=ay.current;a&&a.setSelectionRange(b.text.length,b.text.length)}));return}"Enter"===a.key&&!a.shiftKey&&!a.nativeEvent.isComposing&&(a.preventDefault(),bd&&K.set(bd,{cursor:-1,draftSnapshot:""}),g&&(c||f)?bb(c?"steer":"followup"):ba())},[g,c,f,bb,ba,bc,bd]),bf=(0,e.useCallback)(()=>{let a=ay.current;a&&(a.style.height="auto",a.style.height=`${Math.min(a.scrollHeight,200)}px`)},[]),bg=(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(),aK(b.map(a=>a.getAsFile()).filter(a=>null!==a)))},[aK]);return(0,e.useEffect)(()=>{if(!U&&!Z&&!_&&!ab&&!ad&&!af)return;let a=a=>{let b=a.target;if(!(b instanceof Node))return;let c=!!az.current?.contains(b),d=!!aA.current?.contains(b);c||d||V(!1),aB.current?.contains(b)||$(!1),aC.current?.contains(b)||aa(!1),aD.current?.contains(b)||ac(!1),aE.current?.contains(b)||ae(!1),aF.current?.contains(b)||ag(!1)};return document.addEventListener("pointerdown",a,!0),()=>{document.removeEventListener("pointerdown",a,!0)}},[U,Z,_,ab,ad,af]),(0,e.useEffect)(()=>{if(!r)return;let a=!1;return fetch("/api/subagents/status").then(a=>a.ok?a.json():null).then(b=>{a||ai(!!b?.ready)}).catch(()=>{a||ai(!1)}),()=>{a=!0}},[r]),(0,d.jsxs)("div",{style:av,children:[a8&&(0,d.jsx)("div",{"aria-hidden":!0,onClick:()=>{V(!1),$(!1),aa(!1),ac(!1),ae(!1),ag(!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:aG,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:a=>{aJ(Array.from(a.target.files??[])),a.target.value=""}}),(0,d.jsx)("input",{ref:aH,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=>{aK(Array.from(a.target.files??[])),a.target.value=""}}),(0,d.jsxs)("div",{style:{maxWidth:an?"100%":820,margin:"0 auto",position:"relative",width:"100%",padding:an?"0 8px":void 0,boxSizing:"border-box"},children:[C&&(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:C}),y&&(0,d.jsxs)("div",{style:{marginBottom:an?6:8,padding:an?"4px 8px":"5px 10px",background:"rgba(234,179,8,0.08)",border:"1px solid rgba(234,179,8,0.25)",borderRadius:6,fontSize:an?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]})]}),(aj.length>0||al.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:[aj.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 ${aT?"rgba(220,38,38,0.45)":"var(--border)"}`,display:"block"}}),(0,d.jsx)("button",{onClick:()=>aL(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}`)),al.map((a,b)=>(0,d.jsx)(S,{doc:a,onRemove:()=>aM(b)},`doc-${b}`))]}),(aT||aw)&&(0,d.jsxs)("div",{style:{marginTop:6,display:"flex",alignItems:"center",gap:6,fontSize:an?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:aw??"当前模型不支持图片输入。请切换到带 image 标记的模型后再发送。"})]})]}),(0,d.jsxs)("div",{style:{display:"flex",gap:an?4:8,alignItems:an?"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:an?13:14,padding:an?"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:ay,value:J,onChange:a=>T(a.target.value),onKeyDown:be,onInput:bf,onPaste:bg,placeholder:g&&(c||f)?"Steer 立即注入 / Follow-up 排队…":g?"Agent is running…":"Message…",rows:1,style:{flex:1,alignSelf:an?"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:+!!an,paddingBottom:+!!an}}),g?(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:an?4:6,flexShrink:0,alignSelf:"flex-end"},children:[c&&(0,d.jsxs)("button",{onClick:()=>bb("steer"),disabled:!aU,title:aT?"当前模型不支持图片输入":"打断 Agent 当前运行,立即注入消息",style:{display:"flex",alignItems:"center",gap:5*!an,padding:an?"6px 8px":"7px 12px",background:aU?"rgba(234,179,8,0.12)":"none",border:"1px solid rgba(234,179,8,0.35)",borderRadius:8,color:aU?"rgba(180,130,0,1)":"var(--text-dim)",cursor:aU?"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"})]}),!an&&"Steer"]}),f&&(0,d.jsxs)("button",{onClick:()=>bb("followup"),disabled:!aU,title:aT?"当前模型不支持图片输入":"在 Agent 完成后排队发送",style:{display:"flex",alignItems:"center",gap:5*!an,padding:an?"6px 8px":"7px 12px",background:aU?"rgba(129,140,248,0.12)":"none",border:"1px solid rgba(129,140,248,0.35)",borderRadius:8,color:aU?"rgba(99,102,241,1)":"var(--text-dim)",cursor:aU?"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"})]}),!an&&"Follow-up"]})]}):(0,d.jsxs)("button",{onClick:ba,disabled:!aU,title:aT?"当前模型不支持图片输入":"Send",style:{flexShrink:0,alignSelf:"flex-end",display:"flex",alignItems:"center",gap:an?3:6,padding:an?"5px 9px":"7px 14px",marginBottom:+!!an,background:aU?"var(--accent)":"var(--bg-panel)",border:"none",borderRadius:8,color:aU?"#fff":"var(--text-dim)",cursor:aU?"pointer":"not-allowed",fontSize:an?11:13,fontWeight:600,letterSpacing:"-0.01em",boxShadow:aU?"0 1px 3px rgba(37,99,235,0.25)":"none",transition:"background 0.15s, box-shadow 0.15s"},children:[(0,d.jsxs)("svg",{width:an?13:14,height:an?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:an?5:8,display:"flex",alignItems:an?"flex-start":"center",gap:a6,flexWrap:an?"wrap":"nowrap"},children:[(0,d.jsxs)("div",{className:"chat-input-toolbar-left",style:{flex:an?"1 1 100%":"0 0 auto",width:an?"100%":void 0,display:"flex",alignItems:"center",gap:2*!an,flexWrap:an?"wrap":"nowrap",rowGap:4*!!an},children:[(0,d.jsx)("button",{onClick:()=>aG.current?.click(),disabled:g,title:"Attach image (right-click for document)",style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:a4,height:a4,padding:0,background:"none",border:"none",borderRadius:a5,color:aj.length||al.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=aj.length||al.length?"var(--accent)":"var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background="none",a.currentTarget.style.color=aj.length||al.length?"var(--accent)":"var(--text-muted)"},onContextMenu:a=>{a.preventDefault(),aH.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:aB,style:{position:"relative"},children:[(0,d.jsxs)("button",{onClick:()=>{g||($(a=>!a),aa(!1),V(!1),ac(!1),ae(!1),ag(!1))},disabled:g,title:"插入斜杠命令",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:a4,height:a4,padding:0,background:Z?"var(--bg-hover)":"none",border:"none",borderRadius:a5,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=Z?"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"}})]}),Z&&(0,d.jsxs)("div",{style:{...an?a7:{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}),aW.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"}),aW.map(a=>(0,d.jsxs)("button",{onClick:()=>{($(!1),"/compact"===a.command&&n)?m?.():a9(a.command)},style:{display:"flex",alignItems:"center",gap:an?6:8,width:"100%",padding:aq,background:"none",border:"none",color:"/compact"===a.command&&n?"#ef4444":"var(--text-muted)",cursor:"pointer",fontSize:an?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))]}),aX.length>0&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{style:{marginTop:2*(aW.length>0),padding:"6px 10px 4px",fontSize:10,fontWeight:600,color:"var(--text-dim)",textTransform:"uppercase",letterSpacing:"0.07em",borderTop:aW.length>0?"1px solid var(--border)":"none"},children:"Prompt Shortcuts"}),aX.map(a=>(0,d.jsxs)("button",{onClick:()=>{$(!1),a9(a.command)},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:aq,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:an?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:aC,style:{position:"relative"},children:[(0,d.jsxs)("button",{onClick:()=>{g||(aa(a=>!a),$(!1),V(!1),ac(!1),ae(!1),ag(!1))},disabled:g,title:"选择 retain / recall / reflect",style:{position:"relative",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",width:38,height:ap,padding:0,background:_?"var(--bg-hover)":"none",border:"none",borderRadius:an?8:9,color:aY.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=aY.length>0?"var(--accent)":"var(--text)")},onMouseLeave:a=>{a.currentTarget.style.background=_?"var(--bg-hover)":"none",a.currentTarget.style.color=aY.length>0?"var(--accent)":"var(--text-muted)"},children:[" >_".trim(),aY.length>0&&(0,d.jsx)("span",{style:{position:"absolute",top:7,right:7,width:5,height:5,borderRadius:"50%",background:"currentColor"}})]}),_&&(0,d.jsxs)("div",{style:{...an?a7:{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"}),B.map(a=>{let b=aY.includes(a),c=O[a];return(0,d.jsxs)("button",{onClick:()=>{t(b?aY.filter(b=>b!==a):[...aY,a])},style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:aq,background:b?"var(--bg-selected)":"none",border:"none",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer",fontSize:an?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)})]})]}),a$&&(0,d.jsxs)("div",{ref:az,style:{position:"relative",flex:an?"1 1 160px":void 0,minWidth:0},children:[(0,d.jsxs)("button",{onClick:a=>{if(!an){let b=a.currentTarget.getBoundingClientRect();X({top:b.top,left:b.left,width:b.width})}$(!1),aa(!1),ac(!1),ae(!1),ag(!1),V(a=>!a)},disabled:g,style:{display:"flex",alignItems:"center",gap:6,padding:aq,height:ap,width:an?"100%":void 0,maxWidth:an?"100%":220,overflow:"hidden",background:U?"var(--bg-hover)":"none",border:"none",borderRadius:an?8:9,color:"var(--text-muted)",cursor:g?"not-allowed":"pointer",fontSize:an?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=U?"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:aQ})]}),U&&(an?(0,d.jsxs)("div",{ref:aA,style:{...a7,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:aQ})]}),(0,d.jsx)("div",{style:{overflowY:"auto"},children:aP.map((a,b)=>(0,d.jsxs)("div",{children:[aP.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:()=>{V(!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))})]}):W&&(H=(G=window.visualViewport?.height??window.innerHeight)-W.top+6,I=Math.max(120,Math.min(W.top-8,.6*G)),(0,d.jsx)("div",{ref:aA,style:{position:"fixed",bottom:H,left:W.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:W.width,maxHeight:I,overflowY:"auto"},children:aP.map((a,b)=>(0,d.jsxs)("div",{children:[aP.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:()=>{V(!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))})))]})]}),(0,d.jsx)("div",{className:"chat-input-toolbar-spacer",style:{display:as?"none":void 0,flex:an?"0 0 auto":1,width:an?0:void 0,height:an?0:void 0}}),(0,d.jsxs)("div",{className:"chat-input-toolbar-right",style:{flex:an?"1 1 100%":"0 0 auto",width:an?"100%":void 0,display:"flex",alignItems:"center",justifyContent:an?"space-between":void 0,gap:an?4:2,marginLeft:an?0:"auto",marginTop:2*!!an},children:[as&&(0,d.jsxs)("div",{ref:aF,style:{position:"relative"},children:[(0,d.jsx)("button",{onClick:()=>{$(!1),aa(!1),V(!1),ac(!1),ae(!1),ag(a=>!a)},title:"更多设置",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,padding:0,background:af?"var(--bg-hover)":"none",border:"none",borderRadius:8,color:at,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=af?"var(--bg-hover)":"none",a.currentTarget.style.color=af?"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"})]})}),af&&(0,d.jsxs)("div",{style:{...a7,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:[a$&&(0,d.jsxs)("button",{onClick:()=>{ag(!1),ae(!1),ac(!1),aa(!1),V(!0)},style:au,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:a1})]}),(a_||a0)&&(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:4},children:[a_&&(0,d.jsxs)("button",{onClick:()=>{ag(!1),V(!1),ac(!1),aa(!1),ae(!0)},style:au,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:a2})]}),a0&&(0,d.jsxs)("button",{onClick:()=>{ag(!1),V(!1),ae(!1),aa(!1),ac(!0)},style:au,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:a3})]})]}),!!t&&(0,d.jsxs)("button",{onClick:()=>{ag(!1),V(!1),ae(!1),ac(!1),aa(!0)},style:au,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:aY.length>0?"var(--accent)":"var(--text)",marginTop:2},children:aZ})]})]})]})]}),(!as&&!g||an&&ad)&&v&&(0,d.jsxs)("div",{ref:aE,style:{position:"relative"},children:[!as&&!g&&(0,d.jsxs)("button",{onClick:()=>{g||($(!1),aa(!1),V(!1),ac(!1),ag(!1),ae(a=>!a))},disabled:g,title:"切换推理强度",style:{display:"flex",alignItems:"center",gap:an?3:5,padding:aq,height:ap,background:ad?"var(--bg-hover)":"none",border:"none",borderRadius:an?8:9,color:"var(--text-muted)",cursor:g?"not-allowed":"pointer",fontSize:an?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=ad?"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:ao,children:(()=>{let a=u??"auto";if("auto"===a||!x)return a;let b=x[a];return null!=b?b:a})()})]}),ad&&(0,d.jsx)("div",{style:{...an?a7:{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:ar},overflow:"hidden"},children:P.filter(a=>!w||"auto"===a||w.includes(a)).map(a=>{let b=(u??"auto")===a,c=Q[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:()=>{ae(!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:an?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)})})]}),(!as&&!g||an&&ab)&&a0&&(0,d.jsxs)("div",{ref:aD,style:{position:"relative"},children:[!as&&!g&&(0,d.jsxs)("button",{onClick:()=>{g||($(!1),aa(!1),V(!1),ae(!1),ag(!1),ac(a=>!a))},disabled:g,title:"切换工具预设",style:{display:"flex",alignItems:"center",gap:an?3:5,padding:aq,height:ap,background:ab?"var(--bg-hover)":"none",border:"none",borderRadius:an?8:9,color:(p??"full")==="workbench"?"var(--accent)":"var(--text-muted)",cursor:g?"not-allowed":"pointer",fontSize:an?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=ab?"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:ao,children:a3})]}),ab&&(0,d.jsx)("div",{style:{...an?a7:{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:L.map(a=>{let b=M[a],c=(p??"full")===b,e="agent"===a&&!1===ah,f=e?"需安装 pi-subagents":N[a];return(0,d.jsxs)("button",{onClick:()=>{!e&&(ac(!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:an?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:ap,background:"rgba(239,68,68,0.08)",border:"1px solid rgba(239,68,68,0.3)",borderRadius:an?8:9,color:"#ef4444",cursor:"pointer",fontSize:an?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"]}),void 0!==A&&(0,d.jsx)("button",{onClick:A,title:z?"关闭完成提示音":"开启完成提示音",style:{display:"flex",alignItems:"center",justifyContent:"center",width:an?28:32,height:an?28:32,padding:0,background:"none",border:"none",borderRadius:an?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 $(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 _({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=$(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=$(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 aa(a){return"object"==typeof a&&null!==a&&!Array.isArray(a)}function ab(a,b=220){if(!a)return;let c=a.trim();if(c)return c.length>b?`${c.slice(0,b)}...`:c}function ac(...a){for(let b of a)if("string"==typeof b&&b.trim())return b}function ad(...a){for(let b of a)if("number"==typeof b&&Number.isFinite(b))return b}function ae(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:ab(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(!aa(b))return{...a,summary:ab(c)};let e=Array.isArray(b.results)?b.results.filter(aa):[],f=e[0],g=f?.progressSummary,h=f&&(d=f.artifactPaths)?Object.values(d).filter(a=>"string"==typeof a&&a.trim().length>0):[],i=ac(f?.finalOutput,f?.output,c);return{...a,mode:ac(b.mode),runId:ac(b.runId),agent:ac(f?.agent,a.agent)??a.agent,task:ac(f?.task,a.task),summary:ab(i),model:ac(f?.model),durationMs:ad(g?.durationMs),toolCount:ad(g?.toolCount),tokens:ad(g?.tokens),outputPath:ac(f?.savedOutputPath,f?.artifactPaths?.outputPath),sessionFile:ac(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 aa(b)&&Array.isArray(b.results)&&b.results.some(a=>aa(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 af({messages:a,runs:b}){let c=(0,e.useMemo)(()=>ae(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)(ag,{title:`Active (${g.length})`,runs:g}),h.length>0&&(0,d.jsx)(ag,{title:`Completed (${h.length})`,runs:h,compact:g.length>0})]})}function ag({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)(ah,{run:a},a.id))]})}function ah({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)(ai,{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:ab(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)(aj,{run:a})]})]})}function ai({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 aj({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 ak({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 al(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 am(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}function an(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 ao(a){if("user"!==a.role)return null;var b=a.content;if("string"==typeof b)return`text:${b}`;if(!Array.isArray(b))try{return`other:${JSON.stringify(b)}`}catch{return"other:"}let c=b.map(a=>{if(!a||"object"!=typeof a)return a;if("text"===a.type)return{type:"text",text:a.text};if("image"===a.type){let b=a.source&&"object"==typeof a.source?a.source:{};return{type:"image",mimeType:b.media_type??a.mimeType,data:b.data??a.data,url:b.url}}return a});try{return`blocks:${JSON.stringify(c)}`}catch{return"blocks:"}}function ap(a){if(!a.role)return null;try{return`${a.role}:${JSON.stringify(a)}`}catch{return null}}let aq=["image/","application/pdf","application/vnd.openxmlformats-officedocument","application/msword","application/vnd.ms-"];function ar(a){return aq.some(b=>a.type.startsWith(b))}function as({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.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 at(a){return a>=1e6?`${(a/1e6).toFixed(1)}M`:a>=1e3?`${(a/1e3).toFixed(1)}K`:String(a)}function au({goal:a,planTasks:b,isRunning:c,onExecutePlan:f}){let[g,h]=(0,e.useState)(!1),i=(0,e.useCallback)(()=>h(a=>!a),[]),j=a&&"dropped"!==a.status,k=b&&b.length>0;if(!j&&!k)return null;let l=(0,e.useMemo)(()=>!a?.tokenBudget||a.tokenBudget<=0?null:Math.min(100,Math.round(a.tokensUsed/a.tokenBudget*100)),[a?.tokenBudget,a?.tokensUsed]),m=b?.filter(a=>"completed"===a.status).length??0,n=!!b&&m===b.length;return(0,d.jsxs)("div",{style:{marginBottom:16,borderRadius:10,border:"1px solid var(--border)",background:"var(--bg-panel)",overflow:"hidden"},children:[j&&(0,d.jsxs)("div",{style:{padding:"10px 14px",borderBottom:k?"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:[at(a.tokensUsed),a.tokenBudget?` / ${at(a.tokenBudget)} tokens`:" tokens"]}),null!=l&&(0,d.jsxs)("span",{children:[l,"%"]})]}),null!=l&&(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:l>=100?"rgba(239,68,68,0.6)":"rgba(37,99,235,0.5)",width:`${Math.min(l,100)}%`,transition:"width 0.3s"}})})]}),k&&(0,d.jsxs)("div",{style:{padding:"4px 14px 10px"},children:[(0,d.jsxs)("div",{onClick:i,role:"button",tabIndex:0,onKeyDown:a=>{("Enter"===a.key||" "===a.key)&&i()},"aria-expanded":!g,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," 步"]}),n&&(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:["已完成 ",m,"/",b.length]})]}),(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0},children:[f&&n&&(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:g?"rotate(-90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:(0,d.jsx)("polyline",{points:"6 9 12 15 18 9"})})]})]}),!g&&(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 av=["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 aw({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 ax({status:a}){let b=a?.current??"0.8.61"??"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 ay({session:a,newSessionCwd:b,onAgentEnd:c,onSessionCreated:f,onSessionForked:g,modelsRefreshKey:h,chatInputRef:i,onBranchDataChange:j,onSystemPromptChange:k,onSessionStatsChange:m,onContextUsageChange:n,onToolPresetActive:o,generativeUI:p}){var q;let r,[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)(!1),[w,x]=(0,e.useState)([]),{data:y,loading:C,error:I,messages:K,entryIds:L,streamState:M,agentRunning:N,modelNames:O,modelList:P,modelThinkingLevels:Q,modelThinkingLevelMaps:R,toolPreset:S,memoryTools:T,thinkingLevel:U,retryInfo:V,contextUsage:W,forkingEntryId:X,isCompacting:Y,compactError:$,displayModel:aa,sessionStats:ab,agentPhase:ac,agentError:ad,isNew:ag,messagesEndRef:ah,scrollContainerRef:ai,lastUserMsgRef:aj,handleSend:aq,handleAbort:at,handleFork:az,handleNavigate:aA,handleModelChange:aB,handleCompact:aC,handleSteer:aD,handleFollowUp:aE,handleAbortCompaction:aF,handleToolPresetChange:aG,handleMemoryToolsChange:aH,handleThinkingLevelChange:aI,handleAgentEventRef:aJ}=function(a){let{session:b,newSessionCwd:c,onAgentEnd:d,onSessionCreated:f,onSessionForked:g,modelsRefreshKey:h,onBranchDataChange:i,onSystemPromptChange:j}=a,k=null===b&&null!==c,[l,m]=(0,e.useState)(null),[n,o]=(0,e.useState)(!k),[p,q]=(0,e.useState)(null),[r,s]=(0,e.useState)(null),[t,u]=(0,e.useState)([]),[v,w]=(0,e.useState)([]),[x,y]=(0,e.useReducer)(an,{isStreaming:!1,streamingMessage:null}),[z,C]=(0,e.useState)(!1),[I,K]=(0,e.useState)({}),[L,M]=(0,e.useState)([]),[N,O]=(0,e.useState)({}),[P,Q]=(0,e.useState)({}),[R,S]=(0,e.useState)(null),[T,U]=(0,e.useState)("full"),[V,W]=(0,e.useState)([...B]),[X,Y]=(0,e.useState)("auto"),[Z,$]=(0,e.useState)(null),[_,aa]=(0,e.useState)(null),[ab,ac]=(0,e.useState)(null),[ad,ae]=(0,e.useState)(null),[af,ag]=(0,e.useState)(null),[ah,ai]=(0,e.useState)(null),[aj,ak]=(0,e.useState)(!1),[aq,ar]=(0,e.useState)(null),[as,at]=(0,e.useState)(null),[au,av]=(0,e.useState)(null),aw=(0,e.useRef)(null),ax=(0,e.useRef)(b?.id??null),ay=(0,e.useRef)(!1),az=(0,e.useRef)(null),aA=(0,e.useRef)(!1),aB=(0,e.useRef)(null),aC=(0,e.useRef)(!1),aD=(0,e.useRef)(null),aE=(0,e.useRef)(null),aF=(0,e.useRef)(new Map),aG=(0,e.useRef)(new Set),aH=a.setNewSessionModel??S,aI=a.setToolPreset??U,aJ=a.setMemoryTools??W,aK=af??l?.context.model??ah??null,aL=k?R:aK,aM=(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}
|
|
8
8
|
${b}
|
|
9
9
|
${a.extractedText}`.trim()}return`${c}
|
|
10
|
-
[Text extraction unavailable: ${a.extractionError??"unsupported file type"}]`}).join("\n\n---\n\n"):"",[]),aN=(0,e.useCallback)(a=>{let b=
|
|
10
|
+
[Text extraction unavailable: ${a.extractionError??"unsupported file type"}]`}).join("\n\n---\n\n"):"",[]),aN=(0,e.useCallback)(a=>{let b=ao(a);if(!b)return;let c=aF.current;c.set(b,(c.get(b)??0)+1)},[]),aO=(0,e.useCallback)(a=>{let b=ao(a);if(!b)return!1;let c=aF.current,d=c.get(b)??0;return!(d<=0)&&(1===d?c.delete(b):c.set(b,d-1),!0)},[]),aP=(()=>{let a={input:0,output:0,cacheRead:0,cacheWrite:0},b=0;for(let c of t){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})(),aQ=(0,e.useCallback)(async(a,b=!1,c=!1)=>{try{b&&o(!0);let d=c?`/api/sessions/${encodeURIComponent(a)}?includeState`:`/api/sessions/${encodeURIComponent(a)}`,e=await fetch(d);if(ax.current&&ax.current!==a)return null;if(404===e.status)return b&&(m(null),s(null),u([]),q(null)),null;if(!e.ok)throw Error(`HTTP ${e.status}`);let f=await e.json();return m(f),s(f.leafId),u(f.context.messages),w(f.context.entryIds??[]),aF.current.clear(),aG.current=new Set(f.context.messages.map(ap).filter(a=>!!a)),ag(null),q(null),!f.agentState?.state?.thinkingLevel&&f.context.thinkingLevel&&"off"!==f.context.thinkingLevel&&Y(f.context.thinkingLevel),f.agentState??null}catch(a){return q(String(a)),null}finally{b&&o(!1)}},[]),aR=(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();u(e.context.messages),w(e.context.entryIds??[]),aF.current.clear()}catch(a){console.error("Failed to load context:",a)}},[]),aS=(0,e.useCallback)(async a=>{try{let b=await am(a,{type:"get_tools"});if(b){let a,c,d,e;aI((c=(a=b.filter(a=>a.active).map(a=>a.name)).filter(a=>!B.includes(a)),d=H(a),e=H(c),""===d?"none":d===H(D)?"default":d===H(E)?"full":d===H(F)?"workbench":d===H(G)?"agent":""===e?"none":e===H(D)?"default":e===H(E)?"full":e===H(F)?"workbench":e===H(G)||a.includes(A)?"agent":"default")),aJ(B.filter(a=>b.some(b=>b.active&&b.name===a)))}}catch(a){console.error("Failed to load tools:",a)}},[aJ,aI]),aT=(0,e.useCallback)((a,b={})=>{aw.current&&(aw.current.close(),aw.current=null);let c=new EventSource(`/api/agent/${encodeURIComponent(a)}/events${b.replay?"?replay=1":""}`);aw.current=c,c.onmessage=a=>{try{let b=JSON.parse(a.data);az.current?.(b)}catch{}},c.onerror=()=>{aw.current===c&&ay.current&&(c.close(),aw.current=null,setTimeout(()=>{ay.current&&aT(a)},1e3))}},[]);az.current=(0,e.useCallback)(a=>{switch(a.type){case"agent_start":av(null),C(!0),at({kind:"waiting_model"}),y({type:"start"});break;case"agent_end":ay.current=!1,aw.current?.close(),aw.current=null,C(!1),at(null),$(null),y({type:"end"}),ax.current&&(aQ(ax.current),fetch(`/api/agent/${encodeURIComponent(ax.current)}`).then(a=>a.json()).then(a=>{!1===a.running&&(C(!1),at(null),y({type:"end"})),a.state?.contextUsage!==void 0&&aa(a.state.contextUsage??null),a.state?.systemPrompt!==void 0&&ac(a.state.systemPrompt??null),a.state?.isCompacting!==void 0&&ak(a.state.isCompacting)}).catch(()=>{})),d?.();break;case"message_start":case"message_update":{let b=a.message;if(b){let a=al(b);aG.current.has(ap(a)??"")||y({type:"update",message:a})}at(null);break}case"message_end":{let b=a.message;if(b){let a=al(b),c=ap(a),d=!!c&&aG.current.has(c);c&&aG.current.add(c),d||"user"===a.role&&aO(a)||u(b=>[...b,a])}y({type:"reset"}),at({kind:"waiting_model"});break}case"tool_execution_start":{let b=a.toolCallId,c=a.toolName;at(a=>{let d=a?.kind==="running_tools"?[...a.tools]:[];return d.some(a=>a.id===b)||d.push({id:b,name:c}),{kind:"running_tools",tools:d}});break}case"tool_execution_end":{let b=a.toolCallId;at(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":$({attempt:a.attempt,maxAttempts:a.maxAttempts,errorMessage:a.errorMessage});break;case"auto_retry_end":$(null);break;case"auto_compaction_start":case"compaction_start":ak(!0),ar(null);break;case"auto_compaction_end":case"compaction_end":ak(!1),a.errorMessage?ar(a.errorMessage):!a.aborted&&ax.current&&aQ(ax.current)}},[aO,aQ,d]);let aU=(0,e.useCallback)(async(a,d,e)=>{if(!a.trim()&&!d?.length&&!e?.length||z)return;let g=aM(e),h=a.trim()?g?`${a}
|
|
11
11
|
|
|
12
12
|
Attached document text:
|
|
13
13
|
|
|
14
14
|
${g}`:a:g?`Attached document text:
|
|
15
15
|
|
|
16
|
-
${g}`:"",i=d?.map(a=>({type:"image",source:{type:"base64",media_type:a.mimeType,data:a.data}})),j={role:"user",content:i?.length?[...h.trim()?[{type:"text",text:h}]:[],...i]:h,timestamp:Date.now()};aN(j),u(a=>[...a,j]),av(null),
|
|
16
|
+
${g}`:"",i=d?.map(a=>({type:"image",source:{type:"base64",media_type:a.mimeType,data:a.data}})),j={role:"user",content:i?.length?[...h.trim()?[{type:"text",text:h}]:[],...i]:h,timestamp:Date.now()};aN(j),u(a=>[...a,j]),av(null),C(!0),at({kind:"waiting_model"}),y({type:"start"}),aC.current=!0;let l=d?.map(a=>({type:"image",data:a.data,mimeType:a.mimeType}));try{if(k&&c){R&&ai(R);let b=J(T,V),d=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:c,type:"prompt",message:h,toolNames:b,...l?.length?{images:l}:{},...R?{provider:R.provider,modelId:R.modelId}:{},..."auto"!==X?{thinkingLevel:X}:{}})}),e=await d.json().catch(()=>({}));if(!d.ok||e.error||!e.sessionId)throw Error(e.error??`HTTP ${d.status}`);let g=e.sessionId;ax.current=g,aT(g,{replay:!0}),f?.({id:g,path:"",cwd:c,name:void 0,created:new Date().toISOString(),modified:new Date().toISOString(),messageCount:1,firstMessage:a})}else if(b){let a=J(T,V);aT(b.id),await am(b.id,{type:"prompt",message:h,toolNames:a,...l?.length?{images:l}:{}})}}catch(a){aO(j),console.error("Failed to send message:",a),av(a instanceof Error?a.message:String(a)),C(!1),at(null),y({type:"end"})}},[k,c,R,T,V,X,b,z,aT,f,aM,aO,aN]),aV=(0,e.useCallback)(async()=>{let a=ax.current;if(a){ay.current=!1,av(null),C(!1),at(null),y({type:"end"}),aw.current?.close(),aw.current=null;try{await am(a,{type:"abort"}),await aQ(a)}catch(b){console.error("Failed to abort:",b),await aQ(a)}}},[aQ]),aW=(0,e.useCallback)(async a=>{let b=ax.current;if(b){ae(a);try{let{cancelled:c,newSessionId:d}=await am(b,{type:"fork",entryId:a})??{};!c&&d&&g?.(d)}catch(a){console.error("Fork failed:",a)}finally{ae(null)}}},[g]),aX=(0,e.useCallback)(async a=>{let b=ax.current;b&&(am(b,{type:"navigate_tree",targetId:a}).catch(()=>{}),s(a),await aR(b,a))},[aR]);(0,e.useCallback)(async a=>{s(a);let b=ax.current;b&&(await aR(b,a),a&&am(b,{type:"navigate_tree",targetId:a}).catch(()=>{}))},[aR]);let aY=(0,e.useCallback)(async(a,b)=>{if(k)return void aH({provider:a,modelId:b});let c=ax.current;if(c)try{await am(c,{type:"set_model",provider:a,modelId:b}),ag({provider:a,modelId:b})}catch(a){console.error("Failed to set model:",a)}},[k,aH]),aZ=(0,e.useCallback)(async()=>{let a=ax.current;if(a&&!aj){ak(!0),ar(null);try{await am(a,{type:"compact"}),await aQ(a,!0)}catch(a){ar(a instanceof Error?a.message:String(a))}finally{ak(!1)}}},[aj,aQ]),a$=(0,e.useCallback)(async(a,b,c)=>{let d=ax.current;if(!d)return;let e=aM(c),f=a.trim()?e?`${a}
|
|
17
17
|
|
|
18
18
|
Attached document text:
|
|
19
19
|
|
|
20
20
|
${e}`:a:e?`Attached document text:
|
|
21
21
|
|
|
22
|
-
${e}`:"",g={role:"user",content:`[steer] ${f}`,timestamp:Date.now()};aN(g),u(a=>[...a,g]);let h=b?.map(a=>({type:"image",data:a.data,mimeType:a.mimeType}));try{await
|
|
22
|
+
${e}`:"",g={role:"user",content:`[steer] ${f}`,timestamp:Date.now()};aN(g),u(a=>[...a,g]);let h=b?.map(a=>({type:"image",data:a.data,mimeType:a.mimeType}));try{await am(d,{type:"steer",message:f,...h?.length?{images:h}:{}})}catch(a){aO(g),console.error("Failed to steer:",a)}},[aM,aO,aN]),a_=(0,e.useCallback)(async(a,b,c)=>{let d=ax.current;if(!d)return;let e=aM(c),f=a.trim()?e?`${a}
|
|
23
23
|
|
|
24
24
|
Attached document text:
|
|
25
25
|
|
|
26
26
|
${e}`:a:e?`Attached document text:
|
|
27
27
|
|
|
28
|
-
${e}`:"",g={role:"user",content:f,timestamp:Date.now()};aN(g),u(a=>[...a,g]);let h=b?.map(a=>({type:"image",data:a.data,mimeType:a.mimeType}));try{await al(d,{type:"follow_up",message:f,...h?.length?{images:h}:{}})}catch(a){aO(g),console.error("Failed to follow up:",a)}},[aM,aO,aN]),a0=(0,e.useCallback)(async()=>{let a=ax.current;if(a)try{await al(a,{type:"abort_compaction"})}catch(a){console.error("Failed to abort compaction:",a)}},[]),a1=(0,e.useCallback)(async a=>{if(Y(a),"auto"===a)return;let b=ax.current;if(b)try{await al(b,{type:"set_thinking_level",level:a})}catch(a){console.error("Failed to set thinking level:",a)}},[]),a2=(0,e.useCallback)(async a=>{aI(a);let b=I(a,V),c=ax.current;if(c)try{await al(c,{type:"set_tools",toolNames:b})}catch(a){console.error("Failed to set tools:",a)}},[V,aI]),a3=(0,e.useCallback)(async a=>{aJ(a);let b=I(T,a),c=ax.current;if(c)try{await al(c,{type:"set_tools",toolNames:b})}catch(a){console.error("Failed to set memory tools:",a)}},[aJ,T]);return(0,e.useCallback)((a="smooth")=>{aD.current?.scrollIntoView({behavior:a})},[]),(0,e.useCallback)(()=>{let a=aE.current,b=aB.current;if(!a||!b)return;let c=b.getBoundingClientRect().top-a.getBoundingClientRect().top+a.scrollTop;a.scrollTo({top:c-16,behavior:"smooth"})},[]),{data:l,loading:n,error:p,activeLeafId:r,messages:t,entryIds:v,streamState:x,agentRunning:B,modelNames:J,modelList:L,modelThinkingLevels:N,modelThinkingLevelMaps:P,newSessionModel:R,toolPreset:T,memoryTools:V,thinkingLevel:X,retryInfo:Z,contextUsage:_,systemPrompt:ab,forkingEntryId:ad,isCompacting:aj,compactError:aq,currentModel:aK,displayModel:aL,sessionStats:aP,agentPhase:as,agentError:au,isNew:k,sessionIdRef:ax,eventSourceRef:aw,messagesEndRef:aD,scrollContainerRef:aE,lastUserMsgRef:aB,pendingScrollToUserRef:aC,initialScrollDoneRef:aA,handleSend:aU,handleAbort:aV,handleFork:aW,handleNavigate:aX,handleModelChange:aY,handleCompact:aZ,handleSteer:a$,handleFollowUp:a_,handleAbortCompaction:a0,handleToolPresetChange:a2,handleMemoryToolsChange:a3,handleThinkingLevelChange:a1,loadTools:aS,setActiveLeafId:s,setData:m,setMessages:u,dispatch:y,setAgentRunning:H,setForkingEntryId:ae,handleAgentEventRef:az}}({session:a,newSessionCwd:b,onAgentEnd:c,onSessionCreated:f,onSessionForked:g,modelsRefreshKey:h,onBranchDataChange:j,onSystemPromptChange:l}),{soundEnabled:aK,onSoundToggle:aL,playDoneSound:aM}=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,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)(aM).current=aM,(0,e.useRef)(aK).current=aK,aJ.current,ab&&(ab.tokens.input,ab.tokens.output,ab.tokens.cacheRead,ab.tokens.cacheWrite,ab.cost),(0,e.useRef)(ab).current=ab,W&&(W.percent,W.contextWindow,W.tokens),(0,e.useRef)(W).current=W;let{isDragOver:aN,handleDragEnter:aO,handleDragOver:aP,handleDragLeave:aQ,handleDrop:aR}=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(aq)&&(a.preventDefault(),d.current+=1,c(!0))},[]),g=(0,e.useCallback)(a=>{Array.from(a.dataTransfer.items).some(aq)&&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])}}((0,e.useCallback)(a=>{i?.current?.addFiles(a)},[i])),[aS,aT]=(0,e.useState)(null),aU=K.filter(a=>"user"===a.role||"assistant"===a.role),aV=(q=aU.length,(r=(0,e.useRef)([])).current=Array(q).fill(null).map((a,b)=>r.current[b]??null),r),aW=(0,e.useMemo)(()=>{let a=new Map;for(let b of K)"toolResult"===b.role&&a.set(b.toolCallId,b);return a},[K]),aX=ag&&0===K.length&&!M.isStreaming&&!N,aY=B?.info?.cwd??a?.cwd??b??null,aZ=function(a){if(!a)return null;let b=a.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean);return b[b.length-1]||a}(aY),a$=function(a=768){let[b,c]=(0,e.useState)(!1);return b}(),[a_,a0]=(0,e.useState)(!1),[a1,a2]=(0,e.useState)(!1),a3=ad(K),a4=a3.filter(a=>"running"===a.status).length,a5=(0,e.useCallback)(()=>{a?.id&&!N&&(async()=>{await aG("workbench");let a=B?.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 as(b)}})()},[N,B?.sessionMeta,as,aG,a?.id]),a6=aa?Q[`${aa.provider}:${aa.modelId}`]??null:null,a7=aa?R[`${aa.provider}:${aa.modelId}`]??null:null,a8=B?.sessionMeta?.sessionKind??null,a9=a?.id??b??"new-chat",ba=(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})(aU.map(a=>({role:a.role,text:"string"==typeof a.content?a.content:""}))),[aU]),bb=(0,e.useCallback)(async(a,b,c)=>{"/plan"===a.trim()||a.trim().startsWith("/plan ")?v(a=>!a):await as(a,b,c)},[as]),bc=(0,d.jsx)(Y,{ref:i,onSend:bb,onAbort:ay,onSteer:N?aD:void 0,onFollowUp:N?aE:void 0,isStreaming:N,model:aa,modelNames:O,modelList:P,onModelChange:aB,onCompact:a||ag?aC:void 0,onAbortCompaction:aF,isCompacting:Z,compactError:_,toolPreset:S,sessionKind:a8,onToolPresetChange:a||ag?aG:void 0,memoryTools:T,onMemoryToolsChange:a||ag?aH:void 0,thinkingLevel:U,onThinkingLevelChange:a||ag?aI:void 0,availableThinkingLevels:a6,thinkingLevelMap:a7,retryInfo:V,soundEnabled:aK,onSoundToggle:aL,cornerBadge:aX?(0,d.jsx)(aw,{status:aS}):void 0,promptHistory:ba,sessionHistoryKey:a9}),bd=(0,e.useCallback)(a=>{N?i?.current?.insertText(a):as(a)},[N,i,as]);return H?(0,d.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:"Loading session..."}):J?(0,d.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:J}):(0,d.jsxs)("div",{className:"relative flex h-full flex-col overflow-hidden",onDragEnter:aO,onDragOver:aP,onDragLeave:aQ,onDrop:aR,children:[aN&&(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"})]})]})]}),!a1&&(0,d.jsx)(aj,{sessionKind:a8,toolPreset:S,initialSourcePath:B?.sessionMeta?.initialSourcePath??null,initialKernel:B?.sessionMeta?.initialKernel??null,isNew:ag,isStreaming:N,onResume:a5,onDismiss:()=>a2(!0)}),aX?(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:[aZ&&(0,d.jsxs)("div",{style:{padding:a$?"7px 9px":"9px 12px",border:"1px solid var(--border)",borderRadius:a$?9:10,background:"linear-gradient(180deg, var(--bg-panel), rgba(127,127,127,0.03))",minWidth:0,display:"flex",alignItems:"flex-start",gap:a$?8:10,boxShadow:a$?"0 2px 10px rgba(0,0,0,0.04)":"none"},children:[(0,d.jsx)("div",{"aria-hidden":!0,style:{flex:"0 0 auto",width:a$?18:20,height:a$?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:a$?12.5:14,color:"var(--text)",fontWeight:700,lineHeight:1.3,wordBreak:"break-word"},children:aZ}),aY&&(0,d.jsx)("div",{title:aY,style:{fontSize:10.5,color:"var(--text-dim)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:aY})]})]}),(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:k}),(0,d.jsx)("span",{style:{fontSize:14,minWidth:0,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:(0,d.jsx)(av,{phrases:au})})]})]}),bc]})}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{className:"relative flex flex-1 overflow-hidden",children:[(0,d.jsx)("div",{ref:ai,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:a$?{paddingBottom:"calc(env(safe-area-inset-bottom, 0px) + 128px)"}:void 0,children:[(0,d.jsx)(at,{goal:B?.sessionMeta?.goal??null,planTasks:w,isRunning:N}),(()=>{let c=-1;for(let a=K.length-1;a>=0;a--)if("user"===K[a].role){c=a;break}let e=0;return K.map((f,g)=>{let h="user"===f.role&&g>0&&"assistant"===K[g-1].role?L[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<K.length;a++){let b=K[a].role;if("user"===b)break;if("assistant"===b){l=!1;break}}l&&M.isStreaming&&g===K.length-1&&(l=!1)}let m=(0,d.jsx)(y.D,{message:f,toolResults:aW,modelNames:O,entryId:L[g],onFork:N||ag||0===g&&"user"===f.role?void 0:az,forking:X===L[g],onNavigate:N?void 0:aA,prevAssistantEntryId:N?void 0:h,onEditContent:a=>i?.current?.insertIfEmpty(a),onSendMessage:bd,showTimestamp:l,prevTimestamp:g>0?K[g-1].timestamp:void 0,renderVisualCodeBlocks:!!p,cwd:B?.info?.cwd??a?.cwd??b??void 0},g);return j?(0,d.jsx)("div",{ref:a=>{aV.current[k]=a,g===c&&(ap.current=a)},children:m},g):m})})(),N&&(0,d.jsx)(ar,{agentPhase:ac,startedAt:s}),M.isStreaming&&M.streamingMessage&&(0,d.jsx)(y.D,{message:M.streamingMessage,isStreaming:!0,toolResults:aW,modelNames:O,onSendMessage:bd,renderVisualCodeBlocks:!!p,cwd:B?.info?.cwd??a?.cwd??b??void 0}),N&&!M.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..."}(ac)})}),B?.info?.cwd&&!1===B.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:B.info.cwd})]}),af&&(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:af}),N&&(0,d.jsx)("div",{style:{height:ai.current?ai.current.clientHeight:"80vh"}}),(0,d.jsx)("div",{ref:ah})]})}),!a$&&(0,d.jsx)($,{messages:K,streamingMessage:M.streamingMessage,scrollContainer:ai,messageRefs:aV}),a3.length>0&&(0,d.jsxs)("button",{onClick:()=>a0(a=>!a),title:a_?"Hide subagent runs":"Show subagent runs",style:{position:"absolute",right:a$?8:a_?260:40,top:8,minWidth:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:a4>0||a3.length>1?"0 8px":0,background:a_?"var(--bg-selected)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:a_?"var(--accent)":"var(--text-dim)",cursor:"pointer",zIndex:30,fontSize:12,transition:"right 0.2s ease, background 0.12s"},onMouseEnter:a=>{a_||(a.currentTarget.style.color="var(--text)")},onMouseLeave:a=>{a_||(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"})]}),(a4>0||a3.length>1)&&(0,d.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,fontSize:10,fontWeight:700,color:a4>0?"var(--accent)":"var(--text-dim)"},children:[a4>0&&(0,d.jsxs)("span",{children:[a4," active"]}),(0,d.jsx)("span",{children:a3.length})]})]}),a_&&a3.length>0&&(0,d.jsxs)("div",{style:{position:"absolute",right:a$?8:48,top:4,bottom:4,width:a$?"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)(ae,{runs:a3})]})]}),(0,d.jsx)("div",{className:"relative",children:bc})]})]})}var ay=c(90707),az=c(52515);class aA 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)(az.fj,{style:{background:"var(--bg)"},children:(0,d.jsx)(az.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 aB(a,b,c){return Math.min(Math.max(a,b),c)}function aC({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:aB(c,8,Math.max(8,window.innerWidth-120)),top:aB(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:aB(c,360,Math.max(360,window.innerWidth-a.left-8)),height:aB(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:aD,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:aD,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)(aA,{filePath:b,children:(0,d.jsx)(ay.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 aD={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},aE="var(--text-dim)";function aF({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:aE}),(0,d.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:aE,strokeWidth:"1",fill:aE,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:aE,strokeWidth:"1",fill:aE,fillOpacity:"0.1"})})}function aG({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:aE,strokeWidth:"1",fill:aE,fillOpacity:"0.08"}),(0,d.jsx)("path",{d:"M10 2v3h3",stroke:aE,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function aH({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:aE,strokeWidth:"0.9",fill:aE,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aE,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:aE,letterSpacing:"0",children:a})]})}function aI({size:a=14}){return(0,d.jsx)(aH,{label:"TS",size:a})}function aJ({size:a=14}){return(0,d.jsx)(aH,{label:"TSX",size:a})}function aK({size:a=14}){return(0,d.jsx)(aH,{label:"JS",size:a})}function aL({size:a=14}){return(0,d.jsx)(aH,{label:"JSX",size:a})}function aM({size:a=14}){return(0,d.jsx)(aH,{label:"PY",size:a})}function aN({size:a=14}){return(0,d.jsx)(aH,{label:"{}",size:a})}function aO({size:a=14}){return(0,d.jsx)(aH,{label:"CSS",size:a})}function aP({size:a=14}){return(0,d.jsx)(aH,{label:"SC",size:a})}function aQ({size:a=14}){return(0,d.jsx)(aH,{label:"HTM",size:a})}function aR({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:aE,strokeWidth:"0.9",fill:aE,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aE,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:aE,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,d.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:aE,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function aS({size:a=14}){return(0,d.jsx)(aH,{label:"YML",size:a})}function aT({size:a=14}){return(0,d.jsx)(aH,{label:"TOM",size:a})}function aU({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:aE,strokeWidth:"0.9",fill:aE,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aE,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:aE,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,d.jsx)("path",{d:"M7.5 10.5h2.5",stroke:aE,strokeWidth:"0.95",strokeLinecap:"round"})]})}function aV({size:a=14}){return(0,d.jsx)(aH,{label:"RS",size:a})}function aW({size:a=14}){return(0,d.jsx)(aH,{label:"GO",size:a})}function aX({size:a=14}){return(0,d.jsx)(aH,{label:"SQL",size:a})}function aY({size:a=14}){return(0,d.jsx)(aH,{label:"GQL",size:a})}function aZ({size:a=14}){return(0,d.jsx)(aH,{label:"TF",size:a})}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:aE,strokeWidth:"0.9",fill:aE,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aE,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:aE,strokeWidth:"0.8"}),(0,d.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:aE,strokeWidth:"0.8"}),(0,d.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:aE,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:aE,strokeWidth:"0.9",fill:aE,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aE,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:aE,strokeWidth:"0.9"}),(0,d.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:aE,strokeWidth:"0.9",strokeLinecap:"round"})]})}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:aE,strokeWidth:"0.9",fill:aE,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aE,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:aE,strokeWidth:"0.85"}),(0,d.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:aE,strokeWidth:"0.85"}),(0,d.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:aE,strokeWidth:"0.85"}),(0,d.jsx)("path",{d:"M5 7.5V9",stroke:aE,strokeWidth:"0.85",strokeLinecap:"round"}),(0,d.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:aE,strokeWidth:"0.85",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:aE,strokeWidth:"0.9",fill:aE,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aE,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:aE,strokeWidth:"0.9"}),(0,d.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:aE,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}function a2({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:aE,strokeWidth:"0.9",fill:aE,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aE,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:aE,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:aE,strokeWidth:"0.8",strokeLinecap:"round"})]})}function a3(a,b=14){let c=a.toLowerCase(),e=c.split(".").pop()??"";if("dockerfile"===c||c.startsWith("dockerfile."))return(0,d.jsx)(a$,{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)(a0,{size:b});if("package-lock.json"===c||"yarn.lock"===c||"bun.lock"===c||"pnpm-lock.yaml"===c||"cargo.lock"===c)return(0,d.jsx)(a1,{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)(a2,{size:b});switch(e){case"ts":return(0,d.jsx)(aI,{size:b});case"tsx":return(0,d.jsx)(aJ,{size:b});case"js":case"mjs":case"cjs":return(0,d.jsx)(aK,{size:b});case"jsx":return(0,d.jsx)(aL,{size:b});case"py":return(0,d.jsx)(aM,{size:b});case"json":case"jsonl":return(0,d.jsx)(aN,{size:b});case"css":case"less":return(0,d.jsx)(aO,{size:b});case"scss":return(0,d.jsx)(aP,{size:b});case"html":case"htm":return(0,d.jsx)(aQ,{size:b});case"md":case"mdx":return(0,d.jsx)(aR,{size:b});case"yaml":case"yml":return(0,d.jsx)(aS,{size:b});case"toml":return(0,d.jsx)(aT,{size:b});case"sh":case"bash":case"zsh":case"fish":return(0,d.jsx)(aU,{size:b});case"rs":return(0,d.jsx)(aV,{size:b});case"go":return(0,d.jsx)(aW,{size:b});case"sql":return(0,d.jsx)(aX,{size:b});case"graphql":case"gql":return(0,d.jsx)(aY,{size:b});case"tf":case"hcl":return(0,d.jsx)(aZ,{size:b});case"lock":return(0,d.jsx)(a1,{size:b});default:return(0,d.jsx)(aG,{size:b})}}var a4=c(31343);async function a5(a){let b=(0,a4.HG)(a),c=await fetch(`/api/files/${b}?type=list`);return c.ok?((await c.json()).entries??[]).map(b=>({name:b.name,fullPath:(0,a4.e_)(a,b.name),isDir:b.isDir,size:b.size,children:b.isDir?[]:void 0,loaded:!b.isDir})):[]}function a6(a,b){let c=b.trim().toLowerCase();return!!(!c||a.name.toLowerCase().includes(c))||(a.children??[]).some(a=>a6(a,c))}function a7(a){return!!Array.from(a.types).includes("Files")||Array.from(a.items).some(a=>"file"===a.kind)}function a8(a){return Array.from(a.files).filter(a=>!!a.name)}function a9(a,b){return a===b?".":(0,a4.qP)(a,b)}function ba({node:a,depth:b,cwd:c,onOpenFile:f,onExploreFile:g,onAtMention:h,expandedPaths:i,onToggleExpanded:j,onUploadFiles:k,uploadTargetPath:l,refreshKey:m,searchQuery:n}){let o=!!n?.trim(),p=o?a.isDir:i.has(a.fullPath),[q,r]=(0,e.useState)(a.children??[]),[s,t]=(0,e.useState)(a.loaded??!1),[u,v]=(0,e.useState)(!1),[w,x]=(0,e.useState)(!1),[y,z]=(0,e.useState)(!1),A=a.isDir&&(y||l===a.fullPath),B=!!h&&w,C=!!g&&w&&!a.isDir&&a.name.toLowerCase().endsWith(".h5ad"),D=B||C,E=o?q.filter(a=>a6(a,n??"")):q,F=(0,e.useCallback)(async(b=!1)=>{if(!s||b){v(!0);try{let b=await a5(a.fullPath);r(b),t(!0)}catch{}finally{v(!1)}}},[s,a.fullPath]);(0,e.useRef)(s);let G=(0,e.useCallback)(()=>{if(a.isDir){let b=!p;j(a.fullPath,b),b&&!s&&F()}else f(a.fullPath,a.name)},[a.isDir,a.fullPath,a.name,s,p,F,f,j]),H=(0,e.useCallback)(b=>{a.isDir&&a7(b.dataTransfer)&&(b.preventDefault(),b.stopPropagation(),b.dataTransfer.dropEffect="copy",z(!0))},[a.isDir]),I=(0,e.useCallback)(b=>{a.isDir&&a7(b.dataTransfer)&&(b.preventDefault(),b.stopPropagation(),b.dataTransfer.dropEffect="copy")},[a.isDir]),J=(0,e.useCallback)(b=>{if(!a.isDir)return;let c=b.relatedTarget;c instanceof Node&&b.currentTarget.contains(c)||z(!1)},[a.isDir]),K=(0,e.useCallback)(b=>{if(!a.isDir||!a7(b.dataTransfer))return;b.preventDefault(),b.stopPropagation(),z(!1);let c=a8(b.dataTransfer);c.length>0&&(k(c,a.fullPath),p||j(a.fullPath,!0),s||F())},[F,s,a.fullPath,a.isDir,j,k,p]);return(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{onClick:G,onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),onDragEnter:H,onDragOver:I,onDragLeave:J,onDrop:K,style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*b,paddingRight:D?B&&C?146:82:8,height:24,cursor:"pointer",background:A?"rgba(37,99,235,0.14)":w?"var(--bg-hover)":"transparent",outline:A?"1px solid rgba(37,99,235,0.42)":"none",outlineOffset:-1,borderRadius:4,userSelect:"none",transition:"background 0.12s, outline-color 0.12s"},children:[a.isDir&&(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:p?"rotate(90deg)":"none",transition:"transform 0.1s"},children:(0,d.jsx)("polyline",{points:"3 2 7 5 3 8"})}),!a.isDir&&(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),(0,d.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:a.isDir?(0,d.jsx)(aF,{size:14,open:p}):a3(a.name,14)}),(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:a.fullPath,children:a.name}),u&&(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",children:(0,d.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})}),D&&(0,d.jsxs)("div",{style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",gap:4},children:[C&&(0,d.jsxs)("button",{onClick:b=>{b.stopPropagation(),g?.(a.fullPath,a.name)},title:"Explore H5AD",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,d.jsx)("path",{d:"M16 16l4 4"}),(0,d.jsx)("path",{d:"M8.5 11h5"}),(0,d.jsx)("path",{d:"M11 8.5v5"})]}),"@explore"]}),B&&(0,d.jsxs)("button",{onClick:b=>{b.stopPropagation(),h?.((0,a4.qP)(a.fullPath,c))},title:"Insert path into chat",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,d.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]}),"@mention"]})]})]}),a.isDir&&p&&(0,d.jsxs)("div",{children:[E.map(a=>(0,d.jsx)(ba,{node:a,depth:b+1,cwd:c,onOpenFile:f,onExploreFile:g,onAtMention:h,expandedPaths:i,onToggleExpanded:j,onUploadFiles:k,uploadTargetPath:l,refreshKey:m,searchQuery:n},a.fullPath)),0===E.length&&s&&!o&&(0,d.jsx)("div",{style:{paddingLeft:8+(b+1)*14,fontSize:11,color:"var(--text-dim)",height:22,display:"flex",alignItems:"center"},children:"empty"})]})]})}function bb({cwd:a,onOpenFile:b,onExploreFile:c,refreshKey:f,onAtMention:g,searchQuery:h="",onSearchChange:i}){let[j,k]=(0,e.useState)([]),[l,m]=(0,e.useState)(!0),[n,o]=(0,e.useState)(null),[p,q]=(0,e.useState)(new Set),[r,s]=(0,e.useState)(!1),[t,u]=(0,e.useState)(null),[v,w]=(0,e.useState)(null);(0,e.useRef)(null);let x=(0,e.useRef)(null),y=(0,e.useRef)(0),z=(0,e.useCallback)((a,b)=>(m(b),o(null),a5(a).then(a=>k(a)).catch(a=>o(String(a))).finally(()=>m(!1))),[]),A=(0,e.useCallback)((a,b)=>{q(c=>{let d=new Set(c);return b?d.add(a):d.delete(a),d})},[]),B=(0,e.useCallback)(()=>{z(a,0===j.length)},[a,j.length,z]),C=(0,e.useCallback)(()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>w(null),5e3)},[]),D=(0,e.useCallback)((b,c)=>{if(0===b.length)return;y.current=0,s(!1),x.current&&clearTimeout(x.current);let d=b.reduce((a,b)=>a+b.size,0),e=a9(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,a4.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}),B(),C()}else{let e=a.error??`Upload failed (HTTP ${g.status})`;w({phase:(g.status,"error"),targetPath:c,fileCount:b.length,loaded:0,total:d,message:e,details:403===g.status?["Check directory write permission or project access."]:void 0}),C()}},g.onerror=()=>{u(null),w({phase:"error",targetPath:c,fileCount:b.length,loaded:0,total:d,message:"Upload failed due to a network error"}),C()},g.onabort=()=>{u(null),w({phase:"error",targetPath:c,fileCount:b.length,loaded:0,total:d,message:"Upload canceled"}),C()},g.send(f)},[a,B,C]),E=(0,e.useCallback)(a=>{a7(a.dataTransfer)&&(a.preventDefault(),y.current+=1,s(!0))},[]),F=(0,e.useCallback)(a=>{a7(a.dataTransfer)&&(a.preventDefault(),a.dataTransfer.dropEffect="copy")},[]),G=(0,e.useCallback)(()=>{y.current-=1,y.current<=0&&(y.current=0,s(!1))},[]),H=(0,e.useCallback)(b=>{if(!a7(b.dataTransfer))return;b.preventDefault(),y.current=0,s(!1);let c=a8(b.dataTransfer);c.length>0&&D(c,a)},[a,D]),I=h.trim()?j.filter(a=>a6(a,h)):j,J=h.trim().length>0;return l?(0,d.jsx)(bc,{cwd:a,isDraggingFiles:r,uploadState:v,onDragEnter:E,onDragOver:F,onDragLeave:G,onDrop:H,children:(0,d.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."})}):n?(0,d.jsx)(bc,{cwd:a,isDraggingFiles:r,uploadState:v,onDragEnter:E,onDragOver:F,onDragLeave:G,onDrop:H,children:(0,d.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:n})}):(0,d.jsx)(bc,{cwd:a,isDraggingFiles:r,uploadState:v,onDragEnter:E,onDragOver:F,onDragLeave:G,onDrop:H,children:(0,d.jsxs)("div",{style:{padding:"2px 4px"},children:[I.map(e=>(0,d.jsx)(ba,{node:e,depth:0,cwd:a,onOpenFile:b,onExploreFile:c,onAtMention:g,expandedPaths:p,onToggleExpanded:A,onUploadFiles:D,uploadTargetPath:t,refreshKey:f,searchQuery:h},e.fullPath)),0===I.length&&(0,d.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:J?"No matching files":"No files found"})]})})}function bc({cwd:a,isDraggingFiles:b,uploadState:c,onDragEnter:e,onDragOver:f,onDragLeave:g,onDrop:h,children:i}){let j=c&&c.total>0?Math.max(0,Math.min(100,Math.round(c.loaded/c.total*100))):c?.phase==="uploading"?8:100,k=c?.phase==="success"?"#22c55e":c?.phase==="warning"?"#f59e0b":c?.phase==="error"?"#ef4444":"var(--accent)";return(0,d.jsxs)("div",{onDragEnter:e,onDragOver:f,onDragLeave:g,onDrop:h,style:{position:"relative",display:"flex",flexDirection:"column",height:"100%",minHeight:0,outline:b?"1px solid rgba(37,99,235,0.45)":"none",outlineOffset:-1,background:b?"rgba(37,99,235,0.04)":void 0,transition:"background 0.12s, outline-color 0.12s"},children:[(0,d.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",overscrollBehavior:"contain",scrollbarWidth:"thin"},children:i}),b&&(0,d.jsx)("div",{style:{pointerEvents:"none",position:"absolute",inset:6,top:42,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",strokeLinejoin:"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 ",a9(a,a)]})}),c&&(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)"},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:k,flexShrink:0}}),(0,d.jsx)("span",{title:c.message,style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11,fontWeight:600},children:c.message}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,flexShrink:0},children:"uploading"===c.phase?`${j}%`: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]}`}(c.total)})]}),(0,d.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,background:"var(--bg)",overflow:"hidden"},children:(0,d.jsx)("div",{style:{width:`${j}%`,height:"100%",borderRadius:999,background:k,transition:"width 0.15s ease"}})}),c.details&&c.details.length>0&&(0,d.jsx)("div",{style:{marginTop:5,display:"grid",gap:2},children:c.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))})]})]})}function bd({cwd:a,refreshKey:b=0,onOpenFile:c,onExploreFile:f,onAtMention:g}){let[h,i]=(0,e.useState)(""),[j,k]=(0,e.useState)(0);return(0,d.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",background:"var(--bg)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:"9px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,d.jsxs)("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:2,fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:a??"No project selected"})]}),(0,d.jsx)("button",{type:"button",onClick:()=>k(a=>a+1),disabled:!a,title:"Refresh files",style:{width:28,height:28,padding:0,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:a?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center",opacity:a?1:.55},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)("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"})]})})]}),(0,d.jsxs)("div",{style:{position:"relative",marginTop:9},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:30,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:j,onAtMention:g,searchQuery:h,onSearchChange:i}):(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,a4.WP)(b):l?(0,a4.WP)(l.filePath):"",G=b&&c?(0,a4.qP)(b,c):l?.filePath&&l.cwd?(0,a4.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}){let[i,j]=(0,e.useState)([]),[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)(null),[u,v]=(0,e.useState)(null),[w,x]=(0,e.useState)(null),[y,z]=(0,e.useState)(null),[A,B]=(0,e.useState)(null),C=(0,e.useMemo)(()=>[...i].sort((a,b)=>{let c=+!!a.running,d=+!!b.running;return c!==d?d-c:Date.parse(b.lastActivity)-Date.parse(a.lastActivity)}),[i]),D=(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}`);j(b.apps),h?.(b.apps),p(null)}catch(a){p(a instanceof Error?a.message:String(a))}},[h]),E=(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}`);l(d),n(d.memory??null),r(null)}catch(a){r(a instanceof Error?a.message:String(a))}},[c]),F=(0,e.useCallback)(async a=>{x(a.id),p(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}`);j(a=>a.map(a=>a.id===c.app.id?c.app:a)),g?.(c.app),await D()}catch(a){p(a instanceof Error?a.message:String(a))}finally{x(null)}},[D,g]),G=(0,e.useCallback)(async a=>{z(a.sessionId),r(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 E()}catch(a){r(a instanceof Error?a.message:String(a))}finally{z(null)}},[E]),H=(0,e.useCallback)(async(a,b)=>{if(c){v(`${a}:${b}`),t(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 E()}catch(a){t(a instanceof Error?a.message:String(a))}finally{v(null)}}},[c,E]),I=i.filter(a=>a.running).length,J=i.reduce((a,b)=>a+(b.running?b.rssBytes??0:0),0),K=k?.sessions??[],L=K.filter(a=>a.busy),M=L.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:[L.length," agent running \xb7 ",I," explore \xb7 ",bs(J)]})]}),(0,d.jsx)("button",{type:"button",onClick:()=>{D(),E()},style:bz,title:"Refresh status",children:"Refresh"})]}),o&&(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:o}),q&&(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:q}),s&&(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:s})]}),(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:M.length>0?`${M.length} waiting for model first token`:`${L.length} active chat${1===L.length?"":"s"}`}),0===K.length?(0,d.jsx)(bw,{label:"No agent runtime is active."}):(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:K.map(a=>{var b;let c=a.model?`${a.model.provider}/${a.model.id}`:"-",e=a.cwd?(0,a4.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 G(a),disabled:!a.busy||y===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&&y!==a.sessionId?1:.55},children:"Abort"})})]},a.sessionId)})})]}),(0,d.jsxs)("section",{children:[(0,d.jsx)(bv,{title:"Memory",subtitle:m?`${m.count} stored \xb7 ${m.candidateCount} candidates`:c?"loading":"No project selected"}),c?m?(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(m.byType.fact)}),(0,d.jsx)(bx,{label:"context",value:String(m.byType.context)}),(0,d.jsx)(bx,{label:"decision",value:String(m.byType.decision)}),(0,d.jsx)(bx,{label:"preference",value:String(m.byType.preference)}),(0,d.jsx)(bx,{label:"note",value:String(m.byType.note)}),(0,d.jsx)(bx,{label:"candidates",value:String(m.candidateCount),color:m.candidateCount>0?"var(--accent)":void 0})]}),(0,d.jsx)("div",{title:m.filePath,style:{marginTop:8,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(0,a4.qP)(m.filePath,c)})]}),(0,d.jsx)(by,{title:"Promotion Candidates",emptyLabel:"No promotion candidates yet.",items:m.topCandidates,onPromote:H,busyAction:u}),(0,d.jsx)(by,{title:"Recent Memory",emptyLabel:"No memory stored for this project.",items:m.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:`${I} running \xb7 ${bs(J)}`}),0===C.length?(0,d.jsx)(bw,{label:"No explore tools are running."}):(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:C.map(a=>{let e,g=b===a.id,h=A===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,a4.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,a4.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:()=>B(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 F(a),disabled:!a.running||w===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&&w!==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,busyAction:f}){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&&(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[(0,d.jsx)("button",{type:"button",disabled:a.promotedTo.includes("memory")||f===`${a.id}:context`||f===`${a.id}:memory`,onClick:()=>void e(a.id,"memory"),style:{...bz,height:24,padding:"0 8px",opacity:a.promotedTo.includes("memory")||f===`${a.id}:context`||f===`${a.id}:memory`?.55:1},children:a.promotedTo.includes("memory")?"In MEMORY.md":f===`${a.id}:memory`?"Saving...":"To MEMORY.md"}),(0,d.jsx)("button",{type:"button",disabled:a.promotedTo.includes("context")||f===`${a.id}:context`||f===`${a.id}:memory`,onClick:()=>void e(a.id,"context"),style:{...bz,height:24,padding:"0 8px",opacity:a.promotedTo.includes("context")||f===`${a.id}:context`||f===`${a.id}:memory`?.55:1},children:a.promotedTo.includes("context")?"In CONTEXT.md":f===`${a.id}:context`?"Saving...":"To CONTEXT.md"})]})]},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}){let[g,h]=(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,i=!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"})}):a3(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}),i&&(0,d.jsx)("button",{onClick:b=>{b.stopPropagation(),f(a.id)},onMouseEnter:()=>h(a.id),onMouseLeave:()=>h(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:g===a.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:3,color:g===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){let b=a,c=0;for(;1===b.children.length;)b=b.children[0],c++;return{node:b,skipped:c}}function bC({node:a,activePathIds:b,depth:c,isLast:e,parentLines:f,onSelect:g}){let{node:h,skipped:i}=bB(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)(bC,{node:a,activePathIds:b,depth:c+1,isLast:i===h.children.length-1,parentLines:[...f,!e],onSelect:g},a.entry.id))]})}function bD({tree:a,activeLeafId:b,onLeafChange:c,inline:f,containerRef:g,open:h,onToggle:i,hasSession:j}){let[k,l]=(0,e.useState)(!1),m=void 0!==h?h:k,n=(0,e.useRef)(null),[o,p]=(0,e.useState)(null),q=(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]),r=(0,e.useCallback)(a=>{c(a)},[c]),s=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",t=a.length>0?bB(a[0]):null,u=t?.node??null,v=!s&&u&&u.children.length>1,w=(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:v?"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"})]}),x=(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:m?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,d.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})});return f?(0,d.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,d.jsxs)("button",{ref:n,className:"topbar-branches-button",onClick:()=>i?i():l(a=>!a),title:"Branches","aria-label":"Branches",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:m?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${m?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:m?"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=m?"var(--text)":"var(--text-muted)",a.currentTarget.style.background=m?"var(--bg-selected)":"var(--bg-panel)"},children:[(0,d.jsx)("span",{className:"topbar-branches-icon",children:w}),(0,d.jsx)("span",{className:"topbar-branches-label",children:"Branches"})]}),m&&o&&(0,d.jsx)("div",{style:{position:"fixed",top:o.top,left:o.left,width:o.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:v&&u?(0,d.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:u.children.map((a,b)=>(0,d.jsx)(bC,{node:a,activePathIds:q,depth:0,isLast:b===u.children.length-1,parentLines:[],onSelect:r},a.entry.id))}):(0,d.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:s})})]}):(0,d.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,d.jsxs)("button",{onClick:()=>l(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:[w,(0,d.jsx)("span",{style:{color:"var(--text-muted)"},children:"Branches"}),x]}),m&&(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:v&&u?(0,d.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:u.children.map((a,b)=>(0,d.jsx)(bC,{node:a,activePathIds:q,depth:0,isLast:b===u.children.length-1,parentLines:[],onSelect:r},a.entry.id))}):(0,d.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:s??"This session has no branches"})})]})}function bE(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 bF=bE((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"})),bG=bE((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"})),bH=bE((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"})]})),bI=bE((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"})]})),bJ=bE((0,d.jsx)("path",{d:"M4 4h16v16H4z",fill:"#F55036"}),"0 0 24 24"),bK=bE((0,d.jsx)("path",{d:"M4 4h5v5H4zm5.5 0h5v5h-5zM15 4h5v5h-5zM4 9.5h5v5H4zm5.5 5.5h5v5h-5zM15 9.5h5v5h-5z",fill:"#FA6F00"})),bL=bE((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),bM=bE((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"})]})),bN=bE((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#FF5722"}),"0 0 24 24"),bO=bE((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"})),bP=bE((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"})]})),bQ=bE((0,d.jsx)("path",{d:"M12 2l9 5v10l-9 5-9-5V7l9-5z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})),bR=bE((0,d.jsx)("path",{d:"M4 4l8 8 8-8M4 20l8-8 8 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})),bS=bE((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"})),bT={anthropic:{Icon:bF,hasColor:!1},openai:{Icon:bG,hasColor:!1},"openai-codex":{Icon:bG,hasColor:!1},google:{Icon:bH,hasColor:!0},"google-vertex":{Icon:bH,hasColor:!0},deepseek:{Icon:bI,hasColor:!0},groq:{Icon:bJ,hasColor:!1},mistral:{Icon:bK,hasColor:!0},moonshotai:{Icon:bL,hasColor:!1},"moonshotai-cn":{Icon:bL,hasColor:!1},moonshot:{Icon:bL,hasColor:!1},minimax:{Icon:bM,hasColor:!0},"minimax-cn":{Icon:bM,hasColor:!0},fireworks:{Icon:bN,hasColor:!0},huggingface:{Icon:bO,hasColor:!0},cerebras:{Icon:bP,hasColor:!0},openrouter:{Icon:bQ,hasColor:!1},xai:{Icon:bR,hasColor:!1},"cloudflare-ai-gateway":{Icon:bS,hasColor:!0},"cloudflare-workers-ai":{Icon:bS,hasColor:!0},"vercel-ai-gateway":{Icon:bE((0,d.jsx)("path",{d:"M12 2L22 20H2L12 2z",fill:"currentColor"})),hasColor:!1},"github-copilot":{Icon:bE((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:bE((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:bE((0,d.jsx)("path",{d:"M12 2L3 18h5l4-6 4 6h5L12 2z",fill:"#0078D4"})),hasColor:!0},"kimi-coding":{Icon:bE((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:bE((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:bE((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:bE((0,d.jsx)("path",{d:"M4 8h16v2H4zm0 4h12v2H4zm0 4h8v2H4z",fill:"#3059B1"})),hasColor:!0},perplexity:{Icon:bE((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:bE((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#0F6CBD"}),"0 0 24 24"),hasColor:!0},grok:{Icon:bE((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),hasColor:!1}},bU=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],bV="openai-completions",bW={off:"none",xhigh:"xhigh"};function bX(a){let b=a?.toLowerCase().replace(/\s+/g,"-")??"";return/(^|[^a-z0-9])gpt-5($|[.-])/.test(b)}function bY(a,b=bV){return bX(a.id)||bX(a.name)?{...a,api:a.api??("openai-responses"===b?void 0:"openai-responses"),reasoning:a.reasoning??!0,thinkingLevelMap:a.thinkingLevelMap??bW}:a}function bZ({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 b$={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 b_({value:a,onChange:b,placeholder:c,mono:e}){return(0,d.jsx)("input",{value:a,onChange:a=>b(a.target.value),placeholder:c,style:{...b$,fontFamily:e?"var(--font-mono)":"inherit"}})}function b0({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:{...b$,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 b1({value:a,onChange:b,placeholder:c}){return(0,d.jsx)("input",{type:"number",value:a,onChange:a=>b(a.target.value),placeholder:c,style:b$})}function b2({value:a,onChange:b,options:c,required:e}){return(0,d.jsxs)("select",{value:a,onChange:a=>b(a.target.value),style:{...b$,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 b3({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 b4({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 b5({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)(b4,{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)(bZ,{label:"Provider name",children:[(0,d.jsx)(b_,{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)(bZ,{label:"Base URL",children:(0,d.jsx)(b_,{value:b.baseUrl??"",onChange:a=>j("baseUrl",a||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,d.jsxs)(bZ,{label:"API Key",children:[(0,d.jsx)(b0,{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)(bZ,{label:"API",children:(0,d.jsx)(b2,{value:b.api??"openai-completions",onChange:a=>j("api",a),options:bU,required:!0})})]})}let b6=["off","minimal","low","medium","high","xhigh"],b7={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c"};function b8({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:b6.map(a=>{let b=c[a],f=a in c?null===b?"null":"string":"omit",g="string"==typeof b?b:"",h=b7[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 b9={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function ca({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(bY(a,b.api??bV))},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)(b4,{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)(bZ,{label:"ID *",children:(0,d.jsx)(b_,{value:c.id,onChange:a=>k({...c,id:a}),placeholder:"model-id",mono:!0})}),(0,d.jsx)(bZ,{label:"Name",children:(0,d.jsx)(b_,{value:c.name??"",onChange:a=>k({...c,name:a||void 0}),placeholder:"Display name"})})]}),(0,d.jsx)(bZ,{label:"API override",children:(0,d.jsx)(b2,{value:c.api??"",onChange:a=>j("api",a||void 0),options:bU})}),(0,d.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,d.jsx)(b3,{label:"Reasoning / thinking",checked:c.reasoning??!1,onChange:a=>j("reasoning",a||void 0)}),(0,d.jsx)(b3,{label:"Image input",checked:c.input?.includes("image")??!1,onChange:a=>j("input",a?["text","image"]:void 0)})]}),c.reasoning&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(b3,{label:"DeepSeek thinking compat",checked:c.compat?.thinkingFormat==="deepseek",onChange:a=>f(function(a,b){if(b)return{...a,compat:{...a.compat??{},...b9}};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)(b4,{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)(b8,{value:c.thinkingLevelMap,onChange:a=>j("thinkingLevelMap",a)})]})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,d.jsx)(bZ,{label:"Context window (tokens)",children:(0,d.jsx)(b1,{value:void 0!==c.contextWindow?String(c.contextWindow):"",onChange:a=>j("contextWindow",a?parseInt(a):void 0),placeholder:"128000"})}),(0,d.jsx)(bZ,{label:"Max output tokens",children:(0,d.jsx)(b1,{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)(b4,{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)(bZ,{label:a,children:(0,d.jsx)(b1,{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 cb({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)(b4,{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 cc({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)(b4,{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)(bZ,{label:"API Key",children:(0,d.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,d.jsx)(b0,{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 cd({id:a,size:b}){let c=bT[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 ce({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)(cd,{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)(cd,{id:a.id,size:28})]},a.id))]})})]})})}function cf({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)(bZ,{label:"Base URL",children:(0,d.jsx)(b_,{value:f,onChange:g,placeholder:"https://api.example.com",mono:!0})}),(0,d.jsx)(bZ,{label:"API Key",children:(0,d.jsx)(b0,{value:h,onChange:i,placeholder:"optional for local providers",mono:!0})}),(0,d.jsx)(bZ,{label:"Provider name",children:(0,d.jsx)(b_,{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??bV,o=0;for(let a of q.piModels)l.has(a.id)&&!m.has(a.id)&&(m.set(a.id,bY(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 cg({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)(cb,{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)(cc,{provider:a,onRefresh:B},a.id):null}if("provider"===q.type){let a=c.providers?.[q.name];return a?(0,d.jsx)(b5,{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)(ca,{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)(cd,{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)(cd,{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)(ce,{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)(cf,{existingProviders:c.providers??{},onImport:J,onClose:()=>z(!1)})]})}function ch(a){return a.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function ci(a){let b=a.sourceInfo?.source,c=a.sourceInfo?.scope;return"user"===c||"user"===b?"global":"project"===c||"project"===b?"project":"path"}function cj({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 ck({skill:a,cwd:b,onToggle:c,toggling:e,saveError:f}){let g=ci(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 ch(a)}(a.filePath)}),(0,d.jsx)(cj,{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 cl({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/":`${ch(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 cm({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:ch(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=>ci(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)(cl,{cwd:a,onInstalled:()=>{t()}}):h?null:v?(0,d.jsx)(ck,{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 cn=[{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 co(a){return a?a.replace(/^\/(?:Users|home)\/[^/]+/,"~"):""}function cp(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 cq(a){return{id:"",language:a,displayName:"",command:"python"===a?"python3":"R",argsText:JSON.stringify("python"===a?["-u"]:["--slave","--vanilla"]),envText:"{}"}}function cr(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 cs={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"},ct={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 cu({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 cv({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)(()=>cq("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(cq(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 ${cp(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:{...cs,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:{...cs,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:cn.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 ${cp(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:{...cs,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:{...cs,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:co(f?.paths.global??"")})]}),a&&(0,d.jsxs)("div",{children:["Project: ",(0,d.jsx)("code",{style:{fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:co(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(cr(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)(cu,{label:"Command",children:(0,d.jsx)("input",{readOnly:!0,value:K.command,style:{...ct,color:"var(--text-muted)"}})}),(0,d.jsx)(cu,{label:"Args",children:(0,d.jsx)("input",{readOnly:!0,value:JSON.stringify(K.args),style:{...ct,color:"var(--text-muted)"}})})]}),(0,d.jsx)(cu,{label:"Environment",children:(0,d.jsx)("textarea",{readOnly:!0,value:JSON.stringify(K.env,null,2),rows:5,style:{...ct,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:{...cs,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:{...cs,opacity:"default"===j?.6:1},children:"Set default"}),(0,d.jsx)("button",{type:"button",onClick:()=>{u("edit"),s(K.id),w(cr(K)),m(null),o(null)},style:cs,children:"Edit"}),!K.id.startsWith("default-")&&(0,d.jsx)("button",{type:"button",onClick:()=>void Q(K),disabled:"delete"===j,style:{...cs,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)(cu,{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:{...ct,color:"edit"===t?"var(--text-muted)":"var(--text)"}})}),(0,d.jsx)(cu,{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:ct})})]}),(0,d.jsx)(cu,{label:"Command",children:(0,d.jsx)("input",{value:v.command,onChange:a=>w(b=>({...b,command:a.target.value})),placeholder:"/usr/bin/python3",style:ct})}),(0,d.jsx)(cu,{label:"Args JSON",children:(0,d.jsx)("input",{value:v.argsText,onChange:a=>w(b=>({...b,argsText:a.target.value})),style:ct})}),(0,d.jsx)(cu,{label:"Env JSON",children:(0,d.jsx)("textarea",{value:v.envText,onChange:a=>w(b=>({...b,envText:a.target.value})),rows:6,style:{...ct,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:{...cs,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(cr(a)),u("view")):R(),m(null)},style:cs,children:"Cancel"})]})]})})]})]})}function cw({open:a,initialPath:b,onClose:c,onSelect:f}){let[g,h]=(0,e.useState)(""),[i,j]=(0,e.useState)(null),[k,l]=(0,e.useState)([]),[m,n]=(0,e.useState)([]),[o,p]=(0,e.useState)(""),[q,r]=(0,e.useState)(!1),[s,t]=(0,e.useState)(null),u=(0,e.useCallback)(async a=>{r(!0),t(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),l(d.directories??[]),n(d.drives??[]),p(d.current??"")}catch(a){t(a instanceof Error?a.message:String(a))}finally{r(!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=o.trim();b&&f(b)},style:{display:"flex",gap:8},children:[(0,d.jsx)("input",{value:o,onChange:a=>p(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=o.trim();a&&u(a)},disabled:!o.trim()||q,style:{height:32,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:o.trim()&&!q?"var(--text-muted)":"var(--text-dim)",cursor:o.trim()&&!q?"pointer":"default",fontSize:12},children:"Browse"}),(0,d.jsx)("button",{type:"submit",disabled:!o.trim(),style:{height:32,padding:"0 11px",border:"none",borderRadius:6,background:o.trim()?"var(--accent)":"var(--bg-hover)",color:o.trim()?"#fff":"var(--text-dim)",cursor:o.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 u(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"})})}),m.length>0&&(0,d.jsxs)("select",{value:m.find(a=>g.toLowerCase().startsWith(a.toLowerCase()))??"",onChange:a=>{a.target.value&&u(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"}),m.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:q?(0,d.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"Loading..."}):s?(0,d.jsx)("div",{style:{padding:18,color:"#f87171",fontSize:12},children:s}):0===k.length?(0,d.jsx)("div",{style:{padding:18,color:"var(--text-muted)",fontSize:12},children:"No subdirectories"}):k.map(a=>(0,d.jsxs)("button",{type:"button",onClick:()=>void u(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}var cx=c(39868);function cy({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,cx.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 cz="annovibe-im-gateway";function cA({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:cE(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:cE(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)(cH,{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)(cD,{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)(cB,{status:i}):null,(0,d.jsx)(cF,{label:"Bot ID",value:k,onChange:l,placeholder:"从企业微信 AI bot 控制台获取"}),(0,d.jsx)(cF,{label:c?.hasSecret?"Bot Secret(留空则不修改)":"Bot Secret",value:m,onChange:n,placeholder:c?.hasSecret?"留空保留现有 secret":"从企业微信 AI bot 控制台获取",secret:!0}),(0,d.jsx)(cD,{label:"群聊中需要 @提及 bot 才响应",description:"开启后,群聊中用户必须 @bot 才会被处理。",checked:o,disabled:w,compact:!0,onChange:p}),(0,d.jsx)(cF,{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:cK,placeholder:"用户也可通过配对码自助授权"})]}),(0,d.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[(0,d.jsx)(cG,{primary:!0,disabled:w,onClick:H,children:w?"保存中…":"保存 IM 配置"}),(0,d.jsx)(cG,{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)(cC,{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)(cG,{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)(cC,{label:"Gateway 启动命令",value:cz,copyLabel:"复制命令",mono:!0}),(0,d.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["启动 ",(0,d.jsx)("code",{style:cI,children:"annovibe"})," 后,在",(0,d.jsx)("strong",{style:{color:"var(--text-muted)",fontWeight:600},children:"同一 Linux 账户"}),"中运行"," ",(0,d.jsx)("code",{style:cI,children:cz}),"。 Gateway 通过本地 API 读取已启用的项目配置和 bot secret —— 无需手动复制文件。"]}),(0,d.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["配对码与白名单: ",(0,d.jsxs)("code",{style:cI,children:["~/.pi/agent/im/","<project>",".json"]})]}),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 cB({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 cC({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:{...cI,...e?{wordBreak:"break-all"}:{}},children:b})]}),(0,d.jsx)(cy,{text:b,label:c})]})}function cD({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 cE(a){return a.split(/\r?\n/).map(a=>a.trim()).filter(Boolean)}function cF({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:cJ})]})}function cG({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 cH({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 cI={fontFamily:"var(--font-mono)",fontSize:"0.95em"},cJ={height:30,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"},cK={padding:"8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",resize:"vertical"};function cL({activeCwd:a,onSelectProject:b,onProjectsChanged:c}){let[f,g]=(0,e.useState)([]),[h,i]=(0,e.useState)(!0),[j,k]=(0,e.useState)(null),[l,m]=(0,e.useState)(""),[n,o]=(0,e.useState)(!1),[p,q]=(0,e.useState)(null),[r,s]=(0,e.useState)(null),[t,u]=(0,e.useState)(""),[v,w]=(0,e.useState)(new Set),[x,y]=(0,e.useState)(null),[z,A]=(0,e.useState)(null),B=(0,e.useRef)(null),C=(0,e.useCallback)(async()=>{try{i(!0);let a=await fetch("/api/projects"),b=await a.json();if(!a.ok||b.error)throw Error(b.error??`HTTP ${a.status}`);g(b.projects??[]),k(null)}catch(a){k(a instanceof Error?a.message:String(a))}finally{i(!1)}},[]),D=(0,e.useMemo)(()=>({projects:f.length,chats:f.reduce((a,b)=>a+b.chatCount,0)}),[f]),E=(0,e.useCallback)(async()=>{let a=l.trim();if(a){q("add"),k(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}`);m(""),c?.(),b?.(a),C()}catch(a){k(a instanceof Error?a.message:String(a))}finally{q(null)}}},[C,c,b,l]),F=(0,e.useCallback)(async a=>{q("add"),k(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}`);m(""),o(!1),c?.(),b?.(a),C()}catch(a){k(a instanceof Error?a.message:String(a))}finally{q(null)}},[C,c,b]),G=(0,e.useCallback)(async a=>{q(`rename:${a}`),k(null);try{let b=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,name:t})}),d=await b.json();if(!b.ok||d.error)throw Error(d.error??`HTTP ${b.status}`);s(null),u(""),await C(),c?.()}catch(a){k(a instanceof Error?a.message:String(a))}finally{q(null)}},[C,c,t]),H=(0,e.useCallback)(async a=>{q(`remove:${a}`),k(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}`);await C(),c?.()}catch(a){k(a instanceof Error?a.message:String(a))}finally{q(null)}},[C,c]),I=(0,e.useCallback)(a=>{s(a.cwd),u(a.displayName),requestAnimationFrame(()=>B.current?.focus())},[]),J=(0,e.useCallback)(a=>{w(b=>{let c=new Set(b);return c.has(a)?c.delete(a):c.add(a),c})},[]),K=(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{C()}},[C,c]),L=(0,e.useCallback)((a,b)=>{"reorder"!==p&&(y(a),b.dataTransfer.effectAllowed="move",b.dataTransfer.setData("text/project-cwd",a))},[p]),M=(0,e.useCallback)((a,b)=>{b.preventDefault(),b.dataTransfer.dropEffect="move",A(a)},[]),N=(0,e.useCallback)(a=>{if(A(null),!x||x===a)return void y(null);let b=f.map(a=>a.cwd).filter(Boolean),c=b.indexOf(x),d=b.indexOf(a);c<0||d<0?y(null):(b.splice(c,1),b.splice(d,0,x),g(a=>{let c=new Map(a.map(a=>[a.cwd,a]));return b.map(a=>c.get(a)).filter(Boolean)}),y(null),K(b))},[x,K,f]),O=(0,e.useCallback)(()=>{y(null),A(null)},[]);return(0,d.jsxs)("div",{style:{height:"100%",overflowY:"auto"},children:[j&&(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:j}),(0,d.jsx)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:14,padding:"10px 12px",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsxs)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:650,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[D.projects," Projects, ",D.chats," Chats"]}),(0,d.jsx)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11},children:"Settings → Projects"})]})}),(0,d.jsxs)("div",{style:{display:"flex",gap:8,marginBottom:14},children:[(0,d.jsx)("div",{style:{position:"relative",flex:1,minWidth:0},children:(0,d.jsx)("input",{type:"text",value:l,onChange:a=>m(a.target.value),onKeyDown:a=>{"Enter"===a.key&&E()},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"===p,onClick:()=>void E(),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:()=>o(!0),style:{height:30,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Browse…"})]}),h&&(0,d.jsx)("div",{style:{padding:"16px 0",color:"var(--text-muted)",fontSize:12},children:"Loading projects..."}),!h&&(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:f.map(c=>{var e;let f,g=c.lastAccessed??c.created??null,h=c.cwd===a,i=r===c.cwd,j=v.has(c.cwd),k=x===c.cwd,l=z===c.cwd&&x!==c.cwd;return(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"12px 14px",border:`1px solid ${l?"rgba(37,99,235,0.45)":h?"color-mix(in srgb, var(--accent) 40%, var(--border))":"var(--border)"}`,borderRadius:8,background:l?"rgba(37,99,235,0.06)":h?"color-mix(in srgb, var(--accent) 8%, var(--bg-panel))":"var(--bg-panel)",opacity:k?.55:1,transition:"background 0.12s, box-shadow 0.12s"},onDragOver:a=>M(c.cwd,a),onDrop:()=>N(c.cwd),children:[(0,d.jsx)("div",{draggable:!0,onDragStart:a=>L(c.cwd,a),onDragEnd:O,title:"Drag to reorder",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-dim)",cursor:"reorder"===p?"wait":"grab",opacity:"reorder"===p?.65:1,flexShrink:0},children:(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":"true",children:[(0,d.jsx)("circle",{cx:"3",cy:"2.5",r:"1"}),(0,d.jsx)("circle",{cx:"9",cy:"2.5",r:"1"}),(0,d.jsx)("circle",{cx:"3",cy:"6",r:"1"}),(0,d.jsx)("circle",{cx:"9",cy:"6",r:"1"}),(0,d.jsx)("circle",{cx:"3",cy:"9.5",r:"1"}),(0,d.jsx)("circle",{cx:"9",cy:"9.5",r:"1"})]})}),(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[i?(0,d.jsx)("input",{ref:B,value:t,onChange:a=>u(a.target.value),onKeyDown:a=>{"Enter"===a.key&&G(c.cwd),"Escape"===a.key&&s(null)},style:{width:"min(360px, 100%)",height:30,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:13,fontWeight:h?750:650,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.displayName}),(0,d.jsx)("div",{style:{marginTop:4,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:c.cwd,children:(f=(e=c.cwd).split(/[\\/]/).filter(Boolean)).length<=3?e:`.../${f.slice(-3).join("/")}`}),(0,d.jsxs)("div",{style:{marginTop:5,color:"var(--text-muted)",fontSize:11},children:[c.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()}(g),c.exists?"":" / path missing"]})]}),(0,d.jsx)("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:i?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("button",{type:"button",disabled:p===`rename:${c.cwd}`,onClick:()=>void G(c.cwd),style:{height:28,padding:"0 9px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12},children:"Save"}),(0,d.jsx)("button",{type:"button",onClick:()=>s(null),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("button",{type:"button",onClick:()=>b?.(c.cwd),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:h?"var(--accent)":"var(--bg-panel)",color:h?"#fff":"var(--text-muted)",cursor:"pointer",fontSize:12},children:h?"Current":"Switch"}),(0,d.jsxs)("button",{type:"button",onClick:()=>J(c.cwd),"aria-expanded":j,style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:j?"var(--bg-selected)":"var(--bg-panel)",color:j?"var(--accent)":"var(--text-muted)",cursor:"pointer",fontSize:12,display:"inline-flex",alignItems:"center",gap:4},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",style:{transform:j?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,d.jsx)("polyline",{points:"3 2 7 5 3 8"})}),"WeCom IM"]}),(0,d.jsx)("button",{type:"button",onClick:()=>I(c),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Rename"}),(0,d.jsx)("button",{type:"button",disabled:p===`remove:${c.cwd}`,onClick:()=>void H(c.cwd),style:{height:28,padding:"0 9px",border:"1px solid rgba(248,113,113,0.35)",borderRadius:6,background:"transparent",color:"#f87171",cursor:"pointer",fontSize:12},children:"Remove"})]})})]}),j&&(0,d.jsx)("div",{style:{padding:"0 14px 14px",border:"1px solid var(--border)",borderTop:"none",borderRadius:"0 0 8px 8px",background:"var(--bg-panel)"},children:(0,d.jsx)(cA,{cwd:c.cwd,embedded:!0})})]},c.cwd)})}),(0,d.jsx)(cw,{open:n,initialPath:a,onClose:()=>o(!1),onSelect:a=>void F(a)})]})}function cM({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 cN(){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 cO(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"})]}):"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 cP({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:cO("projects")},{id:"models",label:"Models",description:"~/.pi/agent/models.json",icon:cO("models")},{id:"skills",label:"Skills",description:a?"Project and global skills":"Select a project first",disabled:!a,icon:cO("skills")},{id:"generative-ui",label:"Generative UI",description:b?"Enabled":"Disabled",icon:cO("generative-ui")},{id:"workbench-runtime",label:"Workbench Runtime",description:a?"Python / R runtime lifecycle":"Global runtime lifecycle",icon:cO("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)(cN,{})}),(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)(cL,{activeCwd:a,onSelectProject:i,onProjectsChanged:j}),"models"===k&&(0,d.jsx)(cg,{embedded:!0,onClose:()=>{h?.(),g()}}),"skills"===k&&a&&(0,d.jsx)(cm,{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)(cM,{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)(cv,{cwd:a})]})]})]})})}function cQ(a){return a?a.replace(/^\/(?:Users|home)\/[^/]+/,"~"):""}function cR(a){return!Number.isFinite(a)||a<=0?"0.0G":`${(a/1024/1024/1024).toFixed(1)}G`}let cS={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 cT({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)(""),[o,p]=(0,e.useState)(""),[q,r]=(0,e.useState)(!1),[s,t]=(0,e.useState)([]),[u,v]=(0,e.useState)(""),[w,x]=(0,e.useState)(!1),[y,z]=(0,e.useState)(null),A=(0,e.useCallback)(async a=>{if(a){x(!0),z(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();t(d.entries),v(d.path)}catch(a){z(a instanceof Error?a.message:String(a)),t([])}finally{x(!1)}}},[]),B=(0,e.useCallback)(()=>{a&&(r(!0),A(a))},[a,A]),C=(0,e.useCallback)(a=>{A(u?`${u.replace(/\/+$/,"")}/${a}`:a)},[u,A]),D=(0,e.useCallback)(a=>{n(u?`${u.replace(/\/+$/,"")}/${a}`:a),r(!1)},[u]),E="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: ${cQ(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:"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:m,onChange:a=>n(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:B,disabled:!a||f,title:"Browse project files",style:{...cS,whiteSpace:"nowrap",opacity:!a||f?.5:1,cursor:!a||f?"not-allowed":"pointer"},children:q?"Collapse":"Browse"})]})]}),q&&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:()=>{r(!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:"|"}),u?(()=>{let a=u.replace(/^\/+/,"").split("/"),b=[];for(let c=0;c<a.length;c++){let d="/"+a.slice(0,c+1).join("/");b.push({label:0===c?cQ(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:()=>A(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..."})]}),w?(0,d.jsx)("div",{style:{padding:"16px 10px",color:"var(--text-dim)",textAlign:"center"},children:"Loading..."}):y?(0,d.jsx)("div",{style:{padding:"16px 10px",color:"#f87171",textAlign:"center"},children:y}):0===s.length?(0,d.jsx)("div",{style:{padding:"16px 10px",color:"var(--text-dim)",textAlign:"center"},children:"empty directory"}):(0,d.jsxs)("div",{children:[u!==a&&(0,d.jsxs)("div",{onClick:()=>{A(u.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:".."})]}),s.map(a=>{let b,c=!a.isDir&&(b=a.name.toLowerCase(),E.some(a=>b.endsWith(a)));return(0,d.jsxs)("div",{onClick:()=>{a.isDir?C(a.name):D(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:o,onChange:a=>p(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 ",cR(b.totalBytes)]}),(0,d.jsxs)("span",{children:["Current session ",cR(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:cS,children:"Release current chat"}),j&&(0,d.jsx)("button",{type:"button",onClick:j,style:cS,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:cS,children:"Cancel"}),(0,d.jsx)("button",{type:"button",onClick:()=>void h({kernel:k,sourcePath:m.trim(),notes:o.trim()}),disabled:f||!a,style:{...cS,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 cU({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}}let cV=new Set(["pdf","png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]);function cW(a){return!Number.isFinite(a)||a<=0?"0.0G":`${(a/1024/1024/1024).toFixed(1)}G`}function cX(a){let b=a.toLowerCase();return b.endsWith(".rds")||b.endsWith(".qs")}function cY(a){return a.toLowerCase().endsWith(".h5ad")}function cZ(a){let b=(a.split(/[\\/]/).pop()??a).toLowerCase().split(".").pop()??"";return cV.has(b)}function c$(){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,s]=(0,e.useState)(0),[t,u]=(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=cU({initialWidth:260,minWidth:180,maxWidth:500,storageKey:"--pi-sidebar-width"}),E=cU({initialWidth:500,minWidth:300,maxWidth:1200,storageKey:"--pi-right-panel-width",direction:"left"}),F=(0,e.useRef)(null),G=(0,e.useRef)(null),[I,J]=(0,e.useState)([]),[K,L]=(0,e.useState)(null),M=(0,e.useRef)(null),N=(0,e.useCallback)((a,b,c)=>{J(a),L(b),M.current=c},[]),O=(0,e.useCallback)(a=>{M.current?.(a)},[]),[P,Q]=(0,e.useState)(null),R=(0,e.useRef)(null),[S,T]=(0,e.useState)(!1),[U,V]=(0,e.useState)(""),W=(0,e.useRef)(null),X=(0,e.useRef)(!1),Y=(0,e.useCallback)(a=>{Q(a)},[]),Z=(0,e.useCallback)(a=>a?a.name||a.firstMessage.slice(0,80)||a.id.slice(0,12):"",[]),$=(0,e.useCallback)(()=>{i&&(X.current=!1,V(i.name||Z(i)),T(!0),setTimeout(()=>W.current?.select(),0))},[Z,i]),_=(0,e.useCallback)(async()=>{if(X.current){X.current=!1,T(!1);return}if(!i)return void T(!1);let a=U.trim(),b=Z(i);if(T(!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{}},[Z,i,U]),aa=(0,e.useCallback)(a=>{"Enter"===a.key?(a.preventDefault(),_()):"Escape"===a.key&&(X.current=!0,T(!1))},[_]),ab=(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]),[ac,ad]=(0,e.useState)(null),ae=(0,e.useCallback)(a=>{ad(a)},[]),[af,ag]=(0,e.useState)(null),ah=(0,e.useCallback)(a=>{ag(a)},[]),[ai,aj]=(0,e.useState)(null),[ak,al]=(0,e.useState)(null),[am,an]=(0,e.useState)(!1),[ao,ap]=(0,e.useState)(null),[aq,ar]=(0,e.useState)(!1),[as,at]=(0,e.useState)(!1),au=(0,e.useCallback)(a=>{aj(b=>b===a?null:a)},[]),[av,aw]=(0,e.useState)([]),[az,aB]=(0,e.useState)("files"),[aD,aE]=(0,e.useState)(!1),[aF,aG]=(0,e.useState)(null),[aH,aI]=(0,e.useState)(0),[aJ,aK]=(0,e.useState)([]),aL=(0,e.useCallback)(a=>{F.current?.insertText("`"+a+"`")},[]),[aM]=(0,e.useState)(()=>b.get("session")),[aN,aO]=(0,e.useState)(null),[aP,aQ]=(0,e.useState)(()=>!b.get("session")),aR=(0,e.useRef)(!1),aS=(0,e.useCallback)(b=>{aO(b),aG(null),an(!1),ap(null),b&&!aR.current&&(j(a=>a&&a.cwd!==b?null:a),l(a=>a&&a!==b?null:a),p(a=>a+1),s(a=>a+1),J([]),L(null),Q(null),aj(null),a.replace("/",{scroll:!1}))},[a]),aT=(0,e.useCallback)((a,b)=>{aS(a),b?.closeDialog!==!1&&w(!1),n(a=>a+1)},[aS]),aU=(0,e.useCallback)((b,c=!1)=>{l(null),aO(b.cwd),j(b),an(!1),ap(null),p(a=>a+1),Q(null),aQ(!0),c&&(aR.current=!0,setTimeout(()=>{aR.current=!1},0)),c||a.replace(`?session=${encodeURIComponent(b.id)}`,{scroll:!1})},[a]),aV=(0,e.useCallback)((b,c)=>{j(null),l(c),aO(c),an(!1),ap(null),p(a=>a+1),J([]),L(null),Q(null),aj(null),a.replace("/",{scroll:!1})},[a]),aW=(0,e.useCallback)(b=>{l(null),aO(b.cwd),j(b),an(!1),ap(null),n(a=>a+1),a.replace(`?session=${encodeURIComponent(b.id)}`,{scroll:!1}),window.dispatchEvent(new CustomEvent("session-created"))},[a]),aX=(0,e.useCallback)(()=>{n(a=>a+1),s(a=>a+1)},[]),aY=(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]),aZ=(0,e.useCallback)(()=>{aQ(!0)},[]),a$=(0,e.useCallback)(b=>{if(n(a=>a+1),i?.id===b){let b=i.cwd;j(null),l(b??null),an(!1),ap(null),p(a=>a+1),J([]),L(null),Q(null),aj(null),a.replace("/",{scroll:!1})}},[i,a]),a_=i?.cwd??k??aN??null,a0=(0,e.useCallback)((a,b)=>{if(cX(a)||cX(b))return void aG({mode:"start",appType:"stexp",filePath:a,cwd:a_,appId:null});if(cZ(a)||cZ(b)){let c=`preview:${a}`;aK(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}`;aw(d=>d.find(a=>a.id===c)?d:[...d,{id:c,label:b,filePath:a}]),aB(c),aE(!0)},[a_]),a1=(0,e.useCallback)((a,b)=>{(cY(a)||cY(b))&&aG({mode:"start",appType:"h5adexp",filePath:a,cwd:a_,appId:null})},[a_]),a2=(0,e.useCallback)(a=>{ap(a),aj(null),an(!0)},[]),a3=(0,e.useCallback)(()=>{an(!1),ap(null)},[]),a4=(0,e.useCallback)(()=>{aB("tools"),aE(!0),aI(a=>a+1)},[]),a5=(0,e.useCallback)(a=>{aG({mode:"existing",appType:a.appType,filePath:a.filePath,cwd:a.cwd,appId:a.id}),aI(a=>a+1)},[]),a6=(0,e.useCallback)(a=>{aI(a=>a+1),aG(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=>{aK(b=>b.filter(b=>b.id!==a))},[]),a8=(0,e.useCallback)(a=>{aK(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&&(aw(b=>b.filter(b=>b.id!==a)),aB(b=>{if(b!==a)return b;let c=av.filter(b=>b.id!==a);return c.length>0?c[c.length-1].id:"files"}))},[av]),ba=k??(null===i&&aN?aN:null),bb=null!==i||null!==ba,bc=aP&&!bb,be=[{id:"files",label:"Files",closable:!1,icon:"files"},{id:"tools",label:"Status",closable:!1,icon:"tools"},...av],bg=av.find(a=>a.id===az)??null,bj=i?Z(i):ba?"New chat":"No session",bk=i?.cwd??ba??aN??"",bl=bk?bk.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean).pop()||bk:"",bm=ao??a_,bo=(0,e.useCallback)((a="projects")=>{y(a),w(!0)},[]),[bp,bq]=(0,e.useState)(null),[br,bs]=(0,e.useState)(null),[bt,bv]=(0,e.useState)(null);i?.id;let bw=bp?.totalBytes??0,bx=bp?.currentSessionBytes??0,by=(0,e.useCallback)(async()=>{let a=new URLSearchParams;a_&&a.set("cwd",a_),i?.id&&a.set("sessionId",i.id);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}`);bq(c),bs(null)}catch(a){bs(a instanceof Error?a.message:String(a))}},[i?.id,a_]),bz=(0,e.useCallback)(async()=>{if(i?.id&&!bt){bv("all"),bs(null);try{let a=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:i.id})}),b=await a.json();if(!a.ok||b.error)throw Error(b.error??`HTTP ${a.status}`);window.setTimeout(()=>{by()},600)}catch(a){bs(a instanceof Error?a.message:String(a))}finally{bv(null)}}},[by,bt,i?.id]),bB=(0,e.useCallback)(async b=>{let c;if(!bm||aq)return;ar(!0),bs(null);let d=new Date().toISOString(),e=`Workbench \xb7 ${"r"===b.kernel?"R":"Python"}`,f=(c=["Workbench session start.","",`Kernel: ${"r"===b.kernel?"R":"Python"}`],b.sourcePath?c.push(`Primary source: ${b.sourcePath}`):c.push("Primary source: none selected"),b.notes&&(c.push("Notes:"),c.push(b.notes)),c.push("",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` when working with data already in warm memory or when saving final artifacts. 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.join("\n"));try{let c=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:bm,type:"prompt",message:f,toolNames:H("workbench"),sessionName:e,workbenchMeta:{sourcePath:b.sourcePath,kernel:b.kernel}})}),g=await c.json().catch(()=>({}));if(!c.ok||g.error||!g.sessionId)throw Error(g.error??`HTTP ${c.status}`);a3(),l(null),aO(bm),j({id:g.sessionId,path:"",cwd:bm,name:e,created:d,modified:d,messageCount:1,firstMessage:f}),J([]),L(null),Q(null),aj(null),p(a=>a+1),n(a=>a+1),a.replace(`?session=${encodeURIComponent(g.sessionId)}`,{scroll:!1}),window.setTimeout(()=>{by()},600)}catch(a){bs(a instanceof Error?a.message:String(a))}finally{ar(!1)}},[a3,by,a,aq,bm]),bC=(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(r,{selectedSessionId:i?.id??null,onSelectSession:aU,onNewSession:aV,onNewWorkbench:a2,initialSessionId:aM,onInitialRestoreDone:aZ,refreshKey:m,onSessionDeleted:a$,selectedCwd:i?.cwd??k??aN??null,onCwdChange:aS}),(0,d.jsx)("div",{style:{padding:"8px",flexShrink:0,borderTop:"1px solid var(--border)"},children:(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,d.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:2,overflow:"hidden"},children:[(0,d.jsx)("span",{style:{fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:"demo@openvibe.local"}),(0,d.jsx)("a",{href:"/login",style:{fontSize:10,color:"var(--text-muted)",textDecoration:"none"},onMouseEnter:a=>{a.currentTarget.style.color="var(--danger)"},onMouseLeave:a=>{a.currentTarget.style.color="var(--text-muted)"},children:"退出"})]}),(0,d.jsx)("button",{type:"button",onClick:()=>bo("projects"),title:"Settings",style:{width:30,height:30,padding:0,background:"none",border:"none",borderRadius:7,color:"var(--text-muted)",cursor:"pointer",flexShrink:0},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:"14",height:"14",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"})]})})]})})]});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:bC}),B&&(0,d.jsx)(bi,{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:S&&i?(0,d.jsx)("input",{ref:W,value:U,onChange:a=>V(a.target.value),onKeyDown:aa,onBlur:()=>void _(),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:$,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.jsxs)("div",{className:"topbar-chat-tools",style:{display:"flex",alignItems:"center",gap:6,height:28,flexShrink:0},children:[(0,d.jsx)("div",{className:"topbar-branches-control",style:{height:"100%",display:"flex",alignItems:"stretch"},children:(0,d.jsx)(bD,{tree:I,activeLeafId:K,onLeafChange:O,inline:!0,containerRef:G,open:"branches"===ai,onToggle:()=>au("branches"),hasSession:!!i})}),(0,d.jsxs)("button",{ref:R,className:"topbar-system-button",onClick:()=>au("system"),title:"System prompt","aria-label":"System prompt",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:"system"===ai?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${"system"===ai?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:"system"===ai?"var(--text)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:a=>{a.currentTarget.style.color="var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color="system"===ai?"var(--text)":"var(--text-muted)",a.currentTarget.style.background="system"===ai?"var(--bg-selected)":"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:{color:P?"var(--accent)":"var(--text-dim)",flexShrink:0},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"})]}),(0,d.jsx)("span",{className:"topbar-system-label",children:"System"})]}),(0,d.jsxs)("button",{type:"button",className:"topbar-plot-button",onClick:()=>{aj(null),a4()},title:bw>0?`Open Workbench runtime \xb7 ${cW(bw)}`:"Open Workbench runtime status","aria-label":bw>0?`Open Workbench runtime \xb7 ${cW(bw)}`:"Open Workbench runtime status",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:am?"var(--bg-selected)":bw>0||as?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${am||bw>0||as?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:bw>0||as?"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=bw>0||as?"var(--accent)":"var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color=bw>0||as?"var(--accent)":"var(--text-muted)",a.currentTarget.style.background=am?"var(--bg-selected)":bw>0||as?"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"}),bw>0&&(0,d.jsx)("span",{className:"topbar-plot-memory",children:cW(bw)})]})]}),bb&&h&&(0,d.jsxs)("button",{type:"button",className:"topbar-plot-button",onClick:()=>{a4()},title:bw>0?`Open Workbench runtime \xb7 ${cW(bw)}`:"Open Workbench runtime status","aria-label":bw>0?`Open Workbench runtime \xb7 ${cW(bw)}`:"Open Workbench runtime status",style:{display:"flex",alignItems:"center",gap:4,height:28,padding:"0 7px",flexShrink:0,background:am?"var(--bg-selected)":bw>0||as?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${am||bw>0||as?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:bw>0||as?"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"}),bw>0&&(0,d.jsx)("span",{className:"topbar-plot-memory",children:cW(bw)})]}),bb&&(ac||af)&&(()=>{let a=ac?.tokens,b=ac?.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(af?.contextWindow){let a=af.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(af.contextWindow)}`:`? / ${c(af.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)}`)),af?.contextWindow){let a=af.percent;h.push(`context: ${null!==a?a.toFixed(1)+"%":"unknown"} of ${af.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:ab,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:()=>aE(a=>!a),title:aD?"Hide right panel":"Show right panel","aria-label":aD?"Hide right panel":"Show right panel",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:aD?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${aD?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:aD?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:a=>{a.currentTarget.style.color=aD?"var(--accent)":"var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color=aD?"var(--accent)":"var(--text-muted)",a.currentTarget.style.background=aD?"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"})]})}),ai&&ak&&(0,d.jsx)("div",{style:{position:"fixed",top:ak.top,left:ak.left,width:ak.width,zIndex:500},children:"system"===ai&&(0,d.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:P?(0,d.jsx)("div",{style:{maxHeight:"min(600px, 75vh)",overflowY:"auto",padding:"12px 16px",color:"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",fontFamily:"var(--font-mono)"},children:P}):""===P?(0,d.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"System prompt is empty (tools are disabled)"}):(0,d.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"Send a message to load the system prompt"})})})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:bb?(0,d.jsx)(ax,{session:i,newSessionCwd:ba,onAgentEnd:aX,onSessionCreated:aW,onSessionForked:aY,modelsRefreshKey:t,chatInputRef:F,onBranchDataChange:N,onSystemPromptChange:Y,onSessionStatsChange:ae,onContextUsageChange:ah,onToolPresetActive:at,generativeUI:z.generativeUI},o):bc?aN?(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})]}),aD&&(0,d.jsx)(bi,{side:"left",ariaLabel:"Resize right panel",onResizeStart:E.beginResize,onResize:E.resizeBy,onResizeEnd:E.endResize}),(0,d.jsxs)("div",{className:`right-panel-container${aD?" right-panel-open":" right-panel-closed"}`,style:{display:aD?"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:()=>aE(!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:az,onSelectTab:aB,onCloseTab:a9})})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"hidden"},children:"files"===az?(0,d.jsx)(bd,{cwd:aN??i?.cwd??k??null,refreshKey:q,onOpenFile:a0,onExploreFile:a1,onAtMention:aL}):"tools"===az?(0,d.jsx)(bu,{refreshKey:aH,visibleAppId:aF?.appId??null,cwd:aN??i?.cwd??k??null,onOpenApp:a5,onAppChanged:a6}):bg?.filePath?bg.filePath.startsWith("__")?(0,d.jsx)(bh,{filePath:bg.filePath}):(0,d.jsx)(aA,{filePath:bg.filePath,children:(0,d.jsx)(ay.h,{filePath:bg.filePath,cwd:aN??void 0,onOpenFile:a0})}):(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:"No file open"})})]})]}),v&&(0,d.jsx)(cP,{cwd:a_,generativeUI:z.generativeUI,initialTab:x,onGenerativeUIToggle:ab,onModelsChanged:()=>u(a=>a+1),onProjectSelect:aT,onProjectsChanged:()=>n(a=>a+1),onClose:()=>{w(!1),u(a=>a+1)}}),am&&(0,d.jsx)(cT,{cwd:bm,runtime:{totalBytes:bw,currentSessionBytes:bx,idleTimeoutLabel:function(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`}(z.plotIdleTimeoutMs)},runtimeError:br,busy:aq,onClose:a3,onLaunch:a=>bB(a),onReleaseCurrentRuntime:i?.id&&i.cwd===bm?()=>{bz()}:void 0,onOpenSettings:()=>bo("workbench-runtime")}),(0,d.jsx)(bn,{appType:aF?.appType??"stexp",filePath:aF?.filePath??null,cwd:aF?.cwd??null,appId:aF?.appId??null,sessionId:i?.id??null,onClose:()=>aG(null),onAppChanged:a6,onOpenTools:a4}),aJ.map((a,b)=>(0,d.jsx)(aC,{id:a.id,filePath:a.filePath,fileName:a.fileName,cwd:aN??i?.cwd??k??void 0,active:b===aJ.length-1,stackIndex:b,zIndex:700+b,onClose:a7,onFocus:a8,onOpenFile:a0},a.id))]})}},86439:a=>{"use strict";a.exports=require("next/dist/shared/lib/no-fallback-error.external")},94735:a=>{"use strict";a.exports=require("events")},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,9093,1494],()=>b(b.s=71411));module.exports=c})();
|
|
28
|
+
${e}`:"",g={role:"user",content:f,timestamp:Date.now()};aN(g),u(a=>[...a,g]);let h=b?.map(a=>({type:"image",data:a.data,mimeType:a.mimeType}));try{await am(d,{type:"follow_up",message:f,...h?.length?{images:h}:{}})}catch(a){aO(g),console.error("Failed to follow up:",a)}},[aM,aO,aN]),a0=(0,e.useCallback)(async()=>{let a=ax.current;if(a)try{await am(a,{type:"abort_compaction"})}catch(a){console.error("Failed to abort compaction:",a)}},[]),a1=(0,e.useCallback)(async a=>{if(Y(a),"auto"===a)return;let b=ax.current;if(b)try{await am(b,{type:"set_thinking_level",level:a})}catch(a){console.error("Failed to set thinking level:",a)}},[]),a2=(0,e.useCallback)(async a=>{aI(a);let b=J(a,V),c=ax.current;if(c)try{await am(c,{type:"set_tools",toolNames:b})}catch(a){console.error("Failed to set tools:",a)}},[V,aI]),a3=(0,e.useCallback)(async a=>{aJ(a);let b=J(T,a),c=ax.current;if(c)try{await am(c,{type:"set_tools",toolNames:b})}catch(a){console.error("Failed to set memory tools:",a)}},[aJ,T]);return(0,e.useCallback)((a="smooth")=>{aD.current?.scrollIntoView({behavior:a})},[]),(0,e.useCallback)(()=>{let a=aE.current,b=aB.current;if(!a||!b)return;let c=b.getBoundingClientRect().top-a.getBoundingClientRect().top+a.scrollTop;a.scrollTo({top:c-16,behavior:"smooth"})},[]),{data:l,loading:n,error:p,activeLeafId:r,messages:t,entryIds:v,streamState:x,agentRunning:z,modelNames:I,modelList:L,modelThinkingLevels:N,modelThinkingLevelMaps:P,newSessionModel:R,toolPreset:T,memoryTools:V,thinkingLevel:X,retryInfo:Z,contextUsage:_,systemPrompt:ab,forkingEntryId:ad,isCompacting:aj,compactError:aq,currentModel:aK,displayModel:aL,sessionStats:aP,agentPhase:as,agentError:au,isNew:k,sessionIdRef:ax,eventSourceRef:aw,messagesEndRef:aD,scrollContainerRef:aE,lastUserMsgRef:aB,pendingScrollToUserRef:aC,initialScrollDoneRef:aA,handleSend:aU,handleAbort:aV,handleFork:aW,handleNavigate:aX,handleModelChange:aY,handleCompact:aZ,handleSteer:a$,handleFollowUp:a_,handleAbortCompaction:a0,handleToolPresetChange:a2,handleMemoryToolsChange:a3,handleThinkingLevelChange:a1,loadTools:aS,setActiveLeafId:s,setData:m,setMessages:u,dispatch:y,setAgentRunning:C,setForkingEntryId:ae,handleAgentEventRef:az}}({session:a,newSessionCwd:b,onAgentEnd:c,onSessionCreated:f,onSessionForked:g,modelsRefreshKey:h,onBranchDataChange:j,onSystemPromptChange:k}),{soundEnabled:aK,onSoundToggle:aL,playDoneSound:aM}=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,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)(aM).current=aM,(0,e.useRef)(aK).current=aK,aJ.current,ab&&(ab.tokens.input,ab.tokens.output,ab.tokens.cacheRead,ab.tokens.cacheWrite,ab.cost),(0,e.useRef)(ab).current=ab,W&&(W.percent,W.contextWindow,W.tokens),(0,e.useRef)(W).current=W;let{isDragOver:aN,handleDragEnter:aO,handleDragOver:aP,handleDragLeave:aQ,handleDrop:aR}=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(ar)&&(a.preventDefault(),d.current+=1,c(!0))},[]),g=(0,e.useCallback)(a=>{Array.from(a.dataTransfer.items).some(ar)&&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])}}((0,e.useCallback)(a=>{i?.current?.addFiles(a)},[i])),[aS,aT]=(0,e.useState)(null),aU=K.filter(a=>"user"===a.role||"assistant"===a.role),aV=(q=aU.length,(r=(0,e.useRef)([])).current=Array(q).fill(null).map((a,b)=>r.current[b]??null),r),aW=(0,e.useMemo)(()=>{let a=new Map;for(let b of K)"toolResult"===b.role&&a.set(b.toolCallId,b);return a},[K]),aX=ag&&0===K.length&&!M.isStreaming&&!N,aY=y?.info?.cwd??a?.cwd??b??null,aZ=function(a){if(!a)return null;let b=a.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean);return b[b.length-1]||a}(aY),a$=function(a=768){let[b,c]=(0,e.useState)(!1);return b}(),[a_,a0]=(0,e.useState)(!1),[a1,a2]=(0,e.useState)(!1),a3=ae(K),a4=a3.filter(a=>"running"===a.status).length,a5=(0,e.useCallback)(()=>{a?.id&&!N&&(async()=>{await aG("workbench");let a=y?.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 aq(b)}})()},[N,y?.sessionMeta,aq,aG,a?.id]),a6=aa?Q[`${aa.provider}:${aa.modelId}`]??null:null,a7=aa?R[`${aa.provider}:${aa.modelId}`]??null:null,a8=y?.sessionMeta?.sessionKind??null,a9=a?.id??b??"new-chat",ba=(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})(aU.map(a=>({role:a.role,text:"string"==typeof a.content?a.content:""}))),[aU]),bb=(0,e.useCallback)(async(a,b,c)=>{"/plan"===a.trim()||a.trim().startsWith("/plan ")?bc():await aq(a,b,c)},[aq]),bc=(0,e.useCallback)(()=>{let b=!u;v(b);let c=a?.id;c&&am(c,{type:"set_tools",toolNames:b?["read","bash","grep","find","ls"]:["read","bash","edit","write","grep","find","ls"]}).catch(()=>{})},[u,a?.id]),bd=(0,d.jsx)("div",{style:{display:"flex",justifyContent:"center",paddingBottom:4},children:(0,d.jsxs)("button",{onClick:bc,disabled:!a?.id&&!b,title:u?"退出 Plan 模式(恢复完整工具)":"进入 Plan 模式(只读规划)",style:{display:"inline-flex",alignItems:"center",gap:5,padding:"3px 10px",height:24,background:u?"rgba(59,130,246,0.08)":"none",border:u?"1px solid rgba(59,130,246,0.24)":"1px solid var(--border)",borderRadius:6,color:u?"#3b82f6":"var(--text-muted)",cursor:"pointer",fontSize:11,transition:"background 0.12s, color 0.12s, border-color 0.12s"},children:[(0,d.jsx)("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:"M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"})}),u?"Plan: ON":"Plan"]})}),be=(0,d.jsx)(Z,{ref:i,onSend:bb,onAbort:at,onSteer:N?aD:void 0,onFollowUp:N?aE:void 0,isStreaming:N,model:aa,modelNames:O,modelList:P,onModelChange:aB,onCompact:a||ag?aC:void 0,onAbortCompaction:aF,isCompacting:Y,compactError:$,toolPreset:S,sessionKind:a8,onToolPresetChange:a||ag?aG:void 0,memoryTools:T,onMemoryToolsChange:a||ag?aH:void 0,thinkingLevel:U,onThinkingLevelChange:a||ag?aI:void 0,availableThinkingLevels:a6,thinkingLevelMap:a7,retryInfo:V,soundEnabled:aK,onSoundToggle:aL,cornerBadge:aX?(0,d.jsx)(ax,{status:aS}):void 0,promptHistory:ba,sessionHistoryKey:a9}),bf=(0,e.useCallback)(a=>{N?i?.current?.insertText(a):aq(a)},[N,i,aq]);return C?(0,d.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:"Loading session..."}):I?(0,d.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:I}):(0,d.jsxs)("div",{className:"relative flex h-full flex-col overflow-hidden",onDragEnter:aO,onDragOver:aP,onDragLeave:aQ,onDrop:aR,children:[aN&&(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"})]})]})]}),!a1&&(0,d.jsx)(ak,{sessionKind:a8,toolPreset:S,initialSourcePath:y?.sessionMeta?.initialSourcePath??null,initialKernel:y?.sessionMeta?.initialKernel??null,isNew:ag,isStreaming:N,onResume:a5,onDismiss:()=>a2(!0)}),aX?(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:[aZ&&(0,d.jsxs)("div",{style:{padding:a$?"7px 9px":"9px 12px",border:"1px solid var(--border)",borderRadius:a$?9:10,background:"linear-gradient(180deg, var(--bg-panel), rgba(127,127,127,0.03))",minWidth:0,display:"flex",alignItems:"flex-start",gap:a$?8:10,boxShadow:a$?"0 2px 10px rgba(0,0,0,0.04)":"none"},children:[(0,d.jsx)("div",{"aria-hidden":!0,style:{flex:"0 0 auto",width:a$?18:20,height:a$?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:a$?12.5:14,color:"var(--text)",fontWeight:700,lineHeight:1.3,wordBreak:"break-word"},children:aZ}),aY&&(0,d.jsx)("div",{title:aY,style:{fontSize:10.5,color:"var(--text-dim)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:aY})]})]}),(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)(aw,{phrases:av})})]})]}),bd,be]})}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("div",{className:"relative flex flex-1 overflow-hidden",children:[(0,d.jsx)("div",{ref:ai,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:a$?{paddingBottom:"calc(env(safe-area-inset-bottom, 0px) + 128px)"}:void 0,children:[(0,d.jsx)(au,{goal:y?.sessionMeta?.goal??null,planTasks:w,isRunning:N}),(()=>{let c=-1;for(let a=K.length-1;a>=0;a--)if("user"===K[a].role){c=a;break}let e=0;return K.map((f,g)=>{let h="user"===f.role&&g>0&&"assistant"===K[g-1].role?L[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<K.length;a++){let b=K[a].role;if("user"===b)break;if("assistant"===b){l=!1;break}}l&&M.isStreaming&&g===K.length-1&&(l=!1)}let m=(0,d.jsx)(z.D,{message:f,toolResults:aW,modelNames:O,entryId:L[g],onFork:N||ag||0===g&&"user"===f.role?void 0:az,forking:X===L[g],onNavigate:N?void 0:aA,prevAssistantEntryId:N?void 0:h,onEditContent:a=>i?.current?.insertIfEmpty(a),onSendMessage:bf,showTimestamp:l,prevTimestamp:g>0?K[g-1].timestamp:void 0,renderVisualCodeBlocks:!!p,cwd:y?.info?.cwd??a?.cwd??b??void 0},g);return j?(0,d.jsx)("div",{ref:a=>{aV.current[k]=a,g===c&&(aj.current=a)},children:m},g):m})})(),N&&(0,d.jsx)(as,{agentPhase:ac,startedAt:s}),M.isStreaming&&M.streamingMessage&&(0,d.jsx)(z.D,{message:M.streamingMessage,isStreaming:!0,toolResults:aW,modelNames:O,onSendMessage:bf,renderVisualCodeBlocks:!!p,cwd:y?.info?.cwd??a?.cwd??b??void 0}),N&&!M.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..."}(ac)})}),y?.info?.cwd&&!1===y.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:y.info.cwd})]}),ad&&(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:ad}),N&&(0,d.jsx)("div",{style:{height:ai.current?ai.current.clientHeight:"80vh"}}),(0,d.jsx)("div",{ref:ah})]})}),!a$&&(0,d.jsx)(_,{messages:K,streamingMessage:M.streamingMessage,scrollContainer:ai,messageRefs:aV}),a3.length>0&&(0,d.jsxs)("button",{onClick:()=>a0(a=>!a),title:a_?"Hide subagent runs":"Show subagent runs",style:{position:"absolute",right:a$?8:a_?260:40,top:8,minWidth:28,height:28,display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:a4>0||a3.length>1?"0 8px":0,background:a_?"var(--bg-selected)":"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:6,color:a_?"var(--accent)":"var(--text-dim)",cursor:"pointer",zIndex:30,fontSize:12,transition:"right 0.2s ease, background 0.12s"},onMouseEnter:a=>{a_||(a.currentTarget.style.color="var(--text)")},onMouseLeave:a=>{a_||(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"})]}),(a4>0||a3.length>1)&&(0,d.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:4,fontSize:10,fontWeight:700,color:a4>0?"var(--accent)":"var(--text-dim)"},children:[a4>0&&(0,d.jsxs)("span",{children:[a4," active"]}),(0,d.jsx)("span",{children:a3.length})]})]}),a_&&a3.length>0&&(0,d.jsxs)("div",{style:{position:"absolute",right:a$?8:48,top:4,bottom:4,width:a$?"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)(af,{runs:a3})]})]}),(0,d.jsxs)("div",{className:"relative",children:[bd,be]})]})]})}var az=c(90707),aA=c(52515);class aB 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)(aA.fj,{style:{background:"var(--bg)"},children:(0,d.jsx)(aA.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 aC(a,b,c){return Math.min(Math.max(a,b),c)}function aD({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:aC(c,8,Math.max(8,window.innerWidth-120)),top:aC(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:aC(c,360,Math.max(360,window.innerWidth-a.left-8)),height:aC(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:aE,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:aE,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)(aB,{filePath:b,children:(0,d.jsx)(az.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 aE={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},aF="var(--text-dim)";function aG({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:aF}),(0,d.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:aF,strokeWidth:"1",fill:aF,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:aF,strokeWidth:"1",fill:aF,fillOpacity:"0.1"})})}function aH({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:aF,strokeWidth:"1",fill:aF,fillOpacity:"0.08"}),(0,d.jsx)("path",{d:"M10 2v3h3",stroke:aF,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function aI({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:aF,strokeWidth:"0.9",fill:aF,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aF,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:aF,letterSpacing:"0",children:a})]})}function aJ({size:a=14}){return(0,d.jsx)(aI,{label:"TS",size:a})}function aK({size:a=14}){return(0,d.jsx)(aI,{label:"TSX",size:a})}function aL({size:a=14}){return(0,d.jsx)(aI,{label:"JS",size:a})}function aM({size:a=14}){return(0,d.jsx)(aI,{label:"JSX",size:a})}function aN({size:a=14}){return(0,d.jsx)(aI,{label:"PY",size:a})}function aO({size:a=14}){return(0,d.jsx)(aI,{label:"{}",size:a})}function aP({size:a=14}){return(0,d.jsx)(aI,{label:"CSS",size:a})}function aQ({size:a=14}){return(0,d.jsx)(aI,{label:"SC",size:a})}function aR({size:a=14}){return(0,d.jsx)(aI,{label:"HTM",size:a})}function aS({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:aF,strokeWidth:"0.9",fill:aF,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aF,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:aF,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,d.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:aF,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function aT({size:a=14}){return(0,d.jsx)(aI,{label:"YML",size:a})}function aU({size:a=14}){return(0,d.jsx)(aI,{label:"TOM",size:a})}function aV({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:aF,strokeWidth:"0.9",fill:aF,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aF,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:aF,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,d.jsx)("path",{d:"M7.5 10.5h2.5",stroke:aF,strokeWidth:"0.95",strokeLinecap:"round"})]})}function aW({size:a=14}){return(0,d.jsx)(aI,{label:"RS",size:a})}function aX({size:a=14}){return(0,d.jsx)(aI,{label:"GO",size:a})}function aY({size:a=14}){return(0,d.jsx)(aI,{label:"SQL",size:a})}function aZ({size:a=14}){return(0,d.jsx)(aI,{label:"GQL",size:a})}function a$({size:a=14}){return(0,d.jsx)(aI,{label:"TF",size:a})}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:aF,strokeWidth:"0.9",fill:aF,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aF,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:aF,strokeWidth:"0.8"}),(0,d.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:aF,strokeWidth:"0.8"}),(0,d.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:aF,strokeWidth:"0.8"})]})}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:aF,strokeWidth:"0.9",fill:aF,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aF,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("circle",{cx:"5.5",cy:"8.5",r:"1.5",stroke:aF,strokeWidth:"0.9"}),(0,d.jsx)("path",{d:"M7 8.5h2.5M8.5 8.5v1.5",stroke:aF,strokeWidth:"0.9",strokeLinecap:"round"})]})}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:aF,strokeWidth:"0.9",fill:aF,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aF,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("circle",{cx:"5",cy:"6.5",r:"1",stroke:aF,strokeWidth:"0.85"}),(0,d.jsx)("circle",{cx:"9",cy:"6.5",r:"1",stroke:aF,strokeWidth:"0.85"}),(0,d.jsx)("circle",{cx:"5",cy:"10",r:"1",stroke:aF,strokeWidth:"0.85"}),(0,d.jsx)("path",{d:"M5 7.5V9",stroke:aF,strokeWidth:"0.85",strokeLinecap:"round"}),(0,d.jsx)("path",{d:"M9 7.5v.5a2 2 0 0 1-2 2H6",stroke:aF,strokeWidth:"0.85",strokeLinecap:"round",fill:"none"})]})}function a2({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:aF,strokeWidth:"0.9",fill:aF,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aF,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:aF,strokeWidth:"0.9"}),(0,d.jsx)("path",{d:"M5.5 8.5V7.5a1.5 1.5 0 0 1 3 0v1",stroke:aF,strokeWidth:"0.9",strokeLinecap:"round",fill:"none"})]})}function a3({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:aF,strokeWidth:"0.9",fill:aF,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,d.jsx)("path",{d:"M8.5 1v3h3",stroke:aF,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,d.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:aF,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:aF,strokeWidth:"0.8",strokeLinecap:"round"})]})}function a4(a,b=14){let c=a.toLowerCase(),e=c.split(".").pop()??"";if("dockerfile"===c||c.startsWith("dockerfile."))return(0,d.jsx)(a_,{size:b});if(".env"===c||c.startsWith(".env."))return(0,d.jsx)(a0,{size:b});if(".gitignore"===c||".gitattributes"===c||".gitmodules"===c)return(0,d.jsx)(a1,{size:b});if("package-lock.json"===c||"yarn.lock"===c||"bun.lock"===c||"pnpm-lock.yaml"===c||"cargo.lock"===c)return(0,d.jsx)(a2,{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)(a3,{size:b});switch(e){case"ts":return(0,d.jsx)(aJ,{size:b});case"tsx":return(0,d.jsx)(aK,{size:b});case"js":case"mjs":case"cjs":return(0,d.jsx)(aL,{size:b});case"jsx":return(0,d.jsx)(aM,{size:b});case"py":return(0,d.jsx)(aN,{size:b});case"json":case"jsonl":return(0,d.jsx)(aO,{size:b});case"css":case"less":return(0,d.jsx)(aP,{size:b});case"scss":return(0,d.jsx)(aQ,{size:b});case"html":case"htm":return(0,d.jsx)(aR,{size:b});case"md":case"mdx":return(0,d.jsx)(aS,{size:b});case"yaml":case"yml":return(0,d.jsx)(aT,{size:b});case"toml":return(0,d.jsx)(aU,{size:b});case"sh":case"bash":case"zsh":case"fish":return(0,d.jsx)(aV,{size:b});case"rs":return(0,d.jsx)(aW,{size:b});case"go":return(0,d.jsx)(aX,{size:b});case"sql":return(0,d.jsx)(aY,{size:b});case"graphql":case"gql":return(0,d.jsx)(aZ,{size:b});case"tf":case"hcl":return(0,d.jsx)(a$,{size:b});case"lock":return(0,d.jsx)(a2,{size:b});default:return(0,d.jsx)(aH,{size: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??[]).map(b=>({name:b.name,fullPath:(0,a5.e_)(a,b.name),isDir:b.isDir,size:b.size,children:b.isDir?[]:void 0,loaded:!b.isDir})):[]}function a7(a,b){let c=b.trim().toLowerCase();return!!(!c||a.name.toLowerCase().includes(c))||(a.children??[]).some(a=>a7(a,c))}function a8(a){return!!Array.from(a.types).includes("Files")||Array.from(a.items).some(a=>"file"===a.kind)}function a9(a){return Array.from(a.files).filter(a=>!!a.name)}function ba(a,b){return a===b?".":(0,a5.qP)(a,b)}function bb({node:a,depth:b,cwd:c,onOpenFile:f,onExploreFile:g,onAtMention:h,expandedPaths:i,onToggleExpanded:j,onUploadFiles:k,uploadTargetPath:l,refreshKey:m,searchQuery:n}){let o=!!n?.trim(),p=o?a.isDir:i.has(a.fullPath),[q,r]=(0,e.useState)(a.children??[]),[s,t]=(0,e.useState)(a.loaded??!1),[u,v]=(0,e.useState)(!1),[w,x]=(0,e.useState)(!1),[y,z]=(0,e.useState)(!1),A=a.isDir&&(y||l===a.fullPath),B=!!h&&w,C=!!g&&w&&!a.isDir&&a.name.toLowerCase().endsWith(".h5ad"),D=B||C,E=o?q.filter(a=>a7(a,n??"")):q,F=(0,e.useCallback)(async(b=!1)=>{if(!s||b){v(!0);try{let b=await a6(a.fullPath);r(b),t(!0)}catch{}finally{v(!1)}}},[s,a.fullPath]);(0,e.useRef)(s);let G=(0,e.useCallback)(()=>{if(a.isDir){let b=!p;j(a.fullPath,b),b&&!s&&F()}else f(a.fullPath,a.name)},[a.isDir,a.fullPath,a.name,s,p,F,f,j]),H=(0,e.useCallback)(b=>{a.isDir&&a8(b.dataTransfer)&&(b.preventDefault(),b.stopPropagation(),b.dataTransfer.dropEffect="copy",z(!0))},[a.isDir]),I=(0,e.useCallback)(b=>{a.isDir&&a8(b.dataTransfer)&&(b.preventDefault(),b.stopPropagation(),b.dataTransfer.dropEffect="copy")},[a.isDir]),J=(0,e.useCallback)(b=>{if(!a.isDir)return;let c=b.relatedTarget;c instanceof Node&&b.currentTarget.contains(c)||z(!1)},[a.isDir]),K=(0,e.useCallback)(b=>{if(!a.isDir||!a8(b.dataTransfer))return;b.preventDefault(),b.stopPropagation(),z(!1);let c=a9(b.dataTransfer);c.length>0&&(k(c,a.fullPath),p||j(a.fullPath,!0),s||F())},[F,s,a.fullPath,a.isDir,j,k,p]);return(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{onClick:G,onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),onDragEnter:H,onDragOver:I,onDragLeave:J,onDrop:K,style:{position:"relative",display:"flex",alignItems:"center",gap:4,paddingLeft:8+14*b,paddingRight:D?B&&C?146:82:8,height:24,cursor:"pointer",background:A?"rgba(37,99,235,0.14)":w?"var(--bg-hover)":"transparent",outline:A?"1px solid rgba(37,99,235,0.42)":"none",outlineOffset:-1,borderRadius:4,userSelect:"none",transition:"background 0.12s, outline-color 0.12s"},children:[a.isDir&&(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:p?"rotate(90deg)":"none",transition:"transform 0.1s"},children:(0,d.jsx)("polyline",{points:"3 2 7 5 3 8"})}),!a.isDir&&(0,d.jsx)("span",{style:{width:10,flexShrink:0}}),(0,d.jsx)("span",{style:{flexShrink:0,display:"flex",alignItems:"center"},children:a.isDir?(0,d.jsx)(aG,{size:14,open:p}):a4(a.name,14)}),(0,d.jsx)("span",{style:{fontSize:12,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},title:a.fullPath,children:a.name}),u&&(0,d.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-dim)",strokeWidth:"2",strokeLinecap:"round",children:(0,d.jsx)("path",{d:"M12 2v4M12 18v4M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M2 12h4M18 12h4"})}),D&&(0,d.jsxs)("div",{style:{position:"absolute",right:4,top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center",gap:4},children:[C&&(0,d.jsxs)("button",{onClick:b=>{b.stopPropagation(),g?.(a.fullPath,a.name)},title:"Explore H5AD",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,d.jsx)("path",{d:"M16 16l4 4"}),(0,d.jsx)("path",{d:"M8.5 11h5"}),(0,d.jsx)("path",{d:"M11 8.5v5"})]}),"@explore"]}),B&&(0,d.jsxs)("button",{onClick:b=>{b.stopPropagation(),h?.((0,a5.qP)(a.fullPath,c))},title:"Insert path into chat",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"0 8px",height:20,background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--accent)",cursor:"pointer",fontSize:11,fontWeight:600,whiteSpace:"nowrap"},children:[(0,d.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,d.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8"})]}),"@mention"]})]})]}),a.isDir&&p&&(0,d.jsxs)("div",{children:[E.map(a=>(0,d.jsx)(bb,{node:a,depth:b+1,cwd:c,onOpenFile:f,onExploreFile:g,onAtMention:h,expandedPaths:i,onToggleExpanded:j,onUploadFiles:k,uploadTargetPath:l,refreshKey:m,searchQuery:n},a.fullPath)),0===E.length&&s&&!o&&(0,d.jsx)("div",{style:{paddingLeft:8+(b+1)*14,fontSize:11,color:"var(--text-dim)",height:22,display:"flex",alignItems:"center"},children:"empty"})]})]})}function bc({cwd:a,onOpenFile:b,onExploreFile:c,refreshKey:f,onAtMention:g,searchQuery:h="",onSearchChange:i}){let[j,k]=(0,e.useState)([]),[l,m]=(0,e.useState)(!0),[n,o]=(0,e.useState)(null),[p,q]=(0,e.useState)(new Set),[r,s]=(0,e.useState)(!1),[t,u]=(0,e.useState)(null),[v,w]=(0,e.useState)(null);(0,e.useRef)(null);let x=(0,e.useRef)(null),y=(0,e.useRef)(0),z=(0,e.useCallback)((a,b)=>(m(b),o(null),a6(a).then(a=>k(a)).catch(a=>o(String(a))).finally(()=>m(!1))),[]),A=(0,e.useCallback)((a,b)=>{q(c=>{let d=new Set(c);return b?d.add(a):d.delete(a),d})},[]),B=(0,e.useCallback)(()=>{z(a,0===j.length)},[a,j.length,z]),C=(0,e.useCallback)(()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>w(null),5e3)},[]),D=(0,e.useCallback)((b,c)=>{if(0===b.length)return;y.current=0,s(!1),x.current&&clearTimeout(x.current);let d=b.reduce((a,b)=>a+b.size,0),e=ba(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}),B(),C()}else{let e=a.error??`Upload failed (HTTP ${g.status})`;w({phase:(g.status,"error"),targetPath:c,fileCount:b.length,loaded:0,total:d,message:e,details:403===g.status?["Check directory write permission or project access."]:void 0}),C()}},g.onerror=()=>{u(null),w({phase:"error",targetPath:c,fileCount:b.length,loaded:0,total:d,message:"Upload failed due to a network error"}),C()},g.onabort=()=>{u(null),w({phase:"error",targetPath:c,fileCount:b.length,loaded:0,total:d,message:"Upload canceled"}),C()},g.send(f)},[a,B,C]),E=(0,e.useCallback)(a=>{a8(a.dataTransfer)&&(a.preventDefault(),y.current+=1,s(!0))},[]),F=(0,e.useCallback)(a=>{a8(a.dataTransfer)&&(a.preventDefault(),a.dataTransfer.dropEffect="copy")},[]),G=(0,e.useCallback)(()=>{y.current-=1,y.current<=0&&(y.current=0,s(!1))},[]),H=(0,e.useCallback)(b=>{if(!a8(b.dataTransfer))return;b.preventDefault(),y.current=0,s(!1);let c=a9(b.dataTransfer);c.length>0&&D(c,a)},[a,D]),I=h.trim()?j.filter(a=>a7(a,h)):j,J=h.trim().length>0;return l?(0,d.jsx)(bd,{cwd:a,isDraggingFiles:r,uploadState:v,onDragEnter:E,onDragOver:F,onDragLeave:G,onDrop:H,children:(0,d.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:"Loading files..."})}):n?(0,d.jsx)(bd,{cwd:a,isDraggingFiles:r,uploadState:v,onDragEnter:E,onDragOver:F,onDragLeave:G,onDrop:H,children:(0,d.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"#f87171"},children:n})}):(0,d.jsx)(bd,{cwd:a,isDraggingFiles:r,uploadState:v,onDragEnter:E,onDragOver:F,onDragLeave:G,onDrop:H,children:(0,d.jsxs)("div",{style:{padding:"2px 4px"},children:[I.map(e=>(0,d.jsx)(bb,{node:e,depth:0,cwd:a,onOpenFile:b,onExploreFile:c,onAtMention:g,expandedPaths:p,onToggleExpanded:A,onUploadFiles:D,uploadTargetPath:t,refreshKey:f,searchQuery:h},e.fullPath)),0===I.length&&(0,d.jsx)("div",{style:{padding:"8px 12px",fontSize:11,color:"var(--text-dim)"},children:J?"No matching files":"No files found"})]})})}function bd({cwd:a,isDraggingFiles:b,uploadState:c,onDragEnter:e,onDragOver:f,onDragLeave:g,onDrop:h,children:i}){let j=c&&c.total>0?Math.max(0,Math.min(100,Math.round(c.loaded/c.total*100))):c?.phase==="uploading"?8:100,k=c?.phase==="success"?"#22c55e":c?.phase==="warning"?"#f59e0b":c?.phase==="error"?"#ef4444":"var(--accent)";return(0,d.jsxs)("div",{onDragEnter:e,onDragOver:f,onDragLeave:g,onDrop:h,style:{position:"relative",display:"flex",flexDirection:"column",height:"100%",minHeight:0,outline:b?"1px solid rgba(37,99,235,0.45)":"none",outlineOffset:-1,background:b?"rgba(37,99,235,0.04)":void 0,transition:"background 0.12s, outline-color 0.12s"},children:[(0,d.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",overscrollBehavior:"contain",scrollbarWidth:"thin"},children:i}),b&&(0,d.jsx)("div",{style:{pointerEvents:"none",position:"absolute",inset:6,top:42,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",strokeLinejoin:"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 ",ba(a,a)]})}),c&&(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)"},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:k,flexShrink:0}}),(0,d.jsx)("span",{title:c.message,style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text)",fontSize:11,fontWeight:600},children:c.message}),(0,d.jsx)("span",{style:{color:"var(--text-dim)",fontSize:10,flexShrink:0},children:"uploading"===c.phase?`${j}%`: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]}`}(c.total)})]}),(0,d.jsx)("div",{style:{marginTop:6,height:3,borderRadius:999,background:"var(--bg)",overflow:"hidden"},children:(0,d.jsx)("div",{style:{width:`${j}%`,height:"100%",borderRadius:999,background:k,transition:"width 0.15s ease"}})}),c.details&&c.details.length>0&&(0,d.jsx)("div",{style:{marginTop:5,display:"grid",gap:2},children:c.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))})]})]})}function be({cwd:a,refreshKey:b=0,onOpenFile:c,onExploreFile:f,onAtMention:g}){let[h,i]=(0,e.useState)(""),[j,k]=(0,e.useState)(0);return(0,d.jsxs)("div",{style:{height:"100%",display:"flex",flexDirection:"column",background:"var(--bg)",overflow:"hidden"},children:[(0,d.jsxs)("div",{style:{padding:"9px 10px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)",flexShrink:0},children:[(0,d.jsxs)("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:2,fontSize:11,color:"var(--text-dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)"},children:a??"No project selected"})]}),(0,d.jsx)("button",{type:"button",onClick:()=>k(a=>a+1),disabled:!a,title:"Refresh files",style:{width:28,height:28,padding:0,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text-muted)",cursor:a?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center",opacity:a?1:.55},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)("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"})]})})]}),(0,d.jsxs)("div",{style:{position:"relative",marginTop:9},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:30,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)(bc,{cwd:a,onOpenFile:c,onExploreFile:f,refreshKey:j,onAtMention:g,searchQuery:h,onSearchChange:i}):(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 bf=c(32492),bg=c(2857);let bh={__soul__:{apiPath:"/api/soul",title:"SOUL.md"},__harness__:{apiPath:"/api/harness",title:"HARNESS.md"}};function bi({filePath:a}){let b=bh[a],{isDark:c}=(0,bg.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)(bf.g,{initialContent:f,language:"markdown",isDark:c,onChange:g,onSave:p})})]}):null}function bj({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 bk(a){return"running"===a?"#22c55e":"starting"===a?"rgba(234,179,8,0.95)":"error"===a?"#ef4444":"var(--text-dim)"}function bl(a){return"h5adexp"===a?"H5AD Exp":"stexp"}function bm(a,b,c){return Math.min(Math.max(a,b),c)}function bn(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 bo({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=bn(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=bn(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=bn(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:bm(c,8,Math.max(8,window.innerWidth-120)),top:bm(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:bm(c,420,Math.max(420,window.innerWidth-a.left-8)),height:bm(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??bl(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??bl(a)}),(0,d.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:bk(H),flexShrink:0}}),(0,d.jsx)("span",{style:{fontSize:11,color:bk(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:bp,title:"Reload",children:"Reload"}),(0,d.jsx)("button",{type:"button",onPointerDown:a=>a.stopPropagation(),onClick:()=>s(a=>!a),style:{...bp,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:bp,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:{...bp,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:bq,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:bq,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:bq,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 ",bl(a),"..."]}):J&&l?.status!=="stopped"?(0,d.jsx)("iframe",{src:J,title:`${l?.title??bl(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:[bl(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 bp={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},bq={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 br(a){return"running"===a?"#22c55e":"starting"===a?"rgba(234,179,8,0.95)":"error"===a?"#ef4444":"var(--text-dim)"}function bs(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 bt(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 bu(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 bv({refreshKey:a=0,visibleAppId:b,cwd:c,onOpenApp:f,onAppChanged:g,onAppsChanged:h}){let[i,j]=(0,e.useState)([]),[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)(null),[u,v]=(0,e.useState)(null),[w,x]=(0,e.useState)(null),[y,z]=(0,e.useState)(null),[A,B]=(0,e.useState)(null),C=(0,e.useMemo)(()=>[...i].sort((a,b)=>{let c=+!!a.running,d=+!!b.running;return c!==d?d-c:Date.parse(b.lastActivity)-Date.parse(a.lastActivity)}),[i]),D=(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}`);j(b.apps),h?.(b.apps),p(null)}catch(a){p(a instanceof Error?a.message:String(a))}},[h]),E=(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}`);l(d),n(d.memory??null),r(null)}catch(a){r(a instanceof Error?a.message:String(a))}},[c]),F=(0,e.useCallback)(async a=>{x(a.id),p(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}`);j(a=>a.map(a=>a.id===c.app.id?c.app:a)),g?.(c.app),await D()}catch(a){p(a instanceof Error?a.message:String(a))}finally{x(null)}},[D,g]),G=(0,e.useCallback)(async a=>{z(a.sessionId),r(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 E()}catch(a){r(a instanceof Error?a.message:String(a))}finally{z(null)}},[E]),H=(0,e.useCallback)(async(a,b)=>{if(c){v(`${a}:${b}`),t(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 E()}catch(a){t(a instanceof Error?a.message:String(a))}finally{v(null)}}},[c,E]),I=i.filter(a=>a.running).length,J=i.reduce((a,b)=>a+(b.running?b.rssBytes??0:0),0),K=k?.sessions??[],L=K.filter(a=>a.busy),M=L.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:[L.length," agent running \xb7 ",I," explore \xb7 ",bt(J)]})]}),(0,d.jsx)("button",{type:"button",onClick:()=>{D(),E()},style:bA,title:"Refresh status",children:"Refresh"})]}),o&&(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:o}),q&&(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:q}),s&&(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:s})]}),(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)(bw,{title:"Agent Runtime",subtitle:M.length>0?`${M.length} waiting for model first token`:`${L.length} active chat${1===L.length?"":"s"}`}),0===K.length?(0,d.jsx)(bx,{label:"No agent runtime is active."}):(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:K.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:bs(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:bs(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)(by,{label:"uptime",value:bu(a.uptimeMs)}),(0,d.jsx)(by,{label:"wait",value:bu(a.waitingForModelMs),color:"waiting_model"===a.phase?bs(a.phase):void 0}),(0,d.jsx)(by,{label:"pending",value:null===a.pendingMessageCount?"-":String(a.pendingMessageCount)}),(0,d.jsx)(by,{label:"event",value:a.lastEventType??"-"}),(0,d.jsx)(by,{label:"tools",value:f||"-"}),(0,d.jsx)(by,{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 G(a),disabled:!a.busy||y===a.sessionId,style:{...bA,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:a.busy&&y!==a.sessionId?1:.55},children:"Abort"})})]},a.sessionId)})})]}),(0,d.jsxs)("section",{children:[(0,d.jsx)(bw,{title:"Memory",subtitle:m?`${m.count} stored \xb7 ${m.candidateCount} candidates`:c?"loading":"No project selected"}),c?m?(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)(by,{label:"fact",value:String(m.byType.fact)}),(0,d.jsx)(by,{label:"context",value:String(m.byType.context)}),(0,d.jsx)(by,{label:"decision",value:String(m.byType.decision)}),(0,d.jsx)(by,{label:"preference",value:String(m.byType.preference)}),(0,d.jsx)(by,{label:"note",value:String(m.byType.note)}),(0,d.jsx)(by,{label:"candidates",value:String(m.candidateCount),color:m.candidateCount>0?"var(--accent)":void 0})]}),(0,d.jsx)("div",{title:m.filePath,style:{marginTop:8,fontSize:11,color:"var(--text-dim)",fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(0,a5.qP)(m.filePath,c)})]}),(0,d.jsx)(bz,{title:"Promotion Candidates",emptyLabel:"No promotion candidates yet.",items:m.topCandidates,onPromote:H,busyAction:u}),(0,d.jsx)(bz,{title:"Recent Memory",emptyLabel:"No memory stored for this project.",items:m.recent})]}):(0,d.jsx)(bx,{label:"Memory status unavailable."}):(0,d.jsx)(bx,{label:"Select a project to inspect memory status."})]}),(0,d.jsxs)("section",{children:[(0,d.jsx)(bw,{title:"Explore Tools",subtitle:`${I} running \xb7 ${bt(J)}`}),0===C.length?(0,d.jsx)(bx,{label:"No explore tools are running."}):(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:C.map(a=>{let e,g=b===a.id,h=A===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:br(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)(by,{label:"status",value:a.status,color:br(a.status)}),(0,d.jsx)(by,{label:"pid",value:a.pid?String(a.pid):"-"}),(0,d.jsx)(by,{label:"memory",value:bt(a.rssBytes)}),(0,d.jsx)(by,{label:"uptime",value:bu(a.uptimeMs)}),(0,d.jsx)(by,{label:"port",value:String(a.port)}),(0,d.jsx)(by,{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:bA,children:"Open"}),(0,d.jsx)("button",{type:"button",onClick:()=>B(b=>b===a.id?null:a.id),style:{...bA,background:h?"var(--bg-selected)":"var(--bg)"},children:"Logs"}),(0,d.jsx)("button",{type:"button",onClick:()=>void F(a),disabled:!a.running||w===a.id,style:{...bA,border:"1px solid rgba(239,68,68,0.35)",color:"#ef4444",background:"rgba(239,68,68,0.08)",opacity:a.running&&w!==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 bw({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 bx({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 by({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 bz({title:a,emptyLabel:b,items:c,onPromote:e,busyAction:f}){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&&(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[(0,d.jsx)("button",{type:"button",disabled:a.promotedTo.includes("memory")||f===`${a.id}:context`||f===`${a.id}:memory`,onClick:()=>void e(a.id,"memory"),style:{...bA,height:24,padding:"0 8px",opacity:a.promotedTo.includes("memory")||f===`${a.id}:context`||f===`${a.id}:memory`?.55:1},children:a.promotedTo.includes("memory")?"In MEMORY.md":f===`${a.id}:memory`?"Saving...":"To MEMORY.md"}),(0,d.jsx)("button",{type:"button",disabled:a.promotedTo.includes("context")||f===`${a.id}:context`||f===`${a.id}:memory`,onClick:()=>void e(a.id,"context"),style:{...bA,height:24,padding:"0 8px",opacity:a.promotedTo.includes("context")||f===`${a.id}:context`||f===`${a.id}:memory`?.55:1},children:a.promotedTo.includes("context")?"In CONTEXT.md":f===`${a.id}:context`?"Saving...":"To CONTEXT.md"})]})]},a.id))})]})}let bA={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 bB({tabs:a,activeTabId:b,onSelectTab:c,onCloseTab:f}){let[g,h]=(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,i=!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"})}):a4(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}),i&&(0,d.jsx)("button",{onClick:b=>{b.stopPropagation(),f(a.id)},onMouseEnter:()=>h(a.id),onMouseLeave:()=>h(null),style:{display:"flex",alignItems:"center",justifyContent:"center",width:16,height:16,background:g===a.id?"var(--bg-hover)":"transparent",border:"none",borderRadius:3,color:g===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 bC(a){let b=a,c=0;for(;1===b.children.length;)b=b.children[0],c++;return{node:b,skipped:c}}function bD({node:a,activePathIds:b,depth:c,isLast:e,parentLines:f,onSelect:g}){let{node:h,skipped:i}=bC(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)(bD,{node:a,activePathIds:b,depth:c+1,isLast:i===h.children.length-1,parentLines:[...f,!e],onSelect:g},a.entry.id))]})}function bE({tree:a,activeLeafId:b,onLeafChange:c,inline:f,containerRef:g,open:h,onToggle:i,hasSession:j}){let[k,l]=(0,e.useState)(!1),m=void 0!==h?h:k,n=(0,e.useRef)(null),[o,p]=(0,e.useState)(null),q=(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]),r=(0,e.useCallback)(a=>{c(a)},[c]),s=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",t=a.length>0?bC(a[0]):null,u=t?.node??null,v=!s&&u&&u.children.length>1,w=(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:v?"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"})]}),x=(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:m?"rotate(180deg)":"none",transition:"transform 0.15s"},children:(0,d.jsx)("polyline",{points:"2 3.5 5 6.5 8 3.5"})});return f?(0,d.jsxs)("div",{style:{height:"100%",display:"flex",alignItems:"stretch"},children:[(0,d.jsxs)("button",{ref:n,className:"topbar-branches-button",onClick:()=>i?i():l(a=>!a),title:"Branches","aria-label":"Branches",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:m?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${m?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:m?"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=m?"var(--text)":"var(--text-muted)",a.currentTarget.style.background=m?"var(--bg-selected)":"var(--bg-panel)"},children:[(0,d.jsx)("span",{className:"topbar-branches-icon",children:w}),(0,d.jsx)("span",{className:"topbar-branches-label",children:"Branches"})]}),m&&o&&(0,d.jsx)("div",{style:{position:"fixed",top:o.top,left:o.left,width:o.width,background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",zIndex:500},children:v&&u?(0,d.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:u.children.map((a,b)=>(0,d.jsx)(bD,{node:a,activePathIds:q,depth:0,isLast:b===u.children.length-1,parentLines:[],onSelect:r},a.entry.id))}):(0,d.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:s})})]}):(0,d.jsxs)("div",{style:{borderBottom:"1px solid var(--border)",background:"var(--bg)",flexShrink:0,position:"relative"},children:[(0,d.jsxs)("button",{onClick:()=>l(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:[w,(0,d.jsx)("span",{style:{color:"var(--text-muted)"},children:"Branches"}),x]}),m&&(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:v&&u?(0,d.jsx)("div",{style:{padding:"4px 12px 8px 12px",maxHeight:260,overflowY:"auto"},children:u.children.map((a,b)=>(0,d.jsx)(bD,{node:a,activePathIds:q,depth:0,isLast:b===u.children.length-1,parentLines:[],onSelect:r},a.entry.id))}):(0,d.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:s??"This session has no branches"})})]})}function bF(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 bG=bF((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"})),bH=bF((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"})),bI=bF((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"})]})),bJ=bF((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"})]})),bK=bF((0,d.jsx)("path",{d:"M4 4h16v16H4z",fill:"#F55036"}),"0 0 24 24"),bL=bF((0,d.jsx)("path",{d:"M4 4h5v5H4zm5.5 0h5v5h-5zM15 4h5v5h-5zM4 9.5h5v5H4zm5.5 5.5h5v5h-5zM15 9.5h5v5h-5z",fill:"#FA6F00"})),bM=bF((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),bN=bF((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"})]})),bO=bF((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#FF5722"}),"0 0 24 24"),bP=bF((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"})),bQ=bF((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"})]})),bR=bF((0,d.jsx)("path",{d:"M12 2l9 5v10l-9 5-9-5V7l9-5z",stroke:"currentColor",strokeWidth:"1.5",fill:"none"})),bS=bF((0,d.jsx)("path",{d:"M4 4l8 8 8-8M4 20l8-8 8 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})),bT=bF((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"})),bU={anthropic:{Icon:bG,hasColor:!1},openai:{Icon:bH,hasColor:!1},"openai-codex":{Icon:bH,hasColor:!1},google:{Icon:bI,hasColor:!0},"google-vertex":{Icon:bI,hasColor:!0},deepseek:{Icon:bJ,hasColor:!0},groq:{Icon:bK,hasColor:!1},mistral:{Icon:bL,hasColor:!0},moonshotai:{Icon:bM,hasColor:!1},"moonshotai-cn":{Icon:bM,hasColor:!1},moonshot:{Icon:bM,hasColor:!1},minimax:{Icon:bN,hasColor:!0},"minimax-cn":{Icon:bN,hasColor:!0},fireworks:{Icon:bO,hasColor:!0},huggingface:{Icon:bP,hasColor:!0},cerebras:{Icon:bQ,hasColor:!0},openrouter:{Icon:bR,hasColor:!1},xai:{Icon:bS,hasColor:!1},"cloudflare-ai-gateway":{Icon:bT,hasColor:!0},"cloudflare-workers-ai":{Icon:bT,hasColor:!0},"vercel-ai-gateway":{Icon:bF((0,d.jsx)("path",{d:"M12 2L22 20H2L12 2z",fill:"currentColor"})),hasColor:!1},"github-copilot":{Icon:bF((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:bF((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:bF((0,d.jsx)("path",{d:"M12 2L3 18h5l4-6 4 6h5L12 2z",fill:"#0078D4"})),hasColor:!0},"kimi-coding":{Icon:bF((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:bF((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:bF((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:bF((0,d.jsx)("path",{d:"M4 8h16v2H4zm0 4h12v2H4zm0 4h8v2H4z",fill:"#3059B1"})),hasColor:!0},perplexity:{Icon:bF((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:bF((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"#0F6CBD"}),"0 0 24 24"),hasColor:!0},grok:{Icon:bF((0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5",fill:"none"}),"0 0 24 24"),hasColor:!1}},bV=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"],bW="openai-completions",bX={off:"none",xhigh:"xhigh"};function bY(a){let b=a?.toLowerCase().replace(/\s+/g,"-")??"";return/(^|[^a-z0-9])gpt-5($|[.-])/.test(b)}function bZ(a,b=bW){return bY(a.id)||bY(a.name)?{...a,api:a.api??("openai-responses"===b?void 0:"openai-responses"),reasoning:a.reasoning??!0,thinkingLevelMap:a.thinkingLevelMap??bX}:a}function b$({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 b_={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 b0({value:a,onChange:b,placeholder:c,mono:e}){return(0,d.jsx)("input",{value:a,onChange:a=>b(a.target.value),placeholder:c,style:{...b_,fontFamily:e?"var(--font-mono)":"inherit"}})}function b1({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:{...b_,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 b2({value:a,onChange:b,placeholder:c}){return(0,d.jsx)("input",{type:"number",value:a,onChange:a=>b(a.target.value),placeholder:c,style:b_})}function b3({value:a,onChange:b,options:c,required:e}){return(0,d.jsxs)("select",{value:a,onChange:a=>b(a.target.value),style:{...b_,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 b4({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 b5({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 b6({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)(b5,{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)(b$,{label:"Provider name",children:[(0,d.jsx)(b0,{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)(b$,{label:"Base URL",children:(0,d.jsx)(b0,{value:b.baseUrl??"",onChange:a=>j("baseUrl",a||void 0),placeholder:"https://api.example.com/v1",mono:!0})}),(0,d.jsxs)(b$,{label:"API Key",children:[(0,d.jsx)(b1,{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)(b$,{label:"API",children:(0,d.jsx)(b3,{value:b.api??"openai-completions",onChange:a=>j("api",a),options:bV,required:!0})})]})}let b7=["off","minimal","low","medium","high","xhigh"],b8={off:"var(--text-dim)",minimal:"#6b7280",low:"#60a5fa",medium:"#a78bfa",high:"#f472b6",xhigh:"#fb923c"};function b9({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:b7.map(a=>{let b=c[a],f=a in c?null===b?"null":"string":"omit",g="string"==typeof b?b:"",h=b8[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 ca={thinkingFormat:"deepseek",requiresReasoningContentOnAssistantMessages:!0};function cb({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(bZ(a,b.api??bW))},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)(b5,{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)(b$,{label:"ID *",children:(0,d.jsx)(b0,{value:c.id,onChange:a=>k({...c,id:a}),placeholder:"model-id",mono:!0})}),(0,d.jsx)(b$,{label:"Name",children:(0,d.jsx)(b0,{value:c.name??"",onChange:a=>k({...c,name:a||void 0}),placeholder:"Display name"})})]}),(0,d.jsx)(b$,{label:"API override",children:(0,d.jsx)(b3,{value:c.api??"",onChange:a=>j("api",a||void 0),options:bV})}),(0,d.jsxs)("div",{style:{display:"flex",gap:20,flexWrap:"wrap"},children:[(0,d.jsx)(b4,{label:"Reasoning / thinking",checked:c.reasoning??!1,onChange:a=>j("reasoning",a||void 0)}),(0,d.jsx)(b4,{label:"Image input",checked:c.input?.includes("image")??!1,onChange:a=>j("input",a?["text","image"]:void 0)})]}),c.reasoning&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(b4,{label:"DeepSeek thinking compat",checked:c.compat?.thinkingFormat==="deepseek",onChange:a=>f(function(a,b){if(b)return{...a,compat:{...a.compat??{},...ca}};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)(b5,{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)(b9,{value:c.thinkingLevelMap,onChange:a=>j("thinkingLevelMap",a)})]})]}),(0,d.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[(0,d.jsx)(b$,{label:"Context window (tokens)",children:(0,d.jsx)(b2,{value:void 0!==c.contextWindow?String(c.contextWindow):"",onChange:a=>j("contextWindow",a?parseInt(a):void 0),placeholder:"128000"})}),(0,d.jsx)(b$,{label:"Max output tokens",children:(0,d.jsx)(b2,{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)(b5,{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)(b$,{label:a,children:(0,d.jsx)(b2,{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 cc({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)(b5,{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 cd({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)(b5,{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)(b$,{label:"API Key",children:(0,d.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,d.jsx)(b1,{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 ce({id:a,size:b}){let c=bU[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 cf({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)(ce,{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)(ce,{id:a.id,size:28})]},a.id))]})})]})})}function cg({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)(b$,{label:"Base URL",children:(0,d.jsx)(b0,{value:f,onChange:g,placeholder:"https://api.example.com",mono:!0})}),(0,d.jsx)(b$,{label:"API Key",children:(0,d.jsx)(b1,{value:h,onChange:i,placeholder:"optional for local providers",mono:!0})}),(0,d.jsx)(b$,{label:"Provider name",children:(0,d.jsx)(b0,{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??bW,o=0;for(let a of q.piModels)l.has(a.id)&&!m.has(a.id)&&(m.set(a.id,bZ(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 ch({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)(cc,{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)(cd,{provider:a,onRefresh:B},a.id):null}if("provider"===q.type){let a=c.providers?.[q.name];return a?(0,d.jsx)(b6,{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)(cb,{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)(ce,{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)(ce,{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)(cf,{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)(cg,{existingProviders:c.providers??{},onImport:J,onClose:()=>z(!1)})]})}function ci(a){return a.replace(/^\/(?:Users|home)\/[^/]+/,"~")}function cj(a){let b=a.sourceInfo?.source,c=a.sourceInfo?.scope;return"user"===c||"user"===b?"global":"project"===c||"project"===b?"project":"path"}function ck({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 cl({skill:a,cwd:b,onToggle:c,toggling:e,saveError:f}){let g=cj(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 ci(a)}(a.filePath)}),(0,d.jsx)(ck,{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 cm({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/":`${ci(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 cn({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:ci(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=>cj(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)(cm,{cwd:a,onInstalled:()=>{t()}}):h?null:v?(0,d.jsx)(cl,{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 co=[{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 cp(a){return a?a.replace(/^\/(?:Users|home)\/[^/]+/,"~"):""}function cq(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 cr(a){return{id:"",language:a,displayName:"",command:"python"===a?"python3":"R",argsText:JSON.stringify("python"===a?["-u"]:["--slave","--vanilla"]),envText:"{}"}}function cs(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 ct={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"},cu={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 cv({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 cw({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)(()=>cr("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(cr(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 ${cq(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:{...ct,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:{...ct,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:co.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 ${cq(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:{...ct,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:{...ct,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:cp(f?.paths.global??"")})]}),a&&(0,d.jsxs)("div",{children:["Project: ",(0,d.jsx)("code",{style:{fontFamily:"var(--font-mono)",wordBreak:"break-all"},children:cp(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(cs(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)(cv,{label:"Command",children:(0,d.jsx)("input",{readOnly:!0,value:K.command,style:{...cu,color:"var(--text-muted)"}})}),(0,d.jsx)(cv,{label:"Args",children:(0,d.jsx)("input",{readOnly:!0,value:JSON.stringify(K.args),style:{...cu,color:"var(--text-muted)"}})})]}),(0,d.jsx)(cv,{label:"Environment",children:(0,d.jsx)("textarea",{readOnly:!0,value:JSON.stringify(K.env,null,2),rows:5,style:{...cu,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:{...ct,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:{...ct,opacity:"default"===j?.6:1},children:"Set default"}),(0,d.jsx)("button",{type:"button",onClick:()=>{u("edit"),s(K.id),w(cs(K)),m(null),o(null)},style:ct,children:"Edit"}),!K.id.startsWith("default-")&&(0,d.jsx)("button",{type:"button",onClick:()=>void Q(K),disabled:"delete"===j,style:{...ct,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)(cv,{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:{...cu,color:"edit"===t?"var(--text-muted)":"var(--text)"}})}),(0,d.jsx)(cv,{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:cu})})]}),(0,d.jsx)(cv,{label:"Command",children:(0,d.jsx)("input",{value:v.command,onChange:a=>w(b=>({...b,command:a.target.value})),placeholder:"/usr/bin/python3",style:cu})}),(0,d.jsx)(cv,{label:"Args JSON",children:(0,d.jsx)("input",{value:v.argsText,onChange:a=>w(b=>({...b,argsText:a.target.value})),style:cu})}),(0,d.jsx)(cv,{label:"Env JSON",children:(0,d.jsx)("textarea",{value:v.envText,onChange:a=>w(b=>({...b,envText:a.target.value})),rows:6,style:{...cu,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:{...ct,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(cs(a)),u("view")):R(),m(null)},style:ct,children:"Cancel"})]})]})})]})]})}var cx=c(39868);function cy({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,cx.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 cz="annovibe-im-gateway";function cA({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:cE(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:cE(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)(cH,{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)(cD,{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)(cB,{status:i}):null,(0,d.jsx)(cF,{label:"Bot ID",value:k,onChange:l,placeholder:"从企业微信 AI bot 控制台获取"}),(0,d.jsx)(cF,{label:c?.hasSecret?"Bot Secret(留空则不修改)":"Bot Secret",value:m,onChange:n,placeholder:c?.hasSecret?"留空保留现有 secret":"从企业微信 AI bot 控制台获取",secret:!0}),(0,d.jsx)(cD,{label:"群聊中需要 @提及 bot 才响应",description:"开启后,群聊中用户必须 @bot 才会被处理。",checked:o,disabled:w,compact:!0,onChange:p}),(0,d.jsx)(cF,{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:cK,placeholder:"用户也可通过配对码自助授权"})]}),(0,d.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[(0,d.jsx)(cG,{primary:!0,disabled:w,onClick:H,children:w?"保存中…":"保存 IM 配置"}),(0,d.jsx)(cG,{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)(cC,{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)(cG,{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)(cC,{label:"Gateway 启动命令",value:cz,copyLabel:"复制命令",mono:!0}),(0,d.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["启动 ",(0,d.jsx)("code",{style:cI,children:"annovibe"})," 后,在",(0,d.jsx)("strong",{style:{color:"var(--text-muted)",fontWeight:600},children:"同一 Linux 账户"}),"中运行"," ",(0,d.jsx)("code",{style:cI,children:cz}),"。 Gateway 通过本地 API 读取已启用的项目配置和 bot secret —— 无需手动复制文件。"]}),(0,d.jsxs)("div",{style:{lineHeight:1.55,color:"var(--text-dim)"},children:["配对码与白名单: ",(0,d.jsxs)("code",{style:cI,children:["~/.pi/agent/im/","<project>",".json"]})]}),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 cB({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 cC({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:{...cI,...e?{wordBreak:"break-all"}:{}},children:b})]}),(0,d.jsx)(cy,{text:b,label:c})]})}function cD({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 cE(a){return a.split(/\r?\n/).map(a=>a.trim()).filter(Boolean)}function cF({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:cJ})]})}function cG({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 cH({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 cI={fontFamily:"var(--font-mono)",fontSize:"0.95em"},cJ={height:30,padding:"0 8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)"},cK={padding:"8px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text)",fontSize:12,fontFamily:"var(--font-mono)",resize:"vertical"};function cL({activeCwd:a,onSelectProject:b,onProjectsChanged:c}){let[f,g]=(0,e.useState)([]),[h,i]=(0,e.useState)(!0),[j,l]=(0,e.useState)(null),[m,n]=(0,e.useState)(""),[o,p]=(0,e.useState)(!1),[q,r]=(0,e.useState)(null),[s,t]=(0,e.useState)(null),[u,v]=(0,e.useState)(""),[w,x]=(0,e.useState)(new Set),[y,z]=(0,e.useState)(null),[A,B]=(0,e.useState)(null),C=(0,e.useRef)(null),D=(0,e.useCallback)(async()=>{try{i(!0);let a=await fetch("/api/projects"),b=await a.json();if(!a.ok||b.error)throw Error(b.error??`HTTP ${a.status}`);g(b.projects??[]),l(null)}catch(a){l(a instanceof Error?a.message:String(a))}finally{i(!1)}},[]),E=(0,e.useMemo)(()=>({projects:f.length,chats:f.reduce((a,b)=>a+b.chatCount,0)}),[f]),F=(0,e.useCallback)(async()=>{let a=m.trim();if(a){r("add"),l(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}`);n(""),c?.(),b?.(a),D()}catch(a){l(a instanceof Error?a.message:String(a))}finally{r(null)}}},[D,c,b,m]),G=(0,e.useCallback)(async a=>{r("add"),l(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}`);n(""),p(!1),c?.(),b?.(a),D()}catch(a){l(a instanceof Error?a.message:String(a))}finally{r(null)}},[D,c,b]),H=(0,e.useCallback)(async a=>{r(`rename:${a}`),l(null);try{let b=await fetch("/api/projects",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:a,name:u})}),d=await b.json();if(!b.ok||d.error)throw Error(d.error??`HTTP ${b.status}`);t(null),v(""),await D(),c?.()}catch(a){l(a instanceof Error?a.message:String(a))}finally{r(null)}},[D,c,u]),I=(0,e.useCallback)(async a=>{r(`remove:${a}`),l(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}`);await D(),c?.()}catch(a){l(a instanceof Error?a.message:String(a))}finally{r(null)}},[D,c]),J=(0,e.useCallback)(a=>{t(a.cwd),v(a.displayName),requestAnimationFrame(()=>C.current?.focus())},[]),K=(0,e.useCallback)(a=>{x(b=>{let c=new Set(b);return c.has(a)?c.delete(a):c.add(a),c})},[]),L=(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{D()}},[D,c]),M=(0,e.useCallback)((a,b)=>{"reorder"!==q&&(z(a),b.dataTransfer.effectAllowed="move",b.dataTransfer.setData("text/project-cwd",a))},[q]),N=(0,e.useCallback)((a,b)=>{b.preventDefault(),b.dataTransfer.dropEffect="move",B(a)},[]),O=(0,e.useCallback)(a=>{if(B(null),!y||y===a)return void z(null);let b=f.map(a=>a.cwd).filter(Boolean),c=b.indexOf(y),d=b.indexOf(a);c<0||d<0?z(null):(b.splice(c,1),b.splice(d,0,y),g(a=>{let c=new Map(a.map(a=>[a.cwd,a]));return b.map(a=>c.get(a)).filter(Boolean)}),z(null),L(b))},[y,L,f]),P=(0,e.useCallback)(()=>{z(null),B(null)},[]);return(0,d.jsxs)("div",{style:{height:"100%",overflowY:"auto"},children:[j&&(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:j}),(0,d.jsx)("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:14,padding:"10px 12px",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)"},children:(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,d.jsxs)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:650,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[E.projects," Projects, ",E.chats," Chats"]}),(0,d.jsx)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11},children:"Settings → Projects"})]})}),(0,d.jsxs)("div",{style:{display:"flex",gap:8,marginBottom:14},children:[(0,d.jsx)("div",{style:{position:"relative",flex:1,minWidth:0},children:(0,d.jsx)("input",{type:"text",value:m,onChange:a=>n(a.target.value),onKeyDown:a=>{"Enter"===a.key&&F()},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"===q,onClick:()=>void F(),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:()=>p(!0),style:{height:30,padding:"0 11px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Browse…"})]}),h&&(0,d.jsx)("div",{style:{padding:"16px 0",color:"var(--text-muted)",fontSize:12},children:"Loading projects..."}),!h&&(0,d.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:f.map(c=>{var e;let f,g=c.lastAccessed??c.created??null,h=c.cwd===a,i=s===c.cwd,j=w.has(c.cwd),k=y===c.cwd,l=A===c.cwd&&y!==c.cwd;return(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"12px 14px",border:`1px solid ${l?"rgba(37,99,235,0.45)":h?"color-mix(in srgb, var(--accent) 40%, var(--border))":"var(--border)"}`,borderRadius:8,background:l?"rgba(37,99,235,0.06)":h?"color-mix(in srgb, var(--accent) 8%, var(--bg-panel))":"var(--bg-panel)",opacity:k?.55:1,transition:"background 0.12s, box-shadow 0.12s"},onDragOver:a=>N(c.cwd,a),onDrop:()=>O(c.cwd),children:[(0,d.jsx)("div",{draggable:!0,onDragStart:a=>M(c.cwd,a),onDragEnd:P,title:"Drag to reorder",style:{display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-dim)",cursor:"reorder"===q?"wait":"grab",opacity:"reorder"===q?.65:1,flexShrink:0},children:(0,d.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":"true",children:[(0,d.jsx)("circle",{cx:"3",cy:"2.5",r:"1"}),(0,d.jsx)("circle",{cx:"9",cy:"2.5",r:"1"}),(0,d.jsx)("circle",{cx:"3",cy:"6",r:"1"}),(0,d.jsx)("circle",{cx:"9",cy:"6",r:"1"}),(0,d.jsx)("circle",{cx:"3",cy:"9.5",r:"1"}),(0,d.jsx)("circle",{cx:"9",cy:"9.5",r:"1"})]})}),(0,d.jsxs)("div",{style:{minWidth:0,flex:1},children:[i?(0,d.jsx)("input",{ref:C,value:u,onChange:a=>v(a.target.value),onKeyDown:a=>{"Enter"===a.key&&H(c.cwd),"Escape"===a.key&&t(null)},style:{width:"min(360px, 100%)",height:30,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:13,fontWeight:h?750:650,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.displayName}),(0,d.jsx)("div",{style:{marginTop:4,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:c.cwd,children:(f=(e=c.cwd).split(/[\\/]/).filter(Boolean)).length<=3?e:`.../${f.slice(-3).join("/")}`}),(0,d.jsxs)("div",{style:{marginTop:5,color:"var(--text-muted)",fontSize:11},children:[c.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()}(g),c.exists?"":" / path missing"]})]}),(0,d.jsx)("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:i?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("button",{type:"button",disabled:q===`rename:${c.cwd}`,onClick:()=>void H(c.cwd),style:{height:28,padding:"0 9px",border:"none",borderRadius:6,background:"var(--accent)",color:"#fff",cursor:"pointer",fontSize:12},children:"Save"}),(0,d.jsx)("button",{type:"button",onClick:()=>t(null),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Cancel"})]}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("button",{type:"button",onClick:()=>b?.(c.cwd),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:h?"var(--accent)":"var(--bg-panel)",color:h?"#fff":"var(--text-muted)",cursor:"pointer",fontSize:12},children:h?"Current":"Switch"}),(0,d.jsxs)("button",{type:"button",onClick:()=>K(c.cwd),"aria-expanded":j,style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:j?"var(--bg-selected)":"var(--bg-panel)",color:j?"var(--accent)":"var(--text-muted)",cursor:"pointer",fontSize:12,display:"inline-flex",alignItems:"center",gap:4},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",style:{transform:j?"rotate(90deg)":"none",transition:"transform 0.15s",flexShrink:0},children:(0,d.jsx)("polyline",{points:"3 2 7 5 3 8"})}),"WeCom IM"]}),(0,d.jsx)("button",{type:"button",onClick:()=>J(c),style:{height:28,padding:"0 9px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:"Rename"}),(0,d.jsx)("button",{type:"button",disabled:q===`remove:${c.cwd}`,onClick:()=>void I(c.cwd),style:{height:28,padding:"0 9px",border:"1px solid rgba(248,113,113,0.35)",borderRadius:6,background:"transparent",color:"#f87171",cursor:"pointer",fontSize:12},children:"Remove"})]})})]}),j&&(0,d.jsx)("div",{style:{padding:"0 14px 14px",border:"1px solid var(--border)",borderTop:"none",borderRadius:"0 0 8px 8px",background:"var(--bg-panel)"},children:(0,d.jsx)(cA,{cwd:c.cwd,embedded:!0})})]},c.cwd)})}),(0,d.jsx)(k,{open:o,initialPath:a,onClose:()=>p(!1),onSelect:a=>void G(a)})]})}function cM({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 cN(){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 cO(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"})]}):"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 cP({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:cO("projects")},{id:"models",label:"Models",description:"~/.pi/agent/models.json",icon:cO("models")},{id:"skills",label:"Skills",description:a?"Project and global skills":"Select a project first",disabled:!a,icon:cO("skills")},{id:"generative-ui",label:"Generative UI",description:b?"Enabled":"Disabled",icon:cO("generative-ui")},{id:"workbench-runtime",label:"Workbench Runtime",description:a?"Python / R runtime lifecycle":"Global runtime lifecycle",icon:cO("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)(cN,{})}),(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)(cL,{activeCwd:a,onSelectProject:i,onProjectsChanged:j}),"models"===k&&(0,d.jsx)(ch,{embedded:!0,onClose:()=>{h?.(),g()}}),"skills"===k&&a&&(0,d.jsx)(cn,{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)(cM,{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)(cw,{cwd:a})]})]})]})})}function cQ(a){return a?a.replace(/^\/(?:Users|home)\/[^/]+/,"~"):""}function cR(a){return!Number.isFinite(a)||a<=0?"0.0G":`${(a/1024/1024/1024).toFixed(1)}G`}let cS={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 cT({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)(""),[o,p]=(0,e.useState)(""),[q,r]=(0,e.useState)(!1),[s,t]=(0,e.useState)([]),[u,v]=(0,e.useState)(""),[w,x]=(0,e.useState)(!1),[y,z]=(0,e.useState)(null),A=(0,e.useCallback)(async a=>{if(a){x(!0),z(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();t(d.entries),v(d.path)}catch(a){z(a instanceof Error?a.message:String(a)),t([])}finally{x(!1)}}},[]),B=(0,e.useCallback)(()=>{a&&(r(!0),A(a))},[a,A]),C=(0,e.useCallback)(a=>{A(u?`${u.replace(/\/+$/,"")}/${a}`:a)},[u,A]),D=(0,e.useCallback)(a=>{n(u?`${u.replace(/\/+$/,"")}/${a}`:a),r(!1)},[u]),E="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: ${cQ(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:"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:m,onChange:a=>n(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:B,disabled:!a||f,title:"Browse project files",style:{...cS,whiteSpace:"nowrap",opacity:!a||f?.5:1,cursor:!a||f?"not-allowed":"pointer"},children:q?"Collapse":"Browse"})]})]}),q&&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:()=>{r(!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:"|"}),u?(()=>{let a=u.replace(/^\/+/,"").split("/"),b=[];for(let c=0;c<a.length;c++){let d="/"+a.slice(0,c+1).join("/");b.push({label:0===c?cQ(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:()=>A(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..."})]}),w?(0,d.jsx)("div",{style:{padding:"16px 10px",color:"var(--text-dim)",textAlign:"center"},children:"Loading..."}):y?(0,d.jsx)("div",{style:{padding:"16px 10px",color:"#f87171",textAlign:"center"},children:y}):0===s.length?(0,d.jsx)("div",{style:{padding:"16px 10px",color:"var(--text-dim)",textAlign:"center"},children:"empty directory"}):(0,d.jsxs)("div",{children:[u!==a&&(0,d.jsxs)("div",{onClick:()=>{A(u.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:".."})]}),s.map(a=>{let b,c=!a.isDir&&(b=a.name.toLowerCase(),E.some(a=>b.endsWith(a)));return(0,d.jsxs)("div",{onClick:()=>{a.isDir?C(a.name):D(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:o,onChange:a=>p(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 ",cR(b.totalBytes)]}),(0,d.jsxs)("span",{children:["Current session ",cR(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:cS,children:"Release current chat"}),j&&(0,d.jsx)("button",{type:"button",onClick:j,style:cS,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:cS,children:"Cancel"}),(0,d.jsx)("button",{type:"button",onClick:()=>void h({kernel:k,sourcePath:m.trim(),notes:o.trim()}),disabled:f||!a,style:{...cS,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 cU({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}}let cV=new Set(["pdf","png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]);function cW(a){return!Number.isFinite(a)||a<=0?"0.0G":`${(a/1024/1024/1024).toFixed(1)}G`}function cX(a){let b=a.toLowerCase();return b.endsWith(".rds")||b.endsWith(".qs")}function cY(a){return a.toLowerCase().endsWith(".h5ad")}function cZ(a){let b=(a.split(/[\\/]/).pop()??a).toLowerCase().split(".").pop()??"";return cV.has(b)}function c$(){let a=(0,g.useRouter)(),b=(0,g.useSearchParams)(),{isDark:c,toggleTheme:f}=(0,bg.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),[t,u]=(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=cU({initialWidth:260,minWidth:180,maxWidth:500,storageKey:"--pi-sidebar-width"}),E=cU({initialWidth:500,minWidth:300,maxWidth:1200,storageKey:"--pi-right-panel-width",direction:"left"}),F=(0,e.useRef)(null),G=(0,e.useRef)(null),[H,J]=(0,e.useState)([]),[K,L]=(0,e.useState)(null),M=(0,e.useRef)(null),N=(0,e.useCallback)((a,b,c)=>{J(a),L(b),M.current=c},[]),O=(0,e.useCallback)(a=>{M.current?.(a)},[]),[P,Q]=(0,e.useState)(null),R=(0,e.useRef)(null),[S,T]=(0,e.useState)(!1),[U,V]=(0,e.useState)(""),W=(0,e.useRef)(null),X=(0,e.useRef)(!1),Y=(0,e.useCallback)(a=>{Q(a)},[]),Z=(0,e.useCallback)(a=>a?a.name||a.firstMessage.slice(0,80)||a.id.slice(0,12):"",[]),$=(0,e.useCallback)(()=>{i&&(X.current=!1,V(i.name||Z(i)),T(!0),setTimeout(()=>W.current?.select(),0))},[Z,i]),_=(0,e.useCallback)(async()=>{if(X.current){X.current=!1,T(!1);return}if(!i)return void T(!1);let a=U.trim(),b=Z(i);if(T(!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{}},[Z,i,U]),aa=(0,e.useCallback)(a=>{"Enter"===a.key?(a.preventDefault(),_()):"Escape"===a.key&&(X.current=!0,T(!1))},[_]),ab=(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]),[ac,ad]=(0,e.useState)(null),ae=(0,e.useCallback)(a=>{ad(a)},[]),[af,ag]=(0,e.useState)(null),ah=(0,e.useCallback)(a=>{ag(a)},[]),[ai,aj]=(0,e.useState)(null),[ak,al]=(0,e.useState)(null),[am,an]=(0,e.useState)(!1),[ao,ap]=(0,e.useState)(null),[aq,ar]=(0,e.useState)(!1),[as,at]=(0,e.useState)(!1),au=(0,e.useCallback)(a=>{aj(b=>b===a?null:a)},[]),[av,aw]=(0,e.useState)([]),[ax,aA]=(0,e.useState)("files"),[aC,aE]=(0,e.useState)(!1),[aF,aG]=(0,e.useState)(null),[aH,aI]=(0,e.useState)(0),[aJ,aK]=(0,e.useState)([]),aL=(0,e.useCallback)(a=>{F.current?.insertText("`"+a+"`")},[]),[aM]=(0,e.useState)(()=>b.get("session")),[aN,aO]=(0,e.useState)(null),[aP,aQ]=(0,e.useState)(()=>!b.get("session")),aR=(0,e.useRef)(!1),aS=(0,e.useCallback)(b=>{aO(b),aG(null),an(!1),ap(null),b&&!aR.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([]),L(null),Q(null),aj(null),a.replace("/",{scroll:!1}))},[a]),aT=(0,e.useCallback)((a,b)=>{aS(a),b?.closeDialog!==!1&&w(!1),n(a=>a+1)},[aS]),aU=(0,e.useCallback)((b,c=!1)=>{l(null),aO(b.cwd),j(b),an(!1),ap(null),p(a=>a+1),Q(null),aQ(!0),c&&(aR.current=!0,setTimeout(()=>{aR.current=!1},0)),c||a.replace(`?session=${encodeURIComponent(b.id)}`,{scroll:!1})},[a]),aV=(0,e.useCallback)((b,c)=>{j(null),l(c),aO(c),an(!1),ap(null),p(a=>a+1),J([]),L(null),Q(null),aj(null),a.replace("/",{scroll:!1})},[a]),aW=(0,e.useCallback)(b=>{l(null),aO(b.cwd),j(b),an(!1),ap(null),n(a=>a+1),a.replace(`?session=${encodeURIComponent(b.id)}`,{scroll:!1}),window.dispatchEvent(new CustomEvent("session-created"))},[a]),aX=(0,e.useCallback)(()=>{n(a=>a+1),r(a=>a+1)},[]),aY=(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]),aZ=(0,e.useCallback)(()=>{aQ(!0)},[]),a$=(0,e.useCallback)(b=>{if(n(a=>a+1),i?.id===b){let b=i.cwd;j(null),l(b??null),an(!1),ap(null),p(a=>a+1),J([]),L(null),Q(null),aj(null),a.replace("/",{scroll:!1})}},[i,a]),a_=i?.cwd??k??aN??null,a0=(0,e.useCallback)((a,b)=>{if(cX(a)||cX(b))return void aG({mode:"start",appType:"stexp",filePath:a,cwd:a_,appId:null});if(cZ(a)||cZ(b)){let c=`preview:${a}`;aK(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}`;aw(d=>d.find(a=>a.id===c)?d:[...d,{id:c,label:b,filePath:a}]),aA(c),aE(!0)},[a_]),a1=(0,e.useCallback)((a,b)=>{(cY(a)||cY(b))&&aG({mode:"start",appType:"h5adexp",filePath:a,cwd:a_,appId:null})},[a_]),a2=(0,e.useCallback)(a=>{ap(a),aj(null),an(!0)},[]),a3=(0,e.useCallback)(()=>{an(!1),ap(null)},[]),a4=(0,e.useCallback)(()=>{aA("tools"),aE(!0),aI(a=>a+1)},[]),a5=(0,e.useCallback)(a=>{aG({mode:"existing",appType:a.appType,filePath:a.filePath,cwd:a.cwd,appId:a.id}),aI(a=>a+1)},[]),a6=(0,e.useCallback)(a=>{aI(a=>a+1),aG(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=>{aK(b=>b.filter(b=>b.id!==a))},[]),a8=(0,e.useCallback)(a=>{aK(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&&(aw(b=>b.filter(b=>b.id!==a)),aA(b=>{if(b!==a)return b;let c=av.filter(b=>b.id!==a);return c.length>0?c[c.length-1].id:"files"}))},[av]),ba=k??(null===i&&aN?aN:null),bb=null!==i||null!==ba,bc=aP&&!bb,bd=[{id:"files",label:"Files",closable:!1,icon:"files"},{id:"tools",label:"Status",closable:!1,icon:"tools"},...av],bf=av.find(a=>a.id===ax)??null,bh=i?Z(i):ba?"New chat":"No session",bk=i?.cwd??ba??aN??"",bl=bk?bk.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean).pop()||bk:"",bm=ao??a_,bn=(0,e.useCallback)((a="projects")=>{y(a),w(!0)},[]),[bp,bq]=(0,e.useState)(null),[br,bs]=(0,e.useState)(null),[bt,bu]=(0,e.useState)(null);i?.id;let bw=bp?.totalBytes??0,bx=bp?.currentSessionBytes??0,by=(0,e.useCallback)(async()=>{let a=new URLSearchParams;a_&&a.set("cwd",a_),i?.id&&a.set("sessionId",i.id);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}`);bq(c),bs(null)}catch(a){bs(a instanceof Error?a.message:String(a))}},[i?.id,a_]),bz=(0,e.useCallback)(async()=>{if(i?.id&&!bt){bu("all"),bs(null);try{let a=await fetch("/api/plot-kernels/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:i.id})}),b=await a.json();if(!a.ok||b.error)throw Error(b.error??`HTTP ${a.status}`);window.setTimeout(()=>{by()},600)}catch(a){bs(a instanceof Error?a.message:String(a))}finally{bu(null)}}},[by,bt,i?.id]),bA=(0,e.useCallback)(async b=>{let c;if(!bm||aq)return;ar(!0),bs(null);let d=new Date().toISOString(),e=`Workbench \xb7 ${"r"===b.kernel?"R":"Python"}`,f=(c=["Workbench session start.","",`Kernel: ${"r"===b.kernel?"R":"Python"}`],b.sourcePath?c.push(`Primary source: ${b.sourcePath}`):c.push("Primary source: none selected"),b.notes&&(c.push("Notes:"),c.push(b.notes)),c.push("",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` when working with data already in warm memory or when saving final artifacts. 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.join("\n"));try{let c=await fetch("/api/agent/new",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:bm,type:"prompt",message:f,toolNames:I("workbench"),sessionName:e,workbenchMeta:{sourcePath:b.sourcePath,kernel:b.kernel}})}),g=await c.json().catch(()=>({}));if(!c.ok||g.error||!g.sessionId)throw Error(g.error??`HTTP ${c.status}`);a3(),l(null),aO(bm),j({id:g.sessionId,path:"",cwd:bm,name:e,created:d,modified:d,messageCount:1,firstMessage:f}),J([]),L(null),Q(null),aj(null),p(a=>a+1),n(a=>a+1),a.replace(`?session=${encodeURIComponent(g.sessionId)}`,{scroll:!1}),window.setTimeout(()=>{by()},600)}catch(a){bs(a instanceof Error?a.message:String(a))}finally{ar(!1)}},[a3,by,a,aq,bm]),bC=(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(s,{selectedSessionId:i?.id??null,onSelectSession:aU,onNewSession:aV,onNewWorkbench:a2,initialSessionId:aM,onInitialRestoreDone:aZ,refreshKey:m,onSessionDeleted:a$,selectedCwd:i?.cwd??k??aN??null,onCwdChange:aS}),(0,d.jsx)("div",{style:{padding:"8px",flexShrink:0},children:(0,d.jsx)("button",{type:"button",onClick:()=>bn("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:bC}),B&&(0,d.jsx)(bj,{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:S&&i?(0,d.jsx)("input",{ref:W,value:U,onChange:a=>V(a.target.value),onKeyDown:aa,onBlur:()=>void _(),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:bh,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:bh}),i&&(0,d.jsx)("button",{type:"button",className:"topbar-rename-button",onClick:$,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.jsxs)("div",{className:"topbar-chat-tools",style:{display:"flex",alignItems:"center",gap:6,height:28,flexShrink:0},children:[(0,d.jsx)("div",{className:"topbar-branches-control",style:{height:"100%",display:"flex",alignItems:"stretch"},children:(0,d.jsx)(bE,{tree:H,activeLeafId:K,onLeafChange:O,inline:!0,containerRef:G,open:"branches"===ai,onToggle:()=>au("branches"),hasSession:!!i})}),(0,d.jsxs)("button",{ref:R,className:"topbar-system-button",onClick:()=>au("system"),title:"System prompt","aria-label":"System prompt",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:"system"===ai?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${"system"===ai?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:"system"===ai?"var(--text)":"var(--text-muted)",fontSize:11,whiteSpace:"nowrap",transition:"color 0.1s, background 0.1s"},onMouseEnter:a=>{a.currentTarget.style.color="var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color="system"===ai?"var(--text)":"var(--text-muted)",a.currentTarget.style.background="system"===ai?"var(--bg-selected)":"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:{color:P?"var(--accent)":"var(--text-dim)",flexShrink:0},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"})]}),(0,d.jsx)("span",{className:"topbar-system-label",children:"System"})]}),(0,d.jsxs)("button",{type:"button",className:"topbar-plot-button",onClick:()=>{aj(null),a4()},title:bw>0?`Open Workbench runtime \xb7 ${cW(bw)}`:"Open Workbench runtime status","aria-label":bw>0?`Open Workbench runtime \xb7 ${cW(bw)}`:"Open Workbench runtime status",style:{display:"flex",alignItems:"center",gap:6,height:28,padding:"0 9px",background:am?"var(--bg-selected)":bw>0||as?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${am||bw>0||as?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:bw>0||as?"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=bw>0||as?"var(--accent)":"var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color=bw>0||as?"var(--accent)":"var(--text-muted)",a.currentTarget.style.background=am?"var(--bg-selected)":bw>0||as?"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"}),bw>0&&(0,d.jsx)("span",{className:"topbar-plot-memory",children:cW(bw)})]})]}),bb&&h&&(0,d.jsxs)("button",{type:"button",className:"topbar-plot-button",onClick:()=>{a4()},title:bw>0?`Open Workbench runtime \xb7 ${cW(bw)}`:"Open Workbench runtime status","aria-label":bw>0?`Open Workbench runtime \xb7 ${cW(bw)}`:"Open Workbench runtime status",style:{display:"flex",alignItems:"center",gap:4,height:28,padding:"0 7px",flexShrink:0,background:am?"var(--bg-selected)":bw>0||as?"rgba(37,99,235,0.08)":"var(--bg-panel)",border:`1px solid ${am||bw>0||as?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,cursor:"pointer",color:bw>0||as?"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"}),bw>0&&(0,d.jsx)("span",{className:"topbar-plot-memory",children:cW(bw)})]}),bb&&(ac||af)&&(()=>{let a=ac?.tokens,b=ac?.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(af?.contextWindow){let a=af.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(af.contextWindow)}`:`? / ${c(af.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)}`)),af?.contextWindow){let a=af.percent;h.push(`context: ${null!==a?a.toFixed(1)+"%":"unknown"} of ${af.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:ab,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:()=>aE(a=>!a),title:aC?"Hide right panel":"Show right panel","aria-label":aC?"Hide right panel":"Show right panel",style:{display:"flex",alignItems:"center",justifyContent:"center",width:32,height:28,padding:0,background:aC?"var(--bg-selected)":"var(--bg-panel)",border:`1px solid ${aC?"rgba(37,99,235,0.45)":"var(--border)"}`,borderRadius:7,color:aC?"var(--accent)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"color 0.12s, background 0.12s"},onMouseEnter:a=>{a.currentTarget.style.color=aC?"var(--accent)":"var(--text)",a.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:a=>{a.currentTarget.style.color=aC?"var(--accent)":"var(--text-muted)",a.currentTarget.style.background=aC?"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"})]})}),ai&&ak&&(0,d.jsx)("div",{style:{position:"fixed",top:ak.top,left:ak.left,width:ak.width,zIndex:500},children:"system"===ai&&(0,d.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:P?(0,d.jsx)("div",{style:{maxHeight:"min(600px, 75vh)",overflowY:"auto",padding:"12px 16px",color:"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",fontFamily:"var(--font-mono)"},children:P}):""===P?(0,d.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"System prompt is empty (tools are disabled)"}):(0,d.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"Send a message to load the system prompt"})})})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"hidden",position:"relative"},children:bb?(0,d.jsx)(ay,{session:i,newSessionCwd:ba,onAgentEnd:aX,onSessionCreated:aW,onSessionForked:aY,modelsRefreshKey:t,chatInputRef:F,onBranchDataChange:N,onSystemPromptChange:Y,onSessionStatsChange:ae,onContextUsageChange:ah,onToolPresetActive:at,generativeUI:z.generativeUI},o):bc?aN?(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})]}),aC&&(0,d.jsx)(bj,{side:"left",ariaLabel:"Resize right panel",onResizeStart:E.beginResize,onResize:E.resizeBy,onResizeEnd:E.endResize}),(0,d.jsxs)("div",{className:`right-panel-container${aC?" right-panel-open":" right-panel-closed"}`,style:{display:aC?"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:()=>aE(!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)(bB,{tabs:bd,activeTabId:ax,onSelectTab:aA,onCloseTab:a9})})]}),(0,d.jsx)("div",{style:{flex:1,overflow:"hidden"},children:"files"===ax?(0,d.jsx)(be,{cwd:aN??i?.cwd??k??null,refreshKey:q,onOpenFile:a0,onExploreFile:a1,onAtMention:aL}):"tools"===ax?(0,d.jsx)(bv,{refreshKey:aH,visibleAppId:aF?.appId??null,cwd:aN??i?.cwd??k??null,onOpenApp:a5,onAppChanged:a6}):bf?.filePath?bf.filePath.startsWith("__")?(0,d.jsx)(bi,{filePath:bf.filePath}):(0,d.jsx)(aB,{filePath:bf.filePath,children:(0,d.jsx)(az.h,{filePath:bf.filePath,cwd:aN??void 0,onOpenFile:a0})}):(0,d.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-dim)",fontSize:12},children:"No file open"})})]})]}),v&&(0,d.jsx)(cP,{cwd:a_,generativeUI:z.generativeUI,initialTab:x,onGenerativeUIToggle:ab,onModelsChanged:()=>u(a=>a+1),onProjectSelect:aT,onProjectsChanged:()=>n(a=>a+1),onClose:()=>{w(!1),u(a=>a+1)}}),am&&(0,d.jsx)(cT,{cwd:bm,runtime:{totalBytes:bw,currentSessionBytes:bx,idleTimeoutLabel:function(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`}(z.plotIdleTimeoutMs)},runtimeError:br,busy:aq,onClose:a3,onLaunch:a=>bA(a),onReleaseCurrentRuntime:i?.id&&i.cwd===bm?()=>{bz()}:void 0,onOpenSettings:()=>bn("workbench-runtime")}),(0,d.jsx)(bo,{appType:aF?.appType??"stexp",filePath:aF?.filePath??null,cwd:aF?.cwd??null,appId:aF?.appId??null,sessionId:i?.id??null,onClose:()=>aG(null),onAppChanged:a6,onOpenTools:a4}),aJ.map((a,b)=>(0,d.jsx)(aD,{id:a.id,filePath:a.filePath,fileName:a.fileName,cwd:aN??i?.cwd??k??void 0,active:b===aJ.length-1,stackIndex:b,zIndex:700+b,onClose:a7,onFocus:a8,onOpenFile:a0},a.id))]})}},86439:a=>{"use strict";a.exports=require("next/dist/shared/lib/no-fallback-error.external")},94735:a=>{"use strict";a.exports=require("events")},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,9093,1494],()=>b(b.s=71411));module.exports=c})();
|