@stacknet/rackutils 0.1.0 → 0.2.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 +37 -2
- package/dist/hooks/index.d.ts +37 -2
- 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 +118 -1
- package/dist/types/index.d.ts +118 -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:l||void 0}),r++;continue}if(/^\s*[-*+]\s/.test(o)){let l=[];for(;r<e.length&&/^\s*[-*+]\s/.test(e[r]);)l.push(e[r].replace(/^\s*[-*+]\s+/,"")),r++;
|
|
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(...n){return tailwindMerge.twMerge(clsx.clsx(n))}async function w(n,e,a,r){let o={"Content-Type":"application/json",...a?.headers};r&&(o.Authorization=`Bearer ${r}`);let s=await fetch(`${n}${e}`,{...a,headers:o});if(!s.ok){let i=`HTTP ${s.status}`;try{let l=await s.json();l.error&&(i=l.error);}catch{}throw new Error(i)}return s.json()}function z(n){let e=n.apiBaseUrl,a=n.authorMid,r=n.ownerMid,o=n.apiKey;return react.useMemo(()=>({async listRepos(s){let i=s||r?`?owner=${encodeURIComponent(s||r)}`:"";return (await w(e,`/api/rack/repos${i}`,void 0,o)).repos||[]},async initRepo(s){return w(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...s,owner_mid:r})},o)},async push(s,i){return w(e,`/api/rack/${s}/push`,{method:"POST",body:JSON.stringify({...i,author_mid:a})},o)},async getTree(s,i="main"){let l=await w(e,`/api/rack/${s}/tree/${i}`,void 0,o);return {tree:l.tree,commit_cid:l.commit_cid}},async getBlob(s,i){return (await w(e,`/api/rack/${s}/blob/${i}`,void 0,o)).content},async getLog(s,i,l){let d=new URLSearchParams;i&&d.set("ref",i),l&&d.set("max_count",String(l));let f=d.toString()?`?${d}`:"";return (await w(e,`/api/rack/${s}/log${f}`,void 0,o)).commits||[]},async getBranches(s){return (await w(e,`/api/rack/${s}/branches`,void 0,o)).branches||[]},async getDiff(s,i,l){return (await w(e,`/api/rack/${s}/diff/${i}/${l}`,void 0,o)).diff?.entries||[]},async starRepo(s){return w(e,`/api/rack/${s}/star`,{method:"POST"},o)},async unstarRepo(s){return w(e,`/api/rack/${s}/star`,{method:"DELETE"},o)},async getStarInfo(s){return w(e,`/api/rack/${s}/stars`,void 0,o)}}),[e,a,r,o])}function V(n){let e=z(n),a=react.useRef(e);a.current=e;let[r,o]=react.useState([]),[s,i]=react.useState(true),[l,d]=react.useState(null),f=react.useRef(true),m=react.useRef(null),x=react.useCallback(async()=>{m.current?.abort();let p=new AbortController;m.current=p;try{f.current&&(i(!0),d(null));let u=await a.current.listRepos();f.current&&!p.signal.aborted&&o(u);}catch(u){f.current&&!p.signal.aborted&&d(u instanceof Error?u.message:"Failed to load repos");}finally{f.current&&!p.signal.aborted&&i(false);}},[]);return react.useEffect(()=>(f.current=true,x(),()=>{f.current=false,m.current?.abort();}),[x]),{repos:r,loading:s,error:l,refresh:x}}function fe(n){return Object.entries(n).map(([e,a])=>{let r=a.indexOf(":"),o=r>0?a.slice(0,r):"100644",s=r>0?a.slice(r+1):a;return {path:e,mode:o,cid:s,isDir:o==="040000"}}).sort((e,a)=>e.isDir!==a.isDir?e.isDir?-1:1:e.path.localeCompare(a.path))}function W(n,e,a="main"){let r=z(n),[o,s]=react.useState([]),[i,l]=react.useState(false),[d,f]=react.useState(null),m=react.useRef(true),x=react.useCallback(async()=>{if(e)try{m.current&&(l(!0),f(null));let{tree:u}=await r.getTree(e,a);m.current&&s(fe(u.entries));}catch(u){m.current&&f(u instanceof Error?u.message:"Failed to load tree");}finally{m.current&&l(false);}},[r,e,a]);react.useEffect(()=>(m.current=true,x(),()=>{m.current=false;}),[x]);let p=react.useCallback(async u=>{if(!e)throw new Error("No repo selected");return r.getBlob(e,u)},[r,e]);return {entries:o,loading:i,error:d,refresh:x,getFileContent:p}}var pe=/^(https?:\/\/|mailto:|\/[^/])/i;function ge(n){let e=n.trim();return pe.test(e)?e:null}function I(n){let e=[],a=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,r=0,o,s=0;for(;(o=a.exec(n))!==null;){o.index>r&&e.push(n.slice(r,o.index));let i=`i${s++}`;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)},i));else if(o[2])e.push(jsxRuntime.jsx("strong",{children:o[3]},i));else if(o[4])e.push(jsxRuntime.jsx("em",{children:o[5]},i));else if(o[6])e.push(jsxRuntime.jsx("em",{children:o[7]},i));else if(o[8]){let l=ge(o[10]);l?e.push(jsxRuntime.jsx("a",{href:l,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:o[9]},i)):e.push(o[9]);}r=o.index+o[0].length;}return r<n.length&&e.push(n.slice(r)),e.length>0?e:[n]}function he(n){let e=n.split(`
|
|
2
|
+
`),a=[],r=0;for(;r<e.length;){let o=e[r];if(o.trim()===""){r++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(o.trim())){a.push({type:"hr"}),r++;continue}let s=o.match(/^(#{1,6})\s+(.+)/);if(s){a.push({type:"heading",level:s[1].length,content:s[2]}),r++;continue}if(o.trim().startsWith("```")){let l=o.trim().slice(3).trim(),d=[];for(r++;r<e.length&&!e[r].trim().startsWith("```");)d.push(e[r]),r++;a.push({type:"code",content:d.join(`
|
|
3
|
+
`),lang:l||void 0}),r++;continue}if(/^\s*[-*+]\s/.test(o)){let l=[];for(;r<e.length&&/^\s*[-*+]\s/.test(e[r]);)l.push(e[r].replace(/^\s*[-*+]\s+/,"")),r++;a.push({type:"ul",items:l});continue}if(/^\s*\d+[.)]\s/.test(o)){let l=[];for(;r<e.length&&/^\s*\d+[.)]\s/.test(e[r]);)l.push(e[r].replace(/^\s*\d+[.)]\s+/,"")),r++;a.push({type:"ol",items:l});continue}let i=[];for(;r<e.length&&e[r].trim()!==""&&!e[r].match(/^#{1,6}\s/)&&!e[r].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[r])&&!/^\s*\d+[.)]\s/.test(e[r]);)i.push(e[r]),r++;i.length>0&&a.push({type:"paragraph",content:i.join(" ")});}return a}var xe={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 ve(n,e){switch(n.type){case "hr":return jsxRuntime.jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let a=Math.min(Math.max(n.level||1,1),6),r=`h${a}`;return jsxRuntime.jsx(r,{className:k("text-foreground",xe[a]),children:I(n.content||"")},`b${e}`)}case "paragraph":return jsxRuntime.jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:I(n.content||"")},`b${e}`);case "code":return jsxRuntime.jsx("pre",{className:"mb-3 overflow-x-auto rounded-lg bg-muted p-4 text-sm font-mono leading-relaxed text-foreground",children:jsxRuntime.jsx("code",{children:n.content})},`b${e}`);case "ul":return jsxRuntime.jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:n.items?.map((a,r)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:I(a)},`li${e}-${r}`))},`b${e}`);case "ol":return jsxRuntime.jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:n.items?.map((a,r)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:I(a)},`li${e}-${r}`))},`b${e}`);default:return null}}function A({content:n,className:e}){let a=he(n);return jsxRuntime.jsx("div",{className:k("text-sm",e),children:a.map((r,o)=>ve(r,o))})}function K({open:n,className:e}){return jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:k("shrink-0 transition-transform duration-150",n?"rotate-0":"-rotate-90",e),children:jsxRuntime.jsx("path",{d:"M16.134 6.16a.5.5 0 1 1 .732.68l-6.5 7-.077.068a.5.5 0 0 1-.655-.068l-6.5-7-.062-.08a.5.5 0 0 1 .718-.667l.076.067L10 12.767z"})})}function q({size:n=20,className:e}){return jsxRuntime.jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function _({size:n=20,className:e}){return jsxRuntime.jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M15.147 4.146a.5.5 0 0 1 .707.707L10.707 10l5.147 5.147a.5.5 0 0 1-.63.771l-.078-.064L10 10.707l-5.146 5.147a.5.5 0 0 1-.708-.707L9.293 10 4.146 4.853a.5.5 0 0 1 .708-.707L10 9.293z"})})}function Q({size:n=20,className:e}){return jsxRuntime.jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M10 3a.5.5 0 0 1 .5.5v6h6l.1.01a.5.5 0 0 1 0 .98l-.1.01h-6v6a.5.5 0 0 1-1 0v-6h-6a.5.5 0 0 1 0-1h6v-6A.5.5 0 0 1 10 3"})})}function ye(){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 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:"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 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:"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 Y(){let[n,e]=react.useState(false);return react.useEffect(()=>{if(typeof window>"u")return;let a=()=>e(window.innerWidth<768);return a(),window.addEventListener("resize",a),()=>window.removeEventListener("resize",a)},[]),n}function X({onClose:n,children:e,title:a}){let r=Y(),o=react.useRef(n);return o.current=n,react.useEffect(()=>{let s=i=>{i.key==="Escape"&&o.current();};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[]),r?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:n,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full max-h-[90vh] overflow-y-auto rounded-t-2xl bg-[#1a1a1a] p-5 pb-8 animate-in slide-in-from-bottom duration-200",onClick:s=>s.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:a}),jsxRuntime.jsx("button",{onClick:n,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(_,{size:20})})]}),e]})]}):jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:n,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full max-w-lg overflow-y-auto rounded-2xl bg-[#1a1a1a] p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:s=>s.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:a}),jsxRuntime.jsx("button",{onClick:n,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(_,{size:20})})]}),e]})]})}function Re({onClose:n,onCreated:e,config:a}){let[r,o]=react.useState(""),[s,i]=react.useState(""),[l,d]=react.useState(""),[f,m]=react.useState(false),[x,p]=react.useState(null);return jsxRuntime.jsx(X,{title:"Write skill instructions",onClose:n,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsxRuntime.jsx("input",{id:"skill-name",value:r,onChange:b=>o(b.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:s,onChange:b=>i(b.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:l,onChange:b=>d(b.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"})]}),x&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:x}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsxRuntime.jsx("button",{onClick:n,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsxRuntime.jsx("button",{onClick:async()=>{if(r.trim()){m(true),p(null);try{let b=a.apiBaseUrl||"",E=`# ${r.trim()}
|
|
4
4
|
|
|
5
|
-
${
|
|
5
|
+
${s.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=
|
|
9
|
+
${l.trim()}`,N=await fetch(`${b}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.trim(),description:s.trim(),skill_md:E,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?.(),n();}catch(b){p(b instanceof Error?b.message:"Failed to create skill");}finally{m(false);}}},disabled:f||!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:f?"Creating...":"Create"})]})]})})}function Ce({onClose:n,onCreated:e,config:a}){let r=react.useRef(null),[o,s]=react.useState(false),[i,l]=react.useState(false),[d,f]=react.useState(null),m=async p=>{l(true),f(null);try{let u=await p.text(),b=a.apiBaseUrl||"",E=p.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),N=await fetch(`${b}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:E,skill_md:u,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?.(),n();}catch(u){f(u instanceof Error?u.message:"Upload failed");}finally{l(false);}};return jsxRuntime.jsx(X,{title:"Upload skill",onClose:n,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{onDragOver:p=>{p.preventDefault(),s(true);},onDragLeave:()=>s(false),onDrop:p=>{p.preventDefault(),s(false);let u=p.dataTransfer.files[0];u&&m(u);},onClick:()=>r.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(Q,{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:p=>{let u=p.target.files?.[0];u&&m(u);}}),d&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:d}),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 a=Y(),r=react.useRef(null),o=react.useRef(n);o.current=n,react.useEffect(()=>{if(a)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)},[a]);let s=[{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 a?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"}),s.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:s.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 Se({entry:n,selected:e,onSelect:a,depth:r=0}){return jsxRuntime.jsxs("button",{onClick:()=>a(n),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+r*16}px`},children:[jsxRuntime.jsx("span",{className:"truncate flex-1",children:n.path.split("/").pop()}),n.isDir&&jsxRuntime.jsx(K,{className:"ml-auto text-muted-foreground"})]})}function Te({repo:n,selected:e,expanded:a,onSelect:r,onToggle:o,children:s}){return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>{r(),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(K,{open:a}),jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4 shrink-0"}),jsxRuntime.jsx("span",{className:"truncate",children:n.name})]}),a&&s]})}function ze({entry:n,content:e,loading:a,repoName:r}){let[o,s]=react.useState(false),i=react.useRef(null);react.useEffect(()=>()=>{i.current&&clearTimeout(i.current);},[]);let[l,d]=react.useState(false),f=async()=>{if(e)try{await navigator.clipboard.writeText(e),s(!0),d(!1),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>s(!1),2e3);}catch{d(true),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>d(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(a)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let m=n.path.split("/").pop()||n.path,x=/\.(md|mdx)$/i.test(m);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:m}),jsxRuntime.jsx("button",{onClick:f,"aria-label":"Copy file content",className:k("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(A,{content:e||""}):jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function Ie({config:n,category:e,className:a,style:r}){let{repos:o,loading:s,error:i,refresh:l}=V(n),[d,f]=react.useState(null),[m,x]=react.useState(null),[p,u]=react.useState(null),[b,E]=react.useState(null),[N,C]=react.useState(false),[y,B]=react.useState(""),[ee,D]=react.useState(false),[F,U]=react.useState(false),[j,$]=react.useState(null),te=o.find(g=>g.repo_id===d),{entries:re,getFileContent:O}=W(n,m),H=o.filter(g=>!y||g.name.toLowerCase().includes(y.toLowerCase())),ne=react.useCallback(async g=>{if(!g.isDir){u(g),C(true);try{let R=await O(g.cid);E(R);}catch(R){let se=R instanceof Error?R.message:"Unknown error";E(`Failed to load file: ${se}`);}finally{C(false);}}},[O]);react.useEffect(()=>{o.length>0&&!d&&(f(o[0].repo_id),x(o[0].repo_id));},[o,d]);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"):$(g);};return jsxRuntime.jsxs("div",{className:k("flex flex-1 h-full min-h-0",a),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:ee?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: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:()=>{D(false),B("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(_,{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:()=>U(!F),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(Q,{size:20})})]})}),F&&jsxRuntime.jsx(Ee,{onClose:()=>U(false),onSelect:oe}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:s?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}):H.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:H.map(g=>jsxRuntime.jsx(Te,{repo:g,selected:d===g.repo_id,expanded:m===g.repo_id,onSelect:()=>{f(g.repo_id),u(null),E(null);},onToggle:()=>x(m===g.repo_id?null:g.repo_id),children:jsxRuntime.jsx("div",{className:"ml-10 pl-1",children:re.map(R=>jsxRuntime.jsx(Se,{entry:R,selected:p?.path===R.path,onSelect:ne,depth:R.path.split("/").length-1},R.path))})},g.repo_id))})})]}),jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntime.jsx(ze,{entry:p,content:b,loading:N,repoName:te?.name||""})}),j==="write"&&jsxRuntime.jsx(Re,{config:n,onClose:()=>$(null),onCreated:l}),j==="upload"&&jsxRuntime.jsx(Ce,{config:n,onClose:()=>$(null),onCreated:l})]})}
|
|
10
|
+
exports.Markdown=A;exports.RackBrowser=Ie;
|
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:l||void 0}),r++;continue}if(/^\s*[-*+]\s/.test(o)){let l=[];for(;r<e.length&&/^\s*[-*+]\s/.test(e[r]);)l.push(e[r].replace(/^\s*[-*+]\s+/,"")),r++;
|
|
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(...n){return twMerge(clsx(n))}async function w(n,e,a,r){let o={"Content-Type":"application/json",...a?.headers};r&&(o.Authorization=`Bearer ${r}`);let s=await fetch(`${n}${e}`,{...a,headers:o});if(!s.ok){let i=`HTTP ${s.status}`;try{let l=await s.json();l.error&&(i=l.error);}catch{}throw new Error(i)}return s.json()}function z(n){let e=n.apiBaseUrl,a=n.authorMid,r=n.ownerMid,o=n.apiKey;return useMemo(()=>({async listRepos(s){let i=s||r?`?owner=${encodeURIComponent(s||r)}`:"";return (await w(e,`/api/rack/repos${i}`,void 0,o)).repos||[]},async initRepo(s){return w(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...s,owner_mid:r})},o)},async push(s,i){return w(e,`/api/rack/${s}/push`,{method:"POST",body:JSON.stringify({...i,author_mid:a})},o)},async getTree(s,i="main"){let l=await w(e,`/api/rack/${s}/tree/${i}`,void 0,o);return {tree:l.tree,commit_cid:l.commit_cid}},async getBlob(s,i){return (await w(e,`/api/rack/${s}/blob/${i}`,void 0,o)).content},async getLog(s,i,l){let d=new URLSearchParams;i&&d.set("ref",i),l&&d.set("max_count",String(l));let f=d.toString()?`?${d}`:"";return (await w(e,`/api/rack/${s}/log${f}`,void 0,o)).commits||[]},async getBranches(s){return (await w(e,`/api/rack/${s}/branches`,void 0,o)).branches||[]},async getDiff(s,i,l){return (await w(e,`/api/rack/${s}/diff/${i}/${l}`,void 0,o)).diff?.entries||[]},async starRepo(s){return w(e,`/api/rack/${s}/star`,{method:"POST"},o)},async unstarRepo(s){return w(e,`/api/rack/${s}/star`,{method:"DELETE"},o)},async getStarInfo(s){return w(e,`/api/rack/${s}/stars`,void 0,o)}}),[e,a,r,o])}function V(n){let e=z(n),a=useRef(e);a.current=e;let[r,o]=useState([]),[s,i]=useState(true),[l,d]=useState(null),f=useRef(true),m=useRef(null),x=useCallback(async()=>{m.current?.abort();let p=new AbortController;m.current=p;try{f.current&&(i(!0),d(null));let u=await a.current.listRepos();f.current&&!p.signal.aborted&&o(u);}catch(u){f.current&&!p.signal.aborted&&d(u instanceof Error?u.message:"Failed to load repos");}finally{f.current&&!p.signal.aborted&&i(false);}},[]);return useEffect(()=>(f.current=true,x(),()=>{f.current=false,m.current?.abort();}),[x]),{repos:r,loading:s,error:l,refresh:x}}function fe(n){return Object.entries(n).map(([e,a])=>{let r=a.indexOf(":"),o=r>0?a.slice(0,r):"100644",s=r>0?a.slice(r+1):a;return {path:e,mode:o,cid:s,isDir:o==="040000"}}).sort((e,a)=>e.isDir!==a.isDir?e.isDir?-1:1:e.path.localeCompare(a.path))}function W(n,e,a="main"){let r=z(n),[o,s]=useState([]),[i,l]=useState(false),[d,f]=useState(null),m=useRef(true),x=useCallback(async()=>{if(e)try{m.current&&(l(!0),f(null));let{tree:u}=await r.getTree(e,a);m.current&&s(fe(u.entries));}catch(u){m.current&&f(u instanceof Error?u.message:"Failed to load tree");}finally{m.current&&l(false);}},[r,e,a]);useEffect(()=>(m.current=true,x(),()=>{m.current=false;}),[x]);let p=useCallback(async u=>{if(!e)throw new Error("No repo selected");return r.getBlob(e,u)},[r,e]);return {entries:o,loading:i,error:d,refresh:x,getFileContent:p}}var pe=/^(https?:\/\/|mailto:|\/[^/])/i;function ge(n){let e=n.trim();return pe.test(e)?e:null}function I(n){let e=[],a=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,r=0,o,s=0;for(;(o=a.exec(n))!==null;){o.index>r&&e.push(n.slice(r,o.index));let i=`i${s++}`;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)},i));else if(o[2])e.push(jsx("strong",{children:o[3]},i));else if(o[4])e.push(jsx("em",{children:o[5]},i));else if(o[6])e.push(jsx("em",{children:o[7]},i));else if(o[8]){let l=ge(o[10]);l?e.push(jsx("a",{href:l,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:o[9]},i)):e.push(o[9]);}r=o.index+o[0].length;}return r<n.length&&e.push(n.slice(r)),e.length>0?e:[n]}function he(n){let e=n.split(`
|
|
2
|
+
`),a=[],r=0;for(;r<e.length;){let o=e[r];if(o.trim()===""){r++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(o.trim())){a.push({type:"hr"}),r++;continue}let s=o.match(/^(#{1,6})\s+(.+)/);if(s){a.push({type:"heading",level:s[1].length,content:s[2]}),r++;continue}if(o.trim().startsWith("```")){let l=o.trim().slice(3).trim(),d=[];for(r++;r<e.length&&!e[r].trim().startsWith("```");)d.push(e[r]),r++;a.push({type:"code",content:d.join(`
|
|
3
|
+
`),lang:l||void 0}),r++;continue}if(/^\s*[-*+]\s/.test(o)){let l=[];for(;r<e.length&&/^\s*[-*+]\s/.test(e[r]);)l.push(e[r].replace(/^\s*[-*+]\s+/,"")),r++;a.push({type:"ul",items:l});continue}if(/^\s*\d+[.)]\s/.test(o)){let l=[];for(;r<e.length&&/^\s*\d+[.)]\s/.test(e[r]);)l.push(e[r].replace(/^\s*\d+[.)]\s+/,"")),r++;a.push({type:"ol",items:l});continue}let i=[];for(;r<e.length&&e[r].trim()!==""&&!e[r].match(/^#{1,6}\s/)&&!e[r].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[r])&&!/^\s*\d+[.)]\s/.test(e[r]);)i.push(e[r]),r++;i.length>0&&a.push({type:"paragraph",content:i.join(" ")});}return a}var xe={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 ve(n,e){switch(n.type){case "hr":return jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let a=Math.min(Math.max(n.level||1,1),6),r=`h${a}`;return jsx(r,{className:k("text-foreground",xe[a]),children:I(n.content||"")},`b${e}`)}case "paragraph":return jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:I(n.content||"")},`b${e}`);case "code":return jsx("pre",{className:"mb-3 overflow-x-auto rounded-lg bg-muted p-4 text-sm font-mono leading-relaxed text-foreground",children:jsx("code",{children:n.content})},`b${e}`);case "ul":return jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:n.items?.map((a,r)=>jsx("li",{className:"leading-relaxed",children:I(a)},`li${e}-${r}`))},`b${e}`);case "ol":return jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:n.items?.map((a,r)=>jsx("li",{className:"leading-relaxed",children:I(a)},`li${e}-${r}`))},`b${e}`);default:return null}}function A({content:n,className:e}){let a=he(n);return jsx("div",{className:k("text-sm",e),children:a.map((r,o)=>ve(r,o))})}function K({open:n,className:e}){return jsx("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:k("shrink-0 transition-transform duration-150",n?"rotate-0":"-rotate-90",e),children:jsx("path",{d:"M16.134 6.16a.5.5 0 1 1 .732.68l-6.5 7-.077.068a.5.5 0 0 1-.655-.068l-6.5-7-.062-.08a.5.5 0 0 1 .718-.667l.076.067L10 12.767z"})})}function q({size:n=20,className:e}){return jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function _({size:n=20,className:e}){return jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M15.147 4.146a.5.5 0 0 1 .707.707L10.707 10l5.147 5.147a.5.5 0 0 1-.63.771l-.078-.064L10 10.707l-5.146 5.147a.5.5 0 0 1-.708-.707L9.293 10 4.146 4.853a.5.5 0 0 1 .708-.707L10 9.293z"})})}function Q({size:n=20,className:e}){return jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M10 3a.5.5 0 0 1 .5.5v6h6l.1.01a.5.5 0 0 1 0 .98l-.1.01h-6v6a.5.5 0 0 1-1 0v-6h-6a.5.5 0 0 1 0-1h6v-6A.5.5 0 0 1 10 3"})})}function ye(){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 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:"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 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:"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 Y(){let[n,e]=useState(false);return useEffect(()=>{if(typeof window>"u")return;let a=()=>e(window.innerWidth<768);return a(),window.addEventListener("resize",a),()=>window.removeEventListener("resize",a)},[]),n}function X({onClose:n,children:e,title:a}){let r=Y(),o=useRef(n);return o.current=n,useEffect(()=>{let s=i=>{i.key==="Escape"&&o.current();};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[]),r?jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:n,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full max-h-[90vh] overflow-y-auto rounded-t-2xl bg-[#1a1a1a] p-5 pb-8 animate-in slide-in-from-bottom duration-200",onClick:s=>s.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:a}),jsx("button",{onClick:n,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(_,{size:20})})]}),e]})]}):jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:n,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full max-w-lg overflow-y-auto rounded-2xl bg-[#1a1a1a] p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:s=>s.stopPropagation(),children:[jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsx("h2",{className:"text-lg font-semibold text-foreground",children:a}),jsx("button",{onClick:n,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(_,{size:20})})]}),e]})]})}function Re({onClose:n,onCreated:e,config:a}){let[r,o]=useState(""),[s,i]=useState(""),[l,d]=useState(""),[f,m]=useState(false),[x,p]=useState(null);return jsx(X,{title:"Write skill instructions",onClose:n,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsx("input",{id:"skill-name",value:r,onChange:b=>o(b.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:s,onChange:b=>i(b.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:l,onChange:b=>d(b.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"})]}),x&&jsx("p",{className:"text-sm text-red-500",children:x}),jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsx("button",{onClick:n,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsx("button",{onClick:async()=>{if(r.trim()){m(true),p(null);try{let b=a.apiBaseUrl||"",E=`# ${r.trim()}
|
|
4
4
|
|
|
5
|
-
${
|
|
5
|
+
${s.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{
|
|
9
|
+
${l.trim()}`,N=await fetch(`${b}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.trim(),description:s.trim(),skill_md:E,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?.(),n();}catch(b){p(b instanceof Error?b.message:"Failed to create skill");}finally{m(false);}}},disabled:f||!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:f?"Creating...":"Create"})]})]})})}function Ce({onClose:n,onCreated:e,config:a}){let r=useRef(null),[o,s]=useState(false),[i,l]=useState(false),[d,f]=useState(null),m=async p=>{l(true),f(null);try{let u=await p.text(),b=a.apiBaseUrl||"",E=p.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),N=await fetch(`${b}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:E,skill_md:u,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?.(),n();}catch(u){f(u instanceof Error?u.message:"Upload failed");}finally{l(false);}};return jsx(X,{title:"Upload skill",onClose:n,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{onDragOver:p=>{p.preventDefault(),s(true);},onDragLeave:()=>s(false),onDrop:p=>{p.preventDefault(),s(false);let u=p.dataTransfer.files[0];u&&m(u);},onClick:()=>r.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(Q,{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:p=>{let u=p.target.files?.[0];u&&m(u);}}),d&&jsx("p",{className:"text-sm text-red-500",children:d}),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 a=Y(),r=useRef(null),o=useRef(n);o.current=n,useEffect(()=>{if(a)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)},[a]);let s=[{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 a?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"}),s.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:s.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 Se({entry:n,selected:e,onSelect:a,depth:r=0}){return jsxs("button",{onClick:()=>a(n),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+r*16}px`},children:[jsx("span",{className:"truncate flex-1",children:n.path.split("/").pop()}),n.isDir&&jsx(K,{className:"ml-auto text-muted-foreground"})]})}function Te({repo:n,selected:e,expanded:a,onSelect:r,onToggle:o,children:s}){return jsxs("div",{children:[jsxs("button",{onClick:()=>{r(),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(K,{open:a}),jsx(FileText,{className:"h-4 w-4 shrink-0"}),jsx("span",{className:"truncate",children:n.name})]}),a&&s]})}function ze({entry:n,content:e,loading:a,repoName:r}){let[o,s]=useState(false),i=useRef(null);useEffect(()=>()=>{i.current&&clearTimeout(i.current);},[]);let[l,d]=useState(false),f=async()=>{if(e)try{await navigator.clipboard.writeText(e),s(!0),d(!1),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>s(!1),2e3);}catch{d(true),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>d(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(a)return jsx("div",{className:"flex h-full items-center justify-center",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let m=n.path.split("/").pop()||n.path,x=/\.(md|mdx)$/i.test(m);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:m}),jsx("button",{onClick:f,"aria-label":"Copy file content",className:k("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(A,{content:e||""}):jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function Ie({config:n,category:e,className:a,style:r}){let{repos:o,loading:s,error:i,refresh:l}=V(n),[d,f]=useState(null),[m,x]=useState(null),[p,u]=useState(null),[b,E]=useState(null),[N,C]=useState(false),[y,B]=useState(""),[ee,D]=useState(false),[F,U]=useState(false),[j,$]=useState(null),te=o.find(g=>g.repo_id===d),{entries:re,getFileContent:O}=W(n,m),H=o.filter(g=>!y||g.name.toLowerCase().includes(y.toLowerCase())),ne=useCallback(async g=>{if(!g.isDir){u(g),C(true);try{let R=await O(g.cid);E(R);}catch(R){let se=R instanceof Error?R.message:"Unknown error";E(`Failed to load file: ${se}`);}finally{C(false);}}},[O]);useEffect(()=>{o.length>0&&!d&&(f(o[0].repo_id),x(o[0].repo_id));},[o,d]);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"):$(g);};return jsxs("div",{className:k("flex flex-1 h-full min-h-0",a),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:ee?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: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:()=>{D(false),B("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(_,{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:()=>U(!F),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(Q,{size:20})})]})}),F&&jsx(Ee,{onClose:()=>U(false),onSelect:oe}),jsx("div",{className:"flex-1 overflow-y-auto p-2",children:s?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}):H.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:H.map(g=>jsx(Te,{repo:g,selected:d===g.repo_id,expanded:m===g.repo_id,onSelect:()=>{f(g.repo_id),u(null),E(null);},onToggle:()=>x(m===g.repo_id?null:g.repo_id),children:jsx("div",{className:"ml-10 pl-1",children:re.map(R=>jsx(Se,{entry:R,selected:p?.path===R.path,onSelect:ne,depth:R.path.split("/").length-1},R.path))})},g.repo_id))})})]}),jsx("div",{className:"flex-1 min-w-0",children:jsx(ze,{entry:p,content:b,loading:N,repoName:te?.name||""})}),j==="write"&&jsx(Re,{config:n,onClose:()=>$(null),onCreated:l}),j==="upload"&&jsx(Ce,{config:n,onClose:()=>$(null),onCreated:l})]})}
|
|
10
|
+
export{A as Markdown,Ie as RackBrowser};
|
package/dist/hooks/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var react=require('react');async function m(
|
|
1
|
+
'use strict';var react=require('react');async function m(o,e,i,s){let r={"Content-Type":"application/json",...i?.headers};s&&(r.Authorization=`Bearer ${s}`);let t=await fetch(`${o}${e}`,{...i,headers:r});if(!t.ok){let n=`HTTP ${t.status}`;try{let u=await t.json();u.error&&(n=u.error);}catch{}throw new Error(n)}return t.json()}function R(o){let e=o.apiBaseUrl,i=o.authorMid,s=o.ownerMid,r=o.apiKey;return react.useMemo(()=>({async listRepos(t){let n=t||s?`?owner=${encodeURIComponent(t||s)}`:"";return (await m(e,`/api/rack/repos${n}`,void 0,r)).repos||[]},async initRepo(t){return m(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...t,owner_mid:s})},r)},async push(t,n){return m(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...n,author_mid:i})},r)},async getTree(t,n="main"){let u=await m(e,`/api/rack/${t}/tree/${n}`,void 0,r);return {tree:u.tree,commit_cid:u.commit_cid}},async getBlob(t,n){return (await m(e,`/api/rack/${t}/blob/${n}`,void 0,r)).content},async getLog(t,n,u){let f=new URLSearchParams;n&&f.set("ref",n),u&&f.set("max_count",String(u));let g=f.toString()?`?${f}`:"";return (await m(e,`/api/rack/${t}/log${g}`,void 0,r)).commits||[]},async getBranches(t){return (await m(e,`/api/rack/${t}/branches`,void 0,r)).branches||[]},async getDiff(t,n,u){return (await m(e,`/api/rack/${t}/diff/${n}/${u}`,void 0,r)).diff?.entries||[]},async starRepo(t){return m(e,`/api/rack/${t}/star`,{method:"POST"},r)},async unstarRepo(t){return m(e,`/api/rack/${t}/star`,{method:"DELETE"},r)},async getStarInfo(t){return m(e,`/api/rack/${t}/stars`,void 0,r)}}),[e,i,s,r])}function B(o){let e=R(o),i=react.useRef(e);i.current=e;let[s,r]=react.useState([]),[t,n]=react.useState(true),[u,f]=react.useState(null),g=react.useRef(true),p=react.useRef(null),a=react.useCallback(async()=>{p.current?.abort();let c=new AbortController;p.current=c;try{g.current&&(n(!0),f(null));let l=await i.current.listRepos();g.current&&!c.signal.aborted&&r(l);}catch(l){g.current&&!c.signal.aborted&&f(l instanceof Error?l.message:"Failed to load repos");}finally{g.current&&!c.signal.aborted&&n(false);}},[]);return react.useEffect(()=>(g.current=true,a(),()=>{g.current=false,p.current?.abort();}),[a]),{repos:s,loading:t,error:u,refresh:a}}function A(o){return Object.entries(o).map(([e,i])=>{let s=i.indexOf(":"),r=s>0?i.slice(0,s):"100644",t=s>0?i.slice(s+1):i;return {path:e,mode:r,cid:t,isDir:r==="040000"}}).sort((e,i)=>e.isDir!==i.isDir?e.isDir?-1:1:e.path.localeCompare(i.path))}function D(o,e,i="main"){let s=R(o),[r,t]=react.useState([]),[n,u]=react.useState(false),[f,g]=react.useState(null),p=react.useRef(true),a=react.useCallback(async()=>{if(e)try{p.current&&(u(!0),g(null));let{tree:l}=await s.getTree(e,i);p.current&&t(A(l.entries));}catch(l){p.current&&g(l instanceof Error?l.message:"Failed to load tree");}finally{p.current&&u(false);}},[s,e,i]);react.useEffect(()=>(p.current=true,a(),()=>{p.current=false;}),[a]);let c=react.useCallback(async l=>{if(!e)throw new Error("No repo selected");return s.getBlob(e,l)},[s,e]);return {entries:r,loading:n,error:f,refresh:a,getFileContent:c}}function H(o){let e=R(o),[i,s]=react.useState(false),[r,t]=react.useState(null),n=react.useRef(true);return react.useEffect(()=>(n.current=true,()=>{n.current=false;}),[]),{push:react.useCallback(async(f,g,p,a)=>{try{return n.current&&(s(!0),t(null)),await e.push(f,{files:g,message:p,branch:a})}catch(c){let l=c instanceof Error?c.message:"Push failed";return n.current&&t(l),null}finally{n.current&&s(false);}},[e]),pushing:i,error:r}}var T="stacknet-rack-apikey";function z(o){let e=o.stacknetUrl||o.apiBaseUrl,[i,s]=react.useState({authenticated:false}),[r,t]=react.useState(null),[n,u]=react.useState(false),f=react.useCallback(c=>({"Content-Type":"application/json",...c||o.apiKey?{Authorization:`Bearer ${c||o.apiKey}`}:{}}),[o.apiKey]),g=react.useCallback(async c=>{u(true);try{let l=await fetch(`${e}/health`,{headers:f(c)});if(!l.ok)throw new Error(`Authentication failed: ${l.status}`);let d={authenticated:!0,apiKey:c,permission:c.startsWith("gk_")?"write":"read"};s(d);try{localStorage.setItem(T,c);}catch{}return d}catch(l){throw s({authenticated:false}),l}finally{u(false);}},[e,f]),p=react.useCallback(()=>{s({authenticated:false}),t(null);try{localStorage.removeItem(T);}catch{}},[]),a=react.useCallback(async()=>{let c=i.apiKey||o.apiKey;if(!c)return null;try{let l=await fetch(`${e}/network/usage`,{headers:f(c)});if(!l.ok)return null;let d=await l.json(),P={planAllocation:d.plan_allocation??d.planAllocation??0,inferenceUsed:d.inference_used??d.inferenceUsed??0,ledgerSpent:d.ledger_spent??d.ledgerSpent??0,totalUsed:d.total_used??d.totalUsed??0,remaining:d.remaining??0,percent:d.percent??0,exceeded:d.exceeded??!1};return t(P),P}catch{return null}},[i.apiKey,o.apiKey,e,f]);return react.useEffect(()=>{let c=o.apiKey;if(c){s({authenticated:true,apiKey:c,permission:c.startsWith("gk_")?"write":"read"});return}try{let l=localStorage.getItem(T);l&&s({authenticated:!0,apiKey:l,permission:l.startsWith("gk_")?"write":"read"});}catch{}},[o.apiKey]),{session:i,budget:r,loading:n,login:g,logout:p,refreshBudget:a}}var $=1e3,_=1e3,U=100;function x(o,e){if(o==="skill"){let r=U+Math.ceil(e/4);return {type:o,totalBytes:e,totalMegabytes:e/1e6,baseCost:r,multiplier:$,registrationCostTokens:r*$}}let i=Math.ceil(e/1e6),s=U+i;return {type:o,totalBytes:e,totalMegabytes:i,baseCost:s,multiplier:_,registrationCostTokens:s*_}}function W(o){let e=o.stacknetUrl||o.apiBaseUrl,i=o.apiKey,[s,r]=react.useState(false),[t,n]=react.useState(null),u=react.useCallback(()=>{if(!i)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${i}`}},[i]),f=react.useCallback(async p=>{r(true),n(null);try{let a=await fetch(`${e}/skills`,{method:"POST",headers:u(),body:JSON.stringify(p)});if(!a.ok){let c=await a.json().catch(()=>({error:`HTTP ${a.status}`}));throw new Error(c.error||`Registration failed: ${a.status}`)}return await a.json()}catch(a){throw n(a.message),a}finally{r(false);}},[e,u]),g=react.useCallback(async p=>{r(true),n(null);try{let a=await fetch(`${e}/tensors`,{method:"POST",headers:u(),body:JSON.stringify(p)});if(!a.ok){let c=await a.json().catch(()=>({error:`HTTP ${a.status}`}));throw new Error(c.error||`Registration failed: ${a.status}`)}return await a.json()}catch(a){throw n(a.message),a}finally{r(false);}},[e,u]);return {registerSkill:f,registerTensor:g,estimateCost:x,registering:s,error:t}}exports.estimateCost=x;exports.useRackClient=R;exports.useRackRegister=W;exports.useRackSession=z;exports.useRepoPush=H;exports.useRepoTree=D;exports.useRepos=B;
|
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, 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[]>;
|
|
@@ -20,6 +20,9 @@ interface RackClient {
|
|
|
20
20
|
getLog: (repoId: string, ref?: string, maxCount?: number) => Promise<RepoCommit[]>;
|
|
21
21
|
getBranches: (repoId: string) => Promise<string[]>;
|
|
22
22
|
getDiff: (repoId: string, fromRef: string, toRef: string) => Promise<DiffEntry[]>;
|
|
23
|
+
starRepo: (repoId: string) => Promise<StarResult>;
|
|
24
|
+
unstarRepo: (repoId: string) => Promise<StarResult>;
|
|
25
|
+
getStarInfo: (repoId: string) => Promise<StarInfo>;
|
|
23
26
|
}
|
|
24
27
|
/**
|
|
25
28
|
* Low-level hook returning a rack API client.
|
|
@@ -51,4 +54,36 @@ interface UseRepoPushReturn {
|
|
|
51
54
|
}
|
|
52
55
|
declare function useRepoPush(config: RackConfig): UseRepoPushReturn;
|
|
53
56
|
|
|
54
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Session hook for authenticated Rack operations.
|
|
59
|
+
* Manages API key persistence, session validation, and token budget.
|
|
60
|
+
*/
|
|
61
|
+
declare function useRackSession(config: RackConfig): {
|
|
62
|
+
session: RackSession;
|
|
63
|
+
budget: TokenBudget | null;
|
|
64
|
+
loading: boolean;
|
|
65
|
+
login: (apiKey: string) => Promise<RackSession>;
|
|
66
|
+
logout: () => void;
|
|
67
|
+
refreshBudget: () => Promise<TokenBudget | null>;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Estimate registration cost before committing.
|
|
72
|
+
*
|
|
73
|
+
* Skills: (INIT_COST + ceil(totalBytes / 4)) × 1000
|
|
74
|
+
* Tensors: (INIT_COST + ceil(totalMB)) × 1000 (MB-level, not token-level)
|
|
75
|
+
*/
|
|
76
|
+
declare function estimateCost(type: 'skill' | 'tensor', totalBytes: number): CostEstimate;
|
|
77
|
+
/**
|
|
78
|
+
* Hook for registering skills and tensors on StackNet.
|
|
79
|
+
* Requires an authenticated session (API key).
|
|
80
|
+
*/
|
|
81
|
+
declare function useRackRegister(config: RackConfig): {
|
|
82
|
+
registerSkill: (input: SkillRegistrationInput) => Promise<SkillRegistrationResult>;
|
|
83
|
+
registerTensor: (input: TensorRegistrationInput) => Promise<TensorRegistrationResult>;
|
|
84
|
+
estimateCost: typeof estimateCost;
|
|
85
|
+
registering: boolean;
|
|
86
|
+
error: string | null;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export { type RackClient, estimateCost, useRackClient, useRackRegister, useRackSession, useRepoPush, useRepoTree, useRepos };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RepoInfo, InitResult, RepoFile, PushResult, RepoTree, RepoCommit, DiffEntry, RackConfig, TreeEntry } from '../types/index.js';
|
|
1
|
+
import { RepoInfo, InitResult, RepoFile, PushResult, RepoTree, RepoCommit, DiffEntry, StarResult, StarInfo, RackConfig, TreeEntry, RackSession, TokenBudget, CostEstimate, SkillRegistrationInput, SkillRegistrationResult, TensorRegistrationInput, TensorRegistrationResult } from '../types/index.js';
|
|
2
2
|
|
|
3
3
|
interface RackClient {
|
|
4
4
|
listRepos: (owner?: string) => Promise<RepoInfo[]>;
|
|
@@ -20,6 +20,9 @@ interface RackClient {
|
|
|
20
20
|
getLog: (repoId: string, ref?: string, maxCount?: number) => Promise<RepoCommit[]>;
|
|
21
21
|
getBranches: (repoId: string) => Promise<string[]>;
|
|
22
22
|
getDiff: (repoId: string, fromRef: string, toRef: string) => Promise<DiffEntry[]>;
|
|
23
|
+
starRepo: (repoId: string) => Promise<StarResult>;
|
|
24
|
+
unstarRepo: (repoId: string) => Promise<StarResult>;
|
|
25
|
+
getStarInfo: (repoId: string) => Promise<StarInfo>;
|
|
23
26
|
}
|
|
24
27
|
/**
|
|
25
28
|
* Low-level hook returning a rack API client.
|
|
@@ -51,4 +54,36 @@ interface UseRepoPushReturn {
|
|
|
51
54
|
}
|
|
52
55
|
declare function useRepoPush(config: RackConfig): UseRepoPushReturn;
|
|
53
56
|
|
|
54
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Session hook for authenticated Rack operations.
|
|
59
|
+
* Manages API key persistence, session validation, and token budget.
|
|
60
|
+
*/
|
|
61
|
+
declare function useRackSession(config: RackConfig): {
|
|
62
|
+
session: RackSession;
|
|
63
|
+
budget: TokenBudget | null;
|
|
64
|
+
loading: boolean;
|
|
65
|
+
login: (apiKey: string) => Promise<RackSession>;
|
|
66
|
+
logout: () => void;
|
|
67
|
+
refreshBudget: () => Promise<TokenBudget | null>;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Estimate registration cost before committing.
|
|
72
|
+
*
|
|
73
|
+
* Skills: (INIT_COST + ceil(totalBytes / 4)) × 1000
|
|
74
|
+
* Tensors: (INIT_COST + ceil(totalMB)) × 1000 (MB-level, not token-level)
|
|
75
|
+
*/
|
|
76
|
+
declare function estimateCost(type: 'skill' | 'tensor', totalBytes: number): CostEstimate;
|
|
77
|
+
/**
|
|
78
|
+
* Hook for registering skills and tensors on StackNet.
|
|
79
|
+
* Requires an authenticated session (API key).
|
|
80
|
+
*/
|
|
81
|
+
declare function useRackRegister(config: RackConfig): {
|
|
82
|
+
registerSkill: (input: SkillRegistrationInput) => Promise<SkillRegistrationResult>;
|
|
83
|
+
registerTensor: (input: TensorRegistrationInput) => Promise<TensorRegistrationResult>;
|
|
84
|
+
estimateCost: typeof estimateCost;
|
|
85
|
+
registering: boolean;
|
|
86
|
+
error: string | null;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export { type RackClient, estimateCost, useRackClient, useRackRegister, useRackSession, useRepoPush, useRepoTree, useRepos };
|
package/dist/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {useMemo,useRef,useState,useCallback,useEffect}from'react';async function m(
|
|
1
|
+
import {useMemo,useRef,useState,useCallback,useEffect}from'react';async function m(o,e,i,s){let r={"Content-Type":"application/json",...i?.headers};s&&(r.Authorization=`Bearer ${s}`);let t=await fetch(`${o}${e}`,{...i,headers:r});if(!t.ok){let n=`HTTP ${t.status}`;try{let u=await t.json();u.error&&(n=u.error);}catch{}throw new Error(n)}return t.json()}function R(o){let e=o.apiBaseUrl,i=o.authorMid,s=o.ownerMid,r=o.apiKey;return useMemo(()=>({async listRepos(t){let n=t||s?`?owner=${encodeURIComponent(t||s)}`:"";return (await m(e,`/api/rack/repos${n}`,void 0,r)).repos||[]},async initRepo(t){return m(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...t,owner_mid:s})},r)},async push(t,n){return m(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...n,author_mid:i})},r)},async getTree(t,n="main"){let u=await m(e,`/api/rack/${t}/tree/${n}`,void 0,r);return {tree:u.tree,commit_cid:u.commit_cid}},async getBlob(t,n){return (await m(e,`/api/rack/${t}/blob/${n}`,void 0,r)).content},async getLog(t,n,u){let f=new URLSearchParams;n&&f.set("ref",n),u&&f.set("max_count",String(u));let g=f.toString()?`?${f}`:"";return (await m(e,`/api/rack/${t}/log${g}`,void 0,r)).commits||[]},async getBranches(t){return (await m(e,`/api/rack/${t}/branches`,void 0,r)).branches||[]},async getDiff(t,n,u){return (await m(e,`/api/rack/${t}/diff/${n}/${u}`,void 0,r)).diff?.entries||[]},async starRepo(t){return m(e,`/api/rack/${t}/star`,{method:"POST"},r)},async unstarRepo(t){return m(e,`/api/rack/${t}/star`,{method:"DELETE"},r)},async getStarInfo(t){return m(e,`/api/rack/${t}/stars`,void 0,r)}}),[e,i,s,r])}function B(o){let e=R(o),i=useRef(e);i.current=e;let[s,r]=useState([]),[t,n]=useState(true),[u,f]=useState(null),g=useRef(true),p=useRef(null),a=useCallback(async()=>{p.current?.abort();let c=new AbortController;p.current=c;try{g.current&&(n(!0),f(null));let l=await i.current.listRepos();g.current&&!c.signal.aborted&&r(l);}catch(l){g.current&&!c.signal.aborted&&f(l instanceof Error?l.message:"Failed to load repos");}finally{g.current&&!c.signal.aborted&&n(false);}},[]);return useEffect(()=>(g.current=true,a(),()=>{g.current=false,p.current?.abort();}),[a]),{repos:s,loading:t,error:u,refresh:a}}function A(o){return Object.entries(o).map(([e,i])=>{let s=i.indexOf(":"),r=s>0?i.slice(0,s):"100644",t=s>0?i.slice(s+1):i;return {path:e,mode:r,cid:t,isDir:r==="040000"}}).sort((e,i)=>e.isDir!==i.isDir?e.isDir?-1:1:e.path.localeCompare(i.path))}function D(o,e,i="main"){let s=R(o),[r,t]=useState([]),[n,u]=useState(false),[f,g]=useState(null),p=useRef(true),a=useCallback(async()=>{if(e)try{p.current&&(u(!0),g(null));let{tree:l}=await s.getTree(e,i);p.current&&t(A(l.entries));}catch(l){p.current&&g(l instanceof Error?l.message:"Failed to load tree");}finally{p.current&&u(false);}},[s,e,i]);useEffect(()=>(p.current=true,a(),()=>{p.current=false;}),[a]);let c=useCallback(async l=>{if(!e)throw new Error("No repo selected");return s.getBlob(e,l)},[s,e]);return {entries:r,loading:n,error:f,refresh:a,getFileContent:c}}function H(o){let e=R(o),[i,s]=useState(false),[r,t]=useState(null),n=useRef(true);return useEffect(()=>(n.current=true,()=>{n.current=false;}),[]),{push:useCallback(async(f,g,p,a)=>{try{return n.current&&(s(!0),t(null)),await e.push(f,{files:g,message:p,branch:a})}catch(c){let l=c instanceof Error?c.message:"Push failed";return n.current&&t(l),null}finally{n.current&&s(false);}},[e]),pushing:i,error:r}}var T="stacknet-rack-apikey";function z(o){let e=o.stacknetUrl||o.apiBaseUrl,[i,s]=useState({authenticated:false}),[r,t]=useState(null),[n,u]=useState(false),f=useCallback(c=>({"Content-Type":"application/json",...c||o.apiKey?{Authorization:`Bearer ${c||o.apiKey}`}:{}}),[o.apiKey]),g=useCallback(async c=>{u(true);try{let l=await fetch(`${e}/health`,{headers:f(c)});if(!l.ok)throw new Error(`Authentication failed: ${l.status}`);let d={authenticated:!0,apiKey:c,permission:c.startsWith("gk_")?"write":"read"};s(d);try{localStorage.setItem(T,c);}catch{}return d}catch(l){throw s({authenticated:false}),l}finally{u(false);}},[e,f]),p=useCallback(()=>{s({authenticated:false}),t(null);try{localStorage.removeItem(T);}catch{}},[]),a=useCallback(async()=>{let c=i.apiKey||o.apiKey;if(!c)return null;try{let l=await fetch(`${e}/network/usage`,{headers:f(c)});if(!l.ok)return null;let d=await l.json(),P={planAllocation:d.plan_allocation??d.planAllocation??0,inferenceUsed:d.inference_used??d.inferenceUsed??0,ledgerSpent:d.ledger_spent??d.ledgerSpent??0,totalUsed:d.total_used??d.totalUsed??0,remaining:d.remaining??0,percent:d.percent??0,exceeded:d.exceeded??!1};return t(P),P}catch{return null}},[i.apiKey,o.apiKey,e,f]);return useEffect(()=>{let c=o.apiKey;if(c){s({authenticated:true,apiKey:c,permission:c.startsWith("gk_")?"write":"read"});return}try{let l=localStorage.getItem(T);l&&s({authenticated:!0,apiKey:l,permission:l.startsWith("gk_")?"write":"read"});}catch{}},[o.apiKey]),{session:i,budget:r,loading:n,login:g,logout:p,refreshBudget:a}}var $=1e3,_=1e3,U=100;function x(o,e){if(o==="skill"){let r=U+Math.ceil(e/4);return {type:o,totalBytes:e,totalMegabytes:e/1e6,baseCost:r,multiplier:$,registrationCostTokens:r*$}}let i=Math.ceil(e/1e6),s=U+i;return {type:o,totalBytes:e,totalMegabytes:i,baseCost:s,multiplier:_,registrationCostTokens:s*_}}function W(o){let e=o.stacknetUrl||o.apiBaseUrl,i=o.apiKey,[s,r]=useState(false),[t,n]=useState(null),u=useCallback(()=>{if(!i)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${i}`}},[i]),f=useCallback(async p=>{r(true),n(null);try{let a=await fetch(`${e}/skills`,{method:"POST",headers:u(),body:JSON.stringify(p)});if(!a.ok){let c=await a.json().catch(()=>({error:`HTTP ${a.status}`}));throw new Error(c.error||`Registration failed: ${a.status}`)}return await a.json()}catch(a){throw n(a.message),a}finally{r(false);}},[e,u]),g=useCallback(async p=>{r(true),n(null);try{let a=await fetch(`${e}/tensors`,{method:"POST",headers:u(),body:JSON.stringify(p)});if(!a.ok){let c=await a.json().catch(()=>({error:`HTTP ${a.status}`}));throw new Error(c.error||`Registration failed: ${a.status}`)}return await a.json()}catch(a){throw n(a.message),a}finally{r(false);}},[e,u]);return {registerSkill:f,registerTensor:g,estimateCost:x,registering:s,error:t}}export{x as estimateCost,R as useRackClient,W as useRackRegister,z as useRackSession,H as useRepoPush,D as useRepoTree,B as useRepos};
|
package/dist/index.cjs
CHANGED
|
@@ -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');async function
|
|
2
|
-
`),
|
|
3
|
-
`),lang:l||void 0}),
|
|
1
|
+
'use strict';var react=require('react'),lucideReact=require('lucide-react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');async function y(t,e,a,r){let s={"Content-Type":"application/json",...a?.headers};r&&(s.Authorization=`Bearer ${r}`);let i=await fetch(`${t}${e}`,{...a,headers:s});if(!i.ok){let o=`HTTP ${i.status}`;try{let l=await i.json();l.error&&(o=l.error);}catch{}throw new Error(o)}return i.json()}function T(t){let e=t.apiBaseUrl,a=t.authorMid,r=t.ownerMid,s=t.apiKey;return react.useMemo(()=>({async listRepos(i){let o=i||r?`?owner=${encodeURIComponent(i||r)}`:"";return (await y(e,`/api/rack/repos${o}`,void 0,s)).repos||[]},async initRepo(i){return y(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...i,owner_mid:r})},s)},async push(i,o){return y(e,`/api/rack/${i}/push`,{method:"POST",body:JSON.stringify({...o,author_mid:a})},s)},async getTree(i,o="main"){let l=await y(e,`/api/rack/${i}/tree/${o}`,void 0,s);return {tree:l.tree,commit_cid:l.commit_cid}},async getBlob(i,o){return (await y(e,`/api/rack/${i}/blob/${o}`,void 0,s)).content},async getLog(i,o,l){let m=new URLSearchParams;o&&m.set("ref",o),l&&m.set("max_count",String(l));let h=m.toString()?`?${m}`:"";return (await y(e,`/api/rack/${i}/log${h}`,void 0,s)).commits||[]},async getBranches(i){return (await y(e,`/api/rack/${i}/branches`,void 0,s)).branches||[]},async getDiff(i,o,l){return (await y(e,`/api/rack/${i}/diff/${o}/${l}`,void 0,s)).diff?.entries||[]},async starRepo(i){return y(e,`/api/rack/${i}/star`,{method:"POST"},s)},async unstarRepo(i){return y(e,`/api/rack/${i}/star`,{method:"DELETE"},s)},async getStarInfo(i){return y(e,`/api/rack/${i}/stars`,void 0,s)}}),[e,a,r,s])}function L(t){let e=T(t),a=react.useRef(e);a.current=e;let[r,s]=react.useState([]),[i,o]=react.useState(true),[l,m]=react.useState(null),h=react.useRef(true),f=react.useRef(null),d=react.useCallback(async()=>{f.current?.abort();let c=new AbortController;f.current=c;try{h.current&&(o(!0),m(null));let u=await a.current.listRepos();h.current&&!c.signal.aborted&&s(u);}catch(u){h.current&&!c.signal.aborted&&m(u instanceof Error?u.message:"Failed to load repos");}finally{h.current&&!c.signal.aborted&&o(false);}},[]);return react.useEffect(()=>(h.current=true,d(),()=>{h.current=false,f.current?.abort();}),[d]),{repos:r,loading:i,error:l,refresh:d}}function be(t){return Object.entries(t).map(([e,a])=>{let r=a.indexOf(":"),s=r>0?a.slice(0,r):"100644",i=r>0?a.slice(r+1):a;return {path:e,mode:s,cid:i,isDir:s==="040000"}}).sort((e,a)=>e.isDir!==a.isDir?e.isDir?-1:1:e.path.localeCompare(a.path))}function U(t,e,a="main"){let r=T(t),[s,i]=react.useState([]),[o,l]=react.useState(false),[m,h]=react.useState(null),f=react.useRef(true),d=react.useCallback(async()=>{if(e)try{f.current&&(l(!0),h(null));let{tree:u}=await r.getTree(e,a);f.current&&i(be(u.entries));}catch(u){f.current&&h(u instanceof Error?u.message:"Failed to load tree");}finally{f.current&&l(false);}},[r,e,a]);react.useEffect(()=>(f.current=true,d(),()=>{f.current=false;}),[d]);let c=react.useCallback(async u=>{if(!e)throw new Error("No repo selected");return r.getBlob(e,u)},[r,e]);return {entries:s,loading:o,error:m,refresh:d,getFileContent:c}}function Ce(t){let e=T(t),[a,r]=react.useState(false),[s,i]=react.useState(null),o=react.useRef(true);return react.useEffect(()=>(o.current=true,()=>{o.current=false;}),[]),{push:react.useCallback(async(m,h,f,d)=>{try{return o.current&&(r(!0),i(null)),await e.push(m,{files:h,message:f,branch:d})}catch(c){let u=c instanceof Error?c.message:"Push failed";return o.current&&i(u),null}finally{o.current&&r(false);}},[e]),pushing:a,error:s}}var D="stacknet-rack-apikey";function Te(t){let e=t.stacknetUrl||t.apiBaseUrl,[a,r]=react.useState({authenticated:false}),[s,i]=react.useState(null),[o,l]=react.useState(false),m=react.useCallback(c=>({"Content-Type":"application/json",...c||t.apiKey?{Authorization:`Bearer ${c||t.apiKey}`}:{}}),[t.apiKey]),h=react.useCallback(async c=>{l(true);try{let u=await fetch(`${e}/health`,{headers:m(c)});if(!u.ok)throw new Error(`Authentication failed: ${u.status}`);let p={authenticated:!0,apiKey:c,permission:c.startsWith("gk_")?"write":"read"};r(p);try{localStorage.setItem(D,c);}catch{}return p}catch(u){throw r({authenticated:false}),u}finally{l(false);}},[e,m]),f=react.useCallback(()=>{r({authenticated:false}),i(null);try{localStorage.removeItem(D);}catch{}},[]),d=react.useCallback(async()=>{let c=a.apiKey||t.apiKey;if(!c)return null;try{let u=await fetch(`${e}/network/usage`,{headers:m(c)});if(!u.ok)return null;let p=await u.json(),b={planAllocation:p.plan_allocation??p.planAllocation??0,inferenceUsed:p.inference_used??p.inferenceUsed??0,ledgerSpent:p.ledger_spent??p.ledgerSpent??0,totalUsed:p.total_used??p.totalUsed??0,remaining:p.remaining??0,percent:p.percent??0,exceeded:p.exceeded??!1};return i(b),b}catch{return null}},[a.apiKey,t.apiKey,e,m]);return react.useEffect(()=>{let c=t.apiKey;if(c){r({authenticated:true,apiKey:c,permission:c.startsWith("gk_")?"write":"read"});return}try{let u=localStorage.getItem(D);u&&r({authenticated:!0,apiKey:u,permission:u.startsWith("gk_")?"write":"read"});}catch{}},[t.apiKey]),{session:a,budget:s,loading:o,login:h,logout:f,refreshBudget:d}}var X=1e3,ee=1e3,te=100;function re(t,e){if(t==="skill"){let s=te+Math.ceil(e/4);return {type:t,totalBytes:e,totalMegabytes:e/1e6,baseCost:s,multiplier:X,registrationCostTokens:s*X}}let a=Math.ceil(e/1e6),r=te+a;return {type:t,totalBytes:e,totalMegabytes:a,baseCost:r,multiplier:ee,registrationCostTokens:r*ee}}function Ee(t){let e=t.stacknetUrl||t.apiBaseUrl,a=t.apiKey,[r,s]=react.useState(false),[i,o]=react.useState(null),l=react.useCallback(()=>{if(!a)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${a}`}},[a]),m=react.useCallback(async f=>{s(true),o(null);try{let d=await fetch(`${e}/skills`,{method:"POST",headers:l(),body:JSON.stringify(f)});if(!d.ok){let c=await d.json().catch(()=>({error:`HTTP ${d.status}`}));throw new Error(c.error||`Registration failed: ${d.status}`)}return await d.json()}catch(d){throw o(d.message),d}finally{s(false);}},[e,l]),h=react.useCallback(async f=>{s(true),o(null);try{let d=await fetch(`${e}/tensors`,{method:"POST",headers:l(),body:JSON.stringify(f)});if(!d.ok){let c=await d.json().catch(()=>({error:`HTTP ${d.status}`}));throw new Error(c.error||`Registration failed: ${d.status}`)}return await d.json()}catch(d){throw o(d.message),d}finally{s(false);}},[e,l]);return {registerSkill:m,registerTensor:h,estimateCost:re,registering:r,error:i}}function R(...t){return tailwindMerge.twMerge(clsx.clsx(t))}var $e=/^(https?:\/\/|mailto:|\/[^/])/i;function ze(t){let e=t.trim();return $e.test(e)?e:null}function $(t){let e=[],a=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,r=0,s,i=0;for(;(s=a.exec(t))!==null;){s.index>r&&e.push(t.slice(r,s.index));let o=`i${i++}`;if(s[1])e.push(jsxRuntime.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[0.85em] font-mono text-pink-400",children:s[1].slice(1,-1)},o));else if(s[2])e.push(jsxRuntime.jsx("strong",{children:s[3]},o));else if(s[4])e.push(jsxRuntime.jsx("em",{children:s[5]},o));else if(s[6])e.push(jsxRuntime.jsx("em",{children:s[7]},o));else if(s[8]){let l=ze(s[10]);l?e.push(jsxRuntime.jsx("a",{href:l,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:s[9]},o)):e.push(s[9]);}r=s.index+s[0].length;}return r<t.length&&e.push(t.slice(r)),e.length>0?e:[t]}function Me(t){let e=t.split(`
|
|
2
|
+
`),a=[],r=0;for(;r<e.length;){let s=e[r];if(s.trim()===""){r++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(s.trim())){a.push({type:"hr"}),r++;continue}let i=s.match(/^(#{1,6})\s+(.+)/);if(i){a.push({type:"heading",level:i[1].length,content:i[2]}),r++;continue}if(s.trim().startsWith("```")){let l=s.trim().slice(3).trim(),m=[];for(r++;r<e.length&&!e[r].trim().startsWith("```");)m.push(e[r]),r++;a.push({type:"code",content:m.join(`
|
|
3
|
+
`),lang:l||void 0}),r++;continue}if(/^\s*[-*+]\s/.test(s)){let l=[];for(;r<e.length&&/^\s*[-*+]\s/.test(e[r]);)l.push(e[r].replace(/^\s*[-*+]\s+/,"")),r++;a.push({type:"ul",items:l});continue}if(/^\s*\d+[.)]\s/.test(s)){let l=[];for(;r<e.length&&/^\s*\d+[.)]\s/.test(e[r]);)l.push(e[r].replace(/^\s*\d+[.)]\s+/,"")),r++;a.push({type:"ol",items:l});continue}let o=[];for(;r<e.length&&e[r].trim()!==""&&!e[r].match(/^#{1,6}\s/)&&!e[r].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[r])&&!/^\s*\d+[.)]\s/.test(e[r]);)o.push(e[r]),r++;o.length>0&&a.push({type:"paragraph",content:o.join(" ")});}return a}var _e={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 Le(t,e){switch(t.type){case "hr":return jsxRuntime.jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let a=Math.min(Math.max(t.level||1,1),6),r=`h${a}`;return jsxRuntime.jsx(r,{className:R("text-foreground",_e[a]),children:$(t.content||"")},`b${e}`)}case "paragraph":return jsxRuntime.jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:$(t.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:t.content})},`b${e}`);case "ul":return jsxRuntime.jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:t.items?.map((a,r)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:$(a)},`li${e}-${r}`))},`b${e}`);case "ol":return jsxRuntime.jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:t.items?.map((a,r)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:$(a)},`li${e}-${r}`))},`b${e}`);default:return null}}function j({content:t,className:e}){let a=Me(t);return jsxRuntime.jsx("div",{className:R("text-sm",e),children:a.map((r,s)=>Le(r,s))})}function ae({open:t,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:R("shrink-0 transition-transform duration-150",t?"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 ne({size:t=20,className:e}){return jsxRuntime.jsx("svg",{width:t,height:t,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function O({size:t=20,className:e}){return jsxRuntime.jsx("svg",{width:t,height:t,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 ie({size:t=20,className:e}){return jsxRuntime.jsx("svg",{width:t,height:t,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 Be(){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 De(){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 Fe(){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 le(){let[t,e]=react.useState(false);return react.useEffect(()=>{if(typeof window>"u")return;let a=()=>e(window.innerWidth<768);return a(),window.addEventListener("resize",a),()=>window.removeEventListener("resize",a)},[]),t}function ce({onClose:t,children:e,title:a}){let r=le(),s=react.useRef(t);return s.current=t,react.useEffect(()=>{let i=o=>{o.key==="Escape"&&s.current();};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[]),r?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:t,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:i=>i.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:a}),jsxRuntime.jsx("button",{onClick:t,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(O,{size:20})})]}),e]})]}):jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:t,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:i=>i.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:a}),jsxRuntime.jsx("button",{onClick:t,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(O,{size:20})})]}),e]})]})}function je({onClose:t,onCreated:e,config:a}){let[r,s]=react.useState(""),[i,o]=react.useState(""),[l,m]=react.useState(""),[h,f]=react.useState(false),[d,c]=react.useState(null);return jsxRuntime.jsx(ce,{title:"Write skill instructions",onClose:t,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsxRuntime.jsx("input",{id:"skill-name",value:r,onChange:p=>s(p.target.value),placeholder:"weekly-status-report",className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-desc",className:"text-sm text-muted-foreground",children:"Description"}),jsxRuntime.jsx("textarea",{id:"skill-desc",value:i,onChange:p=>o(p.target.value),placeholder:"Generate weekly status reports from recent work.",rows:3,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-instructions",className:"text-sm text-muted-foreground",children:"Instructions"}),jsxRuntime.jsx("textarea",{id:"skill-instructions",value:l,onChange:p=>m(p.target.value),placeholder:"Summarize my recent work in three sections: wins, blockers, and next steps.",rows:8,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),d&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:d}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsxRuntime.jsx("button",{onClick:t,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsxRuntime.jsx("button",{onClick:async()=>{if(r.trim()){f(true),c(null);try{let p=a.apiBaseUrl||"",b=`# ${r.trim()}
|
|
4
4
|
|
|
5
|
-
${
|
|
5
|
+
${i.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:P}],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||!t.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 $e({onClose:n,onCreated:e,config:s}){let t=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||"",R=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:R,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:P}=await E.json(),k=await fetch(`${v}/api/rack/${P}/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(te,{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:()=>t.current?.click(),className:N("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",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(X,{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:t,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 Se({onClose:n,onSelect:e}){let s=ee(),t=react.useRef(null),o=react.useRef(n);o.current=n,react.useEffect(()=>{if(s)return;let i=l=>{t.current&&l.target instanceof Node&&!t.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(Ee,{}),label:"Create with Geoff"},{id:"write",icon:jsxRuntime.jsx(Te,{}),label:"Write skill instructions"},{id:"upload",icon:jsxRuntime.jsx(ze,{}),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:t,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 Me({entry:n,selected:e,onSelect:s,depth:t=0}){return jsxRuntime.jsxs("button",{onClick:()=>s(n),className:N("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+t*16}px`},children:[jsxRuntime.jsx("span",{className:"truncate flex-1",children:n.path.split("/").pop()}),n.isDir&&jsxRuntime.jsx(Y,{className:"ml-auto text-muted-foreground"})]})}function Ie({repo:n,selected:e,expanded:s,onSelect:t,onToggle:o,children:a}){return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>{t(),o();},className:N("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsxRuntime.jsx(Y,{open:s}),jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4 shrink-0"}),jsxRuntime.jsx("span",{className:"truncate",children:n.name})]}),s&&a]})}function Le({entry:n,content:e,loading:s,repoName:t}){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:N("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(U,{content:e||""}):jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function Ae({config:n,category:e,className:s,style:t}){let{repos:o,loading:a,error:i,refresh:l}=_(n),[m,p]=react.useState(null),[f,x]=react.useState(null),[u,d]=react.useState(null),[v,R]=react.useState(null),[E,P]=react.useState(false),[k,b]=react.useState(""),[y,j]=react.useState(false),[O,H]=react.useState(false),[V,I]=react.useState(null),re=o.find(g=>g.repo_id===m),{entries:ne,getFileContent:Z}=F(n,f),W=o.filter(g=>!k||g.name.toLowerCase().includes(k.toLowerCase())),oe=react.useCallback(async g=>{if(!g.isDir){d(g),P(true);try{let C=await Z(g.cid);R(C);}catch(C){let ie=C instanceof Error?C.message:"Unknown error";R(`Failed to load file: ${ie}`);}finally{P(false);}}},[Z]);react.useEffect(()=>{o.length>0&&!m&&(p(o[0].repo_id),x(o[0].repo_id));},[o,m]);let se=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"):I(g);};return jsxRuntime.jsxs("div",{className:N("flex flex-1 h-full min-h-0",s),style:t,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(G,{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:()=>{j(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:()=>j(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsxRuntime.jsx(G,{size:20})}),jsxRuntime.jsx("button",{onClick:()=>H(!O),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(X,{size:20})})]})}),O&&jsxRuntime.jsx(Se,{onClose:()=>H(false),onSelect:se}),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}):W.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:W.map(g=>jsxRuntime.jsx(Ie,{repo:g,selected:m===g.repo_id,expanded:f===g.repo_id,onSelect:()=>{p(g.repo_id),d(null),R(null);},onToggle:()=>x(f===g.repo_id?null:g.repo_id),children:jsxRuntime.jsx("div",{className:"ml-10 pl-1",children:ne.map(C=>jsxRuntime.jsx(Me,{entry:C,selected:u?.path===C.path,onSelect:oe,depth:C.path.split("/").length-1},C.path))})},g.repo_id))})})]}),jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntime.jsx(Le,{entry:u,content:v,loading:E,repoName:re?.name||""})}),V==="write"&&jsxRuntime.jsx(Pe,{config:n,onClose:()=>I(null),onCreated:l}),V==="upload"&&jsxRuntime.jsx($e,{config:n,onClose:()=>I(null),onCreated:l})]})}
|
|
10
|
-
exports.Markdown=
|
|
9
|
+
${l.trim()}`,N=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.trim(),description:i.trim(),skill_md:b,content_type:"code"})});if(!N.ok){let S=`Failed to register skill (${N.status})`;try{let k=await N.json();k.error&&(S=k.error);}catch{}throw new Error(S)}e?.(),t();}catch(p){c(p instanceof Error?p.message:"Failed to create skill");}finally{f(false);}}},disabled:h||!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:h?"Creating...":"Create"})]})]})})}function Oe({onClose:t,onCreated:e,config:a}){let r=react.useRef(null),[s,i]=react.useState(false),[o,l]=react.useState(false),[m,h]=react.useState(null),f=async c=>{l(true),h(null);try{let u=await c.text(),p=a.apiBaseUrl||"",b=c.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),N=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:b,skill_md:u,content_type:"code"})});if(!N.ok){let S=`Failed to register skill (${N.status})`;try{let k=await N.json();k.error&&(S=k.error);}catch{}throw new Error(S)}e?.(),t();}catch(u){h(u instanceof Error?u.message:"Upload failed");}finally{l(false);}};return jsxRuntime.jsx(ce,{title:"Upload skill",onClose:t,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{onDragOver:c=>{c.preventDefault(),i(true);},onDragLeave:()=>i(false),onDrop:c=>{c.preventDefault(),i(false);let u=c.dataTransfer.files[0];u&&f(u);},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",s?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsxRuntime.jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsxRuntime.jsx(ie,{size:20,className:"text-muted-foreground"})}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:o?"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:c=>{let u=c.target.files?.[0];u&&f(u);}}),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 He({onClose:t,onSelect:e}){let a=le(),r=react.useRef(null),s=react.useRef(t);s.current=t,react.useEffect(()=>{if(a)return;let o=l=>{r.current&&l.target instanceof Node&&!r.current.contains(l.target)&&s.current();};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[a]);let i=[{id:"create-with-geoff",icon:jsxRuntime.jsx(Be,{}),label:"Create with Geoff"},{id:"write",icon:jsxRuntime.jsx(De,{}),label:"Write skill instructions"},{id:"upload",icon:jsxRuntime.jsx(Fe,{}),label:"Upload a skill"}];return a?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:t,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:o=>o.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),i.map(o=>jsxRuntime.jsxs("button",{onClick:()=>{e(o.id),t();},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:[o.icon,o.label]},o.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:i.map(o=>jsxRuntime.jsxs("button",{onClick:()=>{e(o.id),t();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[o.icon,o.label]},o.id))})}function Ke({entry:t,selected:e,onSelect:a,depth:r=0}){return jsxRuntime.jsxs("button",{onClick:()=>a(t),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:t.path.split("/").pop()}),t.isDir&&jsxRuntime.jsx(ae,{className:"ml-auto text-muted-foreground"})]})}function We({repo:t,selected:e,expanded:a,onSelect:r,onToggle:s,children:i}){return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>{r(),s();},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(ae,{open:a}),jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4 shrink-0"}),jsxRuntime.jsx("span",{className:"truncate",children:t.name})]}),a&&i]})}function Ve({entry:t,content:e,loading:a,repoName:r}){let[s,i]=react.useState(false),o=react.useRef(null);react.useEffect(()=>()=>{o.current&&clearTimeout(o.current);},[]);let[l,m]=react.useState(false),h=async()=>{if(e)try{await navigator.clipboard.writeText(e),i(!0),m(!1),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>i(!1),2e3);}catch{m(true),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>m(false),2e3);}};if(!t)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(a)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let f=t.path.split("/").pop()||t.path,d=/\.(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:h,"aria-label":"Copy file content",className:R("rounded p-1 transition-colors",s?"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:d?jsxRuntime.jsx(j,{content:e||""}):jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function Ze({config:t,category:e,className:a,style:r}){let{repos:s,loading:i,error:o,refresh:l}=L(t),[m,h]=react.useState(null),[f,d]=react.useState(null),[c,u]=react.useState(null),[p,b]=react.useState(null),[N,S]=react.useState(false),[k,H]=react.useState(""),[ue,K]=react.useState(false),[W,V]=react.useState(false),[Z,z]=react.useState(null),de=s.find(x=>x.repo_id===m),{entries:me,getFileContent:J}=U(t,f),q=s.filter(x=>!k||x.name.toLowerCase().includes(k.toLowerCase())),fe=react.useCallback(async x=>{if(!x.isDir){u(x),S(true);try{let C=await J(x.cid);b(C);}catch(C){let ge=C instanceof Error?C.message:"Unknown error";b(`Failed to load file: ${ge}`);}finally{S(false);}}},[J]);react.useEffect(()=>{s.length>0&&!m&&(h(s[0].repo_id),d(s[0].repo_id));},[s,m]);let pe=x=>{x==="create-with-geoff"?window.open(`https://www.geoff.ai/?p=${encodeURIComponent("Let's create a skill together using your skill-creator skill. First ask me what the skill should do.")}`,"_blank","noopener,noreferrer"):z(x);};return jsxRuntime.jsxs("div",{className:R("flex flex-1 h-full min-h-0",a),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:ue?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(ne,{size:16,className:"shrink-0 text-muted-foreground"}),jsxRuntime.jsx("input",{type:"text",value:k,onChange:x=>H(x.target.value),placeholder:"Search",autoFocus:true,"aria-label":"Search items",className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),jsxRuntime.jsx("button",{onClick:()=>{K(false),H("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(O,{size:16})})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground capitalize",children:e||"Items"}),jsxRuntime.jsx("button",{onClick:()=>K(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsxRuntime.jsx(ne,{size:20})}),jsxRuntime.jsx("button",{onClick:()=>V(!W),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(ie,{size:20})})]})}),W&&jsxRuntime.jsx(He,{onClose:()=>V(false),onSelect:pe}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:i?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"})}):o?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:o}):q.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:q.map(x=>jsxRuntime.jsx(We,{repo:x,selected:m===x.repo_id,expanded:f===x.repo_id,onSelect:()=>{h(x.repo_id),u(null),b(null);},onToggle:()=>d(f===x.repo_id?null:x.repo_id),children:jsxRuntime.jsx("div",{className:"ml-10 pl-1",children:me.map(C=>jsxRuntime.jsx(Ke,{entry:C,selected:c?.path===C.path,onSelect:fe,depth:C.path.split("/").length-1},C.path))})},x.repo_id))})})]}),jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntime.jsx(Ve,{entry:c,content:p,loading:N,repoName:de?.name||""})}),Z==="write"&&jsxRuntime.jsx(je,{config:t,onClose:()=>z(null),onCreated:l}),Z==="upload"&&jsxRuntime.jsx(Oe,{config:t,onClose:()=>z(null),onCreated:l})]})}
|
|
10
|
+
exports.Markdown=j;exports.RackBrowser=Ze;exports.estimateCost=re;exports.useRackClient=T;exports.useRackRegister=Ee;exports.useRackSession=Te;exports.useRepoPush=Ce;exports.useRepoTree=U;exports.useRepos=L;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { DiffEntry, InitResult, PushResult, RackConfig, RepoCommit, RepoFile, RepoInfo, RepoTree, TreeEntry } from './types/index.cjs';
|
|
2
|
-
export { RackClient, useRackClient, useRepoPush, useRepoTree, useRepos } from './hooks/index.cjs';
|
|
1
|
+
export { CostEstimate, DiffEntry, InitResult, PushResult, RackConfig, RackSession, RepoCommit, RepoFile, RepoInfo, RepoTree, SkillRegistrationInput, SkillRegistrationResult, StarInfo, StarResult, TensorRegistrationInput, TensorRegistrationResult, TokenBudget, TreeEntry } from './types/index.cjs';
|
|
2
|
+
export { RackClient, estimateCost, useRackClient, useRackRegister, useRackSession, useRepoPush, useRepoTree, useRepos } from './hooks/index.cjs';
|
|
3
3
|
export { Markdown, RackBrowser, RackBrowserProps } from './components/index.cjs';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { DiffEntry, InitResult, PushResult, RackConfig, RepoCommit, RepoFile, RepoInfo, RepoTree, TreeEntry } from './types/index.js';
|
|
2
|
-
export { RackClient, useRackClient, useRepoPush, useRepoTree, useRepos } from './hooks/index.js';
|
|
1
|
+
export { CostEstimate, DiffEntry, InitResult, PushResult, RackConfig, RackSession, RepoCommit, RepoFile, RepoInfo, RepoTree, SkillRegistrationInput, SkillRegistrationResult, StarInfo, StarResult, TensorRegistrationInput, TensorRegistrationResult, TokenBudget, TreeEntry } from './types/index.js';
|
|
2
|
+
export { RackClient, estimateCost, useRackClient, useRackRegister, useRackSession, useRepoPush, useRepoTree, useRepos } from './hooks/index.js';
|
|
3
3
|
export { Markdown, RackBrowser, RackBrowserProps } from './components/index.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {useMemo,useRef,useState,useCallback,useEffect}from'react';import {Loader2,FileText}from'lucide-react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsx,jsxs,Fragment}from'react/jsx-runtime';async function
|
|
2
|
-
`),
|
|
3
|
-
`),lang:l||void 0}),
|
|
1
|
+
import {useMemo,useRef,useState,useCallback,useEffect}from'react';import {Loader2,FileText}from'lucide-react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsx,jsxs,Fragment}from'react/jsx-runtime';async function y(t,e,a,r){let s={"Content-Type":"application/json",...a?.headers};r&&(s.Authorization=`Bearer ${r}`);let i=await fetch(`${t}${e}`,{...a,headers:s});if(!i.ok){let o=`HTTP ${i.status}`;try{let l=await i.json();l.error&&(o=l.error);}catch{}throw new Error(o)}return i.json()}function T(t){let e=t.apiBaseUrl,a=t.authorMid,r=t.ownerMid,s=t.apiKey;return useMemo(()=>({async listRepos(i){let o=i||r?`?owner=${encodeURIComponent(i||r)}`:"";return (await y(e,`/api/rack/repos${o}`,void 0,s)).repos||[]},async initRepo(i){return y(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...i,owner_mid:r})},s)},async push(i,o){return y(e,`/api/rack/${i}/push`,{method:"POST",body:JSON.stringify({...o,author_mid:a})},s)},async getTree(i,o="main"){let l=await y(e,`/api/rack/${i}/tree/${o}`,void 0,s);return {tree:l.tree,commit_cid:l.commit_cid}},async getBlob(i,o){return (await y(e,`/api/rack/${i}/blob/${o}`,void 0,s)).content},async getLog(i,o,l){let m=new URLSearchParams;o&&m.set("ref",o),l&&m.set("max_count",String(l));let h=m.toString()?`?${m}`:"";return (await y(e,`/api/rack/${i}/log${h}`,void 0,s)).commits||[]},async getBranches(i){return (await y(e,`/api/rack/${i}/branches`,void 0,s)).branches||[]},async getDiff(i,o,l){return (await y(e,`/api/rack/${i}/diff/${o}/${l}`,void 0,s)).diff?.entries||[]},async starRepo(i){return y(e,`/api/rack/${i}/star`,{method:"POST"},s)},async unstarRepo(i){return y(e,`/api/rack/${i}/star`,{method:"DELETE"},s)},async getStarInfo(i){return y(e,`/api/rack/${i}/stars`,void 0,s)}}),[e,a,r,s])}function L(t){let e=T(t),a=useRef(e);a.current=e;let[r,s]=useState([]),[i,o]=useState(true),[l,m]=useState(null),h=useRef(true),f=useRef(null),d=useCallback(async()=>{f.current?.abort();let c=new AbortController;f.current=c;try{h.current&&(o(!0),m(null));let u=await a.current.listRepos();h.current&&!c.signal.aborted&&s(u);}catch(u){h.current&&!c.signal.aborted&&m(u instanceof Error?u.message:"Failed to load repos");}finally{h.current&&!c.signal.aborted&&o(false);}},[]);return useEffect(()=>(h.current=true,d(),()=>{h.current=false,f.current?.abort();}),[d]),{repos:r,loading:i,error:l,refresh:d}}function be(t){return Object.entries(t).map(([e,a])=>{let r=a.indexOf(":"),s=r>0?a.slice(0,r):"100644",i=r>0?a.slice(r+1):a;return {path:e,mode:s,cid:i,isDir:s==="040000"}}).sort((e,a)=>e.isDir!==a.isDir?e.isDir?-1:1:e.path.localeCompare(a.path))}function U(t,e,a="main"){let r=T(t),[s,i]=useState([]),[o,l]=useState(false),[m,h]=useState(null),f=useRef(true),d=useCallback(async()=>{if(e)try{f.current&&(l(!0),h(null));let{tree:u}=await r.getTree(e,a);f.current&&i(be(u.entries));}catch(u){f.current&&h(u instanceof Error?u.message:"Failed to load tree");}finally{f.current&&l(false);}},[r,e,a]);useEffect(()=>(f.current=true,d(),()=>{f.current=false;}),[d]);let c=useCallback(async u=>{if(!e)throw new Error("No repo selected");return r.getBlob(e,u)},[r,e]);return {entries:s,loading:o,error:m,refresh:d,getFileContent:c}}function Ce(t){let e=T(t),[a,r]=useState(false),[s,i]=useState(null),o=useRef(true);return useEffect(()=>(o.current=true,()=>{o.current=false;}),[]),{push:useCallback(async(m,h,f,d)=>{try{return o.current&&(r(!0),i(null)),await e.push(m,{files:h,message:f,branch:d})}catch(c){let u=c instanceof Error?c.message:"Push failed";return o.current&&i(u),null}finally{o.current&&r(false);}},[e]),pushing:a,error:s}}var D="stacknet-rack-apikey";function Te(t){let e=t.stacknetUrl||t.apiBaseUrl,[a,r]=useState({authenticated:false}),[s,i]=useState(null),[o,l]=useState(false),m=useCallback(c=>({"Content-Type":"application/json",...c||t.apiKey?{Authorization:`Bearer ${c||t.apiKey}`}:{}}),[t.apiKey]),h=useCallback(async c=>{l(true);try{let u=await fetch(`${e}/health`,{headers:m(c)});if(!u.ok)throw new Error(`Authentication failed: ${u.status}`);let p={authenticated:!0,apiKey:c,permission:c.startsWith("gk_")?"write":"read"};r(p);try{localStorage.setItem(D,c);}catch{}return p}catch(u){throw r({authenticated:false}),u}finally{l(false);}},[e,m]),f=useCallback(()=>{r({authenticated:false}),i(null);try{localStorage.removeItem(D);}catch{}},[]),d=useCallback(async()=>{let c=a.apiKey||t.apiKey;if(!c)return null;try{let u=await fetch(`${e}/network/usage`,{headers:m(c)});if(!u.ok)return null;let p=await u.json(),b={planAllocation:p.plan_allocation??p.planAllocation??0,inferenceUsed:p.inference_used??p.inferenceUsed??0,ledgerSpent:p.ledger_spent??p.ledgerSpent??0,totalUsed:p.total_used??p.totalUsed??0,remaining:p.remaining??0,percent:p.percent??0,exceeded:p.exceeded??!1};return i(b),b}catch{return null}},[a.apiKey,t.apiKey,e,m]);return useEffect(()=>{let c=t.apiKey;if(c){r({authenticated:true,apiKey:c,permission:c.startsWith("gk_")?"write":"read"});return}try{let u=localStorage.getItem(D);u&&r({authenticated:!0,apiKey:u,permission:u.startsWith("gk_")?"write":"read"});}catch{}},[t.apiKey]),{session:a,budget:s,loading:o,login:h,logout:f,refreshBudget:d}}var X=1e3,ee=1e3,te=100;function re(t,e){if(t==="skill"){let s=te+Math.ceil(e/4);return {type:t,totalBytes:e,totalMegabytes:e/1e6,baseCost:s,multiplier:X,registrationCostTokens:s*X}}let a=Math.ceil(e/1e6),r=te+a;return {type:t,totalBytes:e,totalMegabytes:a,baseCost:r,multiplier:ee,registrationCostTokens:r*ee}}function Ee(t){let e=t.stacknetUrl||t.apiBaseUrl,a=t.apiKey,[r,s]=useState(false),[i,o]=useState(null),l=useCallback(()=>{if(!a)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${a}`}},[a]),m=useCallback(async f=>{s(true),o(null);try{let d=await fetch(`${e}/skills`,{method:"POST",headers:l(),body:JSON.stringify(f)});if(!d.ok){let c=await d.json().catch(()=>({error:`HTTP ${d.status}`}));throw new Error(c.error||`Registration failed: ${d.status}`)}return await d.json()}catch(d){throw o(d.message),d}finally{s(false);}},[e,l]),h=useCallback(async f=>{s(true),o(null);try{let d=await fetch(`${e}/tensors`,{method:"POST",headers:l(),body:JSON.stringify(f)});if(!d.ok){let c=await d.json().catch(()=>({error:`HTTP ${d.status}`}));throw new Error(c.error||`Registration failed: ${d.status}`)}return await d.json()}catch(d){throw o(d.message),d}finally{s(false);}},[e,l]);return {registerSkill:m,registerTensor:h,estimateCost:re,registering:r,error:i}}function R(...t){return twMerge(clsx(t))}var $e=/^(https?:\/\/|mailto:|\/[^/])/i;function ze(t){let e=t.trim();return $e.test(e)?e:null}function $(t){let e=[],a=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,r=0,s,i=0;for(;(s=a.exec(t))!==null;){s.index>r&&e.push(t.slice(r,s.index));let o=`i${i++}`;if(s[1])e.push(jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[0.85em] font-mono text-pink-400",children:s[1].slice(1,-1)},o));else if(s[2])e.push(jsx("strong",{children:s[3]},o));else if(s[4])e.push(jsx("em",{children:s[5]},o));else if(s[6])e.push(jsx("em",{children:s[7]},o));else if(s[8]){let l=ze(s[10]);l?e.push(jsx("a",{href:l,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:s[9]},o)):e.push(s[9]);}r=s.index+s[0].length;}return r<t.length&&e.push(t.slice(r)),e.length>0?e:[t]}function Me(t){let e=t.split(`
|
|
2
|
+
`),a=[],r=0;for(;r<e.length;){let s=e[r];if(s.trim()===""){r++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(s.trim())){a.push({type:"hr"}),r++;continue}let i=s.match(/^(#{1,6})\s+(.+)/);if(i){a.push({type:"heading",level:i[1].length,content:i[2]}),r++;continue}if(s.trim().startsWith("```")){let l=s.trim().slice(3).trim(),m=[];for(r++;r<e.length&&!e[r].trim().startsWith("```");)m.push(e[r]),r++;a.push({type:"code",content:m.join(`
|
|
3
|
+
`),lang:l||void 0}),r++;continue}if(/^\s*[-*+]\s/.test(s)){let l=[];for(;r<e.length&&/^\s*[-*+]\s/.test(e[r]);)l.push(e[r].replace(/^\s*[-*+]\s+/,"")),r++;a.push({type:"ul",items:l});continue}if(/^\s*\d+[.)]\s/.test(s)){let l=[];for(;r<e.length&&/^\s*\d+[.)]\s/.test(e[r]);)l.push(e[r].replace(/^\s*\d+[.)]\s+/,"")),r++;a.push({type:"ol",items:l});continue}let o=[];for(;r<e.length&&e[r].trim()!==""&&!e[r].match(/^#{1,6}\s/)&&!e[r].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[r])&&!/^\s*\d+[.)]\s/.test(e[r]);)o.push(e[r]),r++;o.length>0&&a.push({type:"paragraph",content:o.join(" ")});}return a}var _e={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 Le(t,e){switch(t.type){case "hr":return jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let a=Math.min(Math.max(t.level||1,1),6),r=`h${a}`;return jsx(r,{className:R("text-foreground",_e[a]),children:$(t.content||"")},`b${e}`)}case "paragraph":return jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:$(t.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:t.content})},`b${e}`);case "ul":return jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:t.items?.map((a,r)=>jsx("li",{className:"leading-relaxed",children:$(a)},`li${e}-${r}`))},`b${e}`);case "ol":return jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:t.items?.map((a,r)=>jsx("li",{className:"leading-relaxed",children:$(a)},`li${e}-${r}`))},`b${e}`);default:return null}}function j({content:t,className:e}){let a=Me(t);return jsx("div",{className:R("text-sm",e),children:a.map((r,s)=>Le(r,s))})}function ae({open:t,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:R("shrink-0 transition-transform duration-150",t?"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 ne({size:t=20,className:e}){return jsx("svg",{width:t,height:t,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function O({size:t=20,className:e}){return jsx("svg",{width:t,height:t,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 ie({size:t=20,className:e}){return jsx("svg",{width:t,height:t,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 Be(){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 De(){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 Fe(){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 le(){let[t,e]=useState(false);return useEffect(()=>{if(typeof window>"u")return;let a=()=>e(window.innerWidth<768);return a(),window.addEventListener("resize",a),()=>window.removeEventListener("resize",a)},[]),t}function ce({onClose:t,children:e,title:a}){let r=le(),s=useRef(t);return s.current=t,useEffect(()=>{let i=o=>{o.key==="Escape"&&s.current();};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[]),r?jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:t,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:i=>i.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:a}),jsx("button",{onClick:t,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(O,{size:20})})]}),e]})]}):jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:t,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:i=>i.stopPropagation(),children:[jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsx("h2",{className:"text-lg font-semibold text-foreground",children:a}),jsx("button",{onClick:t,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(O,{size:20})})]}),e]})]})}function je({onClose:t,onCreated:e,config:a}){let[r,s]=useState(""),[i,o]=useState(""),[l,m]=useState(""),[h,f]=useState(false),[d,c]=useState(null);return jsx(ce,{title:"Write skill instructions",onClose:t,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsx("input",{id:"skill-name",value:r,onChange:p=>s(p.target.value),placeholder:"weekly-status-report",className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-desc",className:"text-sm text-muted-foreground",children:"Description"}),jsx("textarea",{id:"skill-desc",value:i,onChange:p=>o(p.target.value),placeholder:"Generate weekly status reports from recent work.",rows:3,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-instructions",className:"text-sm text-muted-foreground",children:"Instructions"}),jsx("textarea",{id:"skill-instructions",value:l,onChange:p=>m(p.target.value),placeholder:"Summarize my recent work in three sections: wins, blockers, and next steps.",rows:8,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),d&&jsx("p",{className:"text-sm text-red-500",children:d}),jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsx("button",{onClick:t,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsx("button",{onClick:async()=>{if(r.trim()){f(true),c(null);try{let p=a.apiBaseUrl||"",b=`# ${r.trim()}
|
|
4
4
|
|
|
5
|
-
${
|
|
5
|
+
${i.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:P}],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||!t.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 $e({onClose:n,onCreated:e,config:s}){let t=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||"",R=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:R,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:P}=await E.json(),k=await fetch(`${v}/api/rack/${P}/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(te,{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:()=>t.current?.click(),className:N("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",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(X,{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:t,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 Se({onClose:n,onSelect:e}){let s=ee(),t=useRef(null),o=useRef(n);o.current=n,useEffect(()=>{if(s)return;let i=l=>{t.current&&l.target instanceof Node&&!t.current.contains(l.target)&&o.current();};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[s]);let a=[{id:"create-with-geoff",icon:jsx(Ee,{}),label:"Create with Geoff"},{id:"write",icon:jsx(Te,{}),label:"Write skill instructions"},{id:"upload",icon:jsx(ze,{}),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:t,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 Me({entry:n,selected:e,onSelect:s,depth:t=0}){return jsxs("button",{onClick:()=>s(n),className:N("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+t*16}px`},children:[jsx("span",{className:"truncate flex-1",children:n.path.split("/").pop()}),n.isDir&&jsx(Y,{className:"ml-auto text-muted-foreground"})]})}function Ie({repo:n,selected:e,expanded:s,onSelect:t,onToggle:o,children:a}){return jsxs("div",{children:[jsxs("button",{onClick:()=>{t(),o();},className:N("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsx(Y,{open:s}),jsx(FileText,{className:"h-4 w-4 shrink-0"}),jsx("span",{className:"truncate",children:n.name})]}),s&&a]})}function Le({entry:n,content:e,loading:s,repoName:t}){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:N("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(U,{content:e||""}):jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function Ae({config:n,category:e,className:s,style:t}){let{repos:o,loading:a,error:i,refresh:l}=_(n),[m,p]=useState(null),[f,x]=useState(null),[u,d]=useState(null),[v,R]=useState(null),[E,P]=useState(false),[k,b]=useState(""),[y,j]=useState(false),[O,H]=useState(false),[V,I]=useState(null),re=o.find(g=>g.repo_id===m),{entries:ne,getFileContent:Z}=F(n,f),W=o.filter(g=>!k||g.name.toLowerCase().includes(k.toLowerCase())),oe=useCallback(async g=>{if(!g.isDir){d(g),P(true);try{let C=await Z(g.cid);R(C);}catch(C){let ie=C instanceof Error?C.message:"Unknown error";R(`Failed to load file: ${ie}`);}finally{P(false);}}},[Z]);useEffect(()=>{o.length>0&&!m&&(p(o[0].repo_id),x(o[0].repo_id));},[o,m]);let se=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"):I(g);};return jsxs("div",{className:N("flex flex-1 h-full min-h-0",s),style:t,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(G,{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:()=>{j(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:()=>j(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsx(G,{size:20})}),jsx("button",{onClick:()=>H(!O),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(X,{size:20})})]})}),O&&jsx(Se,{onClose:()=>H(false),onSelect:se}),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}):W.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:W.map(g=>jsx(Ie,{repo:g,selected:m===g.repo_id,expanded:f===g.repo_id,onSelect:()=>{p(g.repo_id),d(null),R(null);},onToggle:()=>x(f===g.repo_id?null:g.repo_id),children:jsx("div",{className:"ml-10 pl-1",children:ne.map(C=>jsx(Me,{entry:C,selected:u?.path===C.path,onSelect:oe,depth:C.path.split("/").length-1},C.path))})},g.repo_id))})})]}),jsx("div",{className:"flex-1 min-w-0",children:jsx(Le,{entry:u,content:v,loading:E,repoName:re?.name||""})}),V==="write"&&jsx(Pe,{config:n,onClose:()=>I(null),onCreated:l}),V==="upload"&&jsx($e,{config:n,onClose:()=>I(null),onCreated:l})]})}
|
|
10
|
-
export{
|
|
9
|
+
${l.trim()}`,N=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.trim(),description:i.trim(),skill_md:b,content_type:"code"})});if(!N.ok){let S=`Failed to register skill (${N.status})`;try{let k=await N.json();k.error&&(S=k.error);}catch{}throw new Error(S)}e?.(),t();}catch(p){c(p instanceof Error?p.message:"Failed to create skill");}finally{f(false);}}},disabled:h||!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:h?"Creating...":"Create"})]})]})})}function Oe({onClose:t,onCreated:e,config:a}){let r=useRef(null),[s,i]=useState(false),[o,l]=useState(false),[m,h]=useState(null),f=async c=>{l(true),h(null);try{let u=await c.text(),p=a.apiBaseUrl||"",b=c.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),N=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:b,skill_md:u,content_type:"code"})});if(!N.ok){let S=`Failed to register skill (${N.status})`;try{let k=await N.json();k.error&&(S=k.error);}catch{}throw new Error(S)}e?.(),t();}catch(u){h(u instanceof Error?u.message:"Upload failed");}finally{l(false);}};return jsx(ce,{title:"Upload skill",onClose:t,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{onDragOver:c=>{c.preventDefault(),i(true);},onDragLeave:()=>i(false),onDrop:c=>{c.preventDefault(),i(false);let u=c.dataTransfer.files[0];u&&f(u);},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",s?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsx(ie,{size:20,className:"text-muted-foreground"})}),jsx("p",{className:"text-sm text-muted-foreground",children:o?"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:c=>{let u=c.target.files?.[0];u&&f(u);}}),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 He({onClose:t,onSelect:e}){let a=le(),r=useRef(null),s=useRef(t);s.current=t,useEffect(()=>{if(a)return;let o=l=>{r.current&&l.target instanceof Node&&!r.current.contains(l.target)&&s.current();};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[a]);let i=[{id:"create-with-geoff",icon:jsx(Be,{}),label:"Create with Geoff"},{id:"write",icon:jsx(De,{}),label:"Write skill instructions"},{id:"upload",icon:jsx(Fe,{}),label:"Upload a skill"}];return a?jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:t,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:o=>o.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),i.map(o=>jsxs("button",{onClick:()=>{e(o.id),t();},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:[o.icon,o.label]},o.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:i.map(o=>jsxs("button",{onClick:()=>{e(o.id),t();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[o.icon,o.label]},o.id))})}function Ke({entry:t,selected:e,onSelect:a,depth:r=0}){return jsxs("button",{onClick:()=>a(t),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:t.path.split("/").pop()}),t.isDir&&jsx(ae,{className:"ml-auto text-muted-foreground"})]})}function We({repo:t,selected:e,expanded:a,onSelect:r,onToggle:s,children:i}){return jsxs("div",{children:[jsxs("button",{onClick:()=>{r(),s();},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(ae,{open:a}),jsx(FileText,{className:"h-4 w-4 shrink-0"}),jsx("span",{className:"truncate",children:t.name})]}),a&&i]})}function Ve({entry:t,content:e,loading:a,repoName:r}){let[s,i]=useState(false),o=useRef(null);useEffect(()=>()=>{o.current&&clearTimeout(o.current);},[]);let[l,m]=useState(false),h=async()=>{if(e)try{await navigator.clipboard.writeText(e),i(!0),m(!1),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>i(!1),2e3);}catch{m(true),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>m(false),2e3);}};if(!t)return jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(a)return jsx("div",{className:"flex h-full items-center justify-center",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let f=t.path.split("/").pop()||t.path,d=/\.(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:h,"aria-label":"Copy file content",className:R("rounded p-1 transition-colors",s?"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:d?jsx(j,{content:e||""}):jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function Ze({config:t,category:e,className:a,style:r}){let{repos:s,loading:i,error:o,refresh:l}=L(t),[m,h]=useState(null),[f,d]=useState(null),[c,u]=useState(null),[p,b]=useState(null),[N,S]=useState(false),[k,H]=useState(""),[ue,K]=useState(false),[W,V]=useState(false),[Z,z]=useState(null),de=s.find(x=>x.repo_id===m),{entries:me,getFileContent:J}=U(t,f),q=s.filter(x=>!k||x.name.toLowerCase().includes(k.toLowerCase())),fe=useCallback(async x=>{if(!x.isDir){u(x),S(true);try{let C=await J(x.cid);b(C);}catch(C){let ge=C instanceof Error?C.message:"Unknown error";b(`Failed to load file: ${ge}`);}finally{S(false);}}},[J]);useEffect(()=>{s.length>0&&!m&&(h(s[0].repo_id),d(s[0].repo_id));},[s,m]);let pe=x=>{x==="create-with-geoff"?window.open(`https://www.geoff.ai/?p=${encodeURIComponent("Let's create a skill together using your skill-creator skill. First ask me what the skill should do.")}`,"_blank","noopener,noreferrer"):z(x);};return jsxs("div",{className:R("flex flex-1 h-full min-h-0",a),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:ue?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(ne,{size:16,className:"shrink-0 text-muted-foreground"}),jsx("input",{type:"text",value:k,onChange:x=>H(x.target.value),placeholder:"Search",autoFocus:true,"aria-label":"Search items",className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),jsx("button",{onClick:()=>{K(false),H("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(O,{size:16})})]}):jsxs(Fragment,{children:[jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground capitalize",children:e||"Items"}),jsx("button",{onClick:()=>K(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsx(ne,{size:20})}),jsx("button",{onClick:()=>V(!W),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(ie,{size:20})})]})}),W&&jsx(He,{onClose:()=>V(false),onSelect:pe}),jsx("div",{className:"flex-1 overflow-y-auto p-2",children:i?jsx("div",{className:"flex items-center justify-center py-8",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):o?jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:o}):q.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:q.map(x=>jsx(We,{repo:x,selected:m===x.repo_id,expanded:f===x.repo_id,onSelect:()=>{h(x.repo_id),u(null),b(null);},onToggle:()=>d(f===x.repo_id?null:x.repo_id),children:jsx("div",{className:"ml-10 pl-1",children:me.map(C=>jsx(Ke,{entry:C,selected:c?.path===C.path,onSelect:fe,depth:C.path.split("/").length-1},C.path))})},x.repo_id))})})]}),jsx("div",{className:"flex-1 min-w-0",children:jsx(Ve,{entry:c,content:p,loading:N,repoName:de?.name||""})}),Z==="write"&&jsx(je,{config:t,onClose:()=>z(null),onCreated:l}),Z==="upload"&&jsx(Oe,{config:t,onClose:()=>z(null),onCreated:l})]})}
|
|
10
|
+
export{j as Markdown,Ze as RackBrowser,re as estimateCost,T as useRackClient,Ee as useRackRegister,Te as useRackSession,Ce as useRepoPush,U as useRepoTree,L as useRepos};
|
package/dist/types/index.d.cts
CHANGED
|
@@ -44,6 +44,10 @@ interface RackConfig {
|
|
|
44
44
|
ownerMid?: string;
|
|
45
45
|
/** Author MID for write operations */
|
|
46
46
|
authorMid?: string;
|
|
47
|
+
/** StackNet API key (gk_ or sk_ prefixed) for authenticated operations */
|
|
48
|
+
apiKey?: string;
|
|
49
|
+
/** Direct StackNet API URL (for registration/billing — bypasses proxy) */
|
|
50
|
+
stacknetUrl?: string;
|
|
47
51
|
}
|
|
48
52
|
interface InitResult {
|
|
49
53
|
success: boolean;
|
|
@@ -58,5 +62,118 @@ interface PushResult {
|
|
|
58
62
|
tree_cid: string;
|
|
59
63
|
manifest_cid?: string;
|
|
60
64
|
}
|
|
65
|
+
interface RackSession {
|
|
66
|
+
/** Whether the session is authenticated */
|
|
67
|
+
authenticated: boolean;
|
|
68
|
+
/** Resolved user global ID (from API key) */
|
|
69
|
+
userId?: string;
|
|
70
|
+
/** API key in use */
|
|
71
|
+
apiKey?: string;
|
|
72
|
+
/** Permission level */
|
|
73
|
+
permission?: 'read' | 'write';
|
|
74
|
+
}
|
|
75
|
+
interface TokenBudget {
|
|
76
|
+
/** Plan allocation in tokens */
|
|
77
|
+
planAllocation: number;
|
|
78
|
+
/** Inference tokens used */
|
|
79
|
+
inferenceUsed: number;
|
|
80
|
+
/** Ledger debits (skill/tensor registration, etc.) */
|
|
81
|
+
ledgerSpent: number;
|
|
82
|
+
/** Total used */
|
|
83
|
+
totalUsed: number;
|
|
84
|
+
/** Remaining tokens */
|
|
85
|
+
remaining: number;
|
|
86
|
+
/** Usage percentage */
|
|
87
|
+
percent: number;
|
|
88
|
+
/** Whether the plan limit is exceeded */
|
|
89
|
+
exceeded: boolean;
|
|
90
|
+
}
|
|
91
|
+
interface SkillRegistrationInput {
|
|
92
|
+
name: string;
|
|
93
|
+
description?: string;
|
|
94
|
+
skill_md: string;
|
|
95
|
+
content_type?: string;
|
|
96
|
+
category?: string;
|
|
97
|
+
tags?: string[];
|
|
98
|
+
version?: string;
|
|
99
|
+
scripts?: string;
|
|
100
|
+
stack_id?: string;
|
|
101
|
+
}
|
|
102
|
+
interface SkillRegistrationResult {
|
|
103
|
+
skill_id: string;
|
|
104
|
+
rack_repo_id: string | null;
|
|
105
|
+
rack_pinned: boolean;
|
|
106
|
+
attributed_to: string;
|
|
107
|
+
registration_cost_tokens: number | null;
|
|
108
|
+
lode_fingerprint: string | null;
|
|
109
|
+
}
|
|
110
|
+
interface TensorRegistrationInput {
|
|
111
|
+
name: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
tensor_filename: string;
|
|
114
|
+
/** Base64-encoded tensor data (for small files) */
|
|
115
|
+
tensor_data?: string;
|
|
116
|
+
/** SHA-256 hash of tensor file (for large files — reference mode) */
|
|
117
|
+
tensor_hash?: string;
|
|
118
|
+
/** Size of tensor file in bytes (for large files — reference mode) */
|
|
119
|
+
tensor_size_bytes?: number;
|
|
120
|
+
/** Base64-encoded example media */
|
|
121
|
+
example_data?: string;
|
|
122
|
+
example_filename?: string;
|
|
123
|
+
/** Text-based example files (e.g. prompts.md) */
|
|
124
|
+
example_files?: Array<{
|
|
125
|
+
path: string;
|
|
126
|
+
content: string;
|
|
127
|
+
}>;
|
|
128
|
+
content_type?: string;
|
|
129
|
+
category?: string;
|
|
130
|
+
tags?: string[];
|
|
131
|
+
version?: string;
|
|
132
|
+
base_model?: string;
|
|
133
|
+
format?: string;
|
|
134
|
+
training?: {
|
|
135
|
+
steps?: number;
|
|
136
|
+
epochs?: number;
|
|
137
|
+
learning_rate?: string;
|
|
138
|
+
batch_size?: number;
|
|
139
|
+
optimizer?: string;
|
|
140
|
+
};
|
|
141
|
+
trigger_words?: string[];
|
|
142
|
+
}
|
|
143
|
+
interface TensorRegistrationResult {
|
|
144
|
+
tensor_id: string;
|
|
145
|
+
rack_repo_id: string | null;
|
|
146
|
+
rack_pinned: boolean;
|
|
147
|
+
attributed_to: string;
|
|
148
|
+
registration_cost_tokens: number | null;
|
|
149
|
+
tensor_size_mb: number | null;
|
|
150
|
+
lode_fingerprint: string | null;
|
|
151
|
+
}
|
|
152
|
+
interface StarResult {
|
|
153
|
+
success: boolean;
|
|
154
|
+
starred: boolean;
|
|
155
|
+
stars: number;
|
|
156
|
+
cost: number;
|
|
157
|
+
transaction_id?: string;
|
|
158
|
+
}
|
|
159
|
+
interface StarInfo {
|
|
160
|
+
stars: number;
|
|
161
|
+
starred: boolean;
|
|
162
|
+
repo_id: string;
|
|
163
|
+
}
|
|
164
|
+
interface CostEstimate {
|
|
165
|
+
/** Type of registration */
|
|
166
|
+
type: 'skill' | 'tensor';
|
|
167
|
+
/** Total bytes of content */
|
|
168
|
+
totalBytes: number;
|
|
169
|
+
/** Total megabytes (for tensors) */
|
|
170
|
+
totalMegabytes: number;
|
|
171
|
+
/** Base cost before multiplier */
|
|
172
|
+
baseCost: number;
|
|
173
|
+
/** Multiplier applied */
|
|
174
|
+
multiplier: number;
|
|
175
|
+
/** Final registration cost in tokens */
|
|
176
|
+
registrationCostTokens: number;
|
|
177
|
+
}
|
|
61
178
|
|
|
62
|
-
export type { DiffEntry, InitResult, PushResult, RackConfig, RepoCommit, RepoFile, RepoInfo, RepoTree, TreeEntry };
|
|
179
|
+
export type { CostEstimate, DiffEntry, InitResult, PushResult, RackConfig, RackSession, RepoCommit, RepoFile, RepoInfo, RepoTree, SkillRegistrationInput, SkillRegistrationResult, StarInfo, StarResult, TensorRegistrationInput, TensorRegistrationResult, TokenBudget, TreeEntry };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -44,6 +44,10 @@ interface RackConfig {
|
|
|
44
44
|
ownerMid?: string;
|
|
45
45
|
/** Author MID for write operations */
|
|
46
46
|
authorMid?: string;
|
|
47
|
+
/** StackNet API key (gk_ or sk_ prefixed) for authenticated operations */
|
|
48
|
+
apiKey?: string;
|
|
49
|
+
/** Direct StackNet API URL (for registration/billing — bypasses proxy) */
|
|
50
|
+
stacknetUrl?: string;
|
|
47
51
|
}
|
|
48
52
|
interface InitResult {
|
|
49
53
|
success: boolean;
|
|
@@ -58,5 +62,118 @@ interface PushResult {
|
|
|
58
62
|
tree_cid: string;
|
|
59
63
|
manifest_cid?: string;
|
|
60
64
|
}
|
|
65
|
+
interface RackSession {
|
|
66
|
+
/** Whether the session is authenticated */
|
|
67
|
+
authenticated: boolean;
|
|
68
|
+
/** Resolved user global ID (from API key) */
|
|
69
|
+
userId?: string;
|
|
70
|
+
/** API key in use */
|
|
71
|
+
apiKey?: string;
|
|
72
|
+
/** Permission level */
|
|
73
|
+
permission?: 'read' | 'write';
|
|
74
|
+
}
|
|
75
|
+
interface TokenBudget {
|
|
76
|
+
/** Plan allocation in tokens */
|
|
77
|
+
planAllocation: number;
|
|
78
|
+
/** Inference tokens used */
|
|
79
|
+
inferenceUsed: number;
|
|
80
|
+
/** Ledger debits (skill/tensor registration, etc.) */
|
|
81
|
+
ledgerSpent: number;
|
|
82
|
+
/** Total used */
|
|
83
|
+
totalUsed: number;
|
|
84
|
+
/** Remaining tokens */
|
|
85
|
+
remaining: number;
|
|
86
|
+
/** Usage percentage */
|
|
87
|
+
percent: number;
|
|
88
|
+
/** Whether the plan limit is exceeded */
|
|
89
|
+
exceeded: boolean;
|
|
90
|
+
}
|
|
91
|
+
interface SkillRegistrationInput {
|
|
92
|
+
name: string;
|
|
93
|
+
description?: string;
|
|
94
|
+
skill_md: string;
|
|
95
|
+
content_type?: string;
|
|
96
|
+
category?: string;
|
|
97
|
+
tags?: string[];
|
|
98
|
+
version?: string;
|
|
99
|
+
scripts?: string;
|
|
100
|
+
stack_id?: string;
|
|
101
|
+
}
|
|
102
|
+
interface SkillRegistrationResult {
|
|
103
|
+
skill_id: string;
|
|
104
|
+
rack_repo_id: string | null;
|
|
105
|
+
rack_pinned: boolean;
|
|
106
|
+
attributed_to: string;
|
|
107
|
+
registration_cost_tokens: number | null;
|
|
108
|
+
lode_fingerprint: string | null;
|
|
109
|
+
}
|
|
110
|
+
interface TensorRegistrationInput {
|
|
111
|
+
name: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
tensor_filename: string;
|
|
114
|
+
/** Base64-encoded tensor data (for small files) */
|
|
115
|
+
tensor_data?: string;
|
|
116
|
+
/** SHA-256 hash of tensor file (for large files — reference mode) */
|
|
117
|
+
tensor_hash?: string;
|
|
118
|
+
/** Size of tensor file in bytes (for large files — reference mode) */
|
|
119
|
+
tensor_size_bytes?: number;
|
|
120
|
+
/** Base64-encoded example media */
|
|
121
|
+
example_data?: string;
|
|
122
|
+
example_filename?: string;
|
|
123
|
+
/** Text-based example files (e.g. prompts.md) */
|
|
124
|
+
example_files?: Array<{
|
|
125
|
+
path: string;
|
|
126
|
+
content: string;
|
|
127
|
+
}>;
|
|
128
|
+
content_type?: string;
|
|
129
|
+
category?: string;
|
|
130
|
+
tags?: string[];
|
|
131
|
+
version?: string;
|
|
132
|
+
base_model?: string;
|
|
133
|
+
format?: string;
|
|
134
|
+
training?: {
|
|
135
|
+
steps?: number;
|
|
136
|
+
epochs?: number;
|
|
137
|
+
learning_rate?: string;
|
|
138
|
+
batch_size?: number;
|
|
139
|
+
optimizer?: string;
|
|
140
|
+
};
|
|
141
|
+
trigger_words?: string[];
|
|
142
|
+
}
|
|
143
|
+
interface TensorRegistrationResult {
|
|
144
|
+
tensor_id: string;
|
|
145
|
+
rack_repo_id: string | null;
|
|
146
|
+
rack_pinned: boolean;
|
|
147
|
+
attributed_to: string;
|
|
148
|
+
registration_cost_tokens: number | null;
|
|
149
|
+
tensor_size_mb: number | null;
|
|
150
|
+
lode_fingerprint: string | null;
|
|
151
|
+
}
|
|
152
|
+
interface StarResult {
|
|
153
|
+
success: boolean;
|
|
154
|
+
starred: boolean;
|
|
155
|
+
stars: number;
|
|
156
|
+
cost: number;
|
|
157
|
+
transaction_id?: string;
|
|
158
|
+
}
|
|
159
|
+
interface StarInfo {
|
|
160
|
+
stars: number;
|
|
161
|
+
starred: boolean;
|
|
162
|
+
repo_id: string;
|
|
163
|
+
}
|
|
164
|
+
interface CostEstimate {
|
|
165
|
+
/** Type of registration */
|
|
166
|
+
type: 'skill' | 'tensor';
|
|
167
|
+
/** Total bytes of content */
|
|
168
|
+
totalBytes: number;
|
|
169
|
+
/** Total megabytes (for tensors) */
|
|
170
|
+
totalMegabytes: number;
|
|
171
|
+
/** Base cost before multiplier */
|
|
172
|
+
baseCost: number;
|
|
173
|
+
/** Multiplier applied */
|
|
174
|
+
multiplier: number;
|
|
175
|
+
/** Final registration cost in tokens */
|
|
176
|
+
registrationCostTokens: number;
|
|
177
|
+
}
|
|
61
178
|
|
|
62
|
-
export type { DiffEntry, InitResult, PushResult, RackConfig, RepoCommit, RepoFile, RepoInfo, RepoTree, TreeEntry };
|
|
179
|
+
export type { CostEstimate, DiffEntry, InitResult, PushResult, RackConfig, RackSession, RepoCommit, RepoFile, RepoInfo, RepoTree, SkillRegistrationInput, SkillRegistrationResult, StarInfo, StarResult, TensorRegistrationInput, TensorRegistrationResult, TokenBudget, TreeEntry };
|