@stacknet/rackutils 0.3.1 → 0.3.2

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.
@@ -1,10 +1,11 @@
1
- 'use strict';var react=require('react'),lucideReact=require('lucide-react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');function k(...r){return tailwindMerge.twMerge(clsx.clsx(r))}async function v(r,e,i,s){let o={"Content-Type":"application/json",...i?.headers};s&&(o.Authorization=`Bearer ${s}`);let c=await fetch(`${r}${e}`,{...i,headers:o});if(!c.ok){let t=`HTTP ${c.status}`;try{let a=await c.json();a.error&&(t=a.error);}catch{}throw new Error(t)}return c.json()}function $(r){let e=r.indexOf(":");return {mode:r.slice(0,e),cid:r.slice(e+1)}}function P(r){let e=r.apiBaseUrl,i=r.authorMid,s=r.ownerMid,o=r.apiKey,c=r.stacknetUrl||r.apiBaseUrl;return react.useMemo(()=>({async listRepos(t,a){let l=new URLSearchParams;(t||s)&&l.set("owner",t||s),a?.limit&&l.set("limit",String(a.limit)),a?.cursor&&l.set("cursor",a.cursor);let d=l.toString()?`?${l}`:"",u=await v(e,`/api/rack/repos${d}`,void 0,o);return {items:u.repos||[],pagination:u.pagination||{total:(u.repos||[]).length,limit:50,has_more:false,next_cursor:null}}},async initRepo(t){return v(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...t,owner_mid:s})},o)},async push(t,a){return v(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...a,author_mid:i})},o)},async getTree(t,a="main"){let l=await v(e,`/api/rack/${t}/tree/${a}`,void 0,o);return {tree:l.tree,commit_cid:l.commit_cid}},async getBlob(t,a){return (await v(e,`/api/rack/${t}/blob/${a}`,void 0,o)).content},async getLog(t,a,l){let d=new URLSearchParams;a&&d.set("ref",a),l&&d.set("max_count",String(l));let u=d.toString()?`?${d}`:"";return (await v(e,`/api/rack/${t}/log${u}`,void 0,o)).commits||[]},async getBranches(t){return (await v(e,`/api/rack/${t}/branches`,void 0,o)).branches||[]},async createBranch(t,a,l){return v(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:a,from_ref:l})},o)},async merge(t,a,l){return v(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:a,target_branch:l})},o)},async getDiff(t,a,l){return (await v(e,`/api/rack/${t}/diff/${a}/${l}`,void 0,o)).diff?.entries||[]},async starRepo(t){return v(e,`/api/rack/${t}/star`,{method:"POST"},o)},async unstarRepo(t){return v(e,`/api/rack/${t}/star`,{method:"DELETE"},o)},async getStarInfo(t){return v(e,`/api/rack/${t}/stars`,void 0,o)},async getSkillStats(t){let a={meta:null,tokenCount:null,usageCount:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return a;if(l.entries["META.json"]){let p=$(l.entries["META.json"]).cid,g=await this.getBlob(t,p);a.meta=JSON.parse(g);}let d=0,u=Object.values(l.entries).map(async p=>{try{let g=$(p).cid,f=await this.getBlob(t,g);d+=f.length;}catch{}});await Promise.all(u),d>0&&(a.tokenCount=Math.ceil(d/4)),a.meta?.skill_id&&(a.usageCount=await this.getSkillUsageCount(a.meta.skill_id));}catch{}return a},async getSkillUsageCount(t){try{let a=await fetch(`${c}/v1/skills/${encodeURIComponent(t)}`);if(a.ok){let d=await a.json();return d.usage_count??d.usageCount??null}let l=await fetch(`${c}/v1/skills?scope=public`);if(l.ok){let u=((await l.json()).skills||[]).find(p=>p.name===t||p.id===t);if(u)return u.usage_count??u.usageCount??0}return 0}catch{return null}},async getTensorStats(t){let a={meta:null,sizeMB:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return a;if(l.entries["TENSOR_META.json"]){let d=$(l.entries["TENSOR_META.json"]).cid,u=await this.getBlob(t,d);a.meta=JSON.parse(u),a.sizeMB=a.meta?.tensor_size_mb??null;}}catch{}return a},async getNetworkStats(){try{return (await v(e,"/api/rack/stats",void 0,o)).stats||null}catch{return null}},async getTrending(t=5,a=1,l){try{let d=new URLSearchParams({limit:String(t),days:String(a)});l&&d.set("cursor",l);let u=await v(e,`/api/rack/trending?${d}`,void 0,o);return {items:u.trending||[],pagination:u.pagination||{total:(u.trending||[]).length,limit:t,has_more:!1,next_cursor:null}}}catch{return {items:[],pagination:{total:0,limit:t,has_more:false,next_cursor:null}}}}}),[e,i,s,o,c])}function Z(r){let e=P(r),i=react.useRef(e);i.current=e;let[s,o]=react.useState([]),[c,t]=react.useState(true),[a,l]=react.useState(null),d=react.useRef(true),u=react.useRef(null),p=react.useCallback(async()=>{u.current?.abort();let g=new AbortController;u.current=g;try{d.current&&(t(!0),l(null));let f=await i.current.listRepos();d.current&&!g.signal.aborted&&o(f.items);}catch(f){d.current&&!g.signal.aborted&&l(f instanceof Error?f.message:"Failed to load repos");}finally{d.current&&!g.signal.aborted&&t(false);}},[]);return react.useEffect(()=>(d.current=true,p(),()=>{d.current=false,u.current?.abort();}),[p]),{repos:s,loading:c,error:a,refresh:p}}function ge(r){return Object.entries(r).map(([e,i])=>{let s=i.indexOf(":"),o=s>0?i.slice(0,s):"100644",c=s>0?i.slice(s+1):i;return {path:e,mode:o,cid:c,isDir:o==="040000"}}).sort((e,i)=>e.isDir!==i.isDir?e.isDir?-1:1:e.path.localeCompare(i.path))}function W(r,e,i="main"){let s=P(r),[o,c]=react.useState([]),[t,a]=react.useState(false),[l,d]=react.useState(null),u=react.useRef(true),p=react.useCallback(async()=>{if(e)try{u.current&&(a(!0),d(null));let{tree:f}=await s.getTree(e,i);u.current&&c(ge(f.entries));}catch(f){u.current&&d(f instanceof Error?f.message:"Failed to load tree");}finally{u.current&&a(false);}},[s,e,i]);react.useEffect(()=>(u.current=true,p(),()=>{u.current=false;}),[p]);let g=react.useCallback(async f=>{if(!e)throw new Error("No repo selected");return s.getBlob(e,f)},[s,e]);return {entries:o,loading:t,error:l,refresh:p,getFileContent:g}}var pe=/^(https?:\/\/|mailto:|\/[^/])/i;function he(r){let e=r.trim();return pe.test(e)?e:null}function M(r){let e=[],i=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,s=0,o,c=0;for(;(o=i.exec(r))!==null;){o.index>s&&e.push(r.slice(s,o.index));let t=`i${c++}`;if(o[1])e.push(jsxRuntime.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[0.85em] font-mono text-pink-400",children:o[1].slice(1,-1)},t));else if(o[2])e.push(jsxRuntime.jsx("strong",{children:o[3]},t));else if(o[4])e.push(jsxRuntime.jsx("em",{children:o[5]},t));else if(o[6])e.push(jsxRuntime.jsx("em",{children:o[7]},t));else if(o[8]){let a=he(o[10]);a?e.push(jsxRuntime.jsx("a",{href:a,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:o[9]},t)):e.push(o[9]);}s=o.index+o[0].length;}return s<r.length&&e.push(r.slice(s)),e.length>0?e:[r]}function xe(r){let e=r.split(`
2
- `),i=[],s=0;for(;s<e.length;){let o=e[s];if(o.trim()===""){s++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(o.trim())){i.push({type:"hr"}),s++;continue}let c=o.match(/^(#{1,6})\s+(.+)/);if(c){i.push({type:"heading",level:c[1].length,content:c[2]}),s++;continue}if(o.trim().startsWith("```")){let a=o.trim().slice(3).trim(),l=[];for(s++;s<e.length&&!e[s].trim().startsWith("```");)l.push(e[s]),s++;i.push({type:"code",content:l.join(`
3
- `),lang:a||void 0}),s++;continue}if(/^\s*[-*+]\s/.test(o)){let a=[];for(;s<e.length&&/^\s*[-*+]\s/.test(e[s]);)a.push(e[s].replace(/^\s*[-*+]\s+/,"")),s++;i.push({type:"ul",items:a});continue}if(/^\s*\d+[.)]\s/.test(o)){let a=[];for(;s<e.length&&/^\s*\d+[.)]\s/.test(e[s]);)a.push(e[s].replace(/^\s*\d+[.)]\s+/,"")),s++;i.push({type:"ol",items:a});continue}let t=[];for(;s<e.length&&e[s].trim()!==""&&!e[s].match(/^#{1,6}\s/)&&!e[s].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[s])&&!/^\s*\d+[.)]\s/.test(e[s]);)t.push(e[s]),s++;t.length>0&&i.push({type:"paragraph",content:t.join(" ")});}return i}var ve={1:"text-2xl font-bold mt-6 mb-3",2:"text-xl font-bold mt-5 mb-2",3:"text-lg font-semibold mt-4 mb-2",4:"text-base font-semibold mt-3 mb-1",5:"text-sm font-semibold mt-2 mb-1",6:"text-sm font-medium mt-2 mb-1"};function be(r,e){switch(r.type){case "hr":return jsxRuntime.jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let i=Math.min(Math.max(r.level||1,1),6),s=`h${i}`;return jsxRuntime.jsx(s,{className:k("text-foreground",ve[i]),children:M(r.content||"")},`b${e}`)}case "paragraph":return jsxRuntime.jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:M(r.content||"")},`b${e}`);case "code":return jsxRuntime.jsx("pre",{className:"mb-3 overflow-x-auto rounded-lg bg-muted p-4 text-sm font-mono leading-relaxed text-foreground",children:jsxRuntime.jsx("code",{children:r.content})},`b${e}`);case "ul":return jsxRuntime.jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:r.items?.map((i,s)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:M(i)},`li${e}-${s}`))},`b${e}`);case "ol":return jsxRuntime.jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:r.items?.map((i,s)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:M(i)},`li${e}-${s}`))},`b${e}`);default:return null}}function L({content:r,className:e}){let i=xe(r);return jsxRuntime.jsx("div",{className:k("text-sm",e),children:i.map((s,o)=>be(s,o))})}function Q({open:r,className:e}){return jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:k("shrink-0 transition-transform duration-150",r?"rotate-0":"-rotate-90",e),children:jsxRuntime.jsx("path",{d:"M16.134 6.16a.5.5 0 1 1 .732.68l-6.5 7-.077.068a.5.5 0 0 1-.655-.068l-6.5-7-.062-.08a.5.5 0 0 1 .718-.667l.076.067L10 12.767z"})})}function q({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function B({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M15.147 4.146a.5.5 0 0 1 .707.707L10.707 10l5.147 5.147a.5.5 0 0 1-.63.771l-.078-.064L10 10.707l-5.146 5.147a.5.5 0 0 1-.708-.707L9.293 10 4.146 4.853a.5.5 0 0 1 .708-.707L10 9.293z"})})}function Y({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M10 3a.5.5 0 0 1 .5.5v6h6l.1.01a.5.5 0 0 1 0 .98l-.1.01h-6v6a.5.5 0 0 1-1 0v-6h-6a.5.5 0 0 1 0-1h6v-6A.5.5 0 0 1 10 3"})})}function ke(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M6.5 3A2.5 2.5 0 0 0 4 5.5v9A2.5 2.5 0 0 0 6.5 17h7a2.5 2.5 0 0 0 2.5-2.5v-7A2.5 2.5 0 0 0 13.5 5H11V3.5a.5.5 0 0 0-1 0V5H6.5ZM5 5.5A1.5 1.5 0 0 1 6.5 4H9v1H6.5A1.5 1.5 0 0 0 5 6.5v8A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 13.5 6H11V4h2.5A2.5 2.5 0 0 1 16 6.5v8a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-9Z"})})}function Ne(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M5.5 3A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h9a2.5 2.5 0 0 0 2.5-2.5v-9A2.5 2.5 0 0 0 14.5 3h-9ZM4 5.5A1.5 1.5 0 0 1 5.5 4h9A1.5 1.5 0 0 1 16 5.5v9a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 4 14.5v-9ZM7 7.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5Z"})})}function Re(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M10 2a.5.5 0 0 1 .354.146l3 3a.5.5 0 0 1-.708.708L10.5 3.707V12.5a.5.5 0 0 1-1 0V3.707L7.354 5.854a.5.5 0 1 1-.708-.708l3-3A.5.5 0 0 1 10 2ZM4 13.5a.5.5 0 0 1 1 0v1A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-1a.5.5 0 0 1 1 0v1a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-1Z"})})}function X(){let[r,e]=react.useState(false);return react.useEffect(()=>{if(typeof window>"u")return;let i=()=>e(window.innerWidth<768);return i(),window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]),r}function ee({onClose:r,children:e,title:i}){let s=X(),o=react.useRef(r);return o.current=r,react.useEffect(()=>{let c=t=>{t.key==="Escape"&&o.current();};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[]),s?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full max-h-[90vh] overflow-y-auto rounded-t-2xl bg-[#1a1a1a] p-5 pb-8 animate-in slide-in-from-bottom duration-200",onClick:c=>c.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-4 h-1 w-10 rounded-full bg-zinc-600"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-foreground",children:i}),jsxRuntime.jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(B,{size:20})})]}),e]})]}):jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full max-w-lg overflow-y-auto rounded-2xl bg-[#1a1a1a] p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:c=>c.stopPropagation(),children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-foreground",children:i}),jsxRuntime.jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(B,{size:20})})]}),e]})]})}function Ce({onClose:r,onCreated:e,config:i}){let[s,o]=react.useState(""),[c,t]=react.useState(""),[a,l]=react.useState(""),[d,u]=react.useState(false),[p,g]=react.useState(null);return jsxRuntime.jsx(ee,{title:"Write skill instructions",onClose:r,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsxRuntime.jsx("input",{id:"skill-name",value:s,onChange:w=>o(w.target.value),placeholder:"weekly-status-report",className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-desc",className:"text-sm text-muted-foreground",children:"Description"}),jsxRuntime.jsx("textarea",{id:"skill-desc",value:c,onChange:w=>t(w.target.value),placeholder:"Generate weekly status reports from recent work.",rows:3,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-instructions",className:"text-sm text-muted-foreground",children:"Instructions"}),jsxRuntime.jsx("textarea",{id:"skill-instructions",value:a,onChange:w=>l(w.target.value),placeholder:"Summarize my recent work in three sections: wins, blockers, and next steps.",rows:8,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),p&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:p}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsxRuntime.jsx("button",{onClick:r,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsxRuntime.jsx("button",{onClick:async()=>{if(s.trim()){u(true),g(null);try{let w=i.apiBaseUrl||"",S=`# ${s.trim()}
1
+ 'use strict';var react=require('react'),lucideReact=require('lucide-react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');function C(...n){return tailwindMerge.twMerge(clsx.clsx(n))}async function k(n,e,i,r){let a={"Content-Type":"application/json",...i?.headers};r&&(a.Authorization=`Bearer ${r}`);let l=await fetch(`${n}${e}`,{...i,headers:a});if(!l.ok){let t=`HTTP ${l.status}`;try{let s=await l.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return l.json()}function L(n){let e=n.indexOf(":");return {mode:n.slice(0,e),cid:n.slice(e+1)}}function z(n){let e=n.apiBaseUrl,i=n.authorMid,r=n.ownerMid,a=n.apiKey,l=n.stacknetUrl||n.apiBaseUrl;return react.useMemo(()=>({async listRepos(t,s){let c=new URLSearchParams;(t||r)&&c.set("owner",t||r),s?.limit&&c.set("limit",String(s.limit)),s?.cursor&&c.set("cursor",s.cursor);let d=c.toString()?`?${c}`:"",u=await k(e,`/api/rack/repos${d}`,void 0,a);return {items:u.repos||[],pagination:u.pagination||{total:(u.repos||[]).length,limit:50,has_more:false,next_cursor:null}}},async initRepo(t){return k(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...t,owner_mid:r})},a)},async push(t,s){return k(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...s,author_mid:i})},a)},async getTree(t,s="main"){let c=await k(e,`/api/rack/${t}/tree/${s}`,void 0,a);return {tree:c.tree,commit_cid:c.commit_cid}},async getBlob(t,s){return (await k(e,`/api/rack/${t}/blob/${s}`,void 0,a)).content},async getLog(t,s,c){let d=new URLSearchParams;s&&d.set("ref",s),c&&d.set("max_count",String(c));let u=d.toString()?`?${d}`:"";return (await k(e,`/api/rack/${t}/log${u}`,void 0,a)).commits||[]},async getBranches(t){return (await k(e,`/api/rack/${t}/branches`,void 0,a)).branches||[]},async createBranch(t,s,c){return k(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:s,from_ref:c})},a)},async merge(t,s,c){return k(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:s,target_branch:c})},a)},async getDiff(t,s,c){return (await k(e,`/api/rack/${t}/diff/${s}/${c}`,void 0,a)).diff?.entries||[]},async starRepo(t){return k(e,`/api/rack/${t}/star`,{method:"POST"},a)},async unstarRepo(t){return k(e,`/api/rack/${t}/star`,{method:"DELETE"},a)},async getStarInfo(t){return k(e,`/api/rack/${t}/stars`,void 0,a)},async getSkillStats(t){let s={meta:null,tokenCount:null,usageCount:null};try{let{tree:c}=await this.getTree(t,"main");if(!c?.entries)return s;if(c.entries["META.json"]){let h=L(c.entries["META.json"]).cid,g=await this.getBlob(t,h);s.meta=JSON.parse(g);}let d=0,u=Object.values(c.entries).map(async h=>{try{let g=L(h).cid,m=await this.getBlob(t,g);d+=m.length;}catch{}});await Promise.all(u),d>0&&(s.tokenCount=Math.ceil(d/4)),s.meta?.skill_id&&(s.usageCount=await this.getSkillUsageCount(s.meta.skill_id));}catch{}return s},async getSkillUsageCount(t){try{let s=await fetch(`${l}/v1/skills/${encodeURIComponent(t)}`);if(s.ok){let d=await s.json();return d.usage_count??d.usageCount??null}let c=await fetch(`${l}/v1/skills?scope=public`);if(c.ok){let u=((await c.json()).skills||[]).find(h=>h.name===t||h.id===t);if(u)return u.usage_count??u.usageCount??0}return 0}catch{return null}},async getTensorStats(t){let s={meta:null,sizeMB:null};try{let{tree:c}=await this.getTree(t,"main");if(!c?.entries)return s;if(c.entries["TENSOR_META.json"]){let d=L(c.entries["TENSOR_META.json"]).cid,u=await this.getBlob(t,d);s.meta=JSON.parse(u),s.sizeMB=s.meta?.tensor_size_mb??null;}}catch{}return s},async getNetworkStats(){try{return (await k(e,"/api/rack/stats",void 0,a)).stats||null}catch{return null}},async getTrending(t=5,s=1,c){try{let d=new URLSearchParams({limit:String(t),days:String(s)});c&&d.set("cursor",c);let u=await k(e,`/api/rack/trending?${d}`,void 0,a);return {items:u.trending||[],pagination:u.pagination||{total:(u.trending||[]).length,limit:t,has_more:!1,next_cursor:null}}}catch{return {items:[],pagination:{total:0,limit:t,has_more:false,next_cursor:null}}}}}),[e,i,r,a,l])}function K(n,e={}){let{pageSize:i=50,owner:r}=e,a=z(n),[l,t]=react.useState([]),[s,c]=react.useState(null),[d,u]=react.useState(false),[h,g]=react.useState(null),m=react.useRef(null),b=react.useRef(true),v=react.useCallback(async(y,T=false)=>{u(true),g(null);try{let R=await a.listRepos(r,{limit:i,cursor:y||void 0});b.current&&(t(E=>T?[...E,...R.items]:R.items),c(R.pagination),m.current=R.pagination.next_cursor);}catch(R){b.current&&g(R.message);}finally{b.current&&u(false);}},[a,r,i]),S=react.useCallback(async()=>{!m.current||d||await v(m.current,true);},[v,d]),p=react.useCallback(async()=>{m.current=null,await v(void 0,false);},[v]);return react.useEffect(()=>(b.current=true,v(),()=>{b.current=false;}),[v]),{repos:l,hasMore:s?.has_more??false,total:s?.total??0,loading:d,error:h,loadMore:S,reset:p,pagination:s}}function be(n){return Object.entries(n).map(([e,i])=>{let r=i.indexOf(":"),a=r>0?i.slice(0,r):"100644",l=r>0?i.slice(r+1):i;return {path:e,mode:a,cid:l,isDir:a==="040000"}}).sort((e,i)=>e.isDir!==i.isDir?e.isDir?-1:1:e.path.localeCompare(i.path))}function Y(n,e,i="main"){let r=z(n),[a,l]=react.useState([]),[t,s]=react.useState(false),[c,d]=react.useState(null),u=react.useRef(true),h=react.useCallback(async()=>{if(e)try{u.current&&(s(!0),d(null));let{tree:m}=await r.getTree(e,i);u.current&&l(be(m.entries));}catch(m){u.current&&d(m instanceof Error?m.message:"Failed to load tree");}finally{u.current&&s(false);}},[r,e,i]);react.useEffect(()=>(u.current=true,h(),()=>{u.current=false;}),[h]);let g=react.useCallback(async m=>{if(!e)throw new Error("No repo selected");return r.getBlob(e,m)},[r,e]);return {entries:a,loading:t,error:c,refresh:h,getFileContent:g}}var ve=/^(https?:\/\/|mailto:|\/[^/])/i;function ye(n){let e=n.trim();return ve.test(e)?e:null}function _(n){let e=[],i=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,r=0,a,l=0;for(;(a=i.exec(n))!==null;){a.index>r&&e.push(n.slice(r,a.index));let t=`i${l++}`;if(a[1])e.push(jsxRuntime.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[0.85em] font-mono text-pink-400",children:a[1].slice(1,-1)},t));else if(a[2])e.push(jsxRuntime.jsx("strong",{children:a[3]},t));else if(a[4])e.push(jsxRuntime.jsx("em",{children:a[5]},t));else if(a[6])e.push(jsxRuntime.jsx("em",{children:a[7]},t));else if(a[8]){let s=ye(a[10]);s?e.push(jsxRuntime.jsx("a",{href:s,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:a[9]},t)):e.push(a[9]);}r=a.index+a[0].length;}return r<n.length&&e.push(n.slice(r)),e.length>0?e:[n]}function ke(n){let e=n.split(`
2
+ `),i=[],r=0;for(;r<e.length;){let a=e[r];if(a.trim()===""){r++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(a.trim())){i.push({type:"hr"}),r++;continue}let l=a.match(/^(#{1,6})\s+(.+)/);if(l){i.push({type:"heading",level:l[1].length,content:l[2]}),r++;continue}if(a.trim().startsWith("```")){let s=a.trim().slice(3).trim(),c=[];for(r++;r<e.length&&!e[r].trim().startsWith("```");)c.push(e[r]),r++;i.push({type:"code",content:c.join(`
3
+ `),lang:s||void 0}),r++;continue}if(/^\s*[-*+]\s/.test(a)){let s=[];for(;r<e.length&&/^\s*[-*+]\s/.test(e[r]);)s.push(e[r].replace(/^\s*[-*+]\s+/,"")),r++;i.push({type:"ul",items:s});continue}if(/^\s*\d+[.)]\s/.test(a)){let s=[];for(;r<e.length&&/^\s*\d+[.)]\s/.test(e[r]);)s.push(e[r].replace(/^\s*\d+[.)]\s+/,"")),r++;i.push({type:"ol",items:s});continue}let t=[];for(;r<e.length&&e[r].trim()!==""&&!e[r].match(/^#{1,6}\s/)&&!e[r].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[r])&&!/^\s*\d+[.)]\s/.test(e[r]);)t.push(e[r]),r++;t.length>0&&i.push({type:"paragraph",content:t.join(" ")});}return i}var Ne={1:"text-2xl font-bold mt-6 mb-3",2:"text-xl font-bold mt-5 mb-2",3:"text-lg font-semibold mt-4 mb-2",4:"text-base font-semibold mt-3 mb-1",5:"text-sm font-semibold mt-2 mb-1",6:"text-sm font-medium mt-2 mb-1"};function Re(n,e){switch(n.type){case "hr":return jsxRuntime.jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let i=Math.min(Math.max(n.level||1,1),6),r=`h${i}`;return jsxRuntime.jsx(r,{className:C("text-foreground",Ne[i]),children:_(n.content||"")},`b${e}`)}case "paragraph":return jsxRuntime.jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:_(n.content||"")},`b${e}`);case "code":return jsxRuntime.jsx("pre",{className:"mb-3 overflow-x-auto rounded-lg bg-muted p-4 text-sm font-mono leading-relaxed text-foreground",children:jsxRuntime.jsx("code",{children:n.content})},`b${e}`);case "ul":return jsxRuntime.jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:n.items?.map((i,r)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:_(i)},`li${e}-${r}`))},`b${e}`);case "ol":return jsxRuntime.jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:n.items?.map((i,r)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:_(i)},`li${e}-${r}`))},`b${e}`);default:return null}}function D({content:n,className:e}){let i=ke(n);return jsxRuntime.jsx("div",{className:C("text-sm",e),children:i.map((r,a)=>Re(r,a))})}function ne({open:n,className:e}){return jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:C("shrink-0 transition-transform duration-150",n?"rotate-0":"-rotate-90",e),children:jsxRuntime.jsx("path",{d:"M16.134 6.16a.5.5 0 1 1 .732.68l-6.5 7-.077.068a.5.5 0 0 1-.655-.068l-6.5-7-.062-.08a.5.5 0 0 1 .718-.667l.076.067L10 12.767z"})})}function X({size:n=20,className:e}){return jsxRuntime.jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function O({size:n=20,className:e}){return jsxRuntime.jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M15.147 4.146a.5.5 0 0 1 .707.707L10.707 10l5.147 5.147a.5.5 0 0 1-.63.771l-.078-.064L10 10.707l-5.146 5.147a.5.5 0 0 1-.708-.707L9.293 10 4.146 4.853a.5.5 0 0 1 .708-.707L10 9.293z"})})}function re({size:n=20,className:e}){return jsxRuntime.jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M10 3a.5.5 0 0 1 .5.5v6h6l.1.01a.5.5 0 0 1 0 .98l-.1.01h-6v6a.5.5 0 0 1-1 0v-6h-6a.5.5 0 0 1 0-1h6v-6A.5.5 0 0 1 10 3"})})}function Pe(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M6.5 3A2.5 2.5 0 0 0 4 5.5v9A2.5 2.5 0 0 0 6.5 17h7a2.5 2.5 0 0 0 2.5-2.5v-7A2.5 2.5 0 0 0 13.5 5H11V3.5a.5.5 0 0 0-1 0V5H6.5ZM5 5.5A1.5 1.5 0 0 1 6.5 4H9v1H6.5A1.5 1.5 0 0 0 5 6.5v8A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 13.5 6H11V4h2.5A2.5 2.5 0 0 1 16 6.5v8a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-9Z"})})}function Te(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M5.5 3A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h9a2.5 2.5 0 0 0 2.5-2.5v-9A2.5 2.5 0 0 0 14.5 3h-9ZM4 5.5A1.5 1.5 0 0 1 5.5 4h9A1.5 1.5 0 0 1 16 5.5v9a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 4 14.5v-9ZM7 7.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5Z"})})}function Ee(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M10 2a.5.5 0 0 1 .354.146l3 3a.5.5 0 0 1-.708.708L10.5 3.707V12.5a.5.5 0 0 1-1 0V3.707L7.354 5.854a.5.5 0 1 1-.708-.708l3-3A.5.5 0 0 1 10 2ZM4 13.5a.5.5 0 0 1 1 0v1A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-1a.5.5 0 0 1 1 0v1a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-1Z"})})}function se(){let[n,e]=react.useState(false);return react.useEffect(()=>{if(typeof window>"u")return;let i=()=>e(window.innerWidth<768);return i(),window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]),n}function oe({onClose:n,children:e,title:i}){let r=se(),a=react.useRef(n);return a.current=n,react.useEffect(()=>{let l=t=>{t.key==="Escape"&&a.current();};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[]),r?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:n,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full max-h-[90vh] overflow-y-auto rounded-t-2xl bg-[#1a1a1a] p-5 pb-8 animate-in slide-in-from-bottom duration-200",onClick:l=>l.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-4 h-1 w-10 rounded-full bg-zinc-600"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-foreground",children:i}),jsxRuntime.jsx("button",{onClick:n,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(O,{size:20})})]}),e]})]}):jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:n,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full max-w-lg overflow-y-auto rounded-2xl bg-[#1a1a1a] p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:l=>l.stopPropagation(),children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-foreground",children:i}),jsxRuntime.jsx("button",{onClick:n,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(O,{size:20})})]}),e]})]})}function Me(n){let e=n.split(`
4
+ `),i="",r="",l=false;for(let t=0;t<e.length;t++){let s=e[t].trim();if(t===0&&s==="---"){l=true;continue}if(l){s==="---"&&(l=false,true);continue}if(!i){let c=s.match(/^#{1,2}\s+(.+)/);if(c){i=c[1].trim();continue}}if(i&&!r){if(!s||s.startsWith("#")||s==="---"||s==="***"||s==="___")continue;r=s.replace(/\*\*/g,"").replace(/`/g,"").trim();break}}return i?{title:i,description:r}:null}function $e({onClose:n,onCreated:e,config:i}){let[r,a]=react.useState(""),[l,t]=react.useState(""),[s,c]=react.useState(""),[d,u]=react.useState(false),[h,g]=react.useState(null),[m,b]=react.useState(false),v=p=>{if(c(p),!r.trim()&&!l.trim()&&p.trim().length>10){let y=Me(p);y&&(a(y.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")),t(y.description),b(true));}};return jsxRuntime.jsx(oe,{title:"Write skill instructions",onClose:n,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsxRuntime.jsx("input",{id:"skill-name",value:r,onChange:p=>a(p.target.value),placeholder:"weekly-status-report",className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-desc",className:"text-sm text-muted-foreground",children:"Description"}),jsxRuntime.jsx("textarea",{id:"skill-desc",value:l,onChange:p=>t(p.target.value),placeholder:"Generate weekly status reports from recent work.",rows:3,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-instructions",className:"text-sm text-muted-foreground",children:"Instructions"}),jsxRuntime.jsx("textarea",{id:"skill-instructions",value:s,onChange:p=>v(p.target.value),placeholder:"Summarize my recent work in three sections: wins, blockers, and next steps.",rows:8,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),h&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:h}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsxRuntime.jsx("button",{onClick:n,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsxRuntime.jsx("button",{onClick:async()=>{if(r.trim()){u(true),g(null);try{let p=i.apiBaseUrl||"",y=m?s.trim():`# ${r.trim()}
4
5
 
5
- ${c.trim()}
6
+ ${l.trim()}
6
7
 
7
8
  ---
8
9
 
9
- ${a.trim()}`,N=await fetch(`${w}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.trim(),description:c.trim(),skill_md:S,content_type:"code"})});if(!N.ok){let C=`Failed to register skill (${N.status})`;try{let y=await N.json();y.error&&(C=y.error);}catch{}throw new Error(C)}e?.(),r();}catch(w){g(w instanceof Error?w.message:"Failed to create skill");}finally{u(false);}}},disabled:d||!s.trim(),className:"rounded-lg bg-zinc-600 px-4 py-2 text-sm font-medium text-white hover:bg-zinc-500 disabled:opacity-50",children:d?"Creating...":"Create"})]})]})})}function Se({onClose:r,onCreated:e,config:i}){let s=react.useRef(null),[o,c]=react.useState(false),[t,a]=react.useState(false),[l,d]=react.useState(null),u=async g=>{a(true),d(null);try{let f=await g.text(),w=i.apiBaseUrl||"",S=g.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),N=await fetch(`${w}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:S,skill_md:f,content_type:"code"})});if(!N.ok){let C=`Failed to register skill (${N.status})`;try{let y=await N.json();y.error&&(C=y.error);}catch{}throw new Error(C)}e?.(),r();}catch(f){d(f instanceof Error?f.message:"Upload failed");}finally{a(false);}};return jsxRuntime.jsx(ee,{title:"Upload skill",onClose:r,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{onDragOver:g=>{g.preventDefault(),c(true);},onDragLeave:()=>c(false),onDrop:g=>{g.preventDefault(),c(false);let f=g.dataTransfer.files[0];f&&u(f);},onClick:()=>s.current?.click(),className:k("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",o?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsxRuntime.jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsxRuntime.jsx(Y,{size:20,className:"text-muted-foreground"})}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:t?"Uploading...":"Drag and drop or click to upload"})]}),jsxRuntime.jsx("input",{ref:s,type:"file",accept:".md,.zip,.skill,.txt,.yml,.yaml",className:"hidden","aria-label":"Upload skill file",onChange:g=>{let f=g.target.files?.[0];f&&u(f);}}),l&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:l}),jsxRuntime.jsxs("div",{className:"space-y-2 text-xs text-muted-foreground",children:[jsxRuntime.jsx("p",{className:"font-medium text-foreground/70",children:"File requirements"}),jsxRuntime.jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[jsxRuntime.jsx("li",{children:".md file must contain skill name and description formatted in YAML"}),jsxRuntime.jsx("li",{children:".zip or .skill file must include a SKILL.md file"})]})]})]})})}function Te({onClose:r,onSelect:e}){let i=X(),s=react.useRef(null),o=react.useRef(r);o.current=r,react.useEffect(()=>{if(i)return;let t=a=>{s.current&&a.target instanceof Node&&!s.current.contains(a.target)&&o.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[i]);let c=[{id:"create-with-geoff",icon:jsxRuntime.jsx(ke,{}),label:"Create with Geoff"},{id:"write",icon:jsxRuntime.jsx(Ne,{}),label:"Write skill instructions"},{id:"upload",icon:jsxRuntime.jsx(Re,{}),label:"Upload a skill"}];return i?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full rounded-t-2xl bg-[#1a1a1a] p-4 pb-8 animate-in slide-in-from-bottom duration-200",onClick:t=>t.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),c.map(t=>jsxRuntime.jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-800",children:[t.icon,t.label]},t.id))]})]}):jsxRuntime.jsx("div",{ref:s,className:"absolute right-2 top-11 z-50 w-56 overflow-hidden rounded-xl border border-zinc-700 bg-[#2a2a2a] shadow-xl animate-in fade-in zoom-in-95 duration-100",children:c.map(t=>jsxRuntime.jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[t.icon,t.label]},t.id))})}function Ee({entry:r,selected:e,onSelect:i,depth:s=0}){return jsxRuntime.jsxs("button",{onClick:()=>i(r),className:k("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+s*16}px`},children:[jsxRuntime.jsx("span",{className:"truncate flex-1",children:r.path.split("/").pop()}),r.isDir&&jsxRuntime.jsx(Q,{className:"ml-auto text-muted-foreground"})]})}function Pe({repo:r,selected:e,expanded:i,onSelect:s,onToggle:o,children:c}){return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>{s(),o();},className:k("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsxRuntime.jsx(Q,{open:i}),jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4 shrink-0"}),jsxRuntime.jsx("span",{className:"truncate",children:r.name})]}),i&&c]})}function Me({entry:r,content:e,loading:i,repoName:s}){let[o,c]=react.useState(false),t=react.useRef(null);react.useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[a,l]=react.useState(false),d=async()=>{if(e)try{await navigator.clipboard.writeText(e),c(!0),l(!1),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>c(!1),2e3);}catch{l(true),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>l(false),2e3);}};if(!r)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(i)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let u=r.path.split("/").pop()||r.path,p=/\.(md|mdx)$/i.test(u);return jsxRuntime.jsxs("div",{className:"flex h-full flex-col px-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[jsxRuntime.jsx("h3",{className:"text-sm sm:text-lg font-semibold text-foreground",children:u}),jsxRuntime.jsx("button",{onClick:d,"aria-label":"Copy file content",className:k("rounded p-1 transition-colors",o?"text-green-500":a?"text-red-500":"text-muted-foreground hover:text-foreground"),children:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"})})})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-auto p-4",children:p?jsxRuntime.jsx(L,{content:e||""}):jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function ze({config:r,category:e,className:i,style:s}){let{repos:o,loading:c,error:t,refresh:a}=Z(r),[l,d]=react.useState(null),[u,p]=react.useState(null),[g,f]=react.useState(null),[w,S]=react.useState(null),[N,C]=react.useState(false),[y,U]=react.useState(""),[te,D]=react.useState(false),[O,j]=react.useState(false),[F,z]=react.useState(null),re=o.find(h=>h.repo_id===l),{entries:ne,getFileContent:H}=W(r,u),V=o.filter(h=>!y||h.name.toLowerCase().includes(y.toLowerCase())),se=react.useCallback(async h=>{if(!h.isDir){f(h),C(true);try{let R=await H(h.cid);S(R);}catch(R){let ae=R instanceof Error?R.message:"Unknown error";S(`Failed to load file: ${ae}`);}finally{C(false);}}},[H]);react.useEffect(()=>{o.length>0&&!l&&(d(o[0].repo_id),p(o[0].repo_id));},[o,l]);let oe=h=>{h==="create-with-geoff"?window.open(`https://www.geoff.ai/?p=${encodeURIComponent("Let's create a skill together using your skill-creator skill. First ask me what the skill should do.")}`,"_blank","noopener,noreferrer"):z(h);};return jsxRuntime.jsxs("div",{className:k("flex flex-1 h-full min-h-0",i),style:s,children:[jsxRuntime.jsxs("div",{className:"relative flex w-96 shrink-0 flex-col border-r",children:[jsxRuntime.jsx("div",{className:"flex h-12 items-center gap-2 px-3",children:te?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-md border bg-muted/50 px-2 py-1",children:[jsxRuntime.jsx(q,{size:16,className:"shrink-0 text-muted-foreground"}),jsxRuntime.jsx("input",{type:"text",value:y,onChange:h=>U(h.target.value),placeholder:"Search",autoFocus:true,"aria-label":"Search items",className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),jsxRuntime.jsx("button",{onClick:()=>{D(false),U("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(B,{size:16})})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground capitalize",children:e||"Items"}),jsxRuntime.jsx("button",{onClick:()=>D(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsxRuntime.jsx(q,{size:20})}),jsxRuntime.jsx("button",{onClick:()=>j(!O),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(Y,{size:20})})]})}),O&&jsxRuntime.jsx(Te,{onClose:()=>j(false),onSelect:oe}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:c?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):t?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:t}):V.length===0?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:y?"No matching items":"No items yet"}):jsxRuntime.jsx("div",{className:"space-y-0.5",children:V.map(h=>jsxRuntime.jsx(Pe,{repo:h,selected:l===h.repo_id,expanded:u===h.repo_id,onSelect:()=>{d(h.repo_id),f(null),S(null);},onToggle:()=>p(u===h.repo_id?null:h.repo_id),children:jsxRuntime.jsx("div",{className:"ml-10 pl-1",children:ne.map(R=>jsxRuntime.jsx(Ee,{entry:R,selected:g?.path===R.path,onSelect:se,depth:R.path.split("/").length-1},R.path))})},h.repo_id))})})]}),jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntime.jsx(Me,{entry:g,content:w,loading:N,repoName:re?.name||""})}),F==="write"&&jsxRuntime.jsx(Ce,{config:r,onClose:()=>z(null),onCreated:a}),F==="upload"&&jsxRuntime.jsx(Se,{config:r,onClose:()=>z(null),onCreated:a})]})}
10
- exports.Markdown=L;exports.RackBrowser=ze;
10
+ ${s.trim()}`,T=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.trim(),description:l.trim(),skill_md:y,content_type:"code"})});if(!T.ok){let R=`Failed to register skill (${T.status})`;try{let E=await T.json();E.error&&(R=E.error);}catch{}throw new Error(R)}e?.(),n();}catch(p){g(p instanceof Error?p.message:"Failed to create skill");}finally{u(false);}}},disabled:d||!r.trim(),className:"rounded-lg bg-zinc-600 px-4 py-2 text-sm font-medium text-white hover:bg-zinc-500 disabled:opacity-50",children:d?"Creating...":"Create"})]})]})})}function ze({onClose:n,onCreated:e,config:i}){let r=react.useRef(null),[a,l]=react.useState(false),[t,s]=react.useState(false),[c,d]=react.useState(null),u=async g=>{s(true),d(null);try{let m=await g.text(),b=i.apiBaseUrl||"",v=g.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),S=await fetch(`${b}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:v,skill_md:m,content_type:"code"})});if(!S.ok){let p=`Failed to register skill (${S.status})`;try{let y=await S.json();y.error&&(p=y.error);}catch{}throw new Error(p)}e?.(),n();}catch(m){d(m instanceof Error?m.message:"Upload failed");}finally{s(false);}};return jsxRuntime.jsx(oe,{title:"Upload skill",onClose:n,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{onDragOver:g=>{g.preventDefault(),l(true);},onDragLeave:()=>l(false),onDrop:g=>{g.preventDefault(),l(false);let m=g.dataTransfer.files[0];m&&u(m);},onClick:()=>r.current?.click(),className:C("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",a?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsxRuntime.jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsxRuntime.jsx(re,{size:20,className:"text-muted-foreground"})}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:t?"Uploading...":"Drag and drop or click to upload"})]}),jsxRuntime.jsx("input",{ref:r,type:"file",accept:".md,.zip,.skill,.txt,.yml,.yaml",className:"hidden","aria-label":"Upload skill file",onChange:g=>{let m=g.target.files?.[0];m&&u(m);}}),c&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:c}),jsxRuntime.jsxs("div",{className:"space-y-2 text-xs text-muted-foreground",children:[jsxRuntime.jsx("p",{className:"font-medium text-foreground/70",children:"File requirements"}),jsxRuntime.jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[jsxRuntime.jsx("li",{children:".md file must contain skill name and description formatted in YAML"}),jsxRuntime.jsx("li",{children:".zip or .skill file must include a SKILL.md file"})]})]})]})})}function Ie({onClose:n,onSelect:e}){let i=se(),r=react.useRef(null),a=react.useRef(n);a.current=n,react.useEffect(()=>{if(i)return;let t=s=>{r.current&&s.target instanceof Node&&!r.current.contains(s.target)&&a.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[i]);let l=[{id:"create-with-geoff",icon:jsxRuntime.jsx(Pe,{}),label:"Create with Geoff"},{id:"write",icon:jsxRuntime.jsx(Te,{}),label:"Write skill instructions"},{id:"upload",icon:jsxRuntime.jsx(Ee,{}),label:"Upload a skill"}];return i?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:n,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full rounded-t-2xl bg-[#1a1a1a] p-4 pb-8 animate-in slide-in-from-bottom duration-200",onClick:t=>t.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),l.map(t=>jsxRuntime.jsxs("button",{onClick:()=>{e(t.id),n();},className:"flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-800",children:[t.icon,t.label]},t.id))]})]}):jsxRuntime.jsx("div",{ref:r,className:"absolute right-2 top-11 z-50 w-56 overflow-hidden rounded-xl border border-zinc-700 bg-[#2a2a2a] shadow-xl animate-in fade-in zoom-in-95 duration-100",children:l.map(t=>jsxRuntime.jsxs("button",{onClick:()=>{e(t.id),n();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[t.icon,t.label]},t.id))})}function _e({entry:n,selected:e,onSelect:i,depth:r=0}){return jsxRuntime.jsxs("button",{onClick:()=>i(n),className:C("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+r*16}px`},children:[jsxRuntime.jsx("span",{className:"truncate flex-1",children:n.path.split("/").pop()}),n.isDir&&jsxRuntime.jsx(ne,{className:"ml-auto text-muted-foreground"})]})}function Be({repo:n,selected:e,expanded:i,onSelect:r,onToggle:a,children:l}){return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>{r(),a();},className:C("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsxRuntime.jsx(ne,{open:i}),jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4 shrink-0"}),jsxRuntime.jsx("span",{className:"truncate",children:n.name})]}),i&&l]})}function Le({entry:n,content:e,loading:i,repoName:r}){let[a,l]=react.useState(false),t=react.useRef(null);react.useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[s,c]=react.useState(false),d=async()=>{if(e)try{await navigator.clipboard.writeText(e),l(!0),c(!1),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>l(!1),2e3);}catch{c(true),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>c(false),2e3);}};if(!n)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(i)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let u=n.path.split("/").pop()||n.path,h=/\.(md|mdx)$/i.test(u);return jsxRuntime.jsxs("div",{className:"flex h-full flex-col px-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[jsxRuntime.jsx("h3",{className:"text-sm sm:text-lg font-semibold text-foreground",children:u}),jsxRuntime.jsx("button",{onClick:d,"aria-label":"Copy file content",className:C("rounded p-1 transition-colors",a?"text-green-500":s?"text-red-500":"text-muted-foreground hover:text-foreground"),children:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"})})})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-auto p-4",children:h?jsxRuntime.jsx(D,{content:e||""}):jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function Ae({config:n,category:e,className:i,style:r}){let{repos:a,loading:l,error:t,reset:d}=K(n,{pageSize:50}),[u,h]=react.useState(null),[g,m]=react.useState(null),[b,v]=react.useState(null),[S,p]=react.useState(null),[y,T]=react.useState(false),[R,E]=react.useState(""),[ie,H]=react.useState(false),[W,J]=react.useState(false),[V,B]=react.useState(null),le=a.find(w=>w.repo_id===u),{entries:ce,getFileContent:Z}=Y(n,g),q=a.filter(w=>!R||w.name.toLowerCase().includes(R.toLowerCase())),ue=react.useCallback(async w=>{if(!w.isDir){v(w),T(true);try{let P=await Z(w.cid);p(P);}catch(P){let me=P instanceof Error?P.message:"Unknown error";p(`Failed to load file: ${me}`);}finally{T(false);}}},[Z]);react.useEffect(()=>{a.length>0&&!u&&(h(a[0].repo_id),m(a[0].repo_id));},[a,u]);let de=w=>{w==="create-with-geoff"?window.open(`https://www.geoff.ai/?p=${encodeURIComponent("Let's create a skill together using your skill-creator skill. First ask me what the skill should do.")}`,"_blank","noopener,noreferrer"):B(w);};return jsxRuntime.jsxs("div",{className:C("flex flex-1 h-full min-h-0",i),style:r,children:[jsxRuntime.jsxs("div",{className:"relative flex w-96 shrink-0 flex-col border-r",children:[jsxRuntime.jsx("div",{className:"flex h-12 items-center gap-2 px-3",children:ie?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-md border bg-muted/50 px-2 py-1",children:[jsxRuntime.jsx(X,{size:16,className:"shrink-0 text-muted-foreground"}),jsxRuntime.jsx("input",{type:"text",value:R,onChange:w=>E(w.target.value),placeholder:"Search",autoFocus:true,"aria-label":"Search items",className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),jsxRuntime.jsx("button",{onClick:()=>{H(false),E("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(O,{size:16})})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground capitalize",children:e||"Items"}),jsxRuntime.jsx("button",{onClick:()=>H(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsxRuntime.jsx(X,{size:20})}),jsxRuntime.jsx("button",{onClick:()=>J(!W),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(re,{size:20})})]})}),W&&jsxRuntime.jsx(Ie,{onClose:()=>J(false),onSelect:de}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:l?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):t?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:t}):q.length===0?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:R?"No matching items":"No items yet"}):jsxRuntime.jsx("div",{className:"space-y-0.5",children:q.map(w=>jsxRuntime.jsx(Be,{repo:w,selected:u===w.repo_id,expanded:g===w.repo_id,onSelect:()=>{h(w.repo_id),v(null),p(null);},onToggle:()=>m(g===w.repo_id?null:w.repo_id),children:jsxRuntime.jsx("div",{className:"ml-10 pl-1",children:ce.map(P=>jsxRuntime.jsx(_e,{entry:P,selected:b?.path===P.path,onSelect:ue,depth:P.path.split("/").length-1},P.path))})},w.repo_id))})})]}),jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntime.jsx(Le,{entry:b,content:S,loading:y,repoName:le?.name||""})}),V==="write"&&jsxRuntime.jsx($e,{config:n,onClose:()=>B(null),onCreated:d}),V==="upload"&&jsxRuntime.jsx(ze,{config:n,onClose:()=>B(null),onCreated:d})]})}async function ae(n,e,i,r){let a={"Content-Type":"application/json",...i?.headers};r&&(a.Authorization=`Bearer ${r}`);let l=await fetch(`${n}${e}`,{...i,headers:a});if(!l.ok){let t=`HTTP ${l.status}`;try{let s=await l.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return l.json()}function je({config:n,repoId:e,onAuthRequired:i,className:r,style:a}){let l=n.apiBaseUrl,t=n.apiKey,[s,c]=react.useState({stars:0,starred:false,repo_id:e}),[d,u]=react.useState(false),[h,g]=react.useState(null),m=react.useRef(true),b=l.includes("/cpx/rack")?"":"/api/rack";react.useEffect(()=>(m.current=true,ae(l,`${b}/${e}/stars`,void 0,t).then(S=>{m.current&&c(S);}).catch(()=>{}),()=>{m.current=false;}),[l,e,t,b]);let v=react.useCallback(async S=>{if(S.preventDefault(),S.stopPropagation(),!t){i?.();return}u(true),g(null);try{let p=s.starred?"DELETE":"POST",y=await ae(l,`${b}/${e}/star`,{method:p},t);m.current&&c({stars:y.stars,starred:y.starred,repo_id:e});}catch(p){m.current&&g(p.message);}finally{m.current&&u(false);}},[l,e,t,s.starred,i]);return jsxRuntime.jsxs("button",{onClick:v,disabled:d,title:h||(s.starred?"Unstar (100k tokens)":"Star (100k tokens)"),className:r,style:{display:"inline-flex",alignItems:"center",gap:"4px",background:"none",border:"none",cursor:d?"wait":"pointer",padding:"4px 8px",fontSize:"12px",fontFamily:"inherit",color:s.starred?"#f59e0b":"#91918d",transition:"color 150ms",opacity:d?.5:1,...a},children:[jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:s.starred?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})}),jsxRuntime.jsx("span",{children:s.stars})]})}
11
+ exports.Markdown=D;exports.RackBrowser=Ae;exports.StarButton=je;
@@ -16,4 +16,21 @@ interface MarkdownProps {
16
16
  }
17
17
  declare function Markdown({ content, className }: MarkdownProps): react_jsx_runtime.JSX.Element;
18
18
 
19
- export { Markdown, RackBrowser, type RackBrowserProps };
19
+ interface StarButtonProps {
20
+ config: RackConfig;
21
+ repoId: string;
22
+ /** Called when user is not authenticated and tries to star */
23
+ onAuthRequired?: () => void;
24
+ className?: string;
25
+ style?: React.CSSProperties;
26
+ }
27
+ /**
28
+ * Star/unstar button for a rack repo.
29
+ * Shows star count and filled/unfilled state.
30
+ * Costs 100k tokens per star/unstar action.
31
+ *
32
+ * If no session (no apiKey), calls onAuthRequired on click.
33
+ */
34
+ declare function StarButton({ config, repoId, onAuthRequired, className, style }: StarButtonProps): react_jsx_runtime.JSX.Element;
35
+
36
+ export { Markdown, RackBrowser, type RackBrowserProps, StarButton, type StarButtonProps };
@@ -16,4 +16,21 @@ interface MarkdownProps {
16
16
  }
17
17
  declare function Markdown({ content, className }: MarkdownProps): react_jsx_runtime.JSX.Element;
18
18
 
19
- export { Markdown, RackBrowser, type RackBrowserProps };
19
+ interface StarButtonProps {
20
+ config: RackConfig;
21
+ repoId: string;
22
+ /** Called when user is not authenticated and tries to star */
23
+ onAuthRequired?: () => void;
24
+ className?: string;
25
+ style?: React.CSSProperties;
26
+ }
27
+ /**
28
+ * Star/unstar button for a rack repo.
29
+ * Shows star count and filled/unfilled state.
30
+ * Costs 100k tokens per star/unstar action.
31
+ *
32
+ * If no session (no apiKey), calls onAuthRequired on click.
33
+ */
34
+ declare function StarButton({ config, repoId, onAuthRequired, className, style }: StarButtonProps): react_jsx_runtime.JSX.Element;
35
+
36
+ export { Markdown, RackBrowser, type RackBrowserProps, StarButton, type StarButtonProps };
@@ -1,10 +1,11 @@
1
- import {useState,useCallback,useEffect,useRef,useMemo}from'react';import {Loader2,FileText}from'lucide-react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsx,jsxs,Fragment}from'react/jsx-runtime';function k(...r){return twMerge(clsx(r))}async function v(r,e,i,s){let o={"Content-Type":"application/json",...i?.headers};s&&(o.Authorization=`Bearer ${s}`);let c=await fetch(`${r}${e}`,{...i,headers:o});if(!c.ok){let t=`HTTP ${c.status}`;try{let a=await c.json();a.error&&(t=a.error);}catch{}throw new Error(t)}return c.json()}function $(r){let e=r.indexOf(":");return {mode:r.slice(0,e),cid:r.slice(e+1)}}function P(r){let e=r.apiBaseUrl,i=r.authorMid,s=r.ownerMid,o=r.apiKey,c=r.stacknetUrl||r.apiBaseUrl;return useMemo(()=>({async listRepos(t,a){let l=new URLSearchParams;(t||s)&&l.set("owner",t||s),a?.limit&&l.set("limit",String(a.limit)),a?.cursor&&l.set("cursor",a.cursor);let d=l.toString()?`?${l}`:"",u=await v(e,`/api/rack/repos${d}`,void 0,o);return {items:u.repos||[],pagination:u.pagination||{total:(u.repos||[]).length,limit:50,has_more:false,next_cursor:null}}},async initRepo(t){return v(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...t,owner_mid:s})},o)},async push(t,a){return v(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...a,author_mid:i})},o)},async getTree(t,a="main"){let l=await v(e,`/api/rack/${t}/tree/${a}`,void 0,o);return {tree:l.tree,commit_cid:l.commit_cid}},async getBlob(t,a){return (await v(e,`/api/rack/${t}/blob/${a}`,void 0,o)).content},async getLog(t,a,l){let d=new URLSearchParams;a&&d.set("ref",a),l&&d.set("max_count",String(l));let u=d.toString()?`?${d}`:"";return (await v(e,`/api/rack/${t}/log${u}`,void 0,o)).commits||[]},async getBranches(t){return (await v(e,`/api/rack/${t}/branches`,void 0,o)).branches||[]},async createBranch(t,a,l){return v(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:a,from_ref:l})},o)},async merge(t,a,l){return v(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:a,target_branch:l})},o)},async getDiff(t,a,l){return (await v(e,`/api/rack/${t}/diff/${a}/${l}`,void 0,o)).diff?.entries||[]},async starRepo(t){return v(e,`/api/rack/${t}/star`,{method:"POST"},o)},async unstarRepo(t){return v(e,`/api/rack/${t}/star`,{method:"DELETE"},o)},async getStarInfo(t){return v(e,`/api/rack/${t}/stars`,void 0,o)},async getSkillStats(t){let a={meta:null,tokenCount:null,usageCount:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return a;if(l.entries["META.json"]){let p=$(l.entries["META.json"]).cid,g=await this.getBlob(t,p);a.meta=JSON.parse(g);}let d=0,u=Object.values(l.entries).map(async p=>{try{let g=$(p).cid,f=await this.getBlob(t,g);d+=f.length;}catch{}});await Promise.all(u),d>0&&(a.tokenCount=Math.ceil(d/4)),a.meta?.skill_id&&(a.usageCount=await this.getSkillUsageCount(a.meta.skill_id));}catch{}return a},async getSkillUsageCount(t){try{let a=await fetch(`${c}/v1/skills/${encodeURIComponent(t)}`);if(a.ok){let d=await a.json();return d.usage_count??d.usageCount??null}let l=await fetch(`${c}/v1/skills?scope=public`);if(l.ok){let u=((await l.json()).skills||[]).find(p=>p.name===t||p.id===t);if(u)return u.usage_count??u.usageCount??0}return 0}catch{return null}},async getTensorStats(t){let a={meta:null,sizeMB:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return a;if(l.entries["TENSOR_META.json"]){let d=$(l.entries["TENSOR_META.json"]).cid,u=await this.getBlob(t,d);a.meta=JSON.parse(u),a.sizeMB=a.meta?.tensor_size_mb??null;}}catch{}return a},async getNetworkStats(){try{return (await v(e,"/api/rack/stats",void 0,o)).stats||null}catch{return null}},async getTrending(t=5,a=1,l){try{let d=new URLSearchParams({limit:String(t),days:String(a)});l&&d.set("cursor",l);let u=await v(e,`/api/rack/trending?${d}`,void 0,o);return {items:u.trending||[],pagination:u.pagination||{total:(u.trending||[]).length,limit:t,has_more:!1,next_cursor:null}}}catch{return {items:[],pagination:{total:0,limit:t,has_more:false,next_cursor:null}}}}}),[e,i,s,o,c])}function Z(r){let e=P(r),i=useRef(e);i.current=e;let[s,o]=useState([]),[c,t]=useState(true),[a,l]=useState(null),d=useRef(true),u=useRef(null),p=useCallback(async()=>{u.current?.abort();let g=new AbortController;u.current=g;try{d.current&&(t(!0),l(null));let f=await i.current.listRepos();d.current&&!g.signal.aborted&&o(f.items);}catch(f){d.current&&!g.signal.aborted&&l(f instanceof Error?f.message:"Failed to load repos");}finally{d.current&&!g.signal.aborted&&t(false);}},[]);return useEffect(()=>(d.current=true,p(),()=>{d.current=false,u.current?.abort();}),[p]),{repos:s,loading:c,error:a,refresh:p}}function ge(r){return Object.entries(r).map(([e,i])=>{let s=i.indexOf(":"),o=s>0?i.slice(0,s):"100644",c=s>0?i.slice(s+1):i;return {path:e,mode:o,cid:c,isDir:o==="040000"}}).sort((e,i)=>e.isDir!==i.isDir?e.isDir?-1:1:e.path.localeCompare(i.path))}function W(r,e,i="main"){let s=P(r),[o,c]=useState([]),[t,a]=useState(false),[l,d]=useState(null),u=useRef(true),p=useCallback(async()=>{if(e)try{u.current&&(a(!0),d(null));let{tree:f}=await s.getTree(e,i);u.current&&c(ge(f.entries));}catch(f){u.current&&d(f instanceof Error?f.message:"Failed to load tree");}finally{u.current&&a(false);}},[s,e,i]);useEffect(()=>(u.current=true,p(),()=>{u.current=false;}),[p]);let g=useCallback(async f=>{if(!e)throw new Error("No repo selected");return s.getBlob(e,f)},[s,e]);return {entries:o,loading:t,error:l,refresh:p,getFileContent:g}}var pe=/^(https?:\/\/|mailto:|\/[^/])/i;function he(r){let e=r.trim();return pe.test(e)?e:null}function M(r){let e=[],i=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,s=0,o,c=0;for(;(o=i.exec(r))!==null;){o.index>s&&e.push(r.slice(s,o.index));let t=`i${c++}`;if(o[1])e.push(jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[0.85em] font-mono text-pink-400",children:o[1].slice(1,-1)},t));else if(o[2])e.push(jsx("strong",{children:o[3]},t));else if(o[4])e.push(jsx("em",{children:o[5]},t));else if(o[6])e.push(jsx("em",{children:o[7]},t));else if(o[8]){let a=he(o[10]);a?e.push(jsx("a",{href:a,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:o[9]},t)):e.push(o[9]);}s=o.index+o[0].length;}return s<r.length&&e.push(r.slice(s)),e.length>0?e:[r]}function xe(r){let e=r.split(`
2
- `),i=[],s=0;for(;s<e.length;){let o=e[s];if(o.trim()===""){s++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(o.trim())){i.push({type:"hr"}),s++;continue}let c=o.match(/^(#{1,6})\s+(.+)/);if(c){i.push({type:"heading",level:c[1].length,content:c[2]}),s++;continue}if(o.trim().startsWith("```")){let a=o.trim().slice(3).trim(),l=[];for(s++;s<e.length&&!e[s].trim().startsWith("```");)l.push(e[s]),s++;i.push({type:"code",content:l.join(`
3
- `),lang:a||void 0}),s++;continue}if(/^\s*[-*+]\s/.test(o)){let a=[];for(;s<e.length&&/^\s*[-*+]\s/.test(e[s]);)a.push(e[s].replace(/^\s*[-*+]\s+/,"")),s++;i.push({type:"ul",items:a});continue}if(/^\s*\d+[.)]\s/.test(o)){let a=[];for(;s<e.length&&/^\s*\d+[.)]\s/.test(e[s]);)a.push(e[s].replace(/^\s*\d+[.)]\s+/,"")),s++;i.push({type:"ol",items:a});continue}let t=[];for(;s<e.length&&e[s].trim()!==""&&!e[s].match(/^#{1,6}\s/)&&!e[s].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[s])&&!/^\s*\d+[.)]\s/.test(e[s]);)t.push(e[s]),s++;t.length>0&&i.push({type:"paragraph",content:t.join(" ")});}return i}var ve={1:"text-2xl font-bold mt-6 mb-3",2:"text-xl font-bold mt-5 mb-2",3:"text-lg font-semibold mt-4 mb-2",4:"text-base font-semibold mt-3 mb-1",5:"text-sm font-semibold mt-2 mb-1",6:"text-sm font-medium mt-2 mb-1"};function be(r,e){switch(r.type){case "hr":return jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let i=Math.min(Math.max(r.level||1,1),6),s=`h${i}`;return jsx(s,{className:k("text-foreground",ve[i]),children:M(r.content||"")},`b${e}`)}case "paragraph":return jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:M(r.content||"")},`b${e}`);case "code":return jsx("pre",{className:"mb-3 overflow-x-auto rounded-lg bg-muted p-4 text-sm font-mono leading-relaxed text-foreground",children:jsx("code",{children:r.content})},`b${e}`);case "ul":return jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:r.items?.map((i,s)=>jsx("li",{className:"leading-relaxed",children:M(i)},`li${e}-${s}`))},`b${e}`);case "ol":return jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:r.items?.map((i,s)=>jsx("li",{className:"leading-relaxed",children:M(i)},`li${e}-${s}`))},`b${e}`);default:return null}}function L({content:r,className:e}){let i=xe(r);return jsx("div",{className:k("text-sm",e),children:i.map((s,o)=>be(s,o))})}function Q({open:r,className:e}){return jsx("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:k("shrink-0 transition-transform duration-150",r?"rotate-0":"-rotate-90",e),children:jsx("path",{d:"M16.134 6.16a.5.5 0 1 1 .732.68l-6.5 7-.077.068a.5.5 0 0 1-.655-.068l-6.5-7-.062-.08a.5.5 0 0 1 .718-.667l.076.067L10 12.767z"})})}function q({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function B({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M15.147 4.146a.5.5 0 0 1 .707.707L10.707 10l5.147 5.147a.5.5 0 0 1-.63.771l-.078-.064L10 10.707l-5.146 5.147a.5.5 0 0 1-.708-.707L9.293 10 4.146 4.853a.5.5 0 0 1 .708-.707L10 9.293z"})})}function Y({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M10 3a.5.5 0 0 1 .5.5v6h6l.1.01a.5.5 0 0 1 0 .98l-.1.01h-6v6a.5.5 0 0 1-1 0v-6h-6a.5.5 0 0 1 0-1h6v-6A.5.5 0 0 1 10 3"})})}function ke(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M6.5 3A2.5 2.5 0 0 0 4 5.5v9A2.5 2.5 0 0 0 6.5 17h7a2.5 2.5 0 0 0 2.5-2.5v-7A2.5 2.5 0 0 0 13.5 5H11V3.5a.5.5 0 0 0-1 0V5H6.5ZM5 5.5A1.5 1.5 0 0 1 6.5 4H9v1H6.5A1.5 1.5 0 0 0 5 6.5v8A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 13.5 6H11V4h2.5A2.5 2.5 0 0 1 16 6.5v8a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-9Z"})})}function Ne(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M5.5 3A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h9a2.5 2.5 0 0 0 2.5-2.5v-9A2.5 2.5 0 0 0 14.5 3h-9ZM4 5.5A1.5 1.5 0 0 1 5.5 4h9A1.5 1.5 0 0 1 16 5.5v9a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 4 14.5v-9ZM7 7.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5Z"})})}function Re(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M10 2a.5.5 0 0 1 .354.146l3 3a.5.5 0 0 1-.708.708L10.5 3.707V12.5a.5.5 0 0 1-1 0V3.707L7.354 5.854a.5.5 0 1 1-.708-.708l3-3A.5.5 0 0 1 10 2ZM4 13.5a.5.5 0 0 1 1 0v1A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-1a.5.5 0 0 1 1 0v1a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-1Z"})})}function X(){let[r,e]=useState(false);return useEffect(()=>{if(typeof window>"u")return;let i=()=>e(window.innerWidth<768);return i(),window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]),r}function ee({onClose:r,children:e,title:i}){let s=X(),o=useRef(r);return o.current=r,useEffect(()=>{let c=t=>{t.key==="Escape"&&o.current();};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[]),s?jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full max-h-[90vh] overflow-y-auto rounded-t-2xl bg-[#1a1a1a] p-5 pb-8 animate-in slide-in-from-bottom duration-200",onClick:c=>c.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-4 h-1 w-10 rounded-full bg-zinc-600"}),jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsx("h2",{className:"text-lg font-semibold text-foreground",children:i}),jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(B,{size:20})})]}),e]})]}):jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full max-w-lg overflow-y-auto rounded-2xl bg-[#1a1a1a] p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:c=>c.stopPropagation(),children:[jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsx("h2",{className:"text-lg font-semibold text-foreground",children:i}),jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(B,{size:20})})]}),e]})]})}function Ce({onClose:r,onCreated:e,config:i}){let[s,o]=useState(""),[c,t]=useState(""),[a,l]=useState(""),[d,u]=useState(false),[p,g]=useState(null);return jsx(ee,{title:"Write skill instructions",onClose:r,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsx("input",{id:"skill-name",value:s,onChange:w=>o(w.target.value),placeholder:"weekly-status-report",className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-desc",className:"text-sm text-muted-foreground",children:"Description"}),jsx("textarea",{id:"skill-desc",value:c,onChange:w=>t(w.target.value),placeholder:"Generate weekly status reports from recent work.",rows:3,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-instructions",className:"text-sm text-muted-foreground",children:"Instructions"}),jsx("textarea",{id:"skill-instructions",value:a,onChange:w=>l(w.target.value),placeholder:"Summarize my recent work in three sections: wins, blockers, and next steps.",rows:8,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),p&&jsx("p",{className:"text-sm text-red-500",children:p}),jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsx("button",{onClick:r,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsx("button",{onClick:async()=>{if(s.trim()){u(true),g(null);try{let w=i.apiBaseUrl||"",S=`# ${s.trim()}
1
+ import {useState,useCallback,useEffect,useRef,useMemo}from'react';import {Loader2,FileText}from'lucide-react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsx,jsxs,Fragment}from'react/jsx-runtime';function C(...n){return twMerge(clsx(n))}async function k(n,e,i,r){let a={"Content-Type":"application/json",...i?.headers};r&&(a.Authorization=`Bearer ${r}`);let l=await fetch(`${n}${e}`,{...i,headers:a});if(!l.ok){let t=`HTTP ${l.status}`;try{let s=await l.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return l.json()}function L(n){let e=n.indexOf(":");return {mode:n.slice(0,e),cid:n.slice(e+1)}}function z(n){let e=n.apiBaseUrl,i=n.authorMid,r=n.ownerMid,a=n.apiKey,l=n.stacknetUrl||n.apiBaseUrl;return useMemo(()=>({async listRepos(t,s){let c=new URLSearchParams;(t||r)&&c.set("owner",t||r),s?.limit&&c.set("limit",String(s.limit)),s?.cursor&&c.set("cursor",s.cursor);let d=c.toString()?`?${c}`:"",u=await k(e,`/api/rack/repos${d}`,void 0,a);return {items:u.repos||[],pagination:u.pagination||{total:(u.repos||[]).length,limit:50,has_more:false,next_cursor:null}}},async initRepo(t){return k(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...t,owner_mid:r})},a)},async push(t,s){return k(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...s,author_mid:i})},a)},async getTree(t,s="main"){let c=await k(e,`/api/rack/${t}/tree/${s}`,void 0,a);return {tree:c.tree,commit_cid:c.commit_cid}},async getBlob(t,s){return (await k(e,`/api/rack/${t}/blob/${s}`,void 0,a)).content},async getLog(t,s,c){let d=new URLSearchParams;s&&d.set("ref",s),c&&d.set("max_count",String(c));let u=d.toString()?`?${d}`:"";return (await k(e,`/api/rack/${t}/log${u}`,void 0,a)).commits||[]},async getBranches(t){return (await k(e,`/api/rack/${t}/branches`,void 0,a)).branches||[]},async createBranch(t,s,c){return k(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:s,from_ref:c})},a)},async merge(t,s,c){return k(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:s,target_branch:c})},a)},async getDiff(t,s,c){return (await k(e,`/api/rack/${t}/diff/${s}/${c}`,void 0,a)).diff?.entries||[]},async starRepo(t){return k(e,`/api/rack/${t}/star`,{method:"POST"},a)},async unstarRepo(t){return k(e,`/api/rack/${t}/star`,{method:"DELETE"},a)},async getStarInfo(t){return k(e,`/api/rack/${t}/stars`,void 0,a)},async getSkillStats(t){let s={meta:null,tokenCount:null,usageCount:null};try{let{tree:c}=await this.getTree(t,"main");if(!c?.entries)return s;if(c.entries["META.json"]){let h=L(c.entries["META.json"]).cid,g=await this.getBlob(t,h);s.meta=JSON.parse(g);}let d=0,u=Object.values(c.entries).map(async h=>{try{let g=L(h).cid,m=await this.getBlob(t,g);d+=m.length;}catch{}});await Promise.all(u),d>0&&(s.tokenCount=Math.ceil(d/4)),s.meta?.skill_id&&(s.usageCount=await this.getSkillUsageCount(s.meta.skill_id));}catch{}return s},async getSkillUsageCount(t){try{let s=await fetch(`${l}/v1/skills/${encodeURIComponent(t)}`);if(s.ok){let d=await s.json();return d.usage_count??d.usageCount??null}let c=await fetch(`${l}/v1/skills?scope=public`);if(c.ok){let u=((await c.json()).skills||[]).find(h=>h.name===t||h.id===t);if(u)return u.usage_count??u.usageCount??0}return 0}catch{return null}},async getTensorStats(t){let s={meta:null,sizeMB:null};try{let{tree:c}=await this.getTree(t,"main");if(!c?.entries)return s;if(c.entries["TENSOR_META.json"]){let d=L(c.entries["TENSOR_META.json"]).cid,u=await this.getBlob(t,d);s.meta=JSON.parse(u),s.sizeMB=s.meta?.tensor_size_mb??null;}}catch{}return s},async getNetworkStats(){try{return (await k(e,"/api/rack/stats",void 0,a)).stats||null}catch{return null}},async getTrending(t=5,s=1,c){try{let d=new URLSearchParams({limit:String(t),days:String(s)});c&&d.set("cursor",c);let u=await k(e,`/api/rack/trending?${d}`,void 0,a);return {items:u.trending||[],pagination:u.pagination||{total:(u.trending||[]).length,limit:t,has_more:!1,next_cursor:null}}}catch{return {items:[],pagination:{total:0,limit:t,has_more:false,next_cursor:null}}}}}),[e,i,r,a,l])}function K(n,e={}){let{pageSize:i=50,owner:r}=e,a=z(n),[l,t]=useState([]),[s,c]=useState(null),[d,u]=useState(false),[h,g]=useState(null),m=useRef(null),b=useRef(true),v=useCallback(async(y,T=false)=>{u(true),g(null);try{let R=await a.listRepos(r,{limit:i,cursor:y||void 0});b.current&&(t(E=>T?[...E,...R.items]:R.items),c(R.pagination),m.current=R.pagination.next_cursor);}catch(R){b.current&&g(R.message);}finally{b.current&&u(false);}},[a,r,i]),S=useCallback(async()=>{!m.current||d||await v(m.current,true);},[v,d]),p=useCallback(async()=>{m.current=null,await v(void 0,false);},[v]);return useEffect(()=>(b.current=true,v(),()=>{b.current=false;}),[v]),{repos:l,hasMore:s?.has_more??false,total:s?.total??0,loading:d,error:h,loadMore:S,reset:p,pagination:s}}function be(n){return Object.entries(n).map(([e,i])=>{let r=i.indexOf(":"),a=r>0?i.slice(0,r):"100644",l=r>0?i.slice(r+1):i;return {path:e,mode:a,cid:l,isDir:a==="040000"}}).sort((e,i)=>e.isDir!==i.isDir?e.isDir?-1:1:e.path.localeCompare(i.path))}function Y(n,e,i="main"){let r=z(n),[a,l]=useState([]),[t,s]=useState(false),[c,d]=useState(null),u=useRef(true),h=useCallback(async()=>{if(e)try{u.current&&(s(!0),d(null));let{tree:m}=await r.getTree(e,i);u.current&&l(be(m.entries));}catch(m){u.current&&d(m instanceof Error?m.message:"Failed to load tree");}finally{u.current&&s(false);}},[r,e,i]);useEffect(()=>(u.current=true,h(),()=>{u.current=false;}),[h]);let g=useCallback(async m=>{if(!e)throw new Error("No repo selected");return r.getBlob(e,m)},[r,e]);return {entries:a,loading:t,error:c,refresh:h,getFileContent:g}}var ve=/^(https?:\/\/|mailto:|\/[^/])/i;function ye(n){let e=n.trim();return ve.test(e)?e:null}function _(n){let e=[],i=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,r=0,a,l=0;for(;(a=i.exec(n))!==null;){a.index>r&&e.push(n.slice(r,a.index));let t=`i${l++}`;if(a[1])e.push(jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[0.85em] font-mono text-pink-400",children:a[1].slice(1,-1)},t));else if(a[2])e.push(jsx("strong",{children:a[3]},t));else if(a[4])e.push(jsx("em",{children:a[5]},t));else if(a[6])e.push(jsx("em",{children:a[7]},t));else if(a[8]){let s=ye(a[10]);s?e.push(jsx("a",{href:s,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:a[9]},t)):e.push(a[9]);}r=a.index+a[0].length;}return r<n.length&&e.push(n.slice(r)),e.length>0?e:[n]}function ke(n){let e=n.split(`
2
+ `),i=[],r=0;for(;r<e.length;){let a=e[r];if(a.trim()===""){r++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(a.trim())){i.push({type:"hr"}),r++;continue}let l=a.match(/^(#{1,6})\s+(.+)/);if(l){i.push({type:"heading",level:l[1].length,content:l[2]}),r++;continue}if(a.trim().startsWith("```")){let s=a.trim().slice(3).trim(),c=[];for(r++;r<e.length&&!e[r].trim().startsWith("```");)c.push(e[r]),r++;i.push({type:"code",content:c.join(`
3
+ `),lang:s||void 0}),r++;continue}if(/^\s*[-*+]\s/.test(a)){let s=[];for(;r<e.length&&/^\s*[-*+]\s/.test(e[r]);)s.push(e[r].replace(/^\s*[-*+]\s+/,"")),r++;i.push({type:"ul",items:s});continue}if(/^\s*\d+[.)]\s/.test(a)){let s=[];for(;r<e.length&&/^\s*\d+[.)]\s/.test(e[r]);)s.push(e[r].replace(/^\s*\d+[.)]\s+/,"")),r++;i.push({type:"ol",items:s});continue}let t=[];for(;r<e.length&&e[r].trim()!==""&&!e[r].match(/^#{1,6}\s/)&&!e[r].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[r])&&!/^\s*\d+[.)]\s/.test(e[r]);)t.push(e[r]),r++;t.length>0&&i.push({type:"paragraph",content:t.join(" ")});}return i}var Ne={1:"text-2xl font-bold mt-6 mb-3",2:"text-xl font-bold mt-5 mb-2",3:"text-lg font-semibold mt-4 mb-2",4:"text-base font-semibold mt-3 mb-1",5:"text-sm font-semibold mt-2 mb-1",6:"text-sm font-medium mt-2 mb-1"};function Re(n,e){switch(n.type){case "hr":return jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let i=Math.min(Math.max(n.level||1,1),6),r=`h${i}`;return jsx(r,{className:C("text-foreground",Ne[i]),children:_(n.content||"")},`b${e}`)}case "paragraph":return jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:_(n.content||"")},`b${e}`);case "code":return jsx("pre",{className:"mb-3 overflow-x-auto rounded-lg bg-muted p-4 text-sm font-mono leading-relaxed text-foreground",children:jsx("code",{children:n.content})},`b${e}`);case "ul":return jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:n.items?.map((i,r)=>jsx("li",{className:"leading-relaxed",children:_(i)},`li${e}-${r}`))},`b${e}`);case "ol":return jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:n.items?.map((i,r)=>jsx("li",{className:"leading-relaxed",children:_(i)},`li${e}-${r}`))},`b${e}`);default:return null}}function D({content:n,className:e}){let i=ke(n);return jsx("div",{className:C("text-sm",e),children:i.map((r,a)=>Re(r,a))})}function ne({open:n,className:e}){return jsx("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:C("shrink-0 transition-transform duration-150",n?"rotate-0":"-rotate-90",e),children:jsx("path",{d:"M16.134 6.16a.5.5 0 1 1 .732.68l-6.5 7-.077.068a.5.5 0 0 1-.655-.068l-6.5-7-.062-.08a.5.5 0 0 1 .718-.667l.076.067L10 12.767z"})})}function X({size:n=20,className:e}){return jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function O({size:n=20,className:e}){return jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M15.147 4.146a.5.5 0 0 1 .707.707L10.707 10l5.147 5.147a.5.5 0 0 1-.63.771l-.078-.064L10 10.707l-5.146 5.147a.5.5 0 0 1-.708-.707L9.293 10 4.146 4.853a.5.5 0 0 1 .708-.707L10 9.293z"})})}function re({size:n=20,className:e}){return jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M10 3a.5.5 0 0 1 .5.5v6h6l.1.01a.5.5 0 0 1 0 .98l-.1.01h-6v6a.5.5 0 0 1-1 0v-6h-6a.5.5 0 0 1 0-1h6v-6A.5.5 0 0 1 10 3"})})}function Pe(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M6.5 3A2.5 2.5 0 0 0 4 5.5v9A2.5 2.5 0 0 0 6.5 17h7a2.5 2.5 0 0 0 2.5-2.5v-7A2.5 2.5 0 0 0 13.5 5H11V3.5a.5.5 0 0 0-1 0V5H6.5ZM5 5.5A1.5 1.5 0 0 1 6.5 4H9v1H6.5A1.5 1.5 0 0 0 5 6.5v8A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 13.5 6H11V4h2.5A2.5 2.5 0 0 1 16 6.5v8a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-9Z"})})}function Te(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M5.5 3A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h9a2.5 2.5 0 0 0 2.5-2.5v-9A2.5 2.5 0 0 0 14.5 3h-9ZM4 5.5A1.5 1.5 0 0 1 5.5 4h9A1.5 1.5 0 0 1 16 5.5v9a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 4 14.5v-9ZM7 7.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5Z"})})}function Ee(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M10 2a.5.5 0 0 1 .354.146l3 3a.5.5 0 0 1-.708.708L10.5 3.707V12.5a.5.5 0 0 1-1 0V3.707L7.354 5.854a.5.5 0 1 1-.708-.708l3-3A.5.5 0 0 1 10 2ZM4 13.5a.5.5 0 0 1 1 0v1A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-1a.5.5 0 0 1 1 0v1a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-1Z"})})}function se(){let[n,e]=useState(false);return useEffect(()=>{if(typeof window>"u")return;let i=()=>e(window.innerWidth<768);return i(),window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]),n}function oe({onClose:n,children:e,title:i}){let r=se(),a=useRef(n);return a.current=n,useEffect(()=>{let l=t=>{t.key==="Escape"&&a.current();};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[]),r?jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:n,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full max-h-[90vh] overflow-y-auto rounded-t-2xl bg-[#1a1a1a] p-5 pb-8 animate-in slide-in-from-bottom duration-200",onClick:l=>l.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-4 h-1 w-10 rounded-full bg-zinc-600"}),jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsx("h2",{className:"text-lg font-semibold text-foreground",children:i}),jsx("button",{onClick:n,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(O,{size:20})})]}),e]})]}):jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:n,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full max-w-lg overflow-y-auto rounded-2xl bg-[#1a1a1a] p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:l=>l.stopPropagation(),children:[jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsx("h2",{className:"text-lg font-semibold text-foreground",children:i}),jsx("button",{onClick:n,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(O,{size:20})})]}),e]})]})}function Me(n){let e=n.split(`
4
+ `),i="",r="",l=false;for(let t=0;t<e.length;t++){let s=e[t].trim();if(t===0&&s==="---"){l=true;continue}if(l){s==="---"&&(l=false,true);continue}if(!i){let c=s.match(/^#{1,2}\s+(.+)/);if(c){i=c[1].trim();continue}}if(i&&!r){if(!s||s.startsWith("#")||s==="---"||s==="***"||s==="___")continue;r=s.replace(/\*\*/g,"").replace(/`/g,"").trim();break}}return i?{title:i,description:r}:null}function $e({onClose:n,onCreated:e,config:i}){let[r,a]=useState(""),[l,t]=useState(""),[s,c]=useState(""),[d,u]=useState(false),[h,g]=useState(null),[m,b]=useState(false),v=p=>{if(c(p),!r.trim()&&!l.trim()&&p.trim().length>10){let y=Me(p);y&&(a(y.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")),t(y.description),b(true));}};return jsx(oe,{title:"Write skill instructions",onClose:n,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsx("input",{id:"skill-name",value:r,onChange:p=>a(p.target.value),placeholder:"weekly-status-report",className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-desc",className:"text-sm text-muted-foreground",children:"Description"}),jsx("textarea",{id:"skill-desc",value:l,onChange:p=>t(p.target.value),placeholder:"Generate weekly status reports from recent work.",rows:3,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-instructions",className:"text-sm text-muted-foreground",children:"Instructions"}),jsx("textarea",{id:"skill-instructions",value:s,onChange:p=>v(p.target.value),placeholder:"Summarize my recent work in three sections: wins, blockers, and next steps.",rows:8,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),h&&jsx("p",{className:"text-sm text-red-500",children:h}),jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsx("button",{onClick:n,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsx("button",{onClick:async()=>{if(r.trim()){u(true),g(null);try{let p=i.apiBaseUrl||"",y=m?s.trim():`# ${r.trim()}
4
5
 
5
- ${c.trim()}
6
+ ${l.trim()}
6
7
 
7
8
  ---
8
9
 
9
- ${a.trim()}`,N=await fetch(`${w}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.trim(),description:c.trim(),skill_md:S,content_type:"code"})});if(!N.ok){let C=`Failed to register skill (${N.status})`;try{let y=await N.json();y.error&&(C=y.error);}catch{}throw new Error(C)}e?.(),r();}catch(w){g(w instanceof Error?w.message:"Failed to create skill");}finally{u(false);}}},disabled:d||!s.trim(),className:"rounded-lg bg-zinc-600 px-4 py-2 text-sm font-medium text-white hover:bg-zinc-500 disabled:opacity-50",children:d?"Creating...":"Create"})]})]})})}function Se({onClose:r,onCreated:e,config:i}){let s=useRef(null),[o,c]=useState(false),[t,a]=useState(false),[l,d]=useState(null),u=async g=>{a(true),d(null);try{let f=await g.text(),w=i.apiBaseUrl||"",S=g.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),N=await fetch(`${w}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:S,skill_md:f,content_type:"code"})});if(!N.ok){let C=`Failed to register skill (${N.status})`;try{let y=await N.json();y.error&&(C=y.error);}catch{}throw new Error(C)}e?.(),r();}catch(f){d(f instanceof Error?f.message:"Upload failed");}finally{a(false);}};return jsx(ee,{title:"Upload skill",onClose:r,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{onDragOver:g=>{g.preventDefault(),c(true);},onDragLeave:()=>c(false),onDrop:g=>{g.preventDefault(),c(false);let f=g.dataTransfer.files[0];f&&u(f);},onClick:()=>s.current?.click(),className:k("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",o?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsx(Y,{size:20,className:"text-muted-foreground"})}),jsx("p",{className:"text-sm text-muted-foreground",children:t?"Uploading...":"Drag and drop or click to upload"})]}),jsx("input",{ref:s,type:"file",accept:".md,.zip,.skill,.txt,.yml,.yaml",className:"hidden","aria-label":"Upload skill file",onChange:g=>{let f=g.target.files?.[0];f&&u(f);}}),l&&jsx("p",{className:"text-sm text-red-500",children:l}),jsxs("div",{className:"space-y-2 text-xs text-muted-foreground",children:[jsx("p",{className:"font-medium text-foreground/70",children:"File requirements"}),jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[jsx("li",{children:".md file must contain skill name and description formatted in YAML"}),jsx("li",{children:".zip or .skill file must include a SKILL.md file"})]})]})]})})}function Te({onClose:r,onSelect:e}){let i=X(),s=useRef(null),o=useRef(r);o.current=r,useEffect(()=>{if(i)return;let t=a=>{s.current&&a.target instanceof Node&&!s.current.contains(a.target)&&o.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[i]);let c=[{id:"create-with-geoff",icon:jsx(ke,{}),label:"Create with Geoff"},{id:"write",icon:jsx(Ne,{}),label:"Write skill instructions"},{id:"upload",icon:jsx(Re,{}),label:"Upload a skill"}];return i?jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full rounded-t-2xl bg-[#1a1a1a] p-4 pb-8 animate-in slide-in-from-bottom duration-200",onClick:t=>t.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),c.map(t=>jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-800",children:[t.icon,t.label]},t.id))]})]}):jsx("div",{ref:s,className:"absolute right-2 top-11 z-50 w-56 overflow-hidden rounded-xl border border-zinc-700 bg-[#2a2a2a] shadow-xl animate-in fade-in zoom-in-95 duration-100",children:c.map(t=>jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[t.icon,t.label]},t.id))})}function Ee({entry:r,selected:e,onSelect:i,depth:s=0}){return jsxs("button",{onClick:()=>i(r),className:k("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+s*16}px`},children:[jsx("span",{className:"truncate flex-1",children:r.path.split("/").pop()}),r.isDir&&jsx(Q,{className:"ml-auto text-muted-foreground"})]})}function Pe({repo:r,selected:e,expanded:i,onSelect:s,onToggle:o,children:c}){return jsxs("div",{children:[jsxs("button",{onClick:()=>{s(),o();},className:k("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsx(Q,{open:i}),jsx(FileText,{className:"h-4 w-4 shrink-0"}),jsx("span",{className:"truncate",children:r.name})]}),i&&c]})}function Me({entry:r,content:e,loading:i,repoName:s}){let[o,c]=useState(false),t=useRef(null);useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[a,l]=useState(false),d=async()=>{if(e)try{await navigator.clipboard.writeText(e),c(!0),l(!1),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>c(!1),2e3);}catch{l(true),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>l(false),2e3);}};if(!r)return jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(i)return jsx("div",{className:"flex h-full items-center justify-center",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let u=r.path.split("/").pop()||r.path,p=/\.(md|mdx)$/i.test(u);return jsxs("div",{className:"flex h-full flex-col px-3",children:[jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[jsx("h3",{className:"text-sm sm:text-lg font-semibold text-foreground",children:u}),jsx("button",{onClick:d,"aria-label":"Copy file content",className:k("rounded p-1 transition-colors",o?"text-green-500":a?"text-red-500":"text-muted-foreground hover:text-foreground"),children:jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"})})})]}),jsx("div",{className:"flex-1 overflow-auto p-4",children:p?jsx(L,{content:e||""}):jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function ze({config:r,category:e,className:i,style:s}){let{repos:o,loading:c,error:t,refresh:a}=Z(r),[l,d]=useState(null),[u,p]=useState(null),[g,f]=useState(null),[w,S]=useState(null),[N,C]=useState(false),[y,U]=useState(""),[te,D]=useState(false),[O,j]=useState(false),[F,z]=useState(null),re=o.find(h=>h.repo_id===l),{entries:ne,getFileContent:H}=W(r,u),V=o.filter(h=>!y||h.name.toLowerCase().includes(y.toLowerCase())),se=useCallback(async h=>{if(!h.isDir){f(h),C(true);try{let R=await H(h.cid);S(R);}catch(R){let ae=R instanceof Error?R.message:"Unknown error";S(`Failed to load file: ${ae}`);}finally{C(false);}}},[H]);useEffect(()=>{o.length>0&&!l&&(d(o[0].repo_id),p(o[0].repo_id));},[o,l]);let oe=h=>{h==="create-with-geoff"?window.open(`https://www.geoff.ai/?p=${encodeURIComponent("Let's create a skill together using your skill-creator skill. First ask me what the skill should do.")}`,"_blank","noopener,noreferrer"):z(h);};return jsxs("div",{className:k("flex flex-1 h-full min-h-0",i),style:s,children:[jsxs("div",{className:"relative flex w-96 shrink-0 flex-col border-r",children:[jsx("div",{className:"flex h-12 items-center gap-2 px-3",children:te?jsxs(Fragment,{children:[jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-md border bg-muted/50 px-2 py-1",children:[jsx(q,{size:16,className:"shrink-0 text-muted-foreground"}),jsx("input",{type:"text",value:y,onChange:h=>U(h.target.value),placeholder:"Search",autoFocus:true,"aria-label":"Search items",className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),jsx("button",{onClick:()=>{D(false),U("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(B,{size:16})})]}):jsxs(Fragment,{children:[jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground capitalize",children:e||"Items"}),jsx("button",{onClick:()=>D(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsx(q,{size:20})}),jsx("button",{onClick:()=>j(!O),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(Y,{size:20})})]})}),O&&jsx(Te,{onClose:()=>j(false),onSelect:oe}),jsx("div",{className:"flex-1 overflow-y-auto p-2",children:c?jsx("div",{className:"flex items-center justify-center py-8",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):t?jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:t}):V.length===0?jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:y?"No matching items":"No items yet"}):jsx("div",{className:"space-y-0.5",children:V.map(h=>jsx(Pe,{repo:h,selected:l===h.repo_id,expanded:u===h.repo_id,onSelect:()=>{d(h.repo_id),f(null),S(null);},onToggle:()=>p(u===h.repo_id?null:h.repo_id),children:jsx("div",{className:"ml-10 pl-1",children:ne.map(R=>jsx(Ee,{entry:R,selected:g?.path===R.path,onSelect:se,depth:R.path.split("/").length-1},R.path))})},h.repo_id))})})]}),jsx("div",{className:"flex-1 min-w-0",children:jsx(Me,{entry:g,content:w,loading:N,repoName:re?.name||""})}),F==="write"&&jsx(Ce,{config:r,onClose:()=>z(null),onCreated:a}),F==="upload"&&jsx(Se,{config:r,onClose:()=>z(null),onCreated:a})]})}
10
- export{L as Markdown,ze as RackBrowser};
10
+ ${s.trim()}`,T=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.trim(),description:l.trim(),skill_md:y,content_type:"code"})});if(!T.ok){let R=`Failed to register skill (${T.status})`;try{let E=await T.json();E.error&&(R=E.error);}catch{}throw new Error(R)}e?.(),n();}catch(p){g(p instanceof Error?p.message:"Failed to create skill");}finally{u(false);}}},disabled:d||!r.trim(),className:"rounded-lg bg-zinc-600 px-4 py-2 text-sm font-medium text-white hover:bg-zinc-500 disabled:opacity-50",children:d?"Creating...":"Create"})]})]})})}function ze({onClose:n,onCreated:e,config:i}){let r=useRef(null),[a,l]=useState(false),[t,s]=useState(false),[c,d]=useState(null),u=async g=>{s(true),d(null);try{let m=await g.text(),b=i.apiBaseUrl||"",v=g.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),S=await fetch(`${b}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:v,skill_md:m,content_type:"code"})});if(!S.ok){let p=`Failed to register skill (${S.status})`;try{let y=await S.json();y.error&&(p=y.error);}catch{}throw new Error(p)}e?.(),n();}catch(m){d(m instanceof Error?m.message:"Upload failed");}finally{s(false);}};return jsx(oe,{title:"Upload skill",onClose:n,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{onDragOver:g=>{g.preventDefault(),l(true);},onDragLeave:()=>l(false),onDrop:g=>{g.preventDefault(),l(false);let m=g.dataTransfer.files[0];m&&u(m);},onClick:()=>r.current?.click(),className:C("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",a?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsx(re,{size:20,className:"text-muted-foreground"})}),jsx("p",{className:"text-sm text-muted-foreground",children:t?"Uploading...":"Drag and drop or click to upload"})]}),jsx("input",{ref:r,type:"file",accept:".md,.zip,.skill,.txt,.yml,.yaml",className:"hidden","aria-label":"Upload skill file",onChange:g=>{let m=g.target.files?.[0];m&&u(m);}}),c&&jsx("p",{className:"text-sm text-red-500",children:c}),jsxs("div",{className:"space-y-2 text-xs text-muted-foreground",children:[jsx("p",{className:"font-medium text-foreground/70",children:"File requirements"}),jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[jsx("li",{children:".md file must contain skill name and description formatted in YAML"}),jsx("li",{children:".zip or .skill file must include a SKILL.md file"})]})]})]})})}function Ie({onClose:n,onSelect:e}){let i=se(),r=useRef(null),a=useRef(n);a.current=n,useEffect(()=>{if(i)return;let t=s=>{r.current&&s.target instanceof Node&&!r.current.contains(s.target)&&a.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[i]);let l=[{id:"create-with-geoff",icon:jsx(Pe,{}),label:"Create with Geoff"},{id:"write",icon:jsx(Te,{}),label:"Write skill instructions"},{id:"upload",icon:jsx(Ee,{}),label:"Upload a skill"}];return i?jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:n,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full rounded-t-2xl bg-[#1a1a1a] p-4 pb-8 animate-in slide-in-from-bottom duration-200",onClick:t=>t.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),l.map(t=>jsxs("button",{onClick:()=>{e(t.id),n();},className:"flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-800",children:[t.icon,t.label]},t.id))]})]}):jsx("div",{ref:r,className:"absolute right-2 top-11 z-50 w-56 overflow-hidden rounded-xl border border-zinc-700 bg-[#2a2a2a] shadow-xl animate-in fade-in zoom-in-95 duration-100",children:l.map(t=>jsxs("button",{onClick:()=>{e(t.id),n();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[t.icon,t.label]},t.id))})}function _e({entry:n,selected:e,onSelect:i,depth:r=0}){return jsxs("button",{onClick:()=>i(n),className:C("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+r*16}px`},children:[jsx("span",{className:"truncate flex-1",children:n.path.split("/").pop()}),n.isDir&&jsx(ne,{className:"ml-auto text-muted-foreground"})]})}function Be({repo:n,selected:e,expanded:i,onSelect:r,onToggle:a,children:l}){return jsxs("div",{children:[jsxs("button",{onClick:()=>{r(),a();},className:C("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsx(ne,{open:i}),jsx(FileText,{className:"h-4 w-4 shrink-0"}),jsx("span",{className:"truncate",children:n.name})]}),i&&l]})}function Le({entry:n,content:e,loading:i,repoName:r}){let[a,l]=useState(false),t=useRef(null);useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[s,c]=useState(false),d=async()=>{if(e)try{await navigator.clipboard.writeText(e),l(!0),c(!1),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>l(!1),2e3);}catch{c(true),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>c(false),2e3);}};if(!n)return jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(i)return jsx("div",{className:"flex h-full items-center justify-center",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let u=n.path.split("/").pop()||n.path,h=/\.(md|mdx)$/i.test(u);return jsxs("div",{className:"flex h-full flex-col px-3",children:[jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[jsx("h3",{className:"text-sm sm:text-lg font-semibold text-foreground",children:u}),jsx("button",{onClick:d,"aria-label":"Copy file content",className:C("rounded p-1 transition-colors",a?"text-green-500":s?"text-red-500":"text-muted-foreground hover:text-foreground"),children:jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"})})})]}),jsx("div",{className:"flex-1 overflow-auto p-4",children:h?jsx(D,{content:e||""}):jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function Ae({config:n,category:e,className:i,style:r}){let{repos:a,loading:l,error:t,reset:d}=K(n,{pageSize:50}),[u,h]=useState(null),[g,m]=useState(null),[b,v]=useState(null),[S,p]=useState(null),[y,T]=useState(false),[R,E]=useState(""),[ie,H]=useState(false),[W,J]=useState(false),[V,B]=useState(null),le=a.find(w=>w.repo_id===u),{entries:ce,getFileContent:Z}=Y(n,g),q=a.filter(w=>!R||w.name.toLowerCase().includes(R.toLowerCase())),ue=useCallback(async w=>{if(!w.isDir){v(w),T(true);try{let P=await Z(w.cid);p(P);}catch(P){let me=P instanceof Error?P.message:"Unknown error";p(`Failed to load file: ${me}`);}finally{T(false);}}},[Z]);useEffect(()=>{a.length>0&&!u&&(h(a[0].repo_id),m(a[0].repo_id));},[a,u]);let de=w=>{w==="create-with-geoff"?window.open(`https://www.geoff.ai/?p=${encodeURIComponent("Let's create a skill together using your skill-creator skill. First ask me what the skill should do.")}`,"_blank","noopener,noreferrer"):B(w);};return jsxs("div",{className:C("flex flex-1 h-full min-h-0",i),style:r,children:[jsxs("div",{className:"relative flex w-96 shrink-0 flex-col border-r",children:[jsx("div",{className:"flex h-12 items-center gap-2 px-3",children:ie?jsxs(Fragment,{children:[jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-md border bg-muted/50 px-2 py-1",children:[jsx(X,{size:16,className:"shrink-0 text-muted-foreground"}),jsx("input",{type:"text",value:R,onChange:w=>E(w.target.value),placeholder:"Search",autoFocus:true,"aria-label":"Search items",className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),jsx("button",{onClick:()=>{H(false),E("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(O,{size:16})})]}):jsxs(Fragment,{children:[jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground capitalize",children:e||"Items"}),jsx("button",{onClick:()=>H(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsx(X,{size:20})}),jsx("button",{onClick:()=>J(!W),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(re,{size:20})})]})}),W&&jsx(Ie,{onClose:()=>J(false),onSelect:de}),jsx("div",{className:"flex-1 overflow-y-auto p-2",children:l?jsx("div",{className:"flex items-center justify-center py-8",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):t?jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:t}):q.length===0?jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:R?"No matching items":"No items yet"}):jsx("div",{className:"space-y-0.5",children:q.map(w=>jsx(Be,{repo:w,selected:u===w.repo_id,expanded:g===w.repo_id,onSelect:()=>{h(w.repo_id),v(null),p(null);},onToggle:()=>m(g===w.repo_id?null:w.repo_id),children:jsx("div",{className:"ml-10 pl-1",children:ce.map(P=>jsx(_e,{entry:P,selected:b?.path===P.path,onSelect:ue,depth:P.path.split("/").length-1},P.path))})},w.repo_id))})})]}),jsx("div",{className:"flex-1 min-w-0",children:jsx(Le,{entry:b,content:S,loading:y,repoName:le?.name||""})}),V==="write"&&jsx($e,{config:n,onClose:()=>B(null),onCreated:d}),V==="upload"&&jsx(ze,{config:n,onClose:()=>B(null),onCreated:d})]})}async function ae(n,e,i,r){let a={"Content-Type":"application/json",...i?.headers};r&&(a.Authorization=`Bearer ${r}`);let l=await fetch(`${n}${e}`,{...i,headers:a});if(!l.ok){let t=`HTTP ${l.status}`;try{let s=await l.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return l.json()}function je({config:n,repoId:e,onAuthRequired:i,className:r,style:a}){let l=n.apiBaseUrl,t=n.apiKey,[s,c]=useState({stars:0,starred:false,repo_id:e}),[d,u]=useState(false),[h,g]=useState(null),m=useRef(true),b=l.includes("/cpx/rack")?"":"/api/rack";useEffect(()=>(m.current=true,ae(l,`${b}/${e}/stars`,void 0,t).then(S=>{m.current&&c(S);}).catch(()=>{}),()=>{m.current=false;}),[l,e,t,b]);let v=useCallback(async S=>{if(S.preventDefault(),S.stopPropagation(),!t){i?.();return}u(true),g(null);try{let p=s.starred?"DELETE":"POST",y=await ae(l,`${b}/${e}/star`,{method:p},t);m.current&&c({stars:y.stars,starred:y.starred,repo_id:e});}catch(p){m.current&&g(p.message);}finally{m.current&&u(false);}},[l,e,t,s.starred,i]);return jsxs("button",{onClick:v,disabled:d,title:h||(s.starred?"Unstar (100k tokens)":"Star (100k tokens)"),className:r,style:{display:"inline-flex",alignItems:"center",gap:"4px",background:"none",border:"none",cursor:d?"wait":"pointer",padding:"4px 8px",fontSize:"12px",fontFamily:"inherit",color:s.starred?"#f59e0b":"#91918d",transition:"color 150ms",opacity:d?.5:1,...a},children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:s.starred?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})}),jsx("span",{children:s.stars})]})}
11
+ export{D as Markdown,Ae as RackBrowser,je as StarButton};
package/dist/index.cjs CHANGED
@@ -1,10 +1,11 @@
1
- 'use strict';var react=require('react'),lucideReact=require('lucide-react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');async function v(r,e,o,n){let s={"Content-Type":"application/json",...o?.headers};n&&(s.Authorization=`Bearer ${n}`);let f=await fetch(`${r}${e}`,{...o,headers:s});if(!f.ok){let t=`HTTP ${f.status}`;try{let a=await f.json();a.error&&(t=a.error);}catch{}throw new Error(t)}return f.json()}function B(r){let e=r.indexOf(":");return {mode:r.slice(0,e),cid:r.slice(e+1)}}function b(r){let e=r.apiBaseUrl,o=r.authorMid,n=r.ownerMid,s=r.apiKey,f=r.stacknetUrl||r.apiBaseUrl;return react.useMemo(()=>({async listRepos(t,a){let l=new URLSearchParams;(t||n)&&l.set("owner",t||n),a?.limit&&l.set("limit",String(a.limit)),a?.cursor&&l.set("cursor",a.cursor);let c=l.toString()?`?${l}`:"",u=await v(e,`/api/rack/repos${c}`,void 0,s);return {items:u.repos||[],pagination:u.pagination||{total:(u.repos||[]).length,limit:50,has_more:false,next_cursor:null}}},async initRepo(t){return v(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...t,owner_mid:n})},s)},async push(t,a){return v(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...a,author_mid:o})},s)},async getTree(t,a="main"){let l=await v(e,`/api/rack/${t}/tree/${a}`,void 0,s);return {tree:l.tree,commit_cid:l.commit_cid}},async getBlob(t,a){return (await v(e,`/api/rack/${t}/blob/${a}`,void 0,s)).content},async getLog(t,a,l){let c=new URLSearchParams;a&&c.set("ref",a),l&&c.set("max_count",String(l));let u=c.toString()?`?${c}`:"";return (await v(e,`/api/rack/${t}/log${u}`,void 0,s)).commits||[]},async getBranches(t){return (await v(e,`/api/rack/${t}/branches`,void 0,s)).branches||[]},async createBranch(t,a,l){return v(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:a,from_ref:l})},s)},async merge(t,a,l){return v(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:a,target_branch:l})},s)},async getDiff(t,a,l){return (await v(e,`/api/rack/${t}/diff/${a}/${l}`,void 0,s)).diff?.entries||[]},async starRepo(t){return v(e,`/api/rack/${t}/star`,{method:"POST"},s)},async unstarRepo(t){return v(e,`/api/rack/${t}/star`,{method:"DELETE"},s)},async getStarInfo(t){return v(e,`/api/rack/${t}/stars`,void 0,s)},async getSkillStats(t){let a={meta:null,tokenCount:null,usageCount:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return a;if(l.entries["META.json"]){let m=B(l.entries["META.json"]).cid,d=await this.getBlob(t,m);a.meta=JSON.parse(d);}let c=0,u=Object.values(l.entries).map(async m=>{try{let d=B(m).cid,g=await this.getBlob(t,d);c+=g.length;}catch{}});await Promise.all(u),c>0&&(a.tokenCount=Math.ceil(c/4)),a.meta?.skill_id&&(a.usageCount=await this.getSkillUsageCount(a.meta.skill_id));}catch{}return a},async getSkillUsageCount(t){try{let a=await fetch(`${f}/v1/skills/${encodeURIComponent(t)}`);if(a.ok){let c=await a.json();return c.usage_count??c.usageCount??null}let l=await fetch(`${f}/v1/skills?scope=public`);if(l.ok){let u=((await l.json()).skills||[]).find(m=>m.name===t||m.id===t);if(u)return u.usage_count??u.usageCount??0}return 0}catch{return null}},async getTensorStats(t){let a={meta:null,sizeMB:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return a;if(l.entries["TENSOR_META.json"]){let c=B(l.entries["TENSOR_META.json"]).cid,u=await this.getBlob(t,c);a.meta=JSON.parse(u),a.sizeMB=a.meta?.tensor_size_mb??null;}}catch{}return a},async getNetworkStats(){try{return (await v(e,"/api/rack/stats",void 0,s)).stats||null}catch{return null}},async getTrending(t=5,a=1,l){try{let c=new URLSearchParams({limit:String(t),days:String(a)});l&&c.set("cursor",l);let u=await v(e,`/api/rack/trending?${c}`,void 0,s);return {items:u.trending||[],pagination:u.pagination||{total:(u.trending||[]).length,limit:t,has_more:!1,next_cursor:null}}}catch{return {items:[],pagination:{total:0,limit:t,has_more:false,next_cursor:null}}}}}),[e,o,n,s,f])}function D(r){let e=b(r),o=react.useRef(e);o.current=e;let[n,s]=react.useState([]),[f,t]=react.useState(true),[a,l]=react.useState(null),c=react.useRef(true),u=react.useRef(null),m=react.useCallback(async()=>{u.current?.abort();let d=new AbortController;u.current=d;try{c.current&&(t(!0),l(null));let g=await o.current.listRepos();c.current&&!d.signal.aborted&&s(g.items);}catch(g){c.current&&!d.signal.aborted&&l(g instanceof Error?g.message:"Failed to load repos");}finally{c.current&&!d.signal.aborted&&t(false);}},[]);return react.useEffect(()=>(c.current=true,m(),()=>{c.current=false,u.current?.abort();}),[m]),{repos:n,loading:f,error:a,refresh:m}}function $e(r){return Object.entries(r).map(([e,o])=>{let n=o.indexOf(":"),s=n>0?o.slice(0,n):"100644",f=n>0?o.slice(n+1):o;return {path:e,mode:s,cid:f,isDir:s==="040000"}}).sort((e,o)=>e.isDir!==o.isDir?e.isDir?-1:1:e.path.localeCompare(o.path))}function H(r,e,o="main"){let n=b(r),[s,f]=react.useState([]),[t,a]=react.useState(false),[l,c]=react.useState(null),u=react.useRef(true),m=react.useCallback(async()=>{if(e)try{u.current&&(a(!0),c(null));let{tree:g}=await n.getTree(e,o);u.current&&f($e(g.entries));}catch(g){u.current&&c(g instanceof Error?g.message:"Failed to load tree");}finally{u.current&&a(false);}},[n,e,o]);react.useEffect(()=>(u.current=true,m(),()=>{u.current=false;}),[m]);let d=react.useCallback(async g=>{if(!e)throw new Error("No repo selected");return n.getBlob(e,g)},[n,e]);return {entries:s,loading:t,error:l,refresh:m,getFileContent:d}}function Ae(r){let e=b(r),[o,n]=react.useState(false),[s,f]=react.useState(null),t=react.useRef(true);return react.useEffect(()=>(t.current=true,()=>{t.current=false;}),[]),{push:react.useCallback(async(l,c,u,m)=>{try{return t.current&&(n(!0),f(null)),await e.push(l,{files:c,message:u,branch:m})}catch(d){let g=d instanceof Error?d.message:"Push failed";return t.current&&f(g),null}finally{t.current&&n(false);}},[e]),pushing:o,error:s}}function Oe(r,e={}){let{pageSize:o=50,owner:n}=e,s=b(r),[f,t]=react.useState([]),[a,l]=react.useState(null),[c,u]=react.useState(false),[m,d]=react.useState(null),g=react.useRef(null),p=react.useRef(true),x=react.useCallback(async(C,I=false)=>{u(true),d(null);try{let P=await s.listRepos(n,{limit:o,cursor:C||void 0});p.current&&(t(M=>I?[...M,...P.items]:P.items),l(P.pagination),g.current=P.pagination.next_cursor);}catch(P){p.current&&d(P.message);}finally{p.current&&u(false);}},[s,n,o]),w=react.useCallback(async()=>{!g.current||c||await x(g.current,true);},[x,c]),R=react.useCallback(async()=>{g.current=null,await x(void 0,false);},[x]);return react.useEffect(()=>(p.current=true,x(),()=>{p.current=false;}),[x]),{repos:f,hasMore:a?.has_more??false,total:a?.total??0,loading:c,error:m,loadMore:w,reset:R,pagination:a}}var J="stacknet-rack-apikey";function De(r){let e=r.stacknetUrl||r.apiBaseUrl,[o,n]=react.useState({authenticated:false}),[s,f]=react.useState(null),[t,a]=react.useState(false),l=react.useCallback(d=>({"Content-Type":"application/json",...d||r.apiKey?{Authorization:`Bearer ${d||r.apiKey}`}:{}}),[r.apiKey]),c=react.useCallback(async d=>{a(true);try{let g=await fetch(`${e}/health`,{headers:l(d)});if(!g.ok)throw new Error(`Authentication failed: ${g.status}`);let p={authenticated:!0,apiKey:d,permission:d.startsWith("gk_")?"write":"read"};n(p);try{localStorage.setItem(J,d);}catch{}return p}catch(g){throw n({authenticated:false}),g}finally{a(false);}},[e,l]),u=react.useCallback(()=>{n({authenticated:false}),f(null);try{localStorage.removeItem(J);}catch{}},[]),m=react.useCallback(async()=>{let d=o.apiKey||r.apiKey;if(!d)return null;try{let g=await fetch(`${e}/network/usage`,{headers:l(d)});if(!g.ok)return null;let p=await g.json(),x={planAllocation:p.plan_allocation??p.planAllocation??0,inferenceUsed:p.inference_used??p.inferenceUsed??0,ledgerSpent:p.ledger_spent??p.ledgerSpent??0,totalUsed:p.total_used??p.totalUsed??0,remaining:p.remaining??0,percent:p.percent??0,exceeded:p.exceeded??!1};return f(x),x}catch{return null}},[o.apiKey,r.apiKey,e,l]);return react.useEffect(()=>{let d=r.apiKey;if(d){n({authenticated:true,apiKey:d,permission:d.startsWith("gk_")?"write":"read"});return}try{let g=localStorage.getItem(J);g&&n({authenticated:!0,apiKey:g,permission:g.startsWith("gk_")?"write":"read"});}catch{}},[r.apiKey]),{session:o,budget:s,loading:t,login:c,logout:u,refreshBudget:m}}var ce=1e3,ue=1e3,de=100;function fe(r,e){if(r==="skill"){let s=de+Math.ceil(e/4);return {type:r,totalBytes:e,totalMegabytes:e/1e6,baseCost:s,multiplier:ce,registrationCostTokens:s*ce}}let o=Math.ceil(e/1e6),n=de+o;return {type:r,totalBytes:e,totalMegabytes:o,baseCost:n,multiplier:ue,registrationCostTokens:n*ue}}function Fe(r){let e=r.stacknetUrl||r.apiBaseUrl,o=r.apiKey,[n,s]=react.useState(false),[f,t]=react.useState(null),a=react.useCallback(()=>{if(!o)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${o}`}},[o]),l=react.useCallback(async u=>{s(true),t(null);try{let m=await fetch(`${e}/skills`,{method:"POST",headers:a(),body:JSON.stringify(u)});if(!m.ok){let d=await m.json().catch(()=>({error:`HTTP ${m.status}`}));throw new Error(d.error||`Registration failed: ${m.status}`)}return await m.json()}catch(m){throw t(m.message),m}finally{s(false);}},[e,a]),c=react.useCallback(async u=>{s(true),t(null);try{let m=await fetch(`${e}/tensors`,{method:"POST",headers:a(),body:JSON.stringify(u)});if(!m.ok){let d=await m.json().catch(()=>({error:`HTTP ${m.status}`}));throw new Error(d.error||`Registration failed: ${m.status}`)}return await m.json()}catch(m){throw t(m.message),m}finally{s(false);}},[e,a]);return {registerSkill:l,registerTensor:c,estimateCost:fe,registering:n,error:f}}function Je(r,e){let o=b(r),[n,s]=react.useState({meta:null,tokenCount:null,usageCount:null}),[f,t]=react.useState(false),[a,l]=react.useState(null),c=react.useRef(true),u=react.useCallback(async()=>{if(e){t(true),l(null);try{let m=await o.getSkillStats(e);c.current&&s(m);}catch(m){c.current&&l(m.message);}finally{c.current&&t(false);}}},[o,e]);return react.useEffect(()=>(c.current=true,u(),()=>{c.current=false;}),[u]),{stats:n,loading:f,error:a,refresh:u}}function Ge(r,e){let o=b(r),[n,s]=react.useState({meta:null,sizeMB:null}),[f,t]=react.useState(false),[a,l]=react.useState(null),c=react.useRef(true),u=react.useCallback(async()=>{if(e){t(true),l(null);try{let m=await o.getTensorStats(e);c.current&&s(m);}catch(m){c.current&&l(m.message);}finally{c.current&&t(false);}}},[o,e]);return react.useEffect(()=>(c.current=true,u(),()=>{c.current=false;}),[u]),{stats:n,loading:f,error:a,refresh:u}}function et(r){let e=b(r),[o,n]=react.useState(null),[s,f]=react.useState(false),[t,a]=react.useState(null),l=react.useRef(true),c=react.useCallback(async()=>{f(true),a(null);try{let u=await e.getNetworkStats();l.current&&n(u);}catch(u){l.current&&a(u.message);}finally{l.current&&f(false);}},[e]);return react.useEffect(()=>(l.current=true,c(),()=>{l.current=false;}),[c]),{stats:o,loading:s,error:t,refresh:c}}function rt(r,e=5,o=1){let n=b(r),[s,f]=react.useState([]),[t,a]=react.useState(null),[l,c]=react.useState(false),[u,m]=react.useState(null),d=react.useRef(true),g=react.useRef(null),p=react.useCallback(async w=>{c(true),m(null),g.current=null;try{let R=await n.getTrending(e,w??o);d.current&&(f(R.items),a(R.pagination),g.current=R.pagination.next_cursor);}catch(R){d.current&&m(R.message);}finally{d.current&&c(false);}},[n,e,o]),x=react.useCallback(async()=>{if(!(!g.current||l)){c(true);try{let w=await n.getTrending(e,o,g.current);d.current&&(f(R=>[...R,...w.items]),a(w.pagination),g.current=w.pagination.next_cursor);}catch(w){d.current&&m(w.message);}finally{d.current&&c(false);}}},[n,e,o,l]);return react.useEffect(()=>(d.current=true,p(),()=>{d.current=false;}),[p]),{repos:s,hasMore:t?.has_more??false,total:t?.total??0,loading:l,error:u,refresh:p,loadMore:x}}function ot(r,e){let o=b(r),[n,s]=react.useState({stars:0,starred:false,repo_id:e||""}),[f,t]=react.useState(false),[a,l]=react.useState(null),c=react.useRef(true),u=react.useCallback(async()=>{if(e)try{let d=await o.getStarInfo(e);c.current&&s(d);}catch{}},[o,e]);react.useEffect(()=>(c.current=true,u(),()=>{c.current=false;}),[u]);let m=react.useCallback(async()=>{if(e){t(true),l(null);try{let d=n.starred?await o.unstarRepo(e):await o.starRepo(e);c.current&&s({stars:d.stars,starred:d.starred,repo_id:e});}catch(d){c.current&&l(d.message);}finally{c.current&&t(false);}}},[o,e,n.starred]);return {...n,loading:f,error:a,toggle:m,refresh:u}}function N(...r){return tailwindMerge.twMerge(clsx.clsx(r))}var lt=/^(https?:\/\/|mailto:|\/[^/])/i;function ct(r){let e=r.trim();return lt.test(e)?e:null}function U(r){let e=[],o=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,n=0,s,f=0;for(;(s=o.exec(r))!==null;){s.index>n&&e.push(r.slice(n,s.index));let t=`i${f++}`;if(s[1])e.push(jsxRuntime.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[0.85em] font-mono text-pink-400",children:s[1].slice(1,-1)},t));else if(s[2])e.push(jsxRuntime.jsx("strong",{children:s[3]},t));else if(s[4])e.push(jsxRuntime.jsx("em",{children:s[5]},t));else if(s[6])e.push(jsxRuntime.jsx("em",{children:s[7]},t));else if(s[8]){let a=ct(s[10]);a?e.push(jsxRuntime.jsx("a",{href:a,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:s[9]},t)):e.push(s[9]);}n=s.index+s[0].length;}return n<r.length&&e.push(r.slice(n)),e.length>0?e:[r]}function ut(r){let e=r.split(`
2
- `),o=[],n=0;for(;n<e.length;){let s=e[n];if(s.trim()===""){n++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(s.trim())){o.push({type:"hr"}),n++;continue}let f=s.match(/^(#{1,6})\s+(.+)/);if(f){o.push({type:"heading",level:f[1].length,content:f[2]}),n++;continue}if(s.trim().startsWith("```")){let a=s.trim().slice(3).trim(),l=[];for(n++;n<e.length&&!e[n].trim().startsWith("```");)l.push(e[n]),n++;o.push({type:"code",content:l.join(`
3
- `),lang:a||void 0}),n++;continue}if(/^\s*[-*+]\s/.test(s)){let a=[];for(;n<e.length&&/^\s*[-*+]\s/.test(e[n]);)a.push(e[n].replace(/^\s*[-*+]\s+/,"")),n++;o.push({type:"ul",items:a});continue}if(/^\s*\d+[.)]\s/.test(s)){let a=[];for(;n<e.length&&/^\s*\d+[.)]\s/.test(e[n]);)a.push(e[n].replace(/^\s*\d+[.)]\s+/,"")),n++;o.push({type:"ol",items:a});continue}let t=[];for(;n<e.length&&e[n].trim()!==""&&!e[n].match(/^#{1,6}\s/)&&!e[n].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[n])&&!/^\s*\d+[.)]\s/.test(e[n]);)t.push(e[n]),n++;t.length>0&&o.push({type:"paragraph",content:t.join(" ")});}return o}var dt={1:"text-2xl font-bold mt-6 mb-3",2:"text-xl font-bold mt-5 mb-2",3:"text-lg font-semibold mt-4 mb-2",4:"text-base font-semibold mt-3 mb-1",5:"text-sm font-semibold mt-2 mb-1",6:"text-sm font-medium mt-2 mb-1"};function ft(r,e){switch(r.type){case "hr":return jsxRuntime.jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let o=Math.min(Math.max(r.level||1,1),6),n=`h${o}`;return jsxRuntime.jsx(n,{className:N("text-foreground",dt[o]),children:U(r.content||"")},`b${e}`)}case "paragraph":return jsxRuntime.jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:U(r.content||"")},`b${e}`);case "code":return jsxRuntime.jsx("pre",{className:"mb-3 overflow-x-auto rounded-lg bg-muted p-4 text-sm font-mono leading-relaxed text-foreground",children:jsxRuntime.jsx("code",{children:r.content})},`b${e}`);case "ul":return jsxRuntime.jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:r.items?.map((o,n)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:U(o)},`li${e}-${n}`))},`b${e}`);case "ol":return jsxRuntime.jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:r.items?.map((o,n)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:U(o)},`li${e}-${n}`))},`b${e}`);default:return null}}function Q({content:r,className:e}){let o=ut(r);return jsxRuntime.jsx("div",{className:N("text-sm",e),children:o.map((n,s)=>ft(n,s))})}function xe({open:r,className:e}){return jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:N("shrink-0 transition-transform duration-150",r?"rotate-0":"-rotate-90",e),children:jsxRuntime.jsx("path",{d:"M16.134 6.16a.5.5 0 1 1 .732.68l-6.5 7-.077.068a.5.5 0 0 1-.655-.068l-6.5-7-.062-.08a.5.5 0 0 1 .718-.667l.076.067L10 12.767z"})})}function he({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function X({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M15.147 4.146a.5.5 0 0 1 .707.707L10.707 10l5.147 5.147a.5.5 0 0 1-.63.771l-.078-.064L10 10.707l-5.146 5.147a.5.5 0 0 1-.708-.707L9.293 10 4.146 4.853a.5.5 0 0 1 .708-.707L10 9.293z"})})}function we({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M10 3a.5.5 0 0 1 .5.5v6h6l.1.01a.5.5 0 0 1 0 .98l-.1.01h-6v6a.5.5 0 0 1-1 0v-6h-6a.5.5 0 0 1 0-1h6v-6A.5.5 0 0 1 10 3"})})}function pt(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M6.5 3A2.5 2.5 0 0 0 4 5.5v9A2.5 2.5 0 0 0 6.5 17h7a2.5 2.5 0 0 0 2.5-2.5v-7A2.5 2.5 0 0 0 13.5 5H11V3.5a.5.5 0 0 0-1 0V5H6.5ZM5 5.5A1.5 1.5 0 0 1 6.5 4H9v1H6.5A1.5 1.5 0 0 0 5 6.5v8A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 13.5 6H11V4h2.5A2.5 2.5 0 0 1 16 6.5v8a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-9Z"})})}function ht(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M5.5 3A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h9a2.5 2.5 0 0 0 2.5-2.5v-9A2.5 2.5 0 0 0 14.5 3h-9ZM4 5.5A1.5 1.5 0 0 1 5.5 4h9A1.5 1.5 0 0 1 16 5.5v9a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 4 14.5v-9ZM7 7.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5Z"})})}function yt(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M10 2a.5.5 0 0 1 .354.146l3 3a.5.5 0 0 1-.708.708L10.5 3.707V12.5a.5.5 0 0 1-1 0V3.707L7.354 5.854a.5.5 0 1 1-.708-.708l3-3A.5.5 0 0 1 10 2ZM4 13.5a.5.5 0 0 1 1 0v1A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-1a.5.5 0 0 1 1 0v1a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-1Z"})})}function be(){let[r,e]=react.useState(false);return react.useEffect(()=>{if(typeof window>"u")return;let o=()=>e(window.innerWidth<768);return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),r}function Re({onClose:r,children:e,title:o}){let n=be(),s=react.useRef(r);return s.current=r,react.useEffect(()=>{let f=t=>{t.key==="Escape"&&s.current();};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[]),n?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full max-h-[90vh] overflow-y-auto rounded-t-2xl bg-[#1a1a1a] p-5 pb-8 animate-in slide-in-from-bottom duration-200",onClick:f=>f.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-4 h-1 w-10 rounded-full bg-zinc-600"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-foreground",children:o}),jsxRuntime.jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(X,{size:20})})]}),e]})]}):jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full max-w-lg overflow-y-auto rounded-2xl bg-[#1a1a1a] p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:f=>f.stopPropagation(),children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-foreground",children:o}),jsxRuntime.jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(X,{size:20})})]}),e]})]})}function kt({onClose:r,onCreated:e,config:o}){let[n,s]=react.useState(""),[f,t]=react.useState(""),[a,l]=react.useState(""),[c,u]=react.useState(false),[m,d]=react.useState(null);return jsxRuntime.jsx(Re,{title:"Write skill instructions",onClose:r,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsxRuntime.jsx("input",{id:"skill-name",value:n,onChange:p=>s(p.target.value),placeholder:"weekly-status-report",className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-desc",className:"text-sm text-muted-foreground",children:"Description"}),jsxRuntime.jsx("textarea",{id:"skill-desc",value:f,onChange:p=>t(p.target.value),placeholder:"Generate weekly status reports from recent work.",rows:3,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-instructions",className:"text-sm text-muted-foreground",children:"Instructions"}),jsxRuntime.jsx("textarea",{id:"skill-instructions",value:a,onChange:p=>l(p.target.value),placeholder:"Summarize my recent work in three sections: wins, blockers, and next steps.",rows:8,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),m&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:m}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsxRuntime.jsx("button",{onClick:r,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsxRuntime.jsx("button",{onClick:async()=>{if(n.trim()){u(true),d(null);try{let p=o.apiBaseUrl||"",x=`# ${n.trim()}
1
+ 'use strict';var react=require('react'),lucideReact=require('lucide-react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');async function S(r,e,o,n){let a={"Content-Type":"application/json",...o?.headers};n&&(a.Authorization=`Bearer ${n}`);let c=await fetch(`${r}${e}`,{...o,headers:a});if(!c.ok){let t=`HTTP ${c.status}`;try{let s=await c.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return c.json()}function A(r){let e=r.indexOf(":");return {mode:r.slice(0,e),cid:r.slice(e+1)}}function R(r){let e=r.apiBaseUrl,o=r.authorMid,n=r.ownerMid,a=r.apiKey,c=r.stacknetUrl||r.apiBaseUrl;return react.useMemo(()=>({async listRepos(t,s){let i=new URLSearchParams;(t||n)&&i.set("owner",t||n),s?.limit&&i.set("limit",String(s.limit)),s?.cursor&&i.set("cursor",s.cursor);let u=i.toString()?`?${i}`:"",d=await S(e,`/api/rack/repos${u}`,void 0,a);return {items:d.repos||[],pagination:d.pagination||{total:(d.repos||[]).length,limit:50,has_more:false,next_cursor:null}}},async initRepo(t){return S(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...t,owner_mid:n})},a)},async push(t,s){return S(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...s,author_mid:o})},a)},async getTree(t,s="main"){let i=await S(e,`/api/rack/${t}/tree/${s}`,void 0,a);return {tree:i.tree,commit_cid:i.commit_cid}},async getBlob(t,s){return (await S(e,`/api/rack/${t}/blob/${s}`,void 0,a)).content},async getLog(t,s,i){let u=new URLSearchParams;s&&u.set("ref",s),i&&u.set("max_count",String(i));let d=u.toString()?`?${u}`:"";return (await S(e,`/api/rack/${t}/log${d}`,void 0,a)).commits||[]},async getBranches(t){return (await S(e,`/api/rack/${t}/branches`,void 0,a)).branches||[]},async createBranch(t,s,i){return S(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:s,from_ref:i})},a)},async merge(t,s,i){return S(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:s,target_branch:i})},a)},async getDiff(t,s,i){return (await S(e,`/api/rack/${t}/diff/${s}/${i}`,void 0,a)).diff?.entries||[]},async starRepo(t){return S(e,`/api/rack/${t}/star`,{method:"POST"},a)},async unstarRepo(t){return S(e,`/api/rack/${t}/star`,{method:"DELETE"},a)},async getStarInfo(t){return S(e,`/api/rack/${t}/stars`,void 0,a)},async getSkillStats(t){let s={meta:null,tokenCount:null,usageCount:null};try{let{tree:i}=await this.getTree(t,"main");if(!i?.entries)return s;if(i.entries["META.json"]){let m=A(i.entries["META.json"]).cid,f=await this.getBlob(t,m);s.meta=JSON.parse(f);}let u=0,d=Object.values(i.entries).map(async m=>{try{let f=A(m).cid,g=await this.getBlob(t,f);u+=g.length;}catch{}});await Promise.all(d),u>0&&(s.tokenCount=Math.ceil(u/4)),s.meta?.skill_id&&(s.usageCount=await this.getSkillUsageCount(s.meta.skill_id));}catch{}return s},async getSkillUsageCount(t){try{let s=await fetch(`${c}/v1/skills/${encodeURIComponent(t)}`);if(s.ok){let u=await s.json();return u.usage_count??u.usageCount??null}let i=await fetch(`${c}/v1/skills?scope=public`);if(i.ok){let d=((await i.json()).skills||[]).find(m=>m.name===t||m.id===t);if(d)return d.usage_count??d.usageCount??0}return 0}catch{return null}},async getTensorStats(t){let s={meta:null,sizeMB:null};try{let{tree:i}=await this.getTree(t,"main");if(!i?.entries)return s;if(i.entries["TENSOR_META.json"]){let u=A(i.entries["TENSOR_META.json"]).cid,d=await this.getBlob(t,u);s.meta=JSON.parse(d),s.sizeMB=s.meta?.tensor_size_mb??null;}}catch{}return s},async getNetworkStats(){try{return (await S(e,"/api/rack/stats",void 0,a)).stats||null}catch{return null}},async getTrending(t=5,s=1,i){try{let u=new URLSearchParams({limit:String(t),days:String(s)});i&&u.set("cursor",i);let d=await S(e,`/api/rack/trending?${u}`,void 0,a);return {items:d.trending||[],pagination:d.pagination||{total:(d.trending||[]).length,limit:t,has_more:!1,next_cursor:null}}}catch{return {items:[],pagination:{total:0,limit:t,has_more:false,next_cursor:null}}}}}),[e,o,n,a,c])}function Be(r){let e=R(r),o=react.useRef(e);o.current=e;let[n,a]=react.useState([]),[c,t]=react.useState(true),[s,i]=react.useState(null),u=react.useRef(true),d=react.useRef(null),m=react.useCallback(async()=>{d.current?.abort();let f=new AbortController;d.current=f;try{u.current&&(t(!0),i(null));let g=await o.current.listRepos();u.current&&!f.signal.aborted&&a(g.items);}catch(g){u.current&&!f.signal.aborted&&i(g instanceof Error?g.message:"Failed to load repos");}finally{u.current&&!f.signal.aborted&&t(false);}},[]);return react.useEffect(()=>(u.current=true,m(),()=>{u.current=false,d.current?.abort();}),[m]),{repos:n,loading:c,error:s,refresh:m}}function Oe(r){return Object.entries(r).map(([e,o])=>{let n=o.indexOf(":"),a=n>0?o.slice(0,n):"100644",c=n>0?o.slice(n+1):o;return {path:e,mode:a,cid:c,isDir:a==="040000"}}).sort((e,o)=>e.isDir!==o.isDir?e.isDir?-1:1:e.path.localeCompare(o.path))}function F(r,e,o="main"){let n=R(r),[a,c]=react.useState([]),[t,s]=react.useState(false),[i,u]=react.useState(null),d=react.useRef(true),m=react.useCallback(async()=>{if(e)try{d.current&&(s(!0),u(null));let{tree:g}=await n.getTree(e,o);d.current&&c(Oe(g.entries));}catch(g){d.current&&u(g instanceof Error?g.message:"Failed to load tree");}finally{d.current&&s(false);}},[n,e,o]);react.useEffect(()=>(d.current=true,m(),()=>{d.current=false;}),[m]);let f=react.useCallback(async g=>{if(!e)throw new Error("No repo selected");return n.getBlob(e,g)},[n,e]);return {entries:a,loading:t,error:i,refresh:m,getFileContent:f}}function He(r){let e=R(r),[o,n]=react.useState(false),[a,c]=react.useState(null),t=react.useRef(true);return react.useEffect(()=>(t.current=true,()=>{t.current=false;}),[]),{push:react.useCallback(async(i,u,d,m)=>{try{return t.current&&(n(!0),c(null)),await e.push(i,{files:u,message:d,branch:m})}catch(f){let g=f instanceof Error?f.message:"Push failed";return t.current&&c(g),null}finally{t.current&&n(false);}},[e]),pushing:o,error:a}}function K(r,e={}){let{pageSize:o=50,owner:n}=e,a=R(r),[c,t]=react.useState([]),[s,i]=react.useState(null),[u,d]=react.useState(false),[m,f]=react.useState(null),g=react.useRef(null),p=react.useRef(true),w=react.useCallback(async(v,E=false)=>{d(true),f(null);try{let N=await a.listRepos(n,{limit:o,cursor:v||void 0});p.current&&(t(_=>E?[..._,...N.items]:N.items),i(N.pagination),g.current=N.pagination.next_cursor);}catch(N){p.current&&f(N.message);}finally{p.current&&d(false);}},[a,n,o]),k=react.useCallback(async()=>{!g.current||u||await w(g.current,true);},[w,u]),h=react.useCallback(async()=>{g.current=null,await w(void 0,false);},[w]);return react.useEffect(()=>(p.current=true,w(),()=>{p.current=false;}),[w]),{repos:c,hasMore:s?.has_more??false,total:s?.total??0,loading:u,error:m,loadMore:k,reset:h,pagination:s}}var J="stacknet-rack-apikey";function Je(r){let e=r.stacknetUrl||r.apiBaseUrl,[o,n]=react.useState({authenticated:false}),[a,c]=react.useState(null),[t,s]=react.useState(false),i=react.useCallback(f=>({"Content-Type":"application/json",...f||r.apiKey?{Authorization:`Bearer ${f||r.apiKey}`}:{}}),[r.apiKey]),u=react.useCallback(async f=>{s(true);try{let g=await fetch(`${e}/health`,{headers:i(f)});if(!g.ok)throw new Error(`Authentication failed: ${g.status}`);let p={authenticated:!0,apiKey:f,permission:f.startsWith("gk_")?"write":"read"};n(p);try{localStorage.setItem(J,f);}catch{}return p}catch(g){throw n({authenticated:false}),g}finally{s(false);}},[e,i]),d=react.useCallback(()=>{n({authenticated:false}),c(null);try{localStorage.removeItem(J);}catch{}},[]),m=react.useCallback(async()=>{let f=o.apiKey||r.apiKey;if(!f)return null;try{let g=await fetch(`${e}/network/usage`,{headers:i(f)});if(!g.ok)return null;let p=await g.json(),w={planAllocation:p.plan_allocation??p.planAllocation??0,inferenceUsed:p.inference_used??p.inferenceUsed??0,ledgerSpent:p.ledger_spent??p.ledgerSpent??0,totalUsed:p.total_used??p.totalUsed??0,remaining:p.remaining??0,percent:p.percent??0,exceeded:p.exceeded??!1};return c(w),w}catch{return null}},[o.apiKey,r.apiKey,e,i]);return react.useEffect(()=>{let f=r.apiKey;if(f){n({authenticated:true,apiKey:f,permission:f.startsWith("gk_")?"write":"read"});return}try{let g=localStorage.getItem(J);g&&n({authenticated:!0,apiKey:g,permission:g.startsWith("gk_")?"write":"read"});}catch{}},[r.apiKey]),{session:o,budget:a,loading:t,login:u,logout:d,refreshBudget:m}}var fe=1e3,me=1e3,ge=100;function pe(r,e){if(r==="skill"){let a=ge+Math.ceil(e/4);return {type:r,totalBytes:e,totalMegabytes:e/1e6,baseCost:a,multiplier:fe,registrationCostTokens:a*fe}}let o=Math.ceil(e/1e6),n=ge+o;return {type:r,totalBytes:e,totalMegabytes:o,baseCost:n,multiplier:me,registrationCostTokens:n*me}}function Ve(r){let e=r.stacknetUrl||r.apiBaseUrl,o=r.apiKey,[n,a]=react.useState(false),[c,t]=react.useState(null),s=react.useCallback(()=>{if(!o)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${o}`}},[o]),i=react.useCallback(async d=>{a(true),t(null);try{let m=await fetch(`${e}/skills`,{method:"POST",headers:s(),body:JSON.stringify(d)});if(!m.ok){let f=await m.json().catch(()=>({error:`HTTP ${m.status}`}));throw new Error(f.error||`Registration failed: ${m.status}`)}return await m.json()}catch(m){throw t(m.message),m}finally{a(false);}},[e,s]),u=react.useCallback(async d=>{a(true),t(null);try{let m=await fetch(`${e}/tensors`,{method:"POST",headers:s(),body:JSON.stringify(d)});if(!m.ok){let f=await m.json().catch(()=>({error:`HTTP ${m.status}`}));throw new Error(f.error||`Registration failed: ${m.status}`)}return await m.json()}catch(m){throw t(m.message),m}finally{a(false);}},[e,s]);return {registerSkill:i,registerTensor:u,estimateCost:pe,registering:n,error:c}}function Ye(r,e){let o=R(r),[n,a]=react.useState({meta:null,tokenCount:null,usageCount:null}),[c,t]=react.useState(false),[s,i]=react.useState(null),u=react.useRef(true),d=react.useCallback(async()=>{if(e){t(true),i(null);try{let m=await o.getSkillStats(e);u.current&&a(m);}catch(m){u.current&&i(m.message);}finally{u.current&&t(false);}}},[o,e]);return react.useEffect(()=>(u.current=true,d(),()=>{u.current=false;}),[d]),{stats:n,loading:c,error:s,refresh:d}}function tt(r,e){let o=R(r),[n,a]=react.useState({meta:null,sizeMB:null}),[c,t]=react.useState(false),[s,i]=react.useState(null),u=react.useRef(true),d=react.useCallback(async()=>{if(e){t(true),i(null);try{let m=await o.getTensorStats(e);u.current&&a(m);}catch(m){u.current&&i(m.message);}finally{u.current&&t(false);}}},[o,e]);return react.useEffect(()=>(u.current=true,d(),()=>{u.current=false;}),[d]),{stats:n,loading:c,error:s,refresh:d}}function ot(r){let e=R(r),[o,n]=react.useState(null),[a,c]=react.useState(false),[t,s]=react.useState(null),i=react.useRef(true),u=react.useCallback(async()=>{c(true),s(null);try{let d=await e.getNetworkStats();i.current&&n(d);}catch(d){i.current&&s(d.message);}finally{i.current&&c(false);}},[e]);return react.useEffect(()=>(i.current=true,u(),()=>{i.current=false;}),[u]),{stats:o,loading:a,error:t,refresh:u}}function it(r,e=5,o=1){let n=R(r),[a,c]=react.useState([]),[t,s]=react.useState(null),[i,u]=react.useState(false),[d,m]=react.useState(null),f=react.useRef(true),g=react.useRef(null),p=react.useCallback(async k=>{u(true),m(null),g.current=null;try{let h=await n.getTrending(e,k??o);f.current&&(c(h.items),s(h.pagination),g.current=h.pagination.next_cursor);}catch(h){f.current&&m(h.message);}finally{f.current&&u(false);}},[n,e,o]),w=react.useCallback(async()=>{if(!(!g.current||i)){u(true);try{let k=await n.getTrending(e,o,g.current);f.current&&(c(h=>[...h,...k.items]),s(k.pagination),g.current=k.pagination.next_cursor);}catch(k){f.current&&m(k.message);}finally{f.current&&u(false);}}},[n,e,o,i]);return react.useEffect(()=>(f.current=true,p(),()=>{f.current=false;}),[p]),{repos:a,hasMore:t?.has_more??false,total:t?.total??0,loading:i,error:d,refresh:p,loadMore:w}}function ut(r,e){let o=R(r),[n,a]=react.useState({stars:0,starred:false,repo_id:e||""}),[c,t]=react.useState(false),[s,i]=react.useState(null),u=react.useRef(true),d=react.useCallback(async()=>{if(e)try{let f=await o.getStarInfo(e);u.current&&a(f);}catch{}},[o,e]);react.useEffect(()=>(u.current=true,d(),()=>{u.current=false;}),[d]);let m=react.useCallback(async()=>{if(e){t(true),i(null);try{let f=n.starred?await o.unstarRepo(e):await o.starRepo(e);u.current&&a({stars:f.stars,starred:f.starred,repo_id:e});}catch(f){u.current&&i(f.message);}finally{u.current&&t(false);}}},[o,e,n.starred]);return {...n,loading:c,error:s,toggle:m,refresh:d}}function T(...r){return tailwindMerge.twMerge(clsx.clsx(r))}var mt=/^(https?:\/\/|mailto:|\/[^/])/i;function gt(r){let e=r.trim();return mt.test(e)?e:null}function B(r){let e=[],o=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,n=0,a,c=0;for(;(a=o.exec(r))!==null;){a.index>n&&e.push(r.slice(n,a.index));let t=`i${c++}`;if(a[1])e.push(jsxRuntime.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[0.85em] font-mono text-pink-400",children:a[1].slice(1,-1)},t));else if(a[2])e.push(jsxRuntime.jsx("strong",{children:a[3]},t));else if(a[4])e.push(jsxRuntime.jsx("em",{children:a[5]},t));else if(a[6])e.push(jsxRuntime.jsx("em",{children:a[7]},t));else if(a[8]){let s=gt(a[10]);s?e.push(jsxRuntime.jsx("a",{href:s,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:a[9]},t)):e.push(a[9]);}n=a.index+a[0].length;}return n<r.length&&e.push(r.slice(n)),e.length>0?e:[r]}function pt(r){let e=r.split(`
2
+ `),o=[],n=0;for(;n<e.length;){let a=e[n];if(a.trim()===""){n++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(a.trim())){o.push({type:"hr"}),n++;continue}let c=a.match(/^(#{1,6})\s+(.+)/);if(c){o.push({type:"heading",level:c[1].length,content:c[2]}),n++;continue}if(a.trim().startsWith("```")){let s=a.trim().slice(3).trim(),i=[];for(n++;n<e.length&&!e[n].trim().startsWith("```");)i.push(e[n]),n++;o.push({type:"code",content:i.join(`
3
+ `),lang:s||void 0}),n++;continue}if(/^\s*[-*+]\s/.test(a)){let s=[];for(;n<e.length&&/^\s*[-*+]\s/.test(e[n]);)s.push(e[n].replace(/^\s*[-*+]\s+/,"")),n++;o.push({type:"ul",items:s});continue}if(/^\s*\d+[.)]\s/.test(a)){let s=[];for(;n<e.length&&/^\s*\d+[.)]\s/.test(e[n]);)s.push(e[n].replace(/^\s*\d+[.)]\s+/,"")),n++;o.push({type:"ol",items:s});continue}let t=[];for(;n<e.length&&e[n].trim()!==""&&!e[n].match(/^#{1,6}\s/)&&!e[n].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[n])&&!/^\s*\d+[.)]\s/.test(e[n]);)t.push(e[n]),n++;t.length>0&&o.push({type:"paragraph",content:t.join(" ")});}return o}var ht={1:"text-2xl font-bold mt-6 mb-3",2:"text-xl font-bold mt-5 mb-2",3:"text-lg font-semibold mt-4 mb-2",4:"text-base font-semibold mt-3 mb-1",5:"text-sm font-semibold mt-2 mb-1",6:"text-sm font-medium mt-2 mb-1"};function yt(r,e){switch(r.type){case "hr":return jsxRuntime.jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let o=Math.min(Math.max(r.level||1,1),6),n=`h${o}`;return jsxRuntime.jsx(n,{className:T("text-foreground",ht[o]),children:B(r.content||"")},`b${e}`)}case "paragraph":return jsxRuntime.jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:B(r.content||"")},`b${e}`);case "code":return jsxRuntime.jsx("pre",{className:"mb-3 overflow-x-auto rounded-lg bg-muted p-4 text-sm font-mono leading-relaxed text-foreground",children:jsxRuntime.jsx("code",{children:r.content})},`b${e}`);case "ul":return jsxRuntime.jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:r.items?.map((o,n)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:B(o)},`li${e}-${n}`))},`b${e}`);case "ol":return jsxRuntime.jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:r.items?.map((o,n)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:B(o)},`li${e}-${n}`))},`b${e}`);default:return null}}function Q({content:r,className:e}){let o=pt(r);return jsxRuntime.jsx("div",{className:T("text-sm",e),children:o.map((n,a)=>yt(n,a))})}function Re({open:r,className:e}){return jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:T("shrink-0 transition-transform duration-150",r?"rotate-0":"-rotate-90",e),children:jsxRuntime.jsx("path",{d:"M16.134 6.16a.5.5 0 1 1 .732.68l-6.5 7-.077.068a.5.5 0 0 1-.655-.068l-6.5-7-.062-.08a.5.5 0 0 1 .718-.667l.076.067L10 12.767z"})})}function xe({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function X({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M15.147 4.146a.5.5 0 0 1 .707.707L10.707 10l5.147 5.147a.5.5 0 0 1-.63.771l-.078-.064L10 10.707l-5.146 5.147a.5.5 0 0 1-.708-.707L9.293 10 4.146 4.853a.5.5 0 0 1 .708-.707L10 9.293z"})})}function ve({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M10 3a.5.5 0 0 1 .5.5v6h6l.1.01a.5.5 0 0 1 0 .98l-.1.01h-6v6a.5.5 0 0 1-1 0v-6h-6a.5.5 0 0 1 0-1h6v-6A.5.5 0 0 1 10 3"})})}function wt(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M6.5 3A2.5 2.5 0 0 0 4 5.5v9A2.5 2.5 0 0 0 6.5 17h7a2.5 2.5 0 0 0 2.5-2.5v-7A2.5 2.5 0 0 0 13.5 5H11V3.5a.5.5 0 0 0-1 0V5H6.5ZM5 5.5A1.5 1.5 0 0 1 6.5 4H9v1H6.5A1.5 1.5 0 0 0 5 6.5v8A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 13.5 6H11V4h2.5A2.5 2.5 0 0 1 16 6.5v8a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-9Z"})})}function bt(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M5.5 3A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h9a2.5 2.5 0 0 0 2.5-2.5v-9A2.5 2.5 0 0 0 14.5 3h-9ZM4 5.5A1.5 1.5 0 0 1 5.5 4h9A1.5 1.5 0 0 1 16 5.5v9a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 4 14.5v-9ZM7 7.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5Z"})})}function Rt(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M10 2a.5.5 0 0 1 .354.146l3 3a.5.5 0 0 1-.708.708L10.5 3.707V12.5a.5.5 0 0 1-1 0V3.707L7.354 5.854a.5.5 0 1 1-.708-.708l3-3A.5.5 0 0 1 10 2ZM4 13.5a.5.5 0 0 1 1 0v1A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-1a.5.5 0 0 1 1 0v1a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-1Z"})})}function Se(){let[r,e]=react.useState(false);return react.useEffect(()=>{if(typeof window>"u")return;let o=()=>e(window.innerWidth<768);return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),r}function Ce({onClose:r,children:e,title:o}){let n=Se(),a=react.useRef(r);return a.current=r,react.useEffect(()=>{let c=t=>{t.key==="Escape"&&a.current();};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[]),n?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full max-h-[90vh] overflow-y-auto rounded-t-2xl bg-[#1a1a1a] p-5 pb-8 animate-in slide-in-from-bottom duration-200",onClick:c=>c.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-4 h-1 w-10 rounded-full bg-zinc-600"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-foreground",children:o}),jsxRuntime.jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(X,{size:20})})]}),e]})]}):jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full max-w-lg overflow-y-auto rounded-2xl bg-[#1a1a1a] p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:c=>c.stopPropagation(),children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-foreground",children:o}),jsxRuntime.jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(X,{size:20})})]}),e]})]})}function vt(r){let e=r.split(`
4
+ `),o="",n="",c=false;for(let t=0;t<e.length;t++){let s=e[t].trim();if(t===0&&s==="---"){c=true;continue}if(c){s==="---"&&(c=false,true);continue}if(!o){let i=s.match(/^#{1,2}\s+(.+)/);if(i){o=i[1].trim();continue}}if(o&&!n){if(!s||s.startsWith("#")||s==="---"||s==="***"||s==="___")continue;n=s.replace(/\*\*/g,"").replace(/`/g,"").trim();break}}return o?{title:o,description:n}:null}function St({onClose:r,onCreated:e,config:o}){let[n,a]=react.useState(""),[c,t]=react.useState(""),[s,i]=react.useState(""),[u,d]=react.useState(false),[m,f]=react.useState(null),[g,p]=react.useState(false),w=h=>{if(i(h),!n.trim()&&!c.trim()&&h.trim().length>10){let v=vt(h);v&&(a(v.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")),t(v.description),p(true));}};return jsxRuntime.jsx(Ce,{title:"Write skill instructions",onClose:r,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsxRuntime.jsx("input",{id:"skill-name",value:n,onChange:h=>a(h.target.value),placeholder:"weekly-status-report",className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-desc",className:"text-sm text-muted-foreground",children:"Description"}),jsxRuntime.jsx("textarea",{id:"skill-desc",value:c,onChange:h=>t(h.target.value),placeholder:"Generate weekly status reports from recent work.",rows:3,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-instructions",className:"text-sm text-muted-foreground",children:"Instructions"}),jsxRuntime.jsx("textarea",{id:"skill-instructions",value:s,onChange:h=>w(h.target.value),placeholder:"Summarize my recent work in three sections: wins, blockers, and next steps.",rows:8,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),m&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:m}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsxRuntime.jsx("button",{onClick:r,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsxRuntime.jsx("button",{onClick:async()=>{if(n.trim()){d(true),f(null);try{let h=o.apiBaseUrl||"",v=g?s.trim():`# ${n.trim()}
4
5
 
5
- ${f.trim()}
6
+ ${c.trim()}
6
7
 
7
8
  ---
8
9
 
9
- ${a.trim()}`,w=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n.trim(),description:f.trim(),skill_md:x,content_type:"code"})});if(!w.ok){let R=`Failed to register skill (${w.status})`;try{let C=await w.json();C.error&&(R=C.error);}catch{}throw new Error(R)}e?.(),r();}catch(p){d(p instanceof Error?p.message:"Failed to create skill");}finally{u(false);}}},disabled:c||!n.trim(),className:"rounded-lg bg-zinc-600 px-4 py-2 text-sm font-medium text-white hover:bg-zinc-500 disabled:opacity-50",children:c?"Creating...":"Create"})]})]})})}function xt({onClose:r,onCreated:e,config:o}){let n=react.useRef(null),[s,f]=react.useState(false),[t,a]=react.useState(false),[l,c]=react.useState(null),u=async d=>{a(true),c(null);try{let g=await d.text(),p=o.apiBaseUrl||"",x=d.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),w=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:x,skill_md:g,content_type:"code"})});if(!w.ok){let R=`Failed to register skill (${w.status})`;try{let C=await w.json();C.error&&(R=C.error);}catch{}throw new Error(R)}e?.(),r();}catch(g){c(g instanceof Error?g.message:"Upload failed");}finally{a(false);}};return jsxRuntime.jsx(Re,{title:"Upload skill",onClose:r,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{onDragOver:d=>{d.preventDefault(),f(true);},onDragLeave:()=>f(false),onDrop:d=>{d.preventDefault(),f(false);let g=d.dataTransfer.files[0];g&&u(g);},onClick:()=>n.current?.click(),className:N("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",s?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsxRuntime.jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsxRuntime.jsx(we,{size:20,className:"text-muted-foreground"})}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:t?"Uploading...":"Drag and drop or click to upload"})]}),jsxRuntime.jsx("input",{ref:n,type:"file",accept:".md,.zip,.skill,.txt,.yml,.yaml",className:"hidden","aria-label":"Upload skill file",onChange:d=>{let g=d.target.files?.[0];g&&u(g);}}),l&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:l}),jsxRuntime.jsxs("div",{className:"space-y-2 text-xs text-muted-foreground",children:[jsxRuntime.jsx("p",{className:"font-medium text-foreground/70",children:"File requirements"}),jsxRuntime.jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[jsxRuntime.jsx("li",{children:".md file must contain skill name and description formatted in YAML"}),jsxRuntime.jsx("li",{children:".zip or .skill file must include a SKILL.md file"})]})]})]})})}function wt({onClose:r,onSelect:e}){let o=be(),n=react.useRef(null),s=react.useRef(r);s.current=r,react.useEffect(()=>{if(o)return;let t=a=>{n.current&&a.target instanceof Node&&!n.current.contains(a.target)&&s.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[o]);let f=[{id:"create-with-geoff",icon:jsxRuntime.jsx(pt,{}),label:"Create with Geoff"},{id:"write",icon:jsxRuntime.jsx(ht,{}),label:"Write skill instructions"},{id:"upload",icon:jsxRuntime.jsx(yt,{}),label:"Upload a skill"}];return o?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full rounded-t-2xl bg-[#1a1a1a] p-4 pb-8 animate-in slide-in-from-bottom duration-200",onClick:t=>t.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),f.map(t=>jsxRuntime.jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-800",children:[t.icon,t.label]},t.id))]})]}):jsxRuntime.jsx("div",{ref:n,className:"absolute right-2 top-11 z-50 w-56 overflow-hidden rounded-xl border border-zinc-700 bg-[#2a2a2a] shadow-xl animate-in fade-in zoom-in-95 duration-100",children:f.map(t=>jsxRuntime.jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[t.icon,t.label]},t.id))})}function bt({entry:r,selected:e,onSelect:o,depth:n=0}){return jsxRuntime.jsxs("button",{onClick:()=>o(r),className:N("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+n*16}px`},children:[jsxRuntime.jsx("span",{className:"truncate flex-1",children:r.path.split("/").pop()}),r.isDir&&jsxRuntime.jsx(xe,{className:"ml-auto text-muted-foreground"})]})}function Rt({repo:r,selected:e,expanded:o,onSelect:n,onToggle:s,children:f}){return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>{n(),s();},className:N("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsxRuntime.jsx(xe,{open:o}),jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4 shrink-0"}),jsxRuntime.jsx("span",{className:"truncate",children:r.name})]}),o&&f]})}function vt({entry:r,content:e,loading:o,repoName:n}){let[s,f]=react.useState(false),t=react.useRef(null);react.useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[a,l]=react.useState(false),c=async()=>{if(e)try{await navigator.clipboard.writeText(e),f(!0),l(!1),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>f(!1),2e3);}catch{l(true),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>l(false),2e3);}};if(!r)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(o)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let u=r.path.split("/").pop()||r.path,m=/\.(md|mdx)$/i.test(u);return jsxRuntime.jsxs("div",{className:"flex h-full flex-col px-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[jsxRuntime.jsx("h3",{className:"text-sm sm:text-lg font-semibold text-foreground",children:u}),jsxRuntime.jsx("button",{onClick:c,"aria-label":"Copy file content",className:N("rounded p-1 transition-colors",s?"text-green-500":a?"text-red-500":"text-muted-foreground hover:text-foreground"),children:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"})})})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-auto p-4",children:m?jsxRuntime.jsx(Q,{content:e||""}):jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function St({config:r,category:e,className:o,style:n}){let{repos:s,loading:f,error:t,refresh:a}=D(r),[l,c]=react.useState(null),[u,m]=react.useState(null),[d,g]=react.useState(null),[p,x]=react.useState(null),[w,R]=react.useState(false),[C,I]=react.useState(""),[P,M]=react.useState(false),[ee,te]=react.useState(false),[re,A]=react.useState(null),ve=s.find(y=>y.repo_id===l),{entries:Se,getFileContent:ne}=H(r,u),se=s.filter(y=>!C||y.name.toLowerCase().includes(C.toLowerCase())),Ce=react.useCallback(async y=>{if(!y.isDir){g(y),R(true);try{let T=await ne(y.cid);x(T);}catch(T){let Te=T instanceof Error?T.message:"Unknown error";x(`Failed to load file: ${Te}`);}finally{R(false);}}},[ne]);react.useEffect(()=>{s.length>0&&!l&&(c(s[0].repo_id),m(s[0].repo_id));},[s,l]);let Ne=y=>{y==="create-with-geoff"?window.open(`https://www.geoff.ai/?p=${encodeURIComponent("Let's create a skill together using your skill-creator skill. First ask me what the skill should do.")}`,"_blank","noopener,noreferrer"):A(y);};return jsxRuntime.jsxs("div",{className:N("flex flex-1 h-full min-h-0",o),style:n,children:[jsxRuntime.jsxs("div",{className:"relative flex w-96 shrink-0 flex-col border-r",children:[jsxRuntime.jsx("div",{className:"flex h-12 items-center gap-2 px-3",children:P?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-md border bg-muted/50 px-2 py-1",children:[jsxRuntime.jsx(he,{size:16,className:"shrink-0 text-muted-foreground"}),jsxRuntime.jsx("input",{type:"text",value:C,onChange:y=>I(y.target.value),placeholder:"Search",autoFocus:true,"aria-label":"Search items",className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),jsxRuntime.jsx("button",{onClick:()=>{M(false),I("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(X,{size:16})})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground capitalize",children:e||"Items"}),jsxRuntime.jsx("button",{onClick:()=>M(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsxRuntime.jsx(he,{size:20})}),jsxRuntime.jsx("button",{onClick:()=>te(!ee),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(we,{size:20})})]})}),ee&&jsxRuntime.jsx(wt,{onClose:()=>te(false),onSelect:Ne}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:f?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):t?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:t}):se.length===0?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:C?"No matching items":"No items yet"}):jsxRuntime.jsx("div",{className:"space-y-0.5",children:se.map(y=>jsxRuntime.jsx(Rt,{repo:y,selected:l===y.repo_id,expanded:u===y.repo_id,onSelect:()=>{c(y.repo_id),g(null),x(null);},onToggle:()=>m(u===y.repo_id?null:y.repo_id),children:jsxRuntime.jsx("div",{className:"ml-10 pl-1",children:Se.map(T=>jsxRuntime.jsx(bt,{entry:T,selected:d?.path===T.path,onSelect:Ce,depth:T.path.split("/").length-1},T.path))})},y.repo_id))})})]}),jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntime.jsx(vt,{entry:d,content:p,loading:w,repoName:ve?.name||""})}),re==="write"&&jsxRuntime.jsx(kt,{config:r,onClose:()=>A(null),onCreated:a}),re==="upload"&&jsxRuntime.jsx(xt,{config:r,onClose:()=>A(null),onCreated:a})]})}
10
- exports.Markdown=Q;exports.RackBrowser=St;exports.estimateCost=fe;exports.useNetworkStats=et;exports.usePaginatedRepos=Oe;exports.useRackClient=b;exports.useRackRegister=Fe;exports.useRackSession=De;exports.useRepoPush=Ae;exports.useRepoTree=H;exports.useRepos=D;exports.useSkillStats=Je;exports.useStar=ot;exports.useTensorStats=Ge;exports.useTrending=rt;
10
+ ${s.trim()}`,E=await fetch(`${h}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n.trim(),description:c.trim(),skill_md:v,content_type:"code"})});if(!E.ok){let N=`Failed to register skill (${E.status})`;try{let _=await E.json();_.error&&(N=_.error);}catch{}throw new Error(N)}e?.(),r();}catch(h){f(h instanceof Error?h.message:"Failed to create skill");}finally{d(false);}}},disabled:u||!n.trim(),className:"rounded-lg bg-zinc-600 px-4 py-2 text-sm font-medium text-white hover:bg-zinc-500 disabled:opacity-50",children:u?"Creating...":"Create"})]})]})})}function Ct({onClose:r,onCreated:e,config:o}){let n=react.useRef(null),[a,c]=react.useState(false),[t,s]=react.useState(false),[i,u]=react.useState(null),d=async f=>{s(true),u(null);try{let g=await f.text(),p=o.apiBaseUrl||"",w=f.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),k=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:w,skill_md:g,content_type:"code"})});if(!k.ok){let h=`Failed to register skill (${k.status})`;try{let v=await k.json();v.error&&(h=v.error);}catch{}throw new Error(h)}e?.(),r();}catch(g){u(g instanceof Error?g.message:"Upload failed");}finally{s(false);}};return jsxRuntime.jsx(Ce,{title:"Upload skill",onClose:r,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{onDragOver:f=>{f.preventDefault(),c(true);},onDragLeave:()=>c(false),onDrop:f=>{f.preventDefault(),c(false);let g=f.dataTransfer.files[0];g&&d(g);},onClick:()=>n.current?.click(),className:T("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",a?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsxRuntime.jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsxRuntime.jsx(ve,{size:20,className:"text-muted-foreground"})}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:t?"Uploading...":"Drag and drop or click to upload"})]}),jsxRuntime.jsx("input",{ref:n,type:"file",accept:".md,.zip,.skill,.txt,.yml,.yaml",className:"hidden","aria-label":"Upload skill file",onChange:f=>{let g=f.target.files?.[0];g&&d(g);}}),i&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:i}),jsxRuntime.jsxs("div",{className:"space-y-2 text-xs text-muted-foreground",children:[jsxRuntime.jsx("p",{className:"font-medium text-foreground/70",children:"File requirements"}),jsxRuntime.jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[jsxRuntime.jsx("li",{children:".md file must contain skill name and description formatted in YAML"}),jsxRuntime.jsx("li",{children:".zip or .skill file must include a SKILL.md file"})]})]})]})})}function Nt({onClose:r,onSelect:e}){let o=Se(),n=react.useRef(null),a=react.useRef(r);a.current=r,react.useEffect(()=>{if(o)return;let t=s=>{n.current&&s.target instanceof Node&&!n.current.contains(s.target)&&a.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[o]);let c=[{id:"create-with-geoff",icon:jsxRuntime.jsx(wt,{}),label:"Create with Geoff"},{id:"write",icon:jsxRuntime.jsx(bt,{}),label:"Write skill instructions"},{id:"upload",icon:jsxRuntime.jsx(Rt,{}),label:"Upload a skill"}];return o?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full rounded-t-2xl bg-[#1a1a1a] p-4 pb-8 animate-in slide-in-from-bottom duration-200",onClick:t=>t.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),c.map(t=>jsxRuntime.jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-800",children:[t.icon,t.label]},t.id))]})]}):jsxRuntime.jsx("div",{ref:n,className:"absolute right-2 top-11 z-50 w-56 overflow-hidden rounded-xl border border-zinc-700 bg-[#2a2a2a] shadow-xl animate-in fade-in zoom-in-95 duration-100",children:c.map(t=>jsxRuntime.jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[t.icon,t.label]},t.id))})}function Tt({entry:r,selected:e,onSelect:o,depth:n=0}){return jsxRuntime.jsxs("button",{onClick:()=>o(r),className:T("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+n*16}px`},children:[jsxRuntime.jsx("span",{className:"truncate flex-1",children:r.path.split("/").pop()}),r.isDir&&jsxRuntime.jsx(Re,{className:"ml-auto text-muted-foreground"})]})}function Pt({repo:r,selected:e,expanded:o,onSelect:n,onToggle:a,children:c}){return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>{n(),a();},className:T("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsxRuntime.jsx(Re,{open:o}),jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4 shrink-0"}),jsxRuntime.jsx("span",{className:"truncate",children:r.name})]}),o&&c]})}function Et({entry:r,content:e,loading:o,repoName:n}){let[a,c]=react.useState(false),t=react.useRef(null);react.useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[s,i]=react.useState(false),u=async()=>{if(e)try{await navigator.clipboard.writeText(e),c(!0),i(!1),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>c(!1),2e3);}catch{i(true),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>i(false),2e3);}};if(!r)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(o)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let d=r.path.split("/").pop()||r.path,m=/\.(md|mdx)$/i.test(d);return jsxRuntime.jsxs("div",{className:"flex h-full flex-col px-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[jsxRuntime.jsx("h3",{className:"text-sm sm:text-lg font-semibold text-foreground",children:d}),jsxRuntime.jsx("button",{onClick:u,"aria-label":"Copy file content",className:T("rounded p-1 transition-colors",a?"text-green-500":s?"text-red-500":"text-muted-foreground hover:text-foreground"),children:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"})})})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-auto p-4",children:m?jsxRuntime.jsx(Q,{content:e||""}):jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function _t({config:r,category:e,className:o,style:n}){let{repos:a,loading:c,error:t,hasMore:s,loadMore:i,reset:u}=K(r,{pageSize:50}),[d,m]=react.useState(null),[f,g]=react.useState(null),[p,w]=react.useState(null),[k,h]=react.useState(null),[v,E]=react.useState(false),[N,_]=react.useState(""),[Te,re]=react.useState(false),[ne,se]=react.useState(false),[oe,U]=react.useState(null),Pe=a.find(b=>b.repo_id===d),{entries:Ee,getFileContent:ae}=F(r,f),ie=a.filter(b=>!N||b.name.toLowerCase().includes(N.toLowerCase())),_e=react.useCallback(async b=>{if(!b.isDir){w(b),E(true);try{let P=await ae(b.cid);h(P);}catch(P){let $e=P instanceof Error?P.message:"Unknown error";h(`Failed to load file: ${$e}`);}finally{E(false);}}},[ae]);react.useEffect(()=>{a.length>0&&!d&&(m(a[0].repo_id),g(a[0].repo_id));},[a,d]);let Me=b=>{b==="create-with-geoff"?window.open(`https://www.geoff.ai/?p=${encodeURIComponent("Let's create a skill together using your skill-creator skill. First ask me what the skill should do.")}`,"_blank","noopener,noreferrer"):U(b);};return jsxRuntime.jsxs("div",{className:T("flex flex-1 h-full min-h-0",o),style:n,children:[jsxRuntime.jsxs("div",{className:"relative flex w-96 shrink-0 flex-col border-r",children:[jsxRuntime.jsx("div",{className:"flex h-12 items-center gap-2 px-3",children:Te?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-md border bg-muted/50 px-2 py-1",children:[jsxRuntime.jsx(xe,{size:16,className:"shrink-0 text-muted-foreground"}),jsxRuntime.jsx("input",{type:"text",value:N,onChange:b=>_(b.target.value),placeholder:"Search",autoFocus:true,"aria-label":"Search items",className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),jsxRuntime.jsx("button",{onClick:()=>{re(false),_("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(X,{size:16})})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground capitalize",children:e||"Items"}),jsxRuntime.jsx("button",{onClick:()=>re(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsxRuntime.jsx(xe,{size:20})}),jsxRuntime.jsx("button",{onClick:()=>se(!ne),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(ve,{size:20})})]})}),ne&&jsxRuntime.jsx(Nt,{onClose:()=>se(false),onSelect:Me}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:c?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):t?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:t}):ie.length===0?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:N?"No matching items":"No items yet"}):jsxRuntime.jsx("div",{className:"space-y-0.5",children:ie.map(b=>jsxRuntime.jsx(Pt,{repo:b,selected:d===b.repo_id,expanded:f===b.repo_id,onSelect:()=>{m(b.repo_id),w(null),h(null);},onToggle:()=>g(f===b.repo_id?null:b.repo_id),children:jsxRuntime.jsx("div",{className:"ml-10 pl-1",children:Ee.map(P=>jsxRuntime.jsx(Tt,{entry:P,selected:p?.path===P.path,onSelect:_e,depth:P.path.split("/").length-1},P.path))})},b.repo_id))})})]}),jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntime.jsx(Et,{entry:p,content:k,loading:v,repoName:Pe?.name||""})}),oe==="write"&&jsxRuntime.jsx(St,{config:r,onClose:()=>U(null),onCreated:u}),oe==="upload"&&jsxRuntime.jsx(Ct,{config:r,onClose:()=>U(null),onCreated:u})]})}async function Ne(r,e,o,n){let a={"Content-Type":"application/json",...o?.headers};n&&(a.Authorization=`Bearer ${n}`);let c=await fetch(`${r}${e}`,{...o,headers:a});if(!c.ok){let t=`HTTP ${c.status}`;try{let s=await c.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return c.json()}function zt({config:r,repoId:e,onAuthRequired:o,className:n,style:a}){let c=r.apiBaseUrl,t=r.apiKey,[s,i]=react.useState({stars:0,starred:false,repo_id:e}),[u,d]=react.useState(false),[m,f]=react.useState(null),g=react.useRef(true),p=c.includes("/cpx/rack")?"":"/api/rack";react.useEffect(()=>(g.current=true,Ne(c,`${p}/${e}/stars`,void 0,t).then(k=>{g.current&&i(k);}).catch(()=>{}),()=>{g.current=false;}),[c,e,t,p]);let w=react.useCallback(async k=>{if(k.preventDefault(),k.stopPropagation(),!t){o?.();return}d(true),f(null);try{let h=s.starred?"DELETE":"POST",v=await Ne(c,`${p}/${e}/star`,{method:h},t);g.current&&i({stars:v.stars,starred:v.starred,repo_id:e});}catch(h){g.current&&f(h.message);}finally{g.current&&d(false);}},[c,e,t,s.starred,o]);return jsxRuntime.jsxs("button",{onClick:w,disabled:u,title:m||(s.starred?"Unstar (100k tokens)":"Star (100k tokens)"),className:n,style:{display:"inline-flex",alignItems:"center",gap:"4px",background:"none",border:"none",cursor:u?"wait":"pointer",padding:"4px 8px",fontSize:"12px",fontFamily:"inherit",color:s.starred?"#f59e0b":"#91918d",transition:"color 150ms",opacity:u?.5:1,...a},children:[jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:s.starred?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})}),jsxRuntime.jsx("span",{children:s.stars})]})}
11
+ exports.Markdown=Q;exports.RackBrowser=_t;exports.StarButton=zt;exports.estimateCost=pe;exports.useNetworkStats=ot;exports.usePaginatedRepos=K;exports.useRackClient=R;exports.useRackRegister=Ve;exports.useRackSession=Je;exports.useRepoPush=He;exports.useRepoTree=F;exports.useRepos=Be;exports.useSkillStats=Ye;exports.useStar=ut;exports.useTensorStats=tt;exports.useTrending=it;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { CostEstimate, DiffEntry, InitResult, NetworkStats, PaginatedResult, PaginationInfo, PaginationParams, PushResult, RackConfig, RackSession, RepoCommit, RepoFile, RepoInfo, RepoTree, SkillMeta, SkillRegistrationInput, SkillRegistrationResult, SkillStats, StarInfo, StarResult, TensorMeta, TensorRegistrationInput, TensorRegistrationResult, TensorStats, TokenBudget, TreeEntry, TrendingRepo } from './types/index.cjs';
2
2
  export { RackClient, estimateCost, useNetworkStats, usePaginatedRepos, useRackClient, useRackRegister, useRackSession, useRepoPush, useRepoTree, useRepos, useSkillStats, useStar, useTensorStats, useTrending } from './hooks/index.cjs';
3
- export { Markdown, RackBrowser, RackBrowserProps } from './components/index.cjs';
3
+ export { Markdown, RackBrowser, RackBrowserProps, StarButton, StarButtonProps } from './components/index.cjs';
4
4
  import 'react/jsx-runtime';
5
5
  import 'react';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { CostEstimate, DiffEntry, InitResult, NetworkStats, PaginatedResult, PaginationInfo, PaginationParams, PushResult, RackConfig, RackSession, RepoCommit, RepoFile, RepoInfo, RepoTree, SkillMeta, SkillRegistrationInput, SkillRegistrationResult, SkillStats, StarInfo, StarResult, TensorMeta, TensorRegistrationInput, TensorRegistrationResult, TensorStats, TokenBudget, TreeEntry, TrendingRepo } from './types/index.js';
2
2
  export { RackClient, estimateCost, useNetworkStats, usePaginatedRepos, useRackClient, useRackRegister, useRackSession, useRepoPush, useRepoTree, useRepos, useSkillStats, useStar, useTensorStats, useTrending } from './hooks/index.js';
3
- export { Markdown, RackBrowser, RackBrowserProps } from './components/index.js';
3
+ export { Markdown, RackBrowser, RackBrowserProps, StarButton, StarButtonProps } from './components/index.js';
4
4
  import 'react/jsx-runtime';
5
5
  import 'react';
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
- import {useMemo,useRef,useState,useCallback,useEffect}from'react';import {Loader2,FileText}from'lucide-react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsx,jsxs,Fragment}from'react/jsx-runtime';async function v(r,e,o,n){let s={"Content-Type":"application/json",...o?.headers};n&&(s.Authorization=`Bearer ${n}`);let f=await fetch(`${r}${e}`,{...o,headers:s});if(!f.ok){let t=`HTTP ${f.status}`;try{let a=await f.json();a.error&&(t=a.error);}catch{}throw new Error(t)}return f.json()}function B(r){let e=r.indexOf(":");return {mode:r.slice(0,e),cid:r.slice(e+1)}}function b(r){let e=r.apiBaseUrl,o=r.authorMid,n=r.ownerMid,s=r.apiKey,f=r.stacknetUrl||r.apiBaseUrl;return useMemo(()=>({async listRepos(t,a){let l=new URLSearchParams;(t||n)&&l.set("owner",t||n),a?.limit&&l.set("limit",String(a.limit)),a?.cursor&&l.set("cursor",a.cursor);let c=l.toString()?`?${l}`:"",u=await v(e,`/api/rack/repos${c}`,void 0,s);return {items:u.repos||[],pagination:u.pagination||{total:(u.repos||[]).length,limit:50,has_more:false,next_cursor:null}}},async initRepo(t){return v(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...t,owner_mid:n})},s)},async push(t,a){return v(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...a,author_mid:o})},s)},async getTree(t,a="main"){let l=await v(e,`/api/rack/${t}/tree/${a}`,void 0,s);return {tree:l.tree,commit_cid:l.commit_cid}},async getBlob(t,a){return (await v(e,`/api/rack/${t}/blob/${a}`,void 0,s)).content},async getLog(t,a,l){let c=new URLSearchParams;a&&c.set("ref",a),l&&c.set("max_count",String(l));let u=c.toString()?`?${c}`:"";return (await v(e,`/api/rack/${t}/log${u}`,void 0,s)).commits||[]},async getBranches(t){return (await v(e,`/api/rack/${t}/branches`,void 0,s)).branches||[]},async createBranch(t,a,l){return v(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:a,from_ref:l})},s)},async merge(t,a,l){return v(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:a,target_branch:l})},s)},async getDiff(t,a,l){return (await v(e,`/api/rack/${t}/diff/${a}/${l}`,void 0,s)).diff?.entries||[]},async starRepo(t){return v(e,`/api/rack/${t}/star`,{method:"POST"},s)},async unstarRepo(t){return v(e,`/api/rack/${t}/star`,{method:"DELETE"},s)},async getStarInfo(t){return v(e,`/api/rack/${t}/stars`,void 0,s)},async getSkillStats(t){let a={meta:null,tokenCount:null,usageCount:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return a;if(l.entries["META.json"]){let m=B(l.entries["META.json"]).cid,d=await this.getBlob(t,m);a.meta=JSON.parse(d);}let c=0,u=Object.values(l.entries).map(async m=>{try{let d=B(m).cid,g=await this.getBlob(t,d);c+=g.length;}catch{}});await Promise.all(u),c>0&&(a.tokenCount=Math.ceil(c/4)),a.meta?.skill_id&&(a.usageCount=await this.getSkillUsageCount(a.meta.skill_id));}catch{}return a},async getSkillUsageCount(t){try{let a=await fetch(`${f}/v1/skills/${encodeURIComponent(t)}`);if(a.ok){let c=await a.json();return c.usage_count??c.usageCount??null}let l=await fetch(`${f}/v1/skills?scope=public`);if(l.ok){let u=((await l.json()).skills||[]).find(m=>m.name===t||m.id===t);if(u)return u.usage_count??u.usageCount??0}return 0}catch{return null}},async getTensorStats(t){let a={meta:null,sizeMB:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return a;if(l.entries["TENSOR_META.json"]){let c=B(l.entries["TENSOR_META.json"]).cid,u=await this.getBlob(t,c);a.meta=JSON.parse(u),a.sizeMB=a.meta?.tensor_size_mb??null;}}catch{}return a},async getNetworkStats(){try{return (await v(e,"/api/rack/stats",void 0,s)).stats||null}catch{return null}},async getTrending(t=5,a=1,l){try{let c=new URLSearchParams({limit:String(t),days:String(a)});l&&c.set("cursor",l);let u=await v(e,`/api/rack/trending?${c}`,void 0,s);return {items:u.trending||[],pagination:u.pagination||{total:(u.trending||[]).length,limit:t,has_more:!1,next_cursor:null}}}catch{return {items:[],pagination:{total:0,limit:t,has_more:false,next_cursor:null}}}}}),[e,o,n,s,f])}function D(r){let e=b(r),o=useRef(e);o.current=e;let[n,s]=useState([]),[f,t]=useState(true),[a,l]=useState(null),c=useRef(true),u=useRef(null),m=useCallback(async()=>{u.current?.abort();let d=new AbortController;u.current=d;try{c.current&&(t(!0),l(null));let g=await o.current.listRepos();c.current&&!d.signal.aborted&&s(g.items);}catch(g){c.current&&!d.signal.aborted&&l(g instanceof Error?g.message:"Failed to load repos");}finally{c.current&&!d.signal.aborted&&t(false);}},[]);return useEffect(()=>(c.current=true,m(),()=>{c.current=false,u.current?.abort();}),[m]),{repos:n,loading:f,error:a,refresh:m}}function $e(r){return Object.entries(r).map(([e,o])=>{let n=o.indexOf(":"),s=n>0?o.slice(0,n):"100644",f=n>0?o.slice(n+1):o;return {path:e,mode:s,cid:f,isDir:s==="040000"}}).sort((e,o)=>e.isDir!==o.isDir?e.isDir?-1:1:e.path.localeCompare(o.path))}function H(r,e,o="main"){let n=b(r),[s,f]=useState([]),[t,a]=useState(false),[l,c]=useState(null),u=useRef(true),m=useCallback(async()=>{if(e)try{u.current&&(a(!0),c(null));let{tree:g}=await n.getTree(e,o);u.current&&f($e(g.entries));}catch(g){u.current&&c(g instanceof Error?g.message:"Failed to load tree");}finally{u.current&&a(false);}},[n,e,o]);useEffect(()=>(u.current=true,m(),()=>{u.current=false;}),[m]);let d=useCallback(async g=>{if(!e)throw new Error("No repo selected");return n.getBlob(e,g)},[n,e]);return {entries:s,loading:t,error:l,refresh:m,getFileContent:d}}function Ae(r){let e=b(r),[o,n]=useState(false),[s,f]=useState(null),t=useRef(true);return useEffect(()=>(t.current=true,()=>{t.current=false;}),[]),{push:useCallback(async(l,c,u,m)=>{try{return t.current&&(n(!0),f(null)),await e.push(l,{files:c,message:u,branch:m})}catch(d){let g=d instanceof Error?d.message:"Push failed";return t.current&&f(g),null}finally{t.current&&n(false);}},[e]),pushing:o,error:s}}function Oe(r,e={}){let{pageSize:o=50,owner:n}=e,s=b(r),[f,t]=useState([]),[a,l]=useState(null),[c,u]=useState(false),[m,d]=useState(null),g=useRef(null),p=useRef(true),x=useCallback(async(C,I=false)=>{u(true),d(null);try{let P=await s.listRepos(n,{limit:o,cursor:C||void 0});p.current&&(t(M=>I?[...M,...P.items]:P.items),l(P.pagination),g.current=P.pagination.next_cursor);}catch(P){p.current&&d(P.message);}finally{p.current&&u(false);}},[s,n,o]),w=useCallback(async()=>{!g.current||c||await x(g.current,true);},[x,c]),R=useCallback(async()=>{g.current=null,await x(void 0,false);},[x]);return useEffect(()=>(p.current=true,x(),()=>{p.current=false;}),[x]),{repos:f,hasMore:a?.has_more??false,total:a?.total??0,loading:c,error:m,loadMore:w,reset:R,pagination:a}}var J="stacknet-rack-apikey";function De(r){let e=r.stacknetUrl||r.apiBaseUrl,[o,n]=useState({authenticated:false}),[s,f]=useState(null),[t,a]=useState(false),l=useCallback(d=>({"Content-Type":"application/json",...d||r.apiKey?{Authorization:`Bearer ${d||r.apiKey}`}:{}}),[r.apiKey]),c=useCallback(async d=>{a(true);try{let g=await fetch(`${e}/health`,{headers:l(d)});if(!g.ok)throw new Error(`Authentication failed: ${g.status}`);let p={authenticated:!0,apiKey:d,permission:d.startsWith("gk_")?"write":"read"};n(p);try{localStorage.setItem(J,d);}catch{}return p}catch(g){throw n({authenticated:false}),g}finally{a(false);}},[e,l]),u=useCallback(()=>{n({authenticated:false}),f(null);try{localStorage.removeItem(J);}catch{}},[]),m=useCallback(async()=>{let d=o.apiKey||r.apiKey;if(!d)return null;try{let g=await fetch(`${e}/network/usage`,{headers:l(d)});if(!g.ok)return null;let p=await g.json(),x={planAllocation:p.plan_allocation??p.planAllocation??0,inferenceUsed:p.inference_used??p.inferenceUsed??0,ledgerSpent:p.ledger_spent??p.ledgerSpent??0,totalUsed:p.total_used??p.totalUsed??0,remaining:p.remaining??0,percent:p.percent??0,exceeded:p.exceeded??!1};return f(x),x}catch{return null}},[o.apiKey,r.apiKey,e,l]);return useEffect(()=>{let d=r.apiKey;if(d){n({authenticated:true,apiKey:d,permission:d.startsWith("gk_")?"write":"read"});return}try{let g=localStorage.getItem(J);g&&n({authenticated:!0,apiKey:g,permission:g.startsWith("gk_")?"write":"read"});}catch{}},[r.apiKey]),{session:o,budget:s,loading:t,login:c,logout:u,refreshBudget:m}}var ce=1e3,ue=1e3,de=100;function fe(r,e){if(r==="skill"){let s=de+Math.ceil(e/4);return {type:r,totalBytes:e,totalMegabytes:e/1e6,baseCost:s,multiplier:ce,registrationCostTokens:s*ce}}let o=Math.ceil(e/1e6),n=de+o;return {type:r,totalBytes:e,totalMegabytes:o,baseCost:n,multiplier:ue,registrationCostTokens:n*ue}}function Fe(r){let e=r.stacknetUrl||r.apiBaseUrl,o=r.apiKey,[n,s]=useState(false),[f,t]=useState(null),a=useCallback(()=>{if(!o)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${o}`}},[o]),l=useCallback(async u=>{s(true),t(null);try{let m=await fetch(`${e}/skills`,{method:"POST",headers:a(),body:JSON.stringify(u)});if(!m.ok){let d=await m.json().catch(()=>({error:`HTTP ${m.status}`}));throw new Error(d.error||`Registration failed: ${m.status}`)}return await m.json()}catch(m){throw t(m.message),m}finally{s(false);}},[e,a]),c=useCallback(async u=>{s(true),t(null);try{let m=await fetch(`${e}/tensors`,{method:"POST",headers:a(),body:JSON.stringify(u)});if(!m.ok){let d=await m.json().catch(()=>({error:`HTTP ${m.status}`}));throw new Error(d.error||`Registration failed: ${m.status}`)}return await m.json()}catch(m){throw t(m.message),m}finally{s(false);}},[e,a]);return {registerSkill:l,registerTensor:c,estimateCost:fe,registering:n,error:f}}function Je(r,e){let o=b(r),[n,s]=useState({meta:null,tokenCount:null,usageCount:null}),[f,t]=useState(false),[a,l]=useState(null),c=useRef(true),u=useCallback(async()=>{if(e){t(true),l(null);try{let m=await o.getSkillStats(e);c.current&&s(m);}catch(m){c.current&&l(m.message);}finally{c.current&&t(false);}}},[o,e]);return useEffect(()=>(c.current=true,u(),()=>{c.current=false;}),[u]),{stats:n,loading:f,error:a,refresh:u}}function Ge(r,e){let o=b(r),[n,s]=useState({meta:null,sizeMB:null}),[f,t]=useState(false),[a,l]=useState(null),c=useRef(true),u=useCallback(async()=>{if(e){t(true),l(null);try{let m=await o.getTensorStats(e);c.current&&s(m);}catch(m){c.current&&l(m.message);}finally{c.current&&t(false);}}},[o,e]);return useEffect(()=>(c.current=true,u(),()=>{c.current=false;}),[u]),{stats:n,loading:f,error:a,refresh:u}}function et(r){let e=b(r),[o,n]=useState(null),[s,f]=useState(false),[t,a]=useState(null),l=useRef(true),c=useCallback(async()=>{f(true),a(null);try{let u=await e.getNetworkStats();l.current&&n(u);}catch(u){l.current&&a(u.message);}finally{l.current&&f(false);}},[e]);return useEffect(()=>(l.current=true,c(),()=>{l.current=false;}),[c]),{stats:o,loading:s,error:t,refresh:c}}function rt(r,e=5,o=1){let n=b(r),[s,f]=useState([]),[t,a]=useState(null),[l,c]=useState(false),[u,m]=useState(null),d=useRef(true),g=useRef(null),p=useCallback(async w=>{c(true),m(null),g.current=null;try{let R=await n.getTrending(e,w??o);d.current&&(f(R.items),a(R.pagination),g.current=R.pagination.next_cursor);}catch(R){d.current&&m(R.message);}finally{d.current&&c(false);}},[n,e,o]),x=useCallback(async()=>{if(!(!g.current||l)){c(true);try{let w=await n.getTrending(e,o,g.current);d.current&&(f(R=>[...R,...w.items]),a(w.pagination),g.current=w.pagination.next_cursor);}catch(w){d.current&&m(w.message);}finally{d.current&&c(false);}}},[n,e,o,l]);return useEffect(()=>(d.current=true,p(),()=>{d.current=false;}),[p]),{repos:s,hasMore:t?.has_more??false,total:t?.total??0,loading:l,error:u,refresh:p,loadMore:x}}function ot(r,e){let o=b(r),[n,s]=useState({stars:0,starred:false,repo_id:e||""}),[f,t]=useState(false),[a,l]=useState(null),c=useRef(true),u=useCallback(async()=>{if(e)try{let d=await o.getStarInfo(e);c.current&&s(d);}catch{}},[o,e]);useEffect(()=>(c.current=true,u(),()=>{c.current=false;}),[u]);let m=useCallback(async()=>{if(e){t(true),l(null);try{let d=n.starred?await o.unstarRepo(e):await o.starRepo(e);c.current&&s({stars:d.stars,starred:d.starred,repo_id:e});}catch(d){c.current&&l(d.message);}finally{c.current&&t(false);}}},[o,e,n.starred]);return {...n,loading:f,error:a,toggle:m,refresh:u}}function N(...r){return twMerge(clsx(r))}var lt=/^(https?:\/\/|mailto:|\/[^/])/i;function ct(r){let e=r.trim();return lt.test(e)?e:null}function U(r){let e=[],o=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,n=0,s,f=0;for(;(s=o.exec(r))!==null;){s.index>n&&e.push(r.slice(n,s.index));let t=`i${f++}`;if(s[1])e.push(jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[0.85em] font-mono text-pink-400",children:s[1].slice(1,-1)},t));else if(s[2])e.push(jsx("strong",{children:s[3]},t));else if(s[4])e.push(jsx("em",{children:s[5]},t));else if(s[6])e.push(jsx("em",{children:s[7]},t));else if(s[8]){let a=ct(s[10]);a?e.push(jsx("a",{href:a,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:s[9]},t)):e.push(s[9]);}n=s.index+s[0].length;}return n<r.length&&e.push(r.slice(n)),e.length>0?e:[r]}function ut(r){let e=r.split(`
2
- `),o=[],n=0;for(;n<e.length;){let s=e[n];if(s.trim()===""){n++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(s.trim())){o.push({type:"hr"}),n++;continue}let f=s.match(/^(#{1,6})\s+(.+)/);if(f){o.push({type:"heading",level:f[1].length,content:f[2]}),n++;continue}if(s.trim().startsWith("```")){let a=s.trim().slice(3).trim(),l=[];for(n++;n<e.length&&!e[n].trim().startsWith("```");)l.push(e[n]),n++;o.push({type:"code",content:l.join(`
3
- `),lang:a||void 0}),n++;continue}if(/^\s*[-*+]\s/.test(s)){let a=[];for(;n<e.length&&/^\s*[-*+]\s/.test(e[n]);)a.push(e[n].replace(/^\s*[-*+]\s+/,"")),n++;o.push({type:"ul",items:a});continue}if(/^\s*\d+[.)]\s/.test(s)){let a=[];for(;n<e.length&&/^\s*\d+[.)]\s/.test(e[n]);)a.push(e[n].replace(/^\s*\d+[.)]\s+/,"")),n++;o.push({type:"ol",items:a});continue}let t=[];for(;n<e.length&&e[n].trim()!==""&&!e[n].match(/^#{1,6}\s/)&&!e[n].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[n])&&!/^\s*\d+[.)]\s/.test(e[n]);)t.push(e[n]),n++;t.length>0&&o.push({type:"paragraph",content:t.join(" ")});}return o}var dt={1:"text-2xl font-bold mt-6 mb-3",2:"text-xl font-bold mt-5 mb-2",3:"text-lg font-semibold mt-4 mb-2",4:"text-base font-semibold mt-3 mb-1",5:"text-sm font-semibold mt-2 mb-1",6:"text-sm font-medium mt-2 mb-1"};function ft(r,e){switch(r.type){case "hr":return jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let o=Math.min(Math.max(r.level||1,1),6),n=`h${o}`;return jsx(n,{className:N("text-foreground",dt[o]),children:U(r.content||"")},`b${e}`)}case "paragraph":return jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:U(r.content||"")},`b${e}`);case "code":return jsx("pre",{className:"mb-3 overflow-x-auto rounded-lg bg-muted p-4 text-sm font-mono leading-relaxed text-foreground",children:jsx("code",{children:r.content})},`b${e}`);case "ul":return jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:r.items?.map((o,n)=>jsx("li",{className:"leading-relaxed",children:U(o)},`li${e}-${n}`))},`b${e}`);case "ol":return jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:r.items?.map((o,n)=>jsx("li",{className:"leading-relaxed",children:U(o)},`li${e}-${n}`))},`b${e}`);default:return null}}function Q({content:r,className:e}){let o=ut(r);return jsx("div",{className:N("text-sm",e),children:o.map((n,s)=>ft(n,s))})}function xe({open:r,className:e}){return jsx("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:N("shrink-0 transition-transform duration-150",r?"rotate-0":"-rotate-90",e),children:jsx("path",{d:"M16.134 6.16a.5.5 0 1 1 .732.68l-6.5 7-.077.068a.5.5 0 0 1-.655-.068l-6.5-7-.062-.08a.5.5 0 0 1 .718-.667l.076.067L10 12.767z"})})}function he({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function X({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M15.147 4.146a.5.5 0 0 1 .707.707L10.707 10l5.147 5.147a.5.5 0 0 1-.63.771l-.078-.064L10 10.707l-5.146 5.147a.5.5 0 0 1-.708-.707L9.293 10 4.146 4.853a.5.5 0 0 1 .708-.707L10 9.293z"})})}function we({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M10 3a.5.5 0 0 1 .5.5v6h6l.1.01a.5.5 0 0 1 0 .98l-.1.01h-6v6a.5.5 0 0 1-1 0v-6h-6a.5.5 0 0 1 0-1h6v-6A.5.5 0 0 1 10 3"})})}function pt(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M6.5 3A2.5 2.5 0 0 0 4 5.5v9A2.5 2.5 0 0 0 6.5 17h7a2.5 2.5 0 0 0 2.5-2.5v-7A2.5 2.5 0 0 0 13.5 5H11V3.5a.5.5 0 0 0-1 0V5H6.5ZM5 5.5A1.5 1.5 0 0 1 6.5 4H9v1H6.5A1.5 1.5 0 0 0 5 6.5v8A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 13.5 6H11V4h2.5A2.5 2.5 0 0 1 16 6.5v8a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-9Z"})})}function ht(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M5.5 3A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h9a2.5 2.5 0 0 0 2.5-2.5v-9A2.5 2.5 0 0 0 14.5 3h-9ZM4 5.5A1.5 1.5 0 0 1 5.5 4h9A1.5 1.5 0 0 1 16 5.5v9a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 4 14.5v-9ZM7 7.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5Z"})})}function yt(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M10 2a.5.5 0 0 1 .354.146l3 3a.5.5 0 0 1-.708.708L10.5 3.707V12.5a.5.5 0 0 1-1 0V3.707L7.354 5.854a.5.5 0 1 1-.708-.708l3-3A.5.5 0 0 1 10 2ZM4 13.5a.5.5 0 0 1 1 0v1A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-1a.5.5 0 0 1 1 0v1a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-1Z"})})}function be(){let[r,e]=useState(false);return useEffect(()=>{if(typeof window>"u")return;let o=()=>e(window.innerWidth<768);return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),r}function Re({onClose:r,children:e,title:o}){let n=be(),s=useRef(r);return s.current=r,useEffect(()=>{let f=t=>{t.key==="Escape"&&s.current();};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[]),n?jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full max-h-[90vh] overflow-y-auto rounded-t-2xl bg-[#1a1a1a] p-5 pb-8 animate-in slide-in-from-bottom duration-200",onClick:f=>f.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-4 h-1 w-10 rounded-full bg-zinc-600"}),jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsx("h2",{className:"text-lg font-semibold text-foreground",children:o}),jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(X,{size:20})})]}),e]})]}):jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full max-w-lg overflow-y-auto rounded-2xl bg-[#1a1a1a] p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:f=>f.stopPropagation(),children:[jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsx("h2",{className:"text-lg font-semibold text-foreground",children:o}),jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(X,{size:20})})]}),e]})]})}function kt({onClose:r,onCreated:e,config:o}){let[n,s]=useState(""),[f,t]=useState(""),[a,l]=useState(""),[c,u]=useState(false),[m,d]=useState(null);return jsx(Re,{title:"Write skill instructions",onClose:r,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsx("input",{id:"skill-name",value:n,onChange:p=>s(p.target.value),placeholder:"weekly-status-report",className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-desc",className:"text-sm text-muted-foreground",children:"Description"}),jsx("textarea",{id:"skill-desc",value:f,onChange:p=>t(p.target.value),placeholder:"Generate weekly status reports from recent work.",rows:3,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-instructions",className:"text-sm text-muted-foreground",children:"Instructions"}),jsx("textarea",{id:"skill-instructions",value:a,onChange:p=>l(p.target.value),placeholder:"Summarize my recent work in three sections: wins, blockers, and next steps.",rows:8,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),m&&jsx("p",{className:"text-sm text-red-500",children:m}),jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsx("button",{onClick:r,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsx("button",{onClick:async()=>{if(n.trim()){u(true),d(null);try{let p=o.apiBaseUrl||"",x=`# ${n.trim()}
1
+ import {useMemo,useRef,useState,useCallback,useEffect}from'react';import {Loader2,FileText}from'lucide-react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsx,jsxs,Fragment}from'react/jsx-runtime';async function S(r,e,o,n){let a={"Content-Type":"application/json",...o?.headers};n&&(a.Authorization=`Bearer ${n}`);let c=await fetch(`${r}${e}`,{...o,headers:a});if(!c.ok){let t=`HTTP ${c.status}`;try{let s=await c.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return c.json()}function A(r){let e=r.indexOf(":");return {mode:r.slice(0,e),cid:r.slice(e+1)}}function R(r){let e=r.apiBaseUrl,o=r.authorMid,n=r.ownerMid,a=r.apiKey,c=r.stacknetUrl||r.apiBaseUrl;return useMemo(()=>({async listRepos(t,s){let i=new URLSearchParams;(t||n)&&i.set("owner",t||n),s?.limit&&i.set("limit",String(s.limit)),s?.cursor&&i.set("cursor",s.cursor);let u=i.toString()?`?${i}`:"",d=await S(e,`/api/rack/repos${u}`,void 0,a);return {items:d.repos||[],pagination:d.pagination||{total:(d.repos||[]).length,limit:50,has_more:false,next_cursor:null}}},async initRepo(t){return S(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...t,owner_mid:n})},a)},async push(t,s){return S(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...s,author_mid:o})},a)},async getTree(t,s="main"){let i=await S(e,`/api/rack/${t}/tree/${s}`,void 0,a);return {tree:i.tree,commit_cid:i.commit_cid}},async getBlob(t,s){return (await S(e,`/api/rack/${t}/blob/${s}`,void 0,a)).content},async getLog(t,s,i){let u=new URLSearchParams;s&&u.set("ref",s),i&&u.set("max_count",String(i));let d=u.toString()?`?${u}`:"";return (await S(e,`/api/rack/${t}/log${d}`,void 0,a)).commits||[]},async getBranches(t){return (await S(e,`/api/rack/${t}/branches`,void 0,a)).branches||[]},async createBranch(t,s,i){return S(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:s,from_ref:i})},a)},async merge(t,s,i){return S(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:s,target_branch:i})},a)},async getDiff(t,s,i){return (await S(e,`/api/rack/${t}/diff/${s}/${i}`,void 0,a)).diff?.entries||[]},async starRepo(t){return S(e,`/api/rack/${t}/star`,{method:"POST"},a)},async unstarRepo(t){return S(e,`/api/rack/${t}/star`,{method:"DELETE"},a)},async getStarInfo(t){return S(e,`/api/rack/${t}/stars`,void 0,a)},async getSkillStats(t){let s={meta:null,tokenCount:null,usageCount:null};try{let{tree:i}=await this.getTree(t,"main");if(!i?.entries)return s;if(i.entries["META.json"]){let m=A(i.entries["META.json"]).cid,f=await this.getBlob(t,m);s.meta=JSON.parse(f);}let u=0,d=Object.values(i.entries).map(async m=>{try{let f=A(m).cid,g=await this.getBlob(t,f);u+=g.length;}catch{}});await Promise.all(d),u>0&&(s.tokenCount=Math.ceil(u/4)),s.meta?.skill_id&&(s.usageCount=await this.getSkillUsageCount(s.meta.skill_id));}catch{}return s},async getSkillUsageCount(t){try{let s=await fetch(`${c}/v1/skills/${encodeURIComponent(t)}`);if(s.ok){let u=await s.json();return u.usage_count??u.usageCount??null}let i=await fetch(`${c}/v1/skills?scope=public`);if(i.ok){let d=((await i.json()).skills||[]).find(m=>m.name===t||m.id===t);if(d)return d.usage_count??d.usageCount??0}return 0}catch{return null}},async getTensorStats(t){let s={meta:null,sizeMB:null};try{let{tree:i}=await this.getTree(t,"main");if(!i?.entries)return s;if(i.entries["TENSOR_META.json"]){let u=A(i.entries["TENSOR_META.json"]).cid,d=await this.getBlob(t,u);s.meta=JSON.parse(d),s.sizeMB=s.meta?.tensor_size_mb??null;}}catch{}return s},async getNetworkStats(){try{return (await S(e,"/api/rack/stats",void 0,a)).stats||null}catch{return null}},async getTrending(t=5,s=1,i){try{let u=new URLSearchParams({limit:String(t),days:String(s)});i&&u.set("cursor",i);let d=await S(e,`/api/rack/trending?${u}`,void 0,a);return {items:d.trending||[],pagination:d.pagination||{total:(d.trending||[]).length,limit:t,has_more:!1,next_cursor:null}}}catch{return {items:[],pagination:{total:0,limit:t,has_more:false,next_cursor:null}}}}}),[e,o,n,a,c])}function Be(r){let e=R(r),o=useRef(e);o.current=e;let[n,a]=useState([]),[c,t]=useState(true),[s,i]=useState(null),u=useRef(true),d=useRef(null),m=useCallback(async()=>{d.current?.abort();let f=new AbortController;d.current=f;try{u.current&&(t(!0),i(null));let g=await o.current.listRepos();u.current&&!f.signal.aborted&&a(g.items);}catch(g){u.current&&!f.signal.aborted&&i(g instanceof Error?g.message:"Failed to load repos");}finally{u.current&&!f.signal.aborted&&t(false);}},[]);return useEffect(()=>(u.current=true,m(),()=>{u.current=false,d.current?.abort();}),[m]),{repos:n,loading:c,error:s,refresh:m}}function Oe(r){return Object.entries(r).map(([e,o])=>{let n=o.indexOf(":"),a=n>0?o.slice(0,n):"100644",c=n>0?o.slice(n+1):o;return {path:e,mode:a,cid:c,isDir:a==="040000"}}).sort((e,o)=>e.isDir!==o.isDir?e.isDir?-1:1:e.path.localeCompare(o.path))}function F(r,e,o="main"){let n=R(r),[a,c]=useState([]),[t,s]=useState(false),[i,u]=useState(null),d=useRef(true),m=useCallback(async()=>{if(e)try{d.current&&(s(!0),u(null));let{tree:g}=await n.getTree(e,o);d.current&&c(Oe(g.entries));}catch(g){d.current&&u(g instanceof Error?g.message:"Failed to load tree");}finally{d.current&&s(false);}},[n,e,o]);useEffect(()=>(d.current=true,m(),()=>{d.current=false;}),[m]);let f=useCallback(async g=>{if(!e)throw new Error("No repo selected");return n.getBlob(e,g)},[n,e]);return {entries:a,loading:t,error:i,refresh:m,getFileContent:f}}function He(r){let e=R(r),[o,n]=useState(false),[a,c]=useState(null),t=useRef(true);return useEffect(()=>(t.current=true,()=>{t.current=false;}),[]),{push:useCallback(async(i,u,d,m)=>{try{return t.current&&(n(!0),c(null)),await e.push(i,{files:u,message:d,branch:m})}catch(f){let g=f instanceof Error?f.message:"Push failed";return t.current&&c(g),null}finally{t.current&&n(false);}},[e]),pushing:o,error:a}}function K(r,e={}){let{pageSize:o=50,owner:n}=e,a=R(r),[c,t]=useState([]),[s,i]=useState(null),[u,d]=useState(false),[m,f]=useState(null),g=useRef(null),p=useRef(true),w=useCallback(async(v,E=false)=>{d(true),f(null);try{let N=await a.listRepos(n,{limit:o,cursor:v||void 0});p.current&&(t(_=>E?[..._,...N.items]:N.items),i(N.pagination),g.current=N.pagination.next_cursor);}catch(N){p.current&&f(N.message);}finally{p.current&&d(false);}},[a,n,o]),k=useCallback(async()=>{!g.current||u||await w(g.current,true);},[w,u]),h=useCallback(async()=>{g.current=null,await w(void 0,false);},[w]);return useEffect(()=>(p.current=true,w(),()=>{p.current=false;}),[w]),{repos:c,hasMore:s?.has_more??false,total:s?.total??0,loading:u,error:m,loadMore:k,reset:h,pagination:s}}var J="stacknet-rack-apikey";function Je(r){let e=r.stacknetUrl||r.apiBaseUrl,[o,n]=useState({authenticated:false}),[a,c]=useState(null),[t,s]=useState(false),i=useCallback(f=>({"Content-Type":"application/json",...f||r.apiKey?{Authorization:`Bearer ${f||r.apiKey}`}:{}}),[r.apiKey]),u=useCallback(async f=>{s(true);try{let g=await fetch(`${e}/health`,{headers:i(f)});if(!g.ok)throw new Error(`Authentication failed: ${g.status}`);let p={authenticated:!0,apiKey:f,permission:f.startsWith("gk_")?"write":"read"};n(p);try{localStorage.setItem(J,f);}catch{}return p}catch(g){throw n({authenticated:false}),g}finally{s(false);}},[e,i]),d=useCallback(()=>{n({authenticated:false}),c(null);try{localStorage.removeItem(J);}catch{}},[]),m=useCallback(async()=>{let f=o.apiKey||r.apiKey;if(!f)return null;try{let g=await fetch(`${e}/network/usage`,{headers:i(f)});if(!g.ok)return null;let p=await g.json(),w={planAllocation:p.plan_allocation??p.planAllocation??0,inferenceUsed:p.inference_used??p.inferenceUsed??0,ledgerSpent:p.ledger_spent??p.ledgerSpent??0,totalUsed:p.total_used??p.totalUsed??0,remaining:p.remaining??0,percent:p.percent??0,exceeded:p.exceeded??!1};return c(w),w}catch{return null}},[o.apiKey,r.apiKey,e,i]);return useEffect(()=>{let f=r.apiKey;if(f){n({authenticated:true,apiKey:f,permission:f.startsWith("gk_")?"write":"read"});return}try{let g=localStorage.getItem(J);g&&n({authenticated:!0,apiKey:g,permission:g.startsWith("gk_")?"write":"read"});}catch{}},[r.apiKey]),{session:o,budget:a,loading:t,login:u,logout:d,refreshBudget:m}}var fe=1e3,me=1e3,ge=100;function pe(r,e){if(r==="skill"){let a=ge+Math.ceil(e/4);return {type:r,totalBytes:e,totalMegabytes:e/1e6,baseCost:a,multiplier:fe,registrationCostTokens:a*fe}}let o=Math.ceil(e/1e6),n=ge+o;return {type:r,totalBytes:e,totalMegabytes:o,baseCost:n,multiplier:me,registrationCostTokens:n*me}}function Ve(r){let e=r.stacknetUrl||r.apiBaseUrl,o=r.apiKey,[n,a]=useState(false),[c,t]=useState(null),s=useCallback(()=>{if(!o)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${o}`}},[o]),i=useCallback(async d=>{a(true),t(null);try{let m=await fetch(`${e}/skills`,{method:"POST",headers:s(),body:JSON.stringify(d)});if(!m.ok){let f=await m.json().catch(()=>({error:`HTTP ${m.status}`}));throw new Error(f.error||`Registration failed: ${m.status}`)}return await m.json()}catch(m){throw t(m.message),m}finally{a(false);}},[e,s]),u=useCallback(async d=>{a(true),t(null);try{let m=await fetch(`${e}/tensors`,{method:"POST",headers:s(),body:JSON.stringify(d)});if(!m.ok){let f=await m.json().catch(()=>({error:`HTTP ${m.status}`}));throw new Error(f.error||`Registration failed: ${m.status}`)}return await m.json()}catch(m){throw t(m.message),m}finally{a(false);}},[e,s]);return {registerSkill:i,registerTensor:u,estimateCost:pe,registering:n,error:c}}function Ye(r,e){let o=R(r),[n,a]=useState({meta:null,tokenCount:null,usageCount:null}),[c,t]=useState(false),[s,i]=useState(null),u=useRef(true),d=useCallback(async()=>{if(e){t(true),i(null);try{let m=await o.getSkillStats(e);u.current&&a(m);}catch(m){u.current&&i(m.message);}finally{u.current&&t(false);}}},[o,e]);return useEffect(()=>(u.current=true,d(),()=>{u.current=false;}),[d]),{stats:n,loading:c,error:s,refresh:d}}function tt(r,e){let o=R(r),[n,a]=useState({meta:null,sizeMB:null}),[c,t]=useState(false),[s,i]=useState(null),u=useRef(true),d=useCallback(async()=>{if(e){t(true),i(null);try{let m=await o.getTensorStats(e);u.current&&a(m);}catch(m){u.current&&i(m.message);}finally{u.current&&t(false);}}},[o,e]);return useEffect(()=>(u.current=true,d(),()=>{u.current=false;}),[d]),{stats:n,loading:c,error:s,refresh:d}}function ot(r){let e=R(r),[o,n]=useState(null),[a,c]=useState(false),[t,s]=useState(null),i=useRef(true),u=useCallback(async()=>{c(true),s(null);try{let d=await e.getNetworkStats();i.current&&n(d);}catch(d){i.current&&s(d.message);}finally{i.current&&c(false);}},[e]);return useEffect(()=>(i.current=true,u(),()=>{i.current=false;}),[u]),{stats:o,loading:a,error:t,refresh:u}}function it(r,e=5,o=1){let n=R(r),[a,c]=useState([]),[t,s]=useState(null),[i,u]=useState(false),[d,m]=useState(null),f=useRef(true),g=useRef(null),p=useCallback(async k=>{u(true),m(null),g.current=null;try{let h=await n.getTrending(e,k??o);f.current&&(c(h.items),s(h.pagination),g.current=h.pagination.next_cursor);}catch(h){f.current&&m(h.message);}finally{f.current&&u(false);}},[n,e,o]),w=useCallback(async()=>{if(!(!g.current||i)){u(true);try{let k=await n.getTrending(e,o,g.current);f.current&&(c(h=>[...h,...k.items]),s(k.pagination),g.current=k.pagination.next_cursor);}catch(k){f.current&&m(k.message);}finally{f.current&&u(false);}}},[n,e,o,i]);return useEffect(()=>(f.current=true,p(),()=>{f.current=false;}),[p]),{repos:a,hasMore:t?.has_more??false,total:t?.total??0,loading:i,error:d,refresh:p,loadMore:w}}function ut(r,e){let o=R(r),[n,a]=useState({stars:0,starred:false,repo_id:e||""}),[c,t]=useState(false),[s,i]=useState(null),u=useRef(true),d=useCallback(async()=>{if(e)try{let f=await o.getStarInfo(e);u.current&&a(f);}catch{}},[o,e]);useEffect(()=>(u.current=true,d(),()=>{u.current=false;}),[d]);let m=useCallback(async()=>{if(e){t(true),i(null);try{let f=n.starred?await o.unstarRepo(e):await o.starRepo(e);u.current&&a({stars:f.stars,starred:f.starred,repo_id:e});}catch(f){u.current&&i(f.message);}finally{u.current&&t(false);}}},[o,e,n.starred]);return {...n,loading:c,error:s,toggle:m,refresh:d}}function T(...r){return twMerge(clsx(r))}var mt=/^(https?:\/\/|mailto:|\/[^/])/i;function gt(r){let e=r.trim();return mt.test(e)?e:null}function B(r){let e=[],o=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,n=0,a,c=0;for(;(a=o.exec(r))!==null;){a.index>n&&e.push(r.slice(n,a.index));let t=`i${c++}`;if(a[1])e.push(jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[0.85em] font-mono text-pink-400",children:a[1].slice(1,-1)},t));else if(a[2])e.push(jsx("strong",{children:a[3]},t));else if(a[4])e.push(jsx("em",{children:a[5]},t));else if(a[6])e.push(jsx("em",{children:a[7]},t));else if(a[8]){let s=gt(a[10]);s?e.push(jsx("a",{href:s,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:a[9]},t)):e.push(a[9]);}n=a.index+a[0].length;}return n<r.length&&e.push(r.slice(n)),e.length>0?e:[r]}function pt(r){let e=r.split(`
2
+ `),o=[],n=0;for(;n<e.length;){let a=e[n];if(a.trim()===""){n++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(a.trim())){o.push({type:"hr"}),n++;continue}let c=a.match(/^(#{1,6})\s+(.+)/);if(c){o.push({type:"heading",level:c[1].length,content:c[2]}),n++;continue}if(a.trim().startsWith("```")){let s=a.trim().slice(3).trim(),i=[];for(n++;n<e.length&&!e[n].trim().startsWith("```");)i.push(e[n]),n++;o.push({type:"code",content:i.join(`
3
+ `),lang:s||void 0}),n++;continue}if(/^\s*[-*+]\s/.test(a)){let s=[];for(;n<e.length&&/^\s*[-*+]\s/.test(e[n]);)s.push(e[n].replace(/^\s*[-*+]\s+/,"")),n++;o.push({type:"ul",items:s});continue}if(/^\s*\d+[.)]\s/.test(a)){let s=[];for(;n<e.length&&/^\s*\d+[.)]\s/.test(e[n]);)s.push(e[n].replace(/^\s*\d+[.)]\s+/,"")),n++;o.push({type:"ol",items:s});continue}let t=[];for(;n<e.length&&e[n].trim()!==""&&!e[n].match(/^#{1,6}\s/)&&!e[n].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[n])&&!/^\s*\d+[.)]\s/.test(e[n]);)t.push(e[n]),n++;t.length>0&&o.push({type:"paragraph",content:t.join(" ")});}return o}var ht={1:"text-2xl font-bold mt-6 mb-3",2:"text-xl font-bold mt-5 mb-2",3:"text-lg font-semibold mt-4 mb-2",4:"text-base font-semibold mt-3 mb-1",5:"text-sm font-semibold mt-2 mb-1",6:"text-sm font-medium mt-2 mb-1"};function yt(r,e){switch(r.type){case "hr":return jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let o=Math.min(Math.max(r.level||1,1),6),n=`h${o}`;return jsx(n,{className:T("text-foreground",ht[o]),children:B(r.content||"")},`b${e}`)}case "paragraph":return jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:B(r.content||"")},`b${e}`);case "code":return jsx("pre",{className:"mb-3 overflow-x-auto rounded-lg bg-muted p-4 text-sm font-mono leading-relaxed text-foreground",children:jsx("code",{children:r.content})},`b${e}`);case "ul":return jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:r.items?.map((o,n)=>jsx("li",{className:"leading-relaxed",children:B(o)},`li${e}-${n}`))},`b${e}`);case "ol":return jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:r.items?.map((o,n)=>jsx("li",{className:"leading-relaxed",children:B(o)},`li${e}-${n}`))},`b${e}`);default:return null}}function Q({content:r,className:e}){let o=pt(r);return jsx("div",{className:T("text-sm",e),children:o.map((n,a)=>yt(n,a))})}function Re({open:r,className:e}){return jsx("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:T("shrink-0 transition-transform duration-150",r?"rotate-0":"-rotate-90",e),children:jsx("path",{d:"M16.134 6.16a.5.5 0 1 1 .732.68l-6.5 7-.077.068a.5.5 0 0 1-.655-.068l-6.5-7-.062-.08a.5.5 0 0 1 .718-.667l.076.067L10 12.767z"})})}function xe({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function X({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M15.147 4.146a.5.5 0 0 1 .707.707L10.707 10l5.147 5.147a.5.5 0 0 1-.63.771l-.078-.064L10 10.707l-5.146 5.147a.5.5 0 0 1-.708-.707L9.293 10 4.146 4.853a.5.5 0 0 1 .708-.707L10 9.293z"})})}function ve({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M10 3a.5.5 0 0 1 .5.5v6h6l.1.01a.5.5 0 0 1 0 .98l-.1.01h-6v6a.5.5 0 0 1-1 0v-6h-6a.5.5 0 0 1 0-1h6v-6A.5.5 0 0 1 10 3"})})}function wt(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M6.5 3A2.5 2.5 0 0 0 4 5.5v9A2.5 2.5 0 0 0 6.5 17h7a2.5 2.5 0 0 0 2.5-2.5v-7A2.5 2.5 0 0 0 13.5 5H11V3.5a.5.5 0 0 0-1 0V5H6.5ZM5 5.5A1.5 1.5 0 0 1 6.5 4H9v1H6.5A1.5 1.5 0 0 0 5 6.5v8A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 13.5 6H11V4h2.5A2.5 2.5 0 0 1 16 6.5v8a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-9Z"})})}function bt(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M5.5 3A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h9a2.5 2.5 0 0 0 2.5-2.5v-9A2.5 2.5 0 0 0 14.5 3h-9ZM4 5.5A1.5 1.5 0 0 1 5.5 4h9A1.5 1.5 0 0 1 16 5.5v9a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 4 14.5v-9ZM7 7.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5Z"})})}function Rt(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M10 2a.5.5 0 0 1 .354.146l3 3a.5.5 0 0 1-.708.708L10.5 3.707V12.5a.5.5 0 0 1-1 0V3.707L7.354 5.854a.5.5 0 1 1-.708-.708l3-3A.5.5 0 0 1 10 2ZM4 13.5a.5.5 0 0 1 1 0v1A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-1a.5.5 0 0 1 1 0v1a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-1Z"})})}function Se(){let[r,e]=useState(false);return useEffect(()=>{if(typeof window>"u")return;let o=()=>e(window.innerWidth<768);return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),r}function Ce({onClose:r,children:e,title:o}){let n=Se(),a=useRef(r);return a.current=r,useEffect(()=>{let c=t=>{t.key==="Escape"&&a.current();};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[]),n?jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full max-h-[90vh] overflow-y-auto rounded-t-2xl bg-[#1a1a1a] p-5 pb-8 animate-in slide-in-from-bottom duration-200",onClick:c=>c.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-4 h-1 w-10 rounded-full bg-zinc-600"}),jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsx("h2",{className:"text-lg font-semibold text-foreground",children:o}),jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(X,{size:20})})]}),e]})]}):jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full max-w-lg overflow-y-auto rounded-2xl bg-[#1a1a1a] p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:c=>c.stopPropagation(),children:[jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsx("h2",{className:"text-lg font-semibold text-foreground",children:o}),jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(X,{size:20})})]}),e]})]})}function vt(r){let e=r.split(`
4
+ `),o="",n="",c=false;for(let t=0;t<e.length;t++){let s=e[t].trim();if(t===0&&s==="---"){c=true;continue}if(c){s==="---"&&(c=false,true);continue}if(!o){let i=s.match(/^#{1,2}\s+(.+)/);if(i){o=i[1].trim();continue}}if(o&&!n){if(!s||s.startsWith("#")||s==="---"||s==="***"||s==="___")continue;n=s.replace(/\*\*/g,"").replace(/`/g,"").trim();break}}return o?{title:o,description:n}:null}function St({onClose:r,onCreated:e,config:o}){let[n,a]=useState(""),[c,t]=useState(""),[s,i]=useState(""),[u,d]=useState(false),[m,f]=useState(null),[g,p]=useState(false),w=h=>{if(i(h),!n.trim()&&!c.trim()&&h.trim().length>10){let v=vt(h);v&&(a(v.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")),t(v.description),p(true));}};return jsx(Ce,{title:"Write skill instructions",onClose:r,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsx("input",{id:"skill-name",value:n,onChange:h=>a(h.target.value),placeholder:"weekly-status-report",className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-desc",className:"text-sm text-muted-foreground",children:"Description"}),jsx("textarea",{id:"skill-desc",value:c,onChange:h=>t(h.target.value),placeholder:"Generate weekly status reports from recent work.",rows:3,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-instructions",className:"text-sm text-muted-foreground",children:"Instructions"}),jsx("textarea",{id:"skill-instructions",value:s,onChange:h=>w(h.target.value),placeholder:"Summarize my recent work in three sections: wins, blockers, and next steps.",rows:8,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),m&&jsx("p",{className:"text-sm text-red-500",children:m}),jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsx("button",{onClick:r,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsx("button",{onClick:async()=>{if(n.trim()){d(true),f(null);try{let h=o.apiBaseUrl||"",v=g?s.trim():`# ${n.trim()}
4
5
 
5
- ${f.trim()}
6
+ ${c.trim()}
6
7
 
7
8
  ---
8
9
 
9
- ${a.trim()}`,w=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n.trim(),description:f.trim(),skill_md:x,content_type:"code"})});if(!w.ok){let R=`Failed to register skill (${w.status})`;try{let C=await w.json();C.error&&(R=C.error);}catch{}throw new Error(R)}e?.(),r();}catch(p){d(p instanceof Error?p.message:"Failed to create skill");}finally{u(false);}}},disabled:c||!n.trim(),className:"rounded-lg bg-zinc-600 px-4 py-2 text-sm font-medium text-white hover:bg-zinc-500 disabled:opacity-50",children:c?"Creating...":"Create"})]})]})})}function xt({onClose:r,onCreated:e,config:o}){let n=useRef(null),[s,f]=useState(false),[t,a]=useState(false),[l,c]=useState(null),u=async d=>{a(true),c(null);try{let g=await d.text(),p=o.apiBaseUrl||"",x=d.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),w=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:x,skill_md:g,content_type:"code"})});if(!w.ok){let R=`Failed to register skill (${w.status})`;try{let C=await w.json();C.error&&(R=C.error);}catch{}throw new Error(R)}e?.(),r();}catch(g){c(g instanceof Error?g.message:"Upload failed");}finally{a(false);}};return jsx(Re,{title:"Upload skill",onClose:r,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{onDragOver:d=>{d.preventDefault(),f(true);},onDragLeave:()=>f(false),onDrop:d=>{d.preventDefault(),f(false);let g=d.dataTransfer.files[0];g&&u(g);},onClick:()=>n.current?.click(),className:N("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",s?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsx(we,{size:20,className:"text-muted-foreground"})}),jsx("p",{className:"text-sm text-muted-foreground",children:t?"Uploading...":"Drag and drop or click to upload"})]}),jsx("input",{ref:n,type:"file",accept:".md,.zip,.skill,.txt,.yml,.yaml",className:"hidden","aria-label":"Upload skill file",onChange:d=>{let g=d.target.files?.[0];g&&u(g);}}),l&&jsx("p",{className:"text-sm text-red-500",children:l}),jsxs("div",{className:"space-y-2 text-xs text-muted-foreground",children:[jsx("p",{className:"font-medium text-foreground/70",children:"File requirements"}),jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[jsx("li",{children:".md file must contain skill name and description formatted in YAML"}),jsx("li",{children:".zip or .skill file must include a SKILL.md file"})]})]})]})})}function wt({onClose:r,onSelect:e}){let o=be(),n=useRef(null),s=useRef(r);s.current=r,useEffect(()=>{if(o)return;let t=a=>{n.current&&a.target instanceof Node&&!n.current.contains(a.target)&&s.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[o]);let f=[{id:"create-with-geoff",icon:jsx(pt,{}),label:"Create with Geoff"},{id:"write",icon:jsx(ht,{}),label:"Write skill instructions"},{id:"upload",icon:jsx(yt,{}),label:"Upload a skill"}];return o?jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full rounded-t-2xl bg-[#1a1a1a] p-4 pb-8 animate-in slide-in-from-bottom duration-200",onClick:t=>t.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),f.map(t=>jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-800",children:[t.icon,t.label]},t.id))]})]}):jsx("div",{ref:n,className:"absolute right-2 top-11 z-50 w-56 overflow-hidden rounded-xl border border-zinc-700 bg-[#2a2a2a] shadow-xl animate-in fade-in zoom-in-95 duration-100",children:f.map(t=>jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[t.icon,t.label]},t.id))})}function bt({entry:r,selected:e,onSelect:o,depth:n=0}){return jsxs("button",{onClick:()=>o(r),className:N("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+n*16}px`},children:[jsx("span",{className:"truncate flex-1",children:r.path.split("/").pop()}),r.isDir&&jsx(xe,{className:"ml-auto text-muted-foreground"})]})}function Rt({repo:r,selected:e,expanded:o,onSelect:n,onToggle:s,children:f}){return jsxs("div",{children:[jsxs("button",{onClick:()=>{n(),s();},className:N("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsx(xe,{open:o}),jsx(FileText,{className:"h-4 w-4 shrink-0"}),jsx("span",{className:"truncate",children:r.name})]}),o&&f]})}function vt({entry:r,content:e,loading:o,repoName:n}){let[s,f]=useState(false),t=useRef(null);useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[a,l]=useState(false),c=async()=>{if(e)try{await navigator.clipboard.writeText(e),f(!0),l(!1),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>f(!1),2e3);}catch{l(true),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>l(false),2e3);}};if(!r)return jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(o)return jsx("div",{className:"flex h-full items-center justify-center",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let u=r.path.split("/").pop()||r.path,m=/\.(md|mdx)$/i.test(u);return jsxs("div",{className:"flex h-full flex-col px-3",children:[jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[jsx("h3",{className:"text-sm sm:text-lg font-semibold text-foreground",children:u}),jsx("button",{onClick:c,"aria-label":"Copy file content",className:N("rounded p-1 transition-colors",s?"text-green-500":a?"text-red-500":"text-muted-foreground hover:text-foreground"),children:jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"})})})]}),jsx("div",{className:"flex-1 overflow-auto p-4",children:m?jsx(Q,{content:e||""}):jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function St({config:r,category:e,className:o,style:n}){let{repos:s,loading:f,error:t,refresh:a}=D(r),[l,c]=useState(null),[u,m]=useState(null),[d,g]=useState(null),[p,x]=useState(null),[w,R]=useState(false),[C,I]=useState(""),[P,M]=useState(false),[ee,te]=useState(false),[re,A]=useState(null),ve=s.find(y=>y.repo_id===l),{entries:Se,getFileContent:ne}=H(r,u),se=s.filter(y=>!C||y.name.toLowerCase().includes(C.toLowerCase())),Ce=useCallback(async y=>{if(!y.isDir){g(y),R(true);try{let T=await ne(y.cid);x(T);}catch(T){let Te=T instanceof Error?T.message:"Unknown error";x(`Failed to load file: ${Te}`);}finally{R(false);}}},[ne]);useEffect(()=>{s.length>0&&!l&&(c(s[0].repo_id),m(s[0].repo_id));},[s,l]);let Ne=y=>{y==="create-with-geoff"?window.open(`https://www.geoff.ai/?p=${encodeURIComponent("Let's create a skill together using your skill-creator skill. First ask me what the skill should do.")}`,"_blank","noopener,noreferrer"):A(y);};return jsxs("div",{className:N("flex flex-1 h-full min-h-0",o),style:n,children:[jsxs("div",{className:"relative flex w-96 shrink-0 flex-col border-r",children:[jsx("div",{className:"flex h-12 items-center gap-2 px-3",children:P?jsxs(Fragment,{children:[jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-md border bg-muted/50 px-2 py-1",children:[jsx(he,{size:16,className:"shrink-0 text-muted-foreground"}),jsx("input",{type:"text",value:C,onChange:y=>I(y.target.value),placeholder:"Search",autoFocus:true,"aria-label":"Search items",className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),jsx("button",{onClick:()=>{M(false),I("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(X,{size:16})})]}):jsxs(Fragment,{children:[jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground capitalize",children:e||"Items"}),jsx("button",{onClick:()=>M(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsx(he,{size:20})}),jsx("button",{onClick:()=>te(!ee),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(we,{size:20})})]})}),ee&&jsx(wt,{onClose:()=>te(false),onSelect:Ne}),jsx("div",{className:"flex-1 overflow-y-auto p-2",children:f?jsx("div",{className:"flex items-center justify-center py-8",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):t?jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:t}):se.length===0?jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:C?"No matching items":"No items yet"}):jsx("div",{className:"space-y-0.5",children:se.map(y=>jsx(Rt,{repo:y,selected:l===y.repo_id,expanded:u===y.repo_id,onSelect:()=>{c(y.repo_id),g(null),x(null);},onToggle:()=>m(u===y.repo_id?null:y.repo_id),children:jsx("div",{className:"ml-10 pl-1",children:Se.map(T=>jsx(bt,{entry:T,selected:d?.path===T.path,onSelect:Ce,depth:T.path.split("/").length-1},T.path))})},y.repo_id))})})]}),jsx("div",{className:"flex-1 min-w-0",children:jsx(vt,{entry:d,content:p,loading:w,repoName:ve?.name||""})}),re==="write"&&jsx(kt,{config:r,onClose:()=>A(null),onCreated:a}),re==="upload"&&jsx(xt,{config:r,onClose:()=>A(null),onCreated:a})]})}
10
- export{Q as Markdown,St as RackBrowser,fe as estimateCost,et as useNetworkStats,Oe as usePaginatedRepos,b as useRackClient,Fe as useRackRegister,De as useRackSession,Ae as useRepoPush,H as useRepoTree,D as useRepos,Je as useSkillStats,ot as useStar,Ge as useTensorStats,rt as useTrending};
10
+ ${s.trim()}`,E=await fetch(`${h}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n.trim(),description:c.trim(),skill_md:v,content_type:"code"})});if(!E.ok){let N=`Failed to register skill (${E.status})`;try{let _=await E.json();_.error&&(N=_.error);}catch{}throw new Error(N)}e?.(),r();}catch(h){f(h instanceof Error?h.message:"Failed to create skill");}finally{d(false);}}},disabled:u||!n.trim(),className:"rounded-lg bg-zinc-600 px-4 py-2 text-sm font-medium text-white hover:bg-zinc-500 disabled:opacity-50",children:u?"Creating...":"Create"})]})]})})}function Ct({onClose:r,onCreated:e,config:o}){let n=useRef(null),[a,c]=useState(false),[t,s]=useState(false),[i,u]=useState(null),d=async f=>{s(true),u(null);try{let g=await f.text(),p=o.apiBaseUrl||"",w=f.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),k=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:w,skill_md:g,content_type:"code"})});if(!k.ok){let h=`Failed to register skill (${k.status})`;try{let v=await k.json();v.error&&(h=v.error);}catch{}throw new Error(h)}e?.(),r();}catch(g){u(g instanceof Error?g.message:"Upload failed");}finally{s(false);}};return jsx(Ce,{title:"Upload skill",onClose:r,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{onDragOver:f=>{f.preventDefault(),c(true);},onDragLeave:()=>c(false),onDrop:f=>{f.preventDefault(),c(false);let g=f.dataTransfer.files[0];g&&d(g);},onClick:()=>n.current?.click(),className:T("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",a?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsx(ve,{size:20,className:"text-muted-foreground"})}),jsx("p",{className:"text-sm text-muted-foreground",children:t?"Uploading...":"Drag and drop or click to upload"})]}),jsx("input",{ref:n,type:"file",accept:".md,.zip,.skill,.txt,.yml,.yaml",className:"hidden","aria-label":"Upload skill file",onChange:f=>{let g=f.target.files?.[0];g&&d(g);}}),i&&jsx("p",{className:"text-sm text-red-500",children:i}),jsxs("div",{className:"space-y-2 text-xs text-muted-foreground",children:[jsx("p",{className:"font-medium text-foreground/70",children:"File requirements"}),jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[jsx("li",{children:".md file must contain skill name and description formatted in YAML"}),jsx("li",{children:".zip or .skill file must include a SKILL.md file"})]})]})]})})}function Nt({onClose:r,onSelect:e}){let o=Se(),n=useRef(null),a=useRef(r);a.current=r,useEffect(()=>{if(o)return;let t=s=>{n.current&&s.target instanceof Node&&!n.current.contains(s.target)&&a.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[o]);let c=[{id:"create-with-geoff",icon:jsx(wt,{}),label:"Create with Geoff"},{id:"write",icon:jsx(bt,{}),label:"Write skill instructions"},{id:"upload",icon:jsx(Rt,{}),label:"Upload a skill"}];return o?jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full rounded-t-2xl bg-[#1a1a1a] p-4 pb-8 animate-in slide-in-from-bottom duration-200",onClick:t=>t.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),c.map(t=>jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-800",children:[t.icon,t.label]},t.id))]})]}):jsx("div",{ref:n,className:"absolute right-2 top-11 z-50 w-56 overflow-hidden rounded-xl border border-zinc-700 bg-[#2a2a2a] shadow-xl animate-in fade-in zoom-in-95 duration-100",children:c.map(t=>jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[t.icon,t.label]},t.id))})}function Tt({entry:r,selected:e,onSelect:o,depth:n=0}){return jsxs("button",{onClick:()=>o(r),className:T("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+n*16}px`},children:[jsx("span",{className:"truncate flex-1",children:r.path.split("/").pop()}),r.isDir&&jsx(Re,{className:"ml-auto text-muted-foreground"})]})}function Pt({repo:r,selected:e,expanded:o,onSelect:n,onToggle:a,children:c}){return jsxs("div",{children:[jsxs("button",{onClick:()=>{n(),a();},className:T("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsx(Re,{open:o}),jsx(FileText,{className:"h-4 w-4 shrink-0"}),jsx("span",{className:"truncate",children:r.name})]}),o&&c]})}function Et({entry:r,content:e,loading:o,repoName:n}){let[a,c]=useState(false),t=useRef(null);useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[s,i]=useState(false),u=async()=>{if(e)try{await navigator.clipboard.writeText(e),c(!0),i(!1),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>c(!1),2e3);}catch{i(true),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>i(false),2e3);}};if(!r)return jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(o)return jsx("div",{className:"flex h-full items-center justify-center",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let d=r.path.split("/").pop()||r.path,m=/\.(md|mdx)$/i.test(d);return jsxs("div",{className:"flex h-full flex-col px-3",children:[jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[jsx("h3",{className:"text-sm sm:text-lg font-semibold text-foreground",children:d}),jsx("button",{onClick:u,"aria-label":"Copy file content",className:T("rounded p-1 transition-colors",a?"text-green-500":s?"text-red-500":"text-muted-foreground hover:text-foreground"),children:jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"})})})]}),jsx("div",{className:"flex-1 overflow-auto p-4",children:m?jsx(Q,{content:e||""}):jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function _t({config:r,category:e,className:o,style:n}){let{repos:a,loading:c,error:t,hasMore:s,loadMore:i,reset:u}=K(r,{pageSize:50}),[d,m]=useState(null),[f,g]=useState(null),[p,w]=useState(null),[k,h]=useState(null),[v,E]=useState(false),[N,_]=useState(""),[Te,re]=useState(false),[ne,se]=useState(false),[oe,U]=useState(null),Pe=a.find(b=>b.repo_id===d),{entries:Ee,getFileContent:ae}=F(r,f),ie=a.filter(b=>!N||b.name.toLowerCase().includes(N.toLowerCase())),_e=useCallback(async b=>{if(!b.isDir){w(b),E(true);try{let P=await ae(b.cid);h(P);}catch(P){let $e=P instanceof Error?P.message:"Unknown error";h(`Failed to load file: ${$e}`);}finally{E(false);}}},[ae]);useEffect(()=>{a.length>0&&!d&&(m(a[0].repo_id),g(a[0].repo_id));},[a,d]);let Me=b=>{b==="create-with-geoff"?window.open(`https://www.geoff.ai/?p=${encodeURIComponent("Let's create a skill together using your skill-creator skill. First ask me what the skill should do.")}`,"_blank","noopener,noreferrer"):U(b);};return jsxs("div",{className:T("flex flex-1 h-full min-h-0",o),style:n,children:[jsxs("div",{className:"relative flex w-96 shrink-0 flex-col border-r",children:[jsx("div",{className:"flex h-12 items-center gap-2 px-3",children:Te?jsxs(Fragment,{children:[jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-md border bg-muted/50 px-2 py-1",children:[jsx(xe,{size:16,className:"shrink-0 text-muted-foreground"}),jsx("input",{type:"text",value:N,onChange:b=>_(b.target.value),placeholder:"Search",autoFocus:true,"aria-label":"Search items",className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),jsx("button",{onClick:()=>{re(false),_("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(X,{size:16})})]}):jsxs(Fragment,{children:[jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground capitalize",children:e||"Items"}),jsx("button",{onClick:()=>re(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsx(xe,{size:20})}),jsx("button",{onClick:()=>se(!ne),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(ve,{size:20})})]})}),ne&&jsx(Nt,{onClose:()=>se(false),onSelect:Me}),jsx("div",{className:"flex-1 overflow-y-auto p-2",children:c?jsx("div",{className:"flex items-center justify-center py-8",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):t?jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:t}):ie.length===0?jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:N?"No matching items":"No items yet"}):jsx("div",{className:"space-y-0.5",children:ie.map(b=>jsx(Pt,{repo:b,selected:d===b.repo_id,expanded:f===b.repo_id,onSelect:()=>{m(b.repo_id),w(null),h(null);},onToggle:()=>g(f===b.repo_id?null:b.repo_id),children:jsx("div",{className:"ml-10 pl-1",children:Ee.map(P=>jsx(Tt,{entry:P,selected:p?.path===P.path,onSelect:_e,depth:P.path.split("/").length-1},P.path))})},b.repo_id))})})]}),jsx("div",{className:"flex-1 min-w-0",children:jsx(Et,{entry:p,content:k,loading:v,repoName:Pe?.name||""})}),oe==="write"&&jsx(St,{config:r,onClose:()=>U(null),onCreated:u}),oe==="upload"&&jsx(Ct,{config:r,onClose:()=>U(null),onCreated:u})]})}async function Ne(r,e,o,n){let a={"Content-Type":"application/json",...o?.headers};n&&(a.Authorization=`Bearer ${n}`);let c=await fetch(`${r}${e}`,{...o,headers:a});if(!c.ok){let t=`HTTP ${c.status}`;try{let s=await c.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return c.json()}function zt({config:r,repoId:e,onAuthRequired:o,className:n,style:a}){let c=r.apiBaseUrl,t=r.apiKey,[s,i]=useState({stars:0,starred:false,repo_id:e}),[u,d]=useState(false),[m,f]=useState(null),g=useRef(true),p=c.includes("/cpx/rack")?"":"/api/rack";useEffect(()=>(g.current=true,Ne(c,`${p}/${e}/stars`,void 0,t).then(k=>{g.current&&i(k);}).catch(()=>{}),()=>{g.current=false;}),[c,e,t,p]);let w=useCallback(async k=>{if(k.preventDefault(),k.stopPropagation(),!t){o?.();return}d(true),f(null);try{let h=s.starred?"DELETE":"POST",v=await Ne(c,`${p}/${e}/star`,{method:h},t);g.current&&i({stars:v.stars,starred:v.starred,repo_id:e});}catch(h){g.current&&f(h.message);}finally{g.current&&d(false);}},[c,e,t,s.starred,o]);return jsxs("button",{onClick:w,disabled:u,title:m||(s.starred?"Unstar (100k tokens)":"Star (100k tokens)"),className:n,style:{display:"inline-flex",alignItems:"center",gap:"4px",background:"none",border:"none",cursor:u?"wait":"pointer",padding:"4px 8px",fontSize:"12px",fontFamily:"inherit",color:s.starred?"#f59e0b":"#91918d",transition:"color 150ms",opacity:u?.5:1,...a},children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:s.starred?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})}),jsx("span",{children:s.stars})]})}
11
+ export{Q as Markdown,_t as RackBrowser,zt as StarButton,pe as estimateCost,ot as useNetworkStats,K as usePaginatedRepos,R as useRackClient,Ve as useRackRegister,Je as useRackSession,He as useRepoPush,F as useRepoTree,Be as useRepos,Ye as useSkillStats,ut as useStar,tt as useTensorStats,it as useTrending};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stacknet/rackutils",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "React hooks and components for reading and writing StackNet Racks",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",