@stacknet/rackutils 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/index.cjs +7 -7
- package/dist/components/index.js +7 -7
- package/dist/hooks/index.cjs +1 -1
- package/dist/hooks/index.d.cts +2 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +1 -1
- package/dist/index.cjs +7 -7
- package/dist/index.js +7 -7
- package/dist/types/index.d.cts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +18 -13
|
@@ -1,11 +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 C(...
|
|
2
|
-
`),i=[],
|
|
3
|
-
`),lang:n||void 0}),
|
|
4
|
-
`),i="",
|
|
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(...s){return tailwindMerge.twMerge(clsx.clsx(s))}async function k(s,e,i,r){let a={"Content-Type":"application/json",...i?.headers};r&&(a.Authorization=`Bearer ${r}`);let c=await fetch(`${s}${e}`,{...i,headers:a});if(!c.ok){let t=`HTTP ${c.status}`;try{let n=await c.json();n.error&&(t=n.error);}catch{}throw new Error(t)}return c.json()}function I(s){let e=s.indexOf(":");return {mode:s.slice(0,e),cid:s.slice(e+1)}}function z(s){let e=s.apiBaseUrl,i=s.authorMid,r=s.ownerMid,a=s.apiKey,c=s.stacknetUrl||s.apiBaseUrl;return react.useMemo(()=>({async listRepos(t,n){let l=new URLSearchParams;(t||r)&&l.set("owner",t||r),n?.limit&&l.set("limit",String(n.limit)),n?.cursor&&l.set("cursor",n.cursor),n?.category&&l.set("category",n.category);let d=l.toString()?`?${l}`:"",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,n){return k(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...n,author_mid:i})},a)},async getTree(t,n="main"){let l=await k(e,`/api/rack/${t}/tree/${n}`,void 0,a);return {tree:l.tree,commit_cid:l.commit_cid}},async getBlob(t,n){return (await k(e,`/api/rack/${t}/blob/${n}`,void 0,a)).content},async getLog(t,n,l){let d=new URLSearchParams;n&&d.set("ref",n),l&&d.set("max_count",String(l));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,n,l){return k(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:n,from_ref:l,author_mid:i})},a)},async merge(t,n,l){return k(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:n,target_branch:l,author_mid:i})},a)},async getDiff(t,n,l){return (await k(e,`/api/rack/${t}/diff/${n}/${l}`,void 0,a)).diff?.entries||[]},async starRepo(t){return k(e,`/api/rack/${t}/star`,{method:"POST",body:JSON.stringify({owner_mid:r})},a)},async unstarRepo(t){return k(e,`/api/rack/${t}/star`,{method:"DELETE",body:JSON.stringify({owner_mid:r})},a)},async getStarInfo(t){return k(e,`/api/rack/${t}/stars`,void 0,a)},async getSkillStats(t){let n={meta:null,tokenCount:null,usageCount:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return n;if(l.entries["META.json"]){let h=I(l.entries["META.json"]).cid,g=await this.getBlob(t,h);n.meta=JSON.parse(g);}let d=0,u=Object.values(l.entries).map(async h=>{try{let g=I(h).cid,m=await this.getBlob(t,g);d+=m.length;}catch{}});await Promise.all(u),d>0&&(n.tokenCount=Math.ceil(d/4)),n.meta?.skill_id&&(n.usageCount=await this.getSkillUsageCount(n.meta.skill_id));}catch{}return n},async getSkillUsageCount(t){try{let n=await fetch(`${c}/v1/skills/${encodeURIComponent(t)}`);if(n.ok){let d=await n.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(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 n={meta:null,sizeMB:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return n;if(l.entries["TENSOR_META.json"]){let d=I(l.entries["TENSOR_META.json"]).cid,u=await this.getBlob(t,d);n.meta=JSON.parse(u),n.sizeMB=n.meta?.tensor_size_mb??null;}}catch{}return n},async getLooopStats(t){let n={meta:null,fileCount:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return n;if(l.entries["META.json"]){let d=I(l.entries["META.json"]).cid,u=await this.getBlob(t,d);n.meta=JSON.parse(u);}n.fileCount=Object.keys(l.entries).length;}catch{}return n},async getNetworkStats(){try{return (await k(e,"/api/rack/stats",void 0,a)).stats||null}catch{return null}},async getTrending(t=5,n=1,l){try{let d=new URLSearchParams({limit:String(t),days:String(n)});l&&d.set("cursor",l);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,c])}function Q(s,e={}){let{pageSize:i=50,owner:r,category:a}=e,c=z(s),[t,n]=react.useState([]),[l,d]=react.useState(null),[u,h]=react.useState(false),[g,m]=react.useState(null),b=react.useRef(null),N=react.useRef(true),w=react.useCallback(async(E,P=false)=>{h(true),m(null);try{let S=await c.listRepos(r,{limit:i,cursor:E||void 0,category:a});N.current&&(n(A=>P?[...A,...S.items]:S.items),d(S.pagination),b.current=S.pagination.next_cursor);}catch(S){N.current&&m(S.message);}finally{N.current&&h(false);}},[c,r,i,a]),p=react.useCallback(async()=>{!b.current||u||await w(b.current,true);},[w,u]),v=react.useCallback(async()=>{b.current=null,await w(void 0,false);},[w]);return react.useEffect(()=>(N.current=true,w(),()=>{N.current=false;}),[w]),{repos:t,hasMore:l?.has_more??false,total:l?.total??0,loading:u,error:g,loadMore:p,reset:v,pagination:l}}function be(s){return Object.entries(s).map(([e,i])=>{let r=i.indexOf(":"),a=r>0?i.slice(0,r):"100644",c=r>0?i.slice(r+1):i;return {path:e,mode:a,cid:c,isDir:a==="040000"}}).sort((e,i)=>e.isDir!==i.isDir?e.isDir?-1:1:e.path.localeCompare(i.path))}function ee(s,e,i="main"){let r=z(s),[a,c]=react.useState([]),[t,n]=react.useState(false),[l,d]=react.useState(null),u=react.useRef(true),h=react.useCallback(async()=>{if(e)try{u.current&&(n(!0),d(null));let{tree:m}=await r.getTree(e,i);u.current&&c(be(m.entries));}catch(m){u.current&&d(m instanceof Error?m.message:"Failed to load tree");}finally{u.current&&n(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:l,refresh:h,getFileContent:g}}var ve=/^(https?:\/\/|mailto:|\/[^/])/i;function ke(s){let e=s.trim();return ve.test(e)?e:null}function B(s){let e=[],i=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,r=0,a,c=0;for(;(a=i.exec(s))!==null;){a.index>r&&e.push(s.slice(r,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 n=ke(a[10]);n?e.push(jsxRuntime.jsx("a",{href:n,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<s.length&&e.push(s.slice(r)),e.length>0?e:[s]}function Re(s){let e=s.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 c=a.match(/^(#{1,6})\s+(.+)/);if(c){i.push({type:"heading",level:c[1].length,content:c[2]}),r++;continue}if(a.trim().startsWith("```")){let n=a.trim().slice(3).trim(),l=[];for(r++;r<e.length&&!e[r].trim().startsWith("```");)l.push(e[r]),r++;i.push({type:"code",content:l.join(`
|
|
3
|
+
`),lang:n||void 0}),r++;continue}if(/^\s*[-*+]\s/.test(a)){let n=[];for(;r<e.length&&/^\s*[-*+]\s/.test(e[r]);)n.push(e[r].replace(/^\s*[-*+]\s+/,"")),r++;i.push({type:"ul",items:n});continue}if(/^\s*\d+[.)]\s/.test(a)){let n=[];for(;r<e.length&&/^\s*\d+[.)]\s/.test(e[r]);)n.push(e[r].replace(/^\s*\d+[.)]\s+/,"")),r++;i.push({type:"ol",items:n});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 Se(s,e){switch(s.type){case "hr":return jsxRuntime.jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let i=Math.min(Math.max(s.level||1,1),6),r=`h${i}`;return jsxRuntime.jsx(r,{className:C("text-foreground",Ne[i]),children:B(s.content||"")},`b${e}`)}case "paragraph":return jsxRuntime.jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:B(s.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:s.content})},`b${e}`);case "ul":return jsxRuntime.jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:s.items?.map((i,r)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:B(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:s.items?.map((i,r)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:B(i)},`li${e}-${r}`))},`b${e}`);default:return null}}function D({content:s,className:e}){let i=Re(s);return jsxRuntime.jsx("div",{className:C("text-sm",e),children:i.map((r,a)=>Se(r,a))})}function se({open:s,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",s?"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 te({size:s=20,className:e}){return jsxRuntime.jsx("svg",{width:s,height:s,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 F({size:s=20,className:e}){return jsxRuntime.jsx("svg",{width:s,height:s,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 oe({size:s=20,className:e}){return jsxRuntime.jsx("svg",{width:s,height:s,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 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:"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 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:"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 Me(){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 ae(){let[s,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)},[]),s}function ie({onClose:s,children:e,title:i}){let r=ae(),a=react.useRef(s);return a.current=s,react.useEffect(()=>{let c=t=>{t.key==="Escape"&&a.current();};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[]),r?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:s,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:s,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(F,{size:20})})]}),e]})]}):jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:s,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:s,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(F,{size:20})})]}),e]})]})}function _e(s){let e=s.split(`
|
|
4
|
+
`),i="",r="",c=false;for(let t=0;t<e.length;t++){let n=e[t].trim();if(t===0&&n==="---"){c=true;continue}if(c){n==="---"&&(c=false,true);continue}if(!i){let l=n.match(/^#{1,2}\s+(.+)/);if(l){i=l[1].trim();continue}}if(i&&!r){if(!n||n.startsWith("#")||n==="---"||n==="***"||n==="___")continue;r=n.replace(/\*\*/g,"").replace(/`/g,"").trim();break}}return i?{title:i,description:r}:null}function $e({onClose:s,onCreated:e,config:i}){let[r,a]=react.useState(""),[c,t]=react.useState(""),[n,l]=react.useState(""),[d,u]=react.useState(false),[h,g]=react.useState(null),[m,b]=react.useState(false),N=p=>{if(l(p),!r.trim()&&!c.trim()&&p.trim().length>10){let v=_e(p);v&&(a(v.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")),t(v.description),b(true));}};return jsxRuntime.jsx(ie,{title:"Write skill instructions",onClose:s,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:c,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:n,onChange:p=>N(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:s,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||"",v=m?n.trim():`# ${r.trim()}
|
|
5
5
|
|
|
6
|
-
${
|
|
6
|
+
${c.trim()}
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
-
${n.trim()}`,T=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.trim(),description:l.trim(),skill_md:v,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?.(),r();}catch(p){g(p instanceof Error?p.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 ze({onClose:r,onCreated:e,config:i}){let s=react.useRef(null),[a,l]=react.useState(false),[t,n]=react.useState(false),[c,d]=react.useState(null),u=async g=>{n(true),d(null);try{let m=await g.text(),y=i.apiBaseUrl||"",b=g.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),S=await fetch(`${y}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:b,skill_md:m,content_type:"code"})});if(!S.ok){let p=`Failed to register skill (${S.status})`;try{let v=await S.json();v.error&&(p=v.error);}catch{}throw new Error(p)}e?.(),r();}catch(m){d(m instanceof Error?m.message:"Upload failed");}finally{n(false);}};return jsxRuntime.jsx(oe,{title:"Upload skill",onClose:r,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:()=>s.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:s,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 _e({onClose:r,onSelect:e}){let i=se(),s=react.useRef(null),a=react.useRef(r);a.current=r,react.useEffect(()=>{if(i)return;let t=n=>{s.current&&n.target instanceof Node&&!s.current.contains(n.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: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"}),l.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:l.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 Ie({entry:r,selected:e,onSelect:i,depth:s=0}){return jsxRuntime.jsxs("button",{onClick:()=>i(r),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+s*16}px`},children:[jsxRuntime.jsx("span",{className:"truncate flex-1",children:r.path.split("/").pop()}),r.isDir&&jsxRuntime.jsx(ne,{className:"ml-auto text-muted-foreground"})]})}function Le({repo:r,selected:e,expanded:i,onSelect:s,onToggle:a,children:l}){return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>{s(),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:r.name})]}),i&&l]})}function Be({entry:r,content:e,loading:i,repoName:s}){let[a,l]=react.useState(false),t=react.useRef(null);react.useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[n,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(!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,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":n?"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(U,{content:e||""}):jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function Ae({config:r,category:e,className:i,style:s}){let{repos:a,loading:l,error:t,reset:d}=K(r,{pageSize:50}),[u,h]=react.useState(null),[g,m]=react.useState(null),[y,b]=react.useState(null),[S,p]=react.useState(null),[v,T]=react.useState(false),[R,E]=react.useState(""),[ie,H]=react.useState(false),[J,W]=react.useState(false),[V,B]=react.useState(null),le=a.find(w=>w.repo_id===u),{entries:ce,getFileContent:Z}=Y(r,g),q=a.filter(w=>!R||w.name.toLowerCase().includes(R.toLowerCase())),ue=react.useCallback(async w=>{if(!w.isDir){b(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: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: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(j,{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:()=>W(!J),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(re,{size:20})})]})}),J&&jsxRuntime.jsx(_e,{onClose:()=>W(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(Le,{repo:w,selected:u===w.repo_id,expanded:g===w.repo_id,onSelect:()=>{h(w.repo_id),b(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(Ie,{entry:P,selected:y?.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(Be,{entry:y,content:S,loading:v,repoName:le?.name||""})}),V==="write"&&jsxRuntime.jsx($e,{config:r,onClose:()=>B(null),onCreated:d}),V==="upload"&&jsxRuntime.jsx(ze,{config:r,onClose:()=>B(null),onCreated:d})]})}async function ae(r,e,i,s){let a={"Content-Type":"application/json",...i?.headers};s&&(a.Authorization=`Bearer ${s}`);let l=await fetch(`${r}${e}`,{...i,headers:a});if(!l.ok){let t=`HTTP ${l.status}`;try{let n=await l.json();n.error&&(t=n.error);}catch{}throw new Error(t)}return l.json()}function De({config:r,repoId:e,onAuthRequired:i,className:s,style:a}){let l=r.apiBaseUrl,t=r.apiKey,[n,c]=react.useState({stars:0,starred:false,repo_id:e}),[d,u]=react.useState(false),[h,g]=react.useState(null),m=react.useRef(true),y=l.includes("/cpx/rack")?"":"/api/rack";react.useEffect(()=>(m.current=true,ae(l,`${y}/${e}/stars`,void 0,t).then(S=>{m.current&&c(S);}).catch(()=>{}),()=>{m.current=false;}),[l,e,t,y]);let b=react.useCallback(async S=>{if(S.preventDefault(),S.stopPropagation(),!t){i?.();return}u(true),g(null);try{let p=n.starred?"DELETE":"POST",v=await ae(l,`${y}/${e}/star`,{method:p},t);m.current&&c({stars:v.stars,starred:v.starred,repo_id:e});}catch(p){m.current&&g(p.message);}finally{m.current&&u(false);}},[l,e,t,n.starred,i]);return jsxRuntime.jsxs("button",{onClick:b,disabled:d,title:h||(n.starred?"Unstar (100k tokens)":"Star (100k tokens)"),className:s,style:{display:"inline-flex",alignItems:"center",gap:"4px",background:"none",border:"none",cursor:d?"wait":"pointer",padding:"4px 8px",fontSize:"12px",fontFamily:"inherit",color:n.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:n.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:n.stars})]})}
|
|
11
|
-
exports.Markdown=
|
|
10
|
+
${n.trim()}`,E=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.trim(),description:c.trim(),skill_md:v,content_type:"code"})});if(!E.ok){let P=`Failed to register skill (${E.status})`;try{let S=await E.json();S.error&&(P=S.error);}catch{}throw new Error(P)}e?.(),s();}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 Ie({onClose:s,onCreated:e,config:i}){let r=react.useRef(null),[a,c]=react.useState(false),[t,n]=react.useState(false),[l,d]=react.useState(null),u=async g=>{n(true),d(null);try{let m=await g.text(),b=i.apiBaseUrl||"",N=g.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),w=await fetch(`${b}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:N,skill_md:m,content_type:"code"})});if(!w.ok){let p=`Failed to register skill (${w.status})`;try{let v=await w.json();v.error&&(p=v.error);}catch{}throw new Error(p)}e?.(),s();}catch(m){d(m instanceof Error?m.message:"Upload failed");}finally{n(false);}};return jsxRuntime.jsx(ie,{title:"Upload skill",onClose:s,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 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(oe,{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);}}),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 ze({onClose:s,onSelect:e}){let i=ae(),r=react.useRef(null),a=react.useRef(s);a.current=s,react.useEffect(()=>{if(i)return;let t=n=>{r.current&&n.target instanceof Node&&!r.current.contains(n.target)&&a.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[i]);let c=[{id:"create-with-geoff",icon:jsxRuntime.jsx(Te,{}),label:"Create with Geoff"},{id:"write",icon:jsxRuntime.jsx(Ee,{}),label:"Write skill instructions"},{id:"upload",icon:jsxRuntime.jsx(Me,{}),label:"Upload a skill"}];return i?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:s,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),s();},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:c.map(t=>jsxRuntime.jsxs("button",{onClick:()=>{e(t.id),s();},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 Le({entry:s,selected:e,onSelect:i,depth:r=0}){return jsxRuntime.jsxs("button",{onClick:()=>i(s),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:s.path.split("/").pop()}),s.isDir&&jsxRuntime.jsx(se,{className:"ml-auto text-muted-foreground"})]})}function Be({repo:s,selected:e,expanded:i,onSelect:r,onToggle:a,children:c}){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(se,{open:i}),jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4 shrink-0"}),jsxRuntime.jsx("span",{className:"truncate",children:s.name})]}),i&&c]})}function Ae({entry:s,content:e,loading:i,repoName:r}){let[a,c]=react.useState(false),t=react.useRef(null);react.useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[n,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(!s)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=s.path.split("/").pop()||s.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":n?"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||""})})]})}var Oe={skills:"Skills",looops:"Looops",tensors:"Models",imaginations:"Imaginations",images:"Images"},Ue={skills:"skill/",looops:"looop/",tensors:"tensor/"};function je({config:s,category:e,className:i,style:r}){let{repos:a,loading:c,error:t,reset:d}=Q(s,{pageSize:50,category:e}),[u,h]=react.useState(null),[g,m]=react.useState(null),[b,N]=react.useState(null),[w,p]=react.useState(null),[v,E]=react.useState(false),[P,S]=react.useState(""),[A,W]=react.useState(false),[V,Z]=react.useState(false),[q,O]=react.useState(null),ce=a.find(x=>x.repo_id===u),{entries:ue,getFileContent:G}=ee(s,g),K=e?Ue[e]:void 0,M=a.filter(x=>!(K&&!x.name.startsWith(K)||P&&!x.name.toLowerCase().includes(P.toLowerCase()))),de=react.useCallback(async x=>{if(!x.isDir){N(x),E(true);try{let T=await G(x.cid);p(T);}catch(T){let fe=T instanceof Error?T.message:"Unknown error";p(`Failed to load file: ${fe}`);}finally{E(false);}}},[G]);react.useEffect(()=>{M.length>0&&!u&&(h(M[0].repo_id),m(M[0].repo_id));},[M,u]);let me=x=>{x==="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"):O(x);};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:A?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(te,{size:16,className:"shrink-0 text-muted-foreground"}),jsxRuntime.jsx("input",{type:"text",value:P,onChange:x=>S(x.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:()=>{W(false),S("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(F,{size:16})})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground",children:e&&Oe[e]||e||"Items"}),jsxRuntime.jsx("button",{onClick:()=>W(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsxRuntime.jsx(te,{size:20})}),jsxRuntime.jsx("button",{onClick:()=>Z(!V),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(oe,{size:20})})]})}),V&&jsxRuntime.jsx(ze,{onClose:()=>Z(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}):M.length===0?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:P?"No matching items":"No items yet"}):jsxRuntime.jsx("div",{className:"space-y-0.5",children:M.map(x=>jsxRuntime.jsx(Be,{repo:x,selected:u===x.repo_id,expanded:g===x.repo_id,onSelect:()=>{h(x.repo_id),N(null),p(null);},onToggle:()=>m(g===x.repo_id?null:x.repo_id),children:jsxRuntime.jsx("div",{className:"ml-10 pl-1",children:ue.map(T=>jsxRuntime.jsx(Le,{entry:T,selected:b?.path===T.path,onSelect:de,depth:T.path.split("/").length-1},T.path))})},x.repo_id))})})]}),jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntime.jsx(Ae,{entry:b,content:w,loading:v,repoName:ce?.name||""})}),q==="write"&&jsxRuntime.jsx($e,{config:s,onClose:()=>O(null),onCreated:d}),q==="upload"&&jsxRuntime.jsx(Ie,{config:s,onClose:()=>O(null),onCreated:d})]})}async function le(s,e,i,r){let a={"Content-Type":"application/json",...i?.headers};r&&(a.Authorization=`Bearer ${r}`);let c=await fetch(`${s}${e}`,{...i,headers:a});if(!c.ok){let t=`HTTP ${c.status}`;try{let n=await c.json();n.error&&(t=n.error);}catch{}throw new Error(t)}return c.json()}function Je({config:s,repoId:e,onAuthRequired:i,className:r,style:a}){let c=s.apiBaseUrl,t=s.apiKey,[n,l]=react.useState({stars:0,starred:false,repo_id:e}),[d,u]=react.useState(false),[h,g]=react.useState(null),m=react.useRef(true),b=c.includes("/cpx/rack")?"":"/api/rack";react.useEffect(()=>(m.current=true,le(c,`${b}/${e}/stars`,void 0,t).then(w=>{m.current&&l(w);}).catch(()=>{}),()=>{m.current=false;}),[c,e,t,b]);let N=react.useCallback(async w=>{if(w.preventDefault(),w.stopPropagation(),!t){i?.();return}u(true),g(null);try{let p=n.starred?"DELETE":"POST",v=await le(c,`${b}/${e}/star`,{method:p},t);m.current&&l({stars:v.stars,starred:v.starred,repo_id:e});}catch(p){m.current&&g(p.message);}finally{m.current&&u(false);}},[c,e,t,n.starred,i]);return jsxRuntime.jsxs("button",{onClick:N,disabled:d,title:h||(n.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:n.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:n.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:n.stars})]})}
|
|
11
|
+
exports.Markdown=D;exports.RackBrowser=je;exports.StarButton=Je;
|
package/dist/components/index.js
CHANGED
|
@@ -1,11 +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 C(...
|
|
2
|
-
`),i=[],
|
|
3
|
-
`),lang:n||void 0}),
|
|
4
|
-
`),i="",
|
|
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(...s){return twMerge(clsx(s))}async function k(s,e,i,r){let a={"Content-Type":"application/json",...i?.headers};r&&(a.Authorization=`Bearer ${r}`);let c=await fetch(`${s}${e}`,{...i,headers:a});if(!c.ok){let t=`HTTP ${c.status}`;try{let n=await c.json();n.error&&(t=n.error);}catch{}throw new Error(t)}return c.json()}function I(s){let e=s.indexOf(":");return {mode:s.slice(0,e),cid:s.slice(e+1)}}function z(s){let e=s.apiBaseUrl,i=s.authorMid,r=s.ownerMid,a=s.apiKey,c=s.stacknetUrl||s.apiBaseUrl;return useMemo(()=>({async listRepos(t,n){let l=new URLSearchParams;(t||r)&&l.set("owner",t||r),n?.limit&&l.set("limit",String(n.limit)),n?.cursor&&l.set("cursor",n.cursor),n?.category&&l.set("category",n.category);let d=l.toString()?`?${l}`:"",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,n){return k(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...n,author_mid:i})},a)},async getTree(t,n="main"){let l=await k(e,`/api/rack/${t}/tree/${n}`,void 0,a);return {tree:l.tree,commit_cid:l.commit_cid}},async getBlob(t,n){return (await k(e,`/api/rack/${t}/blob/${n}`,void 0,a)).content},async getLog(t,n,l){let d=new URLSearchParams;n&&d.set("ref",n),l&&d.set("max_count",String(l));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,n,l){return k(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:n,from_ref:l,author_mid:i})},a)},async merge(t,n,l){return k(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:n,target_branch:l,author_mid:i})},a)},async getDiff(t,n,l){return (await k(e,`/api/rack/${t}/diff/${n}/${l}`,void 0,a)).diff?.entries||[]},async starRepo(t){return k(e,`/api/rack/${t}/star`,{method:"POST",body:JSON.stringify({owner_mid:r})},a)},async unstarRepo(t){return k(e,`/api/rack/${t}/star`,{method:"DELETE",body:JSON.stringify({owner_mid:r})},a)},async getStarInfo(t){return k(e,`/api/rack/${t}/stars`,void 0,a)},async getSkillStats(t){let n={meta:null,tokenCount:null,usageCount:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return n;if(l.entries["META.json"]){let h=I(l.entries["META.json"]).cid,g=await this.getBlob(t,h);n.meta=JSON.parse(g);}let d=0,u=Object.values(l.entries).map(async h=>{try{let g=I(h).cid,m=await this.getBlob(t,g);d+=m.length;}catch{}});await Promise.all(u),d>0&&(n.tokenCount=Math.ceil(d/4)),n.meta?.skill_id&&(n.usageCount=await this.getSkillUsageCount(n.meta.skill_id));}catch{}return n},async getSkillUsageCount(t){try{let n=await fetch(`${c}/v1/skills/${encodeURIComponent(t)}`);if(n.ok){let d=await n.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(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 n={meta:null,sizeMB:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return n;if(l.entries["TENSOR_META.json"]){let d=I(l.entries["TENSOR_META.json"]).cid,u=await this.getBlob(t,d);n.meta=JSON.parse(u),n.sizeMB=n.meta?.tensor_size_mb??null;}}catch{}return n},async getLooopStats(t){let n={meta:null,fileCount:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return n;if(l.entries["META.json"]){let d=I(l.entries["META.json"]).cid,u=await this.getBlob(t,d);n.meta=JSON.parse(u);}n.fileCount=Object.keys(l.entries).length;}catch{}return n},async getNetworkStats(){try{return (await k(e,"/api/rack/stats",void 0,a)).stats||null}catch{return null}},async getTrending(t=5,n=1,l){try{let d=new URLSearchParams({limit:String(t),days:String(n)});l&&d.set("cursor",l);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,c])}function Q(s,e={}){let{pageSize:i=50,owner:r,category:a}=e,c=z(s),[t,n]=useState([]),[l,d]=useState(null),[u,h]=useState(false),[g,m]=useState(null),b=useRef(null),N=useRef(true),w=useCallback(async(E,P=false)=>{h(true),m(null);try{let S=await c.listRepos(r,{limit:i,cursor:E||void 0,category:a});N.current&&(n(A=>P?[...A,...S.items]:S.items),d(S.pagination),b.current=S.pagination.next_cursor);}catch(S){N.current&&m(S.message);}finally{N.current&&h(false);}},[c,r,i,a]),p=useCallback(async()=>{!b.current||u||await w(b.current,true);},[w,u]),v=useCallback(async()=>{b.current=null,await w(void 0,false);},[w]);return useEffect(()=>(N.current=true,w(),()=>{N.current=false;}),[w]),{repos:t,hasMore:l?.has_more??false,total:l?.total??0,loading:u,error:g,loadMore:p,reset:v,pagination:l}}function be(s){return Object.entries(s).map(([e,i])=>{let r=i.indexOf(":"),a=r>0?i.slice(0,r):"100644",c=r>0?i.slice(r+1):i;return {path:e,mode:a,cid:c,isDir:a==="040000"}}).sort((e,i)=>e.isDir!==i.isDir?e.isDir?-1:1:e.path.localeCompare(i.path))}function ee(s,e,i="main"){let r=z(s),[a,c]=useState([]),[t,n]=useState(false),[l,d]=useState(null),u=useRef(true),h=useCallback(async()=>{if(e)try{u.current&&(n(!0),d(null));let{tree:m}=await r.getTree(e,i);u.current&&c(be(m.entries));}catch(m){u.current&&d(m instanceof Error?m.message:"Failed to load tree");}finally{u.current&&n(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:l,refresh:h,getFileContent:g}}var ve=/^(https?:\/\/|mailto:|\/[^/])/i;function ke(s){let e=s.trim();return ve.test(e)?e:null}function B(s){let e=[],i=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,r=0,a,c=0;for(;(a=i.exec(s))!==null;){a.index>r&&e.push(s.slice(r,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 n=ke(a[10]);n?e.push(jsx("a",{href:n,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<s.length&&e.push(s.slice(r)),e.length>0?e:[s]}function Re(s){let e=s.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 c=a.match(/^(#{1,6})\s+(.+)/);if(c){i.push({type:"heading",level:c[1].length,content:c[2]}),r++;continue}if(a.trim().startsWith("```")){let n=a.trim().slice(3).trim(),l=[];for(r++;r<e.length&&!e[r].trim().startsWith("```");)l.push(e[r]),r++;i.push({type:"code",content:l.join(`
|
|
3
|
+
`),lang:n||void 0}),r++;continue}if(/^\s*[-*+]\s/.test(a)){let n=[];for(;r<e.length&&/^\s*[-*+]\s/.test(e[r]);)n.push(e[r].replace(/^\s*[-*+]\s+/,"")),r++;i.push({type:"ul",items:n});continue}if(/^\s*\d+[.)]\s/.test(a)){let n=[];for(;r<e.length&&/^\s*\d+[.)]\s/.test(e[r]);)n.push(e[r].replace(/^\s*\d+[.)]\s+/,"")),r++;i.push({type:"ol",items:n});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 Se(s,e){switch(s.type){case "hr":return jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let i=Math.min(Math.max(s.level||1,1),6),r=`h${i}`;return jsx(r,{className:C("text-foreground",Ne[i]),children:B(s.content||"")},`b${e}`)}case "paragraph":return jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:B(s.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:s.content})},`b${e}`);case "ul":return jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:s.items?.map((i,r)=>jsx("li",{className:"leading-relaxed",children:B(i)},`li${e}-${r}`))},`b${e}`);case "ol":return jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:s.items?.map((i,r)=>jsx("li",{className:"leading-relaxed",children:B(i)},`li${e}-${r}`))},`b${e}`);default:return null}}function D({content:s,className:e}){let i=Re(s);return jsx("div",{className:C("text-sm",e),children:i.map((r,a)=>Se(r,a))})}function se({open:s,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",s?"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 te({size:s=20,className:e}){return jsx("svg",{width:s,height:s,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 F({size:s=20,className:e}){return jsx("svg",{width:s,height:s,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 oe({size:s=20,className:e}){return jsx("svg",{width:s,height:s,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 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:"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 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:"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 Me(){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 ae(){let[s,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)},[]),s}function ie({onClose:s,children:e,title:i}){let r=ae(),a=useRef(s);return a.current=s,useEffect(()=>{let c=t=>{t.key==="Escape"&&a.current();};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[]),r?jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:s,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:s,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(F,{size:20})})]}),e]})]}):jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:s,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:s,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(F,{size:20})})]}),e]})]})}function _e(s){let e=s.split(`
|
|
4
|
+
`),i="",r="",c=false;for(let t=0;t<e.length;t++){let n=e[t].trim();if(t===0&&n==="---"){c=true;continue}if(c){n==="---"&&(c=false,true);continue}if(!i){let l=n.match(/^#{1,2}\s+(.+)/);if(l){i=l[1].trim();continue}}if(i&&!r){if(!n||n.startsWith("#")||n==="---"||n==="***"||n==="___")continue;r=n.replace(/\*\*/g,"").replace(/`/g,"").trim();break}}return i?{title:i,description:r}:null}function $e({onClose:s,onCreated:e,config:i}){let[r,a]=useState(""),[c,t]=useState(""),[n,l]=useState(""),[d,u]=useState(false),[h,g]=useState(null),[m,b]=useState(false),N=p=>{if(l(p),!r.trim()&&!c.trim()&&p.trim().length>10){let v=_e(p);v&&(a(v.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")),t(v.description),b(true));}};return jsx(ie,{title:"Write skill instructions",onClose:s,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:c,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:n,onChange:p=>N(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:s,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||"",v=m?n.trim():`# ${r.trim()}
|
|
5
5
|
|
|
6
|
-
${
|
|
6
|
+
${c.trim()}
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
-
${n.trim()}`,T=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.trim(),description:l.trim(),skill_md:v,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?.(),r();}catch(p){g(p instanceof Error?p.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 ze({onClose:r,onCreated:e,config:i}){let s=useRef(null),[a,l]=useState(false),[t,n]=useState(false),[c,d]=useState(null),u=async g=>{n(true),d(null);try{let m=await g.text(),y=i.apiBaseUrl||"",b=g.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),S=await fetch(`${y}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:b,skill_md:m,content_type:"code"})});if(!S.ok){let p=`Failed to register skill (${S.status})`;try{let v=await S.json();v.error&&(p=v.error);}catch{}throw new Error(p)}e?.(),r();}catch(m){d(m instanceof Error?m.message:"Upload failed");}finally{n(false);}};return jsx(oe,{title:"Upload skill",onClose:r,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:()=>s.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:s,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 _e({onClose:r,onSelect:e}){let i=se(),s=useRef(null),a=useRef(r);a.current=r,useEffect(()=>{if(i)return;let t=n=>{s.current&&n.target instanceof Node&&!s.current.contains(n.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: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"}),l.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:l.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 Ie({entry:r,selected:e,onSelect:i,depth:s=0}){return jsxs("button",{onClick:()=>i(r),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+s*16}px`},children:[jsx("span",{className:"truncate flex-1",children:r.path.split("/").pop()}),r.isDir&&jsx(ne,{className:"ml-auto text-muted-foreground"})]})}function Le({repo:r,selected:e,expanded:i,onSelect:s,onToggle:a,children:l}){return jsxs("div",{children:[jsxs("button",{onClick:()=>{s(),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:r.name})]}),i&&l]})}function Be({entry:r,content:e,loading:i,repoName:s}){let[a,l]=useState(false),t=useRef(null);useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[n,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(!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,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":n?"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(U,{content:e||""}):jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function Ae({config:r,category:e,className:i,style:s}){let{repos:a,loading:l,error:t,reset:d}=K(r,{pageSize:50}),[u,h]=useState(null),[g,m]=useState(null),[y,b]=useState(null),[S,p]=useState(null),[v,T]=useState(false),[R,E]=useState(""),[ie,H]=useState(false),[J,W]=useState(false),[V,B]=useState(null),le=a.find(w=>w.repo_id===u),{entries:ce,getFileContent:Z}=Y(r,g),q=a.filter(w=>!R||w.name.toLowerCase().includes(R.toLowerCase())),ue=useCallback(async w=>{if(!w.isDir){b(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: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: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(j,{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:()=>W(!J),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(re,{size:20})})]})}),J&&jsx(_e,{onClose:()=>W(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(Le,{repo:w,selected:u===w.repo_id,expanded:g===w.repo_id,onSelect:()=>{h(w.repo_id),b(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(Ie,{entry:P,selected:y?.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(Be,{entry:y,content:S,loading:v,repoName:le?.name||""})}),V==="write"&&jsx($e,{config:r,onClose:()=>B(null),onCreated:d}),V==="upload"&&jsx(ze,{config:r,onClose:()=>B(null),onCreated:d})]})}async function ae(r,e,i,s){let a={"Content-Type":"application/json",...i?.headers};s&&(a.Authorization=`Bearer ${s}`);let l=await fetch(`${r}${e}`,{...i,headers:a});if(!l.ok){let t=`HTTP ${l.status}`;try{let n=await l.json();n.error&&(t=n.error);}catch{}throw new Error(t)}return l.json()}function De({config:r,repoId:e,onAuthRequired:i,className:s,style:a}){let l=r.apiBaseUrl,t=r.apiKey,[n,c]=useState({stars:0,starred:false,repo_id:e}),[d,u]=useState(false),[h,g]=useState(null),m=useRef(true),y=l.includes("/cpx/rack")?"":"/api/rack";useEffect(()=>(m.current=true,ae(l,`${y}/${e}/stars`,void 0,t).then(S=>{m.current&&c(S);}).catch(()=>{}),()=>{m.current=false;}),[l,e,t,y]);let b=useCallback(async S=>{if(S.preventDefault(),S.stopPropagation(),!t){i?.();return}u(true),g(null);try{let p=n.starred?"DELETE":"POST",v=await ae(l,`${y}/${e}/star`,{method:p},t);m.current&&c({stars:v.stars,starred:v.starred,repo_id:e});}catch(p){m.current&&g(p.message);}finally{m.current&&u(false);}},[l,e,t,n.starred,i]);return jsxs("button",{onClick:b,disabled:d,title:h||(n.starred?"Unstar (100k tokens)":"Star (100k tokens)"),className:s,style:{display:"inline-flex",alignItems:"center",gap:"4px",background:"none",border:"none",cursor:d?"wait":"pointer",padding:"4px 8px",fontSize:"12px",fontFamily:"inherit",color:n.starred?"#f59e0b":"#91918d",transition:"color 150ms",opacity:d?.5:1,...a},children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:n.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:n.stars})]})}
|
|
11
|
-
export{
|
|
10
|
+
${n.trim()}`,E=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.trim(),description:c.trim(),skill_md:v,content_type:"code"})});if(!E.ok){let P=`Failed to register skill (${E.status})`;try{let S=await E.json();S.error&&(P=S.error);}catch{}throw new Error(P)}e?.(),s();}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 Ie({onClose:s,onCreated:e,config:i}){let r=useRef(null),[a,c]=useState(false),[t,n]=useState(false),[l,d]=useState(null),u=async g=>{n(true),d(null);try{let m=await g.text(),b=i.apiBaseUrl||"",N=g.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),w=await fetch(`${b}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:N,skill_md:m,content_type:"code"})});if(!w.ok){let p=`Failed to register skill (${w.status})`;try{let v=await w.json();v.error&&(p=v.error);}catch{}throw new Error(p)}e?.(),s();}catch(m){d(m instanceof Error?m.message:"Upload failed");}finally{n(false);}};return jsx(ie,{title:"Upload skill",onClose:s,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 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(oe,{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);}}),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 ze({onClose:s,onSelect:e}){let i=ae(),r=useRef(null),a=useRef(s);a.current=s,useEffect(()=>{if(i)return;let t=n=>{r.current&&n.target instanceof Node&&!r.current.contains(n.target)&&a.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[i]);let c=[{id:"create-with-geoff",icon:jsx(Te,{}),label:"Create with Geoff"},{id:"write",icon:jsx(Ee,{}),label:"Write skill instructions"},{id:"upload",icon:jsx(Me,{}),label:"Upload a skill"}];return i?jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:s,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),s();},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:c.map(t=>jsxs("button",{onClick:()=>{e(t.id),s();},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 Le({entry:s,selected:e,onSelect:i,depth:r=0}){return jsxs("button",{onClick:()=>i(s),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:s.path.split("/").pop()}),s.isDir&&jsx(se,{className:"ml-auto text-muted-foreground"})]})}function Be({repo:s,selected:e,expanded:i,onSelect:r,onToggle:a,children:c}){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(se,{open:i}),jsx(FileText,{className:"h-4 w-4 shrink-0"}),jsx("span",{className:"truncate",children:s.name})]}),i&&c]})}function Ae({entry:s,content:e,loading:i,repoName:r}){let[a,c]=useState(false),t=useRef(null);useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[n,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(!s)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=s.path.split("/").pop()||s.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":n?"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||""})})]})}var Oe={skills:"Skills",looops:"Looops",tensors:"Models",imaginations:"Imaginations",images:"Images"},Ue={skills:"skill/",looops:"looop/",tensors:"tensor/"};function je({config:s,category:e,className:i,style:r}){let{repos:a,loading:c,error:t,reset:d}=Q(s,{pageSize:50,category:e}),[u,h]=useState(null),[g,m]=useState(null),[b,N]=useState(null),[w,p]=useState(null),[v,E]=useState(false),[P,S]=useState(""),[A,W]=useState(false),[V,Z]=useState(false),[q,O]=useState(null),ce=a.find(x=>x.repo_id===u),{entries:ue,getFileContent:G}=ee(s,g),K=e?Ue[e]:void 0,M=a.filter(x=>!(K&&!x.name.startsWith(K)||P&&!x.name.toLowerCase().includes(P.toLowerCase()))),de=useCallback(async x=>{if(!x.isDir){N(x),E(true);try{let T=await G(x.cid);p(T);}catch(T){let fe=T instanceof Error?T.message:"Unknown error";p(`Failed to load file: ${fe}`);}finally{E(false);}}},[G]);useEffect(()=>{M.length>0&&!u&&(h(M[0].repo_id),m(M[0].repo_id));},[M,u]);let me=x=>{x==="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"):O(x);};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:A?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(te,{size:16,className:"shrink-0 text-muted-foreground"}),jsx("input",{type:"text",value:P,onChange:x=>S(x.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:()=>{W(false),S("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(F,{size:16})})]}):jsxs(Fragment,{children:[jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground",children:e&&Oe[e]||e||"Items"}),jsx("button",{onClick:()=>W(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsx(te,{size:20})}),jsx("button",{onClick:()=>Z(!V),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(oe,{size:20})})]})}),V&&jsx(ze,{onClose:()=>Z(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}):M.length===0?jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:P?"No matching items":"No items yet"}):jsx("div",{className:"space-y-0.5",children:M.map(x=>jsx(Be,{repo:x,selected:u===x.repo_id,expanded:g===x.repo_id,onSelect:()=>{h(x.repo_id),N(null),p(null);},onToggle:()=>m(g===x.repo_id?null:x.repo_id),children:jsx("div",{className:"ml-10 pl-1",children:ue.map(T=>jsx(Le,{entry:T,selected:b?.path===T.path,onSelect:de,depth:T.path.split("/").length-1},T.path))})},x.repo_id))})})]}),jsx("div",{className:"flex-1 min-w-0",children:jsx(Ae,{entry:b,content:w,loading:v,repoName:ce?.name||""})}),q==="write"&&jsx($e,{config:s,onClose:()=>O(null),onCreated:d}),q==="upload"&&jsx(Ie,{config:s,onClose:()=>O(null),onCreated:d})]})}async function le(s,e,i,r){let a={"Content-Type":"application/json",...i?.headers};r&&(a.Authorization=`Bearer ${r}`);let c=await fetch(`${s}${e}`,{...i,headers:a});if(!c.ok){let t=`HTTP ${c.status}`;try{let n=await c.json();n.error&&(t=n.error);}catch{}throw new Error(t)}return c.json()}function Je({config:s,repoId:e,onAuthRequired:i,className:r,style:a}){let c=s.apiBaseUrl,t=s.apiKey,[n,l]=useState({stars:0,starred:false,repo_id:e}),[d,u]=useState(false),[h,g]=useState(null),m=useRef(true),b=c.includes("/cpx/rack")?"":"/api/rack";useEffect(()=>(m.current=true,le(c,`${b}/${e}/stars`,void 0,t).then(w=>{m.current&&l(w);}).catch(()=>{}),()=>{m.current=false;}),[c,e,t,b]);let N=useCallback(async w=>{if(w.preventDefault(),w.stopPropagation(),!t){i?.();return}u(true),g(null);try{let p=n.starred?"DELETE":"POST",v=await le(c,`${b}/${e}/star`,{method:p},t);m.current&&l({stars:v.stars,starred:v.starred,repo_id:e});}catch(p){m.current&&g(p.message);}finally{m.current&&u(false);}},[c,e,t,n.starred,i]);return jsxs("button",{onClick:N,disabled:d,title:h||(n.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:n.starred?"#f59e0b":"#91918d",transition:"color 150ms",opacity:d?.5:1,...a},children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:n.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:n.stars})]})}
|
|
11
|
+
export{D as Markdown,je as RackBrowser,Je as StarButton};
|
package/dist/hooks/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var react=require('react');async function R(u,t,i,l){let c={"Content-Type":"application/json",...i?.headers};l&&(c.Authorization=`Bearer ${l}`);let p=await fetch(`${u}${t}`,{...i,headers:c});if(!p.ok){let e=`HTTP ${p.status}`;try{let r=await p.json();r.error&&(e=r.error);}catch{}throw new Error(e)}return p.json()}function w(u){let t=u.indexOf(":");return {mode:u.slice(0,t),cid:u.slice(t+1)}}function d(u){let t=u.apiBaseUrl,i=u.authorMid,l=u.ownerMid,c=u.apiKey,p=u.stacknetUrl||u.apiBaseUrl;return react.useMemo(()=>({async listRepos(e,r){let n=new URLSearchParams;(e||l)&&n.set("owner",e||l),r?.limit&&n.set("limit",String(r.limit)),r?.cursor&&n.set("cursor",r.cursor);let s=n.toString()?`?${n}`:"",a=await R(t,`/api/rack/repos${s}`,void 0,c);return {items:a.repos||[],pagination:a.pagination||{total:(a.repos||[]).length,limit:50,has_more:false,next_cursor:null}}},async initRepo(e){return R(t,"/api/rack/init",{method:"POST",body:JSON.stringify({...e,owner_mid:l})},c)},async push(e,r){return R(t,`/api/rack/${e}/push`,{method:"POST",body:JSON.stringify({...r,author_mid:i})},c)},async getTree(e,r="main"){let n=await R(t,`/api/rack/${e}/tree/${r}`,void 0,c);return {tree:n.tree,commit_cid:n.commit_cid}},async getBlob(e,r){return (await R(t,`/api/rack/${e}/blob/${r}`,void 0,c)).content},async getLog(e,r,n){let s=new URLSearchParams;r&&s.set("ref",r),n&&s.set("max_count",String(n));let a=s.toString()?`?${s}`:"";return (await R(t,`/api/rack/${e}/log${a}`,void 0,c)).commits||[]},async getBranches(e){return (await R(t,`/api/rack/${e}/branches`,void 0,c)).branches||[]},async createBranch(e,r,n){return R(t,`/api/rack/${e}/branch`,{method:"POST",body:JSON.stringify({branch_name:r,from_ref:n})},c)},async merge(e,r,n){return R(t,`/api/rack/${e}/merge`,{method:"POST",body:JSON.stringify({source_branch:r,target_branch:n})},c)},async getDiff(e,r,n){return (await R(t,`/api/rack/${e}/diff/${r}/${n}`,void 0,c)).diff?.entries||[]},async starRepo(e){return R(t,`/api/rack/${e}/star`,{method:"POST"},c)},async unstarRepo(e){return R(t,`/api/rack/${e}/star`,{method:"DELETE"},c)},async getStarInfo(e){return R(t,`/api/rack/${e}/stars`,void 0,c)},async getSkillStats(e){let r={meta:null,tokenCount:null,usageCount:null};try{let{tree:n}=await this.getTree(e,"main");if(!n?.entries)return r;if(n.entries["META.json"]){let f=w(n.entries["META.json"]).cid,o=await this.getBlob(e,f);r.meta=JSON.parse(o);}let s=0,a=Object.values(n.entries).map(async f=>{try{let o=w(f).cid,g=await this.getBlob(e,o);s+=g.length;}catch{}});await Promise.all(a),s>0&&(r.tokenCount=Math.ceil(s/4)),r.meta?.skill_id&&(r.usageCount=await this.getSkillUsageCount(r.meta.skill_id));}catch{}return r},async getSkillUsageCount(e){try{let r=await fetch(`${p}/v1/skills/${encodeURIComponent(e)}`);if(r.ok){let s=await r.json();return s.usage_count??s.usageCount??null}let n=await fetch(`${p}/v1/skills?scope=public`);if(n.ok){let a=((await n.json()).skills||[]).find(f=>f.name===e||f.id===e);if(a)return a.usage_count??a.usageCount??0}return 0}catch{return null}},async getTensorStats(e){let r={meta:null,sizeMB:null};try{let{tree:n}=await this.getTree(e,"main");if(!n?.entries)return r;if(n.entries["TENSOR_META.json"]){let s=w(n.entries["TENSOR_META.json"]).cid,a=await this.getBlob(e,s);r.meta=JSON.parse(a),r.sizeMB=r.meta?.tensor_size_mb??null;}}catch{}return r},async getLooopStats(e){let r={meta:null,fileCount:null};try{let{tree:n}=await this.getTree(e,"main");if(!n?.entries)return r;if(n.entries["LOOOP_META.json"]){let s=w(n.entries["LOOOP_META.json"]).cid,a=await this.getBlob(e,s);r.meta=JSON.parse(a);}r.fileCount=Object.keys(n.entries).length;}catch{}return r},async getNetworkStats(){try{return (await R(t,"/api/rack/stats",void 0,c)).stats||null}catch{return null}},async getTrending(e=5,r=1,n){try{let s=new URLSearchParams({limit:String(e),days:String(r)});n&&s.set("cursor",n);let a=await R(t,`/api/rack/trending?${s}`,void 0,c);return {items:a.trending||[],pagination:a.pagination||{total:(a.trending||[]).length,limit:e,has_more:!1,next_cursor:null}}}catch{return {items:[],pagination:{total:0,limit:e,has_more:false,next_cursor:null}}}}}),[t,i,l,c,p])}function Z(u){let t=d(u),i=react.useRef(t);i.current=t;let[l,c]=react.useState([]),[p,e]=react.useState(true),[r,n]=react.useState(null),s=react.useRef(true),a=react.useRef(null),f=react.useCallback(async()=>{a.current?.abort();let o=new AbortController;a.current=o;try{s.current&&(e(!0),n(null));let g=await i.current.listRepos();s.current&&!o.signal.aborted&&c(g.items);}catch(g){s.current&&!o.signal.aborted&&n(g instanceof Error?g.message:"Failed to load repos");}finally{s.current&&!o.signal.aborted&&e(false);}},[]);return react.useEffect(()=>(s.current=true,f(),()=>{s.current=false,a.current?.abort();}),[f]),{repos:l,loading:p,error:r,refresh:f}}function rt(u){return Object.entries(u).map(([t,i])=>{let l=i.indexOf(":"),c=l>0?i.slice(0,l):"100644",p=l>0?i.slice(l+1):i;return {path:t,mode:c,cid:p,isDir:c==="040000"}}).sort((t,i)=>t.isDir!==i.isDir?t.isDir?-1:1:t.path.localeCompare(i.path))}function nt(u,t,i="main"){let l=d(u),[c,p]=react.useState([]),[e,r]=react.useState(false),[n,s]=react.useState(null),a=react.useRef(true),f=react.useCallback(async()=>{if(t)try{a.current&&(r(!0),s(null));let{tree:g}=await l.getTree(t,i);a.current&&p(rt(g.entries));}catch(g){a.current&&s(g instanceof Error?g.message:"Failed to load tree");}finally{a.current&&r(false);}},[l,t,i]);react.useEffect(()=>(a.current=true,f(),()=>{a.current=false;}),[f]);let o=react.useCallback(async g=>{if(!t)throw new Error("No repo selected");return l.getBlob(t,g)},[l,t]);return {entries:c,loading:e,error:n,refresh:f,getFileContent:o}}function it(u){let t=d(u),[i,l]=react.useState(false),[c,p]=react.useState(null),e=react.useRef(true);return react.useEffect(()=>(e.current=true,()=>{e.current=false;}),[]),{push:react.useCallback(async(n,s,a,f)=>{try{return e.current&&(l(!0),p(null)),await t.push(n,{files:s,message:a,branch:f})}catch(o){let g=o instanceof Error?o.message:"Push failed";return e.current&&p(g),null}finally{e.current&&l(false);}},[t]),pushing:i,error:c}}function ut(u,t={}){let{pageSize:i=50,owner:l}=t,c=d(u),[p,e]=react.useState([]),[r,n]=react.useState(null),[s,a]=react.useState(false),[f,o]=react.useState(null),g=react.useRef(null),m=react.useRef(true),h=react.useCallback(async(W,G=false)=>{a(true),o(null);try{let S=await c.listRepos(l,{limit:i,cursor:W||void 0});m.current&&(e(Y=>G?[...Y,...S.items]:S.items),n(S.pagination),g.current=S.pagination.next_cursor);}catch(S){m.current&&o(S.message);}finally{m.current&&a(false);}},[c,l,i]),y=react.useCallback(async()=>{!g.current||s||await h(g.current,true);},[h,s]),k=react.useCallback(async()=>{g.current=null,await h(void 0,false);},[h]);return react.useEffect(()=>(m.current=true,h(),()=>{m.current=false;}),[h]),{repos:p,hasMore:r?.has_more??false,total:r?.total??0,loading:s,error:f,loadMore:y,reset:k,pagination:r}}var O="stacknet-rack-apikey";function ft(u){let t=u.stacknetUrl||u.apiBaseUrl,[i,l]=react.useState({authenticated:false}),[c,p]=react.useState(null),[e,r]=react.useState(false),n=react.useCallback(o=>({"Content-Type":"application/json",...o||u.apiKey?{Authorization:`Bearer ${o||u.apiKey}`}:{}}),[u.apiKey]),s=react.useCallback(async o=>{r(true);try{let g=await fetch(`${t}/health`,{headers:n(o)});if(!g.ok)throw new Error(`Authentication failed: ${g.status}`);let m={authenticated:!0,apiKey:o,permission:o.startsWith("gk_")?"write":"read"};l(m);try{localStorage.setItem(O,o);}catch{}return m}catch(g){throw l({authenticated:false}),g}finally{r(false);}},[t,n]),a=react.useCallback(()=>{l({authenticated:false}),p(null);try{localStorage.removeItem(O);}catch{}},[]),f=react.useCallback(async()=>{let o=i.apiKey||u.apiKey;if(!o)return null;try{let g=await fetch(`${t}/network/usage`,{headers:n(o)});if(!g.ok)return null;let m=await g.json(),h={planAllocation:m.plan_allocation??m.planAllocation??0,inferenceUsed:m.inference_used??m.inferenceUsed??0,ledgerSpent:m.ledger_spent??m.ledgerSpent??0,totalUsed:m.total_used??m.totalUsed??0,remaining:m.remaining??0,percent:m.percent??0,exceeded:m.exceeded??!1};return p(h),h}catch{return null}},[i.apiKey,u.apiKey,t,n]);return react.useEffect(()=>{let o=u.apiKey;if(o){l({authenticated:true,apiKey:o,permission:o.startsWith("gk_")?"write":"read"});return}try{let g=localStorage.getItem(O);g&&l({authenticated:!0,apiKey:g,permission:g.startsWith("gk_")?"write":"read"});}catch{}},[u.apiKey]),{session:i,budget:c,loading:e,login:s,logout:a,refreshBudget:f}}var gt=1e3,J=1e3,pt=1e3,z=100;function F(u,t){if(u==="skill"||u==="looop"){let c=u==="skill"?gt:pt,p=z+Math.ceil(t/4);return {type:u,totalBytes:t,totalMegabytes:t/1e6,baseCost:p,multiplier:c,registrationCostTokens:p*c}}let i=Math.ceil(t/1e6),l=z+i;return {type:u,totalBytes:t,totalMegabytes:i,baseCost:l,multiplier:J,registrationCostTokens:l*J}}function mt(u){let t=u.stacknetUrl||u.apiBaseUrl,i=u.apiKey,[l,c]=react.useState(false),[p,e]=react.useState(null),r=react.useCallback(()=>{if(!i)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${i}`}},[i]),n=react.useCallback(async f=>{c(true),e(null);try{let o=await fetch(`${t}/skills`,{method:"POST",headers:r(),body:JSON.stringify(f)});if(!o.ok){let g=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(g.error||`Registration failed: ${o.status}`)}return await o.json()}catch(o){throw e(o.message),o}finally{c(false);}},[t,r]),s=react.useCallback(async f=>{c(true),e(null);try{let o=await fetch(`${t}/tensors`,{method:"POST",headers:r(),body:JSON.stringify(f)});if(!o.ok){let g=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(g.error||`Registration failed: ${o.status}`)}return await o.json()}catch(o){throw e(o.message),o}finally{c(false);}},[t,r]),a=react.useCallback(async f=>{c(true),e(null);try{let o=await fetch(`${t}/looops`,{method:"POST",headers:r(),body:JSON.stringify(f)});if(!o.ok){let g=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(g.error||`Registration failed: ${o.status}`)}return await o.json()}catch(o){throw e(o.message),o}finally{c(false);}},[t,r]);return {registerSkill:n,registerTensor:s,registerLooop:a,estimateCost:F,registering:l,error:p}}function yt(u,t){let i=d(u),[l,c]=react.useState({meta:null,tokenCount:null,usageCount:null}),[p,e]=react.useState(false),[r,n]=react.useState(null),s=react.useRef(true),a=react.useCallback(async()=>{if(t){e(true),n(null);try{let f=await i.getSkillStats(t);s.current&&c(f);}catch(f){s.current&&n(f.message);}finally{s.current&&e(false);}}},[i,t]);return react.useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:l,loading:p,error:r,refresh:a}}function Pt(u,t){let i=d(u),[l,c]=react.useState({meta:null,sizeMB:null}),[p,e]=react.useState(false),[r,n]=react.useState(null),s=react.useRef(true),a=react.useCallback(async()=>{if(t){e(true),n(null);try{let f=await i.getTensorStats(t);s.current&&c(f);}catch(f){s.current&&n(f.message);}finally{s.current&&e(false);}}},[i,t]);return react.useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:l,loading:p,error:r,refresh:a}}function Et(u,t){let i=d(u),[l,c]=react.useState({meta:null,fileCount:null}),[p,e]=react.useState(false),[r,n]=react.useState(null),s=react.useRef(true),a=react.useCallback(async()=>{if(t){e(true),n(null);try{let f=await i.getLooopStats(t);s.current&&c(f);}catch(f){s.current&&n(f.message);}finally{s.current&&e(false);}}},[i,t]);return react.useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:l,loading:p,error:r,refresh:a}}function xt(u){let t=d(u),[i,l]=react.useState(null),[c,p]=react.useState(false),[e,r]=react.useState(null),n=react.useRef(true),s=react.useCallback(async()=>{p(true),r(null);try{let a=await t.getNetworkStats();n.current&&l(a);}catch(a){n.current&&r(a.message);}finally{n.current&&p(false);}},[t]);return react.useEffect(()=>(n.current=true,s(),()=>{n.current=false;}),[s]),{stats:i,loading:c,error:e,refresh:s}}function $t(u,t=5,i=1){let l=d(u),[c,p]=react.useState([]),[e,r]=react.useState(null),[n,s]=react.useState(false),[a,f]=react.useState(null),o=react.useRef(true),g=react.useRef(null),m=react.useCallback(async y=>{s(true),f(null),g.current=null;try{let k=await l.getTrending(t,y??i);o.current&&(p(k.items),r(k.pagination),g.current=k.pagination.next_cursor);}catch(k){o.current&&f(k.message);}finally{o.current&&s(false);}},[l,t,i]),h=react.useCallback(async()=>{if(!(!g.current||n)){s(true);try{let y=await l.getTrending(t,i,g.current);o.current&&(p(k=>[...k,...y.items]),r(y.pagination),g.current=y.pagination.next_cursor);}catch(y){o.current&&f(y.message);}finally{o.current&&s(false);}}},[l,t,i,n]);return react.useEffect(()=>(o.current=true,m(),()=>{o.current=false;}),[m]),{repos:c,hasMore:e?.has_more??false,total:e?.total??0,loading:n,error:a,refresh:m,loadMore:h}}function Nt(u,t){let i=d(u),[l,c]=react.useState({stars:0,starred:false,repo_id:t||""}),[p,e]=react.useState(false),[r,n]=react.useState(null),s=react.useRef(true),a=react.useCallback(async()=>{if(t)try{let o=await i.getStarInfo(t);s.current&&c(o);}catch{}},[i,t]);react.useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]);let f=react.useCallback(async()=>{if(t){e(true),n(null);try{let o=l.starred?await i.unstarRepo(t):await i.starRepo(t);s.current&&c({stars:o.stars,starred:o.starred,repo_id:t});}catch(o){s.current&&n(o.message);}finally{s.current&&e(false);}}},[i,t,l.starred]);return {...l,loading:p,error:r,toggle:f,refresh:a}}exports.estimateCost=F;exports.useLooopStats=Et;exports.useNetworkStats=xt;exports.usePaginatedRepos=ut;exports.useRackClient=d;exports.useRackRegister=mt;exports.useRackSession=ft;exports.useRepoPush=it;exports.useRepoTree=nt;exports.useRepos=Z;exports.useSkillStats=yt;exports.useStar=Nt;exports.useTensorStats=Pt;exports.useTrending=$t;
|
|
1
|
+
'use strict';var react=require('react');async function R(l,t,i,u){let c={"Content-Type":"application/json",...i?.headers};u&&(c.Authorization=`Bearer ${u}`);let g=await fetch(`${l}${t}`,{...i,headers:c});if(!g.ok){let e=`HTTP ${g.status}`;try{let r=await g.json();r.error&&(e=r.error);}catch{}throw new Error(e)}return g.json()}function w(l){let t=l.indexOf(":");return {mode:l.slice(0,t),cid:l.slice(t+1)}}function d(l){let t=l.apiBaseUrl,i=l.authorMid,u=l.ownerMid,c=l.apiKey,g=l.stacknetUrl||l.apiBaseUrl;return react.useMemo(()=>({async listRepos(e,r){let n=new URLSearchParams;(e||u)&&n.set("owner",e||u),r?.limit&&n.set("limit",String(r.limit)),r?.cursor&&n.set("cursor",r.cursor),r?.category&&n.set("category",r.category);let s=n.toString()?`?${n}`:"",a=await R(t,`/api/rack/repos${s}`,void 0,c);return {items:a.repos||[],pagination:a.pagination||{total:(a.repos||[]).length,limit:50,has_more:false,next_cursor:null}}},async initRepo(e){return R(t,"/api/rack/init",{method:"POST",body:JSON.stringify({...e,owner_mid:u})},c)},async push(e,r){return R(t,`/api/rack/${e}/push`,{method:"POST",body:JSON.stringify({...r,author_mid:i})},c)},async getTree(e,r="main"){let n=await R(t,`/api/rack/${e}/tree/${r}`,void 0,c);return {tree:n.tree,commit_cid:n.commit_cid}},async getBlob(e,r){return (await R(t,`/api/rack/${e}/blob/${r}`,void 0,c)).content},async getLog(e,r,n){let s=new URLSearchParams;r&&s.set("ref",r),n&&s.set("max_count",String(n));let a=s.toString()?`?${s}`:"";return (await R(t,`/api/rack/${e}/log${a}`,void 0,c)).commits||[]},async getBranches(e){return (await R(t,`/api/rack/${e}/branches`,void 0,c)).branches||[]},async createBranch(e,r,n){return R(t,`/api/rack/${e}/branch`,{method:"POST",body:JSON.stringify({branch_name:r,from_ref:n,author_mid:i})},c)},async merge(e,r,n){return R(t,`/api/rack/${e}/merge`,{method:"POST",body:JSON.stringify({source_branch:r,target_branch:n,author_mid:i})},c)},async getDiff(e,r,n){return (await R(t,`/api/rack/${e}/diff/${r}/${n}`,void 0,c)).diff?.entries||[]},async starRepo(e){return R(t,`/api/rack/${e}/star`,{method:"POST",body:JSON.stringify({owner_mid:u})},c)},async unstarRepo(e){return R(t,`/api/rack/${e}/star`,{method:"DELETE",body:JSON.stringify({owner_mid:u})},c)},async getStarInfo(e){return R(t,`/api/rack/${e}/stars`,void 0,c)},async getSkillStats(e){let r={meta:null,tokenCount:null,usageCount:null};try{let{tree:n}=await this.getTree(e,"main");if(!n?.entries)return r;if(n.entries["META.json"]){let f=w(n.entries["META.json"]).cid,o=await this.getBlob(e,f);r.meta=JSON.parse(o);}let s=0,a=Object.values(n.entries).map(async f=>{try{let o=w(f).cid,p=await this.getBlob(e,o);s+=p.length;}catch{}});await Promise.all(a),s>0&&(r.tokenCount=Math.ceil(s/4)),r.meta?.skill_id&&(r.usageCount=await this.getSkillUsageCount(r.meta.skill_id));}catch{}return r},async getSkillUsageCount(e){try{let r=await fetch(`${g}/v1/skills/${encodeURIComponent(e)}`);if(r.ok){let s=await r.json();return s.usage_count??s.usageCount??null}let n=await fetch(`${g}/v1/skills?scope=public`);if(n.ok){let a=((await n.json()).skills||[]).find(f=>f.name===e||f.id===e);if(a)return a.usage_count??a.usageCount??0}return 0}catch{return null}},async getTensorStats(e){let r={meta:null,sizeMB:null};try{let{tree:n}=await this.getTree(e,"main");if(!n?.entries)return r;if(n.entries["TENSOR_META.json"]){let s=w(n.entries["TENSOR_META.json"]).cid,a=await this.getBlob(e,s);r.meta=JSON.parse(a),r.sizeMB=r.meta?.tensor_size_mb??null;}}catch{}return r},async getLooopStats(e){let r={meta:null,fileCount:null};try{let{tree:n}=await this.getTree(e,"main");if(!n?.entries)return r;if(n.entries["META.json"]){let s=w(n.entries["META.json"]).cid,a=await this.getBlob(e,s);r.meta=JSON.parse(a);}r.fileCount=Object.keys(n.entries).length;}catch{}return r},async getNetworkStats(){try{return (await R(t,"/api/rack/stats",void 0,c)).stats||null}catch{return null}},async getTrending(e=5,r=1,n){try{let s=new URLSearchParams({limit:String(e),days:String(r)});n&&s.set("cursor",n);let a=await R(t,`/api/rack/trending?${s}`,void 0,c);return {items:a.trending||[],pagination:a.pagination||{total:(a.trending||[]).length,limit:e,has_more:!1,next_cursor:null}}}catch{return {items:[],pagination:{total:0,limit:e,has_more:false,next_cursor:null}}}}}),[t,i,u,c,g])}function tt(l){let t=d(l),i=react.useRef(t);i.current=t;let[u,c]=react.useState([]),[g,e]=react.useState(true),[r,n]=react.useState(null),s=react.useRef(true),a=react.useRef(null),f=react.useCallback(async()=>{a.current?.abort();let o=new AbortController;a.current=o;try{s.current&&(e(!0),n(null));let p=await i.current.listRepos();s.current&&!o.signal.aborted&&c(p.items);}catch(p){s.current&&!o.signal.aborted&&n(p instanceof Error?p.message:"Failed to load repos");}finally{s.current&&!o.signal.aborted&&e(false);}},[]);return react.useEffect(()=>(s.current=true,f(),()=>{s.current=false,a.current?.abort();}),[f]),{repos:u,loading:g,error:r,refresh:f}}function nt(l){return Object.entries(l).map(([t,i])=>{let u=i.indexOf(":"),c=u>0?i.slice(0,u):"100644",g=u>0?i.slice(u+1):i;return {path:t,mode:c,cid:g,isDir:c==="040000"}}).sort((t,i)=>t.isDir!==i.isDir?t.isDir?-1:1:t.path.localeCompare(i.path))}function st(l,t,i="main"){let u=d(l),[c,g]=react.useState([]),[e,r]=react.useState(false),[n,s]=react.useState(null),a=react.useRef(true),f=react.useCallback(async()=>{if(t)try{a.current&&(r(!0),s(null));let{tree:p}=await u.getTree(t,i);a.current&&g(nt(p.entries));}catch(p){a.current&&s(p instanceof Error?p.message:"Failed to load tree");}finally{a.current&&r(false);}},[u,t,i]);react.useEffect(()=>(a.current=true,f(),()=>{a.current=false;}),[f]);let o=react.useCallback(async p=>{if(!t)throw new Error("No repo selected");return u.getBlob(t,p)},[u,t]);return {entries:c,loading:e,error:n,refresh:f,getFileContent:o}}function ct(l){let t=d(l),[i,u]=react.useState(false),[c,g]=react.useState(null),e=react.useRef(true);return react.useEffect(()=>(e.current=true,()=>{e.current=false;}),[]),{push:react.useCallback(async(n,s,a,f)=>{try{return e.current&&(u(!0),g(null)),await t.push(n,{files:s,message:a,branch:f})}catch(o){let p=o instanceof Error?o.message:"Push failed";return e.current&&g(p),null}finally{e.current&&u(false);}},[t]),pushing:i,error:c}}function lt(l,t={}){let{pageSize:i=50,owner:u,category:c}=t,g=d(l),[e,r]=react.useState([]),[n,s]=react.useState(null),[a,f]=react.useState(false),[o,p]=react.useState(null),m=react.useRef(null),y=react.useRef(true),h=react.useCallback(async(G,Y=false)=>{f(true),p(null);try{let S=await g.listRepos(u,{limit:i,cursor:G||void 0,category:c});y.current&&(r(Q=>Y?[...Q,...S.items]:S.items),s(S.pagination),m.current=S.pagination.next_cursor);}catch(S){y.current&&p(S.message);}finally{y.current&&f(false);}},[g,u,i,c]),k=react.useCallback(async()=>{!m.current||a||await h(m.current,true);},[h,a]),W=react.useCallback(async()=>{m.current=null,await h(void 0,false);},[h]);return react.useEffect(()=>(y.current=true,h(),()=>{y.current=false;}),[h]),{repos:e,hasMore:n?.has_more??false,total:n?.total??0,loading:a,error:o,loadMore:k,reset:W,pagination:n}}var $="stacknet-rack-apikey";function gt(l){let t=l.stacknetUrl||l.apiBaseUrl,[i,u]=react.useState({authenticated:false}),[c,g]=react.useState(null),[e,r]=react.useState(false),n=react.useCallback(o=>({"Content-Type":"application/json",...o||l.apiKey?{Authorization:`Bearer ${o||l.apiKey}`}:{}}),[l.apiKey]),s=react.useCallback(async o=>{r(true);try{let p=await fetch(`${t}/health`,{headers:n(o)});if(!p.ok)throw new Error(`Authentication failed: ${p.status}`);let m={authenticated:!0,apiKey:o,permission:o.startsWith("gk_")?"write":"read"};u(m);try{localStorage.setItem($,o);}catch{}return m}catch(p){throw u({authenticated:false}),p}finally{r(false);}},[t,n]),a=react.useCallback(()=>{u({authenticated:false}),g(null);try{localStorage.removeItem($);}catch{}},[]),f=react.useCallback(async()=>{let o=i.apiKey||l.apiKey;if(!o)return null;try{let p=await fetch(`${t}/network/usage`,{headers:n(o)});if(!p.ok)return null;let m=await p.json(),y={planAllocation:m.plan_allocation??m.planAllocation??0,inferenceUsed:m.inference_used??m.inferenceUsed??0,ledgerSpent:m.ledger_spent??m.ledgerSpent??0,totalUsed:m.total_used??m.totalUsed??0,remaining:m.remaining??0,percent:m.percent??0,exceeded:m.exceeded??!1};return g(y),y}catch{return null}},[i.apiKey,l.apiKey,t,n]);return react.useEffect(()=>{let o=l.apiKey;if(o){u({authenticated:true,apiKey:o,permission:o.startsWith("gk_")?"write":"read"});return}try{let p=localStorage.getItem($);p&&u({authenticated:!0,apiKey:p,permission:p.startsWith("gk_")?"write":"read"});}catch{}},[l.apiKey]),{session:i,budget:c,loading:e,login:s,logout:a,refreshBudget:f}}var pt=1e3,D=1e3,mt=1e3,z=100;function F(l,t){if(l==="skill"||l==="looop"){let c=l==="skill"?pt:mt,g=z+Math.ceil(t/4);return {type:l,totalBytes:t,totalMegabytes:t/1e6,baseCost:g,multiplier:c,registrationCostTokens:g*c}}let i=Math.ceil(t/1e6),u=z+i;return {type:l,totalBytes:t,totalMegabytes:i,baseCost:u,multiplier:D,registrationCostTokens:u*D}}function dt(l){let t=l.stacknetUrl||l.apiBaseUrl,i=l.apiKey,[u,c]=react.useState(false),[g,e]=react.useState(null),r=react.useCallback(()=>{if(!i)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${i}`}},[i]),n=react.useCallback(async f=>{c(true),e(null);try{let o=await fetch(`${t}/skills`,{method:"POST",headers:r(),body:JSON.stringify(f)});if(!o.ok){let p=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(p.error||`Registration failed: ${o.status}`)}return await o.json()}catch(o){throw e(o.message),o}finally{c(false);}},[t,r]),s=react.useCallback(async f=>{c(true),e(null);try{let o=await fetch(`${t}/tensors`,{method:"POST",headers:r(),body:JSON.stringify(f)});if(!o.ok){let p=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(p.error||`Registration failed: ${o.status}`)}return await o.json()}catch(o){throw e(o.message),o}finally{c(false);}},[t,r]),a=react.useCallback(async f=>{c(true),e(null);try{let o=await fetch(`${t}/looops`,{method:"POST",headers:r(),body:JSON.stringify(f)});if(!o.ok){let p=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(p.error||`Registration failed: ${o.status}`)}return await o.json()}catch(o){throw e(o.message),o}finally{c(false);}},[t,r]);return {registerSkill:n,registerTensor:s,registerLooop:a,estimateCost:F,registering:u,error:g}}function kt(l,t){let i=d(l),[u,c]=react.useState({meta:null,tokenCount:null,usageCount:null}),[g,e]=react.useState(false),[r,n]=react.useState(null),s=react.useRef(true),a=react.useCallback(async()=>{if(t){e(true),n(null);try{let f=await i.getSkillStats(t);s.current&&c(f);}catch(f){s.current&&n(f.message);}finally{s.current&&e(false);}}},[i,t]);return react.useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:u,loading:g,error:r,refresh:a}}function Pt(l,t){let i=d(l),[u,c]=react.useState({meta:null,sizeMB:null}),[g,e]=react.useState(false),[r,n]=react.useState(null),s=react.useRef(true),a=react.useCallback(async()=>{if(t){e(true),n(null);try{let f=await i.getTensorStats(t);s.current&&c(f);}catch(f){s.current&&n(f.message);}finally{s.current&&e(false);}}},[i,t]);return react.useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:u,loading:g,error:r,refresh:a}}function _t(l,t){let i=d(l),[u,c]=react.useState({meta:null,fileCount:null}),[g,e]=react.useState(false),[r,n]=react.useState(null),s=react.useRef(true),a=react.useCallback(async()=>{if(t){e(true),n(null);try{let f=await i.getLooopStats(t);s.current&&c(f);}catch(f){s.current&&n(f.message);}finally{s.current&&e(false);}}},[i,t]);return react.useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:u,loading:g,error:r,refresh:a}}function $t(l){let t=d(l),[i,u]=react.useState(null),[c,g]=react.useState(false),[e,r]=react.useState(null),n=react.useRef(true),s=react.useCallback(async()=>{g(true),r(null);try{let a=await t.getNetworkStats();n.current&&u(a);}catch(a){n.current&&r(a.message);}finally{n.current&&g(false);}},[t]);return react.useEffect(()=>(n.current=true,s(),()=>{n.current=false;}),[s]),{stats:i,loading:c,error:e,refresh:s}}function Mt(l,t=5,i=1){let u=d(l),[c,g]=react.useState([]),[e,r]=react.useState(null),[n,s]=react.useState(false),[a,f]=react.useState(null),o=react.useRef(true),p=react.useRef(null),m=react.useCallback(async h=>{s(true),f(null),p.current=null;try{let k=await u.getTrending(t,h??i);o.current&&(g(k.items),r(k.pagination),p.current=k.pagination.next_cursor);}catch(k){o.current&&f(k.message);}finally{o.current&&s(false);}},[u,t,i]),y=react.useCallback(async()=>{if(!(!p.current||n)){s(true);try{let h=await u.getTrending(t,i,p.current);o.current&&(g(k=>[...k,...h.items]),r(h.pagination),p.current=h.pagination.next_cursor);}catch(h){o.current&&f(h.message);}finally{o.current&&s(false);}}},[u,t,i,n]);return react.useEffect(()=>(o.current=true,m(),()=>{o.current=false;}),[m]),{repos:c,hasMore:e?.has_more??false,total:e?.total??0,loading:n,error:a,refresh:m,loadMore:y}}function Bt(l,t){let i=d(l),[u,c]=react.useState({stars:0,starred:false,repo_id:t||""}),[g,e]=react.useState(false),[r,n]=react.useState(null),s=react.useRef(true),a=react.useCallback(async()=>{if(t)try{let o=await i.getStarInfo(t);s.current&&c(o);}catch{}},[i,t]);react.useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]);let f=react.useCallback(async()=>{if(t){e(true),n(null);try{let o=u.starred?await i.unstarRepo(t):await i.starRepo(t);s.current&&c({stars:o.stars,starred:o.starred,repo_id:t});}catch(o){s.current&&n(o.message);}finally{s.current&&e(false);}}},[i,t,u.starred]);return {...u,loading:g,error:r,toggle:f,refresh:a}}exports.estimateCost=F;exports.useLooopStats=_t;exports.useNetworkStats=$t;exports.usePaginatedRepos=lt;exports.useRackClient=d;exports.useRackRegister=dt;exports.useRackSession=gt;exports.useRepoPush=ct;exports.useRepoTree=st;exports.useRepos=tt;exports.useSkillStats=kt;exports.useStar=Bt;exports.useTensorStats=Pt;exports.useTrending=Mt;
|
package/dist/hooks/index.d.cts
CHANGED
|
@@ -74,6 +74,8 @@ interface UsePaginatedReposOptions {
|
|
|
74
74
|
pageSize?: number;
|
|
75
75
|
/** Filter by owner */
|
|
76
76
|
owner?: string;
|
|
77
|
+
/** Filter by category (skills, looops, tensors, imaginations, images) */
|
|
78
|
+
category?: string;
|
|
77
79
|
}
|
|
78
80
|
interface UsePaginatedReposReturn {
|
|
79
81
|
/** Current page of repos */
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -74,6 +74,8 @@ interface UsePaginatedReposOptions {
|
|
|
74
74
|
pageSize?: number;
|
|
75
75
|
/** Filter by owner */
|
|
76
76
|
owner?: string;
|
|
77
|
+
/** Filter by category (skills, looops, tensors, imaginations, images) */
|
|
78
|
+
category?: string;
|
|
77
79
|
}
|
|
78
80
|
interface UsePaginatedReposReturn {
|
|
79
81
|
/** Current page of repos */
|
package/dist/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {useMemo,useRef,useState,useCallback,useEffect}from'react';async function R(u,t,i,l){let c={"Content-Type":"application/json",...i?.headers};l&&(c.Authorization=`Bearer ${l}`);let p=await fetch(`${u}${t}`,{...i,headers:c});if(!p.ok){let e=`HTTP ${p.status}`;try{let r=await p.json();r.error&&(e=r.error);}catch{}throw new Error(e)}return p.json()}function w(u){let t=u.indexOf(":");return {mode:u.slice(0,t),cid:u.slice(t+1)}}function d(u){let t=u.apiBaseUrl,i=u.authorMid,l=u.ownerMid,c=u.apiKey,p=u.stacknetUrl||u.apiBaseUrl;return useMemo(()=>({async listRepos(e,r){let n=new URLSearchParams;(e||l)&&n.set("owner",e||l),r?.limit&&n.set("limit",String(r.limit)),r?.cursor&&n.set("cursor",r.cursor);let s=n.toString()?`?${n}`:"",a=await R(t,`/api/rack/repos${s}`,void 0,c);return {items:a.repos||[],pagination:a.pagination||{total:(a.repos||[]).length,limit:50,has_more:false,next_cursor:null}}},async initRepo(e){return R(t,"/api/rack/init",{method:"POST",body:JSON.stringify({...e,owner_mid:l})},c)},async push(e,r){return R(t,`/api/rack/${e}/push`,{method:"POST",body:JSON.stringify({...r,author_mid:i})},c)},async getTree(e,r="main"){let n=await R(t,`/api/rack/${e}/tree/${r}`,void 0,c);return {tree:n.tree,commit_cid:n.commit_cid}},async getBlob(e,r){return (await R(t,`/api/rack/${e}/blob/${r}`,void 0,c)).content},async getLog(e,r,n){let s=new URLSearchParams;r&&s.set("ref",r),n&&s.set("max_count",String(n));let a=s.toString()?`?${s}`:"";return (await R(t,`/api/rack/${e}/log${a}`,void 0,c)).commits||[]},async getBranches(e){return (await R(t,`/api/rack/${e}/branches`,void 0,c)).branches||[]},async createBranch(e,r,n){return R(t,`/api/rack/${e}/branch`,{method:"POST",body:JSON.stringify({branch_name:r,from_ref:n})},c)},async merge(e,r,n){return R(t,`/api/rack/${e}/merge`,{method:"POST",body:JSON.stringify({source_branch:r,target_branch:n})},c)},async getDiff(e,r,n){return (await R(t,`/api/rack/${e}/diff/${r}/${n}`,void 0,c)).diff?.entries||[]},async starRepo(e){return R(t,`/api/rack/${e}/star`,{method:"POST"},c)},async unstarRepo(e){return R(t,`/api/rack/${e}/star`,{method:"DELETE"},c)},async getStarInfo(e){return R(t,`/api/rack/${e}/stars`,void 0,c)},async getSkillStats(e){let r={meta:null,tokenCount:null,usageCount:null};try{let{tree:n}=await this.getTree(e,"main");if(!n?.entries)return r;if(n.entries["META.json"]){let f=w(n.entries["META.json"]).cid,o=await this.getBlob(e,f);r.meta=JSON.parse(o);}let s=0,a=Object.values(n.entries).map(async f=>{try{let o=w(f).cid,g=await this.getBlob(e,o);s+=g.length;}catch{}});await Promise.all(a),s>0&&(r.tokenCount=Math.ceil(s/4)),r.meta?.skill_id&&(r.usageCount=await this.getSkillUsageCount(r.meta.skill_id));}catch{}return r},async getSkillUsageCount(e){try{let r=await fetch(`${p}/v1/skills/${encodeURIComponent(e)}`);if(r.ok){let s=await r.json();return s.usage_count??s.usageCount??null}let n=await fetch(`${p}/v1/skills?scope=public`);if(n.ok){let a=((await n.json()).skills||[]).find(f=>f.name===e||f.id===e);if(a)return a.usage_count??a.usageCount??0}return 0}catch{return null}},async getTensorStats(e){let r={meta:null,sizeMB:null};try{let{tree:n}=await this.getTree(e,"main");if(!n?.entries)return r;if(n.entries["TENSOR_META.json"]){let s=w(n.entries["TENSOR_META.json"]).cid,a=await this.getBlob(e,s);r.meta=JSON.parse(a),r.sizeMB=r.meta?.tensor_size_mb??null;}}catch{}return r},async getLooopStats(e){let r={meta:null,fileCount:null};try{let{tree:n}=await this.getTree(e,"main");if(!n?.entries)return r;if(n.entries["LOOOP_META.json"]){let s=w(n.entries["LOOOP_META.json"]).cid,a=await this.getBlob(e,s);r.meta=JSON.parse(a);}r.fileCount=Object.keys(n.entries).length;}catch{}return r},async getNetworkStats(){try{return (await R(t,"/api/rack/stats",void 0,c)).stats||null}catch{return null}},async getTrending(e=5,r=1,n){try{let s=new URLSearchParams({limit:String(e),days:String(r)});n&&s.set("cursor",n);let a=await R(t,`/api/rack/trending?${s}`,void 0,c);return {items:a.trending||[],pagination:a.pagination||{total:(a.trending||[]).length,limit:e,has_more:!1,next_cursor:null}}}catch{return {items:[],pagination:{total:0,limit:e,has_more:false,next_cursor:null}}}}}),[t,i,l,c,p])}function Z(u){let t=d(u),i=useRef(t);i.current=t;let[l,c]=useState([]),[p,e]=useState(true),[r,n]=useState(null),s=useRef(true),a=useRef(null),f=useCallback(async()=>{a.current?.abort();let o=new AbortController;a.current=o;try{s.current&&(e(!0),n(null));let g=await i.current.listRepos();s.current&&!o.signal.aborted&&c(g.items);}catch(g){s.current&&!o.signal.aborted&&n(g instanceof Error?g.message:"Failed to load repos");}finally{s.current&&!o.signal.aborted&&e(false);}},[]);return useEffect(()=>(s.current=true,f(),()=>{s.current=false,a.current?.abort();}),[f]),{repos:l,loading:p,error:r,refresh:f}}function rt(u){return Object.entries(u).map(([t,i])=>{let l=i.indexOf(":"),c=l>0?i.slice(0,l):"100644",p=l>0?i.slice(l+1):i;return {path:t,mode:c,cid:p,isDir:c==="040000"}}).sort((t,i)=>t.isDir!==i.isDir?t.isDir?-1:1:t.path.localeCompare(i.path))}function nt(u,t,i="main"){let l=d(u),[c,p]=useState([]),[e,r]=useState(false),[n,s]=useState(null),a=useRef(true),f=useCallback(async()=>{if(t)try{a.current&&(r(!0),s(null));let{tree:g}=await l.getTree(t,i);a.current&&p(rt(g.entries));}catch(g){a.current&&s(g instanceof Error?g.message:"Failed to load tree");}finally{a.current&&r(false);}},[l,t,i]);useEffect(()=>(a.current=true,f(),()=>{a.current=false;}),[f]);let o=useCallback(async g=>{if(!t)throw new Error("No repo selected");return l.getBlob(t,g)},[l,t]);return {entries:c,loading:e,error:n,refresh:f,getFileContent:o}}function it(u){let t=d(u),[i,l]=useState(false),[c,p]=useState(null),e=useRef(true);return useEffect(()=>(e.current=true,()=>{e.current=false;}),[]),{push:useCallback(async(n,s,a,f)=>{try{return e.current&&(l(!0),p(null)),await t.push(n,{files:s,message:a,branch:f})}catch(o){let g=o instanceof Error?o.message:"Push failed";return e.current&&p(g),null}finally{e.current&&l(false);}},[t]),pushing:i,error:c}}function ut(u,t={}){let{pageSize:i=50,owner:l}=t,c=d(u),[p,e]=useState([]),[r,n]=useState(null),[s,a]=useState(false),[f,o]=useState(null),g=useRef(null),m=useRef(true),h=useCallback(async(W,G=false)=>{a(true),o(null);try{let S=await c.listRepos(l,{limit:i,cursor:W||void 0});m.current&&(e(Y=>G?[...Y,...S.items]:S.items),n(S.pagination),g.current=S.pagination.next_cursor);}catch(S){m.current&&o(S.message);}finally{m.current&&a(false);}},[c,l,i]),y=useCallback(async()=>{!g.current||s||await h(g.current,true);},[h,s]),k=useCallback(async()=>{g.current=null,await h(void 0,false);},[h]);return useEffect(()=>(m.current=true,h(),()=>{m.current=false;}),[h]),{repos:p,hasMore:r?.has_more??false,total:r?.total??0,loading:s,error:f,loadMore:y,reset:k,pagination:r}}var O="stacknet-rack-apikey";function ft(u){let t=u.stacknetUrl||u.apiBaseUrl,[i,l]=useState({authenticated:false}),[c,p]=useState(null),[e,r]=useState(false),n=useCallback(o=>({"Content-Type":"application/json",...o||u.apiKey?{Authorization:`Bearer ${o||u.apiKey}`}:{}}),[u.apiKey]),s=useCallback(async o=>{r(true);try{let g=await fetch(`${t}/health`,{headers:n(o)});if(!g.ok)throw new Error(`Authentication failed: ${g.status}`);let m={authenticated:!0,apiKey:o,permission:o.startsWith("gk_")?"write":"read"};l(m);try{localStorage.setItem(O,o);}catch{}return m}catch(g){throw l({authenticated:false}),g}finally{r(false);}},[t,n]),a=useCallback(()=>{l({authenticated:false}),p(null);try{localStorage.removeItem(O);}catch{}},[]),f=useCallback(async()=>{let o=i.apiKey||u.apiKey;if(!o)return null;try{let g=await fetch(`${t}/network/usage`,{headers:n(o)});if(!g.ok)return null;let m=await g.json(),h={planAllocation:m.plan_allocation??m.planAllocation??0,inferenceUsed:m.inference_used??m.inferenceUsed??0,ledgerSpent:m.ledger_spent??m.ledgerSpent??0,totalUsed:m.total_used??m.totalUsed??0,remaining:m.remaining??0,percent:m.percent??0,exceeded:m.exceeded??!1};return p(h),h}catch{return null}},[i.apiKey,u.apiKey,t,n]);return useEffect(()=>{let o=u.apiKey;if(o){l({authenticated:true,apiKey:o,permission:o.startsWith("gk_")?"write":"read"});return}try{let g=localStorage.getItem(O);g&&l({authenticated:!0,apiKey:g,permission:g.startsWith("gk_")?"write":"read"});}catch{}},[u.apiKey]),{session:i,budget:c,loading:e,login:s,logout:a,refreshBudget:f}}var gt=1e3,J=1e3,pt=1e3,z=100;function F(u,t){if(u==="skill"||u==="looop"){let c=u==="skill"?gt:pt,p=z+Math.ceil(t/4);return {type:u,totalBytes:t,totalMegabytes:t/1e6,baseCost:p,multiplier:c,registrationCostTokens:p*c}}let i=Math.ceil(t/1e6),l=z+i;return {type:u,totalBytes:t,totalMegabytes:i,baseCost:l,multiplier:J,registrationCostTokens:l*J}}function mt(u){let t=u.stacknetUrl||u.apiBaseUrl,i=u.apiKey,[l,c]=useState(false),[p,e]=useState(null),r=useCallback(()=>{if(!i)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${i}`}},[i]),n=useCallback(async f=>{c(true),e(null);try{let o=await fetch(`${t}/skills`,{method:"POST",headers:r(),body:JSON.stringify(f)});if(!o.ok){let g=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(g.error||`Registration failed: ${o.status}`)}return await o.json()}catch(o){throw e(o.message),o}finally{c(false);}},[t,r]),s=useCallback(async f=>{c(true),e(null);try{let o=await fetch(`${t}/tensors`,{method:"POST",headers:r(),body:JSON.stringify(f)});if(!o.ok){let g=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(g.error||`Registration failed: ${o.status}`)}return await o.json()}catch(o){throw e(o.message),o}finally{c(false);}},[t,r]),a=useCallback(async f=>{c(true),e(null);try{let o=await fetch(`${t}/looops`,{method:"POST",headers:r(),body:JSON.stringify(f)});if(!o.ok){let g=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(g.error||`Registration failed: ${o.status}`)}return await o.json()}catch(o){throw e(o.message),o}finally{c(false);}},[t,r]);return {registerSkill:n,registerTensor:s,registerLooop:a,estimateCost:F,registering:l,error:p}}function yt(u,t){let i=d(u),[l,c]=useState({meta:null,tokenCount:null,usageCount:null}),[p,e]=useState(false),[r,n]=useState(null),s=useRef(true),a=useCallback(async()=>{if(t){e(true),n(null);try{let f=await i.getSkillStats(t);s.current&&c(f);}catch(f){s.current&&n(f.message);}finally{s.current&&e(false);}}},[i,t]);return useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:l,loading:p,error:r,refresh:a}}function Pt(u,t){let i=d(u),[l,c]=useState({meta:null,sizeMB:null}),[p,e]=useState(false),[r,n]=useState(null),s=useRef(true),a=useCallback(async()=>{if(t){e(true),n(null);try{let f=await i.getTensorStats(t);s.current&&c(f);}catch(f){s.current&&n(f.message);}finally{s.current&&e(false);}}},[i,t]);return useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:l,loading:p,error:r,refresh:a}}function Et(u,t){let i=d(u),[l,c]=useState({meta:null,fileCount:null}),[p,e]=useState(false),[r,n]=useState(null),s=useRef(true),a=useCallback(async()=>{if(t){e(true),n(null);try{let f=await i.getLooopStats(t);s.current&&c(f);}catch(f){s.current&&n(f.message);}finally{s.current&&e(false);}}},[i,t]);return useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:l,loading:p,error:r,refresh:a}}function xt(u){let t=d(u),[i,l]=useState(null),[c,p]=useState(false),[e,r]=useState(null),n=useRef(true),s=useCallback(async()=>{p(true),r(null);try{let a=await t.getNetworkStats();n.current&&l(a);}catch(a){n.current&&r(a.message);}finally{n.current&&p(false);}},[t]);return useEffect(()=>(n.current=true,s(),()=>{n.current=false;}),[s]),{stats:i,loading:c,error:e,refresh:s}}function $t(u,t=5,i=1){let l=d(u),[c,p]=useState([]),[e,r]=useState(null),[n,s]=useState(false),[a,f]=useState(null),o=useRef(true),g=useRef(null),m=useCallback(async y=>{s(true),f(null),g.current=null;try{let k=await l.getTrending(t,y??i);o.current&&(p(k.items),r(k.pagination),g.current=k.pagination.next_cursor);}catch(k){o.current&&f(k.message);}finally{o.current&&s(false);}},[l,t,i]),h=useCallback(async()=>{if(!(!g.current||n)){s(true);try{let y=await l.getTrending(t,i,g.current);o.current&&(p(k=>[...k,...y.items]),r(y.pagination),g.current=y.pagination.next_cursor);}catch(y){o.current&&f(y.message);}finally{o.current&&s(false);}}},[l,t,i,n]);return useEffect(()=>(o.current=true,m(),()=>{o.current=false;}),[m]),{repos:c,hasMore:e?.has_more??false,total:e?.total??0,loading:n,error:a,refresh:m,loadMore:h}}function Nt(u,t){let i=d(u),[l,c]=useState({stars:0,starred:false,repo_id:t||""}),[p,e]=useState(false),[r,n]=useState(null),s=useRef(true),a=useCallback(async()=>{if(t)try{let o=await i.getStarInfo(t);s.current&&c(o);}catch{}},[i,t]);useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]);let f=useCallback(async()=>{if(t){e(true),n(null);try{let o=l.starred?await i.unstarRepo(t):await i.starRepo(t);s.current&&c({stars:o.stars,starred:o.starred,repo_id:t});}catch(o){s.current&&n(o.message);}finally{s.current&&e(false);}}},[i,t,l.starred]);return {...l,loading:p,error:r,toggle:f,refresh:a}}export{F as estimateCost,Et as useLooopStats,xt as useNetworkStats,ut as usePaginatedRepos,d as useRackClient,mt as useRackRegister,ft as useRackSession,it as useRepoPush,nt as useRepoTree,Z as useRepos,yt as useSkillStats,Nt as useStar,Pt as useTensorStats,$t as useTrending};
|
|
1
|
+
import {useMemo,useRef,useState,useCallback,useEffect}from'react';async function R(l,t,i,u){let c={"Content-Type":"application/json",...i?.headers};u&&(c.Authorization=`Bearer ${u}`);let g=await fetch(`${l}${t}`,{...i,headers:c});if(!g.ok){let e=`HTTP ${g.status}`;try{let r=await g.json();r.error&&(e=r.error);}catch{}throw new Error(e)}return g.json()}function w(l){let t=l.indexOf(":");return {mode:l.slice(0,t),cid:l.slice(t+1)}}function d(l){let t=l.apiBaseUrl,i=l.authorMid,u=l.ownerMid,c=l.apiKey,g=l.stacknetUrl||l.apiBaseUrl;return useMemo(()=>({async listRepos(e,r){let n=new URLSearchParams;(e||u)&&n.set("owner",e||u),r?.limit&&n.set("limit",String(r.limit)),r?.cursor&&n.set("cursor",r.cursor),r?.category&&n.set("category",r.category);let s=n.toString()?`?${n}`:"",a=await R(t,`/api/rack/repos${s}`,void 0,c);return {items:a.repos||[],pagination:a.pagination||{total:(a.repos||[]).length,limit:50,has_more:false,next_cursor:null}}},async initRepo(e){return R(t,"/api/rack/init",{method:"POST",body:JSON.stringify({...e,owner_mid:u})},c)},async push(e,r){return R(t,`/api/rack/${e}/push`,{method:"POST",body:JSON.stringify({...r,author_mid:i})},c)},async getTree(e,r="main"){let n=await R(t,`/api/rack/${e}/tree/${r}`,void 0,c);return {tree:n.tree,commit_cid:n.commit_cid}},async getBlob(e,r){return (await R(t,`/api/rack/${e}/blob/${r}`,void 0,c)).content},async getLog(e,r,n){let s=new URLSearchParams;r&&s.set("ref",r),n&&s.set("max_count",String(n));let a=s.toString()?`?${s}`:"";return (await R(t,`/api/rack/${e}/log${a}`,void 0,c)).commits||[]},async getBranches(e){return (await R(t,`/api/rack/${e}/branches`,void 0,c)).branches||[]},async createBranch(e,r,n){return R(t,`/api/rack/${e}/branch`,{method:"POST",body:JSON.stringify({branch_name:r,from_ref:n,author_mid:i})},c)},async merge(e,r,n){return R(t,`/api/rack/${e}/merge`,{method:"POST",body:JSON.stringify({source_branch:r,target_branch:n,author_mid:i})},c)},async getDiff(e,r,n){return (await R(t,`/api/rack/${e}/diff/${r}/${n}`,void 0,c)).diff?.entries||[]},async starRepo(e){return R(t,`/api/rack/${e}/star`,{method:"POST",body:JSON.stringify({owner_mid:u})},c)},async unstarRepo(e){return R(t,`/api/rack/${e}/star`,{method:"DELETE",body:JSON.stringify({owner_mid:u})},c)},async getStarInfo(e){return R(t,`/api/rack/${e}/stars`,void 0,c)},async getSkillStats(e){let r={meta:null,tokenCount:null,usageCount:null};try{let{tree:n}=await this.getTree(e,"main");if(!n?.entries)return r;if(n.entries["META.json"]){let f=w(n.entries["META.json"]).cid,o=await this.getBlob(e,f);r.meta=JSON.parse(o);}let s=0,a=Object.values(n.entries).map(async f=>{try{let o=w(f).cid,p=await this.getBlob(e,o);s+=p.length;}catch{}});await Promise.all(a),s>0&&(r.tokenCount=Math.ceil(s/4)),r.meta?.skill_id&&(r.usageCount=await this.getSkillUsageCount(r.meta.skill_id));}catch{}return r},async getSkillUsageCount(e){try{let r=await fetch(`${g}/v1/skills/${encodeURIComponent(e)}`);if(r.ok){let s=await r.json();return s.usage_count??s.usageCount??null}let n=await fetch(`${g}/v1/skills?scope=public`);if(n.ok){let a=((await n.json()).skills||[]).find(f=>f.name===e||f.id===e);if(a)return a.usage_count??a.usageCount??0}return 0}catch{return null}},async getTensorStats(e){let r={meta:null,sizeMB:null};try{let{tree:n}=await this.getTree(e,"main");if(!n?.entries)return r;if(n.entries["TENSOR_META.json"]){let s=w(n.entries["TENSOR_META.json"]).cid,a=await this.getBlob(e,s);r.meta=JSON.parse(a),r.sizeMB=r.meta?.tensor_size_mb??null;}}catch{}return r},async getLooopStats(e){let r={meta:null,fileCount:null};try{let{tree:n}=await this.getTree(e,"main");if(!n?.entries)return r;if(n.entries["META.json"]){let s=w(n.entries["META.json"]).cid,a=await this.getBlob(e,s);r.meta=JSON.parse(a);}r.fileCount=Object.keys(n.entries).length;}catch{}return r},async getNetworkStats(){try{return (await R(t,"/api/rack/stats",void 0,c)).stats||null}catch{return null}},async getTrending(e=5,r=1,n){try{let s=new URLSearchParams({limit:String(e),days:String(r)});n&&s.set("cursor",n);let a=await R(t,`/api/rack/trending?${s}`,void 0,c);return {items:a.trending||[],pagination:a.pagination||{total:(a.trending||[]).length,limit:e,has_more:!1,next_cursor:null}}}catch{return {items:[],pagination:{total:0,limit:e,has_more:false,next_cursor:null}}}}}),[t,i,u,c,g])}function tt(l){let t=d(l),i=useRef(t);i.current=t;let[u,c]=useState([]),[g,e]=useState(true),[r,n]=useState(null),s=useRef(true),a=useRef(null),f=useCallback(async()=>{a.current?.abort();let o=new AbortController;a.current=o;try{s.current&&(e(!0),n(null));let p=await i.current.listRepos();s.current&&!o.signal.aborted&&c(p.items);}catch(p){s.current&&!o.signal.aborted&&n(p instanceof Error?p.message:"Failed to load repos");}finally{s.current&&!o.signal.aborted&&e(false);}},[]);return useEffect(()=>(s.current=true,f(),()=>{s.current=false,a.current?.abort();}),[f]),{repos:u,loading:g,error:r,refresh:f}}function nt(l){return Object.entries(l).map(([t,i])=>{let u=i.indexOf(":"),c=u>0?i.slice(0,u):"100644",g=u>0?i.slice(u+1):i;return {path:t,mode:c,cid:g,isDir:c==="040000"}}).sort((t,i)=>t.isDir!==i.isDir?t.isDir?-1:1:t.path.localeCompare(i.path))}function st(l,t,i="main"){let u=d(l),[c,g]=useState([]),[e,r]=useState(false),[n,s]=useState(null),a=useRef(true),f=useCallback(async()=>{if(t)try{a.current&&(r(!0),s(null));let{tree:p}=await u.getTree(t,i);a.current&&g(nt(p.entries));}catch(p){a.current&&s(p instanceof Error?p.message:"Failed to load tree");}finally{a.current&&r(false);}},[u,t,i]);useEffect(()=>(a.current=true,f(),()=>{a.current=false;}),[f]);let o=useCallback(async p=>{if(!t)throw new Error("No repo selected");return u.getBlob(t,p)},[u,t]);return {entries:c,loading:e,error:n,refresh:f,getFileContent:o}}function ct(l){let t=d(l),[i,u]=useState(false),[c,g]=useState(null),e=useRef(true);return useEffect(()=>(e.current=true,()=>{e.current=false;}),[]),{push:useCallback(async(n,s,a,f)=>{try{return e.current&&(u(!0),g(null)),await t.push(n,{files:s,message:a,branch:f})}catch(o){let p=o instanceof Error?o.message:"Push failed";return e.current&&g(p),null}finally{e.current&&u(false);}},[t]),pushing:i,error:c}}function lt(l,t={}){let{pageSize:i=50,owner:u,category:c}=t,g=d(l),[e,r]=useState([]),[n,s]=useState(null),[a,f]=useState(false),[o,p]=useState(null),m=useRef(null),y=useRef(true),h=useCallback(async(G,Y=false)=>{f(true),p(null);try{let S=await g.listRepos(u,{limit:i,cursor:G||void 0,category:c});y.current&&(r(Q=>Y?[...Q,...S.items]:S.items),s(S.pagination),m.current=S.pagination.next_cursor);}catch(S){y.current&&p(S.message);}finally{y.current&&f(false);}},[g,u,i,c]),k=useCallback(async()=>{!m.current||a||await h(m.current,true);},[h,a]),W=useCallback(async()=>{m.current=null,await h(void 0,false);},[h]);return useEffect(()=>(y.current=true,h(),()=>{y.current=false;}),[h]),{repos:e,hasMore:n?.has_more??false,total:n?.total??0,loading:a,error:o,loadMore:k,reset:W,pagination:n}}var $="stacknet-rack-apikey";function gt(l){let t=l.stacknetUrl||l.apiBaseUrl,[i,u]=useState({authenticated:false}),[c,g]=useState(null),[e,r]=useState(false),n=useCallback(o=>({"Content-Type":"application/json",...o||l.apiKey?{Authorization:`Bearer ${o||l.apiKey}`}:{}}),[l.apiKey]),s=useCallback(async o=>{r(true);try{let p=await fetch(`${t}/health`,{headers:n(o)});if(!p.ok)throw new Error(`Authentication failed: ${p.status}`);let m={authenticated:!0,apiKey:o,permission:o.startsWith("gk_")?"write":"read"};u(m);try{localStorage.setItem($,o);}catch{}return m}catch(p){throw u({authenticated:false}),p}finally{r(false);}},[t,n]),a=useCallback(()=>{u({authenticated:false}),g(null);try{localStorage.removeItem($);}catch{}},[]),f=useCallback(async()=>{let o=i.apiKey||l.apiKey;if(!o)return null;try{let p=await fetch(`${t}/network/usage`,{headers:n(o)});if(!p.ok)return null;let m=await p.json(),y={planAllocation:m.plan_allocation??m.planAllocation??0,inferenceUsed:m.inference_used??m.inferenceUsed??0,ledgerSpent:m.ledger_spent??m.ledgerSpent??0,totalUsed:m.total_used??m.totalUsed??0,remaining:m.remaining??0,percent:m.percent??0,exceeded:m.exceeded??!1};return g(y),y}catch{return null}},[i.apiKey,l.apiKey,t,n]);return useEffect(()=>{let o=l.apiKey;if(o){u({authenticated:true,apiKey:o,permission:o.startsWith("gk_")?"write":"read"});return}try{let p=localStorage.getItem($);p&&u({authenticated:!0,apiKey:p,permission:p.startsWith("gk_")?"write":"read"});}catch{}},[l.apiKey]),{session:i,budget:c,loading:e,login:s,logout:a,refreshBudget:f}}var pt=1e3,D=1e3,mt=1e3,z=100;function F(l,t){if(l==="skill"||l==="looop"){let c=l==="skill"?pt:mt,g=z+Math.ceil(t/4);return {type:l,totalBytes:t,totalMegabytes:t/1e6,baseCost:g,multiplier:c,registrationCostTokens:g*c}}let i=Math.ceil(t/1e6),u=z+i;return {type:l,totalBytes:t,totalMegabytes:i,baseCost:u,multiplier:D,registrationCostTokens:u*D}}function dt(l){let t=l.stacknetUrl||l.apiBaseUrl,i=l.apiKey,[u,c]=useState(false),[g,e]=useState(null),r=useCallback(()=>{if(!i)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${i}`}},[i]),n=useCallback(async f=>{c(true),e(null);try{let o=await fetch(`${t}/skills`,{method:"POST",headers:r(),body:JSON.stringify(f)});if(!o.ok){let p=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(p.error||`Registration failed: ${o.status}`)}return await o.json()}catch(o){throw e(o.message),o}finally{c(false);}},[t,r]),s=useCallback(async f=>{c(true),e(null);try{let o=await fetch(`${t}/tensors`,{method:"POST",headers:r(),body:JSON.stringify(f)});if(!o.ok){let p=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(p.error||`Registration failed: ${o.status}`)}return await o.json()}catch(o){throw e(o.message),o}finally{c(false);}},[t,r]),a=useCallback(async f=>{c(true),e(null);try{let o=await fetch(`${t}/looops`,{method:"POST",headers:r(),body:JSON.stringify(f)});if(!o.ok){let p=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(p.error||`Registration failed: ${o.status}`)}return await o.json()}catch(o){throw e(o.message),o}finally{c(false);}},[t,r]);return {registerSkill:n,registerTensor:s,registerLooop:a,estimateCost:F,registering:u,error:g}}function kt(l,t){let i=d(l),[u,c]=useState({meta:null,tokenCount:null,usageCount:null}),[g,e]=useState(false),[r,n]=useState(null),s=useRef(true),a=useCallback(async()=>{if(t){e(true),n(null);try{let f=await i.getSkillStats(t);s.current&&c(f);}catch(f){s.current&&n(f.message);}finally{s.current&&e(false);}}},[i,t]);return useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:u,loading:g,error:r,refresh:a}}function Pt(l,t){let i=d(l),[u,c]=useState({meta:null,sizeMB:null}),[g,e]=useState(false),[r,n]=useState(null),s=useRef(true),a=useCallback(async()=>{if(t){e(true),n(null);try{let f=await i.getTensorStats(t);s.current&&c(f);}catch(f){s.current&&n(f.message);}finally{s.current&&e(false);}}},[i,t]);return useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:u,loading:g,error:r,refresh:a}}function _t(l,t){let i=d(l),[u,c]=useState({meta:null,fileCount:null}),[g,e]=useState(false),[r,n]=useState(null),s=useRef(true),a=useCallback(async()=>{if(t){e(true),n(null);try{let f=await i.getLooopStats(t);s.current&&c(f);}catch(f){s.current&&n(f.message);}finally{s.current&&e(false);}}},[i,t]);return useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:u,loading:g,error:r,refresh:a}}function $t(l){let t=d(l),[i,u]=useState(null),[c,g]=useState(false),[e,r]=useState(null),n=useRef(true),s=useCallback(async()=>{g(true),r(null);try{let a=await t.getNetworkStats();n.current&&u(a);}catch(a){n.current&&r(a.message);}finally{n.current&&g(false);}},[t]);return useEffect(()=>(n.current=true,s(),()=>{n.current=false;}),[s]),{stats:i,loading:c,error:e,refresh:s}}function Mt(l,t=5,i=1){let u=d(l),[c,g]=useState([]),[e,r]=useState(null),[n,s]=useState(false),[a,f]=useState(null),o=useRef(true),p=useRef(null),m=useCallback(async h=>{s(true),f(null),p.current=null;try{let k=await u.getTrending(t,h??i);o.current&&(g(k.items),r(k.pagination),p.current=k.pagination.next_cursor);}catch(k){o.current&&f(k.message);}finally{o.current&&s(false);}},[u,t,i]),y=useCallback(async()=>{if(!(!p.current||n)){s(true);try{let h=await u.getTrending(t,i,p.current);o.current&&(g(k=>[...k,...h.items]),r(h.pagination),p.current=h.pagination.next_cursor);}catch(h){o.current&&f(h.message);}finally{o.current&&s(false);}}},[u,t,i,n]);return useEffect(()=>(o.current=true,m(),()=>{o.current=false;}),[m]),{repos:c,hasMore:e?.has_more??false,total:e?.total??0,loading:n,error:a,refresh:m,loadMore:y}}function Bt(l,t){let i=d(l),[u,c]=useState({stars:0,starred:false,repo_id:t||""}),[g,e]=useState(false),[r,n]=useState(null),s=useRef(true),a=useCallback(async()=>{if(t)try{let o=await i.getStarInfo(t);s.current&&c(o);}catch{}},[i,t]);useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]);let f=useCallback(async()=>{if(t){e(true),n(null);try{let o=u.starred?await i.unstarRepo(t):await i.starRepo(t);s.current&&c({stars:o.stars,starred:o.starred,repo_id:t});}catch(o){s.current&&n(o.message);}finally{s.current&&e(false);}}},[i,t,u.starred]);return {...u,loading:g,error:r,toggle:f,refresh:a}}export{F as estimateCost,_t as useLooopStats,$t as useNetworkStats,lt as usePaginatedRepos,d as useRackClient,dt as useRackRegister,gt as useRackSession,ct as useRepoPush,st as useRepoTree,tt as useRepos,kt as useSkillStats,Bt as useStar,Pt as useTensorStats,Mt as useTrending};
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +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 S(r,e,a,n){let o={"Content-Type":"application/json",...a?.headers};n&&(o.Authorization=`Bearer ${n}`);let u=await fetch(`${r}${e}`,{...a,headers:o});if(!u.ok){let t=`HTTP ${u.status}`;try{let s=await u.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return u.json()}function $(r){let e=r.indexOf(":");return {mode:r.slice(0,e),cid:r.slice(e+1)}}function w(r){let e=r.apiBaseUrl,a=r.authorMid,n=r.ownerMid,o=r.apiKey,u=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 c=i.toString()?`?${i}`:"",f=await S(e,`/api/rack/repos${c}`,void 0,o);return {items:f.repos||[],pagination:f.pagination||{total:(f.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})},o)},async push(t,s){return S(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...s,author_mid:a})},o)},async getTree(t,s="main"){let i=await S(e,`/api/rack/${t}/tree/${s}`,void 0,o);return {tree:i.tree,commit_cid:i.commit_cid}},async getBlob(t,s){return (await S(e,`/api/rack/${t}/blob/${s}`,void 0,o)).content},async getLog(t,s,i){let c=new URLSearchParams;s&&c.set("ref",s),i&&c.set("max_count",String(i));let f=c.toString()?`?${c}`:"";return (await S(e,`/api/rack/${t}/log${f}`,void 0,o)).commits||[]},async getBranches(t){return (await S(e,`/api/rack/${t}/branches`,void 0,o)).branches||[]},async createBranch(t,s,i){return S(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:s,from_ref:i})},o)},async merge(t,s,i){return S(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:s,target_branch:i})},o)},async getDiff(t,s,i){return (await S(e,`/api/rack/${t}/diff/${s}/${i}`,void 0,o)).diff?.entries||[]},async starRepo(t){return S(e,`/api/rack/${t}/star`,{method:"POST"},o)},async unstarRepo(t){return S(e,`/api/rack/${t}/star`,{method:"DELETE"},o)},async getStarInfo(t){return S(e,`/api/rack/${t}/stars`,void 0,o)},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 g=$(i.entries["META.json"]).cid,l=await this.getBlob(t,g);s.meta=JSON.parse(l);}let c=0,f=Object.values(i.entries).map(async g=>{try{let l=$(g).cid,m=await this.getBlob(t,l);c+=m.length;}catch{}});await Promise.all(f),c>0&&(s.tokenCount=Math.ceil(c/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(`${u}/v1/skills/${encodeURIComponent(t)}`);if(s.ok){let c=await s.json();return c.usage_count??c.usageCount??null}let i=await fetch(`${u}/v1/skills?scope=public`);if(i.ok){let f=((await i.json()).skills||[]).find(g=>g.name===t||g.id===t);if(f)return f.usage_count??f.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 c=$(i.entries["TENSOR_META.json"]).cid,f=await this.getBlob(t,c);s.meta=JSON.parse(f),s.sizeMB=s.meta?.tensor_size_mb??null;}}catch{}return s},async getLooopStats(t){let s={meta:null,fileCount:null};try{let{tree:i}=await this.getTree(t,"main");if(!i?.entries)return s;if(i.entries["LOOOP_META.json"]){let c=$(i.entries["LOOOP_META.json"]).cid,f=await this.getBlob(t,c);s.meta=JSON.parse(f);}s.fileCount=Object.keys(i.entries).length;}catch{}return s},async getNetworkStats(){try{return (await S(e,"/api/rack/stats",void 0,o)).stats||null}catch{return null}},async getTrending(t=5,s=1,i){try{let c=new URLSearchParams({limit:String(t),days:String(s)});i&&c.set("cursor",i);let f=await S(e,`/api/rack/trending?${c}`,void 0,o);return {items:f.trending||[],pagination:f.pagination||{total:(f.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,a,n,o,u])}function Be(r){let e=w(r),a=react.useRef(e);a.current=e;let[n,o]=react.useState([]),[u,t]=react.useState(true),[s,i]=react.useState(null),c=react.useRef(true),f=react.useRef(null),g=react.useCallback(async()=>{f.current?.abort();let l=new AbortController;f.current=l;try{c.current&&(t(!0),i(null));let m=await a.current.listRepos();c.current&&!l.signal.aborted&&o(m.items);}catch(m){c.current&&!l.signal.aborted&&i(m instanceof Error?m.message:"Failed to load repos");}finally{c.current&&!l.signal.aborted&&t(false);}},[]);return react.useEffect(()=>(c.current=true,g(),()=>{c.current=false,f.current?.abort();}),[g]),{repos:n,loading:u,error:s,refresh:g}}function Oe(r){return Object.entries(r).map(([e,a])=>{let n=a.indexOf(":"),o=n>0?a.slice(0,n):"100644",u=n>0?a.slice(n+1):a;return {path:e,mode:o,cid:u,isDir:o==="040000"}}).sort((e,a)=>e.isDir!==a.isDir?e.isDir?-1:1:e.path.localeCompare(a.path))}function H(r,e,a="main"){let n=w(r),[o,u]=react.useState([]),[t,s]=react.useState(false),[i,c]=react.useState(null),f=react.useRef(true),g=react.useCallback(async()=>{if(e)try{f.current&&(s(!0),c(null));let{tree:m}=await n.getTree(e,a);f.current&&u(Oe(m.entries));}catch(m){f.current&&c(m instanceof Error?m.message:"Failed to load tree");}finally{f.current&&s(false);}},[n,e,a]);react.useEffect(()=>(f.current=true,g(),()=>{f.current=false;}),[g]);let l=react.useCallback(async m=>{if(!e)throw new Error("No repo selected");return n.getBlob(e,m)},[n,e]);return {entries:o,loading:t,error:i,refresh:g,getFileContent:l}}function He(r){let e=w(r),[a,n]=react.useState(false),[o,u]=react.useState(null),t=react.useRef(true);return react.useEffect(()=>(t.current=true,()=>{t.current=false;}),[]),{push:react.useCallback(async(i,c,f,g)=>{try{return t.current&&(n(!0),u(null)),await e.push(i,{files:c,message:f,branch:g})}catch(l){let m=l instanceof Error?l.message:"Push failed";return t.current&&u(m),null}finally{t.current&&n(false);}},[e]),pushing:a,error:o}}function J(r,e={}){let{pageSize:a=50,owner:n}=e,o=w(r),[u,t]=react.useState([]),[s,i]=react.useState(null),[c,f]=react.useState(false),[g,l]=react.useState(null),m=react.useRef(null),p=react.useRef(true),R=react.useCallback(async(v,E=false)=>{f(true),l(null);try{let N=await o.listRepos(n,{limit:a,cursor:v||void 0});p.current&&(t(_=>E?[..._,...N.items]:N.items),i(N.pagination),m.current=N.pagination.next_cursor);}catch(N){p.current&&l(N.message);}finally{p.current&&f(false);}},[o,n,a]),k=react.useCallback(async()=>{!m.current||c||await R(m.current,true);},[R,c]),h=react.useCallback(async()=>{m.current=null,await R(void 0,false);},[R]);return react.useEffect(()=>(p.current=true,R(),()=>{p.current=false;}),[R]),{repos:u,hasMore:s?.has_more??false,total:s?.total??0,loading:c,error:g,loadMore:k,reset:h,pagination:s}}var V="stacknet-rack-apikey";function We(r){let e=r.stacknetUrl||r.apiBaseUrl,[a,n]=react.useState({authenticated:false}),[o,u]=react.useState(null),[t,s]=react.useState(false),i=react.useCallback(l=>({"Content-Type":"application/json",...l||r.apiKey?{Authorization:`Bearer ${l||r.apiKey}`}:{}}),[r.apiKey]),c=react.useCallback(async l=>{s(true);try{let m=await fetch(`${e}/health`,{headers:i(l)});if(!m.ok)throw new Error(`Authentication failed: ${m.status}`);let p={authenticated:!0,apiKey:l,permission:l.startsWith("gk_")?"write":"read"};n(p);try{localStorage.setItem(V,l);}catch{}return p}catch(m){throw n({authenticated:false}),m}finally{s(false);}},[e,i]),f=react.useCallback(()=>{n({authenticated:false}),u(null);try{localStorage.removeItem(V);}catch{}},[]),g=react.useCallback(async()=>{let l=a.apiKey||r.apiKey;if(!l)return null;try{let m=await fetch(`${e}/network/usage`,{headers:i(l)});if(!m.ok)return null;let p=await m.json(),R={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 u(R),R}catch{return null}},[a.apiKey,r.apiKey,e,i]);return react.useEffect(()=>{let l=r.apiKey;if(l){n({authenticated:true,apiKey:l,permission:l.startsWith("gk_")?"write":"read"});return}try{let m=localStorage.getItem(V);m&&n({authenticated:!0,apiKey:m,permission:m.startsWith("gk_")?"write":"read"});}catch{}},[r.apiKey]),{session:a,budget:o,loading:t,login:c,logout:f,refreshBudget:g}}var Ve=1e3,me=1e3,Ze=1e3,ge=100;function pe(r,e){if(r==="skill"||r==="looop"){let o=r==="skill"?Ve:Ze,u=ge+Math.ceil(e/4);return {type:r,totalBytes:e,totalMegabytes:e/1e6,baseCost:u,multiplier:o,registrationCostTokens:u*o}}let a=Math.ceil(e/1e6),n=ge+a;return {type:r,totalBytes:e,totalMegabytes:a,baseCost:n,multiplier:me,registrationCostTokens:n*me}}function qe(r){let e=r.stacknetUrl||r.apiBaseUrl,a=r.apiKey,[n,o]=react.useState(false),[u,t]=react.useState(null),s=react.useCallback(()=>{if(!a)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${a}`}},[a]),i=react.useCallback(async g=>{o(true),t(null);try{let l=await fetch(`${e}/skills`,{method:"POST",headers:s(),body:JSON.stringify(g)});if(!l.ok){let m=await l.json().catch(()=>({error:`HTTP ${l.status}`}));throw new Error(m.error||`Registration failed: ${l.status}`)}return await l.json()}catch(l){throw t(l.message),l}finally{o(false);}},[e,s]),c=react.useCallback(async g=>{o(true),t(null);try{let l=await fetch(`${e}/tensors`,{method:"POST",headers:s(),body:JSON.stringify(g)});if(!l.ok){let m=await l.json().catch(()=>({error:`HTTP ${l.status}`}));throw new Error(m.error||`Registration failed: ${l.status}`)}return await l.json()}catch(l){throw t(l.message),l}finally{o(false);}},[e,s]),f=react.useCallback(async g=>{o(true),t(null);try{let l=await fetch(`${e}/looops`,{method:"POST",headers:s(),body:JSON.stringify(g)});if(!l.ok){let m=await l.json().catch(()=>({error:`HTTP ${l.status}`}));throw new Error(m.error||`Registration failed: ${l.status}`)}return await l.json()}catch(l){throw t(l.message),l}finally{o(false);}},[e,s]);return {registerSkill:i,registerTensor:c,registerLooop:f,estimateCost:pe,registering:n,error:u}}function Xe(r,e){let a=w(r),[n,o]=react.useState({meta:null,tokenCount:null,usageCount:null}),[u,t]=react.useState(false),[s,i]=react.useState(null),c=react.useRef(true),f=react.useCallback(async()=>{if(e){t(true),i(null);try{let g=await a.getSkillStats(e);c.current&&o(g);}catch(g){c.current&&i(g.message);}finally{c.current&&t(false);}}},[a,e]);return react.useEffect(()=>(c.current=true,f(),()=>{c.current=false;}),[f]),{stats:n,loading:u,error:s,refresh:f}}function nt(r,e){let a=w(r),[n,o]=react.useState({meta:null,sizeMB:null}),[u,t]=react.useState(false),[s,i]=react.useState(null),c=react.useRef(true),f=react.useCallback(async()=>{if(e){t(true),i(null);try{let g=await a.getTensorStats(e);c.current&&o(g);}catch(g){c.current&&i(g.message);}finally{c.current&&t(false);}}},[a,e]);return react.useEffect(()=>(c.current=true,f(),()=>{c.current=false;}),[f]),{stats:n,loading:u,error:s,refresh:f}}function it(r,e){let a=w(r),[n,o]=react.useState({meta:null,fileCount:null}),[u,t]=react.useState(false),[s,i]=react.useState(null),c=react.useRef(true),f=react.useCallback(async()=>{if(e){t(true),i(null);try{let g=await a.getLooopStats(e);c.current&&o(g);}catch(g){c.current&&i(g.message);}finally{c.current&&t(false);}}},[a,e]);return react.useEffect(()=>(c.current=true,f(),()=>{c.current=false;}),[f]),{stats:n,loading:u,error:s,refresh:f}}function dt(r){let e=w(r),[a,n]=react.useState(null),[o,u]=react.useState(false),[t,s]=react.useState(null),i=react.useRef(true),c=react.useCallback(async()=>{u(true),s(null);try{let f=await e.getNetworkStats();i.current&&n(f);}catch(f){i.current&&s(f.message);}finally{i.current&&u(false);}},[e]);return react.useEffect(()=>(i.current=true,c(),()=>{i.current=false;}),[c]),{stats:a,loading:o,error:t,refresh:c}}function mt(r,e=5,a=1){let n=w(r),[o,u]=react.useState([]),[t,s]=react.useState(null),[i,c]=react.useState(false),[f,g]=react.useState(null),l=react.useRef(true),m=react.useRef(null),p=react.useCallback(async k=>{c(true),g(null),m.current=null;try{let h=await n.getTrending(e,k??a);l.current&&(u(h.items),s(h.pagination),m.current=h.pagination.next_cursor);}catch(h){l.current&&g(h.message);}finally{l.current&&c(false);}},[n,e,a]),R=react.useCallback(async()=>{if(!(!m.current||i)){c(true);try{let k=await n.getTrending(e,a,m.current);l.current&&(u(h=>[...h,...k.items]),s(k.pagination),m.current=k.pagination.next_cursor);}catch(k){l.current&&g(k.message);}finally{l.current&&c(false);}}},[n,e,a,i]);return react.useEffect(()=>(l.current=true,p(),()=>{l.current=false;}),[p]),{repos:o,hasMore:t?.has_more??false,total:t?.total??0,loading:i,error:f,refresh:p,loadMore:R}}function ht(r,e){let a=w(r),[n,o]=react.useState({stars:0,starred:false,repo_id:e||""}),[u,t]=react.useState(false),[s,i]=react.useState(null),c=react.useRef(true),f=react.useCallback(async()=>{if(e)try{let l=await a.getStarInfo(e);c.current&&o(l);}catch{}},[a,e]);react.useEffect(()=>(c.current=true,f(),()=>{c.current=false;}),[f]);let g=react.useCallback(async()=>{if(e){t(true),i(null);try{let l=n.starred?await a.unstarRepo(e):await a.starRepo(e);c.current&&o({stars:l.stars,starred:l.starred,repo_id:e});}catch(l){c.current&&i(l.message);}finally{c.current&&t(false);}}},[a,e,n.starred]);return {...n,loading:u,error:s,toggle:g,refresh:f}}function T(...r){return tailwindMerge.twMerge(clsx.clsx(r))}var wt=/^(https?:\/\/|mailto:|\/[^/])/i;function xt(r){let e=r.trim();return wt.test(e)?e:null}function A(r){let e=[],a=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,n=0,o,u=0;for(;(o=a.exec(r))!==null;){o.index>n&&e.push(r.slice(n,o.index));let t=`i${u++}`;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 s=xt(o[10]);s?e.push(jsxRuntime.jsx("a",{href:s,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:o[9]},t)):e.push(o[9]);}n=o.index+o[0].length;}return n<r.length&&e.push(r.slice(n)),e.length>0?e:[r]}function Rt(r){let e=r.split(`
|
|
2
|
-
`),
|
|
3
|
-
`),lang:s||void 0}),n++;continue}if(/^\s*[-*+]\s/.test(
|
|
4
|
-
`),
|
|
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 $(r){let e=r.indexOf(":");return {mode:r.slice(0,e),cid:r.slice(e+1)}}function x(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),s?.category&&i.set("category",s.category);let u=i.toString()?`?${i}`:"",f=await S(e,`/api/rack/repos${u}`,void 0,a);return {items:f.repos||[],pagination:f.pagination||{total:(f.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 f=u.toString()?`?${u}`:"";return (await S(e,`/api/rack/${t}/log${f}`,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,author_mid:o})},a)},async merge(t,s,i){return S(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:s,target_branch:i,author_mid:o})},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",body:JSON.stringify({owner_mid:n})},a)},async unstarRepo(t){return S(e,`/api/rack/${t}/star`,{method:"DELETE",body:JSON.stringify({owner_mid:n})},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 g=$(i.entries["META.json"]).cid,l=await this.getBlob(t,g);s.meta=JSON.parse(l);}let u=0,f=Object.values(i.entries).map(async g=>{try{let l=$(g).cid,m=await this.getBlob(t,l);u+=m.length;}catch{}});await Promise.all(f),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 f=((await i.json()).skills||[]).find(g=>g.name===t||g.id===t);if(f)return f.usage_count??f.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=$(i.entries["TENSOR_META.json"]).cid,f=await this.getBlob(t,u);s.meta=JSON.parse(f),s.sizeMB=s.meta?.tensor_size_mb??null;}}catch{}return s},async getLooopStats(t){let s={meta:null,fileCount:null};try{let{tree:i}=await this.getTree(t,"main");if(!i?.entries)return s;if(i.entries["META.json"]){let u=$(i.entries["META.json"]).cid,f=await this.getBlob(t,u);s.meta=JSON.parse(f);}s.fileCount=Object.keys(i.entries).length;}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 f=await S(e,`/api/rack/trending?${u}`,void 0,a);return {items:f.trending||[],pagination:f.pagination||{total:(f.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=x(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),f=react.useRef(null),g=react.useCallback(async()=>{f.current?.abort();let l=new AbortController;f.current=l;try{u.current&&(t(!0),i(null));let m=await o.current.listRepos();u.current&&!l.signal.aborted&&a(m.items);}catch(m){u.current&&!l.signal.aborted&&i(m instanceof Error?m.message:"Failed to load repos");}finally{u.current&&!l.signal.aborted&&t(false);}},[]);return react.useEffect(()=>(u.current=true,g(),()=>{u.current=false,f.current?.abort();}),[g]),{repos:n,loading:c,error:s,refresh:g}}function je(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 K(r,e,o="main"){let n=x(r),[a,c]=react.useState([]),[t,s]=react.useState(false),[i,u]=react.useState(null),f=react.useRef(true),g=react.useCallback(async()=>{if(e)try{f.current&&(s(!0),u(null));let{tree:m}=await n.getTree(e,o);f.current&&c(je(m.entries));}catch(m){f.current&&u(m instanceof Error?m.message:"Failed to load tree");}finally{f.current&&s(false);}},[n,e,o]);react.useEffect(()=>(f.current=true,g(),()=>{f.current=false;}),[g]);let l=react.useCallback(async m=>{if(!e)throw new Error("No repo selected");return n.getBlob(e,m)},[n,e]);return {entries:a,loading:t,error:i,refresh:g,getFileContent:l}}function Je(r){let e=x(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,f,g)=>{try{return t.current&&(n(!0),c(null)),await e.push(i,{files:u,message:f,branch:g})}catch(l){let m=l instanceof Error?l.message:"Push failed";return t.current&&c(m),null}finally{t.current&&n(false);}},[e]),pushing:o,error:a}}function V(r,e={}){let{pageSize:o=50,owner:n,category:a}=e,c=x(r),[t,s]=react.useState([]),[i,u]=react.useState(null),[f,g]=react.useState(false),[l,m]=react.useState(null),h=react.useRef(null),b=react.useRef(true),k=react.useCallback(async(_,P=false)=>{g(true),m(null);try{let N=await c.listRepos(n,{limit:o,cursor:_||void 0,category:a});b.current&&(s(j=>P?[...j,...N.items]:N.items),u(N.pagination),h.current=N.pagination.next_cursor);}catch(N){b.current&&m(N.message);}finally{b.current&&g(false);}},[c,n,o,a]),p=react.useCallback(async()=>{!h.current||f||await k(h.current,true);},[k,f]),v=react.useCallback(async()=>{h.current=null,await k(void 0,false);},[k]);return react.useEffect(()=>(b.current=true,k(),()=>{b.current=false;}),[k]),{repos:t,hasMore:i?.has_more??false,total:i?.total??0,loading:f,error:l,loadMore:p,reset:v,pagination:i}}var q="stacknet-rack-apikey";function Ve(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(l=>({"Content-Type":"application/json",...l||r.apiKey?{Authorization:`Bearer ${l||r.apiKey}`}:{}}),[r.apiKey]),u=react.useCallback(async l=>{s(true);try{let m=await fetch(`${e}/health`,{headers:i(l)});if(!m.ok)throw new Error(`Authentication failed: ${m.status}`);let h={authenticated:!0,apiKey:l,permission:l.startsWith("gk_")?"write":"read"};n(h);try{localStorage.setItem(q,l);}catch{}return h}catch(m){throw n({authenticated:false}),m}finally{s(false);}},[e,i]),f=react.useCallback(()=>{n({authenticated:false}),c(null);try{localStorage.removeItem(q);}catch{}},[]),g=react.useCallback(async()=>{let l=o.apiKey||r.apiKey;if(!l)return null;try{let m=await fetch(`${e}/network/usage`,{headers:i(l)});if(!m.ok)return null;let h=await m.json(),b={planAllocation:h.plan_allocation??h.planAllocation??0,inferenceUsed:h.inference_used??h.inferenceUsed??0,ledgerSpent:h.ledger_spent??h.ledgerSpent??0,totalUsed:h.total_used??h.totalUsed??0,remaining:h.remaining??0,percent:h.percent??0,exceeded:h.exceeded??!1};return c(b),b}catch{return null}},[o.apiKey,r.apiKey,e,i]);return react.useEffect(()=>{let l=r.apiKey;if(l){n({authenticated:true,apiKey:l,permission:l.startsWith("gk_")?"write":"read"});return}try{let m=localStorage.getItem(q);m&&n({authenticated:!0,apiKey:m,permission:m.startsWith("gk_")?"write":"read"});}catch{}},[r.apiKey]),{session:o,budget:a,loading:t,login:u,logout:f,refreshBudget:g}}var Ze=1e3,pe=1e3,qe=1e3,he=100;function ye(r,e){if(r==="skill"||r==="looop"){let a=r==="skill"?Ze:qe,c=he+Math.ceil(e/4);return {type:r,totalBytes:e,totalMegabytes:e/1e6,baseCost:c,multiplier:a,registrationCostTokens:c*a}}let o=Math.ceil(e/1e6),n=he+o;return {type:r,totalBytes:e,totalMegabytes:o,baseCost:n,multiplier:pe,registrationCostTokens:n*pe}}function Ge(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 g=>{a(true),t(null);try{let l=await fetch(`${e}/skills`,{method:"POST",headers:s(),body:JSON.stringify(g)});if(!l.ok){let m=await l.json().catch(()=>({error:`HTTP ${l.status}`}));throw new Error(m.error||`Registration failed: ${l.status}`)}return await l.json()}catch(l){throw t(l.message),l}finally{a(false);}},[e,s]),u=react.useCallback(async g=>{a(true),t(null);try{let l=await fetch(`${e}/tensors`,{method:"POST",headers:s(),body:JSON.stringify(g)});if(!l.ok){let m=await l.json().catch(()=>({error:`HTTP ${l.status}`}));throw new Error(m.error||`Registration failed: ${l.status}`)}return await l.json()}catch(l){throw t(l.message),l}finally{a(false);}},[e,s]),f=react.useCallback(async g=>{a(true),t(null);try{let l=await fetch(`${e}/looops`,{method:"POST",headers:s(),body:JSON.stringify(g)});if(!l.ok){let m=await l.json().catch(()=>({error:`HTTP ${l.status}`}));throw new Error(m.error||`Registration failed: ${l.status}`)}return await l.json()}catch(l){throw t(l.message),l}finally{a(false);}},[e,s]);return {registerSkill:i,registerTensor:u,registerLooop:f,estimateCost:ye,registering:n,error:c}}function et(r,e){let o=x(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),f=react.useCallback(async()=>{if(e){t(true),i(null);try{let g=await o.getSkillStats(e);u.current&&a(g);}catch(g){u.current&&i(g.message);}finally{u.current&&t(false);}}},[o,e]);return react.useEffect(()=>(u.current=true,f(),()=>{u.current=false;}),[f]),{stats:n,loading:c,error:s,refresh:f}}function st(r,e){let o=x(r),[n,a]=react.useState({meta:null,sizeMB:null}),[c,t]=react.useState(false),[s,i]=react.useState(null),u=react.useRef(true),f=react.useCallback(async()=>{if(e){t(true),i(null);try{let g=await o.getTensorStats(e);u.current&&a(g);}catch(g){u.current&&i(g.message);}finally{u.current&&t(false);}}},[o,e]);return react.useEffect(()=>(u.current=true,f(),()=>{u.current=false;}),[f]),{stats:n,loading:c,error:s,refresh:f}}function lt(r,e){let o=x(r),[n,a]=react.useState({meta:null,fileCount:null}),[c,t]=react.useState(false),[s,i]=react.useState(null),u=react.useRef(true),f=react.useCallback(async()=>{if(e){t(true),i(null);try{let g=await o.getLooopStats(e);u.current&&a(g);}catch(g){u.current&&i(g.message);}finally{u.current&&t(false);}}},[o,e]);return react.useEffect(()=>(u.current=true,f(),()=>{u.current=false;}),[f]),{stats:n,loading:c,error:s,refresh:f}}function ft(r){let e=x(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 f=await e.getNetworkStats();i.current&&n(f);}catch(f){i.current&&s(f.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 gt(r,e=5,o=1){let n=x(r),[a,c]=react.useState([]),[t,s]=react.useState(null),[i,u]=react.useState(false),[f,g]=react.useState(null),l=react.useRef(true),m=react.useRef(null),h=react.useCallback(async k=>{u(true),g(null),m.current=null;try{let p=await n.getTrending(e,k??o);l.current&&(c(p.items),s(p.pagination),m.current=p.pagination.next_cursor);}catch(p){l.current&&g(p.message);}finally{l.current&&u(false);}},[n,e,o]),b=react.useCallback(async()=>{if(!(!m.current||i)){u(true);try{let k=await n.getTrending(e,o,m.current);l.current&&(c(p=>[...p,...k.items]),s(k.pagination),m.current=k.pagination.next_cursor);}catch(k){l.current&&g(k.message);}finally{l.current&&u(false);}}},[n,e,o,i]);return react.useEffect(()=>(l.current=true,h(),()=>{l.current=false;}),[h]),{repos:a,hasMore:t?.has_more??false,total:t?.total??0,loading:i,error:f,refresh:h,loadMore:b}}function yt(r,e){let o=x(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),f=react.useCallback(async()=>{if(e)try{let l=await o.getStarInfo(e);u.current&&a(l);}catch{}},[o,e]);react.useEffect(()=>(u.current=true,f(),()=>{u.current=false;}),[f]);let g=react.useCallback(async()=>{if(e){t(true),i(null);try{let l=n.starred?await o.unstarRepo(e):await o.starRepo(e);u.current&&a({stars:l.stars,starred:l.starred,repo_id:e});}catch(l){u.current&&i(l.message);}finally{u.current&&t(false);}}},[o,e,n.starred]);return {...n,loading:c,error:s,toggle:g,refresh:f}}function T(...r){return tailwindMerge.twMerge(clsx.clsx(r))}var xt=/^(https?:\/\/|mailto:|\/[^/])/i;function Rt(r){let e=r.trim();return xt.test(e)?e:null}function O(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=Rt(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 bt(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 vt={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 St(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",vt[o]),children:O(r.content||"")},`b${e}`)}case "paragraph":return jsxRuntime.jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:O(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:O(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:O(o)},`li${e}-${n}`))},`b${e}`);default:return null}}function te({content:r,className:e}){let o=bt(r);return jsxRuntime.jsx("div",{className:T("text-sm",e),children:o.map((n,a)=>St(n,a))})}function Se({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 Re({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 re({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 Ce({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 Tt(){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 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:"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 Et(){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 Ne(){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 Te({onClose:r,children:e,title:o}){let n=Ne(),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(re,{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(re,{size:20})})]}),e]})]})}function _t(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 Lt({onClose:r,onCreated:e,config:o}){let[n,a]=react.useState(""),[c,t]=react.useState(""),[s,i]=react.useState(""),[u,f]=react.useState(false),[g,l]=react.useState(null),[m,h]=react.useState(false),b=p=>{if(i(p),!n.trim()&&!c.trim()&&p.trim().length>10){let v=_t(p);v&&(a(v.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")),t(v.description),h(true));}};return jsxRuntime.jsx(Te,{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=>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:c,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=>b(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"})]}),g&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:g}),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()){f(true),l(null);try{let p=o.apiBaseUrl||"",v=m?s.trim():`# ${n.trim()}
|
|
5
5
|
|
|
6
|
-
${
|
|
6
|
+
${c.trim()}
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
-
${s.trim()}`,E=await fetch(`${h}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n.trim(),description:u.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){l(h instanceof Error?h.message:"Failed to create skill");}finally{f(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 Lt({onClose:r,onCreated:e,config:a}){let n=react.useRef(null),[o,u]=react.useState(false),[t,s]=react.useState(false),[i,c]=react.useState(null),f=async l=>{s(true),c(null);try{let m=await l.text(),p=a.apiBaseUrl||"",R=l.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:R,skill_md:m,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(m){c(m instanceof Error?m.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:l=>{l.preventDefault(),u(true);},onDragLeave:()=>u(false),onDrop:l=>{l.preventDefault(),u(false);let m=l.dataTransfer.files[0];m&&f(m);},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",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(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:l=>{let m=l.target.files?.[0];m&&f(m);}}),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 Mt({onClose:r,onSelect:e}){let a=Se(),n=react.useRef(null),o=react.useRef(r);o.current=r,react.useEffect(()=>{if(a)return;let t=s=>{n.current&&s.target instanceof Node&&!n.current.contains(s.target)&&o.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[a]);let u=[{id:"create-with-geoff",icon:jsxRuntime.jsx(Nt,{}),label:"Create with Geoff"},{id:"write",icon:jsxRuntime.jsx(Tt,{}),label:"Write skill instructions"},{id:"upload",icon:jsxRuntime.jsx(Pt,{}),label:"Upload a skill"}];return a?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"}),u.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:u.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 $t({entry:r,selected:e,onSelect:a,depth:n=0}){return jsxRuntime.jsxs("button",{onClick:()=>a(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(be,{className:"ml-auto text-muted-foreground"})]})}function It({repo:r,selected:e,expanded:a,onSelect:n,onToggle:o,children:u}){return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>{n(),o();},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(be,{open:a}),jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4 shrink-0"}),jsxRuntime.jsx("span",{className:"truncate",children:r.name})]}),a&&u]})}function zt({entry:r,content:e,loading:a,repoName:n}){let[o,u]=react.useState(false),t=react.useRef(null);react.useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[s,i]=react.useState(false),c=async()=>{if(e)try{await navigator.clipboard.writeText(e),u(!0),i(!1),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>u(!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(a)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 f=r.path.split("/").pop()||r.path,g=/\.(md|mdx)$/i.test(f);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:f}),jsxRuntime.jsx("button",{onClick:c,"aria-label":"Copy file content",className:T("rounded p-1 transition-colors",o?"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:g?jsxRuntime.jsx(X,{content:e||""}):jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function Bt({config:r,category:e,className:a,style:n}){let{repos:o,loading:u,error:t,hasMore:s,loadMore:i,reset:c}=J(r,{pageSize:50}),[f,g]=react.useState(null),[l,m]=react.useState(null),[p,R]=react.useState(null),[k,h]=react.useState(null),[v,E]=react.useState(false),[N,_]=react.useState(""),[Te,ne]=react.useState(false),[se,oe]=react.useState(false),[ae,O]=react.useState(null),Pe=o.find(b=>b.repo_id===f),{entries:Ee,getFileContent:ie}=H(r,l),le=o.filter(b=>!N||b.name.toLowerCase().includes(N.toLowerCase())),_e=react.useCallback(async b=>{if(!b.isDir){R(b),E(true);try{let P=await ie(b.cid);h(P);}catch(P){let Me=P instanceof Error?P.message:"Unknown error";h(`Failed to load file: ${Me}`);}finally{E(false);}}},[ie]);react.useEffect(()=>{o.length>0&&!f&&(g(o[0].repo_id),m(o[0].repo_id));},[o,f]);let Le=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"):O(b);};return jsxRuntime.jsxs("div",{className:T("flex flex-1 h-full min-h-0",a),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(we,{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:()=>{ne(false),_("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(ee,{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:()=>ne(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsxRuntime.jsx(we,{size:20})}),jsxRuntime.jsx("button",{onClick:()=>oe(!se),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(ve,{size:20})})]})}),se&&jsxRuntime.jsx(Mt,{onClose:()=>oe(false),onSelect:Le}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:u?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}):le.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:le.map(b=>jsxRuntime.jsx(It,{repo:b,selected:f===b.repo_id,expanded:l===b.repo_id,onSelect:()=>{g(b.repo_id),R(null),h(null);},onToggle:()=>m(l===b.repo_id?null:b.repo_id),children:jsxRuntime.jsx("div",{className:"ml-10 pl-1",children:Ee.map(P=>jsxRuntime.jsx($t,{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(zt,{entry:p,content:k,loading:v,repoName:Pe?.name||""})}),ae==="write"&&jsxRuntime.jsx(_t,{config:r,onClose:()=>O(null),onCreated:c}),ae==="upload"&&jsxRuntime.jsx(Lt,{config:r,onClose:()=>O(null),onCreated:c})]})}async function Ne(r,e,a,n){let o={"Content-Type":"application/json",...a?.headers};n&&(o.Authorization=`Bearer ${n}`);let u=await fetch(`${r}${e}`,{...a,headers:o});if(!u.ok){let t=`HTTP ${u.status}`;try{let s=await u.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return u.json()}function jt({config:r,repoId:e,onAuthRequired:a,className:n,style:o}){let u=r.apiBaseUrl,t=r.apiKey,[s,i]=react.useState({stars:0,starred:false,repo_id:e}),[c,f]=react.useState(false),[g,l]=react.useState(null),m=react.useRef(true),p=u.includes("/cpx/rack")?"":"/api/rack";react.useEffect(()=>(m.current=true,Ne(u,`${p}/${e}/stars`,void 0,t).then(k=>{m.current&&i(k);}).catch(()=>{}),()=>{m.current=false;}),[u,e,t,p]);let R=react.useCallback(async k=>{if(k.preventDefault(),k.stopPropagation(),!t){a?.();return}f(true),l(null);try{let h=s.starred?"DELETE":"POST",v=await Ne(u,`${p}/${e}/star`,{method:h},t);m.current&&i({stars:v.stars,starred:v.starred,repo_id:e});}catch(h){m.current&&l(h.message);}finally{m.current&&f(false);}},[u,e,t,s.starred,a]);return jsxRuntime.jsxs("button",{onClick:R,disabled:c,title:g||(s.starred?"Unstar (100k tokens)":"Star (100k tokens)"),className:n,style:{display:"inline-flex",alignItems:"center",gap:"4px",background:"none",border:"none",cursor:c?"wait":"pointer",padding:"4px 8px",fontSize:"12px",fontFamily:"inherit",color:s.starred?"#f59e0b":"#91918d",transition:"color 150ms",opacity:c?.5:1,...o},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=
|
|
10
|
+
${s.trim()}`,_=await fetch(`${p}/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(!_.ok){let P=`Failed to register skill (${_.status})`;try{let N=await _.json();N.error&&(P=N.error);}catch{}throw new Error(P)}e?.(),r();}catch(p){l(p instanceof Error?p.message:"Failed to create skill");}finally{f(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 Mt({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),f=async l=>{s(true),u(null);try{let m=await l.text(),h=o.apiBaseUrl||"",b=l.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),k=await fetch(`${h}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:b,skill_md:m,content_type:"code"})});if(!k.ok){let p=`Failed to register skill (${k.status})`;try{let v=await k.json();v.error&&(p=v.error);}catch{}throw new Error(p)}e?.(),r();}catch(m){u(m instanceof Error?m.message:"Upload failed");}finally{s(false);}};return jsxRuntime.jsx(Te,{title:"Upload skill",onClose:r,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{onDragOver:l=>{l.preventDefault(),c(true);},onDragLeave:()=>c(false),onDrop:l=>{l.preventDefault(),c(false);let m=l.dataTransfer.files[0];m&&f(m);},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(Ce,{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:l=>{let m=l.target.files?.[0];m&&f(m);}}),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 It({onClose:r,onSelect:e}){let o=Ne(),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(Tt,{}),label:"Create with Geoff"},{id:"write",icon:jsxRuntime.jsx(Pt,{}),label:"Write skill instructions"},{id:"upload",icon:jsxRuntime.jsx(Et,{}),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 $t({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(Se,{className:"ml-auto text-muted-foreground"})]})}function zt({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(Se,{open:o}),jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4 shrink-0"}),jsxRuntime.jsx("span",{className:"truncate",children:r.name})]}),o&&c]})}function At({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 f=r.path.split("/").pop()||r.path,g=/\.(md|mdx)$/i.test(f);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:f}),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:g?jsxRuntime.jsx(te,{content:e||""}):jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}var Bt={skills:"Skills",looops:"Looops",tensors:"Models",imaginations:"Imaginations",images:"Images"},Ut={skills:"skill/",looops:"looop/",tensors:"tensor/"};function Ot({config:r,category:e,className:o,style:n}){let{repos:a,loading:c,error:t,hasMore:s,loadMore:i,reset:u}=V(r,{pageSize:50,category:e}),[f,g]=react.useState(null),[l,m]=react.useState(null),[h,b]=react.useState(null),[k,p]=react.useState(null),[v,_]=react.useState(false),[P,N]=react.useState(""),[j,oe]=react.useState(false),[ae,ie]=react.useState(false),[le,D]=react.useState(null),Ee=a.find(w=>w.repo_id===f),{entries:_e,getFileContent:ce}=K(r,l),ue=e?Ut[e]:void 0,L=a.filter(w=>!(ue&&!w.name.startsWith(ue)||P&&!w.name.toLowerCase().includes(P.toLowerCase()))),Le=react.useCallback(async w=>{if(!w.isDir){b(w),_(true);try{let E=await ce(w.cid);p(E);}catch(E){let Ie=E instanceof Error?E.message:"Unknown error";p(`Failed to load file: ${Ie}`);}finally{_(false);}}},[ce]);react.useEffect(()=>{L.length>0&&!f&&(g(L[0].repo_id),m(L[0].repo_id));},[L,f]);let Me=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"):D(w);};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:j?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(Re,{size:16,className:"shrink-0 text-muted-foreground"}),jsxRuntime.jsx("input",{type:"text",value:P,onChange:w=>N(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:()=>{oe(false),N("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(re,{size:16})})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground",children:e&&Bt[e]||e||"Items"}),jsxRuntime.jsx("button",{onClick:()=>oe(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsxRuntime.jsx(Re,{size:20})}),jsxRuntime.jsx("button",{onClick:()=>ie(!ae),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(Ce,{size:20})})]})}),ae&&jsxRuntime.jsx(It,{onClose:()=>ie(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}):L.length===0?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:P?"No matching items":"No items yet"}):jsxRuntime.jsx("div",{className:"space-y-0.5",children:L.map(w=>jsxRuntime.jsx(zt,{repo:w,selected:f===w.repo_id,expanded:l===w.repo_id,onSelect:()=>{g(w.repo_id),b(null),p(null);},onToggle:()=>m(l===w.repo_id?null:w.repo_id),children:jsxRuntime.jsx("div",{className:"ml-10 pl-1",children:_e.map(E=>jsxRuntime.jsx($t,{entry:E,selected:h?.path===E.path,onSelect:Le,depth:E.path.split("/").length-1},E.path))})},w.repo_id))})})]}),jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntime.jsx(At,{entry:h,content:k,loading:v,repoName:Ee?.name||""})}),le==="write"&&jsxRuntime.jsx(Lt,{config:r,onClose:()=>D(null),onCreated:u}),le==="upload"&&jsxRuntime.jsx(Mt,{config:r,onClose:()=>D(null),onCreated:u})]})}async function Pe(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 Ht({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,f]=react.useState(false),[g,l]=react.useState(null),m=react.useRef(true),h=c.includes("/cpx/rack")?"":"/api/rack";react.useEffect(()=>(m.current=true,Pe(c,`${h}/${e}/stars`,void 0,t).then(k=>{m.current&&i(k);}).catch(()=>{}),()=>{m.current=false;}),[c,e,t,h]);let b=react.useCallback(async k=>{if(k.preventDefault(),k.stopPropagation(),!t){o?.();return}f(true),l(null);try{let p=s.starred?"DELETE":"POST",v=await Pe(c,`${h}/${e}/star`,{method:p},t);m.current&&i({stars:v.stars,starred:v.starred,repo_id:e});}catch(p){m.current&&l(p.message);}finally{m.current&&f(false);}},[c,e,t,s.starred,o]);return jsxRuntime.jsxs("button",{onClick:b,disabled:u,title:g||(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=te;exports.RackBrowser=Ot;exports.StarButton=Ht;exports.estimateCost=ye;exports.useLooopStats=lt;exports.useNetworkStats=ft;exports.usePaginatedRepos=V;exports.useRackClient=x;exports.useRackRegister=Ge;exports.useRackSession=Ve;exports.useRepoPush=Je;exports.useRepoTree=K;exports.useRepos=Be;exports.useSkillStats=et;exports.useStar=yt;exports.useTensorStats=st;exports.useTrending=gt;
|
package/dist/index.js
CHANGED
|
@@ -1,11 +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 S(r,e,a,n){let o={"Content-Type":"application/json",...a?.headers};n&&(o.Authorization=`Bearer ${n}`);let u=await fetch(`${r}${e}`,{...a,headers:o});if(!u.ok){let t=`HTTP ${u.status}`;try{let s=await u.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return u.json()}function $(r){let e=r.indexOf(":");return {mode:r.slice(0,e),cid:r.slice(e+1)}}function w(r){let e=r.apiBaseUrl,a=r.authorMid,n=r.ownerMid,o=r.apiKey,u=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 c=i.toString()?`?${i}`:"",f=await S(e,`/api/rack/repos${c}`,void 0,o);return {items:f.repos||[],pagination:f.pagination||{total:(f.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})},o)},async push(t,s){return S(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...s,author_mid:a})},o)},async getTree(t,s="main"){let i=await S(e,`/api/rack/${t}/tree/${s}`,void 0,o);return {tree:i.tree,commit_cid:i.commit_cid}},async getBlob(t,s){return (await S(e,`/api/rack/${t}/blob/${s}`,void 0,o)).content},async getLog(t,s,i){let c=new URLSearchParams;s&&c.set("ref",s),i&&c.set("max_count",String(i));let f=c.toString()?`?${c}`:"";return (await S(e,`/api/rack/${t}/log${f}`,void 0,o)).commits||[]},async getBranches(t){return (await S(e,`/api/rack/${t}/branches`,void 0,o)).branches||[]},async createBranch(t,s,i){return S(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:s,from_ref:i})},o)},async merge(t,s,i){return S(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:s,target_branch:i})},o)},async getDiff(t,s,i){return (await S(e,`/api/rack/${t}/diff/${s}/${i}`,void 0,o)).diff?.entries||[]},async starRepo(t){return S(e,`/api/rack/${t}/star`,{method:"POST"},o)},async unstarRepo(t){return S(e,`/api/rack/${t}/star`,{method:"DELETE"},o)},async getStarInfo(t){return S(e,`/api/rack/${t}/stars`,void 0,o)},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 g=$(i.entries["META.json"]).cid,l=await this.getBlob(t,g);s.meta=JSON.parse(l);}let c=0,f=Object.values(i.entries).map(async g=>{try{let l=$(g).cid,m=await this.getBlob(t,l);c+=m.length;}catch{}});await Promise.all(f),c>0&&(s.tokenCount=Math.ceil(c/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(`${u}/v1/skills/${encodeURIComponent(t)}`);if(s.ok){let c=await s.json();return c.usage_count??c.usageCount??null}let i=await fetch(`${u}/v1/skills?scope=public`);if(i.ok){let f=((await i.json()).skills||[]).find(g=>g.name===t||g.id===t);if(f)return f.usage_count??f.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 c=$(i.entries["TENSOR_META.json"]).cid,f=await this.getBlob(t,c);s.meta=JSON.parse(f),s.sizeMB=s.meta?.tensor_size_mb??null;}}catch{}return s},async getLooopStats(t){let s={meta:null,fileCount:null};try{let{tree:i}=await this.getTree(t,"main");if(!i?.entries)return s;if(i.entries["LOOOP_META.json"]){let c=$(i.entries["LOOOP_META.json"]).cid,f=await this.getBlob(t,c);s.meta=JSON.parse(f);}s.fileCount=Object.keys(i.entries).length;}catch{}return s},async getNetworkStats(){try{return (await S(e,"/api/rack/stats",void 0,o)).stats||null}catch{return null}},async getTrending(t=5,s=1,i){try{let c=new URLSearchParams({limit:String(t),days:String(s)});i&&c.set("cursor",i);let f=await S(e,`/api/rack/trending?${c}`,void 0,o);return {items:f.trending||[],pagination:f.pagination||{total:(f.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,a,n,o,u])}function Be(r){let e=w(r),a=useRef(e);a.current=e;let[n,o]=useState([]),[u,t]=useState(true),[s,i]=useState(null),c=useRef(true),f=useRef(null),g=useCallback(async()=>{f.current?.abort();let l=new AbortController;f.current=l;try{c.current&&(t(!0),i(null));let m=await a.current.listRepos();c.current&&!l.signal.aborted&&o(m.items);}catch(m){c.current&&!l.signal.aborted&&i(m instanceof Error?m.message:"Failed to load repos");}finally{c.current&&!l.signal.aborted&&t(false);}},[]);return useEffect(()=>(c.current=true,g(),()=>{c.current=false,f.current?.abort();}),[g]),{repos:n,loading:u,error:s,refresh:g}}function Oe(r){return Object.entries(r).map(([e,a])=>{let n=a.indexOf(":"),o=n>0?a.slice(0,n):"100644",u=n>0?a.slice(n+1):a;return {path:e,mode:o,cid:u,isDir:o==="040000"}}).sort((e,a)=>e.isDir!==a.isDir?e.isDir?-1:1:e.path.localeCompare(a.path))}function H(r,e,a="main"){let n=w(r),[o,u]=useState([]),[t,s]=useState(false),[i,c]=useState(null),f=useRef(true),g=useCallback(async()=>{if(e)try{f.current&&(s(!0),c(null));let{tree:m}=await n.getTree(e,a);f.current&&u(Oe(m.entries));}catch(m){f.current&&c(m instanceof Error?m.message:"Failed to load tree");}finally{f.current&&s(false);}},[n,e,a]);useEffect(()=>(f.current=true,g(),()=>{f.current=false;}),[g]);let l=useCallback(async m=>{if(!e)throw new Error("No repo selected");return n.getBlob(e,m)},[n,e]);return {entries:o,loading:t,error:i,refresh:g,getFileContent:l}}function He(r){let e=w(r),[a,n]=useState(false),[o,u]=useState(null),t=useRef(true);return useEffect(()=>(t.current=true,()=>{t.current=false;}),[]),{push:useCallback(async(i,c,f,g)=>{try{return t.current&&(n(!0),u(null)),await e.push(i,{files:c,message:f,branch:g})}catch(l){let m=l instanceof Error?l.message:"Push failed";return t.current&&u(m),null}finally{t.current&&n(false);}},[e]),pushing:a,error:o}}function J(r,e={}){let{pageSize:a=50,owner:n}=e,o=w(r),[u,t]=useState([]),[s,i]=useState(null),[c,f]=useState(false),[g,l]=useState(null),m=useRef(null),p=useRef(true),R=useCallback(async(v,E=false)=>{f(true),l(null);try{let N=await o.listRepos(n,{limit:a,cursor:v||void 0});p.current&&(t(_=>E?[..._,...N.items]:N.items),i(N.pagination),m.current=N.pagination.next_cursor);}catch(N){p.current&&l(N.message);}finally{p.current&&f(false);}},[o,n,a]),k=useCallback(async()=>{!m.current||c||await R(m.current,true);},[R,c]),h=useCallback(async()=>{m.current=null,await R(void 0,false);},[R]);return useEffect(()=>(p.current=true,R(),()=>{p.current=false;}),[R]),{repos:u,hasMore:s?.has_more??false,total:s?.total??0,loading:c,error:g,loadMore:k,reset:h,pagination:s}}var V="stacknet-rack-apikey";function We(r){let e=r.stacknetUrl||r.apiBaseUrl,[a,n]=useState({authenticated:false}),[o,u]=useState(null),[t,s]=useState(false),i=useCallback(l=>({"Content-Type":"application/json",...l||r.apiKey?{Authorization:`Bearer ${l||r.apiKey}`}:{}}),[r.apiKey]),c=useCallback(async l=>{s(true);try{let m=await fetch(`${e}/health`,{headers:i(l)});if(!m.ok)throw new Error(`Authentication failed: ${m.status}`);let p={authenticated:!0,apiKey:l,permission:l.startsWith("gk_")?"write":"read"};n(p);try{localStorage.setItem(V,l);}catch{}return p}catch(m){throw n({authenticated:false}),m}finally{s(false);}},[e,i]),f=useCallback(()=>{n({authenticated:false}),u(null);try{localStorage.removeItem(V);}catch{}},[]),g=useCallback(async()=>{let l=a.apiKey||r.apiKey;if(!l)return null;try{let m=await fetch(`${e}/network/usage`,{headers:i(l)});if(!m.ok)return null;let p=await m.json(),R={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 u(R),R}catch{return null}},[a.apiKey,r.apiKey,e,i]);return useEffect(()=>{let l=r.apiKey;if(l){n({authenticated:true,apiKey:l,permission:l.startsWith("gk_")?"write":"read"});return}try{let m=localStorage.getItem(V);m&&n({authenticated:!0,apiKey:m,permission:m.startsWith("gk_")?"write":"read"});}catch{}},[r.apiKey]),{session:a,budget:o,loading:t,login:c,logout:f,refreshBudget:g}}var Ve=1e3,me=1e3,Ze=1e3,ge=100;function pe(r,e){if(r==="skill"||r==="looop"){let o=r==="skill"?Ve:Ze,u=ge+Math.ceil(e/4);return {type:r,totalBytes:e,totalMegabytes:e/1e6,baseCost:u,multiplier:o,registrationCostTokens:u*o}}let a=Math.ceil(e/1e6),n=ge+a;return {type:r,totalBytes:e,totalMegabytes:a,baseCost:n,multiplier:me,registrationCostTokens:n*me}}function qe(r){let e=r.stacknetUrl||r.apiBaseUrl,a=r.apiKey,[n,o]=useState(false),[u,t]=useState(null),s=useCallback(()=>{if(!a)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${a}`}},[a]),i=useCallback(async g=>{o(true),t(null);try{let l=await fetch(`${e}/skills`,{method:"POST",headers:s(),body:JSON.stringify(g)});if(!l.ok){let m=await l.json().catch(()=>({error:`HTTP ${l.status}`}));throw new Error(m.error||`Registration failed: ${l.status}`)}return await l.json()}catch(l){throw t(l.message),l}finally{o(false);}},[e,s]),c=useCallback(async g=>{o(true),t(null);try{let l=await fetch(`${e}/tensors`,{method:"POST",headers:s(),body:JSON.stringify(g)});if(!l.ok){let m=await l.json().catch(()=>({error:`HTTP ${l.status}`}));throw new Error(m.error||`Registration failed: ${l.status}`)}return await l.json()}catch(l){throw t(l.message),l}finally{o(false);}},[e,s]),f=useCallback(async g=>{o(true),t(null);try{let l=await fetch(`${e}/looops`,{method:"POST",headers:s(),body:JSON.stringify(g)});if(!l.ok){let m=await l.json().catch(()=>({error:`HTTP ${l.status}`}));throw new Error(m.error||`Registration failed: ${l.status}`)}return await l.json()}catch(l){throw t(l.message),l}finally{o(false);}},[e,s]);return {registerSkill:i,registerTensor:c,registerLooop:f,estimateCost:pe,registering:n,error:u}}function Xe(r,e){let a=w(r),[n,o]=useState({meta:null,tokenCount:null,usageCount:null}),[u,t]=useState(false),[s,i]=useState(null),c=useRef(true),f=useCallback(async()=>{if(e){t(true),i(null);try{let g=await a.getSkillStats(e);c.current&&o(g);}catch(g){c.current&&i(g.message);}finally{c.current&&t(false);}}},[a,e]);return useEffect(()=>(c.current=true,f(),()=>{c.current=false;}),[f]),{stats:n,loading:u,error:s,refresh:f}}function nt(r,e){let a=w(r),[n,o]=useState({meta:null,sizeMB:null}),[u,t]=useState(false),[s,i]=useState(null),c=useRef(true),f=useCallback(async()=>{if(e){t(true),i(null);try{let g=await a.getTensorStats(e);c.current&&o(g);}catch(g){c.current&&i(g.message);}finally{c.current&&t(false);}}},[a,e]);return useEffect(()=>(c.current=true,f(),()=>{c.current=false;}),[f]),{stats:n,loading:u,error:s,refresh:f}}function it(r,e){let a=w(r),[n,o]=useState({meta:null,fileCount:null}),[u,t]=useState(false),[s,i]=useState(null),c=useRef(true),f=useCallback(async()=>{if(e){t(true),i(null);try{let g=await a.getLooopStats(e);c.current&&o(g);}catch(g){c.current&&i(g.message);}finally{c.current&&t(false);}}},[a,e]);return useEffect(()=>(c.current=true,f(),()=>{c.current=false;}),[f]),{stats:n,loading:u,error:s,refresh:f}}function dt(r){let e=w(r),[a,n]=useState(null),[o,u]=useState(false),[t,s]=useState(null),i=useRef(true),c=useCallback(async()=>{u(true),s(null);try{let f=await e.getNetworkStats();i.current&&n(f);}catch(f){i.current&&s(f.message);}finally{i.current&&u(false);}},[e]);return useEffect(()=>(i.current=true,c(),()=>{i.current=false;}),[c]),{stats:a,loading:o,error:t,refresh:c}}function mt(r,e=5,a=1){let n=w(r),[o,u]=useState([]),[t,s]=useState(null),[i,c]=useState(false),[f,g]=useState(null),l=useRef(true),m=useRef(null),p=useCallback(async k=>{c(true),g(null),m.current=null;try{let h=await n.getTrending(e,k??a);l.current&&(u(h.items),s(h.pagination),m.current=h.pagination.next_cursor);}catch(h){l.current&&g(h.message);}finally{l.current&&c(false);}},[n,e,a]),R=useCallback(async()=>{if(!(!m.current||i)){c(true);try{let k=await n.getTrending(e,a,m.current);l.current&&(u(h=>[...h,...k.items]),s(k.pagination),m.current=k.pagination.next_cursor);}catch(k){l.current&&g(k.message);}finally{l.current&&c(false);}}},[n,e,a,i]);return useEffect(()=>(l.current=true,p(),()=>{l.current=false;}),[p]),{repos:o,hasMore:t?.has_more??false,total:t?.total??0,loading:i,error:f,refresh:p,loadMore:R}}function ht(r,e){let a=w(r),[n,o]=useState({stars:0,starred:false,repo_id:e||""}),[u,t]=useState(false),[s,i]=useState(null),c=useRef(true),f=useCallback(async()=>{if(e)try{let l=await a.getStarInfo(e);c.current&&o(l);}catch{}},[a,e]);useEffect(()=>(c.current=true,f(),()=>{c.current=false;}),[f]);let g=useCallback(async()=>{if(e){t(true),i(null);try{let l=n.starred?await a.unstarRepo(e):await a.starRepo(e);c.current&&o({stars:l.stars,starred:l.starred,repo_id:e});}catch(l){c.current&&i(l.message);}finally{c.current&&t(false);}}},[a,e,n.starred]);return {...n,loading:u,error:s,toggle:g,refresh:f}}function T(...r){return twMerge(clsx(r))}var wt=/^(https?:\/\/|mailto:|\/[^/])/i;function xt(r){let e=r.trim();return wt.test(e)?e:null}function A(r){let e=[],a=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,n=0,o,u=0;for(;(o=a.exec(r))!==null;){o.index>n&&e.push(r.slice(n,o.index));let t=`i${u++}`;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 s=xt(o[10]);s?e.push(jsx("a",{href:s,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:o[9]},t)):e.push(o[9]);}n=o.index+o[0].length;}return n<r.length&&e.push(r.slice(n)),e.length>0?e:[r]}function Rt(r){let e=r.split(`
|
|
2
|
-
`),
|
|
3
|
-
`),lang:s||void 0}),n++;continue}if(/^\s*[-*+]\s/.test(
|
|
4
|
-
`),
|
|
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 $(r){let e=r.indexOf(":");return {mode:r.slice(0,e),cid:r.slice(e+1)}}function x(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),s?.category&&i.set("category",s.category);let u=i.toString()?`?${i}`:"",f=await S(e,`/api/rack/repos${u}`,void 0,a);return {items:f.repos||[],pagination:f.pagination||{total:(f.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 f=u.toString()?`?${u}`:"";return (await S(e,`/api/rack/${t}/log${f}`,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,author_mid:o})},a)},async merge(t,s,i){return S(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:s,target_branch:i,author_mid:o})},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",body:JSON.stringify({owner_mid:n})},a)},async unstarRepo(t){return S(e,`/api/rack/${t}/star`,{method:"DELETE",body:JSON.stringify({owner_mid:n})},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 g=$(i.entries["META.json"]).cid,l=await this.getBlob(t,g);s.meta=JSON.parse(l);}let u=0,f=Object.values(i.entries).map(async g=>{try{let l=$(g).cid,m=await this.getBlob(t,l);u+=m.length;}catch{}});await Promise.all(f),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 f=((await i.json()).skills||[]).find(g=>g.name===t||g.id===t);if(f)return f.usage_count??f.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=$(i.entries["TENSOR_META.json"]).cid,f=await this.getBlob(t,u);s.meta=JSON.parse(f),s.sizeMB=s.meta?.tensor_size_mb??null;}}catch{}return s},async getLooopStats(t){let s={meta:null,fileCount:null};try{let{tree:i}=await this.getTree(t,"main");if(!i?.entries)return s;if(i.entries["META.json"]){let u=$(i.entries["META.json"]).cid,f=await this.getBlob(t,u);s.meta=JSON.parse(f);}s.fileCount=Object.keys(i.entries).length;}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 f=await S(e,`/api/rack/trending?${u}`,void 0,a);return {items:f.trending||[],pagination:f.pagination||{total:(f.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=x(r),o=useRef(e);o.current=e;let[n,a]=useState([]),[c,t]=useState(true),[s,i]=useState(null),u=useRef(true),f=useRef(null),g=useCallback(async()=>{f.current?.abort();let l=new AbortController;f.current=l;try{u.current&&(t(!0),i(null));let m=await o.current.listRepos();u.current&&!l.signal.aborted&&a(m.items);}catch(m){u.current&&!l.signal.aborted&&i(m instanceof Error?m.message:"Failed to load repos");}finally{u.current&&!l.signal.aborted&&t(false);}},[]);return useEffect(()=>(u.current=true,g(),()=>{u.current=false,f.current?.abort();}),[g]),{repos:n,loading:c,error:s,refresh:g}}function je(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 K(r,e,o="main"){let n=x(r),[a,c]=useState([]),[t,s]=useState(false),[i,u]=useState(null),f=useRef(true),g=useCallback(async()=>{if(e)try{f.current&&(s(!0),u(null));let{tree:m}=await n.getTree(e,o);f.current&&c(je(m.entries));}catch(m){f.current&&u(m instanceof Error?m.message:"Failed to load tree");}finally{f.current&&s(false);}},[n,e,o]);useEffect(()=>(f.current=true,g(),()=>{f.current=false;}),[g]);let l=useCallback(async m=>{if(!e)throw new Error("No repo selected");return n.getBlob(e,m)},[n,e]);return {entries:a,loading:t,error:i,refresh:g,getFileContent:l}}function Je(r){let e=x(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,f,g)=>{try{return t.current&&(n(!0),c(null)),await e.push(i,{files:u,message:f,branch:g})}catch(l){let m=l instanceof Error?l.message:"Push failed";return t.current&&c(m),null}finally{t.current&&n(false);}},[e]),pushing:o,error:a}}function V(r,e={}){let{pageSize:o=50,owner:n,category:a}=e,c=x(r),[t,s]=useState([]),[i,u]=useState(null),[f,g]=useState(false),[l,m]=useState(null),h=useRef(null),b=useRef(true),k=useCallback(async(_,P=false)=>{g(true),m(null);try{let N=await c.listRepos(n,{limit:o,cursor:_||void 0,category:a});b.current&&(s(j=>P?[...j,...N.items]:N.items),u(N.pagination),h.current=N.pagination.next_cursor);}catch(N){b.current&&m(N.message);}finally{b.current&&g(false);}},[c,n,o,a]),p=useCallback(async()=>{!h.current||f||await k(h.current,true);},[k,f]),v=useCallback(async()=>{h.current=null,await k(void 0,false);},[k]);return useEffect(()=>(b.current=true,k(),()=>{b.current=false;}),[k]),{repos:t,hasMore:i?.has_more??false,total:i?.total??0,loading:f,error:l,loadMore:p,reset:v,pagination:i}}var q="stacknet-rack-apikey";function Ve(r){let e=r.stacknetUrl||r.apiBaseUrl,[o,n]=useState({authenticated:false}),[a,c]=useState(null),[t,s]=useState(false),i=useCallback(l=>({"Content-Type":"application/json",...l||r.apiKey?{Authorization:`Bearer ${l||r.apiKey}`}:{}}),[r.apiKey]),u=useCallback(async l=>{s(true);try{let m=await fetch(`${e}/health`,{headers:i(l)});if(!m.ok)throw new Error(`Authentication failed: ${m.status}`);let h={authenticated:!0,apiKey:l,permission:l.startsWith("gk_")?"write":"read"};n(h);try{localStorage.setItem(q,l);}catch{}return h}catch(m){throw n({authenticated:false}),m}finally{s(false);}},[e,i]),f=useCallback(()=>{n({authenticated:false}),c(null);try{localStorage.removeItem(q);}catch{}},[]),g=useCallback(async()=>{let l=o.apiKey||r.apiKey;if(!l)return null;try{let m=await fetch(`${e}/network/usage`,{headers:i(l)});if(!m.ok)return null;let h=await m.json(),b={planAllocation:h.plan_allocation??h.planAllocation??0,inferenceUsed:h.inference_used??h.inferenceUsed??0,ledgerSpent:h.ledger_spent??h.ledgerSpent??0,totalUsed:h.total_used??h.totalUsed??0,remaining:h.remaining??0,percent:h.percent??0,exceeded:h.exceeded??!1};return c(b),b}catch{return null}},[o.apiKey,r.apiKey,e,i]);return useEffect(()=>{let l=r.apiKey;if(l){n({authenticated:true,apiKey:l,permission:l.startsWith("gk_")?"write":"read"});return}try{let m=localStorage.getItem(q);m&&n({authenticated:!0,apiKey:m,permission:m.startsWith("gk_")?"write":"read"});}catch{}},[r.apiKey]),{session:o,budget:a,loading:t,login:u,logout:f,refreshBudget:g}}var Ze=1e3,pe=1e3,qe=1e3,he=100;function ye(r,e){if(r==="skill"||r==="looop"){let a=r==="skill"?Ze:qe,c=he+Math.ceil(e/4);return {type:r,totalBytes:e,totalMegabytes:e/1e6,baseCost:c,multiplier:a,registrationCostTokens:c*a}}let o=Math.ceil(e/1e6),n=he+o;return {type:r,totalBytes:e,totalMegabytes:o,baseCost:n,multiplier:pe,registrationCostTokens:n*pe}}function Ge(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 g=>{a(true),t(null);try{let l=await fetch(`${e}/skills`,{method:"POST",headers:s(),body:JSON.stringify(g)});if(!l.ok){let m=await l.json().catch(()=>({error:`HTTP ${l.status}`}));throw new Error(m.error||`Registration failed: ${l.status}`)}return await l.json()}catch(l){throw t(l.message),l}finally{a(false);}},[e,s]),u=useCallback(async g=>{a(true),t(null);try{let l=await fetch(`${e}/tensors`,{method:"POST",headers:s(),body:JSON.stringify(g)});if(!l.ok){let m=await l.json().catch(()=>({error:`HTTP ${l.status}`}));throw new Error(m.error||`Registration failed: ${l.status}`)}return await l.json()}catch(l){throw t(l.message),l}finally{a(false);}},[e,s]),f=useCallback(async g=>{a(true),t(null);try{let l=await fetch(`${e}/looops`,{method:"POST",headers:s(),body:JSON.stringify(g)});if(!l.ok){let m=await l.json().catch(()=>({error:`HTTP ${l.status}`}));throw new Error(m.error||`Registration failed: ${l.status}`)}return await l.json()}catch(l){throw t(l.message),l}finally{a(false);}},[e,s]);return {registerSkill:i,registerTensor:u,registerLooop:f,estimateCost:ye,registering:n,error:c}}function et(r,e){let o=x(r),[n,a]=useState({meta:null,tokenCount:null,usageCount:null}),[c,t]=useState(false),[s,i]=useState(null),u=useRef(true),f=useCallback(async()=>{if(e){t(true),i(null);try{let g=await o.getSkillStats(e);u.current&&a(g);}catch(g){u.current&&i(g.message);}finally{u.current&&t(false);}}},[o,e]);return useEffect(()=>(u.current=true,f(),()=>{u.current=false;}),[f]),{stats:n,loading:c,error:s,refresh:f}}function st(r,e){let o=x(r),[n,a]=useState({meta:null,sizeMB:null}),[c,t]=useState(false),[s,i]=useState(null),u=useRef(true),f=useCallback(async()=>{if(e){t(true),i(null);try{let g=await o.getTensorStats(e);u.current&&a(g);}catch(g){u.current&&i(g.message);}finally{u.current&&t(false);}}},[o,e]);return useEffect(()=>(u.current=true,f(),()=>{u.current=false;}),[f]),{stats:n,loading:c,error:s,refresh:f}}function lt(r,e){let o=x(r),[n,a]=useState({meta:null,fileCount:null}),[c,t]=useState(false),[s,i]=useState(null),u=useRef(true),f=useCallback(async()=>{if(e){t(true),i(null);try{let g=await o.getLooopStats(e);u.current&&a(g);}catch(g){u.current&&i(g.message);}finally{u.current&&t(false);}}},[o,e]);return useEffect(()=>(u.current=true,f(),()=>{u.current=false;}),[f]),{stats:n,loading:c,error:s,refresh:f}}function ft(r){let e=x(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 f=await e.getNetworkStats();i.current&&n(f);}catch(f){i.current&&s(f.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 gt(r,e=5,o=1){let n=x(r),[a,c]=useState([]),[t,s]=useState(null),[i,u]=useState(false),[f,g]=useState(null),l=useRef(true),m=useRef(null),h=useCallback(async k=>{u(true),g(null),m.current=null;try{let p=await n.getTrending(e,k??o);l.current&&(c(p.items),s(p.pagination),m.current=p.pagination.next_cursor);}catch(p){l.current&&g(p.message);}finally{l.current&&u(false);}},[n,e,o]),b=useCallback(async()=>{if(!(!m.current||i)){u(true);try{let k=await n.getTrending(e,o,m.current);l.current&&(c(p=>[...p,...k.items]),s(k.pagination),m.current=k.pagination.next_cursor);}catch(k){l.current&&g(k.message);}finally{l.current&&u(false);}}},[n,e,o,i]);return useEffect(()=>(l.current=true,h(),()=>{l.current=false;}),[h]),{repos:a,hasMore:t?.has_more??false,total:t?.total??0,loading:i,error:f,refresh:h,loadMore:b}}function yt(r,e){let o=x(r),[n,a]=useState({stars:0,starred:false,repo_id:e||""}),[c,t]=useState(false),[s,i]=useState(null),u=useRef(true),f=useCallback(async()=>{if(e)try{let l=await o.getStarInfo(e);u.current&&a(l);}catch{}},[o,e]);useEffect(()=>(u.current=true,f(),()=>{u.current=false;}),[f]);let g=useCallback(async()=>{if(e){t(true),i(null);try{let l=n.starred?await o.unstarRepo(e):await o.starRepo(e);u.current&&a({stars:l.stars,starred:l.starred,repo_id:e});}catch(l){u.current&&i(l.message);}finally{u.current&&t(false);}}},[o,e,n.starred]);return {...n,loading:c,error:s,toggle:g,refresh:f}}function T(...r){return twMerge(clsx(r))}var xt=/^(https?:\/\/|mailto:|\/[^/])/i;function Rt(r){let e=r.trim();return xt.test(e)?e:null}function O(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=Rt(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 bt(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 vt={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 St(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",vt[o]),children:O(r.content||"")},`b${e}`)}case "paragraph":return jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:O(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:O(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:O(o)},`li${e}-${n}`))},`b${e}`);default:return null}}function te({content:r,className:e}){let o=bt(r);return jsx("div",{className:T("text-sm",e),children:o.map((n,a)=>St(n,a))})}function Se({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 Re({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 re({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 Ce({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 Tt(){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 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:"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 Et(){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 Ne(){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 Te({onClose:r,children:e,title:o}){let n=Ne(),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(re,{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(re,{size:20})})]}),e]})]})}function _t(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 Lt({onClose:r,onCreated:e,config:o}){let[n,a]=useState(""),[c,t]=useState(""),[s,i]=useState(""),[u,f]=useState(false),[g,l]=useState(null),[m,h]=useState(false),b=p=>{if(i(p),!n.trim()&&!c.trim()&&p.trim().length>10){let v=_t(p);v&&(a(v.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")),t(v.description),h(true));}};return jsx(Te,{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=>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:c,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=>b(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"})]}),g&&jsx("p",{className:"text-sm text-red-500",children:g}),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()){f(true),l(null);try{let p=o.apiBaseUrl||"",v=m?s.trim():`# ${n.trim()}
|
|
5
5
|
|
|
6
|
-
${
|
|
6
|
+
${c.trim()}
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
-
${s.trim()}`,E=await fetch(`${h}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n.trim(),description:u.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){l(h instanceof Error?h.message:"Failed to create skill");}finally{f(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 Lt({onClose:r,onCreated:e,config:a}){let n=useRef(null),[o,u]=useState(false),[t,s]=useState(false),[i,c]=useState(null),f=async l=>{s(true),c(null);try{let m=await l.text(),p=a.apiBaseUrl||"",R=l.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:R,skill_md:m,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(m){c(m instanceof Error?m.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:l=>{l.preventDefault(),u(true);},onDragLeave:()=>u(false),onDrop:l=>{l.preventDefault(),u(false);let m=l.dataTransfer.files[0];m&&f(m);},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",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(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:l=>{let m=l.target.files?.[0];m&&f(m);}}),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 Mt({onClose:r,onSelect:e}){let a=Se(),n=useRef(null),o=useRef(r);o.current=r,useEffect(()=>{if(a)return;let t=s=>{n.current&&s.target instanceof Node&&!n.current.contains(s.target)&&o.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[a]);let u=[{id:"create-with-geoff",icon:jsx(Nt,{}),label:"Create with Geoff"},{id:"write",icon:jsx(Tt,{}),label:"Write skill instructions"},{id:"upload",icon:jsx(Pt,{}),label:"Upload a skill"}];return a?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"}),u.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:u.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 $t({entry:r,selected:e,onSelect:a,depth:n=0}){return jsxs("button",{onClick:()=>a(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(be,{className:"ml-auto text-muted-foreground"})]})}function It({repo:r,selected:e,expanded:a,onSelect:n,onToggle:o,children:u}){return jsxs("div",{children:[jsxs("button",{onClick:()=>{n(),o();},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(be,{open:a}),jsx(FileText,{className:"h-4 w-4 shrink-0"}),jsx("span",{className:"truncate",children:r.name})]}),a&&u]})}function zt({entry:r,content:e,loading:a,repoName:n}){let[o,u]=useState(false),t=useRef(null);useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[s,i]=useState(false),c=async()=>{if(e)try{await navigator.clipboard.writeText(e),u(!0),i(!1),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>u(!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(a)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 f=r.path.split("/").pop()||r.path,g=/\.(md|mdx)$/i.test(f);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:f}),jsx("button",{onClick:c,"aria-label":"Copy file content",className:T("rounded p-1 transition-colors",o?"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:g?jsx(X,{content:e||""}):jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function Bt({config:r,category:e,className:a,style:n}){let{repos:o,loading:u,error:t,hasMore:s,loadMore:i,reset:c}=J(r,{pageSize:50}),[f,g]=useState(null),[l,m]=useState(null),[p,R]=useState(null),[k,h]=useState(null),[v,E]=useState(false),[N,_]=useState(""),[Te,ne]=useState(false),[se,oe]=useState(false),[ae,O]=useState(null),Pe=o.find(b=>b.repo_id===f),{entries:Ee,getFileContent:ie}=H(r,l),le=o.filter(b=>!N||b.name.toLowerCase().includes(N.toLowerCase())),_e=useCallback(async b=>{if(!b.isDir){R(b),E(true);try{let P=await ie(b.cid);h(P);}catch(P){let Me=P instanceof Error?P.message:"Unknown error";h(`Failed to load file: ${Me}`);}finally{E(false);}}},[ie]);useEffect(()=>{o.length>0&&!f&&(g(o[0].repo_id),m(o[0].repo_id));},[o,f]);let Le=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"):O(b);};return jsxs("div",{className:T("flex flex-1 h-full min-h-0",a),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(we,{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:()=>{ne(false),_("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(ee,{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:()=>ne(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsx(we,{size:20})}),jsx("button",{onClick:()=>oe(!se),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(ve,{size:20})})]})}),se&&jsx(Mt,{onClose:()=>oe(false),onSelect:Le}),jsx("div",{className:"flex-1 overflow-y-auto p-2",children:u?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}):le.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:le.map(b=>jsx(It,{repo:b,selected:f===b.repo_id,expanded:l===b.repo_id,onSelect:()=>{g(b.repo_id),R(null),h(null);},onToggle:()=>m(l===b.repo_id?null:b.repo_id),children:jsx("div",{className:"ml-10 pl-1",children:Ee.map(P=>jsx($t,{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(zt,{entry:p,content:k,loading:v,repoName:Pe?.name||""})}),ae==="write"&&jsx(_t,{config:r,onClose:()=>O(null),onCreated:c}),ae==="upload"&&jsx(Lt,{config:r,onClose:()=>O(null),onCreated:c})]})}async function Ne(r,e,a,n){let o={"Content-Type":"application/json",...a?.headers};n&&(o.Authorization=`Bearer ${n}`);let u=await fetch(`${r}${e}`,{...a,headers:o});if(!u.ok){let t=`HTTP ${u.status}`;try{let s=await u.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return u.json()}function jt({config:r,repoId:e,onAuthRequired:a,className:n,style:o}){let u=r.apiBaseUrl,t=r.apiKey,[s,i]=useState({stars:0,starred:false,repo_id:e}),[c,f]=useState(false),[g,l]=useState(null),m=useRef(true),p=u.includes("/cpx/rack")?"":"/api/rack";useEffect(()=>(m.current=true,Ne(u,`${p}/${e}/stars`,void 0,t).then(k=>{m.current&&i(k);}).catch(()=>{}),()=>{m.current=false;}),[u,e,t,p]);let R=useCallback(async k=>{if(k.preventDefault(),k.stopPropagation(),!t){a?.();return}f(true),l(null);try{let h=s.starred?"DELETE":"POST",v=await Ne(u,`${p}/${e}/star`,{method:h},t);m.current&&i({stars:v.stars,starred:v.starred,repo_id:e});}catch(h){m.current&&l(h.message);}finally{m.current&&f(false);}},[u,e,t,s.starred,a]);return jsxs("button",{onClick:R,disabled:c,title:g||(s.starred?"Unstar (100k tokens)":"Star (100k tokens)"),className:n,style:{display:"inline-flex",alignItems:"center",gap:"4px",background:"none",border:"none",cursor:c?"wait":"pointer",padding:"4px 8px",fontSize:"12px",fontFamily:"inherit",color:s.starred?"#f59e0b":"#91918d",transition:"color 150ms",opacity:c?.5:1,...o},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{
|
|
10
|
+
${s.trim()}`,_=await fetch(`${p}/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(!_.ok){let P=`Failed to register skill (${_.status})`;try{let N=await _.json();N.error&&(P=N.error);}catch{}throw new Error(P)}e?.(),r();}catch(p){l(p instanceof Error?p.message:"Failed to create skill");}finally{f(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 Mt({onClose:r,onCreated:e,config:o}){let n=useRef(null),[a,c]=useState(false),[t,s]=useState(false),[i,u]=useState(null),f=async l=>{s(true),u(null);try{let m=await l.text(),h=o.apiBaseUrl||"",b=l.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),k=await fetch(`${h}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:b,skill_md:m,content_type:"code"})});if(!k.ok){let p=`Failed to register skill (${k.status})`;try{let v=await k.json();v.error&&(p=v.error);}catch{}throw new Error(p)}e?.(),r();}catch(m){u(m instanceof Error?m.message:"Upload failed");}finally{s(false);}};return jsx(Te,{title:"Upload skill",onClose:r,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{onDragOver:l=>{l.preventDefault(),c(true);},onDragLeave:()=>c(false),onDrop:l=>{l.preventDefault(),c(false);let m=l.dataTransfer.files[0];m&&f(m);},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(Ce,{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:l=>{let m=l.target.files?.[0];m&&f(m);}}),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 It({onClose:r,onSelect:e}){let o=Ne(),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(Tt,{}),label:"Create with Geoff"},{id:"write",icon:jsx(Pt,{}),label:"Write skill instructions"},{id:"upload",icon:jsx(Et,{}),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 $t({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(Se,{className:"ml-auto text-muted-foreground"})]})}function zt({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(Se,{open:o}),jsx(FileText,{className:"h-4 w-4 shrink-0"}),jsx("span",{className:"truncate",children:r.name})]}),o&&c]})}function At({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 f=r.path.split("/").pop()||r.path,g=/\.(md|mdx)$/i.test(f);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:f}),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:g?jsx(te,{content:e||""}):jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}var Bt={skills:"Skills",looops:"Looops",tensors:"Models",imaginations:"Imaginations",images:"Images"},Ut={skills:"skill/",looops:"looop/",tensors:"tensor/"};function Ot({config:r,category:e,className:o,style:n}){let{repos:a,loading:c,error:t,hasMore:s,loadMore:i,reset:u}=V(r,{pageSize:50,category:e}),[f,g]=useState(null),[l,m]=useState(null),[h,b]=useState(null),[k,p]=useState(null),[v,_]=useState(false),[P,N]=useState(""),[j,oe]=useState(false),[ae,ie]=useState(false),[le,D]=useState(null),Ee=a.find(w=>w.repo_id===f),{entries:_e,getFileContent:ce}=K(r,l),ue=e?Ut[e]:void 0,L=a.filter(w=>!(ue&&!w.name.startsWith(ue)||P&&!w.name.toLowerCase().includes(P.toLowerCase()))),Le=useCallback(async w=>{if(!w.isDir){b(w),_(true);try{let E=await ce(w.cid);p(E);}catch(E){let Ie=E instanceof Error?E.message:"Unknown error";p(`Failed to load file: ${Ie}`);}finally{_(false);}}},[ce]);useEffect(()=>{L.length>0&&!f&&(g(L[0].repo_id),m(L[0].repo_id));},[L,f]);let Me=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"):D(w);};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:j?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(Re,{size:16,className:"shrink-0 text-muted-foreground"}),jsx("input",{type:"text",value:P,onChange:w=>N(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:()=>{oe(false),N("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(re,{size:16})})]}):jsxs(Fragment,{children:[jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground",children:e&&Bt[e]||e||"Items"}),jsx("button",{onClick:()=>oe(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsx(Re,{size:20})}),jsx("button",{onClick:()=>ie(!ae),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(Ce,{size:20})})]})}),ae&&jsx(It,{onClose:()=>ie(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}):L.length===0?jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:P?"No matching items":"No items yet"}):jsx("div",{className:"space-y-0.5",children:L.map(w=>jsx(zt,{repo:w,selected:f===w.repo_id,expanded:l===w.repo_id,onSelect:()=>{g(w.repo_id),b(null),p(null);},onToggle:()=>m(l===w.repo_id?null:w.repo_id),children:jsx("div",{className:"ml-10 pl-1",children:_e.map(E=>jsx($t,{entry:E,selected:h?.path===E.path,onSelect:Le,depth:E.path.split("/").length-1},E.path))})},w.repo_id))})})]}),jsx("div",{className:"flex-1 min-w-0",children:jsx(At,{entry:h,content:k,loading:v,repoName:Ee?.name||""})}),le==="write"&&jsx(Lt,{config:r,onClose:()=>D(null),onCreated:u}),le==="upload"&&jsx(Mt,{config:r,onClose:()=>D(null),onCreated:u})]})}async function Pe(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 Ht({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,f]=useState(false),[g,l]=useState(null),m=useRef(true),h=c.includes("/cpx/rack")?"":"/api/rack";useEffect(()=>(m.current=true,Pe(c,`${h}/${e}/stars`,void 0,t).then(k=>{m.current&&i(k);}).catch(()=>{}),()=>{m.current=false;}),[c,e,t,h]);let b=useCallback(async k=>{if(k.preventDefault(),k.stopPropagation(),!t){o?.();return}f(true),l(null);try{let p=s.starred?"DELETE":"POST",v=await Pe(c,`${h}/${e}/star`,{method:p},t);m.current&&i({stars:v.stars,starred:v.starred,repo_id:e});}catch(p){m.current&&l(p.message);}finally{m.current&&f(false);}},[c,e,t,s.starred,o]);return jsxs("button",{onClick:b,disabled:u,title:g||(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{te as Markdown,Ot as RackBrowser,Ht as StarButton,ye as estimateCost,lt as useLooopStats,ft as useNetworkStats,V as usePaginatedRepos,x as useRackClient,Ge as useRackRegister,Ve as useRackSession,Je as useRepoPush,K as useRepoTree,Be as useRepos,et as useSkillStats,yt as useStar,st as useTensorStats,gt as useTrending};
|
package/dist/types/index.d.cts
CHANGED
|
@@ -341,6 +341,8 @@ interface PaginationParams {
|
|
|
341
341
|
limit?: number;
|
|
342
342
|
/** Opaque cursor from a previous response's next_cursor */
|
|
343
343
|
cursor?: string;
|
|
344
|
+
/** Filter by category (skills, looops, tensors, imaginations, images) */
|
|
345
|
+
category?: string;
|
|
344
346
|
}
|
|
345
347
|
interface CostEstimate {
|
|
346
348
|
type: 'skill' | 'tensor' | 'looop';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -341,6 +341,8 @@ interface PaginationParams {
|
|
|
341
341
|
limit?: number;
|
|
342
342
|
/** Opaque cursor from a previous response's next_cursor */
|
|
343
343
|
cursor?: string;
|
|
344
|
+
/** Filter by category (skills, looops, tensors, imaginations, images) */
|
|
345
|
+
category?: string;
|
|
344
346
|
}
|
|
345
347
|
interface CostEstimate {
|
|
346
348
|
type: 'skill' | 'tensor' | 'looop';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacknet/rackutils",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "React hooks and components for reading and writing StackNet Racks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -28,22 +28,17 @@
|
|
|
28
28
|
"require": "./dist/components/index.cjs"
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
-
"files": [
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
"dev": "tsup --watch",
|
|
36
|
-
"clean": "rm -rf dist",
|
|
37
|
-
"typecheck": "tsc --noEmit",
|
|
38
|
-
"prepublishOnly": "pnpm run clean && pnpm run typecheck && pnpm run build:publish",
|
|
39
|
-
"release": "pnpm run prepublishOnly && npm publish --access public"
|
|
40
|
-
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
41
35
|
"dependencies": {
|
|
42
36
|
"clsx": "^2.1.1",
|
|
43
37
|
"tailwind-merge": "^2.5.4",
|
|
44
38
|
"lucide-react": "^0.460.0"
|
|
45
39
|
},
|
|
46
40
|
"devDependencies": {
|
|
41
|
+
"@types/bun": "latest",
|
|
47
42
|
"@types/react": "^19.0.0",
|
|
48
43
|
"@types/react-dom": "^19.0.0",
|
|
49
44
|
"react": "^19.0.0",
|
|
@@ -55,5 +50,15 @@
|
|
|
55
50
|
"react": ">=18.0.0",
|
|
56
51
|
"react-dom": ">=18.0.0"
|
|
57
52
|
},
|
|
58
|
-
"license": "MIT"
|
|
59
|
-
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsup",
|
|
56
|
+
"build:publish": "tsup --no-sourcemap --minify",
|
|
57
|
+
"dev": "tsup --watch",
|
|
58
|
+
"clean": "rm -rf dist",
|
|
59
|
+
"typecheck": "tsc --noEmit",
|
|
60
|
+
"release": "pnpm run prepublishOnly && npm publish --access public",
|
|
61
|
+
"test": "bun test",
|
|
62
|
+
"coverage": "bun test --coverage"
|
|
63
|
+
}
|
|
64
|
+
}
|