@hienlh/ppm 0.7.1 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +2 -0
  3. package/dist/web/assets/ai-settings-section-CBpXqM-I.js +1 -0
  4. package/dist/web/assets/chat-tab--EEbRVaN.js +7 -0
  5. package/dist/web/assets/{code-editor-D6OuzcC-.js → code-editor-DiJdsNLG.js} +1 -1
  6. package/dist/web/assets/{database-viewer-BxUpM_uA.js → database-viewer-CUo4184l.js} +1 -1
  7. package/dist/web/assets/{diff-viewer-DAhrHpNM.js → diff-viewer-C9pppOGA.js} +1 -1
  8. package/dist/web/assets/git-graph-5k5QQSst.js +1 -0
  9. package/dist/web/assets/index-Bl899cTX.css +2 -0
  10. package/dist/web/assets/index-DJ9J8ofO.js +29 -0
  11. package/dist/web/assets/{input-nI4xe1Y9.js → input-BpFvhpT8.js} +1 -1
  12. package/dist/web/assets/keybindings-store-BKy-JlvM.js +1 -0
  13. package/dist/web/assets/{markdown-renderer-CvGYO9sH.js → markdown-renderer-CxhgCtxp.js} +2 -2
  14. package/dist/web/assets/{postgres-viewer-BL99auSm.js → postgres-viewer-V8p5zyzM.js} +1 -1
  15. package/dist/web/assets/{settings-store-CfB0vCtQ.js → settings-store-oxI7uvce.js} +1 -1
  16. package/dist/web/assets/settings-tab-BHdd7GQK.js +1 -0
  17. package/dist/web/assets/{sqlite-viewer-DfgaCbWT.js → sqlite-viewer-CrmQ2d_g.js} +1 -1
  18. package/dist/web/assets/{tab-store-Bm1Hw8OR.js → tab-store-D7tRt0VT.js} +1 -1
  19. package/dist/web/assets/{terminal-tab-D27e4ZTD.js → terminal-tab-DP4NxGnK.js} +2 -2
  20. package/dist/web/assets/{use-monaco-theme-Dexl3s3E.js → use-monaco-theme-CeYne1fd.js} +1 -1
  21. package/dist/web/index.html +9 -8
  22. package/dist/web/sw.js +1 -1
  23. package/package.json +1 -1
  24. package/src/server/index.ts +14 -0
  25. package/src/services/tunnel.service.ts +5 -0
  26. package/src/web/components/chat/chat-history-bar.tsx +15 -1
  27. package/src/web/components/chat/chat-tab.tsx +23 -0
  28. package/src/web/hooks/use-notification-badge.ts +20 -11
  29. package/src/web/hooks/use-tab-overflow.ts +8 -2
  30. package/dist/web/assets/chat-tab-CbNbBMGw.js +0 -7
  31. package/dist/web/assets/git-graph-BpTt5iOd.js +0 -1
  32. package/dist/web/assets/index-BU_07_oW.js +0 -29
  33. package/dist/web/assets/index-CBQhXXeV.css +0 -2
  34. package/dist/web/assets/keybindings-store-C0m8_V9X.js +0 -1
  35. package/dist/web/assets/settings-tab-Bwsxb41F.js +0 -1
  36. /package/dist/web/assets/{api-client-4Ni0i4Hl.js → api-client-B0aMOJxF.js} +0 -0
  37. /package/dist/web/assets/{dist-CNRrBoQi.js → dist-QgqOdSYG.js} +0 -0
  38. /package/dist/web/assets/{react-DHSo28we.js → react-Dk7fkoaB.js} +0 -0
  39. /package/dist/web/assets/{table-DCVKGOr2.js → table-B6neW6Hr.js} +0 -0
  40. /package/dist/web/assets/{utils-siJJ3uG0.js → utils-DBpa1UZX.js} +0 -0
