@stacknet/rackutils 0.1.0 → 0.3.0
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 +6 -6
- package/dist/components/index.js +6 -6
- package/dist/hooks/index.cjs +1 -1
- package/dist/hooks/index.d.cts +107 -3
- package/dist/hooks/index.d.ts +107 -3
- package/dist/hooks/index.js +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/types/index.d.cts +181 -1
- package/dist/types/index.d.ts +181 -1
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
'use strict';var react=require('react'),lucideReact=require('lucide-react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');function
|
|
2
|
-
`),
|
|
3
|
-
`),lang:
|
|
1
|
+
'use strict';var react=require('react'),lucideReact=require('lucide-react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');function k(...r){return tailwindMerge.twMerge(clsx.clsx(r))}async function v(r,e,i,s){let o={"Content-Type":"application/json",...i?.headers};s&&(o.Authorization=`Bearer ${s}`);let c=await fetch(`${r}${e}`,{...i,headers:o});if(!c.ok){let t=`HTTP ${c.status}`;try{let a=await c.json();a.error&&(t=a.error);}catch{}throw new Error(t)}return c.json()}function P(r){let e=r.indexOf(":");return {mode:r.slice(0,e),cid:r.slice(e+1)}}function M(r){let e=r.apiBaseUrl,i=r.authorMid,s=r.ownerMid,o=r.apiKey,c=r.stacknetUrl||r.apiBaseUrl;return react.useMemo(()=>({async listRepos(t){let a=t||s?`?owner=${encodeURIComponent(t||s)}`:"";return (await v(e,`/api/rack/repos${a}`,void 0,o)).repos||[]},async initRepo(t){return v(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...t,owner_mid:s})},o)},async push(t,a){return v(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...a,author_mid:i})},o)},async getTree(t,a="main"){let l=await v(e,`/api/rack/${t}/tree/${a}`,void 0,o);return {tree:l.tree,commit_cid:l.commit_cid}},async getBlob(t,a){return (await v(e,`/api/rack/${t}/blob/${a}`,void 0,o)).content},async getLog(t,a,l){let d=new URLSearchParams;a&&d.set("ref",a),l&&d.set("max_count",String(l));let u=d.toString()?`?${d}`:"";return (await v(e,`/api/rack/${t}/log${u}`,void 0,o)).commits||[]},async getBranches(t){return (await v(e,`/api/rack/${t}/branches`,void 0,o)).branches||[]},async createBranch(t,a,l){return v(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:a,from_ref:l})},o)},async merge(t,a,l){return v(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:a,target_branch:l})},o)},async getDiff(t,a,l){return (await v(e,`/api/rack/${t}/diff/${a}/${l}`,void 0,o)).diff?.entries||[]},async starRepo(t){return v(e,`/api/rack/${t}/star`,{method:"POST"},o)},async unstarRepo(t){return v(e,`/api/rack/${t}/star`,{method:"DELETE"},o)},async getStarInfo(t){return v(e,`/api/rack/${t}/stars`,void 0,o)},async getSkillStats(t){let a={meta:null,tokenCount:null,usageCount:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return a;if(l.entries["META.json"]){let p=P(l.entries["META.json"]).cid,g=await this.getBlob(t,p);a.meta=JSON.parse(g);}let d=0,u=Object.values(l.entries).map(async p=>{try{let g=P(p).cid,f=await this.getBlob(t,g);d+=f.length;}catch{}});await Promise.all(u),d>0&&(a.tokenCount=Math.ceil(d/4)),a.meta?.skill_id&&(a.usageCount=await this.getSkillUsageCount(a.meta.skill_id));}catch{}return a},async getSkillUsageCount(t){try{let a=await fetch(`${c}/v1/skills/${encodeURIComponent(t)}`);if(a.ok){let d=await a.json();return d.usage_count??d.usageCount??null}let l=await fetch(`${c}/v1/skills?scope=public`);if(l.ok){let u=((await l.json()).skills||[]).find(p=>p.name===t||p.id===t);if(u)return u.usage_count??u.usageCount??0}return 0}catch{return null}},async getTensorStats(t){let a={meta:null,sizeMB:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return a;if(l.entries["TENSOR_META.json"]){let d=P(l.entries["TENSOR_META.json"]).cid,u=await this.getBlob(t,d);a.meta=JSON.parse(u),a.sizeMB=a.meta?.tensor_size_mb??null;}}catch{}return a},async getNetworkStats(){try{return (await v(e,"/api/rack/stats",void 0,o)).stats||null}catch{return null}},async getTrending(t=5,a=1){try{return (await v(e,`/api/rack/trending?limit=${t}&days=${a}`,void 0,o)).trending||[]}catch{return []}}}),[e,i,s,o,c])}function Z(r){let e=M(r),i=react.useRef(e);i.current=e;let[s,o]=react.useState([]),[c,t]=react.useState(true),[a,l]=react.useState(null),d=react.useRef(true),u=react.useRef(null),p=react.useCallback(async()=>{u.current?.abort();let g=new AbortController;u.current=g;try{d.current&&(t(!0),l(null));let f=await i.current.listRepos();d.current&&!g.signal.aborted&&o(f);}catch(f){d.current&&!g.signal.aborted&&l(f instanceof Error?f.message:"Failed to load repos");}finally{d.current&&!g.signal.aborted&&t(false);}},[]);return react.useEffect(()=>(d.current=true,p(),()=>{d.current=false,u.current?.abort();}),[p]),{repos:s,loading:c,error:a,refresh:p}}function ge(r){return Object.entries(r).map(([e,i])=>{let s=i.indexOf(":"),o=s>0?i.slice(0,s):"100644",c=s>0?i.slice(s+1):i;return {path:e,mode:o,cid:c,isDir:o==="040000"}}).sort((e,i)=>e.isDir!==i.isDir?e.isDir?-1:1:e.path.localeCompare(i.path))}function W(r,e,i="main"){let s=M(r),[o,c]=react.useState([]),[t,a]=react.useState(false),[l,d]=react.useState(null),u=react.useRef(true),p=react.useCallback(async()=>{if(e)try{u.current&&(a(!0),d(null));let{tree:f}=await s.getTree(e,i);u.current&&c(ge(f.entries));}catch(f){u.current&&d(f instanceof Error?f.message:"Failed to load tree");}finally{u.current&&a(false);}},[s,e,i]);react.useEffect(()=>(u.current=true,p(),()=>{u.current=false;}),[p]);let g=react.useCallback(async f=>{if(!e)throw new Error("No repo selected");return s.getBlob(e,f)},[s,e]);return {entries:o,loading:t,error:l,refresh:p,getFileContent:g}}var pe=/^(https?:\/\/|mailto:|\/[^/])/i;function he(r){let e=r.trim();return pe.test(e)?e:null}function z(r){let e=[],i=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,s=0,o,c=0;for(;(o=i.exec(r))!==null;){o.index>s&&e.push(r.slice(s,o.index));let t=`i${c++}`;if(o[1])e.push(jsxRuntime.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[0.85em] font-mono text-pink-400",children:o[1].slice(1,-1)},t));else if(o[2])e.push(jsxRuntime.jsx("strong",{children:o[3]},t));else if(o[4])e.push(jsxRuntime.jsx("em",{children:o[5]},t));else if(o[6])e.push(jsxRuntime.jsx("em",{children:o[7]},t));else if(o[8]){let a=he(o[10]);a?e.push(jsxRuntime.jsx("a",{href:a,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:o[9]},t)):e.push(o[9]);}s=o.index+o[0].length;}return s<r.length&&e.push(r.slice(s)),e.length>0?e:[r]}function xe(r){let e=r.split(`
|
|
2
|
+
`),i=[],s=0;for(;s<e.length;){let o=e[s];if(o.trim()===""){s++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(o.trim())){i.push({type:"hr"}),s++;continue}let c=o.match(/^(#{1,6})\s+(.+)/);if(c){i.push({type:"heading",level:c[1].length,content:c[2]}),s++;continue}if(o.trim().startsWith("```")){let a=o.trim().slice(3).trim(),l=[];for(s++;s<e.length&&!e[s].trim().startsWith("```");)l.push(e[s]),s++;i.push({type:"code",content:l.join(`
|
|
3
|
+
`),lang:a||void 0}),s++;continue}if(/^\s*[-*+]\s/.test(o)){let a=[];for(;s<e.length&&/^\s*[-*+]\s/.test(e[s]);)a.push(e[s].replace(/^\s*[-*+]\s+/,"")),s++;i.push({type:"ul",items:a});continue}if(/^\s*\d+[.)]\s/.test(o)){let a=[];for(;s<e.length&&/^\s*\d+[.)]\s/.test(e[s]);)a.push(e[s].replace(/^\s*\d+[.)]\s+/,"")),s++;i.push({type:"ol",items:a});continue}let t=[];for(;s<e.length&&e[s].trim()!==""&&!e[s].match(/^#{1,6}\s/)&&!e[s].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[s])&&!/^\s*\d+[.)]\s/.test(e[s]);)t.push(e[s]),s++;t.length>0&&i.push({type:"paragraph",content:t.join(" ")});}return i}var ve={1:"text-2xl font-bold mt-6 mb-3",2:"text-xl font-bold mt-5 mb-2",3:"text-lg font-semibold mt-4 mb-2",4:"text-base font-semibold mt-3 mb-1",5:"text-sm font-semibold mt-2 mb-1",6:"text-sm font-medium mt-2 mb-1"};function be(r,e){switch(r.type){case "hr":return jsxRuntime.jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let i=Math.min(Math.max(r.level||1,1),6),s=`h${i}`;return jsxRuntime.jsx(s,{className:k("text-foreground",ve[i]),children:z(r.content||"")},`b${e}`)}case "paragraph":return jsxRuntime.jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:z(r.content||"")},`b${e}`);case "code":return jsxRuntime.jsx("pre",{className:"mb-3 overflow-x-auto rounded-lg bg-muted p-4 text-sm font-mono leading-relaxed text-foreground",children:jsxRuntime.jsx("code",{children:r.content})},`b${e}`);case "ul":return jsxRuntime.jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:r.items?.map((i,s)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:z(i)},`li${e}-${s}`))},`b${e}`);case "ol":return jsxRuntime.jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:r.items?.map((i,s)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:z(i)},`li${e}-${s}`))},`b${e}`);default:return null}}function B({content:r,className:e}){let i=xe(r);return jsxRuntime.jsx("div",{className:k("text-sm",e),children:i.map((s,o)=>be(s,o))})}function Q({open:r,className:e}){return jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:k("shrink-0 transition-transform duration-150",r?"rotate-0":"-rotate-90",e),children:jsxRuntime.jsx("path",{d:"M16.134 6.16a.5.5 0 1 1 .732.68l-6.5 7-.077.068a.5.5 0 0 1-.655-.068l-6.5-7-.062-.08a.5.5 0 0 1 .718-.667l.076.067L10 12.767z"})})}function q({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function L({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M15.147 4.146a.5.5 0 0 1 .707.707L10.707 10l5.147 5.147a.5.5 0 0 1-.63.771l-.078-.064L10 10.707l-5.146 5.147a.5.5 0 0 1-.708-.707L9.293 10 4.146 4.853a.5.5 0 0 1 .708-.707L10 9.293z"})})}function Y({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M10 3a.5.5 0 0 1 .5.5v6h6l.1.01a.5.5 0 0 1 0 .98l-.1.01h-6v6a.5.5 0 0 1-1 0v-6h-6a.5.5 0 0 1 0-1h6v-6A.5.5 0 0 1 10 3"})})}function ke(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M6.5 3A2.5 2.5 0 0 0 4 5.5v9A2.5 2.5 0 0 0 6.5 17h7a2.5 2.5 0 0 0 2.5-2.5v-7A2.5 2.5 0 0 0 13.5 5H11V3.5a.5.5 0 0 0-1 0V5H6.5ZM5 5.5A1.5 1.5 0 0 1 6.5 4H9v1H6.5A1.5 1.5 0 0 0 5 6.5v8A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 13.5 6H11V4h2.5A2.5 2.5 0 0 1 16 6.5v8a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-9Z"})})}function Ne(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M5.5 3A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h9a2.5 2.5 0 0 0 2.5-2.5v-9A2.5 2.5 0 0 0 14.5 3h-9ZM4 5.5A1.5 1.5 0 0 1 5.5 4h9A1.5 1.5 0 0 1 16 5.5v9a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 4 14.5v-9ZM7 7.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5Z"})})}function Re(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M10 2a.5.5 0 0 1 .354.146l3 3a.5.5 0 0 1-.708.708L10.5 3.707V12.5a.5.5 0 0 1-1 0V3.707L7.354 5.854a.5.5 0 1 1-.708-.708l3-3A.5.5 0 0 1 10 2ZM4 13.5a.5.5 0 0 1 1 0v1A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-1a.5.5 0 0 1 1 0v1a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-1Z"})})}function X(){let[r,e]=react.useState(false);return react.useEffect(()=>{if(typeof window>"u")return;let i=()=>e(window.innerWidth<768);return i(),window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]),r}function ee({onClose:r,children:e,title:i}){let s=X(),o=react.useRef(r);return o.current=r,react.useEffect(()=>{let c=t=>{t.key==="Escape"&&o.current();};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[]),s?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full max-h-[90vh] overflow-y-auto rounded-t-2xl bg-[#1a1a1a] p-5 pb-8 animate-in slide-in-from-bottom duration-200",onClick:c=>c.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-4 h-1 w-10 rounded-full bg-zinc-600"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-foreground",children:i}),jsxRuntime.jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(L,{size:20})})]}),e]})]}):jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full max-w-lg overflow-y-auto rounded-2xl bg-[#1a1a1a] p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:c=>c.stopPropagation(),children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-foreground",children:i}),jsxRuntime.jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(L,{size:20})})]}),e]})]})}function Ce({onClose:r,onCreated:e,config:i}){let[s,o]=react.useState(""),[c,t]=react.useState(""),[a,l]=react.useState(""),[d,u]=react.useState(false),[p,g]=react.useState(null);return jsxRuntime.jsx(ee,{title:"Write skill instructions",onClose:r,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsxRuntime.jsx("input",{id:"skill-name",value:s,onChange:w=>o(w.target.value),placeholder:"weekly-status-report",className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-desc",className:"text-sm text-muted-foreground",children:"Description"}),jsxRuntime.jsx("textarea",{id:"skill-desc",value:c,onChange:w=>t(w.target.value),placeholder:"Generate weekly status reports from recent work.",rows:3,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-instructions",className:"text-sm text-muted-foreground",children:"Instructions"}),jsxRuntime.jsx("textarea",{id:"skill-instructions",value:a,onChange:w=>l(w.target.value),placeholder:"Summarize my recent work in three sections: wins, blockers, and next steps.",rows:8,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),p&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:p}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsxRuntime.jsx("button",{onClick:r,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsxRuntime.jsx("button",{onClick:async()=>{if(s.trim()){u(true),g(null);try{let w=i.apiBaseUrl||"",S=`# ${s.trim()}
|
|
4
4
|
|
|
5
|
-
${
|
|
5
|
+
${c.trim()}
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
${l.trim()}`,k=await fetch(`${v}/api/rack/${E}/push`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[{path:"SKILL.md",content:z}],message:"Initial skill definition",author_mid:s.authorMid})});if(!k.ok){let b=`Failed to save skill (${k.status})`;try{let y=await k.json();y.error&&(b=y.error);}catch{}throw new Error(b)}e?.(),n();}catch(v){u(v instanceof Error?v.message:"Failed to create skill");}finally{f(false);}}},disabled:p||!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:p?"Creating...":"Create"})]})]})})}function Ce({onClose:n,onCreated:e,config:s}){let r=react.useRef(null),[o,a]=react.useState(false),[i,l]=react.useState(false),[m,p]=react.useState(null),f=async u=>{l(true),p(null);try{let d=await u.text(),v=s.apiBaseUrl||"",N=u.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),E=await fetch(`${v}/api/rack/init`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:N,owner_mid:s.ownerMid,is_gitagent:!0})});if(!E.ok){let b=`Failed to create repo (${E.status})`;try{let y=await E.json();y.error&&(b=y.error);}catch{}throw new Error(b)}let{repo_id:z}=await E.json(),k=await fetch(`${v}/api/rack/${z}/push`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[{path:u.name,content:d}],message:`Upload ${u.name}`,author_mid:s.authorMid})});if(!k.ok){let b=`Upload failed (${k.status})`;try{let y=await k.json();y.error&&(b=y.error);}catch{}throw new Error(b)}e?.(),n();}catch(d){p(d instanceof Error?d.message:"Upload failed");}finally{l(false);}};return jsxRuntime.jsx(ee,{title:"Upload skill",onClose:n,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{onDragOver:u=>{u.preventDefault(),a(true);},onDragLeave:()=>a(false),onDrop:u=>{u.preventDefault(),a(false);let d=u.dataTransfer.files[0];d&&f(d);},onClick:()=>r.current?.click(),className:R("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",o?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsxRuntime.jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsxRuntime.jsx(Y,{size:20,className:"text-muted-foreground"})}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:i?"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:u=>{let d=u.target.files?.[0];d&&f(d);}}),m&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:m}),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 Ee({onClose:n,onSelect:e}){let s=X(),r=react.useRef(null),o=react.useRef(n);o.current=n,react.useEffect(()=>{if(s)return;let i=l=>{r.current&&l.target instanceof Node&&!r.current.contains(l.target)&&o.current();};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[s]);let a=[{id:"create-with-geoff",icon:jsxRuntime.jsx(ye,{}),label:"Create with Geoff"},{id:"write",icon:jsxRuntime.jsx(ke,{}),label:"Write skill instructions"},{id:"upload",icon:jsxRuntime.jsx(Ne,{}),label:"Upload a skill"}];return s?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:n,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full rounded-t-2xl bg-[#1a1a1a] p-4 pb-8 animate-in slide-in-from-bottom duration-200",onClick:i=>i.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),a.map(i=>jsxRuntime.jsxs("button",{onClick:()=>{e(i.id),n();},className:"flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-800",children:[i.icon,i.label]},i.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:a.map(i=>jsxRuntime.jsxs("button",{onClick:()=>{e(i.id),n();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[i.icon,i.label]},i.id))})}function Te({entry:n,selected:e,onSelect:s,depth:r=0}){return jsxRuntime.jsxs("button",{onClick:()=>s(n),className:R("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+r*16}px`},children:[jsxRuntime.jsx("span",{className:"truncate flex-1",children:n.path.split("/").pop()}),n.isDir&&jsxRuntime.jsx(Q,{className:"ml-auto text-muted-foreground"})]})}function ze({repo:n,selected:e,expanded:s,onSelect:r,onToggle:o,children:a}){return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>{r(),o();},className:R("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsxRuntime.jsx(Q,{open:s}),jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4 shrink-0"}),jsxRuntime.jsx("span",{className:"truncate",children:n.name})]}),s&&a]})}function $e({entry:n,content:e,loading:s,repoName:r}){let[o,a]=react.useState(false),i=react.useRef(null);react.useEffect(()=>()=>{i.current&&clearTimeout(i.current);},[]);let[l,m]=react.useState(false),p=async()=>{if(e)try{await navigator.clipboard.writeText(e),a(!0),m(!1),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>a(!1),2e3);}catch{m(true),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>m(false),2e3);}};if(!n)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(s)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=n.path.split("/").pop()||n.path,x=/\.(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:p,"aria-label":"Copy file content",className:R("rounded p-1 transition-colors",o?"text-green-500":l?"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:x?jsxRuntime.jsx(B,{content:e||""}):jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function Me({config:n,category:e,className:s,style:r}){let{repos:o,loading:a,error:i,refresh:l}=Z(n),[m,p]=react.useState(null),[f,x]=react.useState(null),[u,d]=react.useState(null),[v,N]=react.useState(null),[E,z]=react.useState(false),[k,b]=react.useState(""),[y,U]=react.useState(false),[j,F]=react.useState(false),[O,L]=react.useState(null),te=o.find(g=>g.repo_id===m),{entries:re,getFileContent:H}=J(n,f),V=o.filter(g=>!k||g.name.toLowerCase().includes(k.toLowerCase())),ne=react.useCallback(async g=>{if(!g.isDir){d(g),z(true);try{let C=await H(g.cid);N(C);}catch(C){let se=C instanceof Error?C.message:"Unknown error";N(`Failed to load file: ${se}`);}finally{z(false);}}},[H]);react.useEffect(()=>{o.length>0&&!m&&(p(o[0].repo_id),x(o[0].repo_id));},[o,m]);let oe=g=>{g==="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"):L(g);};return jsxRuntime.jsxs("div",{className:R("flex flex-1 h-full min-h-0",s),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:y?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-md border bg-muted/50 px-2 py-1",children:[jsxRuntime.jsx(q,{size:16,className:"shrink-0 text-muted-foreground"}),jsxRuntime.jsx("input",{type:"text",value:k,onChange:g=>b(g.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:()=>{U(false),b("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(D,{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:()=>U(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsxRuntime.jsx(q,{size:20})}),jsxRuntime.jsx("button",{onClick:()=>F(!j),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(Y,{size:20})})]})}),j&&jsxRuntime.jsx(Ee,{onClose:()=>F(false),onSelect:oe}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:a?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"})}):i?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:i}):V.length===0?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:k?"No matching items":"No items yet"}):jsxRuntime.jsx("div",{className:"space-y-0.5",children:V.map(g=>jsxRuntime.jsx(ze,{repo:g,selected:m===g.repo_id,expanded:f===g.repo_id,onSelect:()=>{p(g.repo_id),d(null),N(null);},onToggle:()=>x(f===g.repo_id?null:g.repo_id),children:jsxRuntime.jsx("div",{className:"ml-10 pl-1",children:re.map(C=>jsxRuntime.jsx(Te,{entry:C,selected:u?.path===C.path,onSelect:ne,depth:C.path.split("/").length-1},C.path))})},g.repo_id))})})]}),jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntime.jsx($e,{entry:u,content:v,loading:E,repoName:te?.name||""})}),O==="write"&&jsxRuntime.jsx(Re,{config:n,onClose:()=>L(null),onCreated:l}),O==="upload"&&jsxRuntime.jsx(Ce,{config:n,onClose:()=>L(null),onCreated:l})]})}
|
|
10
|
-
exports.Markdown=B;exports.RackBrowser
|
|
9
|
+
${a.trim()}`,N=await fetch(`${w}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.trim(),description:c.trim(),skill_md:S,content_type:"code"})});if(!N.ok){let C=`Failed to register skill (${N.status})`;try{let y=await N.json();y.error&&(C=y.error);}catch{}throw new Error(C)}e?.(),r();}catch(w){g(w instanceof Error?w.message:"Failed to create skill");}finally{u(false);}}},disabled:d||!s.trim(),className:"rounded-lg bg-zinc-600 px-4 py-2 text-sm font-medium text-white hover:bg-zinc-500 disabled:opacity-50",children:d?"Creating...":"Create"})]})]})})}function Se({onClose:r,onCreated:e,config:i}){let s=react.useRef(null),[o,c]=react.useState(false),[t,a]=react.useState(false),[l,d]=react.useState(null),u=async g=>{a(true),d(null);try{let f=await g.text(),w=i.apiBaseUrl||"",S=g.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),N=await fetch(`${w}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:S,skill_md:f,content_type:"code"})});if(!N.ok){let C=`Failed to register skill (${N.status})`;try{let y=await N.json();y.error&&(C=y.error);}catch{}throw new Error(C)}e?.(),r();}catch(f){d(f instanceof Error?f.message:"Upload failed");}finally{a(false);}};return jsxRuntime.jsx(ee,{title:"Upload skill",onClose:r,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{onDragOver:g=>{g.preventDefault(),c(true);},onDragLeave:()=>c(false),onDrop:g=>{g.preventDefault(),c(false);let f=g.dataTransfer.files[0];f&&u(f);},onClick:()=>s.current?.click(),className:k("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",o?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsxRuntime.jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsxRuntime.jsx(Y,{size:20,className:"text-muted-foreground"})}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:t?"Uploading...":"Drag and drop or click to upload"})]}),jsxRuntime.jsx("input",{ref:s,type:"file",accept:".md,.zip,.skill,.txt,.yml,.yaml",className:"hidden","aria-label":"Upload skill file",onChange:g=>{let f=g.target.files?.[0];f&&u(f);}}),l&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:l}),jsxRuntime.jsxs("div",{className:"space-y-2 text-xs text-muted-foreground",children:[jsxRuntime.jsx("p",{className:"font-medium text-foreground/70",children:"File requirements"}),jsxRuntime.jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[jsxRuntime.jsx("li",{children:".md file must contain skill name and description formatted in YAML"}),jsxRuntime.jsx("li",{children:".zip or .skill file must include a SKILL.md file"})]})]})]})})}function Te({onClose:r,onSelect:e}){let i=X(),s=react.useRef(null),o=react.useRef(r);o.current=r,react.useEffect(()=>{if(i)return;let t=a=>{s.current&&a.target instanceof Node&&!s.current.contains(a.target)&&o.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[i]);let c=[{id:"create-with-geoff",icon:jsxRuntime.jsx(ke,{}),label:"Create with Geoff"},{id:"write",icon:jsxRuntime.jsx(Ne,{}),label:"Write skill instructions"},{id:"upload",icon:jsxRuntime.jsx(Re,{}),label:"Upload a skill"}];return i?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full rounded-t-2xl bg-[#1a1a1a] p-4 pb-8 animate-in slide-in-from-bottom duration-200",onClick:t=>t.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),c.map(t=>jsxRuntime.jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-800",children:[t.icon,t.label]},t.id))]})]}):jsxRuntime.jsx("div",{ref:s,className:"absolute right-2 top-11 z-50 w-56 overflow-hidden rounded-xl border border-zinc-700 bg-[#2a2a2a] shadow-xl animate-in fade-in zoom-in-95 duration-100",children:c.map(t=>jsxRuntime.jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[t.icon,t.label]},t.id))})}function Ee({entry:r,selected:e,onSelect:i,depth:s=0}){return jsxRuntime.jsxs("button",{onClick:()=>i(r),className:k("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+s*16}px`},children:[jsxRuntime.jsx("span",{className:"truncate flex-1",children:r.path.split("/").pop()}),r.isDir&&jsxRuntime.jsx(Q,{className:"ml-auto text-muted-foreground"})]})}function Me({repo:r,selected:e,expanded:i,onSelect:s,onToggle:o,children:c}){return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>{s(),o();},className:k("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsxRuntime.jsx(Q,{open:i}),jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4 shrink-0"}),jsxRuntime.jsx("span",{className:"truncate",children:r.name})]}),i&&c]})}function ze({entry:r,content:e,loading:i,repoName:s}){let[o,c]=react.useState(false),t=react.useRef(null);react.useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[a,l]=react.useState(false),d=async()=>{if(e)try{await navigator.clipboard.writeText(e),c(!0),l(!1),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>c(!1),2e3);}catch{l(true),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>l(false),2e3);}};if(!r)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(i)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let u=r.path.split("/").pop()||r.path,p=/\.(md|mdx)$/i.test(u);return jsxRuntime.jsxs("div",{className:"flex h-full flex-col px-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[jsxRuntime.jsx("h3",{className:"text-sm sm:text-lg font-semibold text-foreground",children:u}),jsxRuntime.jsx("button",{onClick:d,"aria-label":"Copy file content",className:k("rounded p-1 transition-colors",o?"text-green-500":a?"text-red-500":"text-muted-foreground hover:text-foreground"),children:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"})})})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-auto p-4",children:p?jsxRuntime.jsx(B,{content:e||""}):jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function $e({config:r,category:e,className:i,style:s}){let{repos:o,loading:c,error:t,refresh:a}=Z(r),[l,d]=react.useState(null),[u,p]=react.useState(null),[g,f]=react.useState(null),[w,S]=react.useState(null),[N,C]=react.useState(false),[y,U]=react.useState(""),[te,D]=react.useState(false),[O,j]=react.useState(false),[F,$]=react.useState(null),re=o.find(h=>h.repo_id===l),{entries:ne,getFileContent:H}=W(r,u),V=o.filter(h=>!y||h.name.toLowerCase().includes(y.toLowerCase())),se=react.useCallback(async h=>{if(!h.isDir){f(h),C(true);try{let R=await H(h.cid);S(R);}catch(R){let ae=R instanceof Error?R.message:"Unknown error";S(`Failed to load file: ${ae}`);}finally{C(false);}}},[H]);react.useEffect(()=>{o.length>0&&!l&&(d(o[0].repo_id),p(o[0].repo_id));},[o,l]);let oe=h=>{h==="create-with-geoff"?window.open(`https://www.geoff.ai/?p=${encodeURIComponent("Let's create a skill together using your skill-creator skill. First ask me what the skill should do.")}`,"_blank","noopener,noreferrer"):$(h);};return jsxRuntime.jsxs("div",{className:k("flex flex-1 h-full min-h-0",i),style:s,children:[jsxRuntime.jsxs("div",{className:"relative flex w-96 shrink-0 flex-col border-r",children:[jsxRuntime.jsx("div",{className:"flex h-12 items-center gap-2 px-3",children:te?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-md border bg-muted/50 px-2 py-1",children:[jsxRuntime.jsx(q,{size:16,className:"shrink-0 text-muted-foreground"}),jsxRuntime.jsx("input",{type:"text",value:y,onChange:h=>U(h.target.value),placeholder:"Search",autoFocus:true,"aria-label":"Search items",className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),jsxRuntime.jsx("button",{onClick:()=>{D(false),U("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(L,{size:16})})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground capitalize",children:e||"Items"}),jsxRuntime.jsx("button",{onClick:()=>D(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsxRuntime.jsx(q,{size:20})}),jsxRuntime.jsx("button",{onClick:()=>j(!O),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(Y,{size:20})})]})}),O&&jsxRuntime.jsx(Te,{onClose:()=>j(false),onSelect:oe}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:c?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):t?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:t}):V.length===0?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:y?"No matching items":"No items yet"}):jsxRuntime.jsx("div",{className:"space-y-0.5",children:V.map(h=>jsxRuntime.jsx(Me,{repo:h,selected:l===h.repo_id,expanded:u===h.repo_id,onSelect:()=>{d(h.repo_id),f(null),S(null);},onToggle:()=>p(u===h.repo_id?null:h.repo_id),children:jsxRuntime.jsx("div",{className:"ml-10 pl-1",children:ne.map(R=>jsxRuntime.jsx(Ee,{entry:R,selected:g?.path===R.path,onSelect:se,depth:R.path.split("/").length-1},R.path))})},h.repo_id))})})]}),jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntime.jsx(ze,{entry:g,content:w,loading:N,repoName:re?.name||""})}),F==="write"&&jsxRuntime.jsx(Ce,{config:r,onClose:()=>$(null),onCreated:a}),F==="upload"&&jsxRuntime.jsx(Se,{config:r,onClose:()=>$(null),onCreated:a})]})}
|
|
10
|
+
exports.Markdown=B;exports.RackBrowser=$e;
|
package/dist/components/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
|
|
2
|
-
`),
|
|
3
|
-
`),lang:
|
|
1
|
+
import {useState,useCallback,useEffect,useRef,useMemo}from'react';import {Loader2,FileText}from'lucide-react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsx,jsxs,Fragment}from'react/jsx-runtime';function k(...r){return twMerge(clsx(r))}async function v(r,e,i,s){let o={"Content-Type":"application/json",...i?.headers};s&&(o.Authorization=`Bearer ${s}`);let c=await fetch(`${r}${e}`,{...i,headers:o});if(!c.ok){let t=`HTTP ${c.status}`;try{let a=await c.json();a.error&&(t=a.error);}catch{}throw new Error(t)}return c.json()}function P(r){let e=r.indexOf(":");return {mode:r.slice(0,e),cid:r.slice(e+1)}}function M(r){let e=r.apiBaseUrl,i=r.authorMid,s=r.ownerMid,o=r.apiKey,c=r.stacknetUrl||r.apiBaseUrl;return useMemo(()=>({async listRepos(t){let a=t||s?`?owner=${encodeURIComponent(t||s)}`:"";return (await v(e,`/api/rack/repos${a}`,void 0,o)).repos||[]},async initRepo(t){return v(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...t,owner_mid:s})},o)},async push(t,a){return v(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...a,author_mid:i})},o)},async getTree(t,a="main"){let l=await v(e,`/api/rack/${t}/tree/${a}`,void 0,o);return {tree:l.tree,commit_cid:l.commit_cid}},async getBlob(t,a){return (await v(e,`/api/rack/${t}/blob/${a}`,void 0,o)).content},async getLog(t,a,l){let d=new URLSearchParams;a&&d.set("ref",a),l&&d.set("max_count",String(l));let u=d.toString()?`?${d}`:"";return (await v(e,`/api/rack/${t}/log${u}`,void 0,o)).commits||[]},async getBranches(t){return (await v(e,`/api/rack/${t}/branches`,void 0,o)).branches||[]},async createBranch(t,a,l){return v(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:a,from_ref:l})},o)},async merge(t,a,l){return v(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:a,target_branch:l})},o)},async getDiff(t,a,l){return (await v(e,`/api/rack/${t}/diff/${a}/${l}`,void 0,o)).diff?.entries||[]},async starRepo(t){return v(e,`/api/rack/${t}/star`,{method:"POST"},o)},async unstarRepo(t){return v(e,`/api/rack/${t}/star`,{method:"DELETE"},o)},async getStarInfo(t){return v(e,`/api/rack/${t}/stars`,void 0,o)},async getSkillStats(t){let a={meta:null,tokenCount:null,usageCount:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return a;if(l.entries["META.json"]){let p=P(l.entries["META.json"]).cid,g=await this.getBlob(t,p);a.meta=JSON.parse(g);}let d=0,u=Object.values(l.entries).map(async p=>{try{let g=P(p).cid,f=await this.getBlob(t,g);d+=f.length;}catch{}});await Promise.all(u),d>0&&(a.tokenCount=Math.ceil(d/4)),a.meta?.skill_id&&(a.usageCount=await this.getSkillUsageCount(a.meta.skill_id));}catch{}return a},async getSkillUsageCount(t){try{let a=await fetch(`${c}/v1/skills/${encodeURIComponent(t)}`);if(a.ok){let d=await a.json();return d.usage_count??d.usageCount??null}let l=await fetch(`${c}/v1/skills?scope=public`);if(l.ok){let u=((await l.json()).skills||[]).find(p=>p.name===t||p.id===t);if(u)return u.usage_count??u.usageCount??0}return 0}catch{return null}},async getTensorStats(t){let a={meta:null,sizeMB:null};try{let{tree:l}=await this.getTree(t,"main");if(!l?.entries)return a;if(l.entries["TENSOR_META.json"]){let d=P(l.entries["TENSOR_META.json"]).cid,u=await this.getBlob(t,d);a.meta=JSON.parse(u),a.sizeMB=a.meta?.tensor_size_mb??null;}}catch{}return a},async getNetworkStats(){try{return (await v(e,"/api/rack/stats",void 0,o)).stats||null}catch{return null}},async getTrending(t=5,a=1){try{return (await v(e,`/api/rack/trending?limit=${t}&days=${a}`,void 0,o)).trending||[]}catch{return []}}}),[e,i,s,o,c])}function Z(r){let e=M(r),i=useRef(e);i.current=e;let[s,o]=useState([]),[c,t]=useState(true),[a,l]=useState(null),d=useRef(true),u=useRef(null),p=useCallback(async()=>{u.current?.abort();let g=new AbortController;u.current=g;try{d.current&&(t(!0),l(null));let f=await i.current.listRepos();d.current&&!g.signal.aborted&&o(f);}catch(f){d.current&&!g.signal.aborted&&l(f instanceof Error?f.message:"Failed to load repos");}finally{d.current&&!g.signal.aborted&&t(false);}},[]);return useEffect(()=>(d.current=true,p(),()=>{d.current=false,u.current?.abort();}),[p]),{repos:s,loading:c,error:a,refresh:p}}function ge(r){return Object.entries(r).map(([e,i])=>{let s=i.indexOf(":"),o=s>0?i.slice(0,s):"100644",c=s>0?i.slice(s+1):i;return {path:e,mode:o,cid:c,isDir:o==="040000"}}).sort((e,i)=>e.isDir!==i.isDir?e.isDir?-1:1:e.path.localeCompare(i.path))}function W(r,e,i="main"){let s=M(r),[o,c]=useState([]),[t,a]=useState(false),[l,d]=useState(null),u=useRef(true),p=useCallback(async()=>{if(e)try{u.current&&(a(!0),d(null));let{tree:f}=await s.getTree(e,i);u.current&&c(ge(f.entries));}catch(f){u.current&&d(f instanceof Error?f.message:"Failed to load tree");}finally{u.current&&a(false);}},[s,e,i]);useEffect(()=>(u.current=true,p(),()=>{u.current=false;}),[p]);let g=useCallback(async f=>{if(!e)throw new Error("No repo selected");return s.getBlob(e,f)},[s,e]);return {entries:o,loading:t,error:l,refresh:p,getFileContent:g}}var pe=/^(https?:\/\/|mailto:|\/[^/])/i;function he(r){let e=r.trim();return pe.test(e)?e:null}function z(r){let e=[],i=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,s=0,o,c=0;for(;(o=i.exec(r))!==null;){o.index>s&&e.push(r.slice(s,o.index));let t=`i${c++}`;if(o[1])e.push(jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[0.85em] font-mono text-pink-400",children:o[1].slice(1,-1)},t));else if(o[2])e.push(jsx("strong",{children:o[3]},t));else if(o[4])e.push(jsx("em",{children:o[5]},t));else if(o[6])e.push(jsx("em",{children:o[7]},t));else if(o[8]){let a=he(o[10]);a?e.push(jsx("a",{href:a,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:o[9]},t)):e.push(o[9]);}s=o.index+o[0].length;}return s<r.length&&e.push(r.slice(s)),e.length>0?e:[r]}function xe(r){let e=r.split(`
|
|
2
|
+
`),i=[],s=0;for(;s<e.length;){let o=e[s];if(o.trim()===""){s++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(o.trim())){i.push({type:"hr"}),s++;continue}let c=o.match(/^(#{1,6})\s+(.+)/);if(c){i.push({type:"heading",level:c[1].length,content:c[2]}),s++;continue}if(o.trim().startsWith("```")){let a=o.trim().slice(3).trim(),l=[];for(s++;s<e.length&&!e[s].trim().startsWith("```");)l.push(e[s]),s++;i.push({type:"code",content:l.join(`
|
|
3
|
+
`),lang:a||void 0}),s++;continue}if(/^\s*[-*+]\s/.test(o)){let a=[];for(;s<e.length&&/^\s*[-*+]\s/.test(e[s]);)a.push(e[s].replace(/^\s*[-*+]\s+/,"")),s++;i.push({type:"ul",items:a});continue}if(/^\s*\d+[.)]\s/.test(o)){let a=[];for(;s<e.length&&/^\s*\d+[.)]\s/.test(e[s]);)a.push(e[s].replace(/^\s*\d+[.)]\s+/,"")),s++;i.push({type:"ol",items:a});continue}let t=[];for(;s<e.length&&e[s].trim()!==""&&!e[s].match(/^#{1,6}\s/)&&!e[s].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[s])&&!/^\s*\d+[.)]\s/.test(e[s]);)t.push(e[s]),s++;t.length>0&&i.push({type:"paragraph",content:t.join(" ")});}return i}var ve={1:"text-2xl font-bold mt-6 mb-3",2:"text-xl font-bold mt-5 mb-2",3:"text-lg font-semibold mt-4 mb-2",4:"text-base font-semibold mt-3 mb-1",5:"text-sm font-semibold mt-2 mb-1",6:"text-sm font-medium mt-2 mb-1"};function be(r,e){switch(r.type){case "hr":return jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let i=Math.min(Math.max(r.level||1,1),6),s=`h${i}`;return jsx(s,{className:k("text-foreground",ve[i]),children:z(r.content||"")},`b${e}`)}case "paragraph":return jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:z(r.content||"")},`b${e}`);case "code":return jsx("pre",{className:"mb-3 overflow-x-auto rounded-lg bg-muted p-4 text-sm font-mono leading-relaxed text-foreground",children:jsx("code",{children:r.content})},`b${e}`);case "ul":return jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:r.items?.map((i,s)=>jsx("li",{className:"leading-relaxed",children:z(i)},`li${e}-${s}`))},`b${e}`);case "ol":return jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:r.items?.map((i,s)=>jsx("li",{className:"leading-relaxed",children:z(i)},`li${e}-${s}`))},`b${e}`);default:return null}}function B({content:r,className:e}){let i=xe(r);return jsx("div",{className:k("text-sm",e),children:i.map((s,o)=>be(s,o))})}function Q({open:r,className:e}){return jsx("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:k("shrink-0 transition-transform duration-150",r?"rotate-0":"-rotate-90",e),children:jsx("path",{d:"M16.134 6.16a.5.5 0 1 1 .732.68l-6.5 7-.077.068a.5.5 0 0 1-.655-.068l-6.5-7-.062-.08a.5.5 0 0 1 .718-.667l.076.067L10 12.767z"})})}function q({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function L({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M15.147 4.146a.5.5 0 0 1 .707.707L10.707 10l5.147 5.147a.5.5 0 0 1-.63.771l-.078-.064L10 10.707l-5.146 5.147a.5.5 0 0 1-.708-.707L9.293 10 4.146 4.853a.5.5 0 0 1 .708-.707L10 9.293z"})})}function Y({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M10 3a.5.5 0 0 1 .5.5v6h6l.1.01a.5.5 0 0 1 0 .98l-.1.01h-6v6a.5.5 0 0 1-1 0v-6h-6a.5.5 0 0 1 0-1h6v-6A.5.5 0 0 1 10 3"})})}function ke(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M6.5 3A2.5 2.5 0 0 0 4 5.5v9A2.5 2.5 0 0 0 6.5 17h7a2.5 2.5 0 0 0 2.5-2.5v-7A2.5 2.5 0 0 0 13.5 5H11V3.5a.5.5 0 0 0-1 0V5H6.5ZM5 5.5A1.5 1.5 0 0 1 6.5 4H9v1H6.5A1.5 1.5 0 0 0 5 6.5v8A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 13.5 6H11V4h2.5A2.5 2.5 0 0 1 16 6.5v8a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-9Z"})})}function Ne(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M5.5 3A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h9a2.5 2.5 0 0 0 2.5-2.5v-9A2.5 2.5 0 0 0 14.5 3h-9ZM4 5.5A1.5 1.5 0 0 1 5.5 4h9A1.5 1.5 0 0 1 16 5.5v9a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 4 14.5v-9ZM7 7.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5Z"})})}function Re(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M10 2a.5.5 0 0 1 .354.146l3 3a.5.5 0 0 1-.708.708L10.5 3.707V12.5a.5.5 0 0 1-1 0V3.707L7.354 5.854a.5.5 0 1 1-.708-.708l3-3A.5.5 0 0 1 10 2ZM4 13.5a.5.5 0 0 1 1 0v1A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-1a.5.5 0 0 1 1 0v1a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-1Z"})})}function X(){let[r,e]=useState(false);return useEffect(()=>{if(typeof window>"u")return;let i=()=>e(window.innerWidth<768);return i(),window.addEventListener("resize",i),()=>window.removeEventListener("resize",i)},[]),r}function ee({onClose:r,children:e,title:i}){let s=X(),o=useRef(r);return o.current=r,useEffect(()=>{let c=t=>{t.key==="Escape"&&o.current();};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[]),s?jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full max-h-[90vh] overflow-y-auto rounded-t-2xl bg-[#1a1a1a] p-5 pb-8 animate-in slide-in-from-bottom duration-200",onClick:c=>c.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-4 h-1 w-10 rounded-full bg-zinc-600"}),jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsx("h2",{className:"text-lg font-semibold text-foreground",children:i}),jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(L,{size:20})})]}),e]})]}):jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full max-w-lg overflow-y-auto rounded-2xl bg-[#1a1a1a] p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:c=>c.stopPropagation(),children:[jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsx("h2",{className:"text-lg font-semibold text-foreground",children:i}),jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(L,{size:20})})]}),e]})]})}function Ce({onClose:r,onCreated:e,config:i}){let[s,o]=useState(""),[c,t]=useState(""),[a,l]=useState(""),[d,u]=useState(false),[p,g]=useState(null);return jsx(ee,{title:"Write skill instructions",onClose:r,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsx("input",{id:"skill-name",value:s,onChange:w=>o(w.target.value),placeholder:"weekly-status-report",className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-desc",className:"text-sm text-muted-foreground",children:"Description"}),jsx("textarea",{id:"skill-desc",value:c,onChange:w=>t(w.target.value),placeholder:"Generate weekly status reports from recent work.",rows:3,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-instructions",className:"text-sm text-muted-foreground",children:"Instructions"}),jsx("textarea",{id:"skill-instructions",value:a,onChange:w=>l(w.target.value),placeholder:"Summarize my recent work in three sections: wins, blockers, and next steps.",rows:8,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),p&&jsx("p",{className:"text-sm text-red-500",children:p}),jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsx("button",{onClick:r,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsx("button",{onClick:async()=>{if(s.trim()){u(true),g(null);try{let w=i.apiBaseUrl||"",S=`# ${s.trim()}
|
|
4
4
|
|
|
5
|
-
${
|
|
5
|
+
${c.trim()}
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
${l.trim()}`,k=await fetch(`${v}/api/rack/${E}/push`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[{path:"SKILL.md",content:z}],message:"Initial skill definition",author_mid:s.authorMid})});if(!k.ok){let b=`Failed to save skill (${k.status})`;try{let y=await k.json();y.error&&(b=y.error);}catch{}throw new Error(b)}e?.(),n();}catch(v){u(v instanceof Error?v.message:"Failed to create skill");}finally{f(false);}}},disabled:p||!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:p?"Creating...":"Create"})]})]})})}function Ce({onClose:n,onCreated:e,config:s}){let r=useRef(null),[o,a]=useState(false),[i,l]=useState(false),[m,p]=useState(null),f=async u=>{l(true),p(null);try{let d=await u.text(),v=s.apiBaseUrl||"",N=u.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),E=await fetch(`${v}/api/rack/init`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:N,owner_mid:s.ownerMid,is_gitagent:!0})});if(!E.ok){let b=`Failed to create repo (${E.status})`;try{let y=await E.json();y.error&&(b=y.error);}catch{}throw new Error(b)}let{repo_id:z}=await E.json(),k=await fetch(`${v}/api/rack/${z}/push`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[{path:u.name,content:d}],message:`Upload ${u.name}`,author_mid:s.authorMid})});if(!k.ok){let b=`Upload failed (${k.status})`;try{let y=await k.json();y.error&&(b=y.error);}catch{}throw new Error(b)}e?.(),n();}catch(d){p(d instanceof Error?d.message:"Upload failed");}finally{l(false);}};return jsx(ee,{title:"Upload skill",onClose:n,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{onDragOver:u=>{u.preventDefault(),a(true);},onDragLeave:()=>a(false),onDrop:u=>{u.preventDefault(),a(false);let d=u.dataTransfer.files[0];d&&f(d);},onClick:()=>r.current?.click(),className:R("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",o?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsx(Y,{size:20,className:"text-muted-foreground"})}),jsx("p",{className:"text-sm text-muted-foreground",children:i?"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:u=>{let d=u.target.files?.[0];d&&f(d);}}),m&&jsx("p",{className:"text-sm text-red-500",children:m}),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 Ee({onClose:n,onSelect:e}){let s=X(),r=useRef(null),o=useRef(n);o.current=n,useEffect(()=>{if(s)return;let i=l=>{r.current&&l.target instanceof Node&&!r.current.contains(l.target)&&o.current();};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[s]);let a=[{id:"create-with-geoff",icon:jsx(ye,{}),label:"Create with Geoff"},{id:"write",icon:jsx(ke,{}),label:"Write skill instructions"},{id:"upload",icon:jsx(Ne,{}),label:"Upload a skill"}];return s?jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:n,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full rounded-t-2xl bg-[#1a1a1a] p-4 pb-8 animate-in slide-in-from-bottom duration-200",onClick:i=>i.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),a.map(i=>jsxs("button",{onClick:()=>{e(i.id),n();},className:"flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-800",children:[i.icon,i.label]},i.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:a.map(i=>jsxs("button",{onClick:()=>{e(i.id),n();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[i.icon,i.label]},i.id))})}function Te({entry:n,selected:e,onSelect:s,depth:r=0}){return jsxs("button",{onClick:()=>s(n),className:R("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+r*16}px`},children:[jsx("span",{className:"truncate flex-1",children:n.path.split("/").pop()}),n.isDir&&jsx(Q,{className:"ml-auto text-muted-foreground"})]})}function ze({repo:n,selected:e,expanded:s,onSelect:r,onToggle:o,children:a}){return jsxs("div",{children:[jsxs("button",{onClick:()=>{r(),o();},className:R("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsx(Q,{open:s}),jsx(FileText,{className:"h-4 w-4 shrink-0"}),jsx("span",{className:"truncate",children:n.name})]}),s&&a]})}function $e({entry:n,content:e,loading:s,repoName:r}){let[o,a]=useState(false),i=useRef(null);useEffect(()=>()=>{i.current&&clearTimeout(i.current);},[]);let[l,m]=useState(false),p=async()=>{if(e)try{await navigator.clipboard.writeText(e),a(!0),m(!1),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>a(!1),2e3);}catch{m(true),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>m(false),2e3);}};if(!n)return jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(s)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=n.path.split("/").pop()||n.path,x=/\.(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:p,"aria-label":"Copy file content",className:R("rounded p-1 transition-colors",o?"text-green-500":l?"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:x?jsx(B,{content:e||""}):jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function Me({config:n,category:e,className:s,style:r}){let{repos:o,loading:a,error:i,refresh:l}=Z(n),[m,p]=useState(null),[f,x]=useState(null),[u,d]=useState(null),[v,N]=useState(null),[E,z]=useState(false),[k,b]=useState(""),[y,U]=useState(false),[j,F]=useState(false),[O,L]=useState(null),te=o.find(g=>g.repo_id===m),{entries:re,getFileContent:H}=J(n,f),V=o.filter(g=>!k||g.name.toLowerCase().includes(k.toLowerCase())),ne=useCallback(async g=>{if(!g.isDir){d(g),z(true);try{let C=await H(g.cid);N(C);}catch(C){let se=C instanceof Error?C.message:"Unknown error";N(`Failed to load file: ${se}`);}finally{z(false);}}},[H]);useEffect(()=>{o.length>0&&!m&&(p(o[0].repo_id),x(o[0].repo_id));},[o,m]);let oe=g=>{g==="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"):L(g);};return jsxs("div",{className:R("flex flex-1 h-full min-h-0",s),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:y?jsxs(Fragment,{children:[jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-md border bg-muted/50 px-2 py-1",children:[jsx(q,{size:16,className:"shrink-0 text-muted-foreground"}),jsx("input",{type:"text",value:k,onChange:g=>b(g.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:()=>{U(false),b("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(D,{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:()=>U(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsx(q,{size:20})}),jsx("button",{onClick:()=>F(!j),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(Y,{size:20})})]})}),j&&jsx(Ee,{onClose:()=>F(false),onSelect:oe}),jsx("div",{className:"flex-1 overflow-y-auto p-2",children:a?jsx("div",{className:"flex items-center justify-center py-8",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):i?jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:i}):V.length===0?jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:k?"No matching items":"No items yet"}):jsx("div",{className:"space-y-0.5",children:V.map(g=>jsx(ze,{repo:g,selected:m===g.repo_id,expanded:f===g.repo_id,onSelect:()=>{p(g.repo_id),d(null),N(null);},onToggle:()=>x(f===g.repo_id?null:g.repo_id),children:jsx("div",{className:"ml-10 pl-1",children:re.map(C=>jsx(Te,{entry:C,selected:u?.path===C.path,onSelect:ne,depth:C.path.split("/").length-1},C.path))})},g.repo_id))})})]}),jsx("div",{className:"flex-1 min-w-0",children:jsx($e,{entry:u,content:v,loading:E,repoName:te?.name||""})}),O==="write"&&jsx(Re,{config:n,onClose:()=>L(null),onCreated:l}),O==="upload"&&jsx(Ce,{config:n,onClose:()=>L(null),onCreated:l})]})}
|
|
10
|
-
export{B as Markdown
|
|
9
|
+
${a.trim()}`,N=await fetch(`${w}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.trim(),description:c.trim(),skill_md:S,content_type:"code"})});if(!N.ok){let C=`Failed to register skill (${N.status})`;try{let y=await N.json();y.error&&(C=y.error);}catch{}throw new Error(C)}e?.(),r();}catch(w){g(w instanceof Error?w.message:"Failed to create skill");}finally{u(false);}}},disabled:d||!s.trim(),className:"rounded-lg bg-zinc-600 px-4 py-2 text-sm font-medium text-white hover:bg-zinc-500 disabled:opacity-50",children:d?"Creating...":"Create"})]})]})})}function Se({onClose:r,onCreated:e,config:i}){let s=useRef(null),[o,c]=useState(false),[t,a]=useState(false),[l,d]=useState(null),u=async g=>{a(true),d(null);try{let f=await g.text(),w=i.apiBaseUrl||"",S=g.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),N=await fetch(`${w}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:S,skill_md:f,content_type:"code"})});if(!N.ok){let C=`Failed to register skill (${N.status})`;try{let y=await N.json();y.error&&(C=y.error);}catch{}throw new Error(C)}e?.(),r();}catch(f){d(f instanceof Error?f.message:"Upload failed");}finally{a(false);}};return jsx(ee,{title:"Upload skill",onClose:r,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{onDragOver:g=>{g.preventDefault(),c(true);},onDragLeave:()=>c(false),onDrop:g=>{g.preventDefault(),c(false);let f=g.dataTransfer.files[0];f&&u(f);},onClick:()=>s.current?.click(),className:k("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",o?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsx(Y,{size:20,className:"text-muted-foreground"})}),jsx("p",{className:"text-sm text-muted-foreground",children:t?"Uploading...":"Drag and drop or click to upload"})]}),jsx("input",{ref:s,type:"file",accept:".md,.zip,.skill,.txt,.yml,.yaml",className:"hidden","aria-label":"Upload skill file",onChange:g=>{let f=g.target.files?.[0];f&&u(f);}}),l&&jsx("p",{className:"text-sm text-red-500",children:l}),jsxs("div",{className:"space-y-2 text-xs text-muted-foreground",children:[jsx("p",{className:"font-medium text-foreground/70",children:"File requirements"}),jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[jsx("li",{children:".md file must contain skill name and description formatted in YAML"}),jsx("li",{children:".zip or .skill file must include a SKILL.md file"})]})]})]})})}function Te({onClose:r,onSelect:e}){let i=X(),s=useRef(null),o=useRef(r);o.current=r,useEffect(()=>{if(i)return;let t=a=>{s.current&&a.target instanceof Node&&!s.current.contains(a.target)&&o.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[i]);let c=[{id:"create-with-geoff",icon:jsx(ke,{}),label:"Create with Geoff"},{id:"write",icon:jsx(Ne,{}),label:"Write skill instructions"},{id:"upload",icon:jsx(Re,{}),label:"Upload a skill"}];return i?jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full rounded-t-2xl bg-[#1a1a1a] p-4 pb-8 animate-in slide-in-from-bottom duration-200",onClick:t=>t.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),c.map(t=>jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-800",children:[t.icon,t.label]},t.id))]})]}):jsx("div",{ref:s,className:"absolute right-2 top-11 z-50 w-56 overflow-hidden rounded-xl border border-zinc-700 bg-[#2a2a2a] shadow-xl animate-in fade-in zoom-in-95 duration-100",children:c.map(t=>jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[t.icon,t.label]},t.id))})}function Ee({entry:r,selected:e,onSelect:i,depth:s=0}){return jsxs("button",{onClick:()=>i(r),className:k("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+s*16}px`},children:[jsx("span",{className:"truncate flex-1",children:r.path.split("/").pop()}),r.isDir&&jsx(Q,{className:"ml-auto text-muted-foreground"})]})}function Me({repo:r,selected:e,expanded:i,onSelect:s,onToggle:o,children:c}){return jsxs("div",{children:[jsxs("button",{onClick:()=>{s(),o();},className:k("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsx(Q,{open:i}),jsx(FileText,{className:"h-4 w-4 shrink-0"}),jsx("span",{className:"truncate",children:r.name})]}),i&&c]})}function ze({entry:r,content:e,loading:i,repoName:s}){let[o,c]=useState(false),t=useRef(null);useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[a,l]=useState(false),d=async()=>{if(e)try{await navigator.clipboard.writeText(e),c(!0),l(!1),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>c(!1),2e3);}catch{l(true),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>l(false),2e3);}};if(!r)return jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(i)return jsx("div",{className:"flex h-full items-center justify-center",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let u=r.path.split("/").pop()||r.path,p=/\.(md|mdx)$/i.test(u);return jsxs("div",{className:"flex h-full flex-col px-3",children:[jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[jsx("h3",{className:"text-sm sm:text-lg font-semibold text-foreground",children:u}),jsx("button",{onClick:d,"aria-label":"Copy file content",className:k("rounded p-1 transition-colors",o?"text-green-500":a?"text-red-500":"text-muted-foreground hover:text-foreground"),children:jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"})})})]}),jsx("div",{className:"flex-1 overflow-auto p-4",children:p?jsx(B,{content:e||""}):jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function $e({config:r,category:e,className:i,style:s}){let{repos:o,loading:c,error:t,refresh:a}=Z(r),[l,d]=useState(null),[u,p]=useState(null),[g,f]=useState(null),[w,S]=useState(null),[N,C]=useState(false),[y,U]=useState(""),[te,D]=useState(false),[O,j]=useState(false),[F,$]=useState(null),re=o.find(h=>h.repo_id===l),{entries:ne,getFileContent:H}=W(r,u),V=o.filter(h=>!y||h.name.toLowerCase().includes(y.toLowerCase())),se=useCallback(async h=>{if(!h.isDir){f(h),C(true);try{let R=await H(h.cid);S(R);}catch(R){let ae=R instanceof Error?R.message:"Unknown error";S(`Failed to load file: ${ae}`);}finally{C(false);}}},[H]);useEffect(()=>{o.length>0&&!l&&(d(o[0].repo_id),p(o[0].repo_id));},[o,l]);let oe=h=>{h==="create-with-geoff"?window.open(`https://www.geoff.ai/?p=${encodeURIComponent("Let's create a skill together using your skill-creator skill. First ask me what the skill should do.")}`,"_blank","noopener,noreferrer"):$(h);};return jsxs("div",{className:k("flex flex-1 h-full min-h-0",i),style:s,children:[jsxs("div",{className:"relative flex w-96 shrink-0 flex-col border-r",children:[jsx("div",{className:"flex h-12 items-center gap-2 px-3",children:te?jsxs(Fragment,{children:[jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-md border bg-muted/50 px-2 py-1",children:[jsx(q,{size:16,className:"shrink-0 text-muted-foreground"}),jsx("input",{type:"text",value:y,onChange:h=>U(h.target.value),placeholder:"Search",autoFocus:true,"aria-label":"Search items",className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),jsx("button",{onClick:()=>{D(false),U("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(L,{size:16})})]}):jsxs(Fragment,{children:[jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground capitalize",children:e||"Items"}),jsx("button",{onClick:()=>D(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsx(q,{size:20})}),jsx("button",{onClick:()=>j(!O),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(Y,{size:20})})]})}),O&&jsx(Te,{onClose:()=>j(false),onSelect:oe}),jsx("div",{className:"flex-1 overflow-y-auto p-2",children:c?jsx("div",{className:"flex items-center justify-center py-8",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):t?jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:t}):V.length===0?jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:y?"No matching items":"No items yet"}):jsx("div",{className:"space-y-0.5",children:V.map(h=>jsx(Me,{repo:h,selected:l===h.repo_id,expanded:u===h.repo_id,onSelect:()=>{d(h.repo_id),f(null),S(null);},onToggle:()=>p(u===h.repo_id?null:h.repo_id),children:jsx("div",{className:"ml-10 pl-1",children:ne.map(R=>jsx(Ee,{entry:R,selected:g?.path===R.path,onSelect:se,depth:R.path.split("/").length-1},R.path))})},h.repo_id))})})]}),jsx("div",{className:"flex-1 min-w-0",children:jsx(ze,{entry:g,content:w,loading:N,repoName:re?.name||""})}),F==="write"&&jsx(Ce,{config:r,onClose:()=>$(null),onCreated:a}),F==="upload"&&jsx(Se,{config:r,onClose:()=>$(null),onCreated:a})]})}
|
|
10
|
+
export{B as Markdown,$e as RackBrowser};
|
package/dist/hooks/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var react=require('react');async function m(i,e,s){let n=await fetch(`${i}${e}`,{...s,headers:{"Content-Type":"application/json",...s?.headers}});if(!n.ok){let r=`HTTP ${n.status}`;try{let t=await n.json();t.error&&(r=t.error);}catch{}throw new Error(r)}return n.json()}function R(i){let e=i.apiBaseUrl,s=i.authorMid,n=i.ownerMid;return react.useMemo(()=>({async listRepos(r){let t=r||n?`?owner=${encodeURIComponent(r||n)}`:"";return (await m(e,`/api/rack/repos${t}`)).repos||[]},async initRepo(r){return m(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...r,owner_mid:n})})},async push(r,t){return m(e,`/api/rack/${r}/push`,{method:"POST",body:JSON.stringify({...t,author_mid:s})})},async getTree(r,t="main"){let o=await m(e,`/api/rack/${r}/tree/${t}`);return {tree:o.tree,commit_cid:o.commit_cid}},async getBlob(r,t){return (await m(e,`/api/rack/${r}/blob/${t}`)).content},async getLog(r,t,o){let l=new URLSearchParams;t&&l.set("ref",t),o&&l.set("max_count",String(o));let g=l.toString()?`?${l}`:"";return (await m(e,`/api/rack/${r}/log${g}`)).commits||[]},async getBranches(r){return (await m(e,`/api/rack/${r}/branches`)).branches||[]},async getDiff(r,t,o){return (await m(e,`/api/rack/${r}/diff/${t}/${o}`)).diff?.entries||[]}}),[e,s,n])}function T(i){let e=R(i),s=react.useRef(e);s.current=e;let[n,r]=react.useState([]),[t,o]=react.useState(true),[l,g]=react.useState(null),c=react.useRef(true),u=react.useRef(null),p=react.useCallback(async()=>{u.current?.abort();let f=new AbortController;u.current=f;try{c.current&&(o(!0),g(null));let a=await s.current.listRepos();c.current&&!f.signal.aborted&&r(a);}catch(a){c.current&&!f.signal.aborted&&g(a instanceof Error?a.message:"Failed to load repos");}finally{c.current&&!f.signal.aborted&&o(false);}},[]);return react.useEffect(()=>(c.current=true,p(),()=>{c.current=false,u.current?.abort();}),[p]),{repos:n,loading:t,error:l,refresh:p}}function I(i){return Object.entries(i).map(([e,s])=>{let n=s.indexOf(":"),r=n>0?s.slice(0,n):"100644",t=n>0?s.slice(n+1):s;return {path:e,mode:r,cid:t,isDir:r==="040000"}}).sort((e,s)=>e.isDir!==s.isDir?e.isDir?-1:1:e.path.localeCompare(s.path))}function x(i,e,s="main"){let n=R(i),[r,t]=react.useState([]),[o,l]=react.useState(false),[g,c]=react.useState(null),u=react.useRef(true),p=react.useCallback(async()=>{if(e)try{u.current&&(l(!0),c(null));let{tree:a}=await n.getTree(e,s);u.current&&t(I(a.entries));}catch(a){u.current&&c(a instanceof Error?a.message:"Failed to load tree");}finally{u.current&&l(false);}},[n,e,s]);react.useEffect(()=>(u.current=true,p(),()=>{u.current=false;}),[p]);let f=react.useCallback(async a=>{if(!e)throw new Error("No repo selected");return n.getBlob(e,a)},[n,e]);return {entries:r,loading:o,error:g,refresh:p,getFileContent:f}}function U(i){let e=R(i),[s,n]=react.useState(false),[r,t]=react.useState(null),o=react.useRef(true);return react.useEffect(()=>(o.current=true,()=>{o.current=false;}),[]),{push:react.useCallback(async(g,c,u,p)=>{try{return o.current&&(n(!0),t(null)),await e.push(g,{files:c,message:u,branch:p})}catch(f){let a=f instanceof Error?f.message:"Push failed";return o.current&&t(a),null}finally{o.current&&n(false);}},[e]),pushing:s,error:r}}exports.useRackClient=R;exports.useRepoPush=U;exports.useRepoTree=x;exports.useRepos=T;
|
|
1
|
+
'use strict';var react=require('react');async function d(u,t,i,l){let c={"Content-Type":"application/json",...i?.headers};l&&(c.Authorization=`Bearer ${l}`);let g=await fetch(`${u}${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 k(u){let t=u.indexOf(":");return {mode:u.slice(0,t),cid:u.slice(t+1)}}function p(u){let t=u.apiBaseUrl,i=u.authorMid,l=u.ownerMid,c=u.apiKey,g=u.stacknetUrl||u.apiBaseUrl;return react.useMemo(()=>({async listRepos(e){let r=e||l?`?owner=${encodeURIComponent(e||l)}`:"";return (await d(t,`/api/rack/repos${r}`,void 0,c)).repos||[]},async initRepo(e){return d(t,"/api/rack/init",{method:"POST",body:JSON.stringify({...e,owner_mid:l})},c)},async push(e,r){return d(t,`/api/rack/${e}/push`,{method:"POST",body:JSON.stringify({...r,author_mid:i})},c)},async getTree(e,r="main"){let n=await d(t,`/api/rack/${e}/tree/${r}`,void 0,c);return {tree:n.tree,commit_cid:n.commit_cid}},async getBlob(e,r){return (await d(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 d(t,`/api/rack/${e}/log${a}`,void 0,c)).commits||[]},async getBranches(e){return (await d(t,`/api/rack/${e}/branches`,void 0,c)).branches||[]},async createBranch(e,r,n){return d(t,`/api/rack/${e}/branch`,{method:"POST",body:JSON.stringify({branch_name:r,from_ref:n})},c)},async merge(e,r,n){return d(t,`/api/rack/${e}/merge`,{method:"POST",body:JSON.stringify({source_branch:r,target_branch:n})},c)},async getDiff(e,r,n){return (await d(t,`/api/rack/${e}/diff/${r}/${n}`,void 0,c)).diff?.entries||[]},async starRepo(e){return d(t,`/api/rack/${e}/star`,{method:"POST"},c)},async unstarRepo(e){return d(t,`/api/rack/${e}/star`,{method:"DELETE"},c)},async getStarInfo(e){return d(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 o=k(n.entries["META.json"]).cid,f=await this.getBlob(e,o);r.meta=JSON.parse(f);}let s=0,a=Object.values(n.entries).map(async o=>{try{let f=k(o).cid,m=await this.getBlob(e,f);s+=m.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(o=>o.name===e||o.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=k(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 getNetworkStats(){try{return (await d(t,"/api/rack/stats",void 0,c)).stats||null}catch{return null}},async getTrending(e=5,r=1){try{return (await d(t,`/api/rack/trending?limit=${e}&days=${r}`,void 0,c)).trending||[]}catch{return []}}}),[t,i,l,c,g])}function J(u){let t=p(u),i=react.useRef(t);i.current=t;let[l,c]=react.useState([]),[g,e]=react.useState(true),[r,n]=react.useState(null),s=react.useRef(true),a=react.useRef(null),o=react.useCallback(async()=>{a.current?.abort();let f=new AbortController;a.current=f;try{s.current&&(e(!0),n(null));let m=await i.current.listRepos();s.current&&!f.signal.aborted&&c(m);}catch(m){s.current&&!f.signal.aborted&&n(m instanceof Error?m.message:"Failed to load repos");}finally{s.current&&!f.signal.aborted&&e(false);}},[]);return react.useEffect(()=>(s.current=true,o(),()=>{s.current=false,a.current?.abort();}),[o]),{repos:l,loading:g,error:r,refresh:o}}function H(u){return Object.entries(u).map(([t,i])=>{let l=i.indexOf(":"),c=l>0?i.slice(0,l):"100644",g=l>0?i.slice(l+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 W(u,t,i="main"){let l=p(u),[c,g]=react.useState([]),[e,r]=react.useState(false),[n,s]=react.useState(null),a=react.useRef(true),o=react.useCallback(async()=>{if(t)try{a.current&&(r(!0),s(null));let{tree:m}=await l.getTree(t,i);a.current&&g(H(m.entries));}catch(m){a.current&&s(m instanceof Error?m.message:"Failed to load tree");}finally{a.current&&r(false);}},[l,t,i]);react.useEffect(()=>(a.current=true,o(),()=>{a.current=false;}),[o]);let f=react.useCallback(async m=>{if(!t)throw new Error("No repo selected");return l.getBlob(t,m)},[l,t]);return {entries:c,loading:e,error:n,refresh:o,getFileContent:f}}function Q(u){let t=p(u),[i,l]=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,o)=>{try{return e.current&&(l(!0),g(null)),await t.push(n,{files:s,message:a,branch:o})}catch(f){let m=f instanceof Error?f.message:"Push failed";return e.current&&g(m),null}finally{e.current&&l(false);}},[t]),pushing:i,error:c}}var w="stacknet-rack-apikey";function X(u){let t=u.stacknetUrl||u.apiBaseUrl,[i,l]=react.useState({authenticated:false}),[c,g]=react.useState(null),[e,r]=react.useState(false),n=react.useCallback(f=>({"Content-Type":"application/json",...f||u.apiKey?{Authorization:`Bearer ${f||u.apiKey}`}:{}}),[u.apiKey]),s=react.useCallback(async f=>{r(true);try{let m=await fetch(`${t}/health`,{headers:n(f)});if(!m.ok)throw new Error(`Authentication failed: ${m.status}`);let R={authenticated:!0,apiKey:f,permission:f.startsWith("gk_")?"write":"read"};l(R);try{localStorage.setItem(w,f);}catch{}return R}catch(m){throw l({authenticated:false}),m}finally{r(false);}},[t,n]),a=react.useCallback(()=>{l({authenticated:false}),g(null);try{localStorage.removeItem(w);}catch{}},[]),o=react.useCallback(async()=>{let f=i.apiKey||u.apiKey;if(!f)return null;try{let m=await fetch(`${t}/network/usage`,{headers:n(f)});if(!m.ok)return null;let R=await m.json(),I={planAllocation:R.plan_allocation??R.planAllocation??0,inferenceUsed:R.inference_used??R.inferenceUsed??0,ledgerSpent:R.ledger_spent??R.ledgerSpent??0,totalUsed:R.total_used??R.totalUsed??0,remaining:R.remaining??0,percent:R.percent??0,exceeded:R.exceeded??!1};return g(I),I}catch{return null}},[i.apiKey,u.apiKey,t,n]);return react.useEffect(()=>{let f=u.apiKey;if(f){l({authenticated:true,apiKey:f,permission:f.startsWith("gk_")?"write":"read"});return}try{let m=localStorage.getItem(w);m&&l({authenticated:!0,apiKey:m,permission:m.startsWith("gk_")?"write":"read"});}catch{}},[u.apiKey]),{session:i,budget:c,loading:e,login:s,logout:a,refreshBudget:o}}var B=1e3,M=1e3,j=100;function L(u,t){if(u==="skill"){let c=j+Math.ceil(t/4);return {type:u,totalBytes:t,totalMegabytes:t/1e6,baseCost:c,multiplier:B,registrationCostTokens:c*B}}let i=Math.ceil(t/1e6),l=j+i;return {type:u,totalBytes:t,totalMegabytes:i,baseCost:l,multiplier:M,registrationCostTokens:l*M}}function Z(u){let t=u.stacknetUrl||u.apiBaseUrl,i=u.apiKey,[l,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 a=>{c(true),e(null);try{let o=await fetch(`${t}/skills`,{method:"POST",headers:r(),body:JSON.stringify(a)});if(!o.ok){let f=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(f.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 a=>{c(true),e(null);try{let o=await fetch(`${t}/tensors`,{method:"POST",headers:r(),body:JSON.stringify(a)});if(!o.ok){let f=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(f.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,estimateCost:L,registering:l,error:g}}function nt(u,t){let i=p(u),[l,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 o=await i.getSkillStats(t);s.current&&c(o);}catch(o){s.current&&n(o.message);}finally{s.current&&e(false);}}},[i,t]);return react.useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:l,loading:g,error:r,refresh:a}}function it(u,t){let i=p(u),[l,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 o=await i.getTensorStats(t);s.current&&c(o);}catch(o){s.current&&n(o.message);}finally{s.current&&e(false);}}},[i,t]);return react.useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:l,loading:g,error:r,refresh:a}}function ft(u){let t=p(u),[i,l]=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&&l(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 dt(u,t=5,i=1){let l=p(u),[c,g]=react.useState([]),[e,r]=react.useState(false),[n,s]=react.useState(null),a=react.useRef(true),o=react.useCallback(async f=>{r(true),s(null);try{let m=await l.getTrending(t,f??i);a.current&&g(m);}catch(m){a.current&&s(m.message);}finally{a.current&&r(false);}},[l,t,i]);return react.useEffect(()=>(a.current=true,o(),()=>{a.current=false;}),[o]),{repos:c,loading:e,error:n,refresh:o}}function kt(u,t){let i=p(u),[l,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 f=await i.getStarInfo(t);s.current&&c(f);}catch{}},[i,t]);react.useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]);let o=react.useCallback(async()=>{if(t){e(true),n(null);try{let f=l.starred?await i.unstarRepo(t):await i.starRepo(t);s.current&&c({stars:f.stars,starred:f.starred,repo_id:t});}catch(f){s.current&&n(f.message);}finally{s.current&&e(false);}}},[i,t,l.starred]);return {...l,loading:g,error:r,toggle:o,refresh:a}}exports.estimateCost=L;exports.useNetworkStats=ft;exports.useRackClient=p;exports.useRackRegister=Z;exports.useRackSession=X;exports.useRepoPush=Q;exports.useRepoTree=W;exports.useRepos=J;exports.useSkillStats=nt;exports.useStar=kt;exports.useTensorStats=it;exports.useTrending=dt;
|
package/dist/hooks/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RepoInfo, InitResult, RepoFile, PushResult, RepoTree, RepoCommit, DiffEntry, RackConfig, TreeEntry } from '../types/index.cjs';
|
|
1
|
+
import { RepoInfo, InitResult, RepoFile, PushResult, RepoTree, RepoCommit, DiffEntry, StarResult, StarInfo, SkillStats, TensorStats, NetworkStats, TrendingRepo, RackConfig, TreeEntry, RackSession, TokenBudget, CostEstimate, SkillRegistrationInput, SkillRegistrationResult, TensorRegistrationInput, TensorRegistrationResult } from '../types/index.cjs';
|
|
2
2
|
|
|
3
3
|
interface RackClient {
|
|
4
4
|
listRepos: (owner?: string) => Promise<RepoInfo[]>;
|
|
@@ -19,11 +19,28 @@ interface RackClient {
|
|
|
19
19
|
getBlob: (repoId: string, cid: string) => Promise<string>;
|
|
20
20
|
getLog: (repoId: string, ref?: string, maxCount?: number) => Promise<RepoCommit[]>;
|
|
21
21
|
getBranches: (repoId: string) => Promise<string[]>;
|
|
22
|
+
createBranch: (repoId: string, branchName: string, fromRef?: string) => Promise<{
|
|
23
|
+
success: boolean;
|
|
24
|
+
manifest_cid: string;
|
|
25
|
+
}>;
|
|
26
|
+
merge: (repoId: string, sourceBranch: string, targetBranch?: string) => Promise<{
|
|
27
|
+
success: boolean;
|
|
28
|
+
commit_cid?: string;
|
|
29
|
+
error?: string;
|
|
30
|
+
}>;
|
|
22
31
|
getDiff: (repoId: string, fromRef: string, toRef: string) => Promise<DiffEntry[]>;
|
|
32
|
+
starRepo: (repoId: string) => Promise<StarResult>;
|
|
33
|
+
unstarRepo: (repoId: string) => Promise<StarResult>;
|
|
34
|
+
getStarInfo: (repoId: string) => Promise<StarInfo>;
|
|
35
|
+
getSkillStats: (repoId: string) => Promise<SkillStats>;
|
|
36
|
+
getSkillUsageCount: (skillId: string) => Promise<number | null>;
|
|
37
|
+
getTensorStats: (repoId: string) => Promise<TensorStats>;
|
|
38
|
+
getNetworkStats: () => Promise<NetworkStats | null>;
|
|
39
|
+
getTrending: (limit?: number, days?: number) => Promise<TrendingRepo[]>;
|
|
23
40
|
}
|
|
24
41
|
/**
|
|
25
42
|
* Low-level hook returning a rack API client.
|
|
26
|
-
* All methods route through the host app's proxy.
|
|
43
|
+
* All methods route through the host app's proxy or direct StackNet URL.
|
|
27
44
|
*/
|
|
28
45
|
declare function useRackClient(config: RackConfig): RackClient;
|
|
29
46
|
|
|
@@ -51,4 +68,91 @@ interface UseRepoPushReturn {
|
|
|
51
68
|
}
|
|
52
69
|
declare function useRepoPush(config: RackConfig): UseRepoPushReturn;
|
|
53
70
|
|
|
54
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Session hook for authenticated Rack operations.
|
|
73
|
+
* Manages API key persistence, session validation, and token budget.
|
|
74
|
+
*/
|
|
75
|
+
declare function useRackSession(config: RackConfig): {
|
|
76
|
+
session: RackSession;
|
|
77
|
+
budget: TokenBudget | null;
|
|
78
|
+
loading: boolean;
|
|
79
|
+
login: (apiKey: string) => Promise<RackSession>;
|
|
80
|
+
logout: () => void;
|
|
81
|
+
refreshBudget: () => Promise<TokenBudget | null>;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Estimate registration cost before committing.
|
|
86
|
+
*
|
|
87
|
+
* Skills: (INIT_COST + ceil(totalBytes / 4)) × 1000
|
|
88
|
+
* Tensors: (INIT_COST + ceil(totalMB)) × 1000 (MB-level, not token-level)
|
|
89
|
+
*/
|
|
90
|
+
declare function estimateCost(type: 'skill' | 'tensor', totalBytes: number): CostEstimate;
|
|
91
|
+
/**
|
|
92
|
+
* Hook for registering skills and tensors on StackNet.
|
|
93
|
+
* Requires an authenticated session (API key).
|
|
94
|
+
*/
|
|
95
|
+
declare function useRackRegister(config: RackConfig): {
|
|
96
|
+
registerSkill: (input: SkillRegistrationInput) => Promise<SkillRegistrationResult>;
|
|
97
|
+
registerTensor: (input: TensorRegistrationInput) => Promise<TensorRegistrationResult>;
|
|
98
|
+
estimateCost: typeof estimateCost;
|
|
99
|
+
registering: boolean;
|
|
100
|
+
error: string | null;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Fetch skill stats (META.json, token count, usage count) for a skill repo.
|
|
105
|
+
*/
|
|
106
|
+
declare function useSkillStats(config: RackConfig, repoId: string | null): {
|
|
107
|
+
stats: SkillStats;
|
|
108
|
+
loading: boolean;
|
|
109
|
+
error: string | null;
|
|
110
|
+
refresh: () => Promise<void>;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Fetch tensor stats (TENSOR_META.json, file size) for a tensor repo.
|
|
115
|
+
*/
|
|
116
|
+
declare function useTensorStats(config: RackConfig, repoId: string | null): {
|
|
117
|
+
stats: TensorStats;
|
|
118
|
+
loading: boolean;
|
|
119
|
+
error: string | null;
|
|
120
|
+
refresh: () => Promise<void>;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Fetch network-wide stats (repos, skills, tensors, stacks, stars, tokens, etc.)
|
|
125
|
+
*/
|
|
126
|
+
declare function useNetworkStats(config: RackConfig): {
|
|
127
|
+
stats: NetworkStats | null;
|
|
128
|
+
loading: boolean;
|
|
129
|
+
error: string | null;
|
|
130
|
+
refresh: () => Promise<void>;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Fetch trending repos with time-windowed scoring.
|
|
135
|
+
* Score = (usage × 100) + (stars × 1)
|
|
136
|
+
*/
|
|
137
|
+
declare function useTrending(config: RackConfig, limit?: number, days?: number): {
|
|
138
|
+
repos: TrendingRepo[];
|
|
139
|
+
loading: boolean;
|
|
140
|
+
error: string | null;
|
|
141
|
+
refresh: (newDays?: number) => Promise<void>;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Manage star status for a repo — fetch, star, unstar.
|
|
146
|
+
* Star/unstar costs 100k tokens each.
|
|
147
|
+
*/
|
|
148
|
+
declare function useStar(config: RackConfig, repoId: string | null): {
|
|
149
|
+
loading: boolean;
|
|
150
|
+
error: string | null;
|
|
151
|
+
toggle: () => Promise<void>;
|
|
152
|
+
refresh: () => Promise<void>;
|
|
153
|
+
stars: number;
|
|
154
|
+
starred: boolean;
|
|
155
|
+
repo_id: string;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export { type RackClient, estimateCost, useNetworkStats, useRackClient, useRackRegister, useRackSession, useRepoPush, useRepoTree, useRepos, useSkillStats, useStar, useTensorStats, useTrending };
|