opencode-rag-plugin 1.19.3 → 1.19.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +1 -1
- package/dist/api.js +2 -0
- package/dist/chunker/base.js +19 -5
- package/dist/chunker/factory.js +27 -9
- package/dist/chunker/grammar.d.ts +18 -1
- package/dist/chunker/grammar.js +48 -10
- package/dist/chunker/pdf.js +30 -14
- package/dist/cli/commands/init-helpers.js +15 -2
- package/dist/cli/commands/init.js +31 -21
- package/dist/cli/commands/query.js +2 -0
- package/dist/cli/commands/quirk.js +9 -3
- package/dist/cli/commands/setup.js +5 -2
- package/dist/cli/commands/status.js +14 -5
- package/dist/cli/commands/ui.js +23 -9
- package/dist/cli/commands/update.js +4 -5
- package/dist/cli/format.d.ts +5 -2
- package/dist/cli/format.js +14 -5
- package/dist/content/image.js +33 -11
- package/dist/content/reader.js +79 -17
- package/dist/core/bootstrap.js +10 -3
- package/dist/core/config.js +31 -0
- package/dist/core/desc-cache.d.ts +8 -2
- package/dist/core/desc-cache.js +10 -3
- package/dist/core/doc-progress.js +5 -2
- package/dist/core/interfaces.d.ts +8 -0
- package/dist/core/interfaces.js +8 -1
- package/dist/core/provider-defaults.d.ts +2 -0
- package/dist/core/provider-defaults.js +19 -4
- package/dist/core/runtime-overrides.d.ts +0 -6
- package/dist/core/version-check.d.ts +5 -0
- package/dist/core/version-check.js +8 -2
- package/dist/describer/anthropic.d.ts +2 -2
- package/dist/describer/anthropic.js +19 -5
- package/dist/describer/describer.js +15 -2
- package/dist/describer/gemini.js +25 -10
- package/dist/embedder/factory.d.ts +5 -3
- package/dist/embedder/factory.js +41 -8
- package/dist/embedder/health.js +19 -19
- package/dist/embedder/http.d.ts +14 -1
- package/dist/embedder/http.js +60 -6
- package/dist/eval/session-logger.js +7 -0
- package/dist/eval/storage.js +8 -0
- package/dist/indexer/git-diff.d.ts +1 -1
- package/dist/indexer/git-diff.js +5 -1
- package/dist/indexer/pipeline.js +421 -344
- package/dist/indexer/stats.d.ts +2 -0
- package/dist/indexer/stats.js +1 -0
- package/dist/indexer/watch.js +8 -1
- package/dist/indexer/worker.js +21 -0
- package/dist/mcp/cli.js +4 -0
- package/dist/mcp/handlers.d.ts +1 -1
- package/dist/mcp/handlers.js +23 -6
- package/dist/mcp/server.js +3 -0
- package/dist/opencode/create-read-tool.d.ts +1 -1
- package/dist/opencode/create-read-tool.js +17 -5
- package/dist/opencode/tool-args.js +23 -1
- package/dist/opencode/tools.d.ts +1 -1
- package/dist/opencode/tools.js +3 -1
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +69 -152
- package/dist/quirks/auto-capture.js +5 -0
- package/dist/quirks/quirk-store.d.ts +1 -1
- package/dist/quirks/quirk-store.js +56 -17
- package/dist/retriever/context-optimizer.js +18 -4
- package/dist/retriever/keyword-index.d.ts +2 -0
- package/dist/retriever/keyword-index.js +38 -4
- package/dist/retriever/retriever.js +6 -1
- package/dist/tui.js +41 -4
- package/dist/vectorstore/lancedb.d.ts +25 -1
- package/dist/vectorstore/lancedb.js +157 -11
- package/dist/vectorstore/memory.js +5 -1
- package/dist/watcher.js +30 -4
- package/dist/web/api.d.ts +6 -2
- package/dist/web/api.js +198 -70
- package/dist/web/server.d.ts +2 -0
- package/dist/web/server.js +66 -28
- package/dist/web/static.d.ts +5 -2
- package/dist/web/static.js +9 -5
- package/dist/web/ui/assets/index-BDPYdtA1.js +3 -0
- package/dist/web/ui/index.html +1 -1
- package/package.json +1 -1
- package/dist/web/ui/assets/index-CJBvt6e0.js +0 -3
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{l as M,S as ve,C as ie,t as Bt,k as et,F as Ke,R as Wt}from"./vendor-Dy7HKFCY.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))r(l);new MutationObserver(l=>{for(const a of l)if(a.type==="childList")for(const i of a.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function s(l){const a={};return l.integrity&&(a.integrity=l.integrity),l.referrerPolicy&&(a.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?a.credentials="include":l.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function r(l){if(l.ep)return;l.ep=!0;const a=s(l);fetch(l.href,a)}})();var Vt=0;function t(e,n,s,r,l,a){n||(n={});var i,o,c=n;if("ref"in c)for(o in c={},n)o=="ref"?i=n[o]:c[o]=n[o];var d={type:e,props:c,key:s,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Vt,__i:-1,__u:0,__source:l,__self:a};if(typeof e=="function"&&(i=e.defaultProps))for(o in i)c[o]===void 0&&(c[o]=i[o]);return M.vnode&&M.vnode(d),d}var ge,R,Oe,tt,be=0,kt=[],P=M,nt=P.__b,st=P.__r,at=P.diffed,rt=P.__c,lt=P.unmount,it=P.__;function Ve(e,n){P.__h&&P.__h(R,e,be||n),be=0;var s=R.__H||(R.__H={__:[],__h:[]});return e>=s.__.length&&s.__.push({}),s.__[e]}function b(e){return be=1,zt(Ct,e)}function zt(e,n,s){var r=Ve(ge++,2);if(r.t=e,!r.__c&&(r.__=[s?s(n):Ct(void 0,n),function(o){var c=r.__N?r.__N[0]:r.__[0],d=r.t(c,o);c!==d&&(r.__N=[d,r.__[1]],r.__c.setState({}))}],r.__c=R,!R.__f)){var l=function(o,c,d){if(!r.__c.__H)return!0;var u=!1,h=r.__c.props!==o;if(r.__c.__H.__.some(function(m){if(m.__N){u=!0;var v=m.__[0];m.__=m.__N,m.__N=void 0,v!==m.__[0]&&(h=!0)}}),a){var p=a.call(this,o,c,d);return u?p||h:p}return!u||h};R.__f=!0;var a=R.shouldComponentUpdate,i=R.componentWillUpdate;R.componentWillUpdate=function(o,c,d){if(this.__e){var u=a;a=void 0,l(o,c,d),a=u}i&&i.call(this,o,c,d)},R.shouldComponentUpdate=l}return r.__N||r.__}function A(e,n){var s=Ve(ge++,3);!P.__s&&St(s.__H,n)&&(s.__=e,s.u=n,R.__H.__h.push(s))}function X(e){return be=5,_e(function(){return{current:e}},[])}function _e(e,n){var s=Ve(ge++,7);return St(s.__H,n)&&(s.__=e(),s.__H=n,s.__h=e),s.__}function ot(e,n){return be=8,_e(function(){return e},n)}function Gt(){for(var e;e=kt.shift();){var n=e.__H;if(e.__P&&n)try{n.__h.some($e),n.__h.some(Be),n.__h=[]}catch(s){n.__h=[],P.__e(s,e.__v)}}}P.__b=function(e){R=null,nt&&nt(e)},P.__=function(e,n){e&&n.__k&&n.__k.__m&&(e.__m=n.__k.__m),it&&it(e,n)},P.__r=function(e){st&&st(e),ge=0;var n=(R=e.__c).__H;n&&(Oe===R?(n.__h=[],R.__h=[],n.__.some(function(s){s.__N&&(s.__=s.__N),s.u=s.__N=void 0})):(n.__h.some($e),n.__h.some(Be),n.__h=[],ge=0)),Oe=R},P.diffed=function(e){at&&at(e);var n=e.__c;n&&n.__H&&(n.__H.__h.length&&(kt.push(n)!==1&&tt===P.requestAnimationFrame||((tt=P.requestAnimationFrame)||Qt)(Gt)),n.__H.__.some(function(s){s.u&&(s.__H=s.u,s.u=void 0)})),Oe=R=null},P.__c=function(e,n){n.some(function(s){try{s.__h.some($e),s.__h=s.__h.filter(function(r){return!r.__||Be(r)})}catch(r){n.some(function(l){l.__h&&(l.__h=[])}),n=[],P.__e(r,s.__v)}}),rt&&rt(e,n)},P.unmount=function(e){lt&<(e);var n,s=e.__c;s&&s.__H&&(s.__H.__.some(function(r){try{$e(r)}catch(l){n=l}}),s.__H=void 0,n&&P.__e(n,s.__v))};var ct=typeof requestAnimationFrame=="function";function Qt(e){var n,s=function(){clearTimeout(r),ct&&cancelAnimationFrame(n),setTimeout(e)},r=setTimeout(s,35);ct&&(n=requestAnimationFrame(s))}function $e(e){var n=R,s=e.__c;typeof s=="function"&&(e.__c=void 0,s()),R=n}function Be(e){var n=R;e.__c=e.__(),R=n}function St(e,n){return!e||e.length!==n.length||n.some(function(s,r){return s!==e[r]})}function Ct(e,n){return typeof n=="function"?n(e):n}function dt(){const e=location.hash.slice(1)||"dashboard",n=e.indexOf("?"),s=n>=0?e.slice(0,n):e,r={};if(n>=0){const l=e.slice(n+1);for(const a of l.split("&")){const i=a.indexOf("=");if(i>=0)try{r[decodeURIComponent(a.slice(0,i))]=decodeURIComponent(a.slice(i+1))}catch{}}}return{view:s||"dashboard",params:r}}function ye(){const[e,n]=b(dt);return A(()=>{const s=()=>n(dt());return addEventListener("hashchange",s),()=>removeEventListener("hashchange",s)},[]),e}var Xt=Symbol.for("preact-signals");function Ae(){if(Y>1)Y--;else{var e,n=!1;for(function(){var l=Te;for(Te=void 0;l!==void 0;){var a=l.S;if(a.v===l.v)for(var i=a.t;i!==void 0;i=i.x)i.i===l.i&&(i.i=a.i);l=l.o}}();pe!==void 0;){var s=pe;for(pe=void 0,Le++;s!==void 0;){var r=s.u;if(s.u=void 0,s.f&=-3,!(8&s.f)&&Lt(s))try{s.c()}catch(l){n||(e=l,n=!0)}s=r}}if(Le=0,Y--,n)throw e}}function Yt(e){if(Y>0)return e();We=++Zt,Y++;try{return e()}finally{Ae()}}var me,S=void 0;function Ee(e){var n=S,s=me;S=void 0,me=void 0;try{return e()}finally{S=n,me=s}}var pe=void 0,Y=0,Le=0,Zt=0,We=0,Te=void 0,Ie=0;function $t(e){if(S!==void 0){var n=e.n;if(n===void 0||n.t!==S)return n={i:0,S:e,p:S.s,n:void 0,t:S,e:void 0,x:void 0,r:n},S.s!==void 0&&(S.s.n=n),S.s=n,e.n=n,32&S.f&&e.S(n),n;if(n.i===-1)return n.i=0,n.n!==void 0&&(n.n.p=n.p,n.p!==void 0&&(n.p.n=n.n),n.p=S.s,n.n=void 0,S.s.n=n,S.s=n),n}}function F(e,n){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=n==null?void 0:n.watched,this.Z=n==null?void 0:n.unwatched,this.name=n==null?void 0:n.name}F.prototype.brand=Xt;F.prototype.h=function(){return!0};F.prototype.S=function(e){var n=this,s=this.t;s!==e&&e.e===void 0&&(e.x=s,this.t=e,s!==void 0?s.e=e:Ee(function(){var r;(r=n.W)==null||r.call(n)}))};F.prototype.U=function(e){var n=this;if(this.t!==void 0){var s=e.e,r=e.x;s!==void 0&&(s.x=r,e.e=void 0),r!==void 0&&(r.e=s,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&Ee(function(){var l;(l=n.Z)==null||l.call(n)}))}};F.prototype.subscribe=function(e){var n=this;return Ne(function(){var s=n.value;Ee(function(){return e(s)})},{name:"sub"})};F.prototype.valueOf=function(){return this.value};F.prototype.toString=function(){return this.value+""};F.prototype.toJSON=function(){return this.value};F.prototype.peek=function(){var e=this;return Ee(function(){return e.value})};Object.defineProperty(F.prototype,"value",{get:function(){var e=$t(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Le>100)throw new Error("Cycle detected");(function(s){Y!==0&&Le===0&&s.l!==We&&(s.l=We,Te={S:s,v:s.v,i:s.i,o:Te})})(this),this.v=e,this.i++,Ie++,Y++;try{for(var n=this.t;n!==void 0;n=n.x)n.t.N()}finally{Ae()}}}});function $(e,n){return new F(e,n)}function Lt(e){for(var n=e.s;n!==void 0;n=n.n)if(n.S.i!==n.i||!n.S.h()||n.S.i!==n.i)return!0;return!1}function Tt(e){for(var n=e.s;n!==void 0;n=n.n){var s=n.S.n;if(s!==void 0&&(n.r=s),n.S.n=n,n.i=-1,n.n===void 0){e.s=n;break}}}function It(e){for(var n=e.s,s=void 0;n!==void 0;){var r=n.p;n.i===-1?(n.S.U(n),r!==void 0&&(r.n=n.n),n.n!==void 0&&(n.n.p=r)):s=n,n.S.n=n.r,n.r!==void 0&&(n.r=void 0),n=r}e.s=s}function ne(e,n){F.call(this,void 0,n),this.x=e,this.s=void 0,this.g=Ie-1,this.f=4}ne.prototype=new F;ne.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Ie))return!0;if(this.g=Ie,this.f|=1,this.i>0&&!Lt(this))return this.f&=-2,!0;var e=S;try{Tt(this),S=this;var n=this.x();(16&this.f||this.v!==n||this.i===0)&&(this.v=n,this.f&=-17,this.i++)}catch(s){this.v=s,this.f|=16,this.i++}return S=e,It(this),this.f&=-2,!0};ne.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var n=this.s;n!==void 0;n=n.n)n.S.S(n)}F.prototype.S.call(this,e)};ne.prototype.U=function(e){if(this.t!==void 0&&(F.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var n=this.s;n!==void 0;n=n.n)n.S.U(n)}};ne.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(ne.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=$t(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function ut(e,n){return new ne(e,n)}function Rt(e){var n=e.m;if(e.m=void 0,typeof n=="function"){Y++;var s=S;S=void 0;try{n()}catch(r){throw e.f&=-2,e.f|=8,ze(e),r}finally{S=s,Ae()}}}function ze(e){for(var n=e.s;n!==void 0;n=n.n)n.S.U(n);e.x=void 0,e.s=void 0,Rt(e)}function Jt(e){if(S!==this)throw new Error("Out-of-order effect");It(this),S=e,this.f&=-2,8&this.f&&ze(this),Ae()}function oe(e,n){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=n==null?void 0:n.name,me&&me.push(this)}oe.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var n=this.x();typeof n=="function"&&(this.m=n)}finally{e()}};oe.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Rt(this),Tt(this),Y++;var e=S;return S=this,Jt.bind(this,e)};oe.prototype.N=function(){2&this.f||(this.f|=2,this.u=pe,pe=this)};oe.prototype.d=function(){this.f|=8,1&this.f||ze(this)};oe.prototype.dispose=function(){this.d()};function Ne(e,n){var s=new oe(e,n);try{s.c()}catch(l){throw s.d(),l}var r=s.d.bind(s);return r[Symbol.dispose]=r,r}var Pt,ke,en=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__,Mt=[];Ne(function(){Pt=this.N})();function ce(e,n){M[e]=n.bind(null,M[e]||function(){})}function Re(e){if(ke){var n=ke;ke=void 0,n()}ke=e&&e.S()}function At(e){var n=this,s=e.data,r=nn(s);r.name="ReactiveDom",r.value=s;var l=_e(function(){for(var o=n,c=n.__v;c=c.__;)if(c.__c){c.__c.__$f|=4;break}var d=ut(function(){var m=r.value.value;return m===0?0:m===!0?"":m||""}),u=ut(function(){return!Array.isArray(d.value)&&!Bt(d.value)}),h=Ne(function(){if(this.N=Et,u.value){var m=d.value;o.__v&&o.__v.__e&&o.__v.__e.nodeType===3&&(o.__v.__e.data=m)}}),p=n.__$u.d;return n.__$u.d=function(){h(),p.call(this)},[u,d]},[]),a=l[0],i=l[1];return a.value?i.peek():i.value}At.displayName="ReactiveTextNode";Object.defineProperties(F.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:At},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});ce("__b",function(e,n){if(typeof n.type=="string"){var s,r=n.props;for(var l in r)if(l!=="children"){var a=r[l];a instanceof F&&(s||(n.__np=s={}),s[l]=a,r[l]=a.peek())}}e(n)});ce("__r",function(e,n){if(e(n),n.type!==ve){Re();var s,r=n.__c;r&&(r.__$f&=-2,(s=r.__$u)===void 0&&(r.__$u=s=function(l,a){var i;return Ne(function(){i=this},{name:a}),i.c=l,i}(function(){var l;en&&((l=s.y)==null||l.call(s)),r.__$f|=1,r.setState({})},typeof n.type=="function"?n.type.displayName||n.type.name:""))),Re(s)}});ce("__e",function(e,n,s,r){Re(),e(n,s,r)});ce("diffed",function(e,n){Re();var s;if(typeof n.type=="string"&&(s=n.__e)){var r=n.__np,l=n.props,a=s.U;if(a)for(var i in a){var o=a[i];o===void 0||r&&i in r||(o.d(),a[i]=void 0)}if(r){a||(a={},s.U=a);for(var c in r){var d=a[c],u=r[c];d===void 0?(d=tn(s,c,u,l),a[c]=d):d.o(u,l)}}}e(n)});function tn(e,n,s,r){var l=n in e&&e.ownerSVGElement===void 0,a=$(s);return{o:function(i,o){a.value=i,r=o},d:Ne(function(){this.N=Et;var i=a.value.value;r[n]!==i&&(r[n]=i,l?e[n]=i:i!=null&&(i!==!1||n[4]==="-")?e.setAttribute(n,i):e.removeAttribute(n))})}}ce("unmount",function(e,n){if(typeof n.type=="string"){var s=n.__e;if(s){var r=s.U;if(r){s.U=void 0;for(var l in r){var a=r[l];a&&a.d()}}}var i=n.__np;if(i){var o=n.props;for(var c in i)o[c]=i[c]}n.__np=void 0}else{var d=n.__c;if(d){var u=d.__$u;u&&(d.__$u=void 0,u.d())}}e(n)});ce("__h",function(e,n,s,r){r<3&&(n.__$f|=2),e(n,s,r)});ie.prototype.shouldComponentUpdate=function(e,n){if(this.__R)return!0;var s=this.__$u,r=s&&s.s!==void 0;for(var l in n)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var a=2&this.__$f;if(!(r||a||4&this.__$f)||1&this.__$f)return!0}else if(!(r||4&this.__$f)||3&this.__$f)return!0;for(var i in e)if(i!=="__source"&&e[i]!==this.props[i])return!0;for(var o in this.props)if(!(o in e))return!0;return!1};function nn(e,n){return _e(function(){return $(e,n)},[])}var sn=function(e){queueMicrotask(function(){queueMicrotask(e)})};function an(){Yt(function(){for(var e;e=Mt.shift();)Pt.call(e)})}function Et(){Mt.push(this)===1&&(M.requestAnimationFrame||sn)(an)}const De=$("dashboard"),te=$(null),ae=$(null),re=$(null),he=$(0),rn=$(50),W=$(new Set),Ue=$(new Set),q=$(""),k=$({topK:10,minScore:.35,keywordWeight:.4,hybrid:!0,pathFilter:"",langFilter:""}),J=$([]),Pe=$([]);$(!1);$(null);$([]);$(new Set);$(null);$(null);const Z=$(typeof localStorage<"u"?localStorage.getItem("theme")??"dark":"dark"),Se=$(!0),fe=$([]);let ln=0;function ee(e,n,s=4e3){const r=ln++;fe.value=[...fe.value,{id:r,type:e,message:n,duration:s}],setTimeout(()=>{fe.value=fe.value.filter(l=>l.id!==r)},s)}function E(e){window.location.hash=e}function on(){A(()=>{document.documentElement.classList.toggle("dark",Z.value==="dark"),localStorage.setItem("theme",Z.value)},[Z.value]);const e=()=>{Z.value=Z.value==="dark"?"light":"dark"};return{theme:Z.value,toggle:e}}function cn(){A(()=>{let e=null,n=null;const s=()=>{e&&(clearTimeout(e),e=null),n&&(window.removeEventListener("keydown",n),n=null)},r=l=>{const a=l.target,i=a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable;if((l.metaKey||l.ctrlKey)&&l.key==="k"){l.preventDefault(),E("search"),setTimeout(()=>{var o;(o=document.querySelector(".global-search-input"))==null||o.focus()},0);return}if(!i&&l.key==="g"){const o={d:()=>E("dashboard"),s:()=>E("search"),c:()=>E("chunks"),f:()=>E("files"),e:()=>E("evaluate"),q:()=>E("quirks")};s();const c=d=>{var u;(u=o[d.key])==null||u.call(o),s()};n=c,window.addEventListener("keydown",c),e=setTimeout(s,500);return}};return window.addEventListener("keydown",r),()=>{window.removeEventListener("keydown",r),s()}},[])}function dn(){return t("div",{className:"fixed top-4 right-4 z-[9999] flex flex-col gap-2 pointer-events-none",children:fe.value.map(e=>t("div",{className:`pointer-events-auto px-4 py-2.5 rounded-lg shadow-lg text-sm font-medium transition-all duration-300 animate-slide-in ${e.type==="success"?"bg-green-600 text-white":e.type==="error"?"bg-red-600 text-white":"bg-brand-600 text-white"}`,children:e.message},e.id))})}function un(){const e=Z.value==="dark";return t("button",{className:"p-2 rounded-lg transition-colors",style:{color:"var(--text-muted)"},onClick:()=>{Z.value=e?"light":"dark"},"aria-label":e?"Switch to light mode":"Switch to dark mode",title:e?"Light mode":"Dark mode",children:[t("span",{className:"sr-only",children:e?"Switch to light mode":"Switch to dark mode"}),e?t("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:t("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"})}):t("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:t("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"})})]})}function Ge(e,n){const[s,r]=b(e);return A(()=>{const l=setTimeout(()=>r(e),n);return()=>clearTimeout(l)},[e,n]),s}const hn="/api",ht="opencode-rag-token";function fn(){const e=new URLSearchParams(window.location.search).get("token");if(e){sessionStorage.setItem(ht,e);const n=window.location.pathname+window.location.hash;return window.history.replaceState(null,"",n),e}return sessionStorage.getItem(ht)}function mn(){const e=fn();return e?{Authorization:`Bearer ${e}`}:{}}function ft(e){const n=new URLSearchParams;for(const[s,r]of Object.entries(e))r!==void 0&&r!==""&&n.set(s,String(r));return n.toString()}async function I(e,n){const s={...(n==null?void 0:n.headers)??{},...mn()},r=await fetch(hn+e,{...n,headers:s}),l=await r.json();if(!r.ok)throw new Error(l.error??r.statusText);return l}const T={stats:()=>I("/stats"),files:()=>I("/files"),chunks:e=>I(`/chunks?${ft(e)}`),chunk:e=>I(`/chunks/${encodeURIComponent(e)}`),search:(e,n=20)=>I(`/search?q=${encodeURIComponent(e)}&topK=${n}`),compare:e=>I(`/compare?ids=${e.join(",")}`),retrieve:e=>I(`/retrieve?${ft(e)}`),evalSessions:()=>I("/eval/sessions"),evalSession:e=>I(`/eval/sessions/${encodeURIComponent(e)}`),evalDeleteSession:e=>I(`/eval/sessions/${encodeURIComponent(e)}`,{method:"DELETE"}),evalCompare:(e,n)=>I(`/eval/compare?a=${e}&b=${n}`),evalTokenCompare:(e,n)=>I(`/eval/token-compare?a=${e}&b=${n}`),evalAnalysis:e=>I(`/eval/sessions/${encodeURIComponent(e)}/analysis`),evalProjectSavings:e=>I("/eval/project-savings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),quirks:()=>I("/quirks"),quirkLint:()=>I("/quirks/lint"),deleteQuirk:e=>I(`/quirks/${encodeURIComponent(e)}`,{method:"DELETE"}),indexStatus:()=>I("/indexing/status"),triggerReindex:()=>I("/indexing/reindex",{method:"POST"}),config:()=>I("/config"),embeddingProj:(e=5e3)=>I(`/embeddings/projection?maxChunks=${e}`)},pn={typescript:"text-blue-400",javascript:"text-yellow-400",python:"text-green-400",java:"text-red-400",go:"text-cyan-400",rust:"text-orange-400",ruby:"text-pink-400",csharp:"text-purple-400",cpp:"text-indigo-400",c:"text-gray-400",markdown:"text-gray-300",html:"text-orange-300",css:"text-blue-300",json:"text-yellow-300",kotlin:"text-purple-300",swift:"text-orange-400",tex:"text-emerald-400",sql:"text-cyan-300"};function we(e){return pn[e]??"text-slate-400"}function de(e){return`<span class="inline-block px-1.5 py-0.5 rounded text-xs font-mono ${we(e)} bg-slate-800">${xn(e)}</span>`}function xn(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function C(e){return typeof e!="string"?"":e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function vn(e,n=80){const s=typeof e=="string"?e:String(e??"");return s.length>n?s.slice(0,n)+"...":s}function gn(){const[e,n]=b(""),[s,r]=b([]),[l,a]=b(!1),i=X(null),o=X(null),c=Ge(e,300);A(()=>{if(!c.trim()){r([]),a(!1);return}let h=!1;return T.search(c,10).then(p=>{h||(r((p==null?void 0:p.results)??[]),a(!0))}).catch(()=>{h||a(!1)}),()=>{h=!0}},[c]),A(()=>{const h=p=>{o.current&&!o.current.contains(p.target)&&a(!1)};return document.addEventListener("click",h),()=>document.removeEventListener("click",h)},[]);const d=h=>{h.key==="Escape"&&a(!1)},u=async h=>{a(!1),n(""),E("chunks")};return t("div",{ref:o,className:"relative",children:[t("input",{ref:i,type:"text",placeholder:"Search codebase...",value:e,onInput:h=>n(h.target.value),onKeyDown:d,className:"global-search-input w-56 px-3 py-1.5 bg-slate-800 border border-slate-600 rounded text-sm text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400","aria-label":"Global search",role:"combobox","aria-expanded":l}),l&&s.length>0&&t("div",{className:"absolute top-full right-0 mt-1 w-96 bg-slate-800 border border-slate-600 rounded-lg shadow-xl z-50 max-h-80 overflow-y-auto",role:"listbox",children:s.map(h=>t("div",{className:"search-result p-2 hover:bg-slate-700 cursor-pointer border-b border-slate-700 last:border-0",onClick:()=>u(h.chunk.id),role:"option",children:[t("div",{className:"flex items-center gap-2 text-xs",children:[t("span",{className:"text-yellow-400 font-mono",children:[C(h.chunk.filePath),":",h.chunk.startLine,"-",h.chunk.endLine]}),t("span",{dangerouslySetInnerHTML:{__html:de(h.chunk.language)}}),t("span",{className:"ml-auto text-slate-500",children:h.score})]}),t("div",{className:"text-xs text-slate-400 mt-1 truncate",children:C(h.chunk.content??"").slice(0,80)})]},h.chunk.id))}),l&&e.trim()&&s.length===0&&t("div",{className:"absolute top-full right-0 mt-1 w-96 bg-slate-800 border border-slate-600 rounded-lg shadow-xl z-50 p-3 text-sm text-slate-500",children:"No results"})]})}function z(e,n=[]){const[s,r]=b(null),[l,a]=b(!0),[i,o]=b(null),[c,d]=b(0);return A(()=>{let u=!1;return a(!0),o(null),e().then(h=>{u||(r(h),a(!1))}).catch(h=>{u||(o(h.message),a(!1))}),()=>{u=!0}},[...n,c]),{data:s,isLoading:l,error:i,refresh:()=>d(u=>u+1)}}function bn(){const{data:e}=z(()=>T.files()),n=e??[],[s,r]=b(""),l=Ge(s,300),a=l?n.filter(i=>i.filePath.toLowerCase().includes(l.toLowerCase())):n;return t("div",{className:"flex flex-col h-full",children:[t("div",{className:"flex items-center justify-between mb-2 px-3 pt-3",children:[t("h2",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wide",children:"Files"}),t("span",{className:"text-xs text-slate-500",children:a.length})]}),t("div",{className:"px-3 mb-2",children:t("input",{type:"text",placeholder:"Filter files...",value:s,onInput:i=>r(i.target.value),className:"w-full px-2 py-1 bg-slate-900 border border-slate-700 rounded text-xs focus:outline-none focus:border-brand-400 text-slate-200 placeholder-slate-500"})}),t("div",{className:"flex-1 overflow-y-auto px-1",children:t(_n,{files:a})})]})}function _n({files:e}){const n={};for(const s of e){const r=s.filePath.split("/");let l=n;for(let a=0;a<r.length-1;a++)l[r[a]]||(l[r[a]]={}),l=l[r[a]];l.__files||(l.__files=[]),l.__files.push(s)}return t(Ft,{obj:n,depth:0,parentPath:""})}function jt(e){let n=(e.__files||[]).length;for(const[s,r]of Object.entries(e))s!=="__files"&&(n+=jt(r));return n}function Ft({obj:e,depth:n,parentPath:s}){const r=Object.entries(e).filter(([a])=>a!=="__files").sort(([a],[i])=>a.localeCompare(i)),l=e.__files||[];return t(ve,{children:[r.map(([a,i])=>{const o=s?`${s}/${a}`:a,c=jt(i),d=Ue.value.has(o),u=d?"▸":"▾";return t("div",{children:[t("div",{className:"file-item flex items-center gap-1 py-0.5 px-2 rounded cursor-pointer text-slate-400 hover:text-white",style:{paddingLeft:`${n*12+8}px`},onClick:()=>{const h=new Set(Ue.value);h.has(o)?h.delete(o):h.add(o),Ue.value=h},role:"treeitem","aria-expanded":!d,children:[t("span",{className:"text-xs",children:u}),t("span",{className:"text-xs",children:"📁"}),t("span",{className:"text-xs",children:C(a)}),t("span",{className:"text-xs text-slate-600 ml-auto",children:c})]}),!d&&t("div",{className:"dir-children",children:t(Ft,{obj:i,depth:n+1,parentPath:o})})]},o)}),l.map(a=>{const i=a.filePath.split("/").pop()??a.filePath,o=te.value===a.filePath;return t("div",{className:`file-item flex items-center gap-1 py-0.5 px-2 rounded cursor-pointer ${o?"active text-white":"text-slate-400 hover:text-white"}`,style:{paddingLeft:`${n*12+8}px`},onClick:()=>{te.value=a.filePath,E(`chunks?file=${encodeURIComponent(a.filePath)}`)},role:"treeitem",tabIndex:0,children:[t("span",{className:`text-xs ${we(a.language)}`,children:"♦"}),t("span",{className:"text-xs truncate",children:C(i)}),t("span",{className:"text-xs text-slate-600 ml-auto",children:a.chunkCount})]},a.filePath)})]})}const V="bg-gradient-to-r from-slate-700 via-slate-600 to-slate-700 bg-[length:200%_100%]";function G({type:e="card"}){return t("div",{className:"animate-pulse space-y-4",children:[t("div",{className:`h-8 ${V} rounded w-48`}),e==="card"&&t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[1,2,3,4].map(n=>t("div",{className:"h-24 bg-slate-800 rounded-lg border border-slate-700 p-4",children:[t("div",{className:`h-3 ${V} rounded w-16 mb-2`}),t("div",{className:`h-6 ${V} rounded w-24`})]},n))}),e==="table"&&t("div",{className:"space-y-2",children:[t("div",{className:`h-10 ${V} rounded w-full`}),[1,2,3,4,5].map(n=>t("div",{className:`h-8 ${V} rounded w-full`},n))]}),e==="chart"&&t("div",{className:`h-64 ${V} rounded-lg`}),e==="detail"&&t("div",{className:"flex gap-4",children:[t("div",{className:"flex-1 space-y-3",children:[t("div",{className:`h-6 ${V} rounded w-48`}),t("div",{className:`h-4 ${V} rounded w-32`}),t("div",{className:`h-32 ${V} rounded-lg`})]}),t("div",{className:"flex-1 space-y-3",children:[t("div",{className:`h-6 ${V} rounded w-48`}),t("div",{className:`h-4 ${V} rounded w-32`}),t("div",{className:`h-32 ${V} rounded-lg`})]})]})]})}function Q({message:e,onRetry:n}){return t("div",{className:"flex flex-col items-center justify-center py-12 text-center",role:"alert",children:[t("span",{className:"text-4xl mb-3",children:"⚠️"}),t("p",{className:"text-slate-400 mb-4",children:e}),n&&t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-4 py-2 rounded transition-colors",onClick:n,children:"Retry"})]})}function se({icon:e,message:n,action:s}){return t("div",{className:"flex flex-col items-center justify-center py-16 text-center",role:"status",children:[t("span",{className:"text-5xl mb-4",role:"img","aria-label":e,children:e}),t("p",{className:"text-slate-400 mb-4",children:n}),s&&t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-4 py-2 rounded transition-colors",onClick:s.onClick,children:s.label})]})}function K({label:e,value:n,icon:s}){return t("div",{className:"kpi-card p-4",children:[s&&t("span",{className:"text-lg mb-1 block",children:s}),t("div",{className:"text-slate-400 text-xs mb-1",children:e}),t("div",{className:"text-3xl font-bold text-white",children:n})]})}function O(e){return e>=1e6?(e/1e6).toFixed(1)+"M":e>=1e3?(e/1e3).toFixed(1)+"k":String(e)}function Me(e){return e===0?"$0.00":e<.01?"$"+e.toFixed(4):"$"+e.toFixed(2)}function yn(e){return e>=6e4?(e/6e4).toFixed(1)+"m":e>=1e3?(e/1e3).toFixed(1)+"s":e+"ms"}function Ot(e){if(!e)return"-";const n=new Date(e);return n.toLocaleDateString()+" "+n.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function Nn(e){const n=Date.now()-new Date(e).getTime(),s=Math.floor(n/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const r=Math.floor(s/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function wn(){var p;const[e,n]=b(null),[s,r]=b(!0),[l,a]=b(!1),i=X(null),o=async()=>{try{const m=await T.indexStatus();n(m.body??m)}catch{}r(!1)};A(()=>{o()},[]),A(()=>()=>{i.current&&clearInterval(i.current)},[]);const c=async()=>{var m;a(!0);try{await T.triggerReindex(),ee("info","Reindex started in background");const v=(m=e==null?void 0:e.manifest)==null?void 0:m.lastIndexedAt,f=Date.now();i.current=setInterval(async()=>{var _;if(Date.now()-f>10*6e4){i.current&&clearInterval(i.current),i.current=null,a(!1),ee("info","Reindex is still running — check back later");return}try{const L=await T.indexStatus(),N=L.body??L;((_=N.manifest)==null?void 0:_.lastIndexedAt)!==v&&(i.current&&clearInterval(i.current),i.current=null,n(N),a(!1),ee("success","Reindex complete!"))}catch{}},2e3)}catch(v){const f=v.message??"";ee("error",/already running/i.test(f)?"A reindex is already running":`Reindex failed: ${f}`),a(!1)}};if(s)return null;const d=(p=e==null?void 0:e.manifest)!=null&&p.lastIndexedAt?Nn(e.manifest.lastIndexedAt):"Never",u=(e==null?void 0:e.staleFileCount)??0,h=u===0?"text-green-400":u<50?"text-amber-400":"text-red-400";return t("div",{className:"kpi-card p-4 mb-6",children:[t("div",{className:"flex items-center justify-between mb-3",children:t("h2",{className:"text-lg font-semibold",children:"Index Status"})}),e!=null&&e.manifest?t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Last Indexed"}),t("span",{className:"text-sm font-mono",children:d})]}),t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Total Chunks"}),t("span",{className:"text-sm font-mono",children:O(e.manifest.totalChunks)})]}),t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Total Files"}),t("span",{className:"text-sm font-mono",children:O(e.manifest.totalFiles)})]}),t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Schema Version"}),t("span",{className:"text-sm font-mono",children:e.manifest.schemaVersion})]}),t("div",{className:"col-span-2",children:[t("span",{className:"text-xs text-slate-500 block",children:"Index Freshness"}),t("span",{className:`text-sm font-mono ${h}`,children:u===0?"✓ Up to date":`⚠ ${u} file${u!==1?"s":""} modified since last index`})]}),t("div",{className:"col-span-2 flex items-end",children:l?t("div",{className:"flex items-center gap-2",children:[t("span",{className:"animate-spin",children:"⟳"}),t("span",{className:"text-sm text-amber-400",children:"Reindexing..."})]}):t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-4 py-1.5 rounded text-sm transition-colors",onClick:c,children:"Reindex Now"})})]}):t("div",{className:"text-sm text-slate-400",children:["No index found. Run ",t("code",{className:"text-brand-400",children:"opencode-rag index"})," first."]})]})}function kn(){var p,m,v;const{data:e,isLoading:n,error:s,refresh:r}=z(()=>T.stats()),{data:l}=z(()=>T.files());if(n)return t(G,{type:"card"});if(s)return t(Q,{message:s,onRetry:r});if(!e)return t(se,{icon:"📊",message:"No dashboard data available."});const a=e,i=((p=l==null?void 0:l.body)==null?void 0:p.length)??a.totalFiles??0,o=a.totalChunks??0,c=((m=a.languages)==null?void 0:m.length)??0,d=i>0?(o/i).toFixed(1):"0",u=(a.languages??[]).slice(0,8),h=((v=u[0])==null?void 0:v.count)??1;return t("div",{children:[t("h1",{className:"text-2xl font-bold mb-6",children:"Dashboard"}),t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4 mb-8",children:[t(K,{label:"Total Chunks",value:o.toLocaleString(),icon:"🧩"}),t(K,{label:"Total Files",value:i.toLocaleString(),icon:"📄"}),t(K,{label:"Languages",value:c,icon:"🔤"}),t(K,{label:"Avg Chunks/File",value:d,icon:"📊"})]}),t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-3",children:"Language Distribution"}),t("div",{className:"space-y-2",children:u.map(f=>t("div",{className:"flex items-center gap-3",children:[t("span",{className:`w-24 text-xs text-right ${we(f.language)}`,children:f.language}),t("div",{className:"flex-1 bg-slate-800 rounded-full h-5 overflow-hidden",children:t("div",{className:"h-full rounded-full bg-brand-500 flex items-center pl-2",style:{width:`${Math.max(8,f.count/h*100)}%`},children:t("span",{className:"text-xs font-medium text-white",children:f.count})})}),t("span",{className:"text-xs text-slate-500 w-12 text-right",children:[(f.count/o*100).toFixed(0),"%"]})]},f.language))})]}),t(wn,{}),t("div",{className:"mt-6",children:t("h2",{className:"text-lg font-semibold mb-3",children:t("a",{href:"#config",className:"hover:text-brand-400 transition-colors",children:"Configuration"})})})]})}function mt({text:e,color:n,onDismiss:s}){return t("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-mono bg-slate-800 ${n??"text-slate-400"}`,children:[e,s&&t("button",{className:"ml-0.5 text-slate-500 hover:text-white",onClick:s,"aria-label":`Dismiss ${e} filter`,children:"×"})]})}function Sn(){const e=ye();A(()=>{e.params.file&&(te.value=e.params.file),e.params.lang&&(ae.value=e.params.lang)},[e.params.file,e.params.lang]);const n=he.value,s=rn.value,r=te.value,l=ae.value,{data:a,isLoading:i,error:o,refresh:c}=z(()=>T.chunks({offset:n,limit:s,lang:l??"",file:r??""}),[n,s,r,l]);if(i)return t(G,{type:"detail"});if(o)return t(Q,{message:o,onRetry:c});const d=(a==null?void 0:a.chunks)??[],u=(a==null?void 0:a.total)??d.length,h=Math.ceil(u/s),p=Math.floor(n/s)+1;return t("div",{className:"flex gap-4 h-full",children:[t("div",{className:"w-1/2 flex flex-col",children:[t("div",{className:"flex items-center gap-3 mb-3 flex-wrap",children:[t("h2",{className:"text-lg font-semibold text-white",children:"Chunks"}),t("span",{className:"text-sm text-slate-400",children:[u," total"]}),ae.value&&t(mt,{text:ae.value,color:we(ae.value),onDismiss:()=>{ae.value=null,re.value=null,he.value=0}}),te.value&&t(mt,{text:te.value,onDismiss:()=>{te.value=null,re.value=null,he.value=0}})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden flex-1",children:t("table",{className:"w-full text-sm",role:"table",children:[t("thead",{children:t("tr",{className:"bg-slate-800 text-slate-400 text-xs",children:[t("th",{className:"px-2 py-2 w-8",children:t("input",{type:"checkbox",className:"accent-brand-500",checked:d.length>0&&d.every(m=>W.value.has(m.id||`chunk-${d.indexOf(m)}`)),onChange:()=>{const m=d.map((_,L)=>_.id||`chunk-${L}`),v=m.every(_=>W.value.has(_)),f=new Set(W.value);for(const _ of m)v?f.delete(_):f.add(_);W.value=f},"aria-label":"Select all chunks on this page"})}),t("th",{className:"px-3 py-2 text-left",children:"File"}),t("th",{className:"px-3 py-2 text-left w-20",children:"Lang"}),t("th",{className:"px-3 py-2 text-left",children:"Description"})]})}),t("tbody",{children:d.length===0?t("tr",{children:t("td",{colSpan:4,className:"px-3 py-8 text-center text-slate-500",children:[t("span",{className:"text-2xl block mb-2",children:"🔍"}),"No chunks found"]})}):d.map((m,v)=>{const f=m.id||`chunk-${v}`,_=re.value===f,L=W.value.has(f);return t("tr",{className:`chunk-row border-t border-slate-800 cursor-pointer ${_?"selected":""}`,onClick:()=>{re.value=f},role:"row",tabIndex:0,children:[t("td",{className:"px-2 py-2",onClick:N=>N.stopPropagation(),children:t("input",{type:"checkbox",className:"accent-brand-500",checked:L,onChange:()=>{const N=new Set(W.value);N.has(f)?N.delete(f):N.add(f),W.value=N},"aria-label":`Select chunk ${f}`})}),t("td",{className:"px-3 py-2 text-yellow-400 font-mono text-xs",children:[C(m.filePath),":",m.startLine,"-",m.endLine]}),t("td",{className:"px-3 py-2",dangerouslySetInnerHTML:{__html:de(m.language)}}),t("td",{className:"px-3 py-2 text-slate-400 text-xs",children:C(m.description??"").slice(0,50)})]},f)})})]})}),t("div",{className:"flex items-center justify-between mt-3",children:[t("button",{className:"px-3 py-1 bg-slate-700 rounded text-sm hover:bg-slate-600 disabled:opacity-50",disabled:p<=1,onClick:()=>{he.value=Math.max(0,n-s)},children:"Previous"}),t("span",{className:"text-sm text-slate-400",children:["Page ",p," of ",h||1]}),t("button",{className:"px-3 py-1 bg-slate-700 rounded text-sm hover:bg-slate-600 disabled:opacity-50",disabled:p>=h,onClick:()=>{he.value+=s},children:"Next"})]}),W.value.size>=2&&W.value.size<=3&&t("div",{className:"fixed bottom-6 right-6 z-50",children:t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-6 py-3 rounded-full shadow-lg font-bold transition-all transform hover:scale-105",onClick:()=>{const m=[...W.value];W.value=new Set,E(`compare?ids=${m.join(",")}`)},children:["Compare (",W.value.size,")"]})})]}),t("div",{className:"w-1/2 overflow-y-auto",children:re.value?t(Cn,{chunkId:re.value,chunks:d}):t("div",{className:"flex items-center justify-center h-full text-slate-500",children:t("div",{className:"text-center",children:[t("div",{className:"text-4xl mb-2",children:"📄"}),t("div",{className:"text-sm",children:"Select a chunk to view details"})]})})})]})}function Cn({chunkId:e,chunks:n}){const[s,r]=b(null),[l,a]=b(!1),i=X(null);if(A(()=>{let u=!1;const h=n.find(p=>p.id===e);return h?r(h):T.chunk(e).then(p=>{u||r(p)}).catch(()=>{u||r({id:e,content:"",filePath:"not found",language:"",startLine:0,endLine:0,description:""})}),()=>{u=!0}},[e,n]),A(()=>()=>{i.current&&clearTimeout(i.current)},[]),!s)return t(G,{type:"detail"});const o=s,c=o.language==="image",d=()=>{navigator.clipboard.writeText(o.content).then(()=>{a(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>a(!1),1500)})};return t("div",{children:[t("div",{className:"mb-3",children:[t("div",{className:"flex items-center gap-3 mb-1",children:t("span",{className:"text-yellow-400 font-mono text-sm",children:C(o.filePath)})}),t("div",{className:"flex items-center gap-3 text-sm text-slate-400",children:[t("span",{children:["Lines ",o.startLine,"-",o.endLine]}),t("span",{dangerouslySetInnerHTML:{__html:de(o.language)}}),o.id&&t("span",{className:"text-xs text-slate-600 font-mono",children:o.id})]})]}),o.description&&t("div",{className:"kpi-card p-3 mb-3",children:[t("h3",{className:"text-xs font-semibold text-slate-400 mb-1",children:"Description"}),t("p",{className:"text-sm text-slate-300",children:C(o.description)})]}),c&&t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden mb-3",children:[t("div",{className:"px-3 py-1.5 bg-slate-800 border-b border-slate-700",children:t("span",{className:"text-xs text-slate-400",children:"Image Preview"})}),t("div",{className:"p-3 flex items-center justify-center bg-slate-950",children:t("img",{src:`/api/file?path=${encodeURIComponent(o.filePath)}`,alt:o.filePath,className:"max-w-full max-h-[60vh] object-contain rounded",onError:u=>{const h=u.currentTarget;h.style.display="none",h.parentElement.innerHTML='<span class="text-slate-500 text-sm">Image not available</span>'}})})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden",children:[t("div",{className:"px-3 py-1.5 bg-slate-800 border-b border-slate-700 flex items-center justify-between",children:[t("span",{className:"text-xs text-slate-400",children:c?"Vision Analysis":"Source Code"}),t("button",{className:"text-xs text-slate-500 hover:text-white transition-colors",onClick:d,children:l?"Copied!":"Copy"})]}),t("pre",{className:"p-3 overflow-x-auto text-sm max-h-[calc(100vh-220px)]",children:t("code",{className:`language-${c?"text":o.language}`,children:C(o.content)})})]})]})}function $n(){const{data:e,isLoading:n,error:s,refresh:r}=z(()=>T.files());if(n)return t(G,{type:"table"});if(s)return t(Q,{message:s,onRetry:r});const l=e??[];if(l.length===0)return t(se,{icon:"📂",message:"No files indexed yet."});const a=l.reduce((i,o)=>i+o.chunkCount,0);return t("div",{children:[t("div",{className:"flex items-center gap-3 mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Files"}),t("span",{className:"text-sm text-slate-400",children:[l.length," files, ",a," chunks"]})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden",children:t("table",{className:"w-full text-sm",role:"table","aria-label":"Indexed files",children:[t("thead",{children:t("tr",{className:"bg-slate-800 text-slate-400 text-xs",children:[t("th",{className:"px-3 py-2 text-left",children:"File"}),t("th",{className:"px-3 py-2 text-left w-28",children:"Language"}),t("th",{className:"px-3 py-2 text-left w-20",children:"Chunks"}),t("th",{className:"px-3 py-2 text-left w-24"})]})}),t("tbody",{children:l.map(i=>t("tr",{className:"border-t border-slate-800 hover:bg-slate-800 cursor-pointer",onClick:()=>E(`chunks?file=${encodeURIComponent(i.filePath)}`),role:"row",tabIndex:0,onKeyDown:o=>{o.key==="Enter"&&E(`chunks?file=${encodeURIComponent(i.filePath)}`)},children:[t("td",{className:"px-3 py-2 text-yellow-400 font-mono text-xs",children:i.filePath}),t("td",{className:"px-3 py-2",dangerouslySetInnerHTML:{__html:de(i.language)}}),t("td",{className:"px-3 py-2 text-slate-300",children:i.chunkCount}),t("td",{className:"px-3 py-2 text-slate-500 text-xs",children:t("span",{className:"hover:text-white transition-colors",children:"View chunks"})})]},i.filePath))})]})})]})}function Ln({segments:e,size:n=180,innerRadius:s,centerLabel:r}){const l=n/2,a=n/2,i=n/2-10,o=s??i*.6,c=e.reduce((p,m)=>p+m.value,0);if(c===0)return t("svg",{width:n,height:n,viewBox:`0 0 ${n} ${n}`,children:[t("circle",{cx:l,cy:a,r:i,fill:"none",stroke:"#334155","stroke-width":i-o}),t("circle",{cx:l,cy:a,r:o,fill:"#0f172a"})]});let d=0;const u=e.map(p=>{const m=p.value/c*360,v=d,f=d+m;return d+=m,`<path d="${Tn(l,a,i,v,f,o)}" fill="${p.color}" />`}).join(""),h=r??"";return t("svg",{width:n,height:n,viewBox:`0 0 ${n} ${n}`,className:"chart-svg",children:[t("g",{dangerouslySetInnerHTML:{__html:u}}),t("text",{x:l,y:a-6,"text-anchor":"middle",fill:"white","font-size":"22","font-weight":"bold",children:h}),t("text",{x:l,y:a+14,"text-anchor":"middle",fill:"#64748b","font-size":"11",children:"tokens"})]})}function Tn(e,n,s,r,l,a){const i=l-r;if(i>=359.99)return`M${e},${n-s} A${s},${s} 0 1,1 ${e-.01},${n-s} L${e-.01},${n-a} A${a},${a} 0 1,0 ${e},${n-a} Z`;const o=L=>(L-90)*Math.PI/180,c=e+s*Math.cos(o(r)),d=n+s*Math.sin(o(r)),u=e+s*Math.cos(o(l)),h=n+s*Math.sin(o(l)),p=e+a*Math.cos(o(l)),m=n+a*Math.sin(o(l)),v=e+a*Math.cos(o(r)),f=n+a*Math.sin(o(r)),_=i>180?1:0;return[`M${c},${d}`,`A${s},${s} 0 ${_} 1 ${u},${h}`,`L${p},${m}`,`A${a},${a} 0 ${_} 0 ${v},${f}`,"Z"].join(" ")}function In(){const e=ye();return e.params.compare?t(Mn,{ids:[e.params.a??"",e.params.b??""]}):e.params.session?t(Pn,{sessionId:e.params.session}):t(Rn,{})}function Rn(){const{data:e,isLoading:n,error:s,refresh:r}=z(()=>T.evalSessions()),[l,a]=b(new Set);if(n)return t(G,{type:"table"});if(s)return t(Q,{message:s,onRetry:r});const i=(e==null?void 0:e.sessions)??[];if(i.length===0)return t(se,{icon:"📊",message:"No sessions recorded yet."});const o=c=>{const d=new Set(l);d.has(c)?d.delete(c):d.add(c),a(d)};return t("div",{children:[t("div",{className:"flex items-center justify-between mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Evaluate"}),t("div",{className:"flex gap-2",children:[l.size===2&&t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-3 py-1 rounded text-sm transition-colors",onClick:()=>{const[c,d]=[...l];E(`evaluate?compare&a=${encodeURIComponent(c)}&b=${encodeURIComponent(d)}`)},children:"Compare Selected"}),l.size>0&&t("button",{className:"text-xs text-slate-400 hover:text-white",onClick:()=>a(new Set),children:["Clear (",l.size,")"]})]})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-x-auto",children:t("table",{className:"w-full text-sm",role:"table",children:[t("thead",{children:t("tr",{className:"bg-slate-800 text-slate-400 text-xs",children:[t("th",{className:"px-2 py-2 w-8"}),t("th",{className:"px-3 py-2 text-left",children:"Session"}),t("th",{className:"px-3 py-2 text-left",children:"Last Activity"}),t("th",{className:"px-3 py-2 text-right",children:"Messages"}),t("th",{className:"px-3 py-2 text-right",children:"Input Tokens"}),t("th",{className:"px-3 py-2 text-right",children:"Output Tokens"}),t("th",{className:"px-3 py-2 text-right",children:"Cost"}),t("th",{className:"px-3 py-2 text-right",children:"RAG Calls"}),t("th",{className:"px-3 py-2 text-right",children:"RAG Tokens"}),t("th",{className:"px-3 py-2 text-left",children:"Model"}),t("th",{className:"px-3 py-2 w-8"})]})}),t("tbody",{children:i.map(c=>{var d,u,h,p;return t("tr",{className:"border-t border-slate-800 hover:bg-slate-800 cursor-pointer",onClick:()=>E(`evaluate?session=${encodeURIComponent(c.sessionID)}`),children:[t("td",{className:"px-2 py-2",onClick:m=>m.stopPropagation(),children:t("input",{type:"checkbox",className:"accent-brand-500",checked:l.has(c.sessionID),onChange:()=>o(c.sessionID),"aria-label":`Select session ${c.title??c.sessionID}`})}),t("td",{className:"px-3 py-2 text-slate-200 font-mono text-xs",children:c.title??c.sessionID.slice(0,8)}),t("td",{className:"px-3 py-2 text-slate-400 text-xs",children:Ot(c.lastEventAt)}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:c.messageCount}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:O((((d=c.totalTokens)==null?void 0:d.input)??0)+(((u=c.totalTokens)==null?void 0:u.cacheRead)??0))}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:O(((h=c.totalTokens)==null?void 0:h.output)??0)}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:Me(c.totalCost??0)}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:c.ragContextCount??0}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:O(c.ragContextTokens??0)}),t("td",{className:"px-3 py-2 text-slate-400 text-xs",children:((p=c.models)==null?void 0:p[0])??"-"}),t("td",{className:"px-3 py-2",onClick:m=>m.stopPropagation(),children:t("button",{className:"text-slate-600 hover:text-red-400 text-xs",onClick:async()=>{if(confirm("Delete this session?"))try{await T.evalDeleteSession(c.sessionID),ee("success","Session deleted"),r()}catch(m){ee("error",`Delete failed: ${m.message}`)}},"aria-label":"Delete session",children:"🗑"})})]},c.sessionID)})})]})})]})}function Pn({sessionId:e}){var h,p,m,v,f,_,L,N;const{data:n,isLoading:s,error:r,refresh:l}=z(()=>T.evalSession(e));if(s)return t(G,{type:"detail"});if(r)return t(Q,{message:r,onRetry:l});const a=(n==null?void 0:n.summary)??n,i=(n==null?void 0:n.events)??[],o=a.toolCallCounts??{};["search_semantic","get_file_skeleton","find_usages","describe_image"].reduce((y,U)=>y+(o[U]??0),0);const d=[{label:"Input",value:(((h=a.totalTokens)==null?void 0:h.input)??0)+(((p=a.totalTokens)==null?void 0:p.cacheRead)??0),color:"#3b82f6"},{label:"Output",value:((m=a.totalTokens)==null?void 0:m.output)??0,color:"#a855f7"},{label:"RAG",value:a.ragContextTokens??0,color:"#06b6d4"},{label:"Reasoning",value:((v=a.totalTokens)==null?void 0:v.reasoning)??0,color:"#f59e0b"}].filter(y=>y.value>0),u=d.reduce((y,U)=>y+U.value,0);return t("div",{children:[t("div",{className:"flex items-center gap-3 mb-4",children:[t("button",{className:"text-sm text-slate-400 hover:text-white",onClick:()=>E("evaluate"),children:"← Back"}),t("h1",{className:"text-xl font-bold",children:a.title??((f=a.sessionID)==null?void 0:f.slice(0,12))})]}),t("div",{className:"grid grid-cols-3 lg:grid-cols-5 gap-3 mb-6",children:[t(K,{label:"Total Tokens",value:O(u)}),t(K,{label:"Input",value:O((((_=a.totalTokens)==null?void 0:_.input)??0)+(((L=a.totalTokens)==null?void 0:L.cacheRead)??0))}),t(K,{label:"Output",value:O(((N=a.totalTokens)==null?void 0:N.output)??0)}),t(K,{label:"Cost",value:Me(a.totalCost??0)}),t(K,{label:"RAG Context",value:O(a.ragContextTokens??0)})]}),t("div",{className:"flex items-center gap-6 mb-6",children:[t(Ln,{segments:d,centerLabel:O(u)}),t("div",{className:"flex flex-wrap gap-3",children:d.map(y=>t("div",{className:"flex items-center gap-1.5 text-xs text-slate-400",children:[t("span",{className:"inline-block w-3 h-3 rounded-sm",style:{background:y.color}}),y.label,": ",O(y.value)," (",(y.value/u*100).toFixed(1),"%)"]},y.label))})]}),t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3 mb-6",children:[t(K,{label:"Messages",value:a.messageCount??0}),t(K,{label:"Steps",value:a.totalSteps??0}),t(K,{label:"RAG Injections",value:a.ragContextCount??0}),t(K,{label:"Avg Response",value:yn(a.avgResponseTimeMs??0)})]}),Object.keys(o).length>0&&t("div",{className:"kpi-card p-4 mb-6",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-3",children:"Tool Calls"}),t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-2",children:Object.entries(o).map(([y,U])=>t("div",{className:"flex justify-between text-xs text-slate-400",children:[t("span",{className:"font-mono",children:y}),t("span",{className:"text-white",children:String(U)})]},y))})]}),a.models&&a.models.length>0&&t("div",{className:"kpi-card p-4 mb-6",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-2",children:"Models"}),t("div",{className:"flex flex-wrap gap-2",children:a.models.map(y=>t("span",{className:"px-2 py-0.5 rounded text-xs font-mono bg-slate-800 text-slate-300",children:y},y))})]}),i.length>0&&t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-3",children:"Event Timeline"}),t("div",{className:"space-y-1 max-h-64 overflow-y-auto",children:i.map((y,U)=>t("div",{className:"flex gap-2 text-xs border-b border-slate-700/50 py-1",children:[t("span",{className:"text-slate-500 shrink-0 w-16",children:Ot(y.ts)}),t("span",{className:"text-slate-400",children:y.event}),y.tool&&t("span",{className:"text-slate-500 font-mono",children:y.tool}),y.toolStatus&&t("span",{className:`text-xs ${y.toolStatus==="completed"?"text-green-400":y.toolStatus==="running"?"text-amber-400":"text-slate-500"}`,children:y.toolStatus})]},U))})]})]})}function Mn({ids:e}){var h,p,m,v,f,_,L,N;const[n,s]=e,{data:r,isLoading:l,error:a}=z(()=>Promise.all([T.evalCompare(n,s),T.evalTokenCompare(n,s)]),[n,s]);if(l)return t(G,{type:"chart"});if(a)return t(Q,{message:a});if(!r)return null;const i=r[0],o=r[1],c=((h=o.sessionA)==null?void 0:h.savings)??0,d=((p=o.sessionB)==null?void 0:p.savings)??0,u=c>0&&d>0?"RAG saves tokens":"Mixed results";return t("div",{children:[t("div",{className:"flex items-center gap-3 mb-4",children:[t("button",{className:"text-sm text-slate-400 hover:text-white",onClick:()=>E("evaluate"),children:"← Back"}),t("h1",{className:"text-xl font-bold",children:"Session Comparison"})]}),t("div",{className:`px-4 py-3 rounded-lg mb-4 font-semibold text-sm ${c>0&&d>0?"bg-green-900/50 text-green-300 border border-green-700":"bg-amber-900/50 text-amber-300 border border-amber-700"}`,children:u}),t("div",{className:"grid grid-cols-2 gap-4",children:[t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-2",children:((m=i.sessionA)==null?void 0:m.title)??"Session A"}),t("div",{className:"space-y-1 text-sm",children:[t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Total Tokens"}),t("span",{children:O(((v=i.sessionA)==null?void 0:v.totalTokens)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Cost"}),t("span",{children:Me(((f=i.sessionA)==null?void 0:f.totalCost)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"RAG Savings"}),t("span",{className:c>0?"text-green-400":"text-red-400",children:[O(Math.abs(c))," (",c>0?"+":"",c>0?"+":"",")"]})]})]})]}),t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-2",children:((_=i.sessionB)==null?void 0:_.title)??"Session B"}),t("div",{className:"space-y-1 text-sm",children:[t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Total Tokens"}),t("span",{children:O(((L=i.sessionB)==null?void 0:L.totalTokens)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Cost"}),t("span",{children:Me(((N=i.sessionB)==null?void 0:N.totalCost)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"RAG Savings"}),t("span",{className:d>0?"text-green-400":"text-red-400",children:O(Math.abs(d))})]})]})]})]})]})}const An={gotcha:"text-amber-400 bg-amber-900/20",preference:"text-emerald-400 bg-emerald-900/20",decision:"text-sky-400 bg-sky-900/20","environment-constraint":"text-rose-400 bg-rose-900/20"};function En(e){return`<span class="inline-block px-1.5 py-0.5 rounded text-xs font-mono ${An[e]??"text-slate-400 bg-slate-800"}">${C(e||"general")}</span>`}function jn(){const{data:e,isLoading:n,error:s,refresh:r}=z(()=>T.quirks()),[l,a]=b(null),[i,o]=b(null),[c,d]=b(!1);if(n)return t(G,{type:"card"});if(s)return t(Q,{message:s,onRetry:r});const u=(e==null?void 0:e.quirks)??[],h=[...new Set(u.map(f=>f.type||"general"))],p=l?u.filter(f=>(f.type||"general")===l):u,m=async f=>{if(confirm("Delete this quirk?"))try{await T.deleteQuirk(f),ee("success","Quirk deleted"),r()}catch(_){ee("error",`Delete failed: ${_.message}`)}};return t("div",{children:[t("div",{className:"flex items-center justify-between mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Quirks"}),t("button",{className:"bg-slate-700 hover:bg-slate-600 text-white px-3 py-1 rounded text-sm transition-colors",onClick:async()=>{d(!0);try{const f=await T.quirkLint();o(f)}catch(f){o({error:f.message})}d(!1)},disabled:c,children:c?"Linting...":"Lint"})]}),t("div",{className:"flex gap-2 mb-4 flex-wrap",children:[t("button",{className:`px-2 py-1 rounded text-xs font-medium transition-colors ${l===null?"bg-brand-600 text-white":"bg-slate-700 text-slate-300 hover:bg-slate-600"}`,onClick:()=>a(null),children:"All"}),h.map(f=>t("button",{className:`px-2 py-1 rounded text-xs font-medium transition-colors ${l===f?"bg-brand-600 text-white":"bg-slate-700 text-slate-300 hover:bg-slate-600"}`,onClick:()=>a(f),children:f},f))]}),i&&t("div",{className:`mb-4 p-3 rounded-lg border text-sm ${i.success?"bg-green-900/30 border-green-700 text-green-300":i.error?"bg-red-900/30 border-red-700 text-red-300":"bg-amber-900/30 border-amber-700 text-amber-300"}`,children:t("pre",{className:"text-xs whitespace-pre-wrap",children:JSON.stringify(i,null,2)})}),p.length===0?t(se,{icon:"💡",message:"No quirks stored yet."}):t("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:p.map(f=>t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 p-3 flex flex-col",children:[t("div",{className:"flex items-center justify-between mb-2",children:[t("span",{dangerouslySetInnerHTML:{__html:En(f.type)}}),t("span",{className:`text-xs font-mono ${f.confidence>.7?"text-green-400":f.confidence>.4?"text-amber-400":"text-red-400"}`,children:[(f.confidence*100).toFixed(0),"%"]})]}),t("p",{className:"text-sm text-slate-200 mb-2 flex-1",children:C(f.content)}),f.tags&&f.tags.length>0&&t("div",{className:"flex gap-1 flex-wrap mb-2",children:f.tags.map(_=>t("span",{className:"text-xs bg-slate-800 text-slate-400 px-1.5 py-0.5 rounded",children:["#",_]},_))}),t("div",{className:"flex items-center justify-between text-xs text-slate-600 mt-auto",children:[f.sourceRef&&t("span",{className:"font-mono",children:C(f.sourceRef)}),t("span",{className:"font-mono",children:f.id})]}),t("button",{className:"self-end mt-2 text-xs text-slate-600 hover:text-red-400 transition-colors",onClick:()=>m(f.id),"aria-label":"Delete quirk",children:"Delete"})]},f.id))})]})}function Fn(){const[e,n]=b([]),[s,r]=b(!1),[l,a]=b(null),[i,o]=b(!1),c=Ge(k.value,300);return A(()=>{const d=q.value.trim();if(!d){n([]),a(null),r(!1),J.value=[];return}let u=!1;return(async()=>{var p,m;r(!0),a(null);try{const v=await T.retrieve({q:d,topK:c.topK,minScore:c.minScore,keywordWeight:c.keywordWeight,hybrid:c.hybrid?"true":"false",explain:"true"});if(u)return;if(v.status===503){a(((p=v.body)==null?void 0:p.error)??"Embedding model unavailable"),r(!1);return}o(!1);const f=((m=v.body)==null?void 0:m.results)??v.results??[];n(f),J.value=f;const _={query:d,params:{...c}};Pe.value=[_,...Pe.value.filter(L=>L.query!==d).slice(0,19)]}catch(v){u||a(v.message)}finally{u||r(!1)}})(),()=>{u=!0}},[q.value,c]),{results:e,isLoading:s,isInitializing:i,error:l,setResults:n}}function On({explanation:e}){const{vectorScore:n,keywordScore:s,rawVectorScore:r,rawKeywordScore:l,keywordWeight:a,vectorRank:i,keywordRank:o}=e.scoreBreakdown,c=Math.max(n+s,.001),d=(n/c*100).toFixed(0),u=(s/c*100).toFixed(0);return t("div",{className:"mb-2",children:[t("div",{className:"flex items-center gap-2 text-xs mb-1",children:[t("span",{className:"text-cyan-400",title:`Vector: ${r.toFixed(3)}${i!==void 0?`, rank #${i+1}`:""}`,children:["Vector ",d,"%"]}),t("span",{className:"text-amber-400",title:`Keyword: ${l.toFixed(3)}${o!==void 0?`, rank #${o+1}`:""}`,children:["Keyword ",u,"%"]}),t("span",{className:"text-slate-500 ml-auto",children:["kw=",a.toFixed(1)]})]}),t("div",{className:"h-2 bg-slate-700 rounded-full overflow-hidden flex",children:[t("div",{className:"h-full bg-cyan-500 transition-all duration-200",style:{width:`${d}%`}}),t("div",{className:"h-full bg-amber-500 transition-all duration-200",style:{width:`${u}%`}})]})]})}function Dn(){const e=ye(),{results:n,isLoading:s,isInitializing:r,error:l}=Fn();return A(()=>{e.params.query&&(q.value=e.params.query,k.value={...k.value,topK:parseInt(e.params.topK??"10",10),minScore:parseFloat(e.params.minScore??"0.35"),keywordWeight:parseFloat(e.params.keywordWeight??"0.4"),hybrid:e.params.hybrid!=="false",pathFilter:e.params.path??"",langFilter:e.params.lang??""})},[]),A(()=>{if(q.value.trim()){const a=new URLSearchParams({query:q.value,topK:String(k.value.topK),minScore:String(k.value.minScore),keywordWeight:String(k.value.keywordWeight),hybrid:String(k.value.hybrid)});k.value.pathFilter&&a.set("path",k.value.pathFilter),k.value.langFilter&&a.set("lang",k.value.langFilter);const i=`search?${a.toString()}`;location.hash!==`#${i}`&&history.replaceState(null,"",`#${i}`)}},[q.value,k.value]),t("div",{children:[t("h1",{className:"text-2xl font-bold mb-4",children:"Semantic Search"}),t("div",{className:"flex gap-3 mb-4",children:t("input",{type:"text",value:q.value,onInput:a=>{q.value=a.target.value,J.value=[]},onKeyDown:a=>{a.key==="Enter"&&q.value.trim()},placeholder:"Search your codebase semantically... (e.g., 'how does authentication work?')",className:"flex-1 px-4 py-2 bg-slate-800 border border-slate-600 rounded-lg text-sm text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400",autoFocus:!0,"aria-label":"Semantic search query"})}),t("details",{className:"mb-4 bg-slate-800 rounded-lg border border-slate-700",children:[t("summary",{className:"px-3 py-2 text-xs text-slate-400 cursor-pointer hover:text-white font-medium",children:"Search Parameters"}),t("div",{className:"px-3 pb-3 space-y-3",children:[t(He,{label:"topK",min:1,max:25,step:1,value:k.value.topK,onChange:a=>{k.value={...k.value,topK:a}}}),t(He,{label:"minScore",min:0,max:1,step:.05,value:k.value.minScore,onChange:a=>{k.value={...k.value,minScore:a}}}),t(He,{label:"keywordWeight",min:0,max:1,step:.1,value:k.value.keywordWeight,onChange:a=>{k.value={...k.value,keywordWeight:a}}}),t("div",{className:"flex items-center gap-2",children:[t("label",{className:"text-xs text-slate-400 w-28",children:"Hybrid mode"}),t("input",{type:"checkbox",checked:k.value.hybrid,onChange:a=>{k.value={...k.value,hybrid:a.target.checked}},className:"accent-brand-500"})]})]})]}),r&&t("div",{className:"text-center py-10 text-slate-400",children:[t("span",{className:"animate-spin inline-block mr-2",children:"⟳"}),"Initializing embedding model..."]}),l&&t(Q,{message:l}),!s&&!l&&q.value.trim()&&n.length===0&&t("div",{className:"text-center py-16 text-slate-500",children:[t("div",{className:"text-4xl mb-2",children:"🔍"}),t("div",{children:['No results found for "',C(q.value),'"']})]}),!s&&!l&&!q.value.trim()&&t("div",{className:"text-center py-16 text-slate-500",children:[t("div",{className:"text-4xl mb-2",children:"🔍"}),t("div",{children:"Enter a query to search your codebase"}),Pe.value.length>0&&t("div",{className:"mt-6",children:[t("p",{className:"text-xs text-slate-600 mb-2",children:"Recent queries:"}),t("div",{className:"flex flex-wrap gap-2 justify-center",children:Pe.value.slice(0,10).map((a,i)=>t("button",{className:"px-2 py-1 bg-slate-800 rounded text-xs text-slate-400 hover:text-white hover:bg-slate-700 transition-colors",onClick:()=>{q.value=a.query},children:C(a.query)},i))})]})]}),n.length>0&&t("div",{className:"space-y-3",children:[t("div",{className:"flex items-center justify-between text-sm text-slate-400 mb-2",children:[t("span",{children:[n.length," result",n.length!==1?"s":""]}),s&&t("span",{className:"text-xs text-brand-400 animate-pulse",children:"Searching..."})]}),n.map(a=>t(Un,{result:a},a.chunk.id))]}),s&&n.length===0&&t("div",{className:"text-center py-10 text-slate-400",children:[t("span",{className:"animate-spin inline-block mr-2",children:"⟳"}),"Searching..."]})]})}function Un({result:e}){var r,l;const n=e.chunk,s=e.score;return t("div",{className:"bg-slate-800 rounded-lg p-4 border border-slate-700 hover:border-brand-500/50 transition-colors cursor-pointer",onClick:()=>E(`chunks?id=${encodeURIComponent(n.id)}`),children:[t("div",{className:"flex items-center justify-between mb-2",children:[t("div",{className:"flex items-center gap-2 min-w-0",children:[t("span",{className:"text-sm text-yellow-400 font-mono truncate",children:[C(n.filePath),":",n.startLine,"-",n.endLine]}),t("span",{dangerouslySetInnerHTML:{__html:de(n.language)}})]}),t("span",{className:"text-lg font-bold shrink-0 ml-2",style:{color:Hn(s)},children:s.toFixed(2)})]}),e.explanation&&t(On,{explanation:e.explanation}),((l=(r=e.explanation)==null?void 0:r.matchedTerms)==null?void 0:l.length)>0&&t("div",{className:"flex gap-1 flex-wrap mb-2",children:e.explanation.matchedTerms.map(a=>t("span",{className:"text-xs bg-amber-500/20 text-amber-300 px-1.5 py-0.5 rounded",children:C(a)},a))}),n.description&&t("p",{className:"text-sm text-slate-400 mb-2 line-clamp-2",children:C(n.description)}),t("pre",{className:"text-xs overflow-x-auto max-h-32 rounded bg-slate-900/50 p-2",children:t("code",{children:C(n.content??"").slice(0,500)})})]})}function Hn(e){return e>=.8?"#22c55e":e>=.6?"#06b6d4":e>=.4?"#f59e0b":"#ef4444"}function He({label:e,min:n,max:s,step:r,value:l,onChange:a}){return t("div",{className:"flex items-center gap-3",children:[t("label",{className:"text-xs text-slate-400 w-28 shrink-0",children:e}),t("input",{type:"range",min:n,max:s,step:r,value:l,onInput:i=>a(parseFloat(i.target.value)),className:"flex-1 accent-brand-500"}),t("span",{className:"text-xs text-slate-300 font-mono w-12 text-right",children:l})]})}function qn(){var c;const n=((c=ye().params.ids)==null?void 0:c.split(",").filter(Boolean))??[],[s,r]=b([]),[l,a]=b(!0),[i,o]=b(null);return A(()=>{let d=!1;if(n.length<2){o("Select 2-3 chunks to compare."),a(!1);return}return T.compare(n).then(u=>{var h;d||(r(((h=u==null?void 0:u.body)==null?void 0:h.chunks)??(u==null?void 0:u.chunks)??[]),a(!1))}).catch(u=>{d||(o(u.message),a(!1))}),()=>{d=!0}},[n.join(",")]),l?t(G,{type:"detail"}):i?t(Q,{message:i}):s.length<2?t(se,{icon:"📋",message:"Select 2-3 chunks from the Chunks view to compare them."}):t("div",{children:[t("div",{className:"flex items-center justify-between mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Chunk Comparison"}),t("button",{className:"text-sm text-slate-400 hover:text-white transition-colors",onClick:()=>E("chunks"),children:"← Back to Chunks"})]}),t("div",{className:`grid gap-4 ${s.length===2?"grid-cols-2":"grid-cols-3"}`,children:s.map((d,u)=>t(Kn,{chunk:d,index:u,baseChunk:u>0?s[0]:void 0},d.id))})]})}function Kn({chunk:e,index:n,baseChunk:s}){const r=e.content.split(`
|
|
2
|
+
`),l=(s==null?void 0:s.content.split(`
|
|
3
|
+
`))??[];return t("div",{className:"bg-slate-800 rounded-lg border border-slate-700 overflow-hidden flex flex-col",children:[t("div",{className:"p-3 border-b border-slate-700 bg-slate-800/80",children:[t("div",{className:"flex items-center justify-between mb-1",children:[t("span",{className:"text-sm font-mono text-brand-400 truncate mr-2",children:[C(e.filePath),":",e.startLine,"-",e.endLine]}),t("span",{className:"shrink-0",dangerouslySetInnerHTML:{__html:de(e.language)}})]}),e.description&&t("p",{className:"text-xs text-slate-400 truncate",children:C(e.description)})]}),t("div",{className:"overflow-x-auto flex-1 max-h-[70vh]",children:t("table",{className:"w-full text-xs font-mono border-collapse",children:t("tbody",{children:r.map((a,i)=>{const o=(e.startLine??1)+i,c=l[i]===void 0?"bg-green-900/30":a===""&&l[i]!==""?"bg-red-900/30":a!==l[i]?"bg-amber-900/20":"";return t("tr",{className:c,children:[t("td",{className:"text-right text-slate-600 select-none px-2 w-10 border-r border-slate-700 align-top",children:o}),t("td",{className:"px-3 py-0 whitespace-pre-wrap break-all",children:C(a)||" "})]},i)})})})}),t("div",{className:"px-3 py-1.5 bg-slate-900 border-t border-slate-700 text-xs text-slate-500",children:["Chunk ",n+1,n===0&&t("span",{className:"text-slate-600 ml-1",children:"(reference)"})]})]})}function Bn(){var a;const{data:e,isLoading:n,error:s,refresh:r}=z(()=>T.config());if(n)return t(G,{type:"card"});if(s)return t(Q,{message:s,onRetry:r});const l=((a=e==null?void 0:e.body)==null?void 0:a.config)??(e==null?void 0:e.config);return l?t("div",{children:[t("h1",{className:"text-2xl font-bold mb-6",children:"Configuration"}),t("p",{className:"text-sm text-slate-400 mb-4",children:["Effective configuration from ",t("code",{className:"text-brand-400",children:"opencode-rag.json"}),". API keys are redacted."]}),t("div",{className:"space-y-4",children:Object.entries(l).map(([i,o])=>t("details",{className:"bg-slate-800 rounded-lg border border-slate-700",open:!0,children:[t("summary",{className:"px-4 py-2 cursor-pointer hover:bg-slate-700 font-mono text-sm font-semibold capitalize text-slate-300",children:i.replace(/([A-Z])/g," $1")}),t("div",{className:"px-4 pb-3",children:typeof o=="object"&&o!==null?Object.entries(o).map(([c,d])=>t("div",{className:"flex justify-between py-1 border-b border-slate-700/50 text-sm",children:[t("span",{className:"text-slate-400 font-mono",children:c}),t("span",{className:"text-slate-200 font-mono text-xs text-right ml-4",children:Wn(d)})]},c)):t("div",{className:"flex justify-between py-1 text-sm",children:t("span",{className:"text-slate-200 font-mono",children:String(o)})})})]},i))})]}):t(se,{icon:"⚙",message:"No configuration available."})}function Wn(e){return e===null?"null":e===void 0?"undefined":typeof e=="boolean"?e?"true":"false":Array.isArray(e)?`[${e.join(", ")}]`:typeof e=="object"?JSON.stringify(e).slice(0,150):String(e)}function Vn(e,n){for(var s in n)e[s]=n[s];return e}function pt(e,n){for(var s in e)if(s!=="__source"&&!(s in n))return!0;for(var r in n)if(r!=="__source"&&e[r]!==n[r])return!0;return!1}function xt(e,n){this.props=e,this.context=n}(xt.prototype=new ie).isPureReactComponent=!0,xt.prototype.shouldComponentUpdate=function(e,n){return pt(this.props,e)||pt(this.state,n)};var vt=M.__b;M.__b=function(e){e.type&&e.type.__f&&e.ref&&(e.props.ref=e.ref,e.ref=null),vt&&vt(e)};var zn=M.__e;M.__e=function(e,n,s,r){if(e.then){for(var l,a=n;a=a.__;)if((l=a.__c)&&l.__c)return n.__e==null&&(n.__e=s.__e,n.__k=s.__k||[]),l.__c(e,n)}zn(e,n,s,r)};var gt=M.unmount;function Dt(e,n,s){return e&&(e.__c&&e.__c.__H&&(e.__c.__H.__.forEach(function(r){typeof r.__c=="function"&&r.__c()}),e.__c.__H=null),(e=Vn({},e)).__c!=null&&(e.__c.__P===s&&(e.__c.__P=n),e.__c.__e=!0,e.__c=null),e.__k=e.__k&&e.__k.map(function(r){return Dt(r,n,s)})),e}function Ut(e,n,s){return e&&s&&(e.__v=null,e.__k=e.__k&&e.__k.map(function(r){return Ut(r,n,s)}),e.__c&&e.__c.__P===n&&(e.__e&&s.appendChild(e.__e),e.__c.__e=!0,e.__c.__P=s)),e}function qe(){this.__u=0,this.o=null,this.__b=null}function Ht(e){var n=e.__&&e.__.__c;return n&&n.__a&&n.__a(e)}function Ce(){this.i=null,this.l=null}M.unmount=function(e){var n=e.__c;n&&(n.__z=!0),n&&n.__R&&n.__R(),n&&32&e.__u&&(e.type=null),gt&>(e)},(qe.prototype=new ie).__c=function(e,n){var s=n.__c,r=this;r.o==null&&(r.o=[]),r.o.push(s);var l=Ht(r.__v),a=!1,i=function(){a||r.__z||(a=!0,s.__R=null,l?l(c):c())};s.__R=i;var o=s.__P;s.__P=null;var c=function(){if(!--r.__u){if(r.state.__a){var d=r.state.__a;r.__v.__k[0]=Ut(d,d.__c.__P,d.__c.__O)}var u;for(r.setState({__a:r.__b=null});u=r.o.pop();)u.__P=o,u.forceUpdate()}};r.__u++||32&n.__u||r.setState({__a:r.__b=r.__v.__k[0]}),e.then(i,i)},qe.prototype.componentWillUnmount=function(){this.o=[]},qe.prototype.render=function(e,n){if(this.__b){if(this.__v.__k){var s=document.createElement("div"),r=this.__v.__k[0].__c;this.__v.__k[0]=Dt(this.__b,s,r.__O=r.__P)}this.__b=null}var l=n.__a&&et(ve,null,e.fallback);return l&&(l.__u&=-33),[et(ve,null,n.__a?null:e.children),l]};var bt=function(e,n,s){if(++s[1]===s[0]&&e.l.delete(n),e.props.revealOrder&&(e.props.revealOrder[0]!=="t"||!e.l.size))for(s=e.i;s;){for(;s.length>3;)s.pop()();if(s[1]<s[0])break;e.i=s=s[2]}};(Ce.prototype=new ie).__a=function(e){var n=this,s=Ht(n.__v),r=n.l.get(e);return r[0]++,function(l){var a=function(){n.props.revealOrder?(r.push(l),bt(n,e,r)):l()};s?s(a):a()}},Ce.prototype.render=function(e){this.i=null,this.l=new Map;var n=Ke(e.children);e.revealOrder&&e.revealOrder[0]==="b"&&n.reverse();for(var s=n.length;s--;)this.l.set(n[s],this.i=[1,0,this.i]);return e.children},Ce.prototype.componentDidUpdate=Ce.prototype.componentDidMount=function(){var e=this;this.l.forEach(function(n,s){bt(e,s,n)})};var Gn=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.element")||60103,Qn=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,Xn=/^on(Ani|Tra|Tou|BeforeInp|Compo)/,Yn=/[A-Z0-9]/g,Zn=typeof document<"u",Jn=function(e){return(typeof Symbol<"u"&&typeof Symbol()=="symbol"?/fil|che|rad/:/fil|che|ra/).test(e)};ie.prototype.isReactComponent=!0,["componentWillMount","componentWillReceiveProps","componentWillUpdate"].forEach(function(e){Object.defineProperty(ie.prototype,e,{configurable:!0,get:function(){return this["UNSAFE_"+e]},set:function(n){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:n})}})});var _t=M.event;M.event=function(e){return _t&&(e=_t(e)),e.persist=function(){},e.isPropagationStopped=function(){return this.cancelBubble},e.isDefaultPrevented=function(){return this.defaultPrevented},e.nativeEvent=e};var es={configurable:!0,get:function(){return this.class}},yt=M.vnode;M.vnode=function(e){typeof e.type=="string"&&function(n){var s=n.props,r=n.type,l={},a=r.indexOf("-")==-1;for(var i in s){var o=s[i];if(!(i==="value"&&"defaultValue"in s&&o==null||Zn&&i==="children"&&r==="noscript"||i==="class"||i==="className")){var c=i.toLowerCase();i==="defaultValue"&&"value"in s&&s.value==null?i="value":i==="download"&&o===!0?o="":c==="translate"&&o==="no"?o=!1:c[0]==="o"&&c[1]==="n"?c==="ondoubleclick"?i="ondblclick":c!=="onchange"||r!=="input"&&r!=="textarea"||Jn(s.type)?c==="onfocus"?i="onfocusin":c==="onblur"?i="onfocusout":Xn.test(i)&&(i=c):c=i="oninput":a&&Qn.test(i)?i=i.replace(Yn,"-$&").toLowerCase():o===null&&(o=void 0),c==="oninput"&&l[i=c]&&(i="oninputCapture"),l[i]=o}}r=="select"&&(l.multiple&&Array.isArray(l.value)&&(l.value=Ke(s.children).forEach(function(d){d.props.selected=l.value.indexOf(d.props.value)!=-1})),l.defaultValue!=null&&(l.value=Ke(s.children).forEach(function(d){d.props.selected=l.multiple?l.defaultValue.indexOf(d.props.value)!=-1:l.defaultValue==d.props.value}))),s.class&&!s.className?(l.class=s.class,Object.defineProperty(l,"className",es)):s.className&&(l.class=l.className=s.className),n.props=l}(e),e.$$typeof=Gn,yt&&yt(e)};var Nt=M.__r;M.__r=function(e){Nt&&Nt(e),e.__c};var wt=M.diffed;M.diffed=function(e){wt&&wt(e);var n=e.props,s=e.__e;s!=null&&e.type==="textarea"&&"value"in n&&n.value!==s.value&&(s.value=n.value==null?"":n.value)};const ts=10;function ns({points:e,width:n=800,height:s=600,onPointClick:r,renderTooltip:l}){const a=X(null),[i,o]=b({x:0,y:0,scale:1}),[c,d]=b(null),[u,h]=b(!1),p=X({x:0,y:0}),m=X(null),v=X(null),f=X(e);f.current=e;const _=ot(x=>{m.current=x(m.current??i),v.current===null&&(v.current=requestAnimationFrame(()=>{v.current=null,m.current&&(o(m.current),m.current=null)}))},[i]);A(()=>()=>{v.current!==null&&cancelAnimationFrame(v.current)},[]);const L=ot((x,g)=>{const w=a.current;if(!w)return null;const j=w.getBoundingClientRect(),H=m.current??i,B=x-j.left,D=g-j.top;let Qe=null,Xe=ts;for(const Fe of f.current){const qt=Fe.x*n*H.scale+H.x,Kt=Fe.y*s*H.scale+H.y,Ye=B-qt,Ze=D-Kt,Je=Math.sqrt(Ye*Ye+Ze*Ze);Je<=Xe&&(Xe=Je,Qe=Fe)}return Qe},[i,n,s]);A(()=>{const x=a.current;if(!x)return;const g=x.getContext("2d");if(!g)return;const w=window.devicePixelRatio||1;x.width=n*w,x.height=s*w,g.scale(w,w),g.clearRect(0,0,n,s),g.save(),g.translate(i.x,i.y),g.scale(i.scale,i.scale);for(const j of e){const H=j.x*n,B=j.y*s,D=(j.radius??3)*(j.highlighted?2:1);g.beginPath(),g.arc(H,B,D,0,Math.PI*2),g.fillStyle=j.color,g.globalAlpha=j.highlighted?1:.6,g.fill(),j.highlighted&&(g.strokeStyle="#22d3ee",g.lineWidth=2,g.stroke())}g.restore()},[e,i,n,s]);const N=x=>{x.preventDefault();const g=x.deltaY>0?.9:1.1;_(w=>({...w,scale:Math.max(.5,Math.min(10,w.scale*g))}))},y=x=>{h(!0),p.current={x:x.clientX-i.x,y:x.clientY-i.y}},U=x=>{if(u){_(w=>({...w,x:x.clientX-p.current.x,y:x.clientY-p.current.y}));return}const g=L(x.clientX,x.clientY);d(w=>(w==null?void 0:w.id)===(g==null?void 0:g.id)?w:g)},ue=()=>h(!1);return t("div",{className:"relative overflow-hidden rounded-lg border border-slate-700 bg-slate-900",style:{width:n,height:s},children:[t("canvas",{ref:a,className:"absolute inset-0 cursor-grab active:cursor-grabbing",onMouseDown:y,onMouseMove:U,onMouseUp:ue,onMouseLeave:ue,onClick:x=>{if(u)return;const g=L(x.clientX,x.clientY);g&&(r==null||r(g.id))},onWheel:N}),c&&l&&t("div",{className:"absolute bg-slate-800 border border-slate-600 rounded-lg p-3 shadow-xl text-sm z-10 pointer-events-none",style:{left:Math.min(c.x*n*i.scale+i.x+12,n-200),top:Math.min(c.y*s*i.scale+i.y-12,s-80)},children:l(c)}),i.scale!==1&&t("button",{className:"absolute bottom-3 right-3 px-2 py-1 bg-slate-700 hover:bg-slate-600 rounded text-xs text-white transition-colors z-20",onClick:()=>{o({x:0,y:0,scale:1}),m.current=null},children:"Reset zoom"})]})}function xe(e,n){return Math.sqrt((e.x-n.x)**2+(e.y-n.y)**2)}function ss(e,n=8,s=20){const r=e.length;if(r<=n)return e.map((i,o)=>o);const l=new Array(r).fill(0),a=[];a.push(e[Math.floor(Math.random()*r)]);for(let i=1;i<n;i++){const o=e.map(u=>Math.min(...a.map(h=>xe(u,h)))),c=o.reduce((u,h)=>u+h*h,0);let d=Math.random()*c;for(let u=0;u<r;u++)if(d-=o[u]*o[u],d<=0){a.push(e[u]);break}}for(let i=0;i<s;i++){for(let c=0;c<r;c++){let d=0,u=xe(e[c],a[0]);for(let h=1;h<a.length;h++){const p=xe(e[c],a[h]);p<u&&(u=p,d=h)}l[c]=d}const o=a.map(()=>({x:0,y:0,count:0}));for(let c=0;c<r;c++){const d=l[c];o[d].x+=e[c].x,o[d].y+=e[c].y,o[d].count++}a.forEach((c,d)=>{o[d].count>0&&(c.x=o[d].x/o[d].count,c.y=o[d].y/o[d].count)})}return l}function as(e,n,s){const r=s.map((a,i)=>{const c=e.filter((h,p)=>n[p]===i).map(h=>xe(h,a)),d=c.reduce((h,p)=>h+p,0)/c.length,u=c.reduce((h,p)=>h+(p-d)**2,0)/c.length;return Math.sqrt(u)}),l=new Set;for(let a=0;a<e.length;a++){const i=n[a];xe(e[a],s[i])>2*(r[i]??0)&&l.add(a)}return l}const le=["#3b82f6","#ef4444","#22c55e","#f59e0b","#a855f7","#06b6d4","#ec4899","#84cc16"];function rs(){var ue,je;const{data:e,isLoading:n,error:s,refresh:r}=z(()=>T.embeddingProj(5e3)),[l,a]=b("language"),[i,o]=b(!1),[c,d]=b(!1),[u,h]=b(!1),[p,m]=b(new Set),[v,f]=b(null),[_,L]=b(new Set),N=((ue=e==null?void 0:e.body)==null?void 0:ue.points)??(e==null?void 0:e.points)??[],y=((je=e==null?void 0:e.body)==null?void 0:je.totalChunks)??(e==null?void 0:e.totalChunks)??0;if(A(()=>{if(i&&N.length>0){const x=Math.min(8,Math.max(2,Math.floor(N.length/20))),g=ss(N,x);if(f(g),c){const w=[];for(let j=0;j<x;j++){const H=N.filter((B,D)=>g[D]===j);H.length>0&&w.push({x:H.reduce((B,D)=>B+D.x,0)/H.length,y:H.reduce((B,D)=>B+D.y,0)/H.length})}L(as(N,g,w))}}else f(null),L(new Set)},[i,c,N]),A(()=>{u&&J.value.length>0?m(new Set(J.value.map(x=>x.chunk.id))):m(new Set)},[u,J.value]),n)return t(G,{type:"chart"});if(s)return t(Q,{message:s,onRetry:r});if(N.length===0)return t(se,{icon:"🌐",message:"No embedding data available. Index some files first."});const U=_e(()=>N.map((x,g)=>{let w;if(l==="language")w=we(x.language)==="text-slate-400"?"#94a3b8":is(x.language);else if(l==="file"){const D=x.filePath.split("/")[0]??"root";w=le[ls(D)%le.length]}else{const D=(v==null?void 0:v[g])??0;w=le[D%le.length]}const j=_.has(g),B=p.has(x.id);return{id:x.id,x:x.x,y:x.y,color:B?"#22d3ee":j?"#f97316":w,label:`${x.filePath}:${x.startLine}-${x.endLine} [${x.language}]`,radius:B?6:j?5:3,highlighted:B}}),[N,l,v,_,p]);return t("div",{children:[t("h1",{className:"text-2xl font-bold mb-4",children:"Embedding Space Explorer"}),t("div",{className:"flex flex-wrap gap-3 mb-4 items-center",children:[t("label",{className:"text-xs text-slate-400",children:"Color by:"}),t("select",{className:"bg-slate-800 border border-slate-600 rounded text-xs text-slate-200 px-2 py-1",value:l,onChange:x=>a(x.target.value),children:[t("option",{value:"language",children:"Language"}),t("option",{value:"file",children:"File"}),t("option",{value:"cluster",children:"Cluster"})]}),t("label",{className:"flex items-center gap-1.5 text-xs text-slate-400",children:[t("input",{type:"checkbox",className:"accent-brand-500",checked:i,onChange:x=>o(x.target.checked)}),"Clusters"]}),t("label",{className:"flex items-center gap-1.5 text-xs text-slate-400",children:[t("input",{type:"checkbox",className:"accent-brand-500",checked:c,onChange:x=>d(x.target.checked)}),"Outliers"]}),J.value.length>0&&t("label",{className:"flex items-center gap-1.5 text-xs text-slate-400",children:[t("input",{type:"checkbox",className:"accent-brand-500",checked:u,onChange:x=>h(x.target.checked)}),"Search overlay (",J.value.length," results)"]})]}),l==="cluster"&&v&&t("div",{className:"flex flex-wrap gap-2 mb-3 text-xs",children:Array.from(new Set(v)).sort().map(x=>t("span",{className:"flex items-center gap-1 text-slate-400",children:[t("span",{className:"inline-block w-2 h-2 rounded-full",style:{background:le[x%le.length]}}),"Cluster ",x+1]},x))}),t(ns,{points:U,width:900,height:600,onPointClick:x=>E(`chunks?id=${encodeURIComponent(x)}`),renderTooltip:x=>{const g=N.find(w=>w.id===x.id);return t("div",{children:[t("div",{className:"text-yellow-400 font-mono text-xs",children:C(x.label)}),(g==null?void 0:g.description)&&t("div",{className:"text-slate-400 text-xs mt-1",children:C(vn(g.description,80))})]})}}),t("p",{className:"text-xs text-slate-500 mt-2",children:[U.length," of ",y," chunks displayed",U.length<y&&" (chunks without embeddings omitted)"]})]})}function ls(e){let n=0;for(let s=0;s<e.length;s++)n=n*31+e.charCodeAt(s)|0;return Math.abs(n)}function is(e){return{typescript:"#60a5fa",javascript:"#facc15",python:"#4ade80",java:"#f87171",go:"#22d3ee",rust:"#fb923c",ruby:"#f472b6",csharp:"#a78bfa",cpp:"#818cf8",c:"#9ca3af",markdown:"#d1d5db",html:"#fdba74",css:"#60a5fa",json:"#fde047",kotlin:"#c084fc",swift:"#fb923c",tex:"#34d399",sql:"#67e8f9",text:"#94a3b8",image:"#a78bfa",quirk:"#fbbf24"}[e]??"#94a3b8"}const os=[{view:"dashboard",label:"Dashboard",icon:"📊"},{view:"search",label:"Search",icon:"🔍"},{view:"embeddings",label:"Embeddings",icon:"🌐"},{view:"chunks",label:"Chunks",icon:"🧩"},{view:"files",label:"Files",icon:"📄"},{view:"evaluate",label:"Evaluate",icon:"📈"},{view:"quirks",label:"Quirks",icon:"💡"}];function cs(){on(),cn();const e=ye();De.value=e.view;const n=()=>{Se.value=!Se.value};return t("div",{className:"h-screen flex flex-col overflow-hidden",children:[t("header",{className:"flex items-center gap-3 px-4 py-2 border-b shrink-0",style:{borderColor:"var(--border)"},children:[t("h1",{className:"text-lg font-bold shrink-0",style:{color:"var(--accent)"},children:"OpenCodeRAG"}),t("nav",{className:"flex gap-1 flex-1",role:"navigation","aria-label":"Main navigation",children:os.map(s=>t("button",{id:`nav-${s.view}`,className:`nav-btn ${De.value===s.view?"active":""}`,onClick:()=>window.location.hash=s.view,role:"tab","aria-selected":De.value===s.view,children:[s.icon," ",s.label]},s.view))}),t(gn,{}),t(un,{}),t("button",{className:"p-2 rounded-lg transition-colors hidden lg:block",style:{color:"var(--text-muted)"},onClick:n,"aria-label":"Toggle file tree",title:"Toggle file tree",children:"☰"}),t("button",{className:"p-2 rounded-lg transition-colors lg:hidden",style:{color:"var(--text-muted)"},onClick:n,"aria-label":"Toggle file tree",title:"Toggle file tree",children:"☰"})]}),t("div",{className:"flex flex-1 overflow-hidden",children:[Se.value&&t(ve,{children:[t("div",{className:"fixed inset-0 z-30 lg:hidden",style:{background:"rgba(0,0,0,0.5)"},onClick:()=>{Se.value=!1}}),t("aside",{className:"w-64 overflow-y-auto shrink-0 border-r z-40 fixed lg:relative inset-y-0 left-0",style:{background:"var(--bg-secondary)",borderColor:"var(--border)"},role:"tree","aria-label":"File tree",children:t(bn,{})})]}),t("main",{className:"flex-1 overflow-y-auto p-6",id:"main-content",tabIndex:-1,children:[e.view==="dashboard"&&t(kn,{}),e.view==="search"&&t(Dn,{}),e.view==="embeddings"&&t(rs,{}),e.view==="compare"&&t(qn,{}),e.view==="chunks"&&t(Sn,{}),e.view==="files"&&t($n,{}),e.view==="evaluate"&&t(In,{}),e.view==="quirks"&&t(jn,{}),e.view==="config"&&t(Bn,{})]})]}),t(dn,{})]})}Wt(t(cs,{}),document.getElementById("app"));
|
package/dist/web/ui/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>OpenCodeRAG</title>
|
|
7
7
|
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🔎</text></svg>">
|
|
8
|
-
<script type="module" crossorigin src="/ui/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/ui/assets/index-BDPYdtA1.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/ui/assets/vendor-Dy7HKFCY.js">
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/ui/assets/index-CKdp79Tw.css">
|
|
11
11
|
</head>
|
package/package.json
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{l as P,S as pe,C as re,t as Et,k as Ge,F as He,R as jt}from"./vendor-Dy7HKFCY.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))l(i);new MutationObserver(i=>{for(const a of i)if(a.type==="childList")for(const r of a.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&l(r)}).observe(document,{childList:!0,subtree:!0});function s(i){const a={};return i.integrity&&(a.integrity=i.integrity),i.referrerPolicy&&(a.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?a.credentials="include":i.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function l(i){if(i.ep)return;i.ep=!0;const a=s(i);fetch(i.href,a)}})();var Ft=0;function t(e,n,s,l,i,a){n||(n={});var r,c,o=n;if("ref"in o)for(c in o={},n)c=="ref"?r=n[c]:o[c]=n[c];var d={type:e,props:o,key:s,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Ft,__i:-1,__u:0,__source:i,__self:a};if(typeof e=="function"&&(r=e.defaultProps))for(c in r)o[c]===void 0&&(o[c]=r[c]);return P.vnode&&P.vnode(d),d}var ve,T,Fe,Qe,$e=0,vt=[],I=P,Ze=I.__b,Je=I.__r,Xe=I.diffed,Ye=I.__c,et=I.unmount,tt=I.__;function Be(e,n){I.__h&&I.__h(T,e,$e||n),$e=0;var s=T.__H||(T.__H={__:[],__h:[]});return e>=s.__.length&&s.__.push({}),s.__[e]}function _(e){return $e=1,At(gt,e)}function At(e,n,s){var l=Be(ve++,2);if(l.t=e,!l.__c&&(l.__=[s?s(n):gt(void 0,n),function(c){var o=l.__N?l.__N[0]:l.__[0],d=l.t(o,c);o!==d&&(l.__N=[d,l.__[1]],l.__c.setState({}))}],l.__c=T,!T.__f)){var i=function(c,o,d){if(!l.__c.__H)return!0;var u=!1,h=l.__c.props!==c;if(l.__c.__H.__.some(function(m){if(m.__N){u=!0;var x=m.__[0];m.__=m.__N,m.__N=void 0,x!==m.__[0]&&(h=!0)}}),a){var p=a.call(this,c,o,d);return u?p||h:p}return!u||h};T.__f=!0;var a=T.shouldComponentUpdate,r=T.componentWillUpdate;T.componentWillUpdate=function(c,o,d){if(this.__e){var u=a;a=void 0,i(c,o,d),a=u}r&&r.call(this,c,o,d)},T.shouldComponentUpdate=i}return l.__N||l.__}function E(e,n){var s=Be(ve++,3);!I.__s&&xt(s.__H,n)&&(s.__=e,s.u=n,T.__H.__h.push(s))}function Ce(e){return $e=5,We(function(){return{current:e}},[])}function We(e,n){var s=Be(ve++,7);return xt(s.__H,n)&&(s.__=e(),s.__H=n,s.__h=e),s.__}function Ot(){for(var e;e=vt.shift();){var n=e.__H;if(e.__P&&n)try{n.__h.some(Se),n.__h.some(qe),n.__h=[]}catch(s){n.__h=[],I.__e(s,e.__v)}}}I.__b=function(e){T=null,Ze&&Ze(e)},I.__=function(e,n){e&&n.__k&&n.__k.__m&&(e.__m=n.__k.__m),tt&&tt(e,n)},I.__r=function(e){Je&&Je(e),ve=0;var n=(T=e.__c).__H;n&&(Fe===T?(n.__h=[],T.__h=[],n.__.some(function(s){s.__N&&(s.__=s.__N),s.u=s.__N=void 0})):(n.__h.some(Se),n.__h.some(qe),n.__h=[],ve=0)),Fe=T},I.diffed=function(e){Xe&&Xe(e);var n=e.__c;n&&n.__H&&(n.__H.__h.length&&(vt.push(n)!==1&&Qe===I.requestAnimationFrame||((Qe=I.requestAnimationFrame)||Dt)(Ot)),n.__H.__.some(function(s){s.u&&(s.__H=s.u,s.u=void 0)})),Fe=T=null},I.__c=function(e,n){n.some(function(s){try{s.__h.some(Se),s.__h=s.__h.filter(function(l){return!l.__||qe(l)})}catch(l){n.some(function(i){i.__h&&(i.__h=[])}),n=[],I.__e(l,s.__v)}}),Ye&&Ye(e,n)},I.unmount=function(e){et&&et(e);var n,s=e.__c;s&&s.__H&&(s.__H.__.some(function(l){try{Se(l)}catch(i){n=i}}),s.__H=void 0,n&&I.__e(n,s.__v))};var nt=typeof requestAnimationFrame=="function";function Dt(e){var n,s=function(){clearTimeout(l),nt&&cancelAnimationFrame(n),setTimeout(e)},l=setTimeout(s,35);nt&&(n=requestAnimationFrame(s))}function Se(e){var n=T,s=e.__c;typeof s=="function"&&(e.__c=void 0,s()),T=n}function qe(e){var n=T;e.__c=e.__(),T=n}function xt(e,n){return!e||e.length!==n.length||n.some(function(s,l){return s!==e[l]})}function gt(e,n){return typeof n=="function"?n(e):n}function st(){const e=location.hash.slice(1)||"dashboard",n=e.indexOf("?"),s=n>=0?e.slice(0,n):e,l={};if(n>=0){const i=e.slice(n+1);for(const a of i.split("&")){const r=a.indexOf("=");r>=0&&(l[decodeURIComponent(a.slice(0,r))]=decodeURIComponent(a.slice(r+1)))}}return{view:s||"dashboard",params:l}}function xe(){const[e,n]=_(st);return E(()=>{const s=()=>n(st());return addEventListener("hashchange",s),()=>removeEventListener("hashchange",s)},[]),e}var Ut=Symbol.for("preact-signals");function Ee(){if(G>1)G--;else{var e,n=!1;for(function(){var i=Te;for(Te=void 0;i!==void 0;){var a=i.S;if(a.v===i.v)for(var r=a.t;r!==void 0;r=r.x)r.i===i.i&&(r.i=a.i);i=i.o}}();fe!==void 0;){var s=fe;for(fe=void 0,Le++;s!==void 0;){var l=s.u;if(s.u=void 0,s.f&=-3,!(8&s.f)&&_t(s))try{s.c()}catch(i){n||(e=i,n=!0)}s=l}}if(Le=0,G--,n)throw e}}function Ht(e){if(G>0)return e();Ke=++qt,G++;try{return e()}finally{Ee()}}var he,k=void 0;function je(e){var n=k,s=he;k=void 0,he=void 0;try{return e()}finally{k=n,he=s}}var fe=void 0,G=0,Le=0,qt=0,Ke=0,Te=void 0,Ie=0;function bt(e){if(k!==void 0){var n=e.n;if(n===void 0||n.t!==k)return n={i:0,S:e,p:k.s,n:void 0,t:k,e:void 0,x:void 0,r:n},k.s!==void 0&&(k.s.n=n),k.s=n,e.n=n,32&k.f&&e.S(n),n;if(n.i===-1)return n.i=0,n.n!==void 0&&(n.n.p=n.p,n.p!==void 0&&(n.p.n=n.n),n.p=k.s,n.n=void 0,k.s.n=n,k.s=n),n}}function j(e,n){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=n==null?void 0:n.watched,this.Z=n==null?void 0:n.unwatched,this.name=n==null?void 0:n.name}j.prototype.brand=Ut;j.prototype.h=function(){return!0};j.prototype.S=function(e){var n=this,s=this.t;s!==e&&e.e===void 0&&(e.x=s,this.t=e,s!==void 0?s.e=e:je(function(){var l;(l=n.W)==null||l.call(n)}))};j.prototype.U=function(e){var n=this;if(this.t!==void 0){var s=e.e,l=e.x;s!==void 0&&(s.x=l,e.e=void 0),l!==void 0&&(l.e=s,e.x=void 0),e===this.t&&(this.t=l,l===void 0&&je(function(){var i;(i=n.Z)==null||i.call(n)}))}};j.prototype.subscribe=function(e){var n=this;return ge(function(){var s=n.value;je(function(){return e(s)})},{name:"sub"})};j.prototype.valueOf=function(){return this.value};j.prototype.toString=function(){return this.value+""};j.prototype.toJSON=function(){return this.value};j.prototype.peek=function(){var e=this;return je(function(){return e.value})};Object.defineProperty(j.prototype,"value",{get:function(){var e=bt(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Le>100)throw new Error("Cycle detected");(function(s){G!==0&&Le===0&&s.l!==Ke&&(s.l=Ke,Te={S:s,v:s.v,i:s.i,o:Te})})(this),this.v=e,this.i++,Ie++,G++;try{for(var n=this.t;n!==void 0;n=n.x)n.t.N()}finally{Ee()}}}});function $(e,n){return new j(e,n)}function _t(e){for(var n=e.s;n!==void 0;n=n.n)if(n.S.i!==n.i||!n.S.h()||n.S.i!==n.i)return!0;return!1}function yt(e){for(var n=e.s;n!==void 0;n=n.n){var s=n.S.n;if(s!==void 0&&(n.r=s),n.S.n=n,n.i=-1,n.n===void 0){e.s=n;break}}}function Nt(e){for(var n=e.s,s=void 0;n!==void 0;){var l=n.p;n.i===-1?(n.S.U(n),l!==void 0&&(l.n=n.n),n.n!==void 0&&(n.n.p=l)):s=n,n.S.n=n.r,n.r!==void 0&&(n.r=void 0),n=l}e.s=s}function X(e,n){j.call(this,void 0,n),this.x=e,this.s=void 0,this.g=Ie-1,this.f=4}X.prototype=new j;X.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Ie))return!0;if(this.g=Ie,this.f|=1,this.i>0&&!_t(this))return this.f&=-2,!0;var e=k;try{yt(this),k=this;var n=this.x();(16&this.f||this.v!==n||this.i===0)&&(this.v=n,this.f&=-17,this.i++)}catch(s){this.v=s,this.f|=16,this.i++}return k=e,Nt(this),this.f&=-2,!0};X.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var n=this.s;n!==void 0;n=n.n)n.S.S(n)}j.prototype.S.call(this,e)};X.prototype.U=function(e){if(this.t!==void 0&&(j.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var n=this.s;n!==void 0;n=n.n)n.S.U(n)}};X.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(X.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=bt(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function at(e,n){return new X(e,n)}function wt(e){var n=e.m;if(e.m=void 0,typeof n=="function"){G++;var s=k;k=void 0;try{n()}catch(l){throw e.f&=-2,e.f|=8,Ve(e),l}finally{k=s,Ee()}}}function Ve(e){for(var n=e.s;n!==void 0;n=n.n)n.S.U(n);e.x=void 0,e.s=void 0,wt(e)}function Kt(e){if(k!==this)throw new Error("Out-of-order effect");Nt(this),k=e,this.f&=-2,8&this.f&&Ve(this),Ee()}function ie(e,n){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=n==null?void 0:n.name,he&&he.push(this)}ie.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var n=this.x();typeof n=="function"&&(this.m=n)}finally{e()}};ie.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,wt(this),yt(this),G++;var e=k;return k=this,Kt.bind(this,e)};ie.prototype.N=function(){2&this.f||(this.f|=2,this.u=fe,fe=this)};ie.prototype.d=function(){this.f|=8,1&this.f||Ve(this)};ie.prototype.dispose=function(){this.d()};function ge(e,n){var s=new ie(e,n);try{s.c()}catch(i){throw s.d(),i}var l=s.d.bind(s);return l[Symbol.dispose]=l,l}var kt,Ne,Bt=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__,St=[];ge(function(){kt=this.N})();function oe(e,n){P[e]=n.bind(null,P[e]||function(){})}function Pe(e){if(Ne){var n=Ne;Ne=void 0,n()}Ne=e&&e.S()}function $t(e){var n=this,s=e.data,l=Vt(s);l.name="ReactiveDom",l.value=s;var i=We(function(){for(var c=n,o=n.__v;o=o.__;)if(o.__c){o.__c.__$f|=4;break}var d=at(function(){var m=l.value.value;return m===0?0:m===!0?"":m||""}),u=at(function(){return!Array.isArray(d.value)&&!Et(d.value)}),h=ge(function(){if(this.N=Ct,u.value){var m=d.value;c.__v&&c.__v.__e&&c.__v.__e.nodeType===3&&(c.__v.__e.data=m)}}),p=n.__$u.d;return n.__$u.d=function(){h(),p.call(this)},[u,d]},[]),a=i[0],r=i[1];return a.value?r.peek():r.value}$t.displayName="ReactiveTextNode";Object.defineProperties(j.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:$t},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});oe("__b",function(e,n){if(typeof n.type=="string"){var s,l=n.props;for(var i in l)if(i!=="children"){var a=l[i];a instanceof j&&(s||(n.__np=s={}),s[i]=a,l[i]=a.peek())}}e(n)});oe("__r",function(e,n){if(e(n),n.type!==pe){Pe();var s,l=n.__c;l&&(l.__$f&=-2,(s=l.__$u)===void 0&&(l.__$u=s=function(i,a){var r;return ge(function(){r=this},{name:a}),r.c=i,r}(function(){var i;Bt&&((i=s.y)==null||i.call(s)),l.__$f|=1,l.setState({})},typeof n.type=="function"?n.type.displayName||n.type.name:""))),Pe(s)}});oe("__e",function(e,n,s,l){Pe(),e(n,s,l)});oe("diffed",function(e,n){Pe();var s;if(typeof n.type=="string"&&(s=n.__e)){var l=n.__np,i=n.props,a=s.U;if(a)for(var r in a){var c=a[r];c===void 0||l&&r in l||(c.d(),a[r]=void 0)}if(l){a||(a={},s.U=a);for(var o in l){var d=a[o],u=l[o];d===void 0?(d=Wt(s,o,u,i),a[o]=d):d.o(u,i)}}}e(n)});function Wt(e,n,s,l){var i=n in e&&e.ownerSVGElement===void 0,a=$(s);return{o:function(r,c){a.value=r,l=c},d:ge(function(){this.N=Ct;var r=a.value.value;l[n]!==r&&(l[n]=r,i?e[n]=r:r!=null&&(r!==!1||n[4]==="-")?e.setAttribute(n,r):e.removeAttribute(n))})}}oe("unmount",function(e,n){if(typeof n.type=="string"){var s=n.__e;if(s){var l=s.U;if(l){s.U=void 0;for(var i in l){var a=l[i];a&&a.d()}}}var r=n.__np;if(r){var c=n.props;for(var o in r)c[o]=r[o]}n.__np=void 0}else{var d=n.__c;if(d){var u=d.__$u;u&&(d.__$u=void 0,u.d())}}e(n)});oe("__h",function(e,n,s,l){l<3&&(n.__$f|=2),e(n,s,l)});re.prototype.shouldComponentUpdate=function(e,n){if(this.__R)return!0;var s=this.__$u,l=s&&s.s!==void 0;for(var i in n)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var a=2&this.__$f;if(!(l||a||4&this.__$f)||1&this.__$f)return!0}else if(!(l||4&this.__$f)||3&this.__$f)return!0;for(var r in e)if(r!=="__source"&&e[r]!==this.props[r])return!0;for(var c in this.props)if(!(c in e))return!0;return!1};function Vt(e,n){return We(function(){return $(e,n)},[])}var zt=function(e){queueMicrotask(function(){queueMicrotask(e)})};function Gt(){Ht(function(){for(var e;e=St.shift();)kt.call(e)})}function Ct(){St.push(this)===1&&(P.requestAnimationFrame||zt)(Gt)}const Ae=$("dashboard"),Z=$(null),ne=$(null),se=$(null),de=$(0),Qt=$(50),D=$(new Set),Oe=$(new Set),A=$(""),w=$({topK:10,minScore:.35,keywordWeight:.4,hybrid:!0,pathFilter:"",langFilter:""}),le=$([]),Re=$([]);$(!1);$(null);$([]);$(new Set);$(null);$(null);const z=$("dark"),we=$(!0),ue=$([]);let Zt=0;function J(e,n,s=4e3){const l=Zt++;ue.value=[...ue.value,{id:l,type:e,message:n,duration:s}],setTimeout(()=>{ue.value=ue.value.filter(i=>i.id!==l)},s)}function M(e){window.location.hash=e}function Jt(){E(()=>{const n=localStorage.getItem("theme");n&&(z.value=n)},[]),E(()=>{document.documentElement.classList.toggle("dark",z.value==="dark"),localStorage.setItem("theme",z.value)},[z.value]);const e=()=>{z.value=z.value==="dark"?"light":"dark"};return{theme:z.value,toggle:e}}function Xt(){E(()=>{const e=n=>{const s=n.target,l=s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable;if((n.metaKey||n.ctrlKey)&&n.key==="k"){n.preventDefault(),M("search");return}if(!l&&n.key==="g"){const i={d:()=>M("dashboard"),s:()=>M("search"),c:()=>M("chunks"),f:()=>M("files"),e:()=>M("evaluate"),q:()=>M("quirks")},a=r=>{var c;(c=i[r.key])==null||c.call(i),window.removeEventListener("keydown",a)};window.addEventListener("keydown",a),setTimeout(()=>window.removeEventListener("keydown",a),500);return}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[])}function Yt(){return t("div",{className:"fixed top-4 right-4 z-[9999] flex flex-col gap-2 pointer-events-none",children:ue.value.map(e=>t("div",{className:`pointer-events-auto px-4 py-2.5 rounded-lg shadow-lg text-sm font-medium transition-all duration-300 animate-slide-in ${e.type==="success"?"bg-green-600 text-white":e.type==="error"?"bg-red-600 text-white":"bg-brand-600 text-white"}`,children:e.message},e.id))})}function en(){const e=z.value==="dark";return t("button",{className:"p-2 rounded-lg transition-colors",style:{color:"var(--text-muted)"},onClick:()=>{z.value=e?"light":"dark"},"aria-label":e?"Switch to light mode":"Switch to dark mode",title:e?"Light mode":"Dark mode",children:[t("span",{className:"sr-only",children:e?"Switch to light mode":"Switch to dark mode"}),e?t("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:t("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"})}):t("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:t("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"})})]})}function ze(e,n){const[s,l]=_(e);return E(()=>{const i=setTimeout(()=>l(e),n);return()=>clearTimeout(i)},[e,n]),s}const tn="/api";function lt(e){const n=new URLSearchParams;for(const[s,l]of Object.entries(e))l!==void 0&&l!==""&&n.set(s,String(l));return n.toString()}async function L(e,n){const s=await fetch(tn+e,n),l=await s.json();if(!s.ok)throw new Error(l.error??s.statusText);return l}const C={stats:()=>L("/stats"),files:()=>L("/files"),chunks:e=>L(`/chunks?${lt(e)}`),chunk:e=>L(`/chunks/${encodeURIComponent(e)}`),search:(e,n=20)=>L(`/search?q=${encodeURIComponent(e)}&topK=${n}`),compare:e=>L(`/compare?ids=${e.join(",")}`),retrieve:e=>L(`/retrieve?${lt(e)}`),evalSessions:()=>L("/eval/sessions"),evalSession:e=>L(`/eval/sessions/${encodeURIComponent(e)}`),evalDeleteSession:e=>L(`/eval/sessions/${encodeURIComponent(e)}`,{method:"DELETE"}),evalCompare:(e,n)=>L(`/eval/compare?a=${e}&b=${n}`),evalTokenCompare:(e,n)=>L(`/eval/token-compare?a=${e}&b=${n}`),evalAnalysis:e=>L(`/eval/sessions/${encodeURIComponent(e)}/analysis`),evalProjectSavings:e=>L("/eval/project-savings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),quirks:()=>L("/quirks"),quirkLint:()=>L("/quirks/lint"),deleteQuirk:e=>L(`/quirks/${encodeURIComponent(e)}`,{method:"DELETE"}),indexStatus:()=>L("/indexing/status"),triggerReindex:()=>L("/indexing/reindex",{method:"POST"}),config:()=>L("/config"),embeddingProj:(e=5e3)=>L(`/embeddings/projection?maxChunks=${e}`)},nn={typescript:"text-blue-400",javascript:"text-yellow-400",python:"text-green-400",java:"text-red-400",go:"text-cyan-400",rust:"text-orange-400",ruby:"text-pink-400",csharp:"text-purple-400",cpp:"text-indigo-400",c:"text-gray-400",markdown:"text-gray-300",html:"text-orange-300",css:"text-blue-300",json:"text-yellow-300",kotlin:"text-purple-300",swift:"text-orange-400",tex:"text-emerald-400",sql:"text-cyan-300"};function be(e){return nn[e]??"text-slate-400"}function ce(e){return`<span class="inline-block px-1.5 py-0.5 rounded text-xs font-mono ${be(e)} bg-slate-800">${sn(e)}</span>`}function sn(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function S(e){return typeof e!="string"?"":e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function an(e,n=80){const s=typeof e=="string"?e:String(e??"");return s.length>n?s.slice(0,n)+"...":s}function ln(){const[e,n]=_(""),[s,l]=_([]),[i,a]=_(!1),r=Ce(null),c=Ce(null),o=ze(e,300);E(()=>{if(!o.trim()){l([]),a(!1);return}C.search(o,10).then(h=>{l((h==null?void 0:h.results)??[]),a(!0)})},[o]),E(()=>{const h=p=>{c.current&&!c.current.contains(p.target)&&a(!1)};return document.addEventListener("click",h),()=>document.removeEventListener("click",h)},[]);const d=h=>{h.key==="Escape"&&a(!1)},u=async h=>{a(!1),n(""),M("chunks")};return t("div",{ref:c,className:"relative",children:[t("input",{ref:r,type:"text",placeholder:"Search codebase...",value:e,onInput:h=>n(h.target.value),onKeyDown:d,className:"w-56 px-3 py-1.5 bg-slate-800 border border-slate-600 rounded text-sm text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400","aria-label":"Global search",role:"combobox","aria-expanded":i}),i&&s.length>0&&t("div",{className:"absolute top-full right-0 mt-1 w-96 bg-slate-800 border border-slate-600 rounded-lg shadow-xl z-50 max-h-80 overflow-y-auto",role:"listbox",children:s.map(h=>t("div",{className:"search-result p-2 hover:bg-slate-700 cursor-pointer border-b border-slate-700 last:border-0",onClick:()=>u(h.chunk.id),role:"option",children:[t("div",{className:"flex items-center gap-2 text-xs",children:[t("span",{className:"text-yellow-400 font-mono",children:[S(h.chunk.filePath),":",h.chunk.startLine,"-",h.chunk.endLine]}),t("span",{dangerouslySetInnerHTML:{__html:ce(h.chunk.language)}}),t("span",{className:"ml-auto text-slate-500",children:h.score})]}),t("div",{className:"text-xs text-slate-400 mt-1 truncate",children:S(h.chunk.content??"").slice(0,80)})]},h.chunk.id))}),i&&e.trim()&&s.length===0&&t("div",{className:"absolute top-full right-0 mt-1 w-96 bg-slate-800 border border-slate-600 rounded-lg shadow-xl z-50 p-3 text-sm text-slate-500",children:"No results"})]})}function q(e,n=[]){const[s,l]=_(null),[i,a]=_(!0),[r,c]=_(null),[o,d]=_(0);return E(()=>{let u=!1;return a(!0),c(null),e().then(h=>{u||(l(h),a(!1))}).catch(h=>{u||(c(h.message),a(!1))}),()=>{u=!0}},[...n,o]),{data:s,isLoading:i,error:r,refresh:()=>d(u=>u+1)}}function rn(){const{data:e}=q(()=>C.files()),n=e??[],[s,l]=_(""),i=ze(s,300),a=i?n.filter(r=>r.filePath.toLowerCase().includes(i.toLowerCase())):n;return t("div",{className:"flex flex-col h-full",children:[t("div",{className:"flex items-center justify-between mb-2 px-3 pt-3",children:[t("h2",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wide",children:"Files"}),t("span",{className:"text-xs text-slate-500",children:a.length})]}),t("div",{className:"px-3 mb-2",children:t("input",{type:"text",placeholder:"Filter files...",value:s,onInput:r=>l(r.target.value),className:"w-full px-2 py-1 bg-slate-900 border border-slate-700 rounded text-xs focus:outline-none focus:border-brand-400 text-slate-200 placeholder-slate-500"})}),t("div",{className:"flex-1 overflow-y-auto px-1",children:t(on,{files:a})})]})}function on({files:e}){const n={};for(const s of e){const l=s.filePath.split("/");let i=n;for(let a=0;a<l.length-1;a++)i[l[a]]||(i[l[a]]={}),i=i[l[a]];i.__files||(i.__files=[]),i.__files.push(s)}return t(Tt,{obj:n,depth:0,parentPath:""})}function Lt(e){let n=(e.__files||[]).length;for(const[s,l]of Object.entries(e))s!=="__files"&&(n+=Lt(l));return n}function Tt({obj:e,depth:n,parentPath:s}){const l=Object.entries(e).filter(([a])=>a!=="__files").sort(([a],[r])=>a.localeCompare(r)),i=e.__files||[];return t(pe,{children:[l.map(([a,r])=>{const c=s?`${s}/${a}`:a,o=Lt(r),d=Oe.value.has(c),u=d?"▸":"▾";return t("div",{children:[t("div",{className:"file-item flex items-center gap-1 py-0.5 px-2 rounded cursor-pointer text-slate-400 hover:text-white",style:{paddingLeft:`${n*12+8}px`},onClick:()=>{const h=new Set(Oe.value);h.has(c)?h.delete(c):h.add(c),Oe.value=h},role:"treeitem","aria-expanded":!d,children:[t("span",{className:"text-xs",children:u}),t("span",{className:"text-xs",children:"📁"}),t("span",{className:"text-xs",children:S(a)}),t("span",{className:"text-xs text-slate-600 ml-auto",children:o})]}),!d&&t("div",{className:"dir-children",children:t(Tt,{obj:r,depth:n+1,parentPath:c})})]},c)}),i.map(a=>{const r=a.filePath.split("/").pop()??a.filePath,c=Z.value===a.filePath;return t("div",{className:`file-item flex items-center gap-1 py-0.5 px-2 rounded cursor-pointer ${c?"active text-white":"text-slate-400 hover:text-white"}`,style:{paddingLeft:`${n*12+8}px`},onClick:()=>{Z.value=a.filePath,M(`chunks?file=${encodeURIComponent(a.filePath)}`)},role:"treeitem",tabIndex:0,children:[t("span",{className:`text-xs ${be(a.language)}`,children:"♦"}),t("span",{className:"text-xs truncate",children:S(r)}),t("span",{className:"text-xs text-slate-600 ml-auto",children:a.chunkCount})]},a.filePath)})]})}const U="bg-gradient-to-r from-slate-700 via-slate-600 to-slate-700 bg-[length:200%_100%]";function K({type:e="card"}){return t("div",{className:"animate-pulse space-y-4",children:[t("div",{className:`h-8 ${U} rounded w-48`}),e==="card"&&t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[1,2,3,4].map(n=>t("div",{className:"h-24 bg-slate-800 rounded-lg border border-slate-700 p-4",children:[t("div",{className:`h-3 ${U} rounded w-16 mb-2`}),t("div",{className:`h-6 ${U} rounded w-24`})]},n))}),e==="table"&&t("div",{className:"space-y-2",children:[t("div",{className:`h-10 ${U} rounded w-full`}),[1,2,3,4,5].map(n=>t("div",{className:`h-8 ${U} rounded w-full`},n))]}),e==="chart"&&t("div",{className:`h-64 ${U} rounded-lg`}),e==="detail"&&t("div",{className:"flex gap-4",children:[t("div",{className:"flex-1 space-y-3",children:[t("div",{className:`h-6 ${U} rounded w-48`}),t("div",{className:`h-4 ${U} rounded w-32`}),t("div",{className:`h-32 ${U} rounded-lg`})]}),t("div",{className:"flex-1 space-y-3",children:[t("div",{className:`h-6 ${U} rounded w-48`}),t("div",{className:`h-4 ${U} rounded w-32`}),t("div",{className:`h-32 ${U} rounded-lg`})]})]})]})}function B({message:e,onRetry:n}){return t("div",{className:"flex flex-col items-center justify-center py-12 text-center",role:"alert",children:[t("span",{className:"text-4xl mb-3",children:"⚠️"}),t("p",{className:"text-slate-400 mb-4",children:e}),n&&t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-4 py-2 rounded transition-colors",onClick:n,children:"Retry"})]})}function Y({icon:e,message:n,action:s}){return t("div",{className:"flex flex-col items-center justify-center py-16 text-center",role:"status",children:[t("span",{className:"text-5xl mb-4",role:"img","aria-label":e,children:e}),t("p",{className:"text-slate-400 mb-4",children:n}),s&&t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-4 py-2 rounded transition-colors",onClick:s.onClick,children:s.label})]})}function O({label:e,value:n,icon:s}){return t("div",{className:"kpi-card p-4",children:[s&&t("span",{className:"text-lg mb-1 block",children:s}),t("div",{className:"text-slate-400 text-xs mb-1",children:e}),t("div",{className:"text-3xl font-bold text-white",children:n})]})}function F(e){return e>=1e6?(e/1e6).toFixed(1)+"M":e>=1e3?(e/1e3).toFixed(1)+"k":String(e)}function Me(e){return e===0?"$0.00":e<.01?"$"+e.toFixed(4):"$"+e.toFixed(2)}function cn(e){return e>=6e4?(e/6e4).toFixed(1)+"m":e>=1e3?(e/1e3).toFixed(1)+"s":e+"ms"}function It(e){if(!e)return"-";const n=new Date(e);return n.toLocaleDateString()+" "+n.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function dn(e){const n=Date.now()-new Date(e).getTime(),s=Math.floor(n/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const l=Math.floor(s/60);return l<24?`${l}h ago`:`${Math.floor(l/24)}d ago`}function un(){var h;const[e,n]=_(null),[s,l]=_(!0),[i,a]=_(!1),r=async()=>{try{const p=await C.indexStatus();n(p.body??p)}catch{}l(!1)};E(()=>{r()},[]);const c=async()=>{a(!0);try{await C.triggerReindex(),J("info","Reindex started in background");const p=setInterval(async()=>{var f,N;const m=await C.indexStatus(),x=m.body??m;((f=x.manifest)==null?void 0:f.lastIndexedAt)!==((N=e==null?void 0:e.manifest)==null?void 0:N.lastIndexedAt)&&(clearInterval(p),n(x),a(!1),J("success","Reindex complete!"))},2e3)}catch(p){J("error",`Reindex failed: ${p.message}`),a(!1)}};if(s)return null;const o=(h=e==null?void 0:e.manifest)!=null&&h.lastIndexedAt?dn(e.manifest.lastIndexedAt):"Never",d=(e==null?void 0:e.staleFileCount)??0,u=d===0?"text-green-400":d<50?"text-amber-400":"text-red-400";return t("div",{className:"kpi-card p-4 mb-6",children:[t("div",{className:"flex items-center justify-between mb-3",children:t("h2",{className:"text-lg font-semibold",children:"Index Status"})}),e!=null&&e.manifest?t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Last Indexed"}),t("span",{className:"text-sm font-mono",children:o})]}),t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Total Chunks"}),t("span",{className:"text-sm font-mono",children:F(e.manifest.totalChunks)})]}),t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Total Files"}),t("span",{className:"text-sm font-mono",children:F(e.manifest.totalFiles)})]}),t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Schema Version"}),t("span",{className:"text-sm font-mono",children:e.manifest.schemaVersion})]}),t("div",{className:"col-span-2",children:[t("span",{className:"text-xs text-slate-500 block",children:"Index Freshness"}),t("span",{className:`text-sm font-mono ${u}`,children:d===0?"✓ Up to date":`⚠ ${d} file${d!==1?"s":""} modified since last index`})]}),t("div",{className:"col-span-2 flex items-end",children:i?t("div",{className:"flex items-center gap-2",children:[t("span",{className:"animate-spin",children:"⟳"}),t("span",{className:"text-sm text-amber-400",children:"Reindexing..."})]}):t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-4 py-1.5 rounded text-sm transition-colors",onClick:c,children:"Reindex Now"})})]}):t("div",{className:"text-sm text-slate-400",children:["No index found. Run ",t("code",{className:"text-brand-400",children:"opencode-rag index"})," first."]})]})}function hn(){var p,m,x;const{data:e,isLoading:n,error:s,refresh:l}=q(()=>C.stats()),{data:i}=q(()=>C.files());if(n)return t(K,{type:"card"});if(s)return t(B,{message:s,onRetry:l});if(!e)return t(Y,{icon:"📊",message:"No dashboard data available."});const a=e,r=((p=i==null?void 0:i.body)==null?void 0:p.length)??a.totalFiles??0,c=a.totalChunks??0,o=((m=a.languages)==null?void 0:m.length)??0,d=r>0?(c/r).toFixed(1):"0",u=(a.languages??[]).slice(0,8),h=((x=u[0])==null?void 0:x.count)??1;return t("div",{children:[t("h1",{className:"text-2xl font-bold mb-6",children:"Dashboard"}),t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4 mb-8",children:[t(O,{label:"Total Chunks",value:c.toLocaleString(),icon:"🧩"}),t(O,{label:"Total Files",value:r.toLocaleString(),icon:"📄"}),t(O,{label:"Languages",value:o,icon:"🔤"}),t(O,{label:"Avg Chunks/File",value:d,icon:"📊"})]}),t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-3",children:"Language Distribution"}),t("div",{className:"space-y-2",children:u.map(f=>t("div",{className:"flex items-center gap-3",children:[t("span",{className:`w-24 text-xs text-right ${be(f.language)}`,children:f.language}),t("div",{className:"flex-1 bg-slate-800 rounded-full h-5 overflow-hidden",children:t("div",{className:"h-full rounded-full bg-brand-500 flex items-center pl-2",style:{width:`${Math.max(8,f.count/h*100)}%`},children:t("span",{className:"text-xs font-medium text-white",children:f.count})})}),t("span",{className:"text-xs text-slate-500 w-12 text-right",children:[(f.count/c*100).toFixed(0),"%"]})]},f.language))})]}),t(un,{}),t("div",{className:"mt-6",children:t("h2",{className:"text-lg font-semibold mb-3",children:t("a",{href:"#config",className:"hover:text-brand-400 transition-colors",children:"Configuration"})})})]})}function rt({text:e,color:n,onDismiss:s}){return t("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-mono bg-slate-800 ${n??"text-slate-400"}`,children:[e,s&&t("button",{className:"ml-0.5 text-slate-500 hover:text-white",onClick:s,"aria-label":`Dismiss ${e} filter`,children:"×"})]})}function fn(){const e=xe();E(()=>{e.params.file&&(Z.value=e.params.file),e.params.lang&&(ne.value=e.params.lang)},[e.params.file,e.params.lang]);const n=de.value,s=Qt.value,l=Z.value,i=ne.value,{data:a,isLoading:r,error:c,refresh:o}=q(()=>C.chunks({offset:n,limit:s,lang:i??"",file:l??""}),[n,s,l,i]);if(r)return t(K,{type:"detail"});if(c)return t(B,{message:c,onRetry:o});const d=(a==null?void 0:a.chunks)??[],u=(a==null?void 0:a.total)??d.length,h=Math.ceil(u/s),p=Math.floor(n/s)+1;return t("div",{className:"flex gap-4 h-full",children:[t("div",{className:"w-1/2 flex flex-col",children:[t("div",{className:"flex items-center gap-3 mb-3 flex-wrap",children:[t("h2",{className:"text-lg font-semibold text-white",children:"Chunks"}),t("span",{className:"text-sm text-slate-400",children:[u," total"]}),ne.value&&t(rt,{text:ne.value,color:be(ne.value),onDismiss:()=>{ne.value=null,se.value=null,de.value=0}}),Z.value&&t(rt,{text:Z.value,onDismiss:()=>{Z.value=null,se.value=null,de.value=0}})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden flex-1",children:t("table",{className:"w-full text-sm",role:"table",children:[t("thead",{children:t("tr",{className:"bg-slate-800 text-slate-400 text-xs",children:[t("th",{className:"px-2 py-2 w-8",children:t("input",{type:"checkbox",className:"accent-brand-500",checked:d.length>0&&d.every(m=>D.value.has(m.id||`chunk-${d.indexOf(m)}`)),onChange:()=>{const m=d.map((N,b)=>N.id||`chunk-${b}`),x=m.every(N=>D.value.has(N)),f=new Set(D.value);for(const N of m)x?f.delete(N):f.add(N);D.value=f},"aria-label":"Select all chunks on this page"})}),t("th",{className:"px-3 py-2 text-left",children:"File"}),t("th",{className:"px-3 py-2 text-left w-20",children:"Lang"}),t("th",{className:"px-3 py-2 text-left",children:"Description"})]})}),t("tbody",{children:d.length===0?t("tr",{children:t("td",{colSpan:4,className:"px-3 py-8 text-center text-slate-500",children:[t("span",{className:"text-2xl block mb-2",children:"🔍"}),"No chunks found"]})}):d.map((m,x)=>{const f=m.id||`chunk-${x}`,N=se.value===f,b=D.value.has(f);return t("tr",{className:`chunk-row border-t border-slate-800 cursor-pointer ${N?"selected":""}`,onClick:()=>{se.value=f},role:"row",tabIndex:0,children:[t("td",{className:"px-2 py-2",onClick:v=>v.stopPropagation(),children:t("input",{type:"checkbox",className:"accent-brand-500",checked:b,onChange:()=>{const v=new Set(D.value);v.has(f)?v.delete(f):v.add(f),D.value=v},"aria-label":`Select chunk ${f}`})}),t("td",{className:"px-3 py-2 text-yellow-400 font-mono text-xs",children:[S(m.filePath),":",m.startLine,"-",m.endLine]}),t("td",{className:"px-3 py-2",dangerouslySetInnerHTML:{__html:ce(m.language)}}),t("td",{className:"px-3 py-2 text-slate-400 text-xs",children:S(m.description??"").slice(0,50)})]},f)})})]})}),t("div",{className:"flex items-center justify-between mt-3",children:[t("button",{className:"px-3 py-1 bg-slate-700 rounded text-sm hover:bg-slate-600 disabled:opacity-50",disabled:p<=1,onClick:()=>{de.value=Math.max(0,n-s)},children:"Previous"}),t("span",{className:"text-sm text-slate-400",children:["Page ",p," of ",h||1]}),t("button",{className:"px-3 py-1 bg-slate-700 rounded text-sm hover:bg-slate-600 disabled:opacity-50",disabled:p>=h,onClick:()=>{de.value+=s},children:"Next"})]}),D.value.size>=2&&D.value.size<=3&&t("div",{className:"fixed bottom-6 right-6 z-50",children:t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-6 py-3 rounded-full shadow-lg font-bold transition-all transform hover:scale-105",onClick:()=>{const m=[...D.value];D.value=new Set,M(`compare?ids=${m.join(",")}`)},children:["Compare (",D.value.size,")"]})})]}),t("div",{className:"w-1/2 overflow-y-auto",children:se.value?t(mn,{chunkId:se.value,chunks:d}):t("div",{className:"flex items-center justify-center h-full text-slate-500",children:t("div",{className:"text-center",children:[t("div",{className:"text-4xl mb-2",children:"📄"}),t("div",{className:"text-sm",children:"Select a chunk to view details"})]})})})]})}function mn({chunkId:e,chunks:n}){const[s,l]=_(null),[i,a]=_(!1);if(E(()=>{const d=n.find(u=>u.id===e);d?l(d):C.chunk(e).then(u=>{l(u)})},[e,n]),!s)return t(K,{type:"detail"});const r=s,c=r.language==="image",o=()=>{navigator.clipboard.writeText(r.content).then(()=>{a(!0),setTimeout(()=>a(!1),1500)})};return t("div",{children:[t("div",{className:"mb-3",children:[t("div",{className:"flex items-center gap-3 mb-1",children:t("span",{className:"text-yellow-400 font-mono text-sm",children:S(r.filePath)})}),t("div",{className:"flex items-center gap-3 text-sm text-slate-400",children:[t("span",{children:["Lines ",r.startLine,"-",r.endLine]}),t("span",{dangerouslySetInnerHTML:{__html:ce(r.language)}}),r.id&&t("span",{className:"text-xs text-slate-600 font-mono",children:r.id})]})]}),r.description&&t("div",{className:"kpi-card p-3 mb-3",children:[t("h3",{className:"text-xs font-semibold text-slate-400 mb-1",children:"Description"}),t("p",{className:"text-sm text-slate-300",children:S(r.description)})]}),c&&t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden mb-3",children:[t("div",{className:"px-3 py-1.5 bg-slate-800 border-b border-slate-700",children:t("span",{className:"text-xs text-slate-400",children:"Image Preview"})}),t("div",{className:"p-3 flex items-center justify-center bg-slate-950",children:t("img",{src:`/api/file?path=${encodeURIComponent(r.filePath)}`,alt:r.filePath,className:"max-w-full max-h-[60vh] object-contain rounded",onError:d=>{const u=d.currentTarget;u.style.display="none",u.parentElement.innerHTML='<span class="text-slate-500 text-sm">Image not available</span>'}})})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden",children:[t("div",{className:"px-3 py-1.5 bg-slate-800 border-b border-slate-700 flex items-center justify-between",children:[t("span",{className:"text-xs text-slate-400",children:c?"Vision Analysis":"Source Code"}),t("button",{className:"text-xs text-slate-500 hover:text-white transition-colors",onClick:o,children:i?"Copied!":"Copy"})]}),t("pre",{className:"p-3 overflow-x-auto text-sm max-h-[calc(100vh-220px)]",children:t("code",{className:`language-${c?"text":r.language}`,children:S(r.content)})})]})]})}function pn(){const{data:e,isLoading:n,error:s,refresh:l}=q(()=>C.files());if(n)return t(K,{type:"table"});if(s)return t(B,{message:s,onRetry:l});const i=e??[];if(i.length===0)return t(Y,{icon:"📂",message:"No files indexed yet."});const a=i.reduce((r,c)=>r+c.chunkCount,0);return t("div",{children:[t("div",{className:"flex items-center gap-3 mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Files"}),t("span",{className:"text-sm text-slate-400",children:[i.length," files, ",a," chunks"]})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden",children:t("table",{className:"w-full text-sm",role:"table","aria-label":"Indexed files",children:[t("thead",{children:t("tr",{className:"bg-slate-800 text-slate-400 text-xs",children:[t("th",{className:"px-3 py-2 text-left",children:"File"}),t("th",{className:"px-3 py-2 text-left w-28",children:"Language"}),t("th",{className:"px-3 py-2 text-left w-20",children:"Chunks"}),t("th",{className:"px-3 py-2 text-left w-24"})]})}),t("tbody",{children:i.map(r=>t("tr",{className:"border-t border-slate-800 hover:bg-slate-800 cursor-pointer",onClick:()=>M(`chunks?file=${encodeURIComponent(r.filePath)}`),role:"row",tabIndex:0,onKeyDown:c=>{c.key==="Enter"&&M(`chunks?file=${encodeURIComponent(r.filePath)}`)},children:[t("td",{className:"px-3 py-2 text-yellow-400 font-mono text-xs",children:r.filePath}),t("td",{className:"px-3 py-2",dangerouslySetInnerHTML:{__html:ce(r.language)}}),t("td",{className:"px-3 py-2 text-slate-300",children:r.chunkCount}),t("td",{className:"px-3 py-2 text-slate-500 text-xs",children:t("span",{className:"hover:text-white transition-colors",children:"View chunks"})})]},r.filePath))})]})})]})}function vn({segments:e,size:n=180,innerRadius:s,centerLabel:l}){const i=n/2,a=n/2,r=n/2-10,c=s??r*.6,o=e.reduce((p,m)=>p+m.value,0);if(o===0)return t("svg",{width:n,height:n,viewBox:`0 0 ${n} ${n}`,children:[t("circle",{cx:i,cy:a,r,fill:"none",stroke:"#334155","stroke-width":r-c}),t("circle",{cx:i,cy:a,r:c,fill:"#0f172a"})]});let d=0;const u=e.map(p=>{const m=p.value/o*360,x=d,f=d+m;return d+=m,`<path d="${xn(i,a,r,x,f,c)}" fill="${p.color}" />`}).join(""),h=l??"";return t("svg",{width:n,height:n,viewBox:`0 0 ${n} ${n}`,className:"chart-svg",children:[t("g",{dangerouslySetInnerHTML:{__html:u}}),t("text",{x:i,y:a-6,"text-anchor":"middle",fill:"white","font-size":"22","font-weight":"bold",children:h}),t("text",{x:i,y:a+14,"text-anchor":"middle",fill:"#64748b","font-size":"11",children:"tokens"})]})}function xn(e,n,s,l,i,a){const r=i-l;if(r>=359.99)return`M${e},${n-s} A${s},${s} 0 1,1 ${e-.01},${n-s} L${e-.01},${n-a} A${a},${a} 0 1,0 ${e},${n-a} Z`;const c=b=>(b-90)*Math.PI/180,o=e+s*Math.cos(c(l)),d=n+s*Math.sin(c(l)),u=e+s*Math.cos(c(i)),h=n+s*Math.sin(c(i)),p=e+a*Math.cos(c(i)),m=n+a*Math.sin(c(i)),x=e+a*Math.cos(c(l)),f=n+a*Math.sin(c(l)),N=r>180?1:0;return[`M${o},${d}`,`A${s},${s} 0 ${N} 1 ${u},${h}`,`L${p},${m}`,`A${a},${a} 0 ${N} 0 ${x},${f}`,"Z"].join(" ")}function gn(){const e=xe();return e.params.compare?t(yn,{ids:[e.params.a??"",e.params.b??""]}):e.params.session?t(_n,{sessionId:e.params.session}):t(bn,{})}function bn(){const{data:e,isLoading:n,error:s,refresh:l}=q(()=>C.evalSessions()),[i,a]=_(new Set);if(n)return t(K,{type:"table"});if(s)return t(B,{message:s,onRetry:l});const r=(e==null?void 0:e.sessions)??[];if(r.length===0)return t(Y,{icon:"📊",message:"No sessions recorded yet."});const c=o=>{const d=new Set(i);d.has(o)?d.delete(o):d.add(o),a(d)};return t("div",{children:[t("div",{className:"flex items-center justify-between mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Evaluate"}),t("div",{className:"flex gap-2",children:[i.size===2&&t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-3 py-1 rounded text-sm transition-colors",onClick:()=>{const[o,d]=[...i];M(`evaluate?compare&a=${encodeURIComponent(o)}&b=${encodeURIComponent(d)}`)},children:"Compare Selected"}),i.size>0&&t("button",{className:"text-xs text-slate-400 hover:text-white",onClick:()=>a(new Set),children:["Clear (",i.size,")"]})]})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-x-auto",children:t("table",{className:"w-full text-sm",role:"table",children:[t("thead",{children:t("tr",{className:"bg-slate-800 text-slate-400 text-xs",children:[t("th",{className:"px-2 py-2 w-8"}),t("th",{className:"px-3 py-2 text-left",children:"Session"}),t("th",{className:"px-3 py-2 text-left",children:"Last Activity"}),t("th",{className:"px-3 py-2 text-right",children:"Messages"}),t("th",{className:"px-3 py-2 text-right",children:"Input Tokens"}),t("th",{className:"px-3 py-2 text-right",children:"Output Tokens"}),t("th",{className:"px-3 py-2 text-right",children:"Cost"}),t("th",{className:"px-3 py-2 text-right",children:"RAG Calls"}),t("th",{className:"px-3 py-2 text-right",children:"RAG Tokens"}),t("th",{className:"px-3 py-2 text-left",children:"Model"}),t("th",{className:"px-3 py-2 w-8"})]})}),t("tbody",{children:r.map(o=>{var d,u,h,p;return t("tr",{className:"border-t border-slate-800 hover:bg-slate-800 cursor-pointer",onClick:()=>M(`evaluate?session=${encodeURIComponent(o.sessionID)}`),children:[t("td",{className:"px-2 py-2",onClick:m=>m.stopPropagation(),children:t("input",{type:"checkbox",className:"accent-brand-500",checked:i.has(o.sessionID),onChange:()=>c(o.sessionID),"aria-label":`Select session ${o.title??o.sessionID}`})}),t("td",{className:"px-3 py-2 text-slate-200 font-mono text-xs",children:o.title??o.sessionID.slice(0,8)}),t("td",{className:"px-3 py-2 text-slate-400 text-xs",children:It(o.lastEventAt)}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:o.messageCount}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:F((((d=o.totalTokens)==null?void 0:d.input)??0)+(((u=o.totalTokens)==null?void 0:u.cacheRead)??0))}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:F(((h=o.totalTokens)==null?void 0:h.output)??0)}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:Me(o.totalCost??0)}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:o.ragContextCount??0}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:F(o.ragContextTokens??0)}),t("td",{className:"px-3 py-2 text-slate-400 text-xs",children:((p=o.models)==null?void 0:p[0])??"-"}),t("td",{className:"px-3 py-2",onClick:m=>m.stopPropagation(),children:t("button",{className:"text-slate-600 hover:text-red-400 text-xs",onClick:async()=>{if(confirm("Delete this session?"))try{await C.evalDeleteSession(o.sessionID),J("success","Session deleted"),l()}catch(m){J("error",`Delete failed: ${m.message}`)}},"aria-label":"Delete session",children:"🗑"})})]},o.sessionID)})})]})})]})}function _n({sessionId:e}){var h,p,m,x,f,N,b,v;const{data:n,isLoading:s,error:l,refresh:i}=q(()=>C.evalSession(e));if(s)return t(K,{type:"detail"});if(l)return t(B,{message:l,onRetry:i});const a=(n==null?void 0:n.summary)??n,r=(n==null?void 0:n.events)??[],c=a.toolCallCounts??{};["search_semantic","get_file_skeleton","find_usages","describe_image"].reduce((g,R)=>g+(c[R]??0),0);const d=[{label:"Input",value:(((h=a.totalTokens)==null?void 0:h.input)??0)+(((p=a.totalTokens)==null?void 0:p.cacheRead)??0),color:"#3b82f6"},{label:"Output",value:((m=a.totalTokens)==null?void 0:m.output)??0,color:"#a855f7"},{label:"RAG",value:a.ragContextTokens??0,color:"#06b6d4"},{label:"Reasoning",value:((x=a.totalTokens)==null?void 0:x.reasoning)??0,color:"#f59e0b"}].filter(g=>g.value>0),u=d.reduce((g,R)=>g+R.value,0);return t("div",{children:[t("div",{className:"flex items-center gap-3 mb-4",children:[t("button",{className:"text-sm text-slate-400 hover:text-white",onClick:()=>M("evaluate"),children:"← Back"}),t("h1",{className:"text-xl font-bold",children:a.title??((f=a.sessionID)==null?void 0:f.slice(0,12))})]}),t("div",{className:"grid grid-cols-3 lg:grid-cols-5 gap-3 mb-6",children:[t(O,{label:"Total Tokens",value:F(u)}),t(O,{label:"Input",value:F((((N=a.totalTokens)==null?void 0:N.input)??0)+(((b=a.totalTokens)==null?void 0:b.cacheRead)??0))}),t(O,{label:"Output",value:F(((v=a.totalTokens)==null?void 0:v.output)??0)}),t(O,{label:"Cost",value:Me(a.totalCost??0)}),t(O,{label:"RAG Context",value:F(a.ragContextTokens??0)})]}),t("div",{className:"flex items-center gap-6 mb-6",children:[t(vn,{segments:d,centerLabel:F(u)}),t("div",{className:"flex flex-wrap gap-3",children:d.map(g=>t("div",{className:"flex items-center gap-1.5 text-xs text-slate-400",children:[t("span",{className:"inline-block w-3 h-3 rounded-sm",style:{background:g.color}}),g.label,": ",F(g.value)," (",(g.value/u*100).toFixed(1),"%)"]},g.label))})]}),t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3 mb-6",children:[t(O,{label:"Messages",value:a.messageCount??0}),t(O,{label:"Steps",value:a.totalSteps??0}),t(O,{label:"RAG Injections",value:a.ragContextCount??0}),t(O,{label:"Avg Response",value:cn(a.avgResponseTimeMs??0)})]}),Object.keys(c).length>0&&t("div",{className:"kpi-card p-4 mb-6",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-3",children:"Tool Calls"}),t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-2",children:Object.entries(c).map(([g,R])=>t("div",{className:"flex justify-between text-xs text-slate-400",children:[t("span",{className:"font-mono",children:g}),t("span",{className:"text-white",children:String(R)})]},g))})]}),a.models&&a.models.length>0&&t("div",{className:"kpi-card p-4 mb-6",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-2",children:"Models"}),t("div",{className:"flex flex-wrap gap-2",children:a.models.map(g=>t("span",{className:"px-2 py-0.5 rounded text-xs font-mono bg-slate-800 text-slate-300",children:g},g))})]}),r.length>0&&t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-3",children:"Event Timeline"}),t("div",{className:"space-y-1 max-h-64 overflow-y-auto",children:r.map((g,R)=>t("div",{className:"flex gap-2 text-xs border-b border-slate-700/50 py-1",children:[t("span",{className:"text-slate-500 shrink-0 w-16",children:It(g.ts)}),t("span",{className:"text-slate-400",children:g.event}),g.tool&&t("span",{className:"text-slate-500 font-mono",children:g.tool}),g.toolStatus&&t("span",{className:`text-xs ${g.toolStatus==="completed"?"text-green-400":g.toolStatus==="running"?"text-amber-400":"text-slate-500"}`,children:g.toolStatus})]},R))})]})]})}function yn({ids:e}){var h,p,m,x,f,N,b,v;const[n,s]=e,{data:l,isLoading:i,error:a}=q(()=>Promise.all([C.evalCompare(n,s),C.evalTokenCompare(n,s)]),[n,s]);if(i)return t(K,{type:"chart"});if(a)return t(B,{message:a});if(!l)return null;const r=l[0],c=l[1],o=((h=c.sessionA)==null?void 0:h.savings)??0,d=((p=c.sessionB)==null?void 0:p.savings)??0,u=o>0&&d>0?"RAG saves tokens":"Mixed results";return t("div",{children:[t("div",{className:"flex items-center gap-3 mb-4",children:[t("button",{className:"text-sm text-slate-400 hover:text-white",onClick:()=>M("evaluate"),children:"← Back"}),t("h1",{className:"text-xl font-bold",children:"Session Comparison"})]}),t("div",{className:`px-4 py-3 rounded-lg mb-4 font-semibold text-sm ${o>0&&d>0?"bg-green-900/50 text-green-300 border border-green-700":"bg-amber-900/50 text-amber-300 border border-amber-700"}`,children:u}),t("div",{className:"grid grid-cols-2 gap-4",children:[t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-2",children:((m=r.sessionA)==null?void 0:m.title)??"Session A"}),t("div",{className:"space-y-1 text-sm",children:[t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Total Tokens"}),t("span",{children:F(((x=r.sessionA)==null?void 0:x.totalTokens)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Cost"}),t("span",{children:Me(((f=r.sessionA)==null?void 0:f.totalCost)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"RAG Savings"}),t("span",{className:o>0?"text-green-400":"text-red-400",children:[F(Math.abs(o))," (",o>0?"+":"",o>0?"+":"",")"]})]})]})]}),t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-2",children:((N=r.sessionB)==null?void 0:N.title)??"Session B"}),t("div",{className:"space-y-1 text-sm",children:[t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Total Tokens"}),t("span",{children:F(((b=r.sessionB)==null?void 0:b.totalTokens)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Cost"}),t("span",{children:Me(((v=r.sessionB)==null?void 0:v.totalCost)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"RAG Savings"}),t("span",{className:d>0?"text-green-400":"text-red-400",children:F(Math.abs(d))})]})]})]})]})]})}const Nn={gotcha:"text-amber-400 bg-amber-900/20",preference:"text-emerald-400 bg-emerald-900/20",decision:"text-sky-400 bg-sky-900/20","environment-constraint":"text-rose-400 bg-rose-900/20"};function wn(e){return`<span class="inline-block px-1.5 py-0.5 rounded text-xs font-mono ${Nn[e]??"text-slate-400 bg-slate-800"}">${S(e||"general")}</span>`}function kn(){const{data:e,isLoading:n,error:s,refresh:l}=q(()=>C.quirks()),[i,a]=_(null),[r,c]=_(null),[o,d]=_(!1);if(n)return t(K,{type:"card"});if(s)return t(B,{message:s,onRetry:l});const u=(e==null?void 0:e.quirks)??[],h=[...new Set(u.map(f=>f.type||"general"))],p=i?u.filter(f=>(f.type||"general")===i):u,m=async f=>{if(confirm("Delete this quirk?"))try{await C.deleteQuirk(f),J("success","Quirk deleted"),l()}catch(N){J("error",`Delete failed: ${N.message}`)}};return t("div",{children:[t("div",{className:"flex items-center justify-between mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Quirks"}),t("button",{className:"bg-slate-700 hover:bg-slate-600 text-white px-3 py-1 rounded text-sm transition-colors",onClick:async()=>{d(!0);try{const f=await C.quirkLint();c(f)}catch(f){c({error:f.message})}d(!1)},disabled:o,children:o?"Linting...":"Lint"})]}),t("div",{className:"flex gap-2 mb-4 flex-wrap",children:[t("button",{className:`px-2 py-1 rounded text-xs font-medium transition-colors ${i===null?"bg-brand-600 text-white":"bg-slate-700 text-slate-300 hover:bg-slate-600"}`,onClick:()=>a(null),children:"All"}),h.map(f=>t("button",{className:`px-2 py-1 rounded text-xs font-medium transition-colors ${i===f?"bg-brand-600 text-white":"bg-slate-700 text-slate-300 hover:bg-slate-600"}`,onClick:()=>a(f),children:f},f))]}),r&&t("div",{className:`mb-4 p-3 rounded-lg border text-sm ${r.success?"bg-green-900/30 border-green-700 text-green-300":r.error?"bg-red-900/30 border-red-700 text-red-300":"bg-amber-900/30 border-amber-700 text-amber-300"}`,children:t("pre",{className:"text-xs whitespace-pre-wrap",children:JSON.stringify(r,null,2)})}),p.length===0?t(Y,{icon:"💡",message:"No quirks stored yet."}):t("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:p.map(f=>t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 p-3 flex flex-col",children:[t("div",{className:"flex items-center justify-between mb-2",children:[t("span",{dangerouslySetInnerHTML:{__html:wn(f.type)}}),t("span",{className:`text-xs font-mono ${f.confidence>.7?"text-green-400":f.confidence>.4?"text-amber-400":"text-red-400"}`,children:[(f.confidence*100).toFixed(0),"%"]})]}),t("p",{className:"text-sm text-slate-200 mb-2 flex-1",children:S(f.content)}),f.tags&&f.tags.length>0&&t("div",{className:"flex gap-1 flex-wrap mb-2",children:f.tags.map(N=>t("span",{className:"text-xs bg-slate-800 text-slate-400 px-1.5 py-0.5 rounded",children:["#",N]},N))}),t("div",{className:"flex items-center justify-between text-xs text-slate-600 mt-auto",children:[f.sourceRef&&t("span",{className:"font-mono",children:S(f.sourceRef)}),t("span",{className:"font-mono",children:f.id})]}),t("button",{className:"self-end mt-2 text-xs text-slate-600 hover:text-red-400 transition-colors",onClick:()=>m(f.id),"aria-label":"Delete quirk",children:"Delete"})]},f.id))})]})}function Sn(){const[e,n]=_([]),[s,l]=_(!1),[i,a]=_(null),[r,c]=_(!1),o=ze(w.value,300);return E(()=>{const d=A.value.trim();if(!d){n([]);return}let u=!1;return(async()=>{var p,m;l(!0),a(null);try{const x=await C.retrieve({q:d,topK:o.topK,minScore:o.minScore,keywordWeight:o.keywordWeight,hybrid:o.hybrid?"true":"false",explain:"true"});if(u)return;if(x.status===503){a(((p=x.body)==null?void 0:p.error)??"Embedding model unavailable"),l(!1);return}c(!1);const f=((m=x.body)==null?void 0:m.results)??x.results??[];n(f);const N={query:d,params:{...o}};Re.value=[N,...Re.value.filter(b=>b.query!==d).slice(0,19)]}catch(x){u||a(x.message)}finally{u||l(!1)}})(),()=>{u=!0}},[A.value,o]),{results:e,isLoading:s,isInitializing:r,error:i,setResults:n}}function $n({explanation:e}){const{vectorScore:n,keywordScore:s,rawVectorScore:l,rawKeywordScore:i,keywordWeight:a,vectorRank:r,keywordRank:c}=e.scoreBreakdown,o=Math.max(n+s,.001),d=(n/o*100).toFixed(0),u=(s/o*100).toFixed(0);return t("div",{className:"mb-2",children:[t("div",{className:"flex items-center gap-2 text-xs mb-1",children:[t("span",{className:"text-cyan-400",title:`Vector: ${l.toFixed(3)}${r!==void 0?`, rank #${r+1}`:""}`,children:["Vector ",d,"%"]}),t("span",{className:"text-amber-400",title:`Keyword: ${i.toFixed(3)}${c!==void 0?`, rank #${c+1}`:""}`,children:["Keyword ",u,"%"]}),t("span",{className:"text-slate-500 ml-auto",children:["kw=",a.toFixed(1)]})]}),t("div",{className:"h-2 bg-slate-700 rounded-full overflow-hidden flex",children:[t("div",{className:"h-full bg-cyan-500 transition-all duration-200",style:{width:`${d}%`}}),t("div",{className:"h-full bg-amber-500 transition-all duration-200",style:{width:`${u}%`}})]})]})}function Cn(){const e=xe(),{results:n,isLoading:s,isInitializing:l,error:i}=Sn();return E(()=>{e.params.query&&(A.value=e.params.query,w.value={...w.value,topK:parseInt(e.params.topK??"10",10),minScore:parseFloat(e.params.minScore??"0.35"),keywordWeight:parseFloat(e.params.keywordWeight??"0.4"),hybrid:e.params.hybrid!=="false",pathFilter:e.params.path??"",langFilter:e.params.lang??""})},[]),E(()=>{if(A.value.trim()){const a=new URLSearchParams({query:A.value,topK:String(w.value.topK),minScore:String(w.value.minScore),keywordWeight:String(w.value.keywordWeight),hybrid:String(w.value.hybrid)});w.value.pathFilter&&a.set("path",w.value.pathFilter),w.value.langFilter&&a.set("lang",w.value.langFilter);const r=`search?${a.toString()}`;location.hash!==`#${r}`&&history.replaceState(null,"",`#${r}`)}},[A.value,w.value]),t("div",{children:[t("h1",{className:"text-2xl font-bold mb-4",children:"Semantic Search"}),t("div",{className:"flex gap-3 mb-4",children:t("input",{type:"text",value:A.value,onInput:a=>{A.value=a.target.value,le.value=[]},onKeyDown:a=>{a.key==="Enter"&&A.value.trim()},placeholder:"Search your codebase semantically... (e.g., 'how does authentication work?')",className:"flex-1 px-4 py-2 bg-slate-800 border border-slate-600 rounded-lg text-sm text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400",autoFocus:!0,"aria-label":"Semantic search query"})}),t("details",{className:"mb-4 bg-slate-800 rounded-lg border border-slate-700",children:[t("summary",{className:"px-3 py-2 text-xs text-slate-400 cursor-pointer hover:text-white font-medium",children:"Search Parameters"}),t("div",{className:"px-3 pb-3 space-y-3",children:[t(De,{label:"topK",min:1,max:25,step:1,value:w.value.topK,onChange:a=>{w.value={...w.value,topK:a}}}),t(De,{label:"minScore",min:0,max:1,step:.05,value:w.value.minScore,onChange:a=>{w.value={...w.value,minScore:a}}}),t(De,{label:"keywordWeight",min:0,max:1,step:.1,value:w.value.keywordWeight,onChange:a=>{w.value={...w.value,keywordWeight:a}}}),t("div",{className:"flex items-center gap-2",children:[t("label",{className:"text-xs text-slate-400 w-28",children:"Hybrid mode"}),t("input",{type:"checkbox",checked:w.value.hybrid,onChange:a=>{w.value={...w.value,hybrid:a.target.checked}},className:"accent-brand-500"})]})]})]}),l&&t("div",{className:"text-center py-10 text-slate-400",children:[t("span",{className:"animate-spin inline-block mr-2",children:"⟳"}),"Initializing embedding model..."]}),i&&t(B,{message:i}),!s&&!i&&A.value.trim()&&n.length===0&&t("div",{className:"text-center py-16 text-slate-500",children:[t("div",{className:"text-4xl mb-2",children:"🔍"}),t("div",{children:['No results found for "',S(A.value),'"']})]}),!s&&!i&&!A.value.trim()&&t("div",{className:"text-center py-16 text-slate-500",children:[t("div",{className:"text-4xl mb-2",children:"🔍"}),t("div",{children:"Enter a query to search your codebase"}),Re.value.length>0&&t("div",{className:"mt-6",children:[t("p",{className:"text-xs text-slate-600 mb-2",children:"Recent queries:"}),t("div",{className:"flex flex-wrap gap-2 justify-center",children:Re.value.slice(0,10).map((a,r)=>t("button",{className:"px-2 py-1 bg-slate-800 rounded text-xs text-slate-400 hover:text-white hover:bg-slate-700 transition-colors",onClick:()=>{A.value=a.query},children:S(a.query)},r))})]})]}),n.length>0&&t("div",{className:"space-y-3",children:[t("div",{className:"flex items-center justify-between text-sm text-slate-400 mb-2",children:[t("span",{children:[n.length," result",n.length!==1?"s":""]}),s&&t("span",{className:"text-xs text-brand-400 animate-pulse",children:"Searching..."})]}),n.map(a=>t(Ln,{result:a},a.chunk.id))]}),s&&n.length===0&&t("div",{className:"text-center py-10 text-slate-400",children:[t("span",{className:"animate-spin inline-block mr-2",children:"⟳"}),"Searching..."]})]})}function Ln({result:e}){var l,i;const n=e.chunk,s=e.score;return t("div",{className:"bg-slate-800 rounded-lg p-4 border border-slate-700 hover:border-brand-500/50 transition-colors cursor-pointer",onClick:()=>M(`chunks?id=${encodeURIComponent(n.id)}`),children:[t("div",{className:"flex items-center justify-between mb-2",children:[t("div",{className:"flex items-center gap-2 min-w-0",children:[t("span",{className:"text-sm text-yellow-400 font-mono truncate",children:[S(n.filePath),":",n.startLine,"-",n.endLine]}),t("span",{dangerouslySetInnerHTML:{__html:ce(n.language)}})]}),t("span",{className:"text-lg font-bold shrink-0 ml-2",style:{color:Tn(s)},children:s.toFixed(2)})]}),e.explanation&&t($n,{explanation:e.explanation}),((i=(l=e.explanation)==null?void 0:l.matchedTerms)==null?void 0:i.length)>0&&t("div",{className:"flex gap-1 flex-wrap mb-2",children:e.explanation.matchedTerms.map(a=>t("span",{className:"text-xs bg-amber-500/20 text-amber-300 px-1.5 py-0.5 rounded",children:S(a)},a))}),n.description&&t("p",{className:"text-sm text-slate-400 mb-2 line-clamp-2",children:S(n.description)}),t("pre",{className:"text-xs overflow-x-auto max-h-32 rounded bg-slate-900/50 p-2",children:t("code",{children:S(n.content??"").slice(0,500)})})]})}function Tn(e){return e>=.8?"#22c55e":e>=.6?"#06b6d4":e>=.4?"#f59e0b":"#ef4444"}function De({label:e,min:n,max:s,step:l,value:i,onChange:a}){return t("div",{className:"flex items-center gap-3",children:[t("label",{className:"text-xs text-slate-400 w-28 shrink-0",children:e}),t("input",{type:"range",min:n,max:s,step:l,value:i,onInput:r=>a(parseFloat(r.target.value)),className:"flex-1 accent-brand-500"}),t("span",{className:"text-xs text-slate-300 font-mono w-12 text-right",children:i})]})}function In(){var o;const n=((o=xe().params.ids)==null?void 0:o.split(",").filter(Boolean))??[],[s,l]=_([]),[i,a]=_(!0),[r,c]=_(null);return E(()=>{if(n.length<2){c("Select 2-3 chunks to compare."),a(!1);return}C.compare(n).then(d=>{var u;l(((u=d==null?void 0:d.body)==null?void 0:u.chunks)??(d==null?void 0:d.chunks)??[]),a(!1)}).catch(d=>{c(d.message),a(!1)})},[n.join(",")]),i?t(K,{type:"detail"}):r?t(B,{message:r}):s.length<2?t(Y,{icon:"📋",message:"Select 2-3 chunks from the Chunks view to compare them."}):t("div",{children:[t("div",{className:"flex items-center justify-between mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Chunk Comparison"}),t("button",{className:"text-sm text-slate-400 hover:text-white transition-colors",onClick:()=>M("chunks"),children:"← Back to Chunks"})]}),t("div",{className:`grid gap-4 ${s.length===2?"grid-cols-2":"grid-cols-3"}`,children:s.map((d,u)=>t(Pn,{chunk:d,index:u,baseChunk:u>0?s[0]:void 0},d.id))})]})}function Pn({chunk:e,index:n,baseChunk:s}){const l=e.content.split(`
|
|
2
|
-
`),i=(s==null?void 0:s.content.split(`
|
|
3
|
-
`))??[];return t("div",{className:"bg-slate-800 rounded-lg border border-slate-700 overflow-hidden flex flex-col",children:[t("div",{className:"p-3 border-b border-slate-700 bg-slate-800/80",children:[t("div",{className:"flex items-center justify-between mb-1",children:[t("span",{className:"text-sm font-mono text-brand-400 truncate mr-2",children:[S(e.filePath),":",e.startLine,"-",e.endLine]}),t("span",{className:"shrink-0",dangerouslySetInnerHTML:{__html:ce(e.language)}})]}),e.description&&t("p",{className:"text-xs text-slate-400 truncate",children:S(e.description)})]}),t("div",{className:"overflow-x-auto flex-1 max-h-[70vh]",children:t("table",{className:"w-full text-xs font-mono border-collapse",children:t("tbody",{children:l.map((a,r)=>{const c=(e.startLine??1)+r,o=i[r]===void 0?"bg-green-900/30":a===""&&i[r]!==""?"bg-red-900/30":a!==i[r]?"bg-amber-900/20":"";return t("tr",{className:o,children:[t("td",{className:"text-right text-slate-600 select-none px-2 w-10 border-r border-slate-700 align-top",children:c}),t("td",{className:"px-3 py-0 whitespace-pre-wrap break-all",children:S(a)||" "})]},r)})})})}),t("div",{className:"px-3 py-1.5 bg-slate-900 border-t border-slate-700 text-xs text-slate-500",children:["Chunk ",n+1,n===0&&t("span",{className:"text-slate-600 ml-1",children:"(reference)"})]})]})}function Rn(){var a;const{data:e,isLoading:n,error:s,refresh:l}=q(()=>C.config());if(n)return t(K,{type:"card"});if(s)return t(B,{message:s,onRetry:l});const i=((a=e==null?void 0:e.body)==null?void 0:a.config)??(e==null?void 0:e.config);return i?t("div",{children:[t("h1",{className:"text-2xl font-bold mb-6",children:"Configuration"}),t("p",{className:"text-sm text-slate-400 mb-4",children:["Effective configuration from ",t("code",{className:"text-brand-400",children:"opencode-rag.json"}),". API keys are redacted."]}),t("div",{className:"space-y-4",children:Object.entries(i).map(([r,c])=>t("details",{className:"bg-slate-800 rounded-lg border border-slate-700",open:!0,children:[t("summary",{className:"px-4 py-2 cursor-pointer hover:bg-slate-700 font-mono text-sm font-semibold capitalize text-slate-300",children:r.replace(/([A-Z])/g," $1")}),t("div",{className:"px-4 pb-3",children:typeof c=="object"&&c!==null?Object.entries(c).map(([o,d])=>t("div",{className:"flex justify-between py-1 border-b border-slate-700/50 text-sm",children:[t("span",{className:"text-slate-400 font-mono",children:o}),t("span",{className:"text-slate-200 font-mono text-xs text-right ml-4",children:Mn(d)})]},o)):t("div",{className:"flex justify-between py-1 text-sm",children:t("span",{className:"text-slate-200 font-mono",children:String(c)})})})]},r))})]}):t(Y,{icon:"⚙",message:"No configuration available."})}function Mn(e){return e===null?"null":e===void 0?"undefined":typeof e=="boolean"?e?"true":"false":Array.isArray(e)?`[${e.join(", ")}]`:typeof e=="object"?JSON.stringify(e).slice(0,150):String(e)}function En(e,n){for(var s in n)e[s]=n[s];return e}function it(e,n){for(var s in e)if(s!=="__source"&&!(s in n))return!0;for(var l in n)if(l!=="__source"&&e[l]!==n[l])return!0;return!1}function ot(e,n){this.props=e,this.context=n}(ot.prototype=new re).isPureReactComponent=!0,ot.prototype.shouldComponentUpdate=function(e,n){return it(this.props,e)||it(this.state,n)};var ct=P.__b;P.__b=function(e){e.type&&e.type.__f&&e.ref&&(e.props.ref=e.ref,e.ref=null),ct&&ct(e)};var jn=P.__e;P.__e=function(e,n,s,l){if(e.then){for(var i,a=n;a=a.__;)if((i=a.__c)&&i.__c)return n.__e==null&&(n.__e=s.__e,n.__k=s.__k||[]),i.__c(e,n)}jn(e,n,s,l)};var dt=P.unmount;function Pt(e,n,s){return e&&(e.__c&&e.__c.__H&&(e.__c.__H.__.forEach(function(l){typeof l.__c=="function"&&l.__c()}),e.__c.__H=null),(e=En({},e)).__c!=null&&(e.__c.__P===s&&(e.__c.__P=n),e.__c.__e=!0,e.__c=null),e.__k=e.__k&&e.__k.map(function(l){return Pt(l,n,s)})),e}function Rt(e,n,s){return e&&s&&(e.__v=null,e.__k=e.__k&&e.__k.map(function(l){return Rt(l,n,s)}),e.__c&&e.__c.__P===n&&(e.__e&&s.appendChild(e.__e),e.__c.__e=!0,e.__c.__P=s)),e}function Ue(){this.__u=0,this.o=null,this.__b=null}function Mt(e){var n=e.__&&e.__.__c;return n&&n.__a&&n.__a(e)}function ke(){this.i=null,this.l=null}P.unmount=function(e){var n=e.__c;n&&(n.__z=!0),n&&n.__R&&n.__R(),n&&32&e.__u&&(e.type=null),dt&&dt(e)},(Ue.prototype=new re).__c=function(e,n){var s=n.__c,l=this;l.o==null&&(l.o=[]),l.o.push(s);var i=Mt(l.__v),a=!1,r=function(){a||l.__z||(a=!0,s.__R=null,i?i(o):o())};s.__R=r;var c=s.__P;s.__P=null;var o=function(){if(!--l.__u){if(l.state.__a){var d=l.state.__a;l.__v.__k[0]=Rt(d,d.__c.__P,d.__c.__O)}var u;for(l.setState({__a:l.__b=null});u=l.o.pop();)u.__P=c,u.forceUpdate()}};l.__u++||32&n.__u||l.setState({__a:l.__b=l.__v.__k[0]}),e.then(r,r)},Ue.prototype.componentWillUnmount=function(){this.o=[]},Ue.prototype.render=function(e,n){if(this.__b){if(this.__v.__k){var s=document.createElement("div"),l=this.__v.__k[0].__c;this.__v.__k[0]=Pt(this.__b,s,l.__O=l.__P)}this.__b=null}var i=n.__a&&Ge(pe,null,e.fallback);return i&&(i.__u&=-33),[Ge(pe,null,n.__a?null:e.children),i]};var ut=function(e,n,s){if(++s[1]===s[0]&&e.l.delete(n),e.props.revealOrder&&(e.props.revealOrder[0]!=="t"||!e.l.size))for(s=e.i;s;){for(;s.length>3;)s.pop()();if(s[1]<s[0])break;e.i=s=s[2]}};(ke.prototype=new re).__a=function(e){var n=this,s=Mt(n.__v),l=n.l.get(e);return l[0]++,function(i){var a=function(){n.props.revealOrder?(l.push(i),ut(n,e,l)):i()};s?s(a):a()}},ke.prototype.render=function(e){this.i=null,this.l=new Map;var n=He(e.children);e.revealOrder&&e.revealOrder[0]==="b"&&n.reverse();for(var s=n.length;s--;)this.l.set(n[s],this.i=[1,0,this.i]);return e.children},ke.prototype.componentDidUpdate=ke.prototype.componentDidMount=function(){var e=this;this.l.forEach(function(n,s){ut(e,s,n)})};var Fn=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.element")||60103,An=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,On=/^on(Ani|Tra|Tou|BeforeInp|Compo)/,Dn=/[A-Z0-9]/g,Un=typeof document<"u",Hn=function(e){return(typeof Symbol<"u"&&typeof Symbol()=="symbol"?/fil|che|rad/:/fil|che|ra/).test(e)};re.prototype.isReactComponent=!0,["componentWillMount","componentWillReceiveProps","componentWillUpdate"].forEach(function(e){Object.defineProperty(re.prototype,e,{configurable:!0,get:function(){return this["UNSAFE_"+e]},set:function(n){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:n})}})});var ht=P.event;P.event=function(e){return ht&&(e=ht(e)),e.persist=function(){},e.isPropagationStopped=function(){return this.cancelBubble},e.isDefaultPrevented=function(){return this.defaultPrevented},e.nativeEvent=e};var qn={configurable:!0,get:function(){return this.class}},ft=P.vnode;P.vnode=function(e){typeof e.type=="string"&&function(n){var s=n.props,l=n.type,i={},a=l.indexOf("-")==-1;for(var r in s){var c=s[r];if(!(r==="value"&&"defaultValue"in s&&c==null||Un&&r==="children"&&l==="noscript"||r==="class"||r==="className")){var o=r.toLowerCase();r==="defaultValue"&&"value"in s&&s.value==null?r="value":r==="download"&&c===!0?c="":o==="translate"&&c==="no"?c=!1:o[0]==="o"&&o[1]==="n"?o==="ondoubleclick"?r="ondblclick":o!=="onchange"||l!=="input"&&l!=="textarea"||Hn(s.type)?o==="onfocus"?r="onfocusin":o==="onblur"?r="onfocusout":On.test(r)&&(r=o):o=r="oninput":a&&An.test(r)?r=r.replace(Dn,"-$&").toLowerCase():c===null&&(c=void 0),o==="oninput"&&i[r=o]&&(r="oninputCapture"),i[r]=c}}l=="select"&&(i.multiple&&Array.isArray(i.value)&&(i.value=He(s.children).forEach(function(d){d.props.selected=i.value.indexOf(d.props.value)!=-1})),i.defaultValue!=null&&(i.value=He(s.children).forEach(function(d){d.props.selected=i.multiple?i.defaultValue.indexOf(d.props.value)!=-1:i.defaultValue==d.props.value}))),s.class&&!s.className?(i.class=s.class,Object.defineProperty(i,"className",qn)):s.className&&(i.class=i.className=s.className),n.props=i}(e),e.$$typeof=Fn,ft&&ft(e)};var mt=P.__r;P.__r=function(e){mt&&mt(e),e.__c};var pt=P.diffed;P.diffed=function(e){pt&&pt(e);var n=e.props,s=e.__e;s!=null&&e.type==="textarea"&&"value"in n&&n.value!==s.value&&(s.value=n.value==null?"":n.value)};function Kn({points:e,width:n=800,height:s=600,onPointClick:l,renderTooltip:i}){const a=Ce(null),[r,c]=_({x:0,y:0,scale:1}),[o,d]=_(null),[u,h]=_(!1),p=Ce({x:0,y:0});E(()=>{const b=a.current;if(!b)return;const v=b.getContext("2d");if(!v)return;const g=window.devicePixelRatio||1;b.width=n*g,b.height=s*g,v.scale(g,g),v.clearRect(0,0,n,s),v.save(),v.translate(r.x,r.y),v.scale(r.scale,r.scale);for(const R of e){const _e=R.x*n,ye=R.y*s,y=(R.radius??3)*(R.highlighted?2:1);v.beginPath(),v.arc(_e,ye,y,0,Math.PI*2),v.fillStyle=R.color,v.globalAlpha=R.highlighted?1:.6,v.fill(),R.highlighted&&(v.strokeStyle="#22d3ee",v.lineWidth=2,v.stroke())}v.restore()},[e,r,n,s]);const m=b=>{b.preventDefault();const v=b.deltaY>0?.9:1.1;c(g=>({...g,scale:Math.max(.5,Math.min(10,g.scale*v))}))},x=b=>{h(!0),p.current={x:b.clientX-r.x,y:b.clientY-r.y}},f=b=>{u&&c(v=>({...v,x:b.clientX-p.current.x,y:b.clientY-p.current.y}))},N=()=>h(!1);return t("div",{className:"relative overflow-hidden rounded-lg border border-slate-700 bg-slate-900",style:{width:n,height:s},children:[t("canvas",{ref:a,className:"absolute inset-0 cursor-grab active:cursor-grabbing",onMouseDown:x,onMouseMove:f,onMouseUp:N,onMouseLeave:N,onWheel:m}),t("svg",{width:n,height:s,className:"absolute inset-0 pointer-events-none",children:e.map(b=>t("circle",{cx:b.x*n*r.scale+r.x,cy:b.y*s*r.scale+r.y,r:8,fill:"transparent",className:"pointer-events-auto cursor-pointer",onMouseEnter:()=>d(b),onMouseLeave:()=>d(null),onClick:()=>l==null?void 0:l(b.id)},b.id))}),o&&i&&t("div",{className:"absolute bg-slate-800 border border-slate-600 rounded-lg p-3 shadow-xl text-sm z-10 pointer-events-none",style:{left:Math.min(o.x*n*r.scale+r.x+12,n-200),top:Math.min(o.y*s*r.scale+r.y-12,s-80)},children:i(o)}),r.scale!==1&&t("button",{className:"absolute bottom-3 right-3 px-2 py-1 bg-slate-700 hover:bg-slate-600 rounded text-xs text-white transition-colors z-20",onClick:()=>c({x:0,y:0,scale:1}),children:"Reset zoom"})]})}function me(e,n){return Math.sqrt((e.x-n.x)**2+(e.y-n.y)**2)}function Bn(e,n=8,s=20){const l=e.length;if(l<=n)return e.map((r,c)=>c);const i=new Array(l).fill(0),a=[];a.push(e[Math.floor(Math.random()*l)]);for(let r=1;r<n;r++){const c=e.map(u=>Math.min(...a.map(h=>me(u,h)))),o=c.reduce((u,h)=>u+h*h,0);let d=Math.random()*o;for(let u=0;u<l;u++)if(d-=c[u]*c[u],d<=0){a.push(e[u]);break}}for(let r=0;r<s;r++){for(let o=0;o<l;o++){let d=0,u=me(e[o],a[0]);for(let h=1;h<a.length;h++){const p=me(e[o],a[h]);p<u&&(u=p,d=h)}i[o]=d}const c=a.map(()=>({x:0,y:0,count:0}));for(let o=0;o<l;o++){const d=i[o];c[d].x+=e[o].x,c[d].y+=e[o].y,c[d].count++}a.forEach((o,d)=>{c[d].count>0&&(o.x=c[d].x/c[d].count,o.y=c[d].y/c[d].count)})}return i}function Wn(e,n,s){const l=s.map((a,r)=>{const o=e.filter((h,p)=>n[p]===r).map(h=>me(h,a)),d=o.reduce((h,p)=>h+p,0)/o.length,u=o.reduce((h,p)=>h+(p-d)**2,0)/o.length;return Math.sqrt(u)}),i=new Set;for(let a=0;a<e.length;a++){const r=n[a];me(e[a],s[r])>2*(l[r]??0)&&i.add(a)}return i}const ae=["#3b82f6","#ef4444","#22c55e","#f59e0b","#a855f7","#06b6d4","#ec4899","#84cc16"];function Vn(){var _e,ye;const{data:e,isLoading:n,error:s,refresh:l}=q(()=>C.embeddingProj(5e3)),[i,a]=_("language"),[r,c]=_(!1),[o,d]=_(!1),[u,h]=_(!1),[p,m]=_(new Set),[x,f]=_(null),[N,b]=_(new Set),v=((_e=e==null?void 0:e.body)==null?void 0:_e.points)??(e==null?void 0:e.points)??[],g=((ye=e==null?void 0:e.body)==null?void 0:ye.totalChunks)??(e==null?void 0:e.totalChunks)??0;if(E(()=>{u&&le.value.length>0?m(new Set(le.value.map(y=>y.chunk.id))):m(new Set)},[u,le.value]),n)return t(K,{type:"chart"});if(s)return t(B,{message:s,onRetry:l});if(v.length===0)return t(Y,{icon:"🌐",message:"No embedding data available. Index some files first."});E(()=>{if(r&&v.length>0){const y=Math.min(8,Math.max(2,Math.floor(v.length/20))),H=Bn(v,y);if(f(H),o){const V=[];for(let ee=0;ee<y;ee++){const te=v.filter((Q,W)=>H[W]===ee);te.length>0&&V.push({x:te.reduce((Q,W)=>Q+W.x,0)/te.length,y:te.reduce((Q,W)=>Q+W.y,0)/te.length})}b(Wn(v,H,V))}}else f(null),b(new Set)},[r,o,v]);const R=v.map((y,H)=>{let V;if(i==="language")V=be(y.language)==="text-slate-400"?"#94a3b8":Gn(y.language);else if(i==="file"){const W=y.filePath.split("/")[0]??"root";V=ae[zn(W)%ae.length]}else{const W=(x==null?void 0:x[H])??0;V=ae[W%ae.length]}const ee=N.has(H),Q=p.has(y.id);return{id:y.id,x:y.x,y:y.y,color:Q?"#22d3ee":ee?"#f97316":V,label:`${y.filePath}:${y.startLine}-${y.endLine} [${y.language}]`,radius:Q?6:ee?5:3,highlighted:Q}});return t("div",{children:[t("h1",{className:"text-2xl font-bold mb-4",children:"Embedding Space Explorer"}),t("div",{className:"flex flex-wrap gap-3 mb-4 items-center",children:[t("label",{className:"text-xs text-slate-400",children:"Color by:"}),t("select",{className:"bg-slate-800 border border-slate-600 rounded text-xs text-slate-200 px-2 py-1",value:i,onChange:y=>a(y.target.value),children:[t("option",{value:"language",children:"Language"}),t("option",{value:"file",children:"File"}),t("option",{value:"cluster",children:"Cluster"})]}),t("label",{className:"flex items-center gap-1.5 text-xs text-slate-400",children:[t("input",{type:"checkbox",className:"accent-brand-500",checked:r,onChange:y=>c(y.target.checked)}),"Clusters"]}),t("label",{className:"flex items-center gap-1.5 text-xs text-slate-400",children:[t("input",{type:"checkbox",className:"accent-brand-500",checked:o,onChange:y=>d(y.target.checked)}),"Outliers"]}),le.value.length>0&&t("label",{className:"flex items-center gap-1.5 text-xs text-slate-400",children:[t("input",{type:"checkbox",className:"accent-brand-500",checked:u,onChange:y=>h(y.target.checked)}),"Search overlay (",le.value.length," results)"]})]}),i==="cluster"&&x&&t("div",{className:"flex flex-wrap gap-2 mb-3 text-xs",children:Array.from(new Set(x)).sort().map(y=>t("span",{className:"flex items-center gap-1 text-slate-400",children:[t("span",{className:"inline-block w-2 h-2 rounded-full",style:{background:ae[y%ae.length]}}),"Cluster ",y+1]},y))}),t(Kn,{points:R,width:900,height:600,onPointClick:y=>M(`chunks?id=${encodeURIComponent(y)}`),renderTooltip:y=>{const H=v.find(V=>V.id===y.id);return t("div",{children:[t("div",{className:"text-yellow-400 font-mono text-xs",children:S(y.label)}),(H==null?void 0:H.description)&&t("div",{className:"text-slate-400 text-xs mt-1",children:S(an(H.description,80))})]})}}),t("p",{className:"text-xs text-slate-500 mt-2",children:[R.length," of ",g," chunks displayed",R.length<g&&" (chunks without embeddings omitted)"]})]})}function zn(e){let n=0;for(let s=0;s<e.length;s++)n=n*31+e.charCodeAt(s)|0;return Math.abs(n)}function Gn(e){return{typescript:"#60a5fa",javascript:"#facc15",python:"#4ade80",java:"#f87171",go:"#22d3ee",rust:"#fb923c",ruby:"#f472b6",csharp:"#a78bfa",cpp:"#818cf8",c:"#9ca3af",markdown:"#d1d5db",html:"#fdba74",css:"#60a5fa",json:"#fde047",kotlin:"#c084fc",swift:"#fb923c",tex:"#34d399",sql:"#67e8f9",text:"#94a3b8",image:"#a78bfa",quirk:"#fbbf24"}[e]??"#94a3b8"}const Qn=[{view:"dashboard",label:"Dashboard",icon:"📊"},{view:"search",label:"Search",icon:"🔍"},{view:"embeddings",label:"Embeddings",icon:"🌐"},{view:"chunks",label:"Chunks",icon:"🧩"},{view:"files",label:"Files",icon:"📄"},{view:"evaluate",label:"Evaluate",icon:"📈"},{view:"quirks",label:"Quirks",icon:"💡"}];function Zn(){Jt(),Xt();const e=xe();Ae.value=e.view;const n=()=>{we.value=!we.value};return t("div",{className:"h-screen flex flex-col overflow-hidden",children:[t("header",{className:"flex items-center gap-3 px-4 py-2 border-b shrink-0",style:{borderColor:"var(--border)"},children:[t("h1",{className:"text-lg font-bold shrink-0",style:{color:"var(--accent)"},children:"OpenCodeRAG"}),t("nav",{className:"flex gap-1 flex-1",role:"navigation","aria-label":"Main navigation",children:Qn.map(s=>t("button",{id:`nav-${s.view}`,className:`nav-btn ${Ae.value===s.view?"active":""}`,onClick:()=>window.location.hash=s.view,role:"tab","aria-selected":Ae.value===s.view,children:[s.icon," ",s.label]},s.view))}),t(ln,{}),t(en,{}),t("button",{className:"p-2 rounded-lg transition-colors hidden lg:block",style:{color:"var(--text-muted)"},onClick:n,"aria-label":"Toggle file tree",title:"Toggle file tree",children:"☰"}),t("button",{className:"p-2 rounded-lg transition-colors lg:hidden",style:{color:"var(--text-muted)"},onClick:n,"aria-label":"Toggle file tree",title:"Toggle file tree",children:"☰"})]}),t("div",{className:"flex flex-1 overflow-hidden",children:[we.value&&t(pe,{children:[t("div",{className:"fixed inset-0 z-30 lg:hidden",style:{background:"rgba(0,0,0,0.5)"},onClick:()=>{we.value=!1}}),t("aside",{className:"w-64 overflow-y-auto shrink-0 border-r z-40 fixed lg:relative inset-y-0 left-0",style:{background:"var(--bg-secondary)",borderColor:"var(--border)"},role:"tree","aria-label":"File tree",children:t(rn,{})})]}),t("main",{className:"flex-1 overflow-y-auto p-6",id:"main-content",tabIndex:-1,children:[e.view==="dashboard"&&t(hn,{}),e.view==="search"&&t(Cn,{}),e.view==="embeddings"&&t(Vn,{}),e.view==="compare"&&t(In,{}),e.view==="chunks"&&t(fn,{}),e.view==="files"&&t(pn,{}),e.view==="evaluate"&&t(gn,{}),e.view==="quirks"&&t(kn,{}),e.view==="config"&&t(Rn,{})]})]}),t(Yt,{})]})}jt(t(Zn,{}),document.getElementById("app"));
|