package/dist/web/sw.js CHANGED
@@ -1 +1 @@
1
- try{self[`workbox:core:7.3.0`]&&_()}catch{}var e=(e,...t)=>{let n=e;return t.length>0&&(n+=` :: ${JSON.stringify(t)}`),n},t=class extends Error{constructor(t,n){let r=e(t,n);super(r),this.name=t,this.details=n}},n={googleAnalytics:`googleAnalytics`,precache:`precache-v2`,prefix:`workbox`,runtime:`runtime`,suffix:typeof registration<`u`?registration.scope:``},r=e=>[n.prefix,e,n.suffix].filter(e=>e&&e.length>0).join(`-`),i=e=>{for(let t of Object.keys(n))e(t)},a={updateDetails:e=>{i(t=>{typeof e[t]==`string`&&(n[t]=e[t])})},getGoogleAnalyticsName:e=>e||r(n.googleAnalytics),getPrecacheName:e=>e||r(n.precache),getPrefix:()=>n.prefix,getRuntimeName:e=>e||r(n.runtime),getSuffix:()=>n.suffix};function o(e,t){let n=t();return e.waitUntil(n),n}try{self[`workbox:precaching:7.3.0`]&&_()}catch{}var s=`__WB_REVISION__`;function c(e){if(!e)throw new t(`add-to-cache-list-unexpected-type`,{entry:e});if(typeof e==`string`){let t=new URL(e,location.href);return{cacheKey:t.href,url:t.href}}let{revision:n,url:r}=e;if(!r)throw new t(`add-to-cache-list-unexpected-type`,{entry:e});if(!n){let e=new URL(r,location.href);return{cacheKey:e.href,url:e.href}}let i=new URL(r,location.href),a=new URL(r,location.href);return i.searchParams.set(s,n),{cacheKey:i.href,url:a.href}}var l=class{constructor(){this.updatedURLs=[],this.notUpdatedURLs=[],this.handlerWillStart=async({request:e,state:t})=>{t&&(t.originalRequest=e)},this.cachedResponseWillBeUsed=async({event:e,state:t,cachedResponse:n})=>{if(e.type===`install`&&t&&t.originalRequest&&t.originalRequest instanceof Request){let e=t.originalRequest.url;n?this.notUpdatedURLs.push(e):this.updatedURLs.push(e)}return n}}},u=class{constructor({precacheController:e}){this.cacheKeyWillBeUsed=async({request:e,params:t})=>{let n=t?.cacheKey||this._precacheController.getCacheKeyForURL(e.url);return n?new Request(n,{headers:e.headers}):e},this._precacheController=e}},d;function f(){if(d===void 0){let e=new Response(``);if(`body`in e)try{new Response(e.body),d=!0}catch{d=!1}d=!1}return d}async function p(e,n){let r=null;if(e.url&&(r=new URL(e.url).origin),r!==self.location.origin)throw new t(`cross-origin-copy-response`,{origin:r});let i=e.clone(),a={headers:new Headers(i.headers),status:i.status,statusText:i.statusText},o=n?n(a):a,s=f()?i.body:await i.blob();return new Response(s,o)}var m=e=>new URL(String(e),location.href).href.replace(RegExp(`^${location.origin}`),``);function h(e,t){let n=new URL(e);for(let e of t)n.searchParams.delete(e);return n.href}async function g(e,t,n,r){let i=h(t.url,n);if(t.url===i)return e.match(t,r);let a=Object.assign(Object.assign({},r),{ignoreSearch:!0}),o=await e.keys(t,a);for(let t of o)if(i===h(t.url,n))return e.match(t,r)}var v=class{constructor(){this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}},y=new Set;async function b(){for(let e of y)await e()}function x(e){return new Promise(t=>setTimeout(t,e))}try{self[`workbox:strategies:7.3.0`]&&_()}catch{}function S(e){return typeof e==`string`?new Request(e):e}var C=class{constructor(e,t){this._cacheKeys={},Object.assign(this,t),this.event=t.event,this._strategy=e,this._handlerDeferred=new v,this._extendLifetimePromises=[],this._plugins=[...e.plugins],this._pluginStateMap=new Map;for(let e of this._plugins)this._pluginStateMap.set(e,{});this.event.waitUntil(this._handlerDeferred.promise)}async fetch(e){let{event:n}=this,r=S(e);if(r.mode===`navigate`&&n instanceof FetchEvent&&n.preloadResponse){let e=await n.preloadResponse;if(e)return e}let i=this.hasCallback(`fetchDidFail`)?r.clone():null;try{for(let e of this.iterateCallbacks(`requestWillFetch`))r=await e({request:r.clone(),event:n})}catch(e){if(e instanceof Error)throw new t(`plugin-error-request-will-fetch`,{thrownErrorMessage:e.message})}let a=r.clone();try{let e;e=await fetch(r,r.mode===`navigate`?void 0:this._strategy.fetchOptions);for(let t of this.iterateCallbacks(`fetchDidSucceed`))e=await t({event:n,request:a,response:e});return e}catch(e){throw i&&await this.runCallbacks(`fetchDidFail`,{error:e,event:n,originalRequest:i.clone(),request:a.clone()}),e}}async fetchAndCachePut(e){let t=await this.fetch(e),n=t.clone();return this.waitUntil(this.cachePut(e,n)),t}async cacheMatch(e){let t=S(e),n,{cacheName:r,matchOptions:i}=this._strategy,a=await this.getCacheKey(t,`read`),o=Object.assign(Object.assign({},i),{cacheName:r});n=await caches.match(a,o);for(let e of this.iterateCallbacks(`cachedResponseWillBeUsed`))n=await e({cacheName:r,matchOptions:i,cachedResponse:n,request:a,event:this.event})||void 0;return n}async cachePut(e,n){let r=S(e);await x(0);let i=await this.getCacheKey(r,`write`);if(!n)throw new t(`cache-put-with-no-response`,{url:m(i.url)});let a=await this._ensureResponseSafeToCache(n);if(!a)return!1;let{cacheName:o,matchOptions:s}=this._strategy,c=await self.caches.open(o),l=this.hasCallback(`cacheDidUpdate`),u=l?await g(c,i.clone(),[`__WB_REVISION__`],s):null;try{await c.put(i,l?a.clone():a)}catch(e){if(e instanceof Error)throw e.name===`QuotaExceededError`&&await b(),e}for(let e of this.iterateCallbacks(`cacheDidUpdate`))await e({cacheName:o,oldResponse:u,newResponse:a.clone(),request:i,event:this.event});return!0}async getCacheKey(e,t){let n=`${e.url} | ${t}`;if(!this._cacheKeys[n]){let r=e;for(let e of this.iterateCallbacks(`cacheKeyWillBeUsed`))r=S(await e({mode:t,request:r,event:this.event,params:this.params}));this._cacheKeys[n]=r}return this._cacheKeys[n]}hasCallback(e){for(let t of this._strategy.plugins)if(e in t)return!0;return!1}async runCallbacks(e,t){for(let n of this.iterateCallbacks(e))await n(t)}*iterateCallbacks(e){for(let t of this._strategy.plugins)if(typeof t[e]==`function`){let n=this._pluginStateMap.get(t);yield r=>{let i=Object.assign(Object.assign({},r),{state:n});return t[e](i)}}}waitUntil(e){return this._extendLifetimePromises.push(e),e}async doneWaiting(){for(;this._extendLifetimePromises.length;){let e=this._extendLifetimePromises.splice(0),t=(await Promise.allSettled(e)).find(e=>e.status===`rejected`);if(t)throw t.reason}}destroy(){this._handlerDeferred.resolve(null)}async _ensureResponseSafeToCache(e){let t=e,n=!1;for(let e of this.iterateCallbacks(`cacheWillUpdate`))if(t=await e({request:this.request,response:t,event:this.event})||void 0,n=!0,!t)break;return n||t&&t.status!==200&&(t=void 0),t}},w=class{constructor(e={}){this.cacheName=a.getRuntimeName(e.cacheName),this.plugins=e.plugins||[],this.fetchOptions=e.fetchOptions,this.matchOptions=e.matchOptions}handle(e){let[t]=this.handleAll(e);return t}handleAll(e){e instanceof FetchEvent&&(e={event:e,request:e.request});let t=e.event,n=typeof e.request==`string`?new Request(e.request):e.request,r=`params`in e?e.params:void 0,i=new C(this,{event:t,request:n,params:r}),a=this._getResponse(i,n,t);return[a,this._awaitComplete(a,i,n,t)]}async _getResponse(e,n,r){await e.runCallbacks(`handlerWillStart`,{event:r,request:n});let i;try{if(i=await this._handle(n,e),!i||i.type===`error`)throw new t(`no-response`,{url:n.url})}catch(t){if(t instanceof Error){for(let a of e.iterateCallbacks(`handlerDidError`))if(i=await a({error:t,event:r,request:n}),i)break}if(!i)throw t}for(let t of e.iterateCallbacks(`handlerWillRespond`))i=await t({event:r,request:n,response:i});return i}async _awaitComplete(e,t,n,r){let i,a;try{i=await e}catch{}try{await t.runCallbacks(`handlerDidRespond`,{event:r,request:n,response:i}),await t.doneWaiting()}catch(e){e instanceof Error&&(a=e)}if(await t.runCallbacks(`handlerDidComplete`,{event:r,request:n,response:i,error:a}),t.destroy(),a)throw a}},T=class e extends w{constructor(t={}){t.cacheName=a.getPrecacheName(t.cacheName),super(t),this._fallbackToNetwork=t.fallbackToNetwork!==!1,this.plugins.push(e.copyRedirectedCacheableResponsesPlugin)}async _handle(e,t){return await t.cacheMatch(e)||(t.event&&t.event.type===`install`?await this._handleInstall(e,t):await this._handleFetch(e,t))}async _handleFetch(e,n){let r,i=n.params||{};if(this._fallbackToNetwork){let t=i.integrity,a=e.integrity,o=!a||a===t;r=await n.fetch(new Request(e,{integrity:e.mode===`no-cors`?void 0:a||t})),t&&o&&e.mode!==`no-cors`&&(this._useDefaultCacheabilityPluginIfNeeded(),await n.cachePut(e,r.clone()))}else throw new t(`missing-precache-entry`,{cacheName:this.cacheName,url:e.url});return r}async _handleInstall(e,n){this._useDefaultCacheabilityPluginIfNeeded();let r=await n.fetch(e);if(!await n.cachePut(e,r.clone()))throw new t(`bad-precaching-response`,{url:e.url,status:r.status});return r}_useDefaultCacheabilityPluginIfNeeded(){let t=null,n=0;for(let[r,i]of this.plugins.entries())i!==e.copyRedirectedCacheableResponsesPlugin&&(i===e.defaultPrecacheCacheabilityPlugin&&(t=r),i.cacheWillUpdate&&n++);n===0?this.plugins.push(e.defaultPrecacheCacheabilityPlugin):n>1&&t!==null&&this.plugins.splice(t,1)}};T.defaultPrecacheCacheabilityPlugin={async cacheWillUpdate({response:e}){return!e||e.status>=400?null:e}},T.copyRedirectedCacheableResponsesPlugin={async cacheWillUpdate({response:e}){return e.redirected?await p(e):e}};var E=class{constructor({cacheName:e,plugins:t=[],fallbackToNetwork:n=!0}={}){this._urlsToCacheKeys=new Map,this._urlsToCacheModes=new Map,this._cacheKeysToIntegrities=new Map,this._strategy=new T({cacheName:a.getPrecacheName(e),plugins:[...t,new u({precacheController:this})],fallbackToNetwork:n}),this.install=this.install.bind(this),this.activate=this.activate.bind(this)}get strategy(){return this._strategy}precache(e){this.addToCacheList(e),this._installAndActiveListenersAdded||=(self.addEventListener(`install`,this.install),self.addEventListener(`activate`,this.activate),!0)}addToCacheList(e){let n=[];for(let r of e){typeof r==`string`?n.push(r):r&&r.revision===void 0&&n.push(r.url);let{cacheKey:e,url:i}=c(r),a=typeof r!=`string`&&r.revision?`reload`:`default`;if(this._urlsToCacheKeys.has(i)&&this._urlsToCacheKeys.get(i)!==e)throw new t(`add-to-cache-list-conflicting-entries`,{firstEntry:this._urlsToCacheKeys.get(i),secondEntry:e});if(typeof r!=`string`&&r.integrity){if(this._cacheKeysToIntegrities.has(e)&&this._cacheKeysToIntegrities.get(e)!==r.integrity)throw new t(`add-to-cache-list-conflicting-integrities`,{url:i});this._cacheKeysToIntegrities.set(e,r.integrity)}if(this._urlsToCacheKeys.set(i,e),this._urlsToCacheModes.set(i,a),n.length>0){let e=`Workbox is precaching URLs without revision info: ${n.join(`, `)}\nThis is generally NOT safe. Learn more at https://bit.ly/wb-precache`;console.warn(e)}}}install(e){return o(e,async()=>{let t=new l;this.strategy.plugins.push(t);for(let[t,n]of this._urlsToCacheKeys){let r=this._cacheKeysToIntegrities.get(n),i=this._urlsToCacheModes.get(t),a=new Request(t,{integrity:r,cache:i,credentials:`same-origin`});await Promise.all(this.strategy.handleAll({params:{cacheKey:n},request:a,event:e}))}let{updatedURLs:n,notUpdatedURLs:r}=t;return{updatedURLs:n,notUpdatedURLs:r}})}activate(e){return o(e,async()=>{let e=await self.caches.open(this.strategy.cacheName),t=await e.keys(),n=new Set(this._urlsToCacheKeys.values()),r=[];for(let i of t)n.has(i.url)||(await e.delete(i),r.push(i.url));return{deletedURLs:r}})}getURLsToCacheKeys(){return this._urlsToCacheKeys}getCachedURLs(){return[...this._urlsToCacheKeys.keys()]}getCacheKeyForURL(e){let t=new URL(e,location.href);return this._urlsToCacheKeys.get(t.href)}getIntegrityForCacheKey(e){return this._cacheKeysToIntegrities.get(e)}async matchPrecache(e){let t=e instanceof Request?e.url:e,n=this.getCacheKeyForURL(t);if(n)return(await self.caches.open(this.strategy.cacheName)).match(n)}createHandlerBoundToURL(e){let n=this.getCacheKeyForURL(e);if(!n)throw new t(`non-precached-url`,{url:e});return t=>(t.request=new Request(e),t.params=Object.assign({cacheKey:n},t.params),this.strategy.handle(t))}},D,O=()=>(D||=new E,D);try{self[`workbox:routing:7.3.0`]&&_()}catch{}var k=e=>e&&typeof e==`object`?e:{handle:e},A=class{constructor(e,t,n=`GET`){this.handler=k(t),this.match=e,this.method=n}setCatchHandler(e){this.catchHandler=k(e)}},j=class extends A{constructor(e,t,n){super(({url:t})=>{let n=e.exec(t.href);if(n&&!(t.origin!==location.origin&&n.index!==0))return n.slice(1)},t,n)}},M=class{constructor(){this._routes=new Map,this._defaultHandlerMap=new Map}get routes(){return this._routes}addFetchListener(){self.addEventListener(`fetch`,(e=>{let{request:t}=e,n=this.handleRequest({request:t,event:e});n&&e.respondWith(n)}))}addCacheListener(){self.addEventListener(`message`,(e=>{if(e.data&&e.data.type===`CACHE_URLS`){let{payload:t}=e.data,n=Promise.all(t.urlsToCache.map(t=>{typeof t==`string`&&(t=[t]);let n=new Request(...t);return this.handleRequest({request:n,event:e})}));e.waitUntil(n),e.ports&&e.ports[0]&&n.then(()=>e.ports[0].postMessage(!0))}}))}handleRequest({request:e,event:t}){let n=new URL(e.url,location.href);if(!n.protocol.startsWith(`http`))return;let r=n.origin===location.origin,{params:i,route:a}=this.findMatchingRoute({event:t,request:e,sameOrigin:r,url:n}),o=a&&a.handler,s=e.method;if(!o&&this._defaultHandlerMap.has(s)&&(o=this._defaultHandlerMap.get(s)),!o)return;let c;try{c=o.handle({url:n,request:e,event:t,params:i})}catch(e){c=Promise.reject(e)}let l=a&&a.catchHandler;return c instanceof Promise&&(this._catchHandler||l)&&(c=c.catch(async r=>{if(l)try{return await l.handle({url:n,request:e,event:t,params:i})}catch(e){e instanceof Error&&(r=e)}if(this._catchHandler)return this._catchHandler.handle({url:n,request:e,event:t});throw r})),c}findMatchingRoute({url:e,sameOrigin:t,request:n,event:r}){let i=this._routes.get(n.method)||[];for(let a of i){let i,o=a.match({url:e,sameOrigin:t,request:n,event:r});if(o)return i=o,(Array.isArray(i)&&i.length===0||o.constructor===Object&&Object.keys(o).length===0||typeof o==`boolean`)&&(i=void 0),{route:a,params:i}}return{}}setDefaultHandler(e,t=`GET`){this._defaultHandlerMap.set(t,k(e))}setCatchHandler(e){this._catchHandler=k(e)}registerRoute(e){this._routes.has(e.method)||this._routes.set(e.method,[]),this._routes.get(e.method).push(e)}unregisterRoute(e){if(!this._routes.has(e.method))throw new t(`unregister-route-but-not-found-with-method`,{method:e.method});let n=this._routes.get(e.method).indexOf(e);if(n>-1)this._routes.get(e.method).splice(n,1);else throw new t(`unregister-route-route-not-registered`)}},N,P=()=>(N||(N=new M,N.addFetchListener(),N.addCacheListener()),N);function F(e,n,r){let i;if(typeof e==`string`){let t=new URL(e,location.href);i=new A(({url:e})=>e.href===t.href,n,r)}else if(e instanceof RegExp)i=new j(e,n,r);else if(typeof e==`function`)i=new A(e,n,r);else if(e instanceof A)i=e;else throw new t(`unsupported-route-type`,{moduleName:`workbox-routing`,funcName:`registerRoute`,paramName:`capture`});return P().registerRoute(i),i}function I(e,t=[]){for(let n of[...e.searchParams.keys()])t.some(e=>e.test(n))&&e.searchParams.delete(n);return e}function*L(e,{ignoreURLParametersMatching:t=[/^utm_/,/^fbclid$/],directoryIndex:n=`index.html`,cleanURLs:r=!0,urlManipulation:i}={}){let a=new URL(e,location.href);a.hash=``,yield a.href;let o=I(a,t);if(yield o.href,n&&o.pathname.endsWith(`/`)){let e=new URL(o.href);e.pathname+=n,yield e.href}if(r){let e=new URL(o.href);e.pathname+=`.html`,yield e.href}if(i){let e=i({url:a});for(let t of e)yield t.href}}var R=class extends A{constructor(e,t){super(({request:n})=>{let r=e.getURLsToCacheKeys();for(let i of L(n.url,t)){let t=r.get(i);if(t)return{cacheKey:t,integrity:e.getIntegrityForCacheKey(t)}}},e.strategy)}};function z(e){F(new R(O(),e))}function B(e){O().precache(e)}function V(e,t){B(e),z(t)}V([{"revision":"1872c500de691dce40960bb85481de07","url":"registerSW.js"},{"revision":"4276cff85869e97ffbe37bc4b5426eda","url":"index.html"},{"revision":"a0fb34fc84eb148d51812cd62669f20d","url":"icon-512.svg"},{"revision":"a0fb34fc84eb148d51812cd62669f20d","url":"icon-192.svg"},{"revision":"eb9818b9094675c0c5d303168f273345","url":"monacoeditorwork/ts.worker.bundle.js"},{"revision":"9af0be92dcefdc1f1290441cb5ff5d9b","url":"monacoeditorwork/json.worker.bundle.js"},{"revision":"a261b429c39dbb75ae97972d7d005e6d","url":"monacoeditorwork/html.worker.bundle.js"},{"revision":"79953d804e1bbacecfd79b85fd679016","url":"monacoeditorwork/editor.worker.bundle.js"},{"revision":"fdcba0d09aac31df7a0bc652f6e739bd","url":"monacoeditorwork/css.worker.bundle.js"},{"revision":null,"url":"assets/utils-siJJ3uG0.js"},{"revision":null,"url":"assets/use-monaco-theme-Dexl3s3E.js"},{"revision":null,"url":"assets/terminal-tab-D27e4ZTD.js"},{"revision":null,"url":"assets/terminal-tab-BrP-ENHg.css"},{"revision":null,"url":"assets/table-DCVKGOr2.js"},{"revision":null,"url":"assets/tab-store-Bm1Hw8OR.js"},{"revision":null,"url":"assets/sqlite-viewer-DfgaCbWT.js"},{"revision":null,"url":"assets/settings-tab-Bwsxb41F.js"},{"revision":null,"url":"assets/settings-store-CfB0vCtQ.js"},{"revision":null,"url":"assets/react-DHSo28we.js"},{"revision":null,"url":"assets/react-CYzKIDNi.js"},{"revision":null,"url":"assets/postgres-viewer-BL99auSm.js"},{"revision":null,"url":"assets/markdown-renderer-CvGYO9sH.js"},{"revision":null,"url":"assets/keybindings-store-C0m8_V9X.js"},{"revision":null,"url":"assets/jsx-runtime-wQxeESYQ.js"},{"revision":null,"url":"assets/input-nI4xe1Y9.js"},{"revision":null,"url":"assets/index-CBQhXXeV.css"},{"revision":null,"url":"assets/index-BU_07_oW.js"},{"revision":null,"url":"assets/git-graph-BpTt5iOd.js"},{"revision":null,"url":"assets/dist-CNRrBoQi.js"},{"revision":null,"url":"assets/diff-viewer-DAhrHpNM.js"},{"revision":null,"url":"assets/database-viewer-BxUpM_uA.js"},{"revision":null,"url":"assets/code-editor-D6OuzcC-.js"},{"revision":null,"url":"assets/chat-tab-CbNbBMGw.js"},{"revision":null,"url":"assets/api-client-4Ni0i4Hl.js"},{"revision":"79c8870653c8f419f2e3323085e1f4be","url":"manifest.webmanifest"}]),self.addEventListener(`push`,e=>{e.waitUntil(self.clients.matchAll({type:`window`,includeUncontrolled:!0}).then(t=>{if(t.some(e=>e.visibilityState===`visible`))return;let n=e.data?.json()??{title:`PPM`,body:`Chat completed`};return self.registration.showNotification(n.title,{body:n.body,icon:`/icon-192.png`,badge:`/icon-192.png`,tag:`ppm-chat-done`,silent:!1,data:{url:self.location.origin}})}))}),self.addEventListener(`notificationclick`,e=>{e.notification.close(),e.waitUntil(self.clients.matchAll({type:`window`,includeUncontrolled:!0}).then(t=>{for(let e of t)if(e.url.includes(self.location.origin)&&`focus`in e)return e.focus();return self.clients.openWindow(e.notification.data?.url||`/`)}))});
1
+ try{self[`workbox:core:7.3.0`]&&_()}catch{}var e=(e,...t)=>{let n=e;return t.length>0&&(n+=` :: ${JSON.stringify(t)}`),n},t=class extends Error{constructor(t,n){let r=e(t,n);super(r),this.name=t,this.details=n}},n={googleAnalytics:`googleAnalytics`,precache:`precache-v2`,prefix:`workbox`,runtime:`runtime`,suffix:typeof registration<`u`?registration.scope:``},r=e=>[n.prefix,e,n.suffix].filter(e=>e&&e.length>0).join(`-`),i=e=>{for(let t of Object.keys(n))e(t)},a={updateDetails:e=>{i(t=>{typeof e[t]==`string`&&(n[t]=e[t])})},getGoogleAnalyticsName:e=>e||r(n.googleAnalytics),getPrecacheName:e=>e||r(n.precache),getPrefix:()=>n.prefix,getRuntimeName:e=>e||r(n.runtime),getSuffix:()=>n.suffix};function o(e,t){let n=t();return e.waitUntil(n),n}try{self[`workbox:precaching:7.3.0`]&&_()}catch{}var s=`__WB_REVISION__`;function c(e){if(!e)throw new t(`add-to-cache-list-unexpected-type`,{entry:e});if(typeof e==`string`){let t=new URL(e,location.href);return{cacheKey:t.href,url:t.href}}let{revision:n,url:r}=e;if(!r)throw new t(`add-to-cache-list-unexpected-type`,{entry:e});if(!n){let e=new URL(r,location.href);return{cacheKey:e.href,url:e.href}}let i=new URL(r,location.href),a=new URL(r,location.href);return i.searchParams.set(s,n),{cacheKey:i.href,url:a.href}}var l=class{constructor(){this.updatedURLs=[],this.notUpdatedURLs=[],this.handlerWillStart=async({request:e,state:t})=>{t&&(t.originalRequest=e)},this.cachedResponseWillBeUsed=async({event:e,state:t,cachedResponse:n})=>{if(e.type===`install`&&t&&t.originalRequest&&t.originalRequest instanceof Request){let e=t.originalRequest.url;n?this.notUpdatedURLs.push(e):this.updatedURLs.push(e)}return n}}},u=class{constructor({precacheController:e}){this.cacheKeyWillBeUsed=async({request:e,params:t})=>{let n=t?.cacheKey||this._precacheController.getCacheKeyForURL(e.url);return n?new Request(n,{headers:e.headers}):e},this._precacheController=e}},d;function f(){if(d===void 0){let e=new Response(``);if(`body`in e)try{new Response(e.body),d=!0}catch{d=!1}d=!1}return d}async function p(e,n){let r=null;if(e.url&&(r=new URL(e.url).origin),r!==self.location.origin)throw new t(`cross-origin-copy-response`,{origin:r});let i=e.clone(),a={headers:new Headers(i.headers),status:i.status,statusText:i.statusText},o=n?n(a):a,s=f()?i.body:await i.blob();return new Response(s,o)}var m=e=>new URL(String(e),location.href).href.replace(RegExp(`^${location.origin}`),``);function h(e,t){let n=new URL(e);for(let e of t)n.searchParams.delete(e);return n.href}async function g(e,t,n,r){let i=h(t.url,n);if(t.url===i)return e.match(t,r);let a=Object.assign(Object.assign({},r),{ignoreSearch:!0}),o=await e.keys(t,a);for(let t of o)if(i===h(t.url,n))return e.match(t,r)}var v=class{constructor(){this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}},y=new Set;async function b(){for(let e of y)await e()}function x(e){return new Promise(t=>setTimeout(t,e))}try{self[`workbox:strategies:7.3.0`]&&_()}catch{}function S(e){return typeof e==`string`?new Request(e):e}var C=class{constructor(e,t){this._cacheKeys={},Object.assign(this,t),this.event=t.event,this._strategy=e,this._handlerDeferred=new v,this._extendLifetimePromises=[],this._plugins=[...e.plugins],this._pluginStateMap=new Map;for(let e of this._plugins)this._pluginStateMap.set(e,{});this.event.waitUntil(this._handlerDeferred.promise)}async fetch(e){let{event:n}=this,r=S(e);if(r.mode===`navigate`&&n instanceof FetchEvent&&n.preloadResponse){let e=await n.preloadResponse;if(e)return e}let i=this.hasCallback(`fetchDidFail`)?r.clone():null;try{for(let e of this.iterateCallbacks(`requestWillFetch`))r=await e({request:r.clone(),event:n})}catch(e){if(e instanceof Error)throw new t(`plugin-error-request-will-fetch`,{thrownErrorMessage:e.message})}let a=r.clone();try{let e;e=await fetch(r,r.mode===`navigate`?void 0:this._strategy.fetchOptions);for(let t of this.iterateCallbacks(`fetchDidSucceed`))e=await t({event:n,request:a,response:e});return e}catch(e){throw i&&await this.runCallbacks(`fetchDidFail`,{error:e,event:n,originalRequest:i.clone(),request:a.clone()}),e}}async fetchAndCachePut(e){let t=await this.fetch(e),n=t.clone();return this.waitUntil(this.cachePut(e,n)),t}async cacheMatch(e){let t=S(e),n,{cacheName:r,matchOptions:i}=this._strategy,a=await this.getCacheKey(t,`read`),o=Object.assign(Object.assign({},i),{cacheName:r});n=await caches.match(a,o);for(let e of this.iterateCallbacks(`cachedResponseWillBeUsed`))n=await e({cacheName:r,matchOptions:i,cachedResponse:n,request:a,event:this.event})||void 0;return n}async cachePut(e,n){let r=S(e);await x(0);let i=await this.getCacheKey(r,`write`);if(!n)throw new t(`cache-put-with-no-response`,{url:m(i.url)});let a=await this._ensureResponseSafeToCache(n);if(!a)return!1;let{cacheName:o,matchOptions:s}=this._strategy,c=await self.caches.open(o),l=this.hasCallback(`cacheDidUpdate`),u=l?await g(c,i.clone(),[`__WB_REVISION__`],s):null;try{await c.put(i,l?a.clone():a)}catch(e){if(e instanceof Error)throw e.name===`QuotaExceededError`&&await b(),e}for(let e of this.iterateCallbacks(`cacheDidUpdate`))await e({cacheName:o,oldResponse:u,newResponse:a.clone(),request:i,event:this.event});return!0}async getCacheKey(e,t){let n=`${e.url} | ${t}`;if(!this._cacheKeys[n]){let r=e;for(let e of this.iterateCallbacks(`cacheKeyWillBeUsed`))r=S(await e({mode:t,request:r,event:this.event,params:this.params}));this._cacheKeys[n]=r}return this._cacheKeys[n]}hasCallback(e){for(let t of this._strategy.plugins)if(e in t)return!0;return!1}async runCallbacks(e,t){for(let n of this.iterateCallbacks(e))await n(t)}*iterateCallbacks(e){for(let t of this._strategy.plugins)if(typeof t[e]==`function`){let n=this._pluginStateMap.get(t);yield r=>{let i=Object.assign(Object.assign({},r),{state:n});return t[e](i)}}}waitUntil(e){return this._extendLifetimePromises.push(e),e}async doneWaiting(){for(;this._extendLifetimePromises.length;){let e=this._extendLifetimePromises.splice(0),t=(await Promise.allSettled(e)).find(e=>e.status===`rejected`);if(t)throw t.reason}}destroy(){this._handlerDeferred.resolve(null)}async _ensureResponseSafeToCache(e){let t=e,n=!1;for(let e of this.iterateCallbacks(`cacheWillUpdate`))if(t=await e({request:this.request,response:t,event:this.event})||void 0,n=!0,!t)break;return n||t&&t.status!==200&&(t=void 0),t}},w=class{constructor(e={}){this.cacheName=a.getRuntimeName(e.cacheName),this.plugins=e.plugins||[],this.fetchOptions=e.fetchOptions,this.matchOptions=e.matchOptions}handle(e){let[t]=this.handleAll(e);return t}handleAll(e){e instanceof FetchEvent&&(e={event:e,request:e.request});let t=e.event,n=typeof e.request==`string`?new Request(e.request):e.request,r=`params`in e?e.params:void 0,i=new C(this,{event:t,request:n,params:r}),a=this._getResponse(i,n,t);return[a,this._awaitComplete(a,i,n,t)]}async _getResponse(e,n,r){await e.runCallbacks(`handlerWillStart`,{event:r,request:n});let i;try{if(i=await this._handle(n,e),!i||i.type===`error`)throw new t(`no-response`,{url:n.url})}catch(t){if(t instanceof Error){for(let a of e.iterateCallbacks(`handlerDidError`))if(i=await a({error:t,event:r,request:n}),i)break}if(!i)throw t}for(let t of e.iterateCallbacks(`handlerWillRespond`))i=await t({event:r,request:n,response:i});return i}async _awaitComplete(e,t,n,r){let i,a;try{i=await e}catch{}try{await t.runCallbacks(`handlerDidRespond`,{event:r,request:n,response:i}),await t.doneWaiting()}catch(e){e instanceof Error&&(a=e)}if(await t.runCallbacks(`handlerDidComplete`,{event:r,request:n,response:i,error:a}),t.destroy(),a)throw a}},T=class e extends w{constructor(t={}){t.cacheName=a.getPrecacheName(t.cacheName),super(t),this._fallbackToNetwork=t.fallbackToNetwork!==!1,this.plugins.push(e.copyRedirectedCacheableResponsesPlugin)}async _handle(e,t){return await t.cacheMatch(e)||(t.event&&t.event.type===`install`?await this._handleInstall(e,t):await this._handleFetch(e,t))}async _handleFetch(e,n){let r,i=n.params||{};if(this._fallbackToNetwork){let t=i.integrity,a=e.integrity,o=!a||a===t;r=await n.fetch(new Request(e,{integrity:e.mode===`no-cors`?void 0:a||t})),t&&o&&e.mode!==`no-cors`&&(this._useDefaultCacheabilityPluginIfNeeded(),await n.cachePut(e,r.clone()))}else throw new t(`missing-precache-entry`,{cacheName:this.cacheName,url:e.url});return r}async _handleInstall(e,n){this._useDefaultCacheabilityPluginIfNeeded();let r=await n.fetch(e);if(!await n.cachePut(e,r.clone()))throw new t(`bad-precaching-response`,{url:e.url,status:r.status});return r}_useDefaultCacheabilityPluginIfNeeded(){let t=null,n=0;for(let[r,i]of this.plugins.entries())i!==e.copyRedirectedCacheableResponsesPlugin&&(i===e.defaultPrecacheCacheabilityPlugin&&(t=r),i.cacheWillUpdate&&n++);n===0?this.plugins.push(e.defaultPrecacheCacheabilityPlugin):n>1&&t!==null&&this.plugins.splice(t,1)}};T.defaultPrecacheCacheabilityPlugin={async cacheWillUpdate({response:e}){return!e||e.status>=400?null:e}},T.copyRedirectedCacheableResponsesPlugin={async cacheWillUpdate({response:e}){return e.redirected?await p(e):e}};var E=class{constructor({cacheName:e,plugins:t=[],fallbackToNetwork:n=!0}={}){this._urlsToCacheKeys=new Map,this._urlsToCacheModes=new Map,this._cacheKeysToIntegrities=new Map,this._strategy=new T({cacheName:a.getPrecacheName(e),plugins:[...t,new u({precacheController:this})],fallbackToNetwork:n}),this.install=this.install.bind(this),this.activate=this.activate.bind(this)}get strategy(){return this._strategy}precache(e){this.addToCacheList(e),this._installAndActiveListenersAdded||=(self.addEventListener(`install`,this.install),self.addEventListener(`activate`,this.activate),!0)}addToCacheList(e){let n=[];for(let r of e){typeof r==`string`?n.push(r):r&&r.revision===void 0&&n.push(r.url);let{cacheKey:e,url:i}=c(r),a=typeof r!=`string`&&r.revision?`reload`:`default`;if(this._urlsToCacheKeys.has(i)&&this._urlsToCacheKeys.get(i)!==e)throw new t(`add-to-cache-list-conflicting-entries`,{firstEntry:this._urlsToCacheKeys.get(i),secondEntry:e});if(typeof r!=`string`&&r.integrity){if(this._cacheKeysToIntegrities.has(e)&&this._cacheKeysToIntegrities.get(e)!==r.integrity)throw new t(`add-to-cache-list-conflicting-integrities`,{url:i});this._cacheKeysToIntegrities.set(e,r.integrity)}if(this._urlsToCacheKeys.set(i,e),this._urlsToCacheModes.set(i,a),n.length>0){let e=`Workbox is precaching URLs without revision info: ${n.join(`, `)}\nThis is generally NOT safe. Learn more at https://bit.ly/wb-precache`;console.warn(e)}}}install(e){return o(e,async()=>{let t=new l;this.strategy.plugins.push(t);for(let[t,n]of this._urlsToCacheKeys){let r=this._cacheKeysToIntegrities.get(n),i=this._urlsToCacheModes.get(t),a=new Request(t,{integrity:r,cache:i,credentials:`same-origin`});await Promise.all(this.strategy.handleAll({params:{cacheKey:n},request:a,event:e}))}let{updatedURLs:n,notUpdatedURLs:r}=t;return{updatedURLs:n,notUpdatedURLs:r}})}activate(e){return o(e,async()=>{let e=await self.caches.open(this.strategy.cacheName),t=await e.keys(),n=new Set(this._urlsToCacheKeys.values()),r=[];for(let i of t)n.has(i.url)||(await e.delete(i),r.push(i.url));return{deletedURLs:r}})}getURLsToCacheKeys(){return this._urlsToCacheKeys}getCachedURLs(){return[...this._urlsToCacheKeys.keys()]}getCacheKeyForURL(e){let t=new URL(e,location.href);return this._urlsToCacheKeys.get(t.href)}getIntegrityForCacheKey(e){return this._cacheKeysToIntegrities.get(e)}async matchPrecache(e){let t=e instanceof Request?e.url:e,n=this.getCacheKeyForURL(t);if(n)return(await self.caches.open(this.strategy.cacheName)).match(n)}createHandlerBoundToURL(e){let n=this.getCacheKeyForURL(e);if(!n)throw new t(`non-precached-url`,{url:e});return t=>(t.request=new Request(e),t.params=Object.assign({cacheKey:n},t.params),this.strategy.handle(t))}},D,O=()=>(D||=new E,D);try{self[`workbox:routing:7.3.0`]&&_()}catch{}var k=e=>e&&typeof e==`object`?e:{handle:e},A=class{constructor(e,t,n=`GET`){this.handler=k(t),this.match=e,this.method=n}setCatchHandler(e){this.catchHandler=k(e)}},j=class extends A{constructor(e,t,n){super(({url:t})=>{let n=e.exec(t.href);if(n&&!(t.origin!==location.origin&&n.index!==0))return n.slice(1)},t,n)}},M=class{constructor(){this._routes=new Map,this._defaultHandlerMap=new Map}get routes(){return this._routes}addFetchListener(){self.addEventListener(`fetch`,(e=>{let{request:t}=e,n=this.handleRequest({request:t,event:e});n&&e.respondWith(n)}))}addCacheListener(){self.addEventListener(`message`,(e=>{if(e.data&&e.data.type===`CACHE_URLS`){let{payload:t}=e.data,n=Promise.all(t.urlsToCache.map(t=>{typeof t==`string`&&(t=[t]);let n=new Request(...t);return this.handleRequest({request:n,event:e})}));e.waitUntil(n),e.ports&&e.ports[0]&&n.then(()=>e.ports[0].postMessage(!0))}}))}handleRequest({request:e,event:t}){let n=new URL(e.url,location.href);if(!n.protocol.startsWith(`http`))return;let r=n.origin===location.origin,{params:i,route:a}=this.findMatchingRoute({event:t,request:e,sameOrigin:r,url:n}),o=a&&a.handler,s=e.method;if(!o&&this._defaultHandlerMap.has(s)&&(o=this._defaultHandlerMap.get(s)),!o)return;let c;try{c=o.handle({url:n,request:e,event:t,params:i})}catch(e){c=Promise.reject(e)}let l=a&&a.catchHandler;return c instanceof Promise&&(this._catchHandler||l)&&(c=c.catch(async r=>{if(l)try{return await l.handle({url:n,request:e,event:t,params:i})}catch(e){e instanceof Error&&(r=e)}if(this._catchHandler)return this._catchHandler.handle({url:n,request:e,event:t});throw r})),c}findMatchingRoute({url:e,sameOrigin:t,request:n,event:r}){let i=this._routes.get(n.method)||[];for(let a of i){let i,o=a.match({url:e,sameOrigin:t,request:n,event:r});if(o)return i=o,(Array.isArray(i)&&i.length===0||o.constructor===Object&&Object.keys(o).length===0||typeof o==`boolean`)&&(i=void 0),{route:a,params:i}}return{}}setDefaultHandler(e,t=`GET`){this._defaultHandlerMap.set(t,k(e))}setCatchHandler(e){this._catchHandler=k(e)}registerRoute(e){this._routes.has(e.method)||this._routes.set(e.method,[]),this._routes.get(e.method).push(e)}unregisterRoute(e){if(!this._routes.has(e.method))throw new t(`unregister-route-but-not-found-with-method`,{method:e.method});let n=this._routes.get(e.method).indexOf(e);if(n>-1)this._routes.get(e.method).splice(n,1);else throw new t(`unregister-route-route-not-registered`)}},N,P=()=>(N||(N=new M,N.addFetchListener(),N.addCacheListener()),N);function F(e,n,r){let i;if(typeof e==`string`){let t=new URL(e,location.href);i=new A(({url:e})=>e.href===t.href,n,r)}else if(e instanceof RegExp)i=new j(e,n,r);else if(typeof e==`function`)i=new A(e,n,r);else if(e instanceof A)i=e;else throw new t(`unsupported-route-type`,{moduleName:`workbox-routing`,funcName:`registerRoute`,paramName:`capture`});return P().registerRoute(i),i}function I(e,t=[]){for(let n of[...e.searchParams.keys()])t.some(e=>e.test(n))&&e.searchParams.delete(n);return e}function*L(e,{ignoreURLParametersMatching:t=[/^utm_/,/^fbclid$/],directoryIndex:n=`index.html`,cleanURLs:r=!0,urlManipulation:i}={}){let a=new URL(e,location.href);a.hash=``,yield a.href;let o=I(a,t);if(yield o.href,n&&o.pathname.endsWith(`/`)){let e=new URL(o.href);e.pathname+=n,yield e.href}if(r){let e=new URL(o.href);e.pathname+=`.html`,yield e.href}if(i){let e=i({url:a});for(let t of e)yield t.href}}var R=class extends A{constructor(e,t){super(({request:n})=>{let r=e.getURLsToCacheKeys();for(let i of L(n.url,t)){let t=r.get(i);if(t)return{cacheKey:t,integrity:e.getIntegrityForCacheKey(t)}}},e.strategy)}};function z(e){F(new R(O(),e))}function B(e){O().precache(e)}function V(e,t){B(e),z(t)}V([{"revision":"1872c500de691dce40960bb85481de07","url":"registerSW.js"},{"revision":"657dcb0290a2971084a35f2069bca7b8","url":"index.html"},{"revision":"a0fb34fc84eb148d51812cd62669f20d","url":"icon-512.svg"},{"revision":"a0fb34fc84eb148d51812cd62669f20d","url":"icon-192.svg"},{"revision":"eb9818b9094675c0c5d303168f273345","url":"monacoeditorwork/ts.worker.bundle.js"},{"revision":"9af0be92dcefdc1f1290441cb5ff5d9b","url":"monacoeditorwork/json.worker.bundle.js"},{"revision":"a261b429c39dbb75ae97972d7d005e6d","url":"monacoeditorwork/html.worker.bundle.js"},{"revision":"79953d804e1bbacecfd79b85fd679016","url":"monacoeditorwork/editor.worker.bundle.js"},{"revision":"fdcba0d09aac31df7a0bc652f6e739bd","url":"monacoeditorwork/css.worker.bundle.js"},{"revision":null,"url":"assets/utils-DBpa1UZX.js"},{"revision":null,"url":"assets/use-monaco-theme-CeYne1fd.js"},{"revision":null,"url":"assets/terminal-tab-DP4NxGnK.js"},{"revision":null,"url":"assets/terminal-tab-BrP-ENHg.css"},{"revision":null,"url":"assets/table-B6neW6Hr.js"},{"revision":null,"url":"assets/tab-store-D7tRt0VT.js"},{"revision":null,"url":"assets/sqlite-viewer-CrmQ2d_g.js"},{"revision":null,"url":"assets/settings-tab-BHdd7GQK.js"},{"revision":null,"url":"assets/settings-store-oxI7uvce.js"},{"revision":null,"url":"assets/react-Dk7fkoaB.js"},{"revision":null,"url":"assets/react-CYzKIDNi.js"},{"revision":null,"url":"assets/postgres-viewer-V8p5zyzM.js"},{"revision":null,"url":"assets/markdown-renderer-CxhgCtxp.js"},{"revision":null,"url":"assets/keybindings-store-BKy-JlvM.js"},{"revision":null,"url":"assets/jsx-runtime-wQxeESYQ.js"},{"revision":null,"url":"assets/input-BpFvhpT8.js"},{"revision":null,"url":"assets/index-DJ9J8ofO.js"},{"revision":null,"url":"assets/index-Bl899cTX.css"},{"revision":null,"url":"assets/git-graph-5k5QQSst.js"},{"revision":null,"url":"assets/dist-QgqOdSYG.js"},{"revision":null,"url":"assets/diff-viewer-C9pppOGA.js"},{"revision":null,"url":"assets/database-viewer-CUo4184l.js"},{"revision":null,"url":"assets/code-editor-DiJdsNLG.js"},{"revision":null,"url":"assets/chat-tab--EEbRVaN.js"},{"revision":null,"url":"assets/api-client-B0aMOJxF.js"},{"revision":null,"url":"assets/ai-settings-section-CBpXqM-I.js"},{"revision":"79c8870653c8f419f2e3323085e1f4be","url":"manifest.webmanifest"}]),self.addEventListener(`push`,e=>{e.waitUntil(self.clients.matchAll({type:`window`,includeUncontrolled:!0}).then(t=>{if(t.some(e=>e.visibilityState===`visible`))return;let n=e.data?.json()??{title:`PPM`,body:`Chat completed`};return self.registration.showNotification(n.title,{body:n.body,icon:`/icon-192.png`,badge:`/icon-192.png`,tag:`ppm-chat-done`,silent:!1,data:{url:self.location.origin}})}))}),self.addEventListener(`notificationclick`,e=>{e.notification.close(),e.waitUntil(self.clients.matchAll({type:`window`,includeUncontrolled:!0}).then(t=>{for(let e of t)if(e.url.includes(self.location.origin)&&`focus`in e)return e.focus();return self.clients.openWindow(e.notification.data?.url||`/`)}))});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hienlh/ppm",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Personal Project Manager — mobile-first web IDE with AI assistance",
5
5
  "module": "src/index.ts",
