@stacknet/rackutils 0.2.0 → 0.3.1

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