6
6
  "type": "module",
@@ -448,6 +448,20 @@ if (process.argv.includes("__serve__")) {
448
448
  configService.load(configPath);
449
449
  await setupLogFile();
450
450
 
451
+ // Sync externally-started tunnel URL (from `ppm start --share`) into tunnelService
452
+ // so GET /api/tunnel reflects the correct state and Share button doesn't start a duplicate.
453
+ try {
454
+ const { resolve: r } = await import("node:path");
455
+ const { homedir: h } = await import("node:os");
456
+ const { readFileSync: rf } = await import("node:fs");
457
+ const statusFile = r(h(), ".ppm", "status.json");
458
+ const status = JSON.parse(rf(statusFile, "utf-8"));
459
+ if (status.shareUrl) {
460
+ const { tunnelService } = await import("../services/tunnel.service.ts");
461
+ tunnelService.setExternalUrl(status.shareUrl);
462
+ }
463
+ } catch { /* status.json missing or no shareUrl — normal */ }
464
+
451
465
  Bun.serve({
452
466
  port,
453
467
  hostname: host,
@@ -98,6 +98,11 @@ class TunnelService {
98
98
  getTunnelUrl(): string | null {
99
99
  return this.url;
100
100
  }
101
+
102
+ /** Inject an externally-started tunnel URL (e.g. from daemon --share) */
103
+ setExternalUrl(url: string): void {
104
+ this.url = url;
105
+ }
101
106
  }
102
107
 
103
108
  /** Singleton tunnel service */
@@ -1,8 +1,9 @@
1
1
  import { useState, useEffect, useCallback, useRef } from "react";
2
- import { History, Settings2, Loader2, MessageSquare, RefreshCw, Search, Pencil, Check, X } from "lucide-react";
2
+ import { History, Settings2, Loader2, MessageSquare, RefreshCw, Search, Pencil, Check, X, BellOff } from "lucide-react";
3
3
  import { Activity } from "lucide-react";
4
4
  import { api, projectUrl } from "@/lib/api-client";
5
5
  import { useTabStore } from "@/stores/tab-store";
6
+ import { useNotificationStore } from "@/stores/notification-store";
6
7
  import { AISettingsSection } from "@/components/settings/ai-settings-section";
7
8
  import { UsageDetailPanel } from "./usage-badge";
8
9
  import type { SessionInfo } from "../../../types/chat";
@@ -54,6 +55,8 @@ export function ChatHistoryBar({
54
55
  const [activePanel, setActivePanel] = useState<PanelType>(null);
55
56
  const [sessions, setSessions] = useState<SessionInfo[]>([]);
56
57
  const [loading, setLoading] = useState(false);
58
+ const hasUnread = useNotificationStore((s) => sessionId ? s.notifications.has(sessionId) : false);
59
+ const clearForSession = useNotificationStore((s) => s.clearForSession);
57
60
  const [searchQuery, setSearchQuery] = useState("");
58
61
  const [editingId, setEditingId] = useState<string | null>(null);
59
62
  const [editingTitle, setEditingTitle] = useState("");
@@ -178,6 +181,17 @@ export function ChatHistoryBar({
178
181
  {/* Spacer */}
179
182
  <div className="flex-1" />
180
183
 
184
+ {/* Mark as read */}
185
+ {hasUnread && sessionId && (
186
+ <button
187
+ onClick={() => clearForSession(sessionId)}
188
+ className="p-1 rounded text-amber-500 hover:text-amber-400 hover:bg-surface-elevated transition-colors"
189
+ title="Mark as read"
190
+ >
191
+ <BellOff className="size-3" />
192
+ </button>
193
+ )}
194
+
181
195
  {/* Connection indicator */}
182
196
  {onReconnect && (
183
197
  <button
@@ -5,6 +5,8 @@ import { useChat } from "@/hooks/use-chat";
5
5
  import { useUsage } from "@/hooks/use-usage";
6
6
  import { useTabStore } from "@/stores/tab-store";
7
7
  import { useSettingsStore } from "@/stores/settings-store";
8
+ import { usePanelStore } from "@/stores/panel-store";
9
+ import { useNotificationStore } from "@/stores/notification-store";
8
10
  import { openBugReportPopup } from "@/lib/report-bug";
9
11
  import { MessageList } from "./message-list";
10
12
  import { MessageInput, type ChatAttachment } from "./message-input";
@@ -79,6 +81,27 @@ export function ChatTab({ metadata, tabId }: ChatTabProps) {
79
81
  isConnected,
80
82
  } = useChat(sessionId, providerId, projectName);
81
83
 
84
+ // Auto-clear notification badge when this tab is active and document is visible.
85
+ // Handles the case where notification arrived while browser tab was hidden.
86
+ useEffect(() => {
87
+ if (!sessionId || !tabId) return;
88
+ const maybeClear = () => {
89
+ if (document.hidden) return;
90
+ const { panels, focusedPanelId } = usePanelStore.getState();
91
+ const panel = panels[focusedPanelId];
92
+ if (panel?.activeTabId === tabId) {
93
+ useNotificationStore.getState().clearForSession(sessionId);
94
+ }
95
+ };
96
+ maybeClear();
97
+ document.addEventListener("visibilitychange", maybeClear);
98
+ const unsub = usePanelStore.subscribe(maybeClear);
99
+ return () => {
100
+ document.removeEventListener("visibilitychange", maybeClear);
101
+ unsub();
102
+ };
103
+ }, [sessionId, tabId]);
104
+
82
105
  // Update tab title when SDK summary arrives
83
106
  useEffect(() => {
84
107
  if (tabId && sessionTitle) {
@@ -1,20 +1,29 @@
1
1
  import { useEffect } from "react";
2
2
  import { useNotificationStore, selectTotalUnread } from "@/stores/notification-store";
3
+ import { useProjectStore } from "@/stores/project-store";
4
+ import { useSettingsStore } from "@/stores/settings-store";
3
5
  import { setFavicon } from "@/lib/favicon";
4
6
 
5
- const DEFAULT_TITLE = "PPM Personal Project Manager";
7
+ function buildTitle(unread: number, projectName?: string, deviceName?: string): string {
8
+ const parts = [projectName, deviceName || null, "PPM"].filter(Boolean).join(" - ");
9
+ return unread > 0 ? `(${unread}) ${parts}` : parts;
10
+ }
6
11
 
7
- /** Syncs document.title and favicon with unread notification count */
12
+ /** Syncs document.title and favicon with unread notification count.
13
+ * Uses direct Zustand subscription to update immediately even in background tabs
14
+ * (useEffect is throttled by the browser when the tab is hidden). */
8
15
  export function useNotificationBadge(): void {
9
- const totalUnread = useNotificationStore(selectTotalUnread);
16
+ const activeProject = useProjectStore((s) => s.activeProject);
17
+ const deviceName = useSettingsStore((s) => s.deviceName);
10
18
 
11
19
  useEffect(() => {
12
- if (totalUnread > 0) {
13
- document.title = `(${totalUnread}) PPM`;
14
- setFavicon(true);
15
- } else {
16
- document.title = DEFAULT_TITLE;
17
- setFavicon(false);
18
- }
19
- }, [totalUnread]);
20
+ const update = () => {
21
+ const unread = selectTotalUnread(useNotificationStore.getState());
22
+ document.title = buildTitle(unread, activeProject?.name, deviceName);
23
+ setFavicon(unread > 0);
24
+ };
25
+
26
+ update(); // apply immediately on mount / when project or device name changes
27
+ return useNotificationStore.subscribe(update); // fire on every store change
28
+ }, [activeProject?.name, deviceName]);
20
29
  }
@@ -71,6 +71,8 @@ export function getHiddenUnreadDirection(
71
71
  let rightType: string | null = null;
72
72
  let rightPri = -1;
73
73
 
74
+ const scrollRect = scrollEl.getBoundingClientRect();
75
+
74
76
  for (const tab of tabs) {
75
77
  if (tab.type !== "chat") continue;
76
78
  const sessionId = tab.metadata?.sessionId as string;
@@ -78,11 +80,15 @@ export function getHiddenUnreadDirection(
78
80
  if (!entry || entry.count === 0) continue;
79
81
  const tabEl = tabRefs.get(tab.id);
80
82
  if (!tabEl) continue;
83
+ // Compute tab position relative to the scrollable content area
84
+ const tabRect = tabEl.getBoundingClientRect();
85
+ const tabLeft = tabRect.left - scrollRect.left + scrollEl.scrollLeft;
86
+ const tabRight = tabLeft + tabRect.width;
81
87
  const pri = TYPE_PRIORITY[entry.type] ?? 0;
82
- if (tabEl.offsetLeft + tabEl.offsetWidth < viewLeft && pri > leftPri) {
88
+ if (tabRight <= viewLeft && pri > leftPri) {
83
89
  leftPri = pri; leftType = entry.type;
84
90
  }
85
- if (tabEl.offsetLeft > viewRight && pri > rightPri) {
91
+ if (tabLeft >= viewRight && pri > rightPri) {
86
92
  rightPri = pri; rightType = entry.type;
87
93
  }
88
94
  }
@@ -1,7 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-client-4Ni0i4Hl.js","assets/react-CYzKIDNi.js"])))=>i.map(i=>d[i]);
2
- import{i as e,t}from"./react-CYzKIDNi.js";import{A as n}from"./input-nI4xe1Y9.js";import{n as r,t as i}from"./jsx-runtime-wQxeESYQ.js";import{a,n as o,t as s}from"./tab-store-Bm1Hw8OR.js";import{n as c}from"./settings-store-CfB0vCtQ.js";import{r as l,t as u}from"./utils-siJJ3uG0.js";import{i as d,r as f,t as p}from"./api-client-4Ni0i4Hl.js";import{A as m,C as h,D as g,E as _,F as v,G as y,H as b,I as x,K as S,O as C,P as w,U as T,V as E,_ as D,g as O,j as k,k as A,r as j,t as M,w as N}from"./index-BU_07_oW.js";import{t as P}from"./markdown-renderer-CvGYO9sH.js";var F=r(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),I=r(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),L=r(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),R=r(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),z=r(`code`,[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]),B=r(`columns-2`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M12 3v18`,key:`108xh3`}]]),V=r(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),ee=r(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),H=r(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),U=r(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),W=r(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),te=r(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),G=r(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),ne=r(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),K=r(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),q=e(t(),1),J=3e4,re=1e3,ie=class{ws=null;url;handlers=[];reconnectAttempts=0;reconnectTimer=null;intentionalClose=!1;constructor(e){this.url=e}connect(){this.intentionalClose=!1,this.cleanup();let e=window.location.protocol===`https:`?`wss:`:`ws:`,t=this.url.startsWith(`ws`)?this.url:`${e}//${window.location.host}${this.url}`;this.ws=new WebSocket(t),this.ws.onopen=()=>{this.reconnectAttempts=0;try{this.ws?.send(JSON.stringify({type:`ready`}))}catch{}},this.ws.onmessage=e=>{for(let t of this.handlers)t(e)},this.ws.onclose=()=>{this.intentionalClose||this.scheduleReconnect()},this.ws.onerror=()=>{this.ws?.close()}}disconnect(){this.intentionalClose=!0,this.cleanup(),this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null)}send(e){this.ws?.readyState===WebSocket.OPEN&&this.ws.send(e)}onMessage(e){return this.handlers.push(e),()=>{this.handlers=this.handlers.filter(t=>t!==e)}}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}cleanup(){this.ws&&=(this.ws.onopen=null,this.ws.onclose=null,this.ws.onmessage=null,this.ws.onerror=null,(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)&&this.ws.close(),null)}scheduleReconnect(){let e=Math.min(re*2**this.reconnectAttempts,J);this.reconnectAttempts++,this.reconnectTimer=setTimeout(()=>this.connect(),e)}};function ae({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,q.useRef)(null);return(0,q.useEffect)(()=>{let i=new ie(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,q.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,q.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,q.useCallback)(()=>{r.current?.disconnect()},[])}}var oe=null;function Y(){return oe||=new AudioContext,oe}function X(e,t,n,r,i=`sine`){let a=Y(),o=a.createOscillator(),s=a.createGain();o.type=i,o.frequency.value=e,s.gain.setValueAtTime(r,n),s.gain.exponentialRampToValueAtTime(.001,n+t),o.connect(s),s.connect(a.destination),o.start(n),o.stop(n+t)}function se(){let e=Y().currentTime;X(523,.15,e,.15),X(659,.2,e+.12,.15)}function ce(){let e=Y().currentTime;X(880,.12,e,.18,`square`),X(698,.12,e+.15,.18,`square`),X(880,.15,e+.3,.15,`square`)}function le(){let e=Y().currentTime;X(440,.12,e,.12),X(523,.12,e+.1,.12),X(659,.18,e+.2,.12)}var ue={done:se,approval_request:ce,question:le};function de(e){try{ue[e]?.()}catch{}}function fe(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=o.getState(),r=t[n];if(!r)return!1;let i=r.tabs.find(e=>e.id===r.activeTabId);return i?.type===`chat`&&i.metadata?.sessionId===e}function pe(e,t=`claude`,n=``){let[r,i]=(0,q.useState)([]),[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(`idle`),[p,m]=(0,q.useState)(0),[h,g]=(0,q.useState)(15),[_,v]=(0,q.useState)(null),[y,b]=(0,q.useState)(null),[x,S]=(0,q.useState)(null),[C,w]=(0,q.useState)(!1),T=(0,q.useRef)(``),E=(0,q.useRef)([]),O=(0,q.useRef)(!1),k=(0,q.useRef)(null),A=(0,q.useRef)(()=>{}),j=(0,q.useRef)(null),M=(0,q.useRef)(e);M.current=e;let N=(0,q.useRef)(n);N.current=n;let P=(0,q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type===`ping`)return;if(t.type===`title_updated`){S(t.title??null);return}if(t.type===`streaming_status`){let e=t.status??`idle`;if(u(e),m(e===`connecting`?t.elapsed??0:0),e===`connecting`){let e=t.effort,n=t.thinkingBudget,r=15;n&&n>0?r=Math.max(15,Math.round(n/500)):e===`high`?r=30:e===`low`&&(r=10),g(r)}return}if(t.type===`connected`){w(!0),t.sessionTitle&&S(t.sessionTitle);return}if(t.type===`status`){w(!0);let e=t;e.sessionTitle&&S(e.sessionTitle),e.isStreaming&&(O.current=!0,c(!0)),e.pendingApproval&&v({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),j.current?.();return}let n=(e,t)=>{let n=E.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=E.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return E.current[n]={...r,children:i},!0},r=()=>{let e=T.current,t=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`&&!r.id.startsWith(`final-`)?[...n.slice(0,-1),{...r,content:e,events:t}]:[...n,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:t,timestamp:new Date().toISOString()}]})};switch(t.type){case`text`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}T.current+=t.content,E.current.push(t),r();break}case`thinking`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`approval_request`:if(E.current.push(t),v({requestId:t.requestId,tool:t.tool,input:t.input}),M.current&&!fe(M.current)){let e=t.tool===`AskUserQuestion`?`question`:`approval_request`;D.getState().addNotification(M.current,e,N.current),de(e)}break;case`error`:{E.current.push(t);let e=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,events:e}]:[...n,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]}),O.current=!1,c(!1),u(`idle`);break}case`done`:{if(!O.current)break;t.contextWindowPct!=null&&b(t.contextWindowPct),M.current&&!fe(M.current)&&(D.getState().addNotification(M.current,`done`,N.current),de(`done`));let e=T.current,n=[...E.current];i(t=>{let r=t[t.length-1];return r?.role===`assistant`?[...t.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:n.length>0?n:r.events}]:t}),T.current=``,E.current=[],O.current=!1,c(!1),u(`idle`);break}}},[]),{send:F,connect:I}=ae({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:P,autoConnect:!!e&&!!n});A.current=F,(0,q.useEffect)(()=>{let r=!1;return c(!1),v(null),T.current=``,E.current=[],w(!1),e&&n?(o(!0),fetch(`${d(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${f()}`}}).then(e=>e.json()).then(e=>{r||O.current||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&!O.current&&i([])}).finally(()=>{r||o(!1)})):i([]),()=>{r=!0}},[e,t,n]);let L=(0,q.useCallback)(e=>{if(e.trim()){if(O.current){let e=T.current,t=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),F(JSON.stringify({type:`cancel`}))}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),T.current=``,E.current=[],k.current=null,O.current=!0,c(!0),u(`connecting`),v(null),F(JSON.stringify({type:`message`,content:e}))}},[F]),R=(0,q.useCallback)((e,t,n)=>{if(F(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=E.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`);if(t){let e=t.input;e&&typeof e==`object`&&(e.answers=n)}i(e=>[...e])}v(null)},[F]),z=(0,q.useCallback)(()=>{if(!O.current)return;F(JSON.stringify({type:`cancel`}));let e=T.current,t=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),T.current=``,E.current=[],k.current=null,O.current=!1,c(!1),v(null)},[F]),B=(0,q.useCallback)(()=>{w(!1),I(),j.current?.()},[I]),V=(0,q.useCallback)(()=>{!e||!n||(o(!0),fetch(`${d(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${f()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(i(e.data),T.current=``,E.current=[])}).catch(()=>{}).finally(()=>o(!1)))},[e,t,n]);return j.current=V,{messages:r,messagesLoading:a,isStreaming:s,streamingStatus:l,connectingElapsed:p,thinkingWarningThreshold:h,pendingApproval:_,contextWindowPct:y,sessionTitle:x,sendMessage:L,respondToApproval:R,cancelStreaming:z,reconnect:B,refetchMessages:V,isConnected:C}}var me=3e4;function he(e,t=`claude`){let[n,r]=(0,q.useState)({}),[i,a]=(0,q.useState)(!1),[o,s]=(0,q.useState)(null),c=(0,q.useRef)(null),l=(0,q.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${d(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${f()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),e.data.lastFetchedAt&&s(e.data.lastFetchedAt))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,q.useEffect)(()=>(l(),c.current=setInterval(()=>l(),me),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,q.useCallback)(()=>l(!0),[l])}}var ge={damping:.7,stiffness:.05,mass:1.25},_e=70,ve=1e3/60,ye=350,Z=!1;globalThis.document?.addEventListener(`mousedown`,()=>{Z=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{Z=!1}),globalThis.document?.addEventListener(`click`,()=>{Z=!1});var be=(e={})=>{let[t,n]=(0,q.useState)(!1),[r,i]=(0,q.useState)(e.initial!==!1),[a,o]=(0,q.useState)(!1),s=(0,q.useRef)(null);s.current=e;let c=(0,q.useCallback)(()=>{if(!Z)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let t=e.getRangeAt(0);return t.commonAncestorContainer.contains(g.current)||g.current?.contains(t.commonAncestorContainer)},[]),l=(0,q.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,q.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,q.useMemo)(()=>{let n;return{escapedFromLock:t,isAtBottom:r,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return g.current?.scrollTop??0},set scrollTop(e){g.current&&(g.current.scrollTop=e,d.ignoreScrollToTop=g.current.scrollTop)},get targetScrollTop(){return!g.current||!_.current?0:g.current.scrollHeight-1-g.current.clientHeight},get calculatedTargetScrollTop(){if(!g.current||!_.current)return 0;let{targetScrollTop:t}=this;if(!e.targetScrollTop)return t;if(n?.targetScrollTop===t)return n.calculatedScrollTop;let r=Math.max(Math.min(e.targetScrollTop(t,{scrollElement:g.current,contentElement:_.current}),t),0);return n={targetScrollTop:t,calculatedScrollTop:r},requestAnimationFrame(()=>{n=void 0}),r},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=_e}}},[]),f=(0,q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Ce(s.current,e.animation),{ignoreEscapes:r=!1}=e,i,a=d.calculatedTargetScrollTop;e.duration instanceof Promise?e.duration.finally(()=>{i=Date.now()}):i=t+(e.duration??0);let o=async()=>{let e=new Promise(requestAnimationFrame).then(()=>{if(!d.isAtBottom)return d.animation=void 0,!1;let{scrollTop:l}=d,u=performance.now(),p=(u-(d.lastTick??u))/ve;if(d.animation||={behavior:n,promise:e,ignoreEscapes:r},d.animation.behavior===n&&(d.lastTick=u),c()||t>Date.now())return o();if(l<Math.min(a,d.calculatedTargetScrollTop)){if(d.animation?.behavior===n){if(n===`instant`)return d.scrollTop=d.calculatedTargetScrollTop,o();d.velocity=(n.damping*d.velocity+n.stiffness*d.scrollDifference)/n.mass,d.accumulated+=d.velocity*p,d.scrollTop+=d.accumulated,d.scrollTop!==l&&(d.accumulated=0)}return o()}return i>Date.now()?(a=d.calculatedTargetScrollTop,o()):(d.animation=void 0,d.scrollTop<d.calculatedTargetScrollTop?f({animation:Ce(s.current,s.current.resize),ignoreEscapes:r,duration:Math.max(0,i-Date.now())||void 0}):d.isAtBottom)});return e.then(e=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),e))};return e.wait!==!0&&(d.animation=void 0),d.animation?.behavior===n?d.animation.promise:o()},[l,c,d]),p=(0,q.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,q.useCallback)(({target:e})=>{if(e!==g.current)return;let{scrollTop:t,ignoreScrollToTop:n}=d,{lastScrollTop:r=t}=d;d.lastScrollTop=t,d.ignoreScrollToTop=void 0,n&&n>t&&(r=n),o(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||t===n)return;if(c()){u(!0),l(!1);return}let e=t>r,i=t<r;if(d.animation?.ignoreEscapes){d.scrollTop=r;return}i&&(u(!0),l(!1)),e&&u(!1),!d.escapedFromLock&&d.isNearBottom&&l(!0)},1)},[u,l,c,d]),h=(0,q.useCallback)(({target:e,deltaY:t})=>{let n=e;for(;![`scroll`,`auto`].includes(getComputedStyle(n).overflow);){if(!n.parentElement)return;n=n.parentElement}n===g.current&&t<0&&g.current.scrollHeight>g.current.clientHeight&&!d.animation?.ignoreEscapes&&(u(!0),l(!1))},[u,l,d]),g=xe(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=xe(e=>{if(d.resizeObserver?.disconnect(),!e)return;let t;d.resizeObserver=new ResizeObserver(([e])=>{let{height:n}=e.contentRect,r=n-(t??n);if(d.resizeDifference=r,d.scrollTop>d.targetScrollTop&&(d.scrollTop=d.targetScrollTop),o(d.isNearBottom),r>=0){let e=Ce(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:ye})}else d.isNearBottom&&(u(!1),l(!0));t=n,requestAnimationFrame(()=>{setTimeout(()=>{d.resizeDifference===r&&(d.resizeDifference=0)},1)})}),d.resizeObserver?.observe(e)},[]);return{contentRef:_,scrollRef:g,scrollToBottom:f,stopScroll:p,isAtBottom:r||a,isNearBottom:a,escapedFromLock:t,state:d}};function xe(e,t){let n=(0,q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Se=new Map;function Ce(...e){let t={...ge},n=!1;for(let r of e){if(r===`instant`){n=!0;continue}typeof r==`object`&&(n=!1,t.damping=r.damping??t.damping,t.stiffness=r.stiffness??t.stiffness,t.mass=r.mass??t.mass)}let r=JSON.stringify(t);return Se.has(r)||Se.set(r,Object.freeze(t)),n?`instant`:Se.get(r)}var we=(0,q.createContext)(null),Te=typeof window<`u`?q.useLayoutEffect:q.useEffect;function Ee({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,q.useRef)(null),d=be({mass:i,damping:a,stiffness:o,resize:n,initial:r,targetScrollTop:q.useCallback((e,t)=>(y?.targetScrollTop??s)?.(e,t)??e,[s])}),{scrollRef:f,contentRef:p,scrollToBottom:m,stopScroll:h,isAtBottom:g,escapedFromLock:_,state:v}=e??d,y=(0,q.useMemo)(()=>({scrollToBottom:m,stopScroll:h,scrollRef:f,isAtBottom:g,escapedFromLock:_,contentRef:p,state:v,get targetScrollTop(){return u.current},set targetScrollTop(e){u.current=e}}),[m,g,p,f,h,_,v]);return(0,q.useImperativeHandle)(c,()=>y,[y]),Te(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),q.createElement(we.Provider,{value:y},q.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=De();return q.createElement(`div`,{ref:r.scrollRef,style:{height:`100%`,width:`100%`,scrollbarGutter:`stable both-edges`},className:t},q.createElement(`div`,{...n,ref:r.contentRef},typeof e==`function`?e(r):e))}e.Content=t})(Ee||={});function De(){let e=(0,q.useContext)(we);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var Q=i();function Oe(e){let t=e.type===`approval_request`;return{toolName:e.type===`tool_use`?e.tool:t?e.tool??`Tool`:`Tool`,input:e.type===`tool_use`?e.input:t?e.input??{}:{}}}function ke({tool:e,result:t,completed:n,projectName:r}){let[i,a]=(0,q.useState)(!1);if(e.type===`error`)return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded bg-red-500/10 border border-red-500/20 px-2 py-1.5 text-xs text-red-400`,children:[(0,Q.jsx)(b,{className:`size-3`}),(0,Q.jsx)(`span`,{children:e.message})]});let{toolName:o,input:s}=Oe(e),c=t?.type===`tool_result`,l=c&&!!t.isError,u=o===`AskUserQuestion`&&!!s?.answers,d=(o===`Agent`||o===`Task`)&&e.type===`tool_use`,f=d?e.children:void 0,p=f&&f.length>0;return(0,Q.jsxs)(`div`,{className:`rounded border text-xs ${d?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,Q.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors min-w-0`,children:[i?(0,Q.jsx)(y,{className:`size-3 shrink-0`}):(0,Q.jsx)(T,{className:`size-3 shrink-0`}),l?(0,Q.jsx)(R,{className:`size-3 text-red-400 shrink-0`}):c||u||n?(0,Q.jsx)(E,{className:`size-3 text-green-400 shrink-0`}):(0,Q.jsx)(k,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,Q.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,Q.jsx)(Ae,{name:o,input:s})}),p&&(0,Q.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[f.length,` steps`]})]}),i&&(0,Q.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,Q.jsx)(je,{name:o,input:s,projectName:r}),p&&(0,Q.jsx)(Fe,{events:f,projectName:r}),c&&(0,Q.jsx)(Ne,{toolName:o,output:t.output})]})]})}function Ae({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:u(n(t.file_path))})]});case`Bash`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`font-mono text-text-subtle`,children:$(n(t.command),60)})]});case`Glob`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`font-mono text-text-subtle`,children:$(n(t.pattern),40)})]});case`WebSearch`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(g,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.query),50)})]});case`WebFetch`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(V,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.url),50)})]});case`ToolSearch`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(g,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.query),50)})]});case`Agent`:case`Task`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(L,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=Array.isArray(t.todos)?t.todos:[],r=n.filter(e=>e.status===`completed`).length;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(U,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=Array.isArray(t.questions)?t.questions:[],r=!!t.answers;return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,Q.jsx)(Q.Fragment,{children:e})}}function je({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=s(),o=e=>{n&&i({type:`editor`,title:u(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},c=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${u(e)}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,Q.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,Q.jsx)(`pre`,{className:`font-mono text-text-secondary overflow-x-auto whitespace-pre-wrap break-all`,children:r(t.command)})]});case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:{let n=r(t.file_path);return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`font-mono text-text-secondary break-all hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>o(n),title:`Open file in editor`,children:[(0,Q.jsx)(a,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,Q.jsxs)(`button`,{type:`button`,className:`text-text-subtle hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>c(n,r(t.old_string),r(t.new_string)),title:`View diff in new tab`,children:[(0,Q.jsx)(B,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,Q.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:$(r(t.content),300)})]})}case`Glob`:return(0,Q.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,Q.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,Q.jsx)(Me,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,Q.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,Q.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,Q.jsx)(Ie,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,Q.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsxs)(`a`,{href:r(t.url),target:`_blank`,rel:`noopener noreferrer`,className:`font-mono text-primary hover:underline break-all flex items-center gap-1`,children:[(0,Q.jsx)(V,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,Q.jsx)(`p`,{className:`text-text-subtle`,children:$(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,Q.jsx)(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-xs border ${(n[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border text-text-subtle`}`,children:t.label},r))}),n[e.question]&&(0,Q.jsxs)(`p`,{className:`text-accent text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,Q.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function Me({todos:e}){return(0,Q.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`shrink-0 mt-0.5 ${e.status===`completed`?`text-green-400`:e.status===`in_progress`?`text-yellow-400`:`text-text-subtle`}`,children:e.status===`completed`?`✓`:e.status===`in_progress`?`▶`:`○`}),(0,Q.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function Ne({toolName:e,output:t}){let[n,r]=(0,q.useState)(!1),i=(0,q.useMemo)(()=>{if(e!==`Agent`&&e!==`Task`)return null;try{let e=JSON.parse(t);if(Array.isArray(e)){let t=e.filter(e=>e.type===`text`&&e.text).map(e=>e.text).join(`
3
-
4
- `);if(t)return t}if(typeof e==`string`)return e}catch{if(t&&!t.startsWith(`[{`))return t}return null},[e,t]);return i?(0,Q.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,Q.jsx)(Ie,{content:i,maxHeight:`max-h-60`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>r(!n),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors`,children:[(0,Q.jsx)(z,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,Q.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,Q.jsx)(Pe,{output:t})}function Pe({output:e}){let t=e.split(`
5
- `).length,n=t>3||e.length>200,[r,i]=(0,q.useState)(n);return(0,Q.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>i(!r),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors mb-1`,children:[r?(0,Q.jsx)(T,{className:`size-3`}):(0,Q.jsx)(y,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,Q.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono whitespace-pre-wrap break-all ${r?`max-h-16 overflow-hidden`:`max-h-60`}`,children:e})]})}function Fe({events:e,projectName:t}){let n=[],r=``;for(let t of e)if(t.type===`text`)r+=t.content;else if(t.type===`tool_use`)r&&=(n.push({kind:`text`,content:r}),``),n.push({kind:`tool`,tool:t});else if(t.type===`tool_result`){let e=t.toolUseId,r=e?n.find(t=>t.kind===`tool`&&t.tool.type===`tool_use`&&t.tool.toolUseId===e&&!t.result):n.findLast(e=>e.kind===`tool`&&!e.result);r&&(r.result=t)}return r&&n.push({kind:`text`,content:r}),(0,Q.jsx)(`div`,{className:`border-l-2 border-accent/20 pl-2 space-y-1 mt-1`,children:n.map((e,n)=>e.kind===`text`?(0,Q.jsx)(`div`,{className:`text-text-secondary text-[11px]`,children:(0,Q.jsx)(Ie,{content:e.content,maxHeight:`max-h-24`})},`st-${n}`):(0,Q.jsx)(ke,{tool:e.tool,result:e.result,completed:!!e.result,projectName:t},`sc-${n}`))})}function Ie({content:e,maxHeight:t=`max-h-48`}){return(0,Q.jsx)(P,{content:e,className:`text-text-secondary overflow-auto ${t}`})}function $(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}function Le(e){let[t,n]=(0,q.useState)({}),[r,i]=(0,q.useState)({}),[a,o]=(0,q.useState)(0),s=(0,q.useCallback)((e,t)=>{n(n=>({...n,[e]:[t]})),i(t=>({...t,[e]:``}))},[]),c=(0,q.useCallback)((e,t)=>{n(n=>{let r=n[e]||[];return{...n,[e]:r.includes(t)?r.filter(e=>e!==t):[...r,t]}})},[]),l=(0,q.useCallback)((e,t)=>{i(n=>({...n,[e]:t})),t&&n(t=>({...t,[e]:[]}))},[]),u=(0,q.useCallback)(e=>(t[e]?.length??0)>0||(r[e]?.trim().length??0)>0,[t,r]);return{answers:t,customInputs:r,activeTab:a,setActiveTab:o,handleSingleSelect:s,handleMultiSelect:c,handleCustomInput:l,hasAnswer:u,allAnswered:(0,q.useMemo)(()=>e.every((e,t)=>u(t)),[e,u]),getFinalAnswer:(0,q.useCallback)(e=>r[e]?.trim()||(t[e]??[]).join(`, `),[t,r]),goToNextTab:(0,q.useCallback)(()=>o(t=>Math.min(t+1,e.length-1)),[e.length]),goToPrevTab:(0,q.useCallback)(()=>o(e=>Math.max(e-1,0)),[])}}function Re(e){let[t,n]=(0,q.useState)(0),r=(0,q.useRef)(null);return(0,q.useEffect)(()=>n(0),[e.activeTab]),(0,q.useEffect)(()=>{if(!e.enabled)return;let i=r=>{let i=document.activeElement===e.customInputRef.current;if(!i&&r.key>=`1`&&r.key<=`9`){r.preventDefault();let t=parseInt(r.key)-1;t<e.totalOptions-1&&(n(t),e.onSelectOption(t));return}if(!i&&(r.key===`o`||r.key===`O`||r.key===`0`)){r.preventDefault(),e.customInputRef.current?.focus(),n(e.totalOptions-1);return}if(r.key===`Tab`&&e.questions.length>1){r.preventDefault(),r.shiftKey?e.goToPrevTab():e.goToNextTab();return}if(!i){if(r.key===`ArrowLeft`){r.preventDefault(),e.goToPrevTab();return}if(r.key===`ArrowRight`){r.preventDefault(),e.goToNextTab();return}if(r.key===`ArrowUp`){r.preventDefault(),n(e=>Math.max(0,e-1));return}if(r.key===`ArrowDown`){r.preventDefault(),n(t=>Math.min(e.totalOptions-1,t+1));return}if(r.key===` `){r.preventDefault(),e.onSelectOption(t);return}}if(r.key===`Enter`){r.preventDefault(),e.allAnswered?e.onSubmit():e.hasAnswer(e.activeTab)&&e.goToNextTab();return}r.key===`Escape`&&i&&e.customInputRef.current?.blur()},a=r.current;return a&&(a.addEventListener(`keydown`,i),a.setAttribute(`tabindex`,`0`),a.contains(document.activeElement)||a.focus()),()=>{a?.removeEventListener(`keydown`,i)}},[e,t]),{focusedOption:t,setFocusedOption:n,containerRef:r}}function ze({questions:e,onSubmit:t,onSkip:n}){let r=(0,q.useRef)(null),i=Le(e),a=e[i.activeTab],o=a?a.options.length+1:0,s=e.length>1,c=(0,q.useCallback)(()=>{if(!i.allAnswered)return;let n={};e.forEach((e,t)=>{n[e.question]=i.getFinalAnswer(t)}),t(n)},[i.allAnswered,i.getFinalAnswer,e,t]),l=(0,q.useCallback)(e=>{if(!(!a||e<0))if(e<a.options.length){let t=a.options[e]?.label;if(!t)return;a.multiSelect?i.handleMultiSelect(i.activeTab,t):i.handleSingleSelect(i.activeTab,t)}else e===a.options.length&&r.current?.focus()},[a,i]),u=Re({questions:e,activeTab:i.activeTab,totalOptions:o,allAnswered:i.allAnswered,hasAnswer:i.hasAnswer,onSelectOption:l,goToNextTab:i.goToNextTab,goToPrevTab:i.goToPrevTab,onSubmit:c,customInputRef:r,enabled:!0}),d=(0,q.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,Q.jsxs)(`div`,{ref:u.containerRef,className:`rounded-lg border-2 border-primary/30 bg-primary/5 p-3 space-y-3 outline-none animate-in slide-in-from-bottom-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,Q.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,Q.jsxs)(`span`,{className:`text-[10px] text-text-secondary font-normal`,children:[s?`←→ tabs · `:``,`↑↓ options · 1-`,Math.min(o-1,9),` select · Enter submit`]})]}),s&&(0,Q.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,Q.jsxs)(`button`,{className:`flex items-center gap-1.5 px-3 py-1.5 rounded text-xs whitespace-nowrap transition-all ${i.activeTab===t?`bg-primary text-primary-foreground`:i.hasAnswer(t)?`text-primary bg-transparent`:`text-text-secondary hover:bg-surface-elevated`}`,onClick:()=>{i.setActiveTab(t),u.setFocusedOption(0)},tabIndex:-1,children:[(0,Q.jsx)(`span`,{className:`flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-semibold ${i.activeTab===t?`bg-white/20`:i.hasAnswer(t)?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:i.hasAnswer(t)?`✓`:t+1}),(0,Q.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,Q.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,Q.jsx)(`div`,{className:`text-sm text-text-primary`,children:a.question}),a.multiSelect&&(0,Q.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a.options.map((e,t)=>{let n=(i.answers[i.activeTab]||[]).includes(e.label),r=u.focusedOption===t;return(0,Q.jsxs)(`button`,{onClick:()=>d(t),className:`text-left flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border transition-all ${n?`border-primary bg-primary/10 text-text-primary`:`border-border bg-background text-text-secondary hover:border-primary/40 hover:bg-primary/5`} ${r?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,Q.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded text-[10px] font-semibold shrink-0 mt-px ${n?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:t+1}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,Q.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,Q.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border border-dashed transition-all border-border bg-transparent ${u.focusedOption===o-1?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,Q.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded bg-surface-elevated text-text-secondary text-[10px] font-semibold shrink-0 mt-px`,children:`O`}),(0,Q.jsx)(`input`,{ref:r,type:`text`,className:`flex-1 px-2 py-1 text-xs bg-surface border border-border rounded text-text-primary outline-none placeholder:text-text-subtle focus:border-primary`,placeholder:`Other (press O to type)...`,value:i.customInputs[i.activeTab]||``,onChange:e=>i.handleCustomInput(i.activeTab,e.target.value),onFocus:()=>u.setFocusedOption(o-1)})]})]})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToPrevTab,disabled:i.activeTab===0,tabIndex:-1,children:`← Prev`}),(0,Q.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToNextTab,disabled:i.activeTab===e.length-1,tabIndex:-1,children:`Next →`})]}),(0,Q.jsx)(`button`,{onClick:n,className:`px-4 py-1.5 rounded border border-border bg-background text-text-secondary text-xs hover:bg-surface-elevated transition-colors`,tabIndex:-1,children:`Skip`}),(0,Q.jsxs)(`button`,{onClick:c,disabled:!i.allAnswered,className:`px-4 py-1.5 rounded bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,tabIndex:-1,children:[`Submit `,i.allAnswered?`✓`:`(${e.filter((e,t)=>i.hasAnswer(t)).length}/${e.length})`]})]})]})}function Be({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,streamingStatus:a,connectingElapsed:o,thinkingWarningThreshold:s,projectName:c,onFork:l}){return t?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,Q.jsx)(L,{className:`size-10 text-text-subtle animate-pulse`}),(0,Q.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!i?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,Q.jsx)(L,{className:`size-10 text-text-subtle`}),(0,Q.jsx)(`p`,{className:`text-sm`,children:`Send a message to start the conversation`})]}):(0,Q.jsxs)(Ee,{className:`flex-1 overflow-y-auto`,resize:`smooth`,initial:`instant`,children:[(0,Q.jsxs)(Ee.Content,{className:`p-4 space-y-4`,children:[e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return t||n}).map(e=>(0,Q.jsx)(He,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:c,onFork:e.role===`user`&&l?()=>l(e.content):void 0},e.id)),n&&(n.tool===`AskUserQuestion`?(0,Q.jsx)(rt,{approval:n,onRespond:r}):(0,Q.jsx)(nt,{approval:n,onRespond:r})),i&&(0,Q.jsx)(et,{lastMessage:e[e.length-1],streamingStatus:a,elapsed:o,warningThreshold:s})]}),(0,Q.jsx)(Ve,{})]})}function Ve(){let{isAtBottom:e,scrollToBottom:t}=De();return e?null:(0,Q.jsxs)(`button`,{onClick:()=>t(),className:`absolute bottom-2 left-1/2 -translate-x-1/2 flex items-center gap-1 px-3 py-1 rounded-full bg-surface-elevated border border-border text-xs text-text-secondary hover:text-foreground shadow-lg transition-all`,children:[(0,Q.jsx)(y,{className:`size-3`}),`Scroll to bottom`]})}function He({message:e,isStreaming:t,projectName:n,onFork:r}){return e.role===`user`?(0,Q.jsx)(Je,{content:e.content,projectName:n,onFork:r}):e.role===`system`?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-red-500/10 border border-red-500/20 px-3 py-2 text-sm text-red-400`,children:[(0,Q.jsx)(b,{className:`size-4 shrink-0`}),(0,Q.jsx)(`p`,{children:e.content})]}):(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.events&&e.events.length>0?(0,Q.jsx)(Ze,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,Q.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,Q.jsx)(tt,{content:e.content,projectName:n})})})}var Ue=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function We(e){let t=e.match(/^\[Attached file: (.+?)\]\n\n?/);if(t)return{files:[t[1]],text:e.slice(t[0].length)};let n=e.match(/^\[Attached files:\n([\s\S]+?)\]\n\n?/);return n?{files:n[1].split(`
6
- `).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function Ge(e,t){let n=u(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function Ke(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Ue.has(e.slice(t).toLowerCase())}function qe(e){return e.toLowerCase().endsWith(`.pdf`)}function Je({content:e,projectName:t,onFork:r}){let{files:i,text:a}=(0,q.useMemo)(()=>We(e),[e]);return(0,Q.jsx)(`div`,{className:`flex justify-end group/user`,children:(0,Q.jsxs)(`div`,{className:`rounded-lg bg-primary/10 px-3 py-2 text-sm text-text-primary max-w-[85%] space-y-2 relative`,children:[i.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:i.map((e,n)=>Ke(e)?(0,Q.jsx)(Ye,{src:Ge(e,t),alt:u(e)||`image`},n):qe(e)?(0,Q.jsx)(Xe,{src:Ge(e,t),filename:u(e)||`document.pdf`,mimeType:`application/pdf`},n):(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,Q.jsx)(x,{className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate max-w-40`,children:u(e)})]},n))}),a&&(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:a}),r&&(0,Q.jsx)(`button`,{onClick:r,title:`Retry from this message (fork session)`,className:`absolute -left-8 top-1/2 -translate-y-1/2 opacity-0 group-hover/user:opacity-100 transition-opacity size-6 flex items-center justify-center rounded bg-surface border border-border text-text-subtle hover:text-text-primary hover:bg-surface-elevated`,children:(0,Q.jsx)(n,{className:`size-3`})})]})})}function Ye({src:e,alt:t}){let[n,r]=(0,q.useState)(null),[i,a]=(0,q.useState)(!1);return(0,q.useEffect)(()=>{let t,n=f();return fetch(e,{headers:n?{Authorization:`Bearer ${n}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed to load`);return e.blob()}).then(e=>{let n=URL.createObjectURL(e);t=n,r(n)}).catch(()=>a(!0)),()=>{t&&URL.revokeObjectURL(t)}},[e]),i?(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,Q.jsx)(H,{className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate max-w-40`,children:t})]}):n?(0,Q.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`block`,children:(0,Q.jsx)(`img`,{src:n,alt:t,className:`rounded-md max-h-48 max-w-full object-contain border border-border`})}):(0,Q.jsx)(`div`,{className:`rounded-md bg-surface border border-border h-24 w-32 animate-pulse`})}function Xe({src:e,filename:t,mimeType:n}){let[r,i]=(0,q.useState)(!1);return(0,Q.jsxs)(`button`,{type:`button`,onClick:(0,q.useCallback)(async()=>{i(!0);try{let t=f(),r=await fetch(e,{headers:t?{Authorization:`Bearer ${t}`}:{}});if(!r.ok)throw Error(`Failed to load`);let i=await r.blob(),a=URL.createObjectURL(new Blob([i],{type:n}));window.open(a,`_blank`),setTimeout(()=>URL.revokeObjectURL(a),6e4)}catch{window.open(e,`_blank`)}finally{i(!1)}},[e,n]),disabled:r,className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary hover:bg-surface hover:text-text-primary transition-colors cursor-pointer disabled:opacity-50`,children:[(0,Q.jsx)(x,{className:`size-3.5 shrink-0 text-red-400`}),(0,Q.jsx)(`span`,{className:`truncate max-w-40`,children:t}),r&&(0,Q.jsx)(`span`,{className:`animate-spin text-[10px]`,children:`...`})]})}function Ze({events:e,isStreaming:t,projectName:n}){let r=[],i=``,a=``;for(let t=0;t<e.length;t++){let n=e[t];if(n.type===`thinking`){i&&=(r.push({kind:`text`,content:i}),``),a+=n.content;continue}a&&=(r.push({kind:`thinking`,content:a}),``),n.type===`text`?i+=n.content:n.type===`tool_use`?(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n})):n.type===`tool_result`||(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n}))}a&&r.push({kind:`thinking`,content:a}),i&&r.push({kind:`text`,content:i});let o=e.filter(e=>e.type===`tool_result`);for(let e of o){let t=e.toolUseId;if(t){let n=r.find(e=>e.kind===`tool`&&e.tool.type===`tool_use`&&e.tool.toolUseId===t);if(n){n.result=e;continue}}let n=r.find(e=>e.kind===`tool`&&!e.result);n&&(n.result=e)}for(let e=0;e<r.length;e++){let n=r[e];if(n.kind===`tool`&&!n.result){let i=!1;if(n.tool.type===`tool_use`&&n.tool.tool===`Read`){let t=n.tool.input?.file_path;t&&(i=r.slice(e+1).some(e=>e.kind===`tool`&&e.result&&e.tool.type===`tool_use`&&e.tool.tool===`Edit`&&e.tool.input?.file_path===t))}n.completed=i||!t}}return(0,Q.jsx)(Q.Fragment,{children:r.map((e,i)=>{if(e.kind===`thinking`)return(0,Q.jsx)(Qe,{content:e.content,isStreaming:t&&i===r.length-1},`think-${i}`);if(e.kind===`text`){let a=t&&i===r.length-1;return(0,Q.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,Q.jsx)($e,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,Q.jsx)(ke,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function Qe({content:e,isStreaming:t}){let[n,r]=(0,q.useState)(t);return(0,q.useEffect)(()=>{!t&&e.length>0&&r(!1)},[t,e.length]),(0,Q.jsxs)(`div`,{className:`rounded border border-border/50 bg-surface/30 text-xs`,children:[(0,Q.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors text-text-subtle`,children:[t?(0,Q.jsx)(k,{className:`size-3 animate-spin`}):(0,Q.jsx)(T,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,Q.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,Q.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,Q.jsx)(`div`,{className:`px-2 pb-2 text-text-subtle/80 whitespace-pre-wrap max-h-60 overflow-y-auto text-[11px] leading-relaxed`,children:e})]})}function $e({content:e,animate:t,projectName:n}){return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(tt,{content:e,projectName:n}),t&&(0,Q.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function et({lastMessage:e,streamingStatus:t,elapsed:n,warningThreshold:r=15}){let i=!e||e.role!==`assistant`,a=e?.events?.length?e.events[e.events.length-1].type===`tool_result`:!1;return!i&&!a?null:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-text-subtle`,children:[(0,Q.jsx)(k,{className:`size-3 animate-spin`}),(0,Q.jsxs)(`span`,{children:[`Thinking`,i&&(n??0)>0&&(0,Q.jsxs)(`span`,{className:`text-text-subtle/60`,children:[`... (`,n,`s)`]})]})]}),i&&(n??0)>=r&&(0,Q.jsx)(`p`,{className:`text-xs text-yellow-500/80 ml-5`,children:`Taking longer than usual — may be rate-limited or API slow. Try sending a new message to retry.`})]})}function tt({content:e,projectName:t}){return(0,Q.jsx)(P,{content:e,projectName:t,codeActions:!0})}function nt({approval:e,onRespond:t}){return(0,Q.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,Q.jsx)(G,{className:`size-4`}),(0,Q.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,Q.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,Q.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,Q.jsx)(`pre`,{className:`text-xs font-mono text-text-secondary overflow-x-auto bg-background rounded p-2 border border-border`,children:JSON.stringify(e.input,null,2)}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`button`,{onClick:()=>t(e.requestId,!0),className:`px-4 py-1.5 rounded bg-green-600 text-white text-xs font-medium hover:bg-green-500 transition-colors`,children:`Allow`}),(0,Q.jsx)(`button`,{onClick:()=>t(e.requestId,!1),className:`px-4 py-1.5 rounded bg-red-600 text-white text-xs font-medium hover:bg-red-500 transition-colors`,children:`Deny`})]})]})}function rt({approval:e,onRespond:t}){return(0,Q.jsx)(ze,{questions:e.input.questions??[],onSubmit:n=>t(e.requestId,!0,n),onSkip:()=>t(e.requestId,!1)})}var it=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),at=new Set([`application/pdf`]),ot=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],st=new Set(`.ts,.tsx,.js,.jsx,.mjs,.cjs,.py,.rb,.go,.rs,.java,.kt,.swift,.c,.cpp,.h,.hpp,.cs,.json,.yaml,.yml,.toml,.xml,.md,.mdx,.txt,.csv,.tsv,.html,.css,.scss,.less,.sass,.sh,.bash,.zsh,.fish,.sql,.graphql,.gql,.env,.ini,.cfg,.conf,.dockerfile,.makefile,.vue,.svelte,.astro,.ipynb`.split(`,`));function ct(e){return it.has(e.type)}function lt(e){if(it.has(e.type)||at.has(e.type)||ot.some(t=>e.type.startsWith(t)))return!0;let t=ut(e.name);return!!(t&&st.has(t))}function ut(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function dt({attachments:e,onRemove:t}){return e.length===0?null:(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-2 md:px-4 pt-2`,children:e.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-surface px-2 py-1 text-xs text-text-secondary max-w-48`,children:[e.previewUrl?(0,Q.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,Q.jsx)(H,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,Q.jsx)(x,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,Q.jsx)(k,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,Q.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`shrink-0 rounded-sm p-0.5 hover:bg-border/50 transition-colors`,"aria-label":`Remove ${e.name}`,children:(0,Q.jsx)(h,{className:`size-3`})})]},e.id))})}function ft(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function pt({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,q.useState)(0),s=(0,q.useRef)(null),c=(()=>{if(!t)return e.slice(0,50);let n=t.toLowerCase();return e.filter(e=>e.path.toLowerCase().includes(n)||e.name.toLowerCase().includes(n)).slice(0,50)})();(0,q.useEffect)(()=>{o(0)},[t]),(0,q.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,q.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,q.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,Q.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,Q.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,Q.jsxs)(`button`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,Q.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,Q.jsx)(w,{className:`size-4 text-amber-500`}):(0,Q.jsx)(v,{className:`size-4 text-blue-400`})}),(0,Q.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}function mt({onSend:e,isStreaming:t,onCancel:n,disabled:r,projectName:i,onSlashStateChange:a,onSlashItemsLoaded:o,slashSelected:s,onFileStateChange:c,onFileItemsLoaded:u,fileSelected:m,externalFiles:h,initialValue:g}){let[_,v]=(0,q.useState)(g??``),[y,b]=(0,q.useState)([]),x=(0,q.useRef)(null),S=(0,q.useRef)(null),C=(0,q.useRef)(null),w=(0,q.useRef)([]),T=(0,q.useRef)([]);(0,q.useEffect)(()=>{g&&(v(g),setTimeout(()=>{let e=x.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[g]),(0,q.useEffect)(()=>{if(!i){w.current=[],o?.([]);return}p.get(`${d(i)}/chat/slash-items`).then(e=>{w.current=e,o?.(e)}).catch(()=>{w.current=[],o?.([])})},[i]),(0,q.useEffect)(()=>{if(!i){T.current=[],u?.([]);return}p.get(`${d(i)}/files/tree?depth=5`).then(e=>{let t=ft(e);T.current=t,u?.(t)}).catch(()=>{T.current=[],u?.([])})},[i]),(0,q.useEffect)(()=>{if(!s)return;let e=x.current,t=e?.selectionStart??_.length,n=_.slice(0,t),r=_.slice(t),i=n.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${s.name} `);v(i+r),a?.(!1,``),c?.(!1,``),e&&(e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=i.length},0))},[s]),(0,q.useEffect)(()=>{if(!m)return;let e=x.current;if(!e)return;let t=e.selectionStart,n=_.slice(0,t),r=_.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;v(n.slice(0,t)+`@${m.path} `+r);let a=t+m.path.length+2;setTimeout(()=>{e.selectionStart=e.selectionEnd=a,e.focus()},0)}else{let t=_+`@${m.path} `;v(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}c?.(!1,``)},[m]),(0,q.useEffect)(()=>{!h||h.length===0||D(h)},[h]);let E=(0,q.useCallback)(async e=>{if(!i)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=f();r&&(n.Authorization=`Bearer ${r}`);let a=await(await fetch(`${d(i)}/chat/upload`,{method:`POST`,headers:n,body:t})).json();return a.ok&&Array.isArray(a.data)&&a.data.length>0?a.data[0].path:null}catch{return null}},[i]),D=(0,q.useCallback)(e=>{for(let t of e){if(!lt(t)){v(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=l(),n=ct(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};b(e=>[...e,i]),E(t).then(t=>{b(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}(S.current??x.current)?.focus()},[E]),O=(0,q.useCallback)(e=>{b(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),k=(0,q.useCallback)(()=>{let t=_.trim(),n=y.filter(e=>e.status===`ready`);if(!(!t&&n.length===0)&&!r){a?.(!1,``),c?.(!1,``),e(t,n),v(``);for(let e of y)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);b([]),x.current&&(x.current.style.height=`auto`),S.current&&(S.current.style.height=`auto`)}},[_,y,r,e,a,c]),A=(0,q.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),k())},[k]),j=(0,q.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.match(/(?:^|\s)\/(\S*)$/);if(r&&w.current.length>0){a?.(!0,r[1]??``),c?.(!1,``);return}let i=n.match(/@(\S*)$/);if(i&&T.current.length>0){c?.(!0,i[1]??``),a?.(!1,``);return}a?.(!1,``),c?.(!1,``)},[a,c]),M=(0,q.useCallback)(e=>{v(e),setTimeout(()=>{j(e,x.current?.selectionStart??e.length)},0)},[j]),N=(0,q.useCallback)(e=>{let t=e?.target??x.current;t&&(t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,160)+`px`)},[]),P=(0,q.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t)if(e.kind===`file`){let t=e.getAsFile();t&&n.push(t)}n.length>0&&(e.preventDefault(),D(n))},[D]),F=(0,q.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&D(t)},[D]),L=(0,q.useCallback)(e=>{e.preventDefault()},[]),R=(0,q.useCallback)(()=>{C.current?.click()},[]),z=(0,q.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&D(t),e.target.value=``},[D]),B=_.trim().length>0||y.some(e=>e.status===`ready`),V=t&&!B;return(0,Q.jsxs)(`div`,{className:`p-2 md:p-3 bg-background`,children:[(0,Q.jsxs)(`div`,{className:`border border-border rounded-xl md:rounded-2xl bg-surface shadow-sm cursor-text`,onClick:()=>!r&&(S.current??x.current)?.focus(),children:[(0,Q.jsx)(dt,{attachments:y,onRemove:O}),(0,Q.jsxs)(`div`,{className:`flex items-end gap-1 md:hidden px-2 py-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),R()},disabled:r,className:`flex items-center justify-center size-7 shrink-0 rounded-full text-text-subtle hover:text-text-primary transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,Q.jsx)(W,{className:`size-4`})}),(0,Q.jsx)(`textarea`,{ref:S,value:_,onChange:e=>{M(e.target.value),N(e)},onKeyDown:A,onPaste:P,onDrop:F,onDragOver:L,placeholder:t?`Follow-up...`:`Ask anything...`,disabled:r,rows:1,className:`flex-1 resize-none bg-transparent py-1.5 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-20`}),V?(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop`,children:(0,Q.jsx)(K,{className:`size-3`})}):(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),k()},disabled:r||!B,className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 transition-colors`,"aria-label":`Send`,children:(0,Q.jsx)(I,{className:`size-3.5`})})]}),(0,Q.jsxs)(`div`,{className:`hidden md:block`,children:[(0,Q.jsx)(`textarea`,{ref:x,value:_,onChange:e=>{M(e.target.value),N(e)},onKeyDown:A,onPaste:P,onDrop:F,onDragOver:L,placeholder:t?`Follow-up or Stop...`:`Ask anything...`,disabled:r,rows:1,className:`w-full resize-none bg-transparent px-4 pt-3 pb-1 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-40`}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),R()},disabled:r,className:`flex items-center justify-center size-8 rounded-full text-text-subtle hover:text-text-primary hover:bg-surface-elevated transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,Q.jsx)(W,{className:`size-4`})})}),(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:V?(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-8 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop response`,children:(0,Q.jsx)(K,{className:`size-3.5`})}):(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),k()},disabled:r||!B,className:`flex items-center justify-center size-8 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":`Send message`,children:(0,Q.jsx)(I,{className:`size-4`})})})]})]})]}),(0,Q.jsx)(`input`,{ref:C,type:`file`,multiple:!0,className:`hidden`,onChange:z})]})}function ht({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,q.useState)(0),s=(0,q.useRef)(null),c=e.filter(e=>{let n=t.toLowerCase();return e.name.toLowerCase().includes(n)||e.description.toLowerCase().includes(n)});(0,q.useEffect)(()=>{o(0)},[t]),(0,q.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,q.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,q.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,Q.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,Q.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,Q.jsxs)(`button`,{className:`flex items-start gap-3 w-full px-3 py-2 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,Q.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,Q.jsx)(ne,{className:`size-4 text-amber-500`}):(0,Q.jsx)(_,{className:`size-4 text-blue-500`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Q.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,Q.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,Q.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,Q.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}function gt(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function _t(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function vt(e){if(!e)return null;let t=null;if(e.resetsInMinutes!=null)t=e.resetsInMinutes;else if(e.resetsInHours!=null)t=Math.round(e.resetsInHours*60);else if(e.resetsAt){let n=new Date(e.resetsAt).getTime()-Date.now();t=n>0?Math.ceil(n/6e4):0}if(t==null)return null;if(t<=0)return`now`;let n=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60;return n>0?i>0?`${n}d ${r}h ${i}m`:r>0?`${n}d ${r}h`:`${n}d`:r>0?i>0?`${r}h ${i}m`:`${r}h`:`${i}m`}function yt({label:e,bucket:t}){if(!t)return null;let n=Math.round(t.utilization*100),r=vt(t);return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,Q.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,children:[`↻ `,r]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full rounded-full transition-all ${_t(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Q.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${gt(n)}`,children:[n,`%`]})]})]})}function bt(e){if(!e)return null;let t=Math.round((Date.now()-e)/1e3);return t<5?`just now`:t<60?`${t}s ago`:`${Math.floor(t/60)}m ago`}function xt({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastFetchedAt:a}){if(!t)return null;let o=e.queryCostUsd!=null||e.totalCostUsd!=null,s=e.session||e.weekly||e.weeklyOpus||e.weeklySonnet;return(0,Q.jsxs)(`div`,{className:`border-b border-border bg-surface px-3 py-2.5 space-y-2.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage Limits`}),a&&(0,Q.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:bt(new Date(a).getTime())})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r&&(0,Q.jsx)(`button`,{onClick:r,disabled:i,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50`,title:`Refresh usage data`,children:(0,Q.jsx)(C,{className:`size-3 ${i?`animate-spin`:``}`})}),(0,Q.jsx)(`button`,{onClick:n,className:`text-xs text-text-subtle hover:text-text-primary px-1`,children:`✕`})]})]}),s?(0,Q.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,Q.jsx)(yt,{label:`5-Hour Session`,bucket:e.session}),(0,Q.jsx)(yt,{label:`Weekly`,bucket:e.weekly}),(0,Q.jsx)(yt,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,Q.jsx)(yt,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,Q.jsxs)(`p`,{className:`text-xs text-text-subtle`,children:[`No data — run `,(0,Q.jsx)(`code`,{className:`bg-surface-elevated px-1 rounded`,children:`bun install`})]}),o&&(0,Q.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,Q.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,Q.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]})]})}function St(e){try{return new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}catch{return``}}function Ct(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function wt({projectName:e,usageInfo:t,contextWindowPct:n,usageLoading:r,refreshUsage:i,lastFetchedAt:a,sessionId:o,onSelectSession:c,onBugReport:l,isConnected:u,onReconnect:f}){let[_,v]=(0,q.useState)(null),[y,b]=(0,q.useState)([]),[x,w]=(0,q.useState)(!1),[T,E]=(0,q.useState)(``),[D,O]=(0,q.useState)(null),[M,N]=(0,q.useState)(``),P=(0,q.useRef)(null),I=s(e=>e.openTab),L=e=>{v(t=>t===e?null:e)},R=(0,q.useCallback)(async()=>{if(e){w(!0);try{b(await p.get(`${d(e)}/chat/sessions`))}catch{}finally{w(!1)}}},[e]);(0,q.useEffect)(()=>{_===`history`&&y.length===0&&R()},[_]);function z(t){c?(c(t),v(null)):I({type:`chat`,title:t.title||`Chat`,projectId:e??null,metadata:{projectName:e,sessionId:t.id},closable:!0})}let B=(0,q.useCallback)((e,t)=>{t.stopPropagation(),O(e.id),N(e.title||``),setTimeout(()=>P.current?.select(),0)},[]),V=(0,q.useCallback)(async()=>{if(!D||!M.trim()||!e){O(null);return}try{await p.patch(`${d(e)}/chat/sessions/${D}`,{title:M.trim()}),b(e=>e.map(e=>e.id===D?{...e,title:M.trim()}:e))}catch{}O(null)},[D,M,e]),H=(0,q.useCallback)(()=>O(null),[]),U=T.trim()?y.filter(e=>(e.title||``).toLowerCase().includes(T.toLowerCase())):y,W=t.fiveHour==null?null:Math.round(t.fiveHour*100),G=t.sevenDay==null?null:Math.round(t.sevenDay*100),ne=W!=null||G!=null?Ct(Math.max(W??0,G??0)):`text-text-subtle`;return(0,Q.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,Q.jsxs)(`button`,{onClick:()=>L(`history`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${_===`history`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,children:[(0,Q.jsx)(ee,{className:`size-3`}),(0,Q.jsx)(`span`,{children:`History`})]}),(0,Q.jsx)(`button`,{onClick:()=>L(`config`),className:`p-1 rounded transition-colors ${_===`config`?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:`AI Settings`,children:(0,Q.jsx)(te,{className:`size-3`})}),(0,Q.jsxs)(`button`,{onClick:()=>L(`usage`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] font-medium tabular-nums transition-colors hover:bg-surface-elevated ${_===`usage`?`bg-primary/10`:``} ${ne}`,title:`Usage limits`,children:[(0,Q.jsx)(F,{className:`size-3`}),(0,Q.jsxs)(`span`,{children:[`5h:`,W==null?`--%`:`${W}%`]}),(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,Q.jsxs)(`span`,{children:[`Wk:`,G==null?`--%`:`${G}%`]}),n!=null&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,Q.jsxs)(`span`,{className:Ct(n),children:[`Ctx:`,n,`%`]})]})]}),(0,Q.jsx)(`div`,{className:`flex-1`}),f&&(0,Q.jsx)(`button`,{onClick:f,className:`size-4 flex items-center justify-center`,title:u?`Connected`:`Disconnected — click to reconnect`,children:(0,Q.jsx)(`span`,{className:`size-2 rounded-full ${u?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]}),_===`history`&&(0,Q.jsxs)(`div`,{className:`border-t border-border/30 bg-surface`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 border-b border-border/30`,children:[(0,Q.jsx)(g,{className:`size-3 text-text-subtle shrink-0`}),(0,Q.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),placeholder:`Search sessions...`,className:`flex-1 bg-transparent text-[11px] text-text-primary outline-none placeholder:text-text-subtle`}),(0,Q.jsx)(`button`,{onClick:R,disabled:x,className:`p-0.5 rounded text-text-subtle hover:text-text-secondary transition-colors disabled:opacity-50`,title:`Refresh`,children:(0,Q.jsx)(C,{className:`size-3 ${x?`animate-spin`:``}`})})]}),(0,Q.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:x&&y.length===0?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,Q.jsx)(k,{className:`size-3.5 animate-spin text-text-subtle`})}):U.length===0?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:T?`No matching sessions`:`No sessions yet`}):U.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left hover:bg-surface-elevated transition-colors group`,children:[(0,Q.jsx)(m,{className:`size-3 shrink-0 text-text-subtle`}),D===e.id?(0,Q.jsxs)(`form`,{className:`flex items-center gap-1 flex-1 min-w-0`,onSubmit:e=>{e.preventDefault(),V()},children:[(0,Q.jsx)(`input`,{ref:P,value:M,onChange:e=>N(e.target.value),onBlur:V,onKeyDown:e=>{e.key===`Escape`&&H()},className:`flex-1 min-w-0 bg-surface-elevated text-[11px] text-text-primary px-1 py-0.5 rounded border border-border outline-none focus:border-primary`,autoFocus:!0}),(0,Q.jsx)(`button`,{type:`submit`,className:`p-0.5 text-green-500 hover:text-green-400`,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(S,{className:`size-3`})}),(0,Q.jsx)(`button`,{type:`button`,className:`p-0.5 text-text-subtle hover:text-text-secondary`,onClick:e=>{e.stopPropagation(),H()},children:(0,Q.jsx)(h,{className:`size-3`})})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{onClick:()=>z(e),className:`text-[11px] truncate flex-1 text-left`,children:e.title||`Untitled`}),(0,Q.jsx)(`button`,{onClick:t=>B(e,t),className:`p-0.5 rounded text-text-subtle hover:text-text-secondary opacity-0 group-hover:opacity-100 transition-opacity`,title:`Rename session`,children:(0,Q.jsx)(A,{className:`size-3`})})]}),D!==e.id&&e.updatedAt&&(0,Q.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:St(e.updatedAt)})]},e.id))})]}),_===`config`&&(0,Q.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2 max-h-[280px] overflow-y-auto`,children:(0,Q.jsx)(j,{compact:!0})}),_===`usage`&&(0,Q.jsx)(xt,{usage:t,visible:!0,onClose:()=>v(null),onReload:i,loading:r,lastFetchedAt:a})]})}function Tt({metadata:e,tabId:t}){let[n,r]=(0,q.useState)(e?.sessionId??null),[i,a]=(0,q.useState)(e?.providerId??`claude`),[o,l]=(0,q.useState)([]),[u,f]=(0,q.useState)(!1),[m,h]=(0,q.useState)(``),[g,_]=(0,q.useState)(null),[v,y]=(0,q.useState)([]),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(``),[w,T]=(0,q.useState)(null),[E,D]=(0,q.useState)(!1),[k,A]=(0,q.useState)(null),j=(0,q.useRef)(0),P=e?.projectName??``,F=s(e=>e.updateTab),I=c(e=>e.version),{usageInfo:L,usageLoading:R,lastFetchedAt:z,refreshUsage:B}=he(P,i);(0,q.useEffect)(()=>{!t||!n||F(t,{metadata:{...e,sessionId:n,providerId:i}})},[n,i]);let{messages:V,messagesLoading:ee,isStreaming:H,streamingStatus:U,connectingElapsed:W,thinkingWarningThreshold:te,pendingApproval:G,contextWindowPct:ne,sessionTitle:K,sendMessage:J,respondToApproval:re,cancelStreaming:ie,reconnect:ae,refetchMessages:oe,isConnected:Y}=pe(n,i,P);(0,q.useEffect)(()=>{t&&K&&F(t,{title:K})},[K]);let X=(0,q.useRef)(e?.pendingMessage);(0,q.useEffect)(()=>{if(X.current&&Y&&n){let n=X.current;X.current=void 0,t&&F(t,{metadata:{...e,pendingMessage:void 0}}),setTimeout(()=>J(n),100)}},[Y,n]),(0,q.useCallback)(()=>{s.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:P},projectId:P||null,closable:!0})},[P]);let se=(0,q.useCallback)(e=>{r(e.id),a(e.providerId),t&&F(t,{title:e.title||`Chat`})},[t,F]),ce=(0,q.useCallback)(async e=>{if(!(!n||!P))try{let{api:t,projectUrl:r}=await O(async()=>{let{api:e,projectUrl:t}=await import(`./api-client-4Ni0i4Hl.js`).then(e=>e.n);return{api:e,projectUrl:t}},__vite__mapDeps([0,1])),a=await t.post(`${r(P)}/chat/sessions/${n}/fork?providerId=${i}`);s.getState().openTab({type:`chat`,title:`Fork: ${e.slice(0,30)}`,metadata:{projectName:P,sessionId:a.id,providerId:i,pendingMessage:e},projectId:P||null,closable:!0})}catch(e){console.error(`Fork failed:`,e)}},[n,P,i]),le=(0,q.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
7
- `);return n?(t.length===1?`[Attached file: ${n}]\n\n`:`[Attached files:\n${n}\n]\n\n`)+e:e},[]),ue=(0,q.useCallback)(async(e,t=[])=>{let o=le(e,t);if(o.trim()){if(!n)try{let t=P,n=await p.post(`${d(t)}/chat/sessions`,{providerId:i,title:e.slice(0,50)});r(n.id),a(n.providerId),setTimeout(()=>{J(o)},500);return}catch(e){console.error(`Failed to create session:`,e);return}J(o)}},[n,i,P,J,le]),de=(0,q.useCallback)((e,t)=>{f(e),h(t)},[]),fe=(0,q.useCallback)(e=>{_(e),f(!1),h(``),setTimeout(()=>_(null),50)},[]),me=(0,q.useCallback)(()=>{f(!1),h(``)},[]),ge=(0,q.useCallback)((e,t)=>{x(e),C(t)},[]),_e=(0,q.useCallback)(e=>{T(e),x(!1),C(``),setTimeout(()=>T(null),50)},[]),ve=(0,q.useCallback)(()=>{x(!1),C(``)},[]);return(0,Q.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,q.useCallback)(e=>{e.preventDefault(),j.current++,e.dataTransfer.types.includes(`Files`)&&D(!0)},[]),onDragLeave:(0,q.useCallback)(e=>{e.preventDefault(),j.current--,j.current===0&&D(!1)},[]),onDragOver:(0,q.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,q.useCallback)(e=>{e.preventDefault(),j.current=0,D(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&(A(t),setTimeout(()=>A(null),100))},[]),children:[E&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm border-2 border-dashed border-primary rounded-lg pointer-events-none`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,Q.jsx)(N,{className:`size-8`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),(0,Q.jsx)(Be,{messages:V,messagesLoading:ee,pendingApproval:G,onApprovalResponse:re,isStreaming:H,streamingStatus:U,connectingElapsed:W,thinkingWarningThreshold:te,projectName:P,onFork:H?void 0:ce}),(0,Q.jsxs)(`div`,{className:`border-t border-border bg-background shrink-0`,children:[(0,Q.jsx)(wt,{projectName:P,usageInfo:L,contextWindowPct:ne,usageLoading:R,refreshUsage:B,lastFetchedAt:z,sessionId:n,onSelectSession:se,onBugReport:n?()=>M(I,{sessionId:n,projectName:P}):void 0,isConnected:Y,onReconnect:()=>{Y||ae(),oe()}}),(0,Q.jsx)(ht,{items:o,filter:m,onSelect:fe,onClose:me,visible:u}),(0,Q.jsx)(pt,{items:v,filter:S,onSelect:_e,onClose:ve,visible:b}),(0,Q.jsx)(mt,{onSend:ue,isStreaming:H,onCancel:ie,projectName:P,onSlashStateChange:de,onSlashItemsLoaded:l,slashSelected:g,onFileStateChange:ge,onFileItemsLoaded:y,fileSelected:w,externalFiles:k})]})]})}export{Tt as ChatTab};
@@ -1 +0,0 @@
1
- import{i as e,t}from"./react-CYzKIDNi.js";import{A as n,t as r}from"./input-nI4xe1Y9.js";import{n as i,t as a}from"./jsx-runtime-wQxeESYQ.js";import{a as o,t as s}from"./tab-store-Bm1Hw8OR.js";import{t as c}from"./utils-siJJ3uG0.js";import{i as l,t as u}from"./api-client-4Ni0i4Hl.js";import{M as d,N as f,O as p,T as m,a as h,c as g,d as _,f as v,i as ee,j as te,l as y,m as b,o as ne,p as x,q as S,s as re,u as ie,z as ae}from"./index-BU_07_oW.js";var oe=i(`cherry`,[[`path`,{d:`M2 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`cvxqlc`}],[`path`,{d:`M12 17a5 5 0 0 0 10 0c0-2.76-2.5-5-5-3-2.5-2-5 .24-5 3Z`,key:`1ostrc`}],[`path`,{d:`M7 14c3.22-2.91 4.29-8.75 5-12 1.66 2.38 4.94 9 5 12`,key:`hqx58h`}],[`path`,{d:`M22 9c-4.29 0-7.14-2.33-10-7 5.71 0 10 4.67 10 7Z`,key:`eykp1o`}]]),C=i(`git-merge`,[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]),w=i(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]),T=e(t(),1),E=a(),D=[`#4fc3f7`,`#81c784`,`#ffb74d`,`#e57373`,`#ba68c8`,`#4dd0e1`,`#aed581`,`#ff8a65`,`#f06292`,`#7986cb`],O=32,k=20,se=5;function A({metadata:e}){let t=e?.projectName,[i,a]=(0,T.useState)(null),[o,m]=(0,T.useState)(!0),[S,C]=(0,T.useState)(null),[A,j]=(0,T.useState)(!1),[M,N]=(0,T.useState)({type:null}),[P,F]=(0,T.useState)(``),[I,L]=(0,T.useState)(null),[R,z]=(0,T.useState)([]),[le,B]=(0,T.useState)(!1),{openTab:V}=s(),H=(0,T.useCallback)(async()=>{if(t)try{m(!0),a(await u.get(`${l(t)}/git/graph?max=200`)),C(null)}catch(e){C(e instanceof Error?e.message:`Failed to fetch graph`)}finally{m(!1)}},[t]);(0,T.useEffect)(()=>{H();let e=setInterval(H,1e4);return()=>clearInterval(e)},[H]);let U=async(e,n)=>{if(t){j(!0);try{await u.post(`${l(t)}${e}`,n),await H()}catch(e){C(e instanceof Error?e.message:`Action failed`)}finally{j(!1)}}},W=e=>U(`/git/checkout`,{ref:e}),ue=e=>U(`/git/cherry-pick`,{hash:e}),de=e=>U(`/git/revert`,{hash:e}),fe=e=>U(`/git/merge`,{source:e}),pe=e=>U(`/git/branch/delete`,{name:e}),me=e=>U(`/git/push`,{branch:e}),G=async(e,t)=>{if(i?.branches.some(t=>t.name===e||t.name.endsWith(`/${e}`))){if(!window.confirm(`Branch "${e}" already exists.\nDelete it and recreate from this commit?`))return;await U(`/git/branch/delete`,{name:e})}await U(`/git/branch/create`,{name:e,from:t})},K=(e,t)=>U(`/git/tag`,{name:e,hash:t}),he=async e=>{if(t)try{let n=await u.get(`${l(t)}/git/pr-url?branch=${encodeURIComponent(e)}`);n.url&&window.open(n.url,`_blank`)}catch{}},q=e=>{navigator.clipboard.writeText(e)},ge=async e=>{if(I?.hash===e.hash){L(null);return}L(e),B(!0);try{let n=e.parents[0]??``,r=n?`ref1=${encodeURIComponent(n)}&`:``,i=await u.get(`${l(t)}/git/diff-stat?${r}ref2=${encodeURIComponent(e.hash)}`);z(Array.isArray(i)?i:[])}catch(e){console.error(`diff-stat error:`,e),z([])}finally{B(!1)}},_e=e=>{let n=e.parents[0];V({type:`git-diff`,title:`Diff ${e.abbreviatedHash}`,closable:!0,metadata:{projectName:t,ref1:n??void 0,ref2:e.hash},projectId:t??null})},{laneMap:J,maxLane:ve}=(0,T.useMemo)(()=>{let e=new Map;if(!i)return{laneMap:e,maxLane:0};let t=0,n=new Map;for(let r of i.commits){let i=n.get(r.hash);i===void 0&&(i=t++),e.set(r.hash,i),n.delete(r.hash);for(let e=0;e<r.parents.length;e++){let a=r.parents[e];n.has(a)||n.set(a,e===0?i:t++)}}return{laneMap:e,maxLane:Math.max(t-1,0)}},[i]),Y=i?.branches.find(e=>e.current),ye=(0,T.useMemo)(()=>{let e=new Map;if(!i)return e;for(let t of i.branches){let n=e.get(t.commitHash)??[];n.push({name:t.name,type:`branch`}),e.set(t.commitHash,n)}for(let t of i.commits)for(let n of t.refs)if(n.startsWith(`tag: `)){let r=n.replace(`tag: `,``),i=e.get(t.hash)??[];i.push({name:r,type:`tag`}),e.set(t.hash,i)}return e},[i]),be=(0,T.useMemo)(()=>{if(!i)return[];let e=[];for(let t=0;t<i.commits.length;t++){let n=i.commits[t],r=J.get(n.hash)??0,a=D[r%D.length];for(let o of n.parents){let s=i.commits.findIndex(e=>e.hash===o);if(s<0)continue;let c=J.get(o)??0,l=D[c%D.length],u=r*k+k/2,d=t*O+O/2,f=c*k+k/2,p=s*O+O/2,m,h=n.parents.indexOf(o)>0;if(u===f)m=`M ${u} ${d} L ${f} ${p}`;else if(h){let e=d+O;m=`M ${u} ${d} C ${u} ${e} ${f} ${d} ${f} ${e} L ${f} ${p}`}else{let e=p-O;m=`M ${u} ${d} L ${u} ${e} C ${u} ${p} ${f} ${e} ${f} ${p}`}let g=n.parents.indexOf(o)===0?a:l;e.push({d:m,color:g})}}return e},[i,J]);(ve+1)*k+k;let X=(i?.commits.length??0)*O,[Z,xe]=(0,T.useState)((typeof window<`u`&&window.innerWidth<768?6:10)*k+k),Q=(0,T.useRef)(!1),$=(0,T.useCallback)(e=>{Q.current=!0;let t=Z,n=n=>{if(!Q.current)return;let r=`touches`in n?n.touches[0].clientX:n.clientX;xe(Math.max(40,t+r-e))},r=()=>{Q.current=!1,window.removeEventListener(`mousemove`,n),window.removeEventListener(`mouseup`,r),window.removeEventListener(`touchmove`,n),window.removeEventListener(`touchend`,r)};window.addEventListener(`mousemove`,n),window.addEventListener(`mouseup`,r),window.addEventListener(`touchmove`,n,{passive:!1}),window.addEventListener(`touchend`,r)},[Z]),Se=(0,T.useCallback)(e=>{e.preventDefault(),$(e.clientX)},[$]),Ce=(0,T.useCallback)(e=>{$(e.touches[0].clientX)},[$]);if(!t)return(0,E.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`});if(o&&!i)return(0,E.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,E.jsx)(te,{className:`size-5 animate-spin`}),(0,E.jsx)(`span`,{className:`text-sm`,children:`Loading git graph...`})]});if(S&&!i)return(0,E.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-destructive text-sm`,children:[(0,E.jsx)(`p`,{children:S}),(0,E.jsx)(y,{variant:`outline`,size:`sm`,onClick:H,children:`Retry`})]});function we(e){let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}return(0,E.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b`,children:[(0,E.jsxs)(`span`,{className:`text-sm font-medium`,children:[`Git Graph`,Y?` - ${Y.name}`:``]}),(0,E.jsx)(y,{variant:`ghost`,size:`icon-xs`,onClick:H,disabled:A,children:(0,E.jsx)(p,{className:o?`animate-spin`:``})})]}),S&&(0,E.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-destructive bg-destructive/10`,children:S}),(0,E.jsx)(`div`,{className:`flex-1 overflow-y-auto overflow-x-auto md:overflow-x-hidden`,children:(0,E.jsxs)(`div`,{className:`flex min-w-max md:min-w-0`,style:{height:`${X}px`},children:[(0,E.jsxs)(`div`,{className:`sticky left-0 z-10 shrink-0 bg-background`,style:{width:`${Z}px`},children:[(0,E.jsxs)(`svg`,{width:Z,height:X,children:[be.map((e,t)=>(0,E.jsx)(`path`,{d:e.d,stroke:e.color,strokeWidth:2,fill:`none`},t)),i?.commits.map((e,t)=>{let n=J.get(e.hash)??0,r=n*k+k/2,i=t*O+O/2,a=D[n%D.length];return(0,E.jsx)(`circle`,{cx:r,cy:i,r:se,fill:a,stroke:`#0f1419`,strokeWidth:2},e.hash)})]}),(0,E.jsx)(`div`,{className:`absolute top-0 right-0 w-3 md:w-2 h-full cursor-col-resize hover:bg-primary/20 flex items-center justify-center bg-primary/10 md:bg-transparent`,onMouseDown:Se,onTouchStart:Ce,children:(0,E.jsx)(d,{className:`size-3 text-muted-foreground md:opacity-0 md:hover:opacity-100`})})]}),(0,E.jsx)(`div`,{className:`flex-1 min-w-[400px]`,children:i?.commits.map((e,t)=>{let r=D[(J.get(e.hash)??0)%D.length],i=ye.get(e.hash)??[],a=i.filter(e=>e.type===`branch`),o=i.filter(e=>e.type===`tag`);return(0,E.jsxs)(ie,{children:[(0,E.jsx)(b,{asChild:!0,children:(0,E.jsx)(`div`,{className:`flex items-center hover:bg-muted/50 cursor-pointer text-sm border-b border-border/30 ${I?.hash===e.hash?`bg-primary/10`:``}`,style:{height:`${O}px`},onClick:()=>ge(e),children:(0,E.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 min-w-0 px-2`,children:[(0,E.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground w-14 shrink-0`,children:e.abbreviatedHash}),a.map(e=>(0,E.jsx)(ce,{label:e,color:r,currentBranch:Y,onCheckout:W,onMerge:fe,onPush:me,onCreatePr:he,onDelete:pe},`branch-${e.name}`)),o.map(e=>(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 bg-amber-500/20 text-amber-500 border border-amber-500/30`,children:[(0,E.jsx)(w,{className:`size-2.5`}),e.name]},`tag-${e.name}`)),(0,E.jsx)(`span`,{className:`flex-1 truncate`,children:e.subject}),(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0 hidden sm:inline`,children:e.authorName}),(0,E.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0 w-14 text-right`,children:we(e.authorDate)})]})})}),(0,E.jsxs)(_,{children:[(0,E.jsx)(v,{onClick:()=>W(e.hash),children:`Checkout`}),(0,E.jsxs)(v,{onClick:()=>{N({type:`branch`,hash:e.hash}),F(``)},children:[(0,E.jsx)(f,{className:`size-3`}),`Create Branch...`]}),(0,E.jsx)(x,{}),(0,E.jsxs)(v,{onClick:()=>ue(e.hash),children:[(0,E.jsx)(oe,{className:`size-3`}),`Cherry Pick`]}),(0,E.jsxs)(v,{onClick:()=>de(e.hash),children:[(0,E.jsx)(n,{className:`size-3`}),`Revert`]}),(0,E.jsxs)(v,{onClick:()=>{N({type:`tag`,hash:e.hash}),F(``)},children:[(0,E.jsx)(w,{className:`size-3`}),`Create Tag...`]}),(0,E.jsx)(x,{}),(0,E.jsx)(v,{onClick:()=>_e(e),children:`View Diff`}),(0,E.jsxs)(v,{onClick:()=>q(e.hash),children:[(0,E.jsx)(ae,{className:`size-3`}),`Copy Hash`]})]})]},e.hash)})})]})}),I&&(0,E.jsxs)(`div`,{className:`border-t bg-muted/30 max-h-[40%] overflow-auto`,children:[(0,E.jsxs)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:[(0,E.jsxs)(`span`,{className:`text-sm font-medium truncate`,children:[I.abbreviatedHash,` — `,I.subject]}),(0,E.jsx)(y,{variant:`ghost`,size:`icon-xs`,onClick:()=>L(null),children:`✕`})]}),(0,E.jsxs)(`div`,{className:`px-3 py-2 text-xs space-y-1`,children:[(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Author`}),(0,E.jsxs)(`span`,{children:[I.authorName,` <`,I.authorEmail,`>`]})]}),(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Date`}),(0,E.jsx)(`span`,{children:new Date(I.authorDate).toLocaleString()})]}),(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Hash`}),(0,E.jsx)(`span`,{className:`font-mono cursor-pointer hover:text-primary`,onClick:()=>q(I.hash),children:I.hash})]}),I.parents.length>0&&(0,E.jsxs)(`div`,{className:`flex gap-4`,children:[(0,E.jsx)(`span`,{className:`text-muted-foreground`,children:`Parents`}),(0,E.jsx)(`span`,{className:`font-mono`,children:I.parents.map(e=>e.slice(0,7)).join(`, `)})]}),I.body&&(0,E.jsx)(`div`,{className:`mt-2 p-2 bg-background rounded text-xs whitespace-pre-wrap`,children:I.body})]}),(0,E.jsxs)(`div`,{className:`px-3 py-1 border-t`,children:[(0,E.jsx)(`div`,{className:`text-xs text-muted-foreground py-1`,children:le?`Loading files...`:`${R.length} file${R.length===1?``:`s`} changed`}),R.map(e=>(0,E.jsxs)(`div`,{className:`flex items-center gap-2 py-0.5 text-xs hover:bg-muted/50 rounded px-1 cursor-pointer`,onClick:()=>V({type:`git-diff`,title:`Diff ${c(e.path)}`,closable:!0,metadata:{projectName:t,ref1:I.parents[0]??void 0,ref2:I.hash,filePath:e.path},projectId:t??null}),children:[(0,E.jsx)(`span`,{className:`flex-1 truncate font-mono`,children:e.path}),e.additions>0&&(0,E.jsxs)(`span`,{className:`text-green-500`,children:[`+`,e.additions]}),e.deletions>0&&(0,E.jsxs)(`span`,{className:`text-red-500`,children:[`-`,e.deletions]})]},e.path))]})]}),(0,E.jsx)(ee,{open:M.type!==null,onOpenChange:e=>{e||N({type:null})},children:(0,E.jsxs)(h,{children:[(0,E.jsx)(re,{children:(0,E.jsx)(g,{children:M.type===`branch`?`Create Branch`:`Create Tag`})}),(0,E.jsx)(r,{placeholder:M.type===`branch`?`Branch name`:`Tag name`,value:P,onChange:e=>F(e.target.value),onKeyDown:e=>{e.key===`Enter`&&P.trim()&&(M.type===`branch`?G(P.trim(),M.hash):K(P.trim(),M.hash),N({type:null}))},autoFocus:!0}),(0,E.jsxs)(ne,{children:[(0,E.jsx)(y,{variant:`outline`,onClick:()=>N({type:null}),children:`Cancel`}),(0,E.jsx)(y,{disabled:!P.trim(),onClick:()=>{M.type===`branch`?G(P.trim(),M.hash):K(P.trim(),M.hash),N({type:null})},children:`Create`})]})]})})]})}function ce({label:e,color:t,currentBranch:n,onCheckout:r,onMerge:i,onPush:a,onCreatePr:s,onDelete:c}){return(0,E.jsxs)(ie,{children:[(0,E.jsx)(b,{asChild:!0,children:(0,E.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 cursor-context-menu`,style:{backgroundColor:`${t}30`,color:t,border:`1px solid ${t}50`},children:[(0,E.jsx)(f,{className:`size-2.5`}),e.name]})}),(0,E.jsxs)(_,{children:[(0,E.jsx)(v,{onClick:()=>r(e.name),children:`Checkout`}),(0,E.jsxs)(v,{onClick:()=>i(e.name),disabled:e.name===n?.name,children:[(0,E.jsx)(C,{className:`size-3`}),`Merge into current`]}),(0,E.jsx)(x,{}),(0,E.jsxs)(v,{onClick:()=>a(e.name),children:[(0,E.jsx)(S,{className:`size-3`}),`Push`]}),(0,E.jsxs)(v,{onClick:()=>s(e.name),children:[(0,E.jsx)(o,{className:`size-3`}),`Create PR`]}),(0,E.jsx)(x,{}),(0,E.jsxs)(v,{variant:`destructive`,onClick:()=>c(e.name),disabled:e.name===n?.name,children:[(0,E.jsx)(m,{className:`size-3`}),`Delete`]})]})]})}export{A as GitGraph};