@stacknet/rackutils 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/index.cjs +7 -6
- package/dist/components/index.d.cts +18 -1
- package/dist/components/index.d.ts +18 -1
- package/dist/components/index.js +7 -6
- package/dist/hooks/index.cjs +1 -1
- package/dist/hooks/index.d.cts +42 -5
- package/dist/hooks/index.d.ts +42 -5
- package/dist/hooks/index.js +1 -1
- package/dist/index.cjs +7 -6
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7 -6
- package/dist/types/index.d.cts +21 -1
- package/dist/types/index.d.ts +21 -1
- package/package.json +1 -1
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { RepoInfo, InitResult, RepoFile, PushResult, RepoTree, RepoCommit, DiffEntry, StarResult, StarInfo, SkillStats, TensorStats, NetworkStats, TrendingRepo, RackConfig, TreeEntry, RackSession, TokenBudget, CostEstimate, SkillRegistrationInput, SkillRegistrationResult, TensorRegistrationInput, TensorRegistrationResult } from '../types/index.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;
|
|
@@ -36,7 +36,7 @@ interface RackClient {
|
|
|
36
36
|
getSkillUsageCount: (skillId: string) => Promise<number | null>;
|
|
37
37
|
getTensorStats: (repoId: string) => Promise<TensorStats>;
|
|
38
38
|
getNetworkStats: () => Promise<NetworkStats | null>;
|
|
39
|
-
getTrending: (limit?: number, days?: number) => Promise<TrendingRepo
|
|
39
|
+
getTrending: (limit?: number, days?: number, cursor?: string) => Promise<PaginatedResult<TrendingRepo>>;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Low-level hook returning a rack API client.
|
|
@@ -68,6 +68,40 @@ interface UseRepoPushReturn {
|
|
|
68
68
|
}
|
|
69
69
|
declare function useRepoPush(config: RackConfig): UseRepoPushReturn;
|
|
70
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
|
+
|
|
71
105
|
/**
|
|
72
106
|
* Session hook for authenticated Rack operations.
|
|
73
107
|
* Manages API key persistence, session validation, and token budget.
|
|
@@ -131,14 +165,17 @@ declare function useNetworkStats(config: RackConfig): {
|
|
|
131
165
|
};
|
|
132
166
|
|
|
133
167
|
/**
|
|
134
|
-
* Fetch trending repos with time-windowed scoring.
|
|
168
|
+
* Fetch trending repos with time-windowed scoring and cursor pagination.
|
|
135
169
|
* Score = (usage × 100) + (stars × 1)
|
|
136
170
|
*/
|
|
137
171
|
declare function useTrending(config: RackConfig, limit?: number, days?: number): {
|
|
138
172
|
repos: TrendingRepo[];
|
|
173
|
+
hasMore: boolean;
|
|
174
|
+
total: number;
|
|
139
175
|
loading: boolean;
|
|
140
176
|
error: string | null;
|
|
141
177
|
refresh: (newDays?: number) => Promise<void>;
|
|
178
|
+
loadMore: () => Promise<void>;
|
|
142
179
|
};
|
|
143
180
|
|
|
144
181
|
/**
|
|
@@ -155,4 +192,4 @@ declare function useStar(config: RackConfig, repoId: string | null): {
|
|
|
155
192
|
repo_id: string;
|
|
156
193
|
};
|
|
157
194
|
|
|
158
|
-
export { type RackClient, estimateCost, useNetworkStats, useRackClient, useRackRegister, useRackSession, useRepoPush, useRepoTree, useRepos, useSkillStats, useStar, useTensorStats, useTrending };
|
|
195
|
+
export { type RackClient, estimateCost, useNetworkStats, usePaginatedRepos, useRackClient, useRackRegister, useRackSession, useRepoPush, useRepoTree, useRepos, useSkillStats, useStar, useTensorStats, useTrending };
|
package/dist/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {useMemo,useRef,useState,useCallback,useEffect}from'react';async function d(u,t,i,l){let c={"Content-Type":"application/json",...i?.headers};l&&(c.Authorization=`Bearer ${l}`);let g=await fetch(`${u}${t}`,{...i,headers:c});if(!g.ok){let e=`HTTP ${g.status}`;try{let r=await g.json();r.error&&(e=r.error);}catch{}throw new Error(e)}return g.json()}function k(u){let t=u.indexOf(":");return {mode:u.slice(0,t),cid:u.slice(t+1)}}function p(u){let t=u.apiBaseUrl,i=u.authorMid,l=u.ownerMid,c=u.apiKey,g=u.stacknetUrl||u.apiBaseUrl;return useMemo(()=>({async listRepos(e){let r=e||l?`?owner=${encodeURIComponent(e||l)}`:"";return (await d(t,`/api/rack/repos${r}`,void 0,c)).repos||[]},async initRepo(e){return d(t,"/api/rack/init",{method:"POST",body:JSON.stringify({...e,owner_mid:l})},c)},async push(e,r){return d(t,`/api/rack/${e}/push`,{method:"POST",body:JSON.stringify({...r,author_mid:i})},c)},async getTree(e,r="main"){let n=await d(t,`/api/rack/${e}/tree/${r}`,void 0,c);return {tree:n.tree,commit_cid:n.commit_cid}},async getBlob(e,r){return (await d(t,`/api/rack/${e}/blob/${r}`,void 0,c)).content},async getLog(e,r,n){let s=new URLSearchParams;r&&s.set("ref",r),n&&s.set("max_count",String(n));let a=s.toString()?`?${s}`:"";return (await d(t,`/api/rack/${e}/log${a}`,void 0,c)).commits||[]},async getBranches(e){return (await d(t,`/api/rack/${e}/branches`,void 0,c)).branches||[]},async createBranch(e,r,n){return d(t,`/api/rack/${e}/branch`,{method:"POST",body:JSON.stringify({branch_name:r,from_ref:n})},c)},async merge(e,r,n){return d(t,`/api/rack/${e}/merge`,{method:"POST",body:JSON.stringify({source_branch:r,target_branch:n})},c)},async getDiff(e,r,n){return (await d(t,`/api/rack/${e}/diff/${r}/${n}`,void 0,c)).diff?.entries||[]},async starRepo(e){return d(t,`/api/rack/${e}/star`,{method:"POST"},c)},async unstarRepo(e){return d(t,`/api/rack/${e}/star`,{method:"DELETE"},c)},async getStarInfo(e){return d(t,`/api/rack/${e}/stars`,void 0,c)},async getSkillStats(e){let r={meta:null,tokenCount:null,usageCount:null};try{let{tree:n}=await this.getTree(e,"main");if(!n?.entries)return r;if(n.entries["META.json"]){let o=k(n.entries["META.json"]).cid,f=await this.getBlob(e,o);r.meta=JSON.parse(f);}let s=0,a=Object.values(n.entries).map(async o=>{try{let f=k(o).cid,m=await this.getBlob(e,f);s+=m.length;}catch{}});await Promise.all(a),s>0&&(r.tokenCount=Math.ceil(s/4)),r.meta?.skill_id&&(r.usageCount=await this.getSkillUsageCount(r.meta.skill_id));}catch{}return r},async getSkillUsageCount(e){try{let r=await fetch(`${g}/v1/skills/${encodeURIComponent(e)}`);if(r.ok){let s=await r.json();return s.usage_count??s.usageCount??null}let n=await fetch(`${g}/v1/skills?scope=public`);if(n.ok){let a=((await n.json()).skills||[]).find(o=>o.name===e||o.id===e);if(a)return a.usage_count??a.usageCount??0}return 0}catch{return null}},async getTensorStats(e){let r={meta:null,sizeMB:null};try{let{tree:n}=await this.getTree(e,"main");if(!n?.entries)return r;if(n.entries["TENSOR_META.json"]){let s=k(n.entries["TENSOR_META.json"]).cid,a=await this.getBlob(e,s);r.meta=JSON.parse(a),r.sizeMB=r.meta?.tensor_size_mb??null;}}catch{}return r},async getNetworkStats(){try{return (await d(t,"/api/rack/stats",void 0,c)).stats||null}catch{return null}},async getTrending(e=5,r=1){try{return (await d(t,`/api/rack/trending?limit=${e}&days=${r}`,void 0,c)).trending||[]}catch{return []}}}),[t,i,l,c,g])}function J(u){let t=p(u),i=useRef(t);i.current=t;let[l,c]=useState([]),[g,e]=useState(true),[r,n]=useState(null),s=useRef(true),a=useRef(null),o=useCallback(async()=>{a.current?.abort();let f=new AbortController;a.current=f;try{s.current&&(e(!0),n(null));let m=await i.current.listRepos();s.current&&!f.signal.aborted&&c(m);}catch(m){s.current&&!f.signal.aborted&&n(m instanceof Error?m.message:"Failed to load repos");}finally{s.current&&!f.signal.aborted&&e(false);}},[]);return useEffect(()=>(s.current=true,o(),()=>{s.current=false,a.current?.abort();}),[o]),{repos:l,loading:g,error:r,refresh:o}}function H(u){return Object.entries(u).map(([t,i])=>{let l=i.indexOf(":"),c=l>0?i.slice(0,l):"100644",g=l>0?i.slice(l+1):i;return {path:t,mode:c,cid:g,isDir:c==="040000"}}).sort((t,i)=>t.isDir!==i.isDir?t.isDir?-1:1:t.path.localeCompare(i.path))}function W(u,t,i="main"){let l=p(u),[c,g]=useState([]),[e,r]=useState(false),[n,s]=useState(null),a=useRef(true),o=useCallback(async()=>{if(t)try{a.current&&(r(!0),s(null));let{tree:m}=await l.getTree(t,i);a.current&&g(H(m.entries));}catch(m){a.current&&s(m instanceof Error?m.message:"Failed to load tree");}finally{a.current&&r(false);}},[l,t,i]);useEffect(()=>(a.current=true,o(),()=>{a.current=false;}),[o]);let f=useCallback(async m=>{if(!t)throw new Error("No repo selected");return l.getBlob(t,m)},[l,t]);return {entries:c,loading:e,error:n,refresh:o,getFileContent:f}}function Q(u){let t=p(u),[i,l]=useState(false),[c,g]=useState(null),e=useRef(true);return useEffect(()=>(e.current=true,()=>{e.current=false;}),[]),{push:useCallback(async(n,s,a,o)=>{try{return e.current&&(l(!0),g(null)),await t.push(n,{files:s,message:a,branch:o})}catch(f){let m=f instanceof Error?f.message:"Push failed";return e.current&&g(m),null}finally{e.current&&l(false);}},[t]),pushing:i,error:c}}var w="stacknet-rack-apikey";function X(u){let t=u.stacknetUrl||u.apiBaseUrl,[i,l]=useState({authenticated:false}),[c,g]=useState(null),[e,r]=useState(false),n=useCallback(f=>({"Content-Type":"application/json",...f||u.apiKey?{Authorization:`Bearer ${f||u.apiKey}`}:{}}),[u.apiKey]),s=useCallback(async f=>{r(true);try{let m=await fetch(`${t}/health`,{headers:n(f)});if(!m.ok)throw new Error(`Authentication failed: ${m.status}`);let R={authenticated:!0,apiKey:f,permission:f.startsWith("gk_")?"write":"read"};l(R);try{localStorage.setItem(w,f);}catch{}return R}catch(m){throw l({authenticated:false}),m}finally{r(false);}},[t,n]),a=useCallback(()=>{l({authenticated:false}),g(null);try{localStorage.removeItem(w);}catch{}},[]),o=useCallback(async()=>{let f=i.apiKey||u.apiKey;if(!f)return null;try{let m=await fetch(`${t}/network/usage`,{headers:n(f)});if(!m.ok)return null;let R=await m.json(),I={planAllocation:R.plan_allocation??R.planAllocation??0,inferenceUsed:R.inference_used??R.inferenceUsed??0,ledgerSpent:R.ledger_spent??R.ledgerSpent??0,totalUsed:R.total_used??R.totalUsed??0,remaining:R.remaining??0,percent:R.percent??0,exceeded:R.exceeded??!1};return g(I),I}catch{return null}},[i.apiKey,u.apiKey,t,n]);return useEffect(()=>{let f=u.apiKey;if(f){l({authenticated:true,apiKey:f,permission:f.startsWith("gk_")?"write":"read"});return}try{let m=localStorage.getItem(w);m&&l({authenticated:!0,apiKey:m,permission:m.startsWith("gk_")?"write":"read"});}catch{}},[u.apiKey]),{session:i,budget:c,loading:e,login:s,logout:a,refreshBudget:o}}var B=1e3,M=1e3,j=100;function L(u,t){if(u==="skill"){let c=j+Math.ceil(t/4);return {type:u,totalBytes:t,totalMegabytes:t/1e6,baseCost:c,multiplier:B,registrationCostTokens:c*B}}let i=Math.ceil(t/1e6),l=j+i;return {type:u,totalBytes:t,totalMegabytes:i,baseCost:l,multiplier:M,registrationCostTokens:l*M}}function Z(u){let t=u.stacknetUrl||u.apiBaseUrl,i=u.apiKey,[l,c]=useState(false),[g,e]=useState(null),r=useCallback(()=>{if(!i)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${i}`}},[i]),n=useCallback(async a=>{c(true),e(null);try{let o=await fetch(`${t}/skills`,{method:"POST",headers:r(),body:JSON.stringify(a)});if(!o.ok){let f=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(f.error||`Registration failed: ${o.status}`)}return await o.json()}catch(o){throw e(o.message),o}finally{c(false);}},[t,r]),s=useCallback(async a=>{c(true),e(null);try{let o=await fetch(`${t}/tensors`,{method:"POST",headers:r(),body:JSON.stringify(a)});if(!o.ok){let f=await o.json().catch(()=>({error:`HTTP ${o.status}`}));throw new Error(f.error||`Registration failed: ${o.status}`)}return await o.json()}catch(o){throw e(o.message),o}finally{c(false);}},[t,r]);return {registerSkill:n,registerTensor:s,estimateCost:L,registering:l,error:g}}function nt(u,t){let i=p(u),[l,c]=useState({meta:null,tokenCount:null,usageCount:null}),[g,e]=useState(false),[r,n]=useState(null),s=useRef(true),a=useCallback(async()=>{if(t){e(true),n(null);try{let o=await i.getSkillStats(t);s.current&&c(o);}catch(o){s.current&&n(o.message);}finally{s.current&&e(false);}}},[i,t]);return useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:l,loading:g,error:r,refresh:a}}function it(u,t){let i=p(u),[l,c]=useState({meta:null,sizeMB:null}),[g,e]=useState(false),[r,n]=useState(null),s=useRef(true),a=useCallback(async()=>{if(t){e(true),n(null);try{let o=await i.getTensorStats(t);s.current&&c(o);}catch(o){s.current&&n(o.message);}finally{s.current&&e(false);}}},[i,t]);return useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]),{stats:l,loading:g,error:r,refresh:a}}function ft(u){let t=p(u),[i,l]=useState(null),[c,g]=useState(false),[e,r]=useState(null),n=useRef(true),s=useCallback(async()=>{g(true),r(null);try{let a=await t.getNetworkStats();n.current&&l(a);}catch(a){n.current&&r(a.message);}finally{n.current&&g(false);}},[t]);return useEffect(()=>(n.current=true,s(),()=>{n.current=false;}),[s]),{stats:i,loading:c,error:e,refresh:s}}function dt(u,t=5,i=1){let l=p(u),[c,g]=useState([]),[e,r]=useState(false),[n,s]=useState(null),a=useRef(true),o=useCallback(async f=>{r(true),s(null);try{let m=await l.getTrending(t,f??i);a.current&&g(m);}catch(m){a.current&&s(m.message);}finally{a.current&&r(false);}},[l,t,i]);return useEffect(()=>(a.current=true,o(),()=>{a.current=false;}),[o]),{repos:c,loading:e,error:n,refresh:o}}function kt(u,t){let i=p(u),[l,c]=useState({stars:0,starred:false,repo_id:t||""}),[g,e]=useState(false),[r,n]=useState(null),s=useRef(true),a=useCallback(async()=>{if(t)try{let f=await i.getStarInfo(t);s.current&&c(f);}catch{}},[i,t]);useEffect(()=>(s.current=true,a(),()=>{s.current=false;}),[a]);let o=useCallback(async()=>{if(t){e(true),n(null);try{let f=l.starred?await i.unstarRepo(t):await i.starRepo(t);s.current&&c({stars:f.stars,starred:f.starred,repo_id:t});}catch(f){s.current&&n(f.message);}finally{s.current&&e(false);}}},[i,t,l.starred]);return {...l,loading:g,error:r,toggle:o,refresh:a}}export{L as estimateCost,ft as useNetworkStats,p as useRackClient,Z as useRackRegister,X as useRackSession,Q as useRepoPush,W as useRepoTree,J as useRepos,nt as useSkillStats,kt as useStar,it as useTensorStats,dt as useTrending};
|
|
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,11 @@
|
|
|
1
|
-
'use strict';var react=require('react'),lucideReact=require('lucide-react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');async function w(t,e,o,n){let s={"Content-Type":"application/json",...o?.headers};n&&(s.Authorization=`Bearer ${n}`);let u=await fetch(`${t}${e}`,{...o,headers:s});if(!u.ok){let r=`HTTP ${u.status}`;try{let a=await u.json();a.error&&(r=a.error);}catch{}throw new Error(r)}return u.json()}function I(t){let e=t.indexOf(":");return {mode:t.slice(0,e),cid:t.slice(e+1)}}function x(t){let e=t.apiBaseUrl,o=t.authorMid,n=t.ownerMid,s=t.apiKey,u=t.stacknetUrl||t.apiBaseUrl;return react.useMemo(()=>({async listRepos(r){let a=r||n?`?owner=${encodeURIComponent(r||n)}`:"";return (await w(e,`/api/rack/repos${a}`,void 0,s)).repos||[]},async initRepo(r){return w(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...r,owner_mid:n})},s)},async push(r,a){return w(e,`/api/rack/${r}/push`,{method:"POST",body:JSON.stringify({...a,author_mid:o})},s)},async getTree(r,a="main"){let l=await w(e,`/api/rack/${r}/tree/${a}`,void 0,s);return {tree:l.tree,commit_cid:l.commit_cid}},async getBlob(r,a){return (await w(e,`/api/rack/${r}/blob/${a}`,void 0,s)).content},async getLog(r,a,l){let c=new URLSearchParams;a&&c.set("ref",a),l&&c.set("max_count",String(l));let d=c.toString()?`?${c}`:"";return (await w(e,`/api/rack/${r}/log${d}`,void 0,s)).commits||[]},async getBranches(r){return (await w(e,`/api/rack/${r}/branches`,void 0,s)).branches||[]},async createBranch(r,a,l){return w(e,`/api/rack/${r}/branch`,{method:"POST",body:JSON.stringify({branch_name:a,from_ref:l})},s)},async merge(r,a,l){return w(e,`/api/rack/${r}/merge`,{method:"POST",body:JSON.stringify({source_branch:a,target_branch:l})},s)},async getDiff(r,a,l){return (await w(e,`/api/rack/${r}/diff/${a}/${l}`,void 0,s)).diff?.entries||[]},async starRepo(r){return w(e,`/api/rack/${r}/star`,{method:"POST"},s)},async unstarRepo(r){return w(e,`/api/rack/${r}/star`,{method:"DELETE"},s)},async getStarInfo(r){return w(e,`/api/rack/${r}/stars`,void 0,s)},async getSkillStats(r){let a={meta:null,tokenCount:null,usageCount:null};try{let{tree:l}=await this.getTree(r,"main");if(!l?.entries)return a;if(l.entries["META.json"]){let f=I(l.entries["META.json"]).cid,m=await this.getBlob(r,f);a.meta=JSON.parse(m);}let c=0,d=Object.values(l.entries).map(async f=>{try{let m=I(f).cid,g=await this.getBlob(r,m);c+=g.length;}catch{}});await Promise.all(d),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(r){try{let a=await fetch(`${u}/v1/skills/${encodeURIComponent(r)}`);if(a.ok){let c=await a.json();return c.usage_count??c.usageCount??null}let l=await fetch(`${u}/v1/skills?scope=public`);if(l.ok){let d=((await l.json()).skills||[]).find(f=>f.name===r||f.id===r);if(d)return d.usage_count??d.usageCount??0}return 0}catch{return null}},async getTensorStats(r){let a={meta:null,sizeMB:null};try{let{tree:l}=await this.getTree(r,"main");if(!l?.entries)return a;if(l.entries["TENSOR_META.json"]){let c=I(l.entries["TENSOR_META.json"]).cid,d=await this.getBlob(r,c);a.meta=JSON.parse(d),a.sizeMB=a.meta?.tensor_size_mb??null;}}catch{}return a},async getNetworkStats(){try{return (await w(e,"/api/rack/stats",void 0,s)).stats||null}catch{return null}},async getTrending(r=5,a=1){try{return (await w(e,`/api/rack/trending?limit=${r}&days=${a}`,void 0,s)).trending||[]}catch{return []}}}),[e,o,n,s,u])}function A(t){let e=x(t),o=react.useRef(e);o.current=e;let[n,s]=react.useState([]),[u,r]=react.useState(true),[a,l]=react.useState(null),c=react.useRef(true),d=react.useRef(null),f=react.useCallback(async()=>{d.current?.abort();let m=new AbortController;d.current=m;try{c.current&&(r(!0),l(null));let g=await o.current.listRepos();c.current&&!m.signal.aborted&&s(g);}catch(g){c.current&&!m.signal.aborted&&l(g instanceof Error?g.message:"Failed to load repos");}finally{c.current&&!m.signal.aborted&&r(false);}},[]);return react.useEffect(()=>(c.current=true,f(),()=>{c.current=false,d.current?.abort();}),[f]),{repos:n,loading:u,error:a,refresh:f}}function Ee(t){return Object.entries(t).map(([e,o])=>{let n=o.indexOf(":"),s=n>0?o.slice(0,n):"100644",u=n>0?o.slice(n+1):o;return {path:e,mode:s,cid:u,isDir:s==="040000"}}).sort((e,o)=>e.isDir!==o.isDir?e.isDir?-1:1:e.path.localeCompare(o.path))}function U(t,e,o="main"){let n=x(t),[s,u]=react.useState([]),[r,a]=react.useState(false),[l,c]=react.useState(null),d=react.useRef(true),f=react.useCallback(async()=>{if(e)try{d.current&&(a(!0),c(null));let{tree:g}=await n.getTree(e,o);d.current&&u(Ee(g.entries));}catch(g){d.current&&c(g instanceof Error?g.message:"Failed to load tree");}finally{d.current&&a(false);}},[n,e,o]);react.useEffect(()=>(d.current=true,f(),()=>{d.current=false;}),[f]);let m=react.useCallback(async g=>{if(!e)throw new Error("No repo selected");return n.getBlob(e,g)},[n,e]);return {entries:s,loading:r,error:l,refresh:f,getFileContent:m}}function Me(t){let e=x(t),[o,n]=react.useState(false),[s,u]=react.useState(null),r=react.useRef(true);return react.useEffect(()=>(r.current=true,()=>{r.current=false;}),[]),{push:react.useCallback(async(l,c,d,f)=>{try{return r.current&&(n(!0),u(null)),await e.push(l,{files:c,message:d,branch:f})}catch(m){let g=m instanceof Error?m.message:"Push failed";return r.current&&u(g),null}finally{r.current&&n(false);}},[e]),pushing:o,error:s}}var j="stacknet-rack-apikey";function ze(t){let e=t.stacknetUrl||t.apiBaseUrl,[o,n]=react.useState({authenticated:false}),[s,u]=react.useState(null),[r,a]=react.useState(false),l=react.useCallback(m=>({"Content-Type":"application/json",...m||t.apiKey?{Authorization:`Bearer ${m||t.apiKey}`}:{}}),[t.apiKey]),c=react.useCallback(async m=>{a(true);try{let g=await fetch(`${e}/health`,{headers:l(m)});if(!g.ok)throw new Error(`Authentication failed: ${g.status}`);let p={authenticated:!0,apiKey:m,permission:m.startsWith("gk_")?"write":"read"};n(p);try{localStorage.setItem(j,m);}catch{}return p}catch(g){throw n({authenticated:false}),g}finally{a(false);}},[e,l]),d=react.useCallback(()=>{n({authenticated:false}),u(null);try{localStorage.removeItem(j);}catch{}},[]),f=react.useCallback(async()=>{let m=o.apiKey||t.apiKey;if(!m)return null;try{let g=await fetch(`${e}/network/usage`,{headers:l(m)});if(!g.ok)return null;let p=await g.json(),v={planAllocation:p.plan_allocation??p.planAllocation??0,inferenceUsed:p.inference_used??p.inferenceUsed??0,ledgerSpent:p.ledger_spent??p.ledgerSpent??0,totalUsed:p.total_used??p.totalUsed??0,remaining:p.remaining??0,percent:p.percent??0,exceeded:p.exceeded??!1};return u(v),v}catch{return null}},[o.apiKey,t.apiKey,e,l]);return react.useEffect(()=>{let m=t.apiKey;if(m){n({authenticated:true,apiKey:m,permission:m.startsWith("gk_")?"write":"read"});return}try{let g=localStorage.getItem(j);g&&n({authenticated:!0,apiKey:g,permission:g.startsWith("gk_")?"write":"read"});}catch{}},[t.apiKey]),{session:o,budget:s,loading:r,login:c,logout:d,refreshBudget:f}}var oe=1e3,ae=1e3,ie=100;function le(t,e){if(t==="skill"){let s=ie+Math.ceil(e/4);return {type:t,totalBytes:e,totalMegabytes:e/1e6,baseCost:s,multiplier:oe,registrationCostTokens:s*oe}}let o=Math.ceil(e/1e6),n=ie+o;return {type:t,totalBytes:e,totalMegabytes:o,baseCost:n,multiplier:ae,registrationCostTokens:n*ae}}function Le(t){let e=t.stacknetUrl||t.apiBaseUrl,o=t.apiKey,[n,s]=react.useState(false),[u,r]=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 d=>{s(true),r(null);try{let f=await fetch(`${e}/skills`,{method:"POST",headers:a(),body:JSON.stringify(d)});if(!f.ok){let m=await f.json().catch(()=>({error:`HTTP ${f.status}`}));throw new Error(m.error||`Registration failed: ${f.status}`)}return await f.json()}catch(f){throw r(f.message),f}finally{s(false);}},[e,a]),c=react.useCallback(async d=>{s(true),r(null);try{let f=await fetch(`${e}/tensors`,{method:"POST",headers:a(),body:JSON.stringify(d)});if(!f.ok){let m=await f.json().catch(()=>({error:`HTTP ${f.status}`}));throw new Error(m.error||`Registration failed: ${f.status}`)}return await f.json()}catch(f){throw r(f.message),f}finally{s(false);}},[e,a]);return {registerSkill:l,registerTensor:c,estimateCost:le,registering:n,error:u}}function Oe(t,e){let o=x(t),[n,s]=react.useState({meta:null,tokenCount:null,usageCount:null}),[u,r]=react.useState(false),[a,l]=react.useState(null),c=react.useRef(true),d=react.useCallback(async()=>{if(e){r(true),l(null);try{let f=await o.getSkillStats(e);c.current&&s(f);}catch(f){c.current&&l(f.message);}finally{c.current&&r(false);}}},[o,e]);return react.useEffect(()=>(c.current=true,d(),()=>{c.current=false;}),[d]),{stats:n,loading:u,error:a,refresh:d}}function He(t,e){let o=x(t),[n,s]=react.useState({meta:null,sizeMB:null}),[u,r]=react.useState(false),[a,l]=react.useState(null),c=react.useRef(true),d=react.useCallback(async()=>{if(e){r(true),l(null);try{let f=await o.getTensorStats(e);c.current&&s(f);}catch(f){c.current&&l(f.message);}finally{c.current&&r(false);}}},[o,e]);return react.useEffect(()=>(c.current=true,d(),()=>{c.current=false;}),[d]),{stats:n,loading:u,error:a,refresh:d}}function Ve(t){let e=x(t),[o,n]=react.useState(null),[s,u]=react.useState(false),[r,a]=react.useState(null),l=react.useRef(true),c=react.useCallback(async()=>{u(true),a(null);try{let d=await e.getNetworkStats();l.current&&n(d);}catch(d){l.current&&a(d.message);}finally{l.current&&u(false);}},[e]);return react.useEffect(()=>(l.current=true,c(),()=>{l.current=false;}),[c]),{stats:o,loading:s,error:r,refresh:c}}function Ye(t,e=5,o=1){let n=x(t),[s,u]=react.useState([]),[r,a]=react.useState(false),[l,c]=react.useState(null),d=react.useRef(true),f=react.useCallback(async m=>{a(true),c(null);try{let g=await n.getTrending(e,m??o);d.current&&u(g);}catch(g){d.current&&c(g.message);}finally{d.current&&a(false);}},[n,e,o]);return react.useEffect(()=>(d.current=true,f(),()=>{d.current=false;}),[f]),{repos:s,loading:r,error:l,refresh:f}}function et(t,e){let o=x(t),[n,s]=react.useState({stars:0,starred:false,repo_id:e||""}),[u,r]=react.useState(false),[a,l]=react.useState(null),c=react.useRef(true),d=react.useCallback(async()=>{if(e)try{let m=await o.getStarInfo(e);c.current&&s(m);}catch{}},[o,e]);react.useEffect(()=>(c.current=true,d(),()=>{c.current=false;}),[d]);let f=react.useCallback(async()=>{if(e){r(true),l(null);try{let m=n.starred?await o.unstarRepo(e):await o.starRepo(e);c.current&&s({stars:m.stars,starred:m.starred,repo_id:e});}catch(m){c.current&&l(m.message);}finally{c.current&&r(false);}}},[o,e,n.starred]);return {...n,loading:u,error:a,toggle:f,refresh:d}}function C(...t){return tailwindMerge.twMerge(clsx.clsx(t))}var nt=/^(https?:\/\/|mailto:|\/[^/])/i;function st(t){let e=t.trim();return nt.test(e)?e:null}function _(t){let e=[],o=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,n=0,s,u=0;for(;(s=o.exec(t))!==null;){s.index>n&&e.push(t.slice(n,s.index));let r=`i${u++}`;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)},r));else if(s[2])e.push(jsxRuntime.jsx("strong",{children:s[3]},r));else if(s[4])e.push(jsxRuntime.jsx("em",{children:s[5]},r));else if(s[6])e.push(jsxRuntime.jsx("em",{children:s[7]},r));else if(s[8]){let a=st(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]},r)):e.push(s[9]);}n=s.index+s[0].length;}return n<t.length&&e.push(t.slice(n)),e.length>0?e:[t]}function ot(t){let e=t.split(`
|
|
2
|
-
`),o=[],n=0;for(;n<e.length;){let
|
|
3
|
-
`),lang:
|
|
1
|
+
'use strict';var react=require('react'),lucideReact=require('lucide-react'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime');async function S(r,e,o,n){let a={"Content-Type":"application/json",...o?.headers};n&&(a.Authorization=`Bearer ${n}`);let c=await fetch(`${r}${e}`,{...o,headers:a});if(!c.ok){let t=`HTTP ${c.status}`;try{let s=await c.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return c.json()}function A(r){let e=r.indexOf(":");return {mode:r.slice(0,e),cid:r.slice(e+1)}}function R(r){let e=r.apiBaseUrl,o=r.authorMid,n=r.ownerMid,a=r.apiKey,c=r.stacknetUrl||r.apiBaseUrl;return react.useMemo(()=>({async listRepos(t,s){let i=new URLSearchParams;(t||n)&&i.set("owner",t||n),s?.limit&&i.set("limit",String(s.limit)),s?.cursor&&i.set("cursor",s.cursor);let u=i.toString()?`?${i}`:"",d=await S(e,`/api/rack/repos${u}`,void 0,a);return {items:d.repos||[],pagination:d.pagination||{total:(d.repos||[]).length,limit:50,has_more:false,next_cursor:null}}},async initRepo(t){return S(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...t,owner_mid:n})},a)},async push(t,s){return S(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...s,author_mid:o})},a)},async getTree(t,s="main"){let i=await S(e,`/api/rack/${t}/tree/${s}`,void 0,a);return {tree:i.tree,commit_cid:i.commit_cid}},async getBlob(t,s){return (await S(e,`/api/rack/${t}/blob/${s}`,void 0,a)).content},async getLog(t,s,i){let u=new URLSearchParams;s&&u.set("ref",s),i&&u.set("max_count",String(i));let d=u.toString()?`?${u}`:"";return (await S(e,`/api/rack/${t}/log${d}`,void 0,a)).commits||[]},async getBranches(t){return (await S(e,`/api/rack/${t}/branches`,void 0,a)).branches||[]},async createBranch(t,s,i){return S(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:s,from_ref:i})},a)},async merge(t,s,i){return S(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:s,target_branch:i})},a)},async getDiff(t,s,i){return (await S(e,`/api/rack/${t}/diff/${s}/${i}`,void 0,a)).diff?.entries||[]},async starRepo(t){return S(e,`/api/rack/${t}/star`,{method:"POST"},a)},async unstarRepo(t){return S(e,`/api/rack/${t}/star`,{method:"DELETE"},a)},async getStarInfo(t){return S(e,`/api/rack/${t}/stars`,void 0,a)},async getSkillStats(t){let s={meta:null,tokenCount:null,usageCount:null};try{let{tree:i}=await this.getTree(t,"main");if(!i?.entries)return s;if(i.entries["META.json"]){let m=A(i.entries["META.json"]).cid,f=await this.getBlob(t,m);s.meta=JSON.parse(f);}let u=0,d=Object.values(i.entries).map(async m=>{try{let f=A(m).cid,g=await this.getBlob(t,f);u+=g.length;}catch{}});await Promise.all(d),u>0&&(s.tokenCount=Math.ceil(u/4)),s.meta?.skill_id&&(s.usageCount=await this.getSkillUsageCount(s.meta.skill_id));}catch{}return s},async getSkillUsageCount(t){try{let s=await fetch(`${c}/v1/skills/${encodeURIComponent(t)}`);if(s.ok){let u=await s.json();return u.usage_count??u.usageCount??null}let i=await fetch(`${c}/v1/skills?scope=public`);if(i.ok){let d=((await i.json()).skills||[]).find(m=>m.name===t||m.id===t);if(d)return d.usage_count??d.usageCount??0}return 0}catch{return null}},async getTensorStats(t){let s={meta:null,sizeMB:null};try{let{tree:i}=await this.getTree(t,"main");if(!i?.entries)return s;if(i.entries["TENSOR_META.json"]){let u=A(i.entries["TENSOR_META.json"]).cid,d=await this.getBlob(t,u);s.meta=JSON.parse(d),s.sizeMB=s.meta?.tensor_size_mb??null;}}catch{}return s},async getNetworkStats(){try{return (await S(e,"/api/rack/stats",void 0,a)).stats||null}catch{return null}},async getTrending(t=5,s=1,i){try{let u=new URLSearchParams({limit:String(t),days:String(s)});i&&u.set("cursor",i);let d=await S(e,`/api/rack/trending?${u}`,void 0,a);return {items:d.trending||[],pagination:d.pagination||{total:(d.trending||[]).length,limit:t,has_more:!1,next_cursor:null}}}catch{return {items:[],pagination:{total:0,limit:t,has_more:false,next_cursor:null}}}}}),[e,o,n,a,c])}function Be(r){let e=R(r),o=react.useRef(e);o.current=e;let[n,a]=react.useState([]),[c,t]=react.useState(true),[s,i]=react.useState(null),u=react.useRef(true),d=react.useRef(null),m=react.useCallback(async()=>{d.current?.abort();let f=new AbortController;d.current=f;try{u.current&&(t(!0),i(null));let g=await o.current.listRepos();u.current&&!f.signal.aborted&&a(g.items);}catch(g){u.current&&!f.signal.aborted&&i(g instanceof Error?g.message:"Failed to load repos");}finally{u.current&&!f.signal.aborted&&t(false);}},[]);return react.useEffect(()=>(u.current=true,m(),()=>{u.current=false,d.current?.abort();}),[m]),{repos:n,loading:c,error:s,refresh:m}}function Oe(r){return Object.entries(r).map(([e,o])=>{let n=o.indexOf(":"),a=n>0?o.slice(0,n):"100644",c=n>0?o.slice(n+1):o;return {path:e,mode:a,cid:c,isDir:a==="040000"}}).sort((e,o)=>e.isDir!==o.isDir?e.isDir?-1:1:e.path.localeCompare(o.path))}function F(r,e,o="main"){let n=R(r),[a,c]=react.useState([]),[t,s]=react.useState(false),[i,u]=react.useState(null),d=react.useRef(true),m=react.useCallback(async()=>{if(e)try{d.current&&(s(!0),u(null));let{tree:g}=await n.getTree(e,o);d.current&&c(Oe(g.entries));}catch(g){d.current&&u(g instanceof Error?g.message:"Failed to load tree");}finally{d.current&&s(false);}},[n,e,o]);react.useEffect(()=>(d.current=true,m(),()=>{d.current=false;}),[m]);let f=react.useCallback(async g=>{if(!e)throw new Error("No repo selected");return n.getBlob(e,g)},[n,e]);return {entries:a,loading:t,error:i,refresh:m,getFileContent:f}}function He(r){let e=R(r),[o,n]=react.useState(false),[a,c]=react.useState(null),t=react.useRef(true);return react.useEffect(()=>(t.current=true,()=>{t.current=false;}),[]),{push:react.useCallback(async(i,u,d,m)=>{try{return t.current&&(n(!0),c(null)),await e.push(i,{files:u,message:d,branch:m})}catch(f){let g=f instanceof Error?f.message:"Push failed";return t.current&&c(g),null}finally{t.current&&n(false);}},[e]),pushing:o,error:a}}function K(r,e={}){let{pageSize:o=50,owner:n}=e,a=R(r),[c,t]=react.useState([]),[s,i]=react.useState(null),[u,d]=react.useState(false),[m,f]=react.useState(null),g=react.useRef(null),p=react.useRef(true),w=react.useCallback(async(v,E=false)=>{d(true),f(null);try{let N=await a.listRepos(n,{limit:o,cursor:v||void 0});p.current&&(t(_=>E?[..._,...N.items]:N.items),i(N.pagination),g.current=N.pagination.next_cursor);}catch(N){p.current&&f(N.message);}finally{p.current&&d(false);}},[a,n,o]),k=react.useCallback(async()=>{!g.current||u||await w(g.current,true);},[w,u]),h=react.useCallback(async()=>{g.current=null,await w(void 0,false);},[w]);return react.useEffect(()=>(p.current=true,w(),()=>{p.current=false;}),[w]),{repos:c,hasMore:s?.has_more??false,total:s?.total??0,loading:u,error:m,loadMore:k,reset:h,pagination:s}}var J="stacknet-rack-apikey";function Je(r){let e=r.stacknetUrl||r.apiBaseUrl,[o,n]=react.useState({authenticated:false}),[a,c]=react.useState(null),[t,s]=react.useState(false),i=react.useCallback(f=>({"Content-Type":"application/json",...f||r.apiKey?{Authorization:`Bearer ${f||r.apiKey}`}:{}}),[r.apiKey]),u=react.useCallback(async f=>{s(true);try{let g=await fetch(`${e}/health`,{headers:i(f)});if(!g.ok)throw new Error(`Authentication failed: ${g.status}`);let p={authenticated:!0,apiKey:f,permission:f.startsWith("gk_")?"write":"read"};n(p);try{localStorage.setItem(J,f);}catch{}return p}catch(g){throw n({authenticated:false}),g}finally{s(false);}},[e,i]),d=react.useCallback(()=>{n({authenticated:false}),c(null);try{localStorage.removeItem(J);}catch{}},[]),m=react.useCallback(async()=>{let f=o.apiKey||r.apiKey;if(!f)return null;try{let g=await fetch(`${e}/network/usage`,{headers:i(f)});if(!g.ok)return null;let p=await g.json(),w={planAllocation:p.plan_allocation??p.planAllocation??0,inferenceUsed:p.inference_used??p.inferenceUsed??0,ledgerSpent:p.ledger_spent??p.ledgerSpent??0,totalUsed:p.total_used??p.totalUsed??0,remaining:p.remaining??0,percent:p.percent??0,exceeded:p.exceeded??!1};return c(w),w}catch{return null}},[o.apiKey,r.apiKey,e,i]);return react.useEffect(()=>{let f=r.apiKey;if(f){n({authenticated:true,apiKey:f,permission:f.startsWith("gk_")?"write":"read"});return}try{let g=localStorage.getItem(J);g&&n({authenticated:!0,apiKey:g,permission:g.startsWith("gk_")?"write":"read"});}catch{}},[r.apiKey]),{session:o,budget:a,loading:t,login:u,logout:d,refreshBudget:m}}var fe=1e3,me=1e3,ge=100;function pe(r,e){if(r==="skill"){let a=ge+Math.ceil(e/4);return {type:r,totalBytes:e,totalMegabytes:e/1e6,baseCost:a,multiplier:fe,registrationCostTokens:a*fe}}let o=Math.ceil(e/1e6),n=ge+o;return {type:r,totalBytes:e,totalMegabytes:o,baseCost:n,multiplier:me,registrationCostTokens:n*me}}function Ve(r){let e=r.stacknetUrl||r.apiBaseUrl,o=r.apiKey,[n,a]=react.useState(false),[c,t]=react.useState(null),s=react.useCallback(()=>{if(!o)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${o}`}},[o]),i=react.useCallback(async d=>{a(true),t(null);try{let m=await fetch(`${e}/skills`,{method:"POST",headers:s(),body:JSON.stringify(d)});if(!m.ok){let f=await m.json().catch(()=>({error:`HTTP ${m.status}`}));throw new Error(f.error||`Registration failed: ${m.status}`)}return await m.json()}catch(m){throw t(m.message),m}finally{a(false);}},[e,s]),u=react.useCallback(async d=>{a(true),t(null);try{let m=await fetch(`${e}/tensors`,{method:"POST",headers:s(),body:JSON.stringify(d)});if(!m.ok){let f=await m.json().catch(()=>({error:`HTTP ${m.status}`}));throw new Error(f.error||`Registration failed: ${m.status}`)}return await m.json()}catch(m){throw t(m.message),m}finally{a(false);}},[e,s]);return {registerSkill:i,registerTensor:u,estimateCost:pe,registering:n,error:c}}function Ye(r,e){let o=R(r),[n,a]=react.useState({meta:null,tokenCount:null,usageCount:null}),[c,t]=react.useState(false),[s,i]=react.useState(null),u=react.useRef(true),d=react.useCallback(async()=>{if(e){t(true),i(null);try{let m=await o.getSkillStats(e);u.current&&a(m);}catch(m){u.current&&i(m.message);}finally{u.current&&t(false);}}},[o,e]);return react.useEffect(()=>(u.current=true,d(),()=>{u.current=false;}),[d]),{stats:n,loading:c,error:s,refresh:d}}function tt(r,e){let o=R(r),[n,a]=react.useState({meta:null,sizeMB:null}),[c,t]=react.useState(false),[s,i]=react.useState(null),u=react.useRef(true),d=react.useCallback(async()=>{if(e){t(true),i(null);try{let m=await o.getTensorStats(e);u.current&&a(m);}catch(m){u.current&&i(m.message);}finally{u.current&&t(false);}}},[o,e]);return react.useEffect(()=>(u.current=true,d(),()=>{u.current=false;}),[d]),{stats:n,loading:c,error:s,refresh:d}}function ot(r){let e=R(r),[o,n]=react.useState(null),[a,c]=react.useState(false),[t,s]=react.useState(null),i=react.useRef(true),u=react.useCallback(async()=>{c(true),s(null);try{let d=await e.getNetworkStats();i.current&&n(d);}catch(d){i.current&&s(d.message);}finally{i.current&&c(false);}},[e]);return react.useEffect(()=>(i.current=true,u(),()=>{i.current=false;}),[u]),{stats:o,loading:a,error:t,refresh:u}}function it(r,e=5,o=1){let n=R(r),[a,c]=react.useState([]),[t,s]=react.useState(null),[i,u]=react.useState(false),[d,m]=react.useState(null),f=react.useRef(true),g=react.useRef(null),p=react.useCallback(async k=>{u(true),m(null),g.current=null;try{let h=await n.getTrending(e,k??o);f.current&&(c(h.items),s(h.pagination),g.current=h.pagination.next_cursor);}catch(h){f.current&&m(h.message);}finally{f.current&&u(false);}},[n,e,o]),w=react.useCallback(async()=>{if(!(!g.current||i)){u(true);try{let k=await n.getTrending(e,o,g.current);f.current&&(c(h=>[...h,...k.items]),s(k.pagination),g.current=k.pagination.next_cursor);}catch(k){f.current&&m(k.message);}finally{f.current&&u(false);}}},[n,e,o,i]);return react.useEffect(()=>(f.current=true,p(),()=>{f.current=false;}),[p]),{repos:a,hasMore:t?.has_more??false,total:t?.total??0,loading:i,error:d,refresh:p,loadMore:w}}function ut(r,e){let o=R(r),[n,a]=react.useState({stars:0,starred:false,repo_id:e||""}),[c,t]=react.useState(false),[s,i]=react.useState(null),u=react.useRef(true),d=react.useCallback(async()=>{if(e)try{let f=await o.getStarInfo(e);u.current&&a(f);}catch{}},[o,e]);react.useEffect(()=>(u.current=true,d(),()=>{u.current=false;}),[d]);let m=react.useCallback(async()=>{if(e){t(true),i(null);try{let f=n.starred?await o.unstarRepo(e):await o.starRepo(e);u.current&&a({stars:f.stars,starred:f.starred,repo_id:e});}catch(f){u.current&&i(f.message);}finally{u.current&&t(false);}}},[o,e,n.starred]);return {...n,loading:c,error:s,toggle:m,refresh:d}}function T(...r){return tailwindMerge.twMerge(clsx.clsx(r))}var mt=/^(https?:\/\/|mailto:|\/[^/])/i;function gt(r){let e=r.trim();return mt.test(e)?e:null}function B(r){let e=[],o=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,n=0,a,c=0;for(;(a=o.exec(r))!==null;){a.index>n&&e.push(r.slice(n,a.index));let t=`i${c++}`;if(a[1])e.push(jsxRuntime.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[0.85em] font-mono text-pink-400",children:a[1].slice(1,-1)},t));else if(a[2])e.push(jsxRuntime.jsx("strong",{children:a[3]},t));else if(a[4])e.push(jsxRuntime.jsx("em",{children:a[5]},t));else if(a[6])e.push(jsxRuntime.jsx("em",{children:a[7]},t));else if(a[8]){let s=gt(a[10]);s?e.push(jsxRuntime.jsx("a",{href:s,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:a[9]},t)):e.push(a[9]);}n=a.index+a[0].length;}return n<r.length&&e.push(r.slice(n)),e.length>0?e:[r]}function pt(r){let e=r.split(`
|
|
2
|
+
`),o=[],n=0;for(;n<e.length;){let a=e[n];if(a.trim()===""){n++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(a.trim())){o.push({type:"hr"}),n++;continue}let c=a.match(/^(#{1,6})\s+(.+)/);if(c){o.push({type:"heading",level:c[1].length,content:c[2]}),n++;continue}if(a.trim().startsWith("```")){let s=a.trim().slice(3).trim(),i=[];for(n++;n<e.length&&!e[n].trim().startsWith("```");)i.push(e[n]),n++;o.push({type:"code",content:i.join(`
|
|
3
|
+
`),lang:s||void 0}),n++;continue}if(/^\s*[-*+]\s/.test(a)){let s=[];for(;n<e.length&&/^\s*[-*+]\s/.test(e[n]);)s.push(e[n].replace(/^\s*[-*+]\s+/,"")),n++;o.push({type:"ul",items:s});continue}if(/^\s*\d+[.)]\s/.test(a)){let s=[];for(;n<e.length&&/^\s*\d+[.)]\s/.test(e[n]);)s.push(e[n].replace(/^\s*\d+[.)]\s+/,"")),n++;o.push({type:"ol",items:s});continue}let t=[];for(;n<e.length&&e[n].trim()!==""&&!e[n].match(/^#{1,6}\s/)&&!e[n].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[n])&&!/^\s*\d+[.)]\s/.test(e[n]);)t.push(e[n]),n++;t.length>0&&o.push({type:"paragraph",content:t.join(" ")});}return o}var ht={1:"text-2xl font-bold mt-6 mb-3",2:"text-xl font-bold mt-5 mb-2",3:"text-lg font-semibold mt-4 mb-2",4:"text-base font-semibold mt-3 mb-1",5:"text-sm font-semibold mt-2 mb-1",6:"text-sm font-medium mt-2 mb-1"};function yt(r,e){switch(r.type){case "hr":return jsxRuntime.jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let o=Math.min(Math.max(r.level||1,1),6),n=`h${o}`;return jsxRuntime.jsx(n,{className:T("text-foreground",ht[o]),children:B(r.content||"")},`b${e}`)}case "paragraph":return jsxRuntime.jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:B(r.content||"")},`b${e}`);case "code":return jsxRuntime.jsx("pre",{className:"mb-3 overflow-x-auto rounded-lg bg-muted p-4 text-sm font-mono leading-relaxed text-foreground",children:jsxRuntime.jsx("code",{children:r.content})},`b${e}`);case "ul":return jsxRuntime.jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:r.items?.map((o,n)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:B(o)},`li${e}-${n}`))},`b${e}`);case "ol":return jsxRuntime.jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:r.items?.map((o,n)=>jsxRuntime.jsx("li",{className:"leading-relaxed",children:B(o)},`li${e}-${n}`))},`b${e}`);default:return null}}function Q({content:r,className:e}){let o=pt(r);return jsxRuntime.jsx("div",{className:T("text-sm",e),children:o.map((n,a)=>yt(n,a))})}function Re({open:r,className:e}){return jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:T("shrink-0 transition-transform duration-150",r?"rotate-0":"-rotate-90",e),children:jsxRuntime.jsx("path",{d:"M16.134 6.16a.5.5 0 1 1 .732.68l-6.5 7-.077.068a.5.5 0 0 1-.655-.068l-6.5-7-.062-.08a.5.5 0 0 1 .718-.667l.076.067L10 12.767z"})})}function xe({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function X({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M15.147 4.146a.5.5 0 0 1 .707.707L10.707 10l5.147 5.147a.5.5 0 0 1-.63.771l-.078-.064L10 10.707l-5.146 5.147a.5.5 0 0 1-.708-.707L9.293 10 4.146 4.853a.5.5 0 0 1 .708-.707L10 9.293z"})})}function ve({size:r=20,className:e}){return jsxRuntime.jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsxRuntime.jsx("path",{d:"M10 3a.5.5 0 0 1 .5.5v6h6l.1.01a.5.5 0 0 1 0 .98l-.1.01h-6v6a.5.5 0 0 1-1 0v-6h-6a.5.5 0 0 1 0-1h6v-6A.5.5 0 0 1 10 3"})})}function wt(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M6.5 3A2.5 2.5 0 0 0 4 5.5v9A2.5 2.5 0 0 0 6.5 17h7a2.5 2.5 0 0 0 2.5-2.5v-7A2.5 2.5 0 0 0 13.5 5H11V3.5a.5.5 0 0 0-1 0V5H6.5ZM5 5.5A1.5 1.5 0 0 1 6.5 4H9v1H6.5A1.5 1.5 0 0 0 5 6.5v8A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 13.5 6H11V4h2.5A2.5 2.5 0 0 1 16 6.5v8a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-9Z"})})}function bt(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M5.5 3A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h9a2.5 2.5 0 0 0 2.5-2.5v-9A2.5 2.5 0 0 0 14.5 3h-9ZM4 5.5A1.5 1.5 0 0 1 5.5 4h9A1.5 1.5 0 0 1 16 5.5v9a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 4 14.5v-9ZM7 7.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5Z"})})}function Rt(){return jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M10 2a.5.5 0 0 1 .354.146l3 3a.5.5 0 0 1-.708.708L10.5 3.707V12.5a.5.5 0 0 1-1 0V3.707L7.354 5.854a.5.5 0 1 1-.708-.708l3-3A.5.5 0 0 1 10 2ZM4 13.5a.5.5 0 0 1 1 0v1A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-1a.5.5 0 0 1 1 0v1a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-1Z"})})}function Se(){let[r,e]=react.useState(false);return react.useEffect(()=>{if(typeof window>"u")return;let o=()=>e(window.innerWidth<768);return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),r}function Ce({onClose:r,children:e,title:o}){let n=Se(),a=react.useRef(r);return a.current=r,react.useEffect(()=>{let c=t=>{t.key==="Escape"&&a.current();};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[]),n?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full max-h-[90vh] overflow-y-auto rounded-t-2xl bg-[#1a1a1a] p-5 pb-8 animate-in slide-in-from-bottom duration-200",onClick:c=>c.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-4 h-1 w-10 rounded-full bg-zinc-600"}),jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-foreground",children:o}),jsxRuntime.jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(X,{size:20})})]}),e]})]}):jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full max-w-lg overflow-y-auto rounded-2xl bg-[#1a1a1a] p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:c=>c.stopPropagation(),children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsxRuntime.jsx("h2",{className:"text-lg font-semibold text-foreground",children:o}),jsxRuntime.jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(X,{size:20})})]}),e]})]})}function vt(r){let e=r.split(`
|
|
4
|
+
`),o="",n="",c=false;for(let t=0;t<e.length;t++){let s=e[t].trim();if(t===0&&s==="---"){c=true;continue}if(c){s==="---"&&(c=false,true);continue}if(!o){let i=s.match(/^#{1,2}\s+(.+)/);if(i){o=i[1].trim();continue}}if(o&&!n){if(!s||s.startsWith("#")||s==="---"||s==="***"||s==="___")continue;n=s.replace(/\*\*/g,"").replace(/`/g,"").trim();break}}return o?{title:o,description:n}:null}function St({onClose:r,onCreated:e,config:o}){let[n,a]=react.useState(""),[c,t]=react.useState(""),[s,i]=react.useState(""),[u,d]=react.useState(false),[m,f]=react.useState(null),[g,p]=react.useState(false),w=h=>{if(i(h),!n.trim()&&!c.trim()&&h.trim().length>10){let v=vt(h);v&&(a(v.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")),t(v.description),p(true));}};return jsxRuntime.jsx(Ce,{title:"Write skill instructions",onClose:r,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsxRuntime.jsx("input",{id:"skill-name",value:n,onChange:h=>a(h.target.value),placeholder:"weekly-status-report",className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-desc",className:"text-sm text-muted-foreground",children:"Description"}),jsxRuntime.jsx("textarea",{id:"skill-desc",value:c,onChange:h=>t(h.target.value),placeholder:"Generate weekly status reports from recent work.",rows:3,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxRuntime.jsxs("div",{className:"space-y-1.5",children:[jsxRuntime.jsx("label",{htmlFor:"skill-instructions",className:"text-sm text-muted-foreground",children:"Instructions"}),jsxRuntime.jsx("textarea",{id:"skill-instructions",value:s,onChange:h=>w(h.target.value),placeholder:"Summarize my recent work in three sections: wins, blockers, and next steps.",rows:8,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),m&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:m}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsxRuntime.jsx("button",{onClick:r,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsxRuntime.jsx("button",{onClick:async()=>{if(n.trim()){d(true),f(null);try{let h=o.apiBaseUrl||"",v=g?s.trim():`# ${n.trim()}
|
|
4
5
|
|
|
5
|
-
${
|
|
6
|
+
${c.trim()}
|
|
6
7
|
|
|
7
8
|
---
|
|
8
9
|
|
|
9
|
-
${a.trim()}`,S=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n.trim(),description:u.trim(),skill_md:v,content_type:"code"})});if(!S.ok){let T=`Failed to register skill (${S.status})`;try{let R=await S.json();R.error&&(T=R.error);}catch{}throw new Error(T)}e?.(),t();}catch(p){m(p instanceof Error?p.message:"Failed to create skill");}finally{d(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 gt({onClose:t,onCreated:e,config:o}){let n=react.useRef(null),[s,u]=react.useState(false),[r,a]=react.useState(false),[l,c]=react.useState(null),d=async m=>{a(true),c(null);try{let g=await m.text(),p=o.apiBaseUrl||"",v=m.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),S=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:v,skill_md:g,content_type:"code"})});if(!S.ok){let T=`Failed to register skill (${S.status})`;try{let R=await S.json();R.error&&(T=R.error);}catch{}throw new Error(T)}e?.(),t();}catch(g){c(g instanceof Error?g.message:"Upload failed");}finally{a(false);}};return jsxRuntime.jsx(he,{title:"Upload skill",onClose:t,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{onDragOver:m=>{m.preventDefault(),u(true);},onDragLeave:()=>u(false),onDrop:m=>{m.preventDefault(),u(false);let g=m.dataTransfer.files[0];g&&d(g);},onClick:()=>n.current?.click(),className:C("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",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(ge,{size:20,className:"text-muted-foreground"})}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:r?"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:m=>{let g=m.target.files?.[0];g&&d(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 pt({onClose:t,onSelect:e}){let o=pe(),n=react.useRef(null),s=react.useRef(t);s.current=t,react.useEffect(()=>{if(o)return;let r=a=>{n.current&&a.target instanceof Node&&!n.current.contains(a.target)&&s.current();};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[o]);let u=[{id:"create-with-geoff",icon:jsxRuntime.jsx(ut,{}),label:"Create with Geoff"},{id:"write",icon:jsxRuntime.jsx(dt,{}),label:"Write skill instructions"},{id:"upload",icon:jsxRuntime.jsx(ft,{}),label:"Upload a skill"}];return o?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:r=>r.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),u.map(r=>jsxRuntime.jsxs("button",{onClick:()=>{e(r.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:[r.icon,r.label]},r.id))]})]}):jsxRuntime.jsx("div",{ref:n,className:"absolute right-2 top-11 z-50 w-56 overflow-hidden rounded-xl border border-zinc-700 bg-[#2a2a2a] shadow-xl animate-in fade-in zoom-in-95 duration-100",children:u.map(r=>jsxRuntime.jsxs("button",{onClick:()=>{e(r.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:[r.icon,r.label]},r.id))})}function ht({entry:t,selected:e,onSelect:o,depth:n=0}){return jsxRuntime.jsxs("button",{onClick:()=>o(t),className:C("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+n*16}px`},children:[jsxRuntime.jsx("span",{className:"truncate flex-1",children:t.path.split("/").pop()}),t.isDir&&jsxRuntime.jsx(me,{className:"ml-auto text-muted-foreground"})]})}function yt({repo:t,selected:e,expanded:o,onSelect:n,onToggle:s,children:u}){return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>{n(),s();},className:C("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsxRuntime.jsx(me,{open:o}),jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4 shrink-0"}),jsxRuntime.jsx("span",{className:"truncate",children:t.name})]}),o&&u]})}function kt({entry:t,content:e,loading:o,repoName:n}){let[s,u]=react.useState(false),r=react.useRef(null);react.useEffect(()=>()=>{r.current&&clearTimeout(r.current);},[]);let[a,l]=react.useState(false),c=async()=>{if(e)try{await navigator.clipboard.writeText(e),u(!0),l(!1),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>u(!1),2e3);}catch{l(true),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>l(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(o)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let d=t.path.split("/").pop()||t.path,f=/\.(md|mdx)$/i.test(d);return jsxRuntime.jsxs("div",{className:"flex h-full flex-col px-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[jsxRuntime.jsx("h3",{className:"text-sm sm:text-lg font-semibold text-foreground",children:d}),jsxRuntime.jsx("button",{onClick:c,"aria-label":"Copy file content",className:C("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:f?jsxRuntime.jsx(V,{content:e||""}):jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function xt({config:t,category:e,className:o,style:n}){let{repos:s,loading:u,error:r,refresh:a}=A(t),[l,c]=react.useState(null),[d,f]=react.useState(null),[m,g]=react.useState(null),[p,v]=react.useState(null),[S,T]=react.useState(false),[R,q]=react.useState(""),[ye,G]=react.useState(false),[Y,Q]=react.useState(false),[X,M]=react.useState(null),ke=s.find(y=>y.repo_id===l),{entries:xe,getFileContent:ee}=U(t,d),te=s.filter(y=>!R||y.name.toLowerCase().includes(R.toLowerCase())),we=react.useCallback(async y=>{if(!y.isDir){g(y),T(true);try{let N=await ee(y.cid);v(N);}catch(N){let ve=N instanceof Error?N.message:"Unknown error";v(`Failed to load file: ${ve}`);}finally{T(false);}}},[ee]);react.useEffect(()=>{s.length>0&&!l&&(c(s[0].repo_id),f(s[0].repo_id));},[s,l]);let be=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"):M(y);};return jsxRuntime.jsxs("div",{className:C("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:ye?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(ue,{size:16,className:"shrink-0 text-muted-foreground"}),jsxRuntime.jsx("input",{type:"text",value:R,onChange:y=>q(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:()=>{G(false),q("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(Z,{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:()=>G(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsxRuntime.jsx(ue,{size:20})}),jsxRuntime.jsx("button",{onClick:()=>Q(!Y),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(ge,{size:20})})]})}),Y&&jsxRuntime.jsx(pt,{onClose:()=>Q(false),onSelect:be}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:u?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):r?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:r}):te.length===0?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:R?"No matching items":"No items yet"}):jsxRuntime.jsx("div",{className:"space-y-0.5",children:te.map(y=>jsxRuntime.jsx(yt,{repo:y,selected:l===y.repo_id,expanded:d===y.repo_id,onSelect:()=>{c(y.repo_id),g(null),v(null);},onToggle:()=>f(d===y.repo_id?null:y.repo_id),children:jsxRuntime.jsx("div",{className:"ml-10 pl-1",children:xe.map(N=>jsxRuntime.jsx(ht,{entry:N,selected:m?.path===N.path,onSelect:we,depth:N.path.split("/").length-1},N.path))})},y.repo_id))})})]}),jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntime.jsx(kt,{entry:m,content:p,loading:S,repoName:ke?.name||""})}),X==="write"&&jsxRuntime.jsx(mt,{config:t,onClose:()=>M(null),onCreated:a}),X==="upload"&&jsxRuntime.jsx(gt,{config:t,onClose:()=>M(null),onCreated:a})]})}
|
|
10
|
-
exports.Markdown=
|
|
10
|
+
${s.trim()}`,E=await fetch(`${h}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n.trim(),description:c.trim(),skill_md:v,content_type:"code"})});if(!E.ok){let N=`Failed to register skill (${E.status})`;try{let _=await E.json();_.error&&(N=_.error);}catch{}throw new Error(N)}e?.(),r();}catch(h){f(h instanceof Error?h.message:"Failed to create skill");}finally{d(false);}}},disabled:u||!n.trim(),className:"rounded-lg bg-zinc-600 px-4 py-2 text-sm font-medium text-white hover:bg-zinc-500 disabled:opacity-50",children:u?"Creating...":"Create"})]})]})})}function Ct({onClose:r,onCreated:e,config:o}){let n=react.useRef(null),[a,c]=react.useState(false),[t,s]=react.useState(false),[i,u]=react.useState(null),d=async f=>{s(true),u(null);try{let g=await f.text(),p=o.apiBaseUrl||"",w=f.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),k=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:w,skill_md:g,content_type:"code"})});if(!k.ok){let h=`Failed to register skill (${k.status})`;try{let v=await k.json();v.error&&(h=v.error);}catch{}throw new Error(h)}e?.(),r();}catch(g){u(g instanceof Error?g.message:"Upload failed");}finally{s(false);}};return jsxRuntime.jsx(Ce,{title:"Upload skill",onClose:r,children:jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{onDragOver:f=>{f.preventDefault(),c(true);},onDragLeave:()=>c(false),onDrop:f=>{f.preventDefault(),c(false);let g=f.dataTransfer.files[0];g&&d(g);},onClick:()=>n.current?.click(),className:T("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",a?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsxRuntime.jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsxRuntime.jsx(ve,{size:20,className:"text-muted-foreground"})}),jsxRuntime.jsx("p",{className:"text-sm text-muted-foreground",children:t?"Uploading...":"Drag and drop or click to upload"})]}),jsxRuntime.jsx("input",{ref:n,type:"file",accept:".md,.zip,.skill,.txt,.yml,.yaml",className:"hidden","aria-label":"Upload skill file",onChange:f=>{let g=f.target.files?.[0];g&&d(g);}}),i&&jsxRuntime.jsx("p",{className:"text-sm text-red-500",children:i}),jsxRuntime.jsxs("div",{className:"space-y-2 text-xs text-muted-foreground",children:[jsxRuntime.jsx("p",{className:"font-medium text-foreground/70",children:"File requirements"}),jsxRuntime.jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[jsxRuntime.jsx("li",{children:".md file must contain skill name and description formatted in YAML"}),jsxRuntime.jsx("li",{children:".zip or .skill file must include a SKILL.md file"})]})]})]})})}function Nt({onClose:r,onSelect:e}){let o=Se(),n=react.useRef(null),a=react.useRef(r);a.current=r,react.useEffect(()=>{if(o)return;let t=s=>{n.current&&s.target instanceof Node&&!n.current.contains(s.target)&&a.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[o]);let c=[{id:"create-with-geoff",icon:jsxRuntime.jsx(wt,{}),label:"Create with Geoff"},{id:"write",icon:jsxRuntime.jsx(bt,{}),label:"Write skill instructions"},{id:"upload",icon:jsxRuntime.jsx(Rt,{}),label:"Upload a skill"}];return o?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:r,children:[jsxRuntime.jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxRuntime.jsxs("div",{className:"relative z-10 w-full rounded-t-2xl bg-[#1a1a1a] p-4 pb-8 animate-in slide-in-from-bottom duration-200",onClick:t=>t.stopPropagation(),children:[jsxRuntime.jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),c.map(t=>jsxRuntime.jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-800",children:[t.icon,t.label]},t.id))]})]}):jsxRuntime.jsx("div",{ref:n,className:"absolute right-2 top-11 z-50 w-56 overflow-hidden rounded-xl border border-zinc-700 bg-[#2a2a2a] shadow-xl animate-in fade-in zoom-in-95 duration-100",children:c.map(t=>jsxRuntime.jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[t.icon,t.label]},t.id))})}function Tt({entry:r,selected:e,onSelect:o,depth:n=0}){return jsxRuntime.jsxs("button",{onClick:()=>o(r),className:T("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+n*16}px`},children:[jsxRuntime.jsx("span",{className:"truncate flex-1",children:r.path.split("/").pop()}),r.isDir&&jsxRuntime.jsx(Re,{className:"ml-auto text-muted-foreground"})]})}function Pt({repo:r,selected:e,expanded:o,onSelect:n,onToggle:a,children:c}){return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>{n(),a();},className:T("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsxRuntime.jsx(Re,{open:o}),jsxRuntime.jsx(lucideReact.FileText,{className:"h-4 w-4 shrink-0"}),jsxRuntime.jsx("span",{className:"truncate",children:r.name})]}),o&&c]})}function Et({entry:r,content:e,loading:o,repoName:n}){let[a,c]=react.useState(false),t=react.useRef(null);react.useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[s,i]=react.useState(false),u=async()=>{if(e)try{await navigator.clipboard.writeText(e),c(!0),i(!1),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>c(!1),2e3);}catch{i(true),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>i(false),2e3);}};if(!r)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(o)return jsxRuntime.jsx("div",{className:"flex h-full items-center justify-center",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let d=r.path.split("/").pop()||r.path,m=/\.(md|mdx)$/i.test(d);return jsxRuntime.jsxs("div",{className:"flex h-full flex-col px-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[jsxRuntime.jsx("h3",{className:"text-sm sm:text-lg font-semibold text-foreground",children:d}),jsxRuntime.jsx("button",{onClick:u,"aria-label":"Copy file content",className:T("rounded p-1 transition-colors",a?"text-green-500":s?"text-red-500":"text-muted-foreground hover:text-foreground"),children:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsxRuntime.jsx("path",{d:"M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"})})})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-auto p-4",children:m?jsxRuntime.jsx(Q,{content:e||""}):jsxRuntime.jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function _t({config:r,category:e,className:o,style:n}){let{repos:a,loading:c,error:t,hasMore:s,loadMore:i,reset:u}=K(r,{pageSize:50}),[d,m]=react.useState(null),[f,g]=react.useState(null),[p,w]=react.useState(null),[k,h]=react.useState(null),[v,E]=react.useState(false),[N,_]=react.useState(""),[Te,re]=react.useState(false),[ne,se]=react.useState(false),[oe,U]=react.useState(null),Pe=a.find(b=>b.repo_id===d),{entries:Ee,getFileContent:ae}=F(r,f),ie=a.filter(b=>!N||b.name.toLowerCase().includes(N.toLowerCase())),_e=react.useCallback(async b=>{if(!b.isDir){w(b),E(true);try{let P=await ae(b.cid);h(P);}catch(P){let $e=P instanceof Error?P.message:"Unknown error";h(`Failed to load file: ${$e}`);}finally{E(false);}}},[ae]);react.useEffect(()=>{a.length>0&&!d&&(m(a[0].repo_id),g(a[0].repo_id));},[a,d]);let Me=b=>{b==="create-with-geoff"?window.open(`https://www.geoff.ai/?p=${encodeURIComponent("Let's create a skill together using your skill-creator skill. First ask me what the skill should do.")}`,"_blank","noopener,noreferrer"):U(b);};return jsxRuntime.jsxs("div",{className:T("flex flex-1 h-full min-h-0",o),style:n,children:[jsxRuntime.jsxs("div",{className:"relative flex w-96 shrink-0 flex-col border-r",children:[jsxRuntime.jsx("div",{className:"flex h-12 items-center gap-2 px-3",children:Te?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-md border bg-muted/50 px-2 py-1",children:[jsxRuntime.jsx(xe,{size:16,className:"shrink-0 text-muted-foreground"}),jsxRuntime.jsx("input",{type:"text",value:N,onChange:b=>_(b.target.value),placeholder:"Search",autoFocus:true,"aria-label":"Search items",className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),jsxRuntime.jsx("button",{onClick:()=>{re(false),_("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(X,{size:16})})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground capitalize",children:e||"Items"}),jsxRuntime.jsx("button",{onClick:()=>re(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsxRuntime.jsx(xe,{size:20})}),jsxRuntime.jsx("button",{onClick:()=>se(!ne),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsxRuntime.jsx(ve,{size:20})})]})}),ne&&jsxRuntime.jsx(Nt,{onClose:()=>se(false),onSelect:Me}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:c?jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):t?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:t}):ie.length===0?jsxRuntime.jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:N?"No matching items":"No items yet"}):jsxRuntime.jsx("div",{className:"space-y-0.5",children:ie.map(b=>jsxRuntime.jsx(Pt,{repo:b,selected:d===b.repo_id,expanded:f===b.repo_id,onSelect:()=>{m(b.repo_id),w(null),h(null);},onToggle:()=>g(f===b.repo_id?null:b.repo_id),children:jsxRuntime.jsx("div",{className:"ml-10 pl-1",children:Ee.map(P=>jsxRuntime.jsx(Tt,{entry:P,selected:p?.path===P.path,onSelect:_e,depth:P.path.split("/").length-1},P.path))})},b.repo_id))})})]}),jsxRuntime.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntime.jsx(Et,{entry:p,content:k,loading:v,repoName:Pe?.name||""})}),oe==="write"&&jsxRuntime.jsx(St,{config:r,onClose:()=>U(null),onCreated:u}),oe==="upload"&&jsxRuntime.jsx(Ct,{config:r,onClose:()=>U(null),onCreated:u})]})}async function Ne(r,e,o,n){let a={"Content-Type":"application/json",...o?.headers};n&&(a.Authorization=`Bearer ${n}`);let c=await fetch(`${r}${e}`,{...o,headers:a});if(!c.ok){let t=`HTTP ${c.status}`;try{let s=await c.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return c.json()}function zt({config:r,repoId:e,onAuthRequired:o,className:n,style:a}){let c=r.apiBaseUrl,t=r.apiKey,[s,i]=react.useState({stars:0,starred:false,repo_id:e}),[u,d]=react.useState(false),[m,f]=react.useState(null),g=react.useRef(true),p=c.includes("/cpx/rack")?"":"/api/rack";react.useEffect(()=>(g.current=true,Ne(c,`${p}/${e}/stars`,void 0,t).then(k=>{g.current&&i(k);}).catch(()=>{}),()=>{g.current=false;}),[c,e,t,p]);let w=react.useCallback(async k=>{if(k.preventDefault(),k.stopPropagation(),!t){o?.();return}d(true),f(null);try{let h=s.starred?"DELETE":"POST",v=await Ne(c,`${p}/${e}/star`,{method:h},t);g.current&&i({stars:v.stars,starred:v.starred,repo_id:e});}catch(h){g.current&&f(h.message);}finally{g.current&&d(false);}},[c,e,t,s.starred,o]);return jsxRuntime.jsxs("button",{onClick:w,disabled:u,title:m||(s.starred?"Unstar (100k tokens)":"Star (100k tokens)"),className:n,style:{display:"inline-flex",alignItems:"center",gap:"4px",background:"none",border:"none",cursor:u?"wait":"pointer",padding:"4px 8px",fontSize:"12px",fontFamily:"inherit",color:s.starred?"#f59e0b":"#91918d",transition:"color 150ms",opacity:u?.5:1,...a},children:[jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:s.starred?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})}),jsxRuntime.jsx("span",{children:s.stars})]})}
|
|
11
|
+
exports.Markdown=Q;exports.RackBrowser=_t;exports.StarButton=zt;exports.estimateCost=pe;exports.useNetworkStats=ot;exports.usePaginatedRepos=K;exports.useRackClient=R;exports.useRackRegister=Ve;exports.useRackSession=Je;exports.useRepoPush=He;exports.useRepoTree=F;exports.useRepos=Be;exports.useSkillStats=Ye;exports.useStar=ut;exports.useTensorStats=tt;exports.useTrending=it;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { CostEstimate, DiffEntry, InitResult, NetworkStats, 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, useRackClient, useRackRegister, useRackSession, useRepoPush, useRepoTree, useRepos, useSkillStats, useStar, useTensorStats, useTrending } from './hooks/index.cjs';
|
|
3
|
-
export { Markdown, RackBrowser, RackBrowserProps } from './components/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
|
+
export { Markdown, RackBrowser, RackBrowserProps, StarButton, StarButtonProps } from './components/index.cjs';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { CostEstimate, DiffEntry, InitResult, NetworkStats, 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, useRackClient, useRackRegister, useRackSession, useRepoPush, useRepoTree, useRepos, useSkillStats, useStar, useTensorStats, useTrending } from './hooks/index.js';
|
|
3
|
-
export { Markdown, RackBrowser, RackBrowserProps } from './components/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
|
+
export { Markdown, RackBrowser, RackBrowserProps, StarButton, StarButtonProps } from './components/index.js';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import 'react';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {useMemo,useRef,useState,useCallback,useEffect}from'react';import {Loader2,FileText}from'lucide-react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsx,jsxs,Fragment}from'react/jsx-runtime';async function w(t,e,o,n){let s={"Content-Type":"application/json",...o?.headers};n&&(s.Authorization=`Bearer ${n}`);let u=await fetch(`${t}${e}`,{...o,headers:s});if(!u.ok){let r=`HTTP ${u.status}`;try{let a=await u.json();a.error&&(r=a.error);}catch{}throw new Error(r)}return u.json()}function I(t){let e=t.indexOf(":");return {mode:t.slice(0,e),cid:t.slice(e+1)}}function x(t){let e=t.apiBaseUrl,o=t.authorMid,n=t.ownerMid,s=t.apiKey,u=t.stacknetUrl||t.apiBaseUrl;return useMemo(()=>({async listRepos(r){let a=r||n?`?owner=${encodeURIComponent(r||n)}`:"";return (await w(e,`/api/rack/repos${a}`,void 0,s)).repos||[]},async initRepo(r){return w(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...r,owner_mid:n})},s)},async push(r,a){return w(e,`/api/rack/${r}/push`,{method:"POST",body:JSON.stringify({...a,author_mid:o})},s)},async getTree(r,a="main"){let l=await w(e,`/api/rack/${r}/tree/${a}`,void 0,s);return {tree:l.tree,commit_cid:l.commit_cid}},async getBlob(r,a){return (await w(e,`/api/rack/${r}/blob/${a}`,void 0,s)).content},async getLog(r,a,l){let c=new URLSearchParams;a&&c.set("ref",a),l&&c.set("max_count",String(l));let d=c.toString()?`?${c}`:"";return (await w(e,`/api/rack/${r}/log${d}`,void 0,s)).commits||[]},async getBranches(r){return (await w(e,`/api/rack/${r}/branches`,void 0,s)).branches||[]},async createBranch(r,a,l){return w(e,`/api/rack/${r}/branch`,{method:"POST",body:JSON.stringify({branch_name:a,from_ref:l})},s)},async merge(r,a,l){return w(e,`/api/rack/${r}/merge`,{method:"POST",body:JSON.stringify({source_branch:a,target_branch:l})},s)},async getDiff(r,a,l){return (await w(e,`/api/rack/${r}/diff/${a}/${l}`,void 0,s)).diff?.entries||[]},async starRepo(r){return w(e,`/api/rack/${r}/star`,{method:"POST"},s)},async unstarRepo(r){return w(e,`/api/rack/${r}/star`,{method:"DELETE"},s)},async getStarInfo(r){return w(e,`/api/rack/${r}/stars`,void 0,s)},async getSkillStats(r){let a={meta:null,tokenCount:null,usageCount:null};try{let{tree:l}=await this.getTree(r,"main");if(!l?.entries)return a;if(l.entries["META.json"]){let f=I(l.entries["META.json"]).cid,m=await this.getBlob(r,f);a.meta=JSON.parse(m);}let c=0,d=Object.values(l.entries).map(async f=>{try{let m=I(f).cid,g=await this.getBlob(r,m);c+=g.length;}catch{}});await Promise.all(d),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(r){try{let a=await fetch(`${u}/v1/skills/${encodeURIComponent(r)}`);if(a.ok){let c=await a.json();return c.usage_count??c.usageCount??null}let l=await fetch(`${u}/v1/skills?scope=public`);if(l.ok){let d=((await l.json()).skills||[]).find(f=>f.name===r||f.id===r);if(d)return d.usage_count??d.usageCount??0}return 0}catch{return null}},async getTensorStats(r){let a={meta:null,sizeMB:null};try{let{tree:l}=await this.getTree(r,"main");if(!l?.entries)return a;if(l.entries["TENSOR_META.json"]){let c=I(l.entries["TENSOR_META.json"]).cid,d=await this.getBlob(r,c);a.meta=JSON.parse(d),a.sizeMB=a.meta?.tensor_size_mb??null;}}catch{}return a},async getNetworkStats(){try{return (await w(e,"/api/rack/stats",void 0,s)).stats||null}catch{return null}},async getTrending(r=5,a=1){try{return (await w(e,`/api/rack/trending?limit=${r}&days=${a}`,void 0,s)).trending||[]}catch{return []}}}),[e,o,n,s,u])}function A(t){let e=x(t),o=useRef(e);o.current=e;let[n,s]=useState([]),[u,r]=useState(true),[a,l]=useState(null),c=useRef(true),d=useRef(null),f=useCallback(async()=>{d.current?.abort();let m=new AbortController;d.current=m;try{c.current&&(r(!0),l(null));let g=await o.current.listRepos();c.current&&!m.signal.aborted&&s(g);}catch(g){c.current&&!m.signal.aborted&&l(g instanceof Error?g.message:"Failed to load repos");}finally{c.current&&!m.signal.aborted&&r(false);}},[]);return useEffect(()=>(c.current=true,f(),()=>{c.current=false,d.current?.abort();}),[f]),{repos:n,loading:u,error:a,refresh:f}}function Ee(t){return Object.entries(t).map(([e,o])=>{let n=o.indexOf(":"),s=n>0?o.slice(0,n):"100644",u=n>0?o.slice(n+1):o;return {path:e,mode:s,cid:u,isDir:s==="040000"}}).sort((e,o)=>e.isDir!==o.isDir?e.isDir?-1:1:e.path.localeCompare(o.path))}function U(t,e,o="main"){let n=x(t),[s,u]=useState([]),[r,a]=useState(false),[l,c]=useState(null),d=useRef(true),f=useCallback(async()=>{if(e)try{d.current&&(a(!0),c(null));let{tree:g}=await n.getTree(e,o);d.current&&u(Ee(g.entries));}catch(g){d.current&&c(g instanceof Error?g.message:"Failed to load tree");}finally{d.current&&a(false);}},[n,e,o]);useEffect(()=>(d.current=true,f(),()=>{d.current=false;}),[f]);let m=useCallback(async g=>{if(!e)throw new Error("No repo selected");return n.getBlob(e,g)},[n,e]);return {entries:s,loading:r,error:l,refresh:f,getFileContent:m}}function Me(t){let e=x(t),[o,n]=useState(false),[s,u]=useState(null),r=useRef(true);return useEffect(()=>(r.current=true,()=>{r.current=false;}),[]),{push:useCallback(async(l,c,d,f)=>{try{return r.current&&(n(!0),u(null)),await e.push(l,{files:c,message:d,branch:f})}catch(m){let g=m instanceof Error?m.message:"Push failed";return r.current&&u(g),null}finally{r.current&&n(false);}},[e]),pushing:o,error:s}}var j="stacknet-rack-apikey";function ze(t){let e=t.stacknetUrl||t.apiBaseUrl,[o,n]=useState({authenticated:false}),[s,u]=useState(null),[r,a]=useState(false),l=useCallback(m=>({"Content-Type":"application/json",...m||t.apiKey?{Authorization:`Bearer ${m||t.apiKey}`}:{}}),[t.apiKey]),c=useCallback(async m=>{a(true);try{let g=await fetch(`${e}/health`,{headers:l(m)});if(!g.ok)throw new Error(`Authentication failed: ${g.status}`);let p={authenticated:!0,apiKey:m,permission:m.startsWith("gk_")?"write":"read"};n(p);try{localStorage.setItem(j,m);}catch{}return p}catch(g){throw n({authenticated:false}),g}finally{a(false);}},[e,l]),d=useCallback(()=>{n({authenticated:false}),u(null);try{localStorage.removeItem(j);}catch{}},[]),f=useCallback(async()=>{let m=o.apiKey||t.apiKey;if(!m)return null;try{let g=await fetch(`${e}/network/usage`,{headers:l(m)});if(!g.ok)return null;let p=await g.json(),v={planAllocation:p.plan_allocation??p.planAllocation??0,inferenceUsed:p.inference_used??p.inferenceUsed??0,ledgerSpent:p.ledger_spent??p.ledgerSpent??0,totalUsed:p.total_used??p.totalUsed??0,remaining:p.remaining??0,percent:p.percent??0,exceeded:p.exceeded??!1};return u(v),v}catch{return null}},[o.apiKey,t.apiKey,e,l]);return useEffect(()=>{let m=t.apiKey;if(m){n({authenticated:true,apiKey:m,permission:m.startsWith("gk_")?"write":"read"});return}try{let g=localStorage.getItem(j);g&&n({authenticated:!0,apiKey:g,permission:g.startsWith("gk_")?"write":"read"});}catch{}},[t.apiKey]),{session:o,budget:s,loading:r,login:c,logout:d,refreshBudget:f}}var oe=1e3,ae=1e3,ie=100;function le(t,e){if(t==="skill"){let s=ie+Math.ceil(e/4);return {type:t,totalBytes:e,totalMegabytes:e/1e6,baseCost:s,multiplier:oe,registrationCostTokens:s*oe}}let o=Math.ceil(e/1e6),n=ie+o;return {type:t,totalBytes:e,totalMegabytes:o,baseCost:n,multiplier:ae,registrationCostTokens:n*ae}}function Le(t){let e=t.stacknetUrl||t.apiBaseUrl,o=t.apiKey,[n,s]=useState(false),[u,r]=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 d=>{s(true),r(null);try{let f=await fetch(`${e}/skills`,{method:"POST",headers:a(),body:JSON.stringify(d)});if(!f.ok){let m=await f.json().catch(()=>({error:`HTTP ${f.status}`}));throw new Error(m.error||`Registration failed: ${f.status}`)}return await f.json()}catch(f){throw r(f.message),f}finally{s(false);}},[e,a]),c=useCallback(async d=>{s(true),r(null);try{let f=await fetch(`${e}/tensors`,{method:"POST",headers:a(),body:JSON.stringify(d)});if(!f.ok){let m=await f.json().catch(()=>({error:`HTTP ${f.status}`}));throw new Error(m.error||`Registration failed: ${f.status}`)}return await f.json()}catch(f){throw r(f.message),f}finally{s(false);}},[e,a]);return {registerSkill:l,registerTensor:c,estimateCost:le,registering:n,error:u}}function Oe(t,e){let o=x(t),[n,s]=useState({meta:null,tokenCount:null,usageCount:null}),[u,r]=useState(false),[a,l]=useState(null),c=useRef(true),d=useCallback(async()=>{if(e){r(true),l(null);try{let f=await o.getSkillStats(e);c.current&&s(f);}catch(f){c.current&&l(f.message);}finally{c.current&&r(false);}}},[o,e]);return useEffect(()=>(c.current=true,d(),()=>{c.current=false;}),[d]),{stats:n,loading:u,error:a,refresh:d}}function He(t,e){let o=x(t),[n,s]=useState({meta:null,sizeMB:null}),[u,r]=useState(false),[a,l]=useState(null),c=useRef(true),d=useCallback(async()=>{if(e){r(true),l(null);try{let f=await o.getTensorStats(e);c.current&&s(f);}catch(f){c.current&&l(f.message);}finally{c.current&&r(false);}}},[o,e]);return useEffect(()=>(c.current=true,d(),()=>{c.current=false;}),[d]),{stats:n,loading:u,error:a,refresh:d}}function Ve(t){let e=x(t),[o,n]=useState(null),[s,u]=useState(false),[r,a]=useState(null),l=useRef(true),c=useCallback(async()=>{u(true),a(null);try{let d=await e.getNetworkStats();l.current&&n(d);}catch(d){l.current&&a(d.message);}finally{l.current&&u(false);}},[e]);return useEffect(()=>(l.current=true,c(),()=>{l.current=false;}),[c]),{stats:o,loading:s,error:r,refresh:c}}function Ye(t,e=5,o=1){let n=x(t),[s,u]=useState([]),[r,a]=useState(false),[l,c]=useState(null),d=useRef(true),f=useCallback(async m=>{a(true),c(null);try{let g=await n.getTrending(e,m??o);d.current&&u(g);}catch(g){d.current&&c(g.message);}finally{d.current&&a(false);}},[n,e,o]);return useEffect(()=>(d.current=true,f(),()=>{d.current=false;}),[f]),{repos:s,loading:r,error:l,refresh:f}}function et(t,e){let o=x(t),[n,s]=useState({stars:0,starred:false,repo_id:e||""}),[u,r]=useState(false),[a,l]=useState(null),c=useRef(true),d=useCallback(async()=>{if(e)try{let m=await o.getStarInfo(e);c.current&&s(m);}catch{}},[o,e]);useEffect(()=>(c.current=true,d(),()=>{c.current=false;}),[d]);let f=useCallback(async()=>{if(e){r(true),l(null);try{let m=n.starred?await o.unstarRepo(e):await o.starRepo(e);c.current&&s({stars:m.stars,starred:m.starred,repo_id:e});}catch(m){c.current&&l(m.message);}finally{c.current&&r(false);}}},[o,e,n.starred]);return {...n,loading:u,error:a,toggle:f,refresh:d}}function C(...t){return twMerge(clsx(t))}var nt=/^(https?:\/\/|mailto:|\/[^/])/i;function st(t){let e=t.trim();return nt.test(e)?e:null}function _(t){let e=[],o=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,n=0,s,u=0;for(;(s=o.exec(t))!==null;){s.index>n&&e.push(t.slice(n,s.index));let r=`i${u++}`;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)},r));else if(s[2])e.push(jsx("strong",{children:s[3]},r));else if(s[4])e.push(jsx("em",{children:s[5]},r));else if(s[6])e.push(jsx("em",{children:s[7]},r));else if(s[8]){let a=st(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]},r)):e.push(s[9]);}n=s.index+s[0].length;}return n<t.length&&e.push(t.slice(n)),e.length>0?e:[t]}function ot(t){let e=t.split(`
|
|
2
|
-
`),o=[],n=0;for(;n<e.length;){let
|
|
3
|
-
`),lang:
|
|
1
|
+
import {useMemo,useRef,useState,useCallback,useEffect}from'react';import {Loader2,FileText}from'lucide-react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsx,jsxs,Fragment}from'react/jsx-runtime';async function S(r,e,o,n){let a={"Content-Type":"application/json",...o?.headers};n&&(a.Authorization=`Bearer ${n}`);let c=await fetch(`${r}${e}`,{...o,headers:a});if(!c.ok){let t=`HTTP ${c.status}`;try{let s=await c.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return c.json()}function A(r){let e=r.indexOf(":");return {mode:r.slice(0,e),cid:r.slice(e+1)}}function R(r){let e=r.apiBaseUrl,o=r.authorMid,n=r.ownerMid,a=r.apiKey,c=r.stacknetUrl||r.apiBaseUrl;return useMemo(()=>({async listRepos(t,s){let i=new URLSearchParams;(t||n)&&i.set("owner",t||n),s?.limit&&i.set("limit",String(s.limit)),s?.cursor&&i.set("cursor",s.cursor);let u=i.toString()?`?${i}`:"",d=await S(e,`/api/rack/repos${u}`,void 0,a);return {items:d.repos||[],pagination:d.pagination||{total:(d.repos||[]).length,limit:50,has_more:false,next_cursor:null}}},async initRepo(t){return S(e,"/api/rack/init",{method:"POST",body:JSON.stringify({...t,owner_mid:n})},a)},async push(t,s){return S(e,`/api/rack/${t}/push`,{method:"POST",body:JSON.stringify({...s,author_mid:o})},a)},async getTree(t,s="main"){let i=await S(e,`/api/rack/${t}/tree/${s}`,void 0,a);return {tree:i.tree,commit_cid:i.commit_cid}},async getBlob(t,s){return (await S(e,`/api/rack/${t}/blob/${s}`,void 0,a)).content},async getLog(t,s,i){let u=new URLSearchParams;s&&u.set("ref",s),i&&u.set("max_count",String(i));let d=u.toString()?`?${u}`:"";return (await S(e,`/api/rack/${t}/log${d}`,void 0,a)).commits||[]},async getBranches(t){return (await S(e,`/api/rack/${t}/branches`,void 0,a)).branches||[]},async createBranch(t,s,i){return S(e,`/api/rack/${t}/branch`,{method:"POST",body:JSON.stringify({branch_name:s,from_ref:i})},a)},async merge(t,s,i){return S(e,`/api/rack/${t}/merge`,{method:"POST",body:JSON.stringify({source_branch:s,target_branch:i})},a)},async getDiff(t,s,i){return (await S(e,`/api/rack/${t}/diff/${s}/${i}`,void 0,a)).diff?.entries||[]},async starRepo(t){return S(e,`/api/rack/${t}/star`,{method:"POST"},a)},async unstarRepo(t){return S(e,`/api/rack/${t}/star`,{method:"DELETE"},a)},async getStarInfo(t){return S(e,`/api/rack/${t}/stars`,void 0,a)},async getSkillStats(t){let s={meta:null,tokenCount:null,usageCount:null};try{let{tree:i}=await this.getTree(t,"main");if(!i?.entries)return s;if(i.entries["META.json"]){let m=A(i.entries["META.json"]).cid,f=await this.getBlob(t,m);s.meta=JSON.parse(f);}let u=0,d=Object.values(i.entries).map(async m=>{try{let f=A(m).cid,g=await this.getBlob(t,f);u+=g.length;}catch{}});await Promise.all(d),u>0&&(s.tokenCount=Math.ceil(u/4)),s.meta?.skill_id&&(s.usageCount=await this.getSkillUsageCount(s.meta.skill_id));}catch{}return s},async getSkillUsageCount(t){try{let s=await fetch(`${c}/v1/skills/${encodeURIComponent(t)}`);if(s.ok){let u=await s.json();return u.usage_count??u.usageCount??null}let i=await fetch(`${c}/v1/skills?scope=public`);if(i.ok){let d=((await i.json()).skills||[]).find(m=>m.name===t||m.id===t);if(d)return d.usage_count??d.usageCount??0}return 0}catch{return null}},async getTensorStats(t){let s={meta:null,sizeMB:null};try{let{tree:i}=await this.getTree(t,"main");if(!i?.entries)return s;if(i.entries["TENSOR_META.json"]){let u=A(i.entries["TENSOR_META.json"]).cid,d=await this.getBlob(t,u);s.meta=JSON.parse(d),s.sizeMB=s.meta?.tensor_size_mb??null;}}catch{}return s},async getNetworkStats(){try{return (await S(e,"/api/rack/stats",void 0,a)).stats||null}catch{return null}},async getTrending(t=5,s=1,i){try{let u=new URLSearchParams({limit:String(t),days:String(s)});i&&u.set("cursor",i);let d=await S(e,`/api/rack/trending?${u}`,void 0,a);return {items:d.trending||[],pagination:d.pagination||{total:(d.trending||[]).length,limit:t,has_more:!1,next_cursor:null}}}catch{return {items:[],pagination:{total:0,limit:t,has_more:false,next_cursor:null}}}}}),[e,o,n,a,c])}function Be(r){let e=R(r),o=useRef(e);o.current=e;let[n,a]=useState([]),[c,t]=useState(true),[s,i]=useState(null),u=useRef(true),d=useRef(null),m=useCallback(async()=>{d.current?.abort();let f=new AbortController;d.current=f;try{u.current&&(t(!0),i(null));let g=await o.current.listRepos();u.current&&!f.signal.aborted&&a(g.items);}catch(g){u.current&&!f.signal.aborted&&i(g instanceof Error?g.message:"Failed to load repos");}finally{u.current&&!f.signal.aborted&&t(false);}},[]);return useEffect(()=>(u.current=true,m(),()=>{u.current=false,d.current?.abort();}),[m]),{repos:n,loading:c,error:s,refresh:m}}function Oe(r){return Object.entries(r).map(([e,o])=>{let n=o.indexOf(":"),a=n>0?o.slice(0,n):"100644",c=n>0?o.slice(n+1):o;return {path:e,mode:a,cid:c,isDir:a==="040000"}}).sort((e,o)=>e.isDir!==o.isDir?e.isDir?-1:1:e.path.localeCompare(o.path))}function F(r,e,o="main"){let n=R(r),[a,c]=useState([]),[t,s]=useState(false),[i,u]=useState(null),d=useRef(true),m=useCallback(async()=>{if(e)try{d.current&&(s(!0),u(null));let{tree:g}=await n.getTree(e,o);d.current&&c(Oe(g.entries));}catch(g){d.current&&u(g instanceof Error?g.message:"Failed to load tree");}finally{d.current&&s(false);}},[n,e,o]);useEffect(()=>(d.current=true,m(),()=>{d.current=false;}),[m]);let f=useCallback(async g=>{if(!e)throw new Error("No repo selected");return n.getBlob(e,g)},[n,e]);return {entries:a,loading:t,error:i,refresh:m,getFileContent:f}}function He(r){let e=R(r),[o,n]=useState(false),[a,c]=useState(null),t=useRef(true);return useEffect(()=>(t.current=true,()=>{t.current=false;}),[]),{push:useCallback(async(i,u,d,m)=>{try{return t.current&&(n(!0),c(null)),await e.push(i,{files:u,message:d,branch:m})}catch(f){let g=f instanceof Error?f.message:"Push failed";return t.current&&c(g),null}finally{t.current&&n(false);}},[e]),pushing:o,error:a}}function K(r,e={}){let{pageSize:o=50,owner:n}=e,a=R(r),[c,t]=useState([]),[s,i]=useState(null),[u,d]=useState(false),[m,f]=useState(null),g=useRef(null),p=useRef(true),w=useCallback(async(v,E=false)=>{d(true),f(null);try{let N=await a.listRepos(n,{limit:o,cursor:v||void 0});p.current&&(t(_=>E?[..._,...N.items]:N.items),i(N.pagination),g.current=N.pagination.next_cursor);}catch(N){p.current&&f(N.message);}finally{p.current&&d(false);}},[a,n,o]),k=useCallback(async()=>{!g.current||u||await w(g.current,true);},[w,u]),h=useCallback(async()=>{g.current=null,await w(void 0,false);},[w]);return useEffect(()=>(p.current=true,w(),()=>{p.current=false;}),[w]),{repos:c,hasMore:s?.has_more??false,total:s?.total??0,loading:u,error:m,loadMore:k,reset:h,pagination:s}}var J="stacknet-rack-apikey";function Je(r){let e=r.stacknetUrl||r.apiBaseUrl,[o,n]=useState({authenticated:false}),[a,c]=useState(null),[t,s]=useState(false),i=useCallback(f=>({"Content-Type":"application/json",...f||r.apiKey?{Authorization:`Bearer ${f||r.apiKey}`}:{}}),[r.apiKey]),u=useCallback(async f=>{s(true);try{let g=await fetch(`${e}/health`,{headers:i(f)});if(!g.ok)throw new Error(`Authentication failed: ${g.status}`);let p={authenticated:!0,apiKey:f,permission:f.startsWith("gk_")?"write":"read"};n(p);try{localStorage.setItem(J,f);}catch{}return p}catch(g){throw n({authenticated:false}),g}finally{s(false);}},[e,i]),d=useCallback(()=>{n({authenticated:false}),c(null);try{localStorage.removeItem(J);}catch{}},[]),m=useCallback(async()=>{let f=o.apiKey||r.apiKey;if(!f)return null;try{let g=await fetch(`${e}/network/usage`,{headers:i(f)});if(!g.ok)return null;let p=await g.json(),w={planAllocation:p.plan_allocation??p.planAllocation??0,inferenceUsed:p.inference_used??p.inferenceUsed??0,ledgerSpent:p.ledger_spent??p.ledgerSpent??0,totalUsed:p.total_used??p.totalUsed??0,remaining:p.remaining??0,percent:p.percent??0,exceeded:p.exceeded??!1};return c(w),w}catch{return null}},[o.apiKey,r.apiKey,e,i]);return useEffect(()=>{let f=r.apiKey;if(f){n({authenticated:true,apiKey:f,permission:f.startsWith("gk_")?"write":"read"});return}try{let g=localStorage.getItem(J);g&&n({authenticated:!0,apiKey:g,permission:g.startsWith("gk_")?"write":"read"});}catch{}},[r.apiKey]),{session:o,budget:a,loading:t,login:u,logout:d,refreshBudget:m}}var fe=1e3,me=1e3,ge=100;function pe(r,e){if(r==="skill"){let a=ge+Math.ceil(e/4);return {type:r,totalBytes:e,totalMegabytes:e/1e6,baseCost:a,multiplier:fe,registrationCostTokens:a*fe}}let o=Math.ceil(e/1e6),n=ge+o;return {type:r,totalBytes:e,totalMegabytes:o,baseCost:n,multiplier:me,registrationCostTokens:n*me}}function Ve(r){let e=r.stacknetUrl||r.apiBaseUrl,o=r.apiKey,[n,a]=useState(false),[c,t]=useState(null),s=useCallback(()=>{if(!o)throw new Error("API key required for registration. Call login() first.");return {"Content-Type":"application/json",Authorization:`Bearer ${o}`}},[o]),i=useCallback(async d=>{a(true),t(null);try{let m=await fetch(`${e}/skills`,{method:"POST",headers:s(),body:JSON.stringify(d)});if(!m.ok){let f=await m.json().catch(()=>({error:`HTTP ${m.status}`}));throw new Error(f.error||`Registration failed: ${m.status}`)}return await m.json()}catch(m){throw t(m.message),m}finally{a(false);}},[e,s]),u=useCallback(async d=>{a(true),t(null);try{let m=await fetch(`${e}/tensors`,{method:"POST",headers:s(),body:JSON.stringify(d)});if(!m.ok){let f=await m.json().catch(()=>({error:`HTTP ${m.status}`}));throw new Error(f.error||`Registration failed: ${m.status}`)}return await m.json()}catch(m){throw t(m.message),m}finally{a(false);}},[e,s]);return {registerSkill:i,registerTensor:u,estimateCost:pe,registering:n,error:c}}function Ye(r,e){let o=R(r),[n,a]=useState({meta:null,tokenCount:null,usageCount:null}),[c,t]=useState(false),[s,i]=useState(null),u=useRef(true),d=useCallback(async()=>{if(e){t(true),i(null);try{let m=await o.getSkillStats(e);u.current&&a(m);}catch(m){u.current&&i(m.message);}finally{u.current&&t(false);}}},[o,e]);return useEffect(()=>(u.current=true,d(),()=>{u.current=false;}),[d]),{stats:n,loading:c,error:s,refresh:d}}function tt(r,e){let o=R(r),[n,a]=useState({meta:null,sizeMB:null}),[c,t]=useState(false),[s,i]=useState(null),u=useRef(true),d=useCallback(async()=>{if(e){t(true),i(null);try{let m=await o.getTensorStats(e);u.current&&a(m);}catch(m){u.current&&i(m.message);}finally{u.current&&t(false);}}},[o,e]);return useEffect(()=>(u.current=true,d(),()=>{u.current=false;}),[d]),{stats:n,loading:c,error:s,refresh:d}}function ot(r){let e=R(r),[o,n]=useState(null),[a,c]=useState(false),[t,s]=useState(null),i=useRef(true),u=useCallback(async()=>{c(true),s(null);try{let d=await e.getNetworkStats();i.current&&n(d);}catch(d){i.current&&s(d.message);}finally{i.current&&c(false);}},[e]);return useEffect(()=>(i.current=true,u(),()=>{i.current=false;}),[u]),{stats:o,loading:a,error:t,refresh:u}}function it(r,e=5,o=1){let n=R(r),[a,c]=useState([]),[t,s]=useState(null),[i,u]=useState(false),[d,m]=useState(null),f=useRef(true),g=useRef(null),p=useCallback(async k=>{u(true),m(null),g.current=null;try{let h=await n.getTrending(e,k??o);f.current&&(c(h.items),s(h.pagination),g.current=h.pagination.next_cursor);}catch(h){f.current&&m(h.message);}finally{f.current&&u(false);}},[n,e,o]),w=useCallback(async()=>{if(!(!g.current||i)){u(true);try{let k=await n.getTrending(e,o,g.current);f.current&&(c(h=>[...h,...k.items]),s(k.pagination),g.current=k.pagination.next_cursor);}catch(k){f.current&&m(k.message);}finally{f.current&&u(false);}}},[n,e,o,i]);return useEffect(()=>(f.current=true,p(),()=>{f.current=false;}),[p]),{repos:a,hasMore:t?.has_more??false,total:t?.total??0,loading:i,error:d,refresh:p,loadMore:w}}function ut(r,e){let o=R(r),[n,a]=useState({stars:0,starred:false,repo_id:e||""}),[c,t]=useState(false),[s,i]=useState(null),u=useRef(true),d=useCallback(async()=>{if(e)try{let f=await o.getStarInfo(e);u.current&&a(f);}catch{}},[o,e]);useEffect(()=>(u.current=true,d(),()=>{u.current=false;}),[d]);let m=useCallback(async()=>{if(e){t(true),i(null);try{let f=n.starred?await o.unstarRepo(e):await o.starRepo(e);u.current&&a({stars:f.stars,starred:f.starred,repo_id:e});}catch(f){u.current&&i(f.message);}finally{u.current&&t(false);}}},[o,e,n.starred]);return {...n,loading:c,error:s,toggle:m,refresh:d}}function T(...r){return twMerge(clsx(r))}var mt=/^(https?:\/\/|mailto:|\/[^/])/i;function gt(r){let e=r.trim();return mt.test(e)?e:null}function B(r){let e=[],o=/(`[^`]+`)|(\*\*(.+?)\*\*)|(\*(.+?)\*)|(_(.+?)_)|(\[([^\]]+)\]\(([^)]+)\))/g,n=0,a,c=0;for(;(a=o.exec(r))!==null;){a.index>n&&e.push(r.slice(n,a.index));let t=`i${c++}`;if(a[1])e.push(jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 text-[0.85em] font-mono text-pink-400",children:a[1].slice(1,-1)},t));else if(a[2])e.push(jsx("strong",{children:a[3]},t));else if(a[4])e.push(jsx("em",{children:a[5]},t));else if(a[6])e.push(jsx("em",{children:a[7]},t));else if(a[8]){let s=gt(a[10]);s?e.push(jsx("a",{href:s,className:"text-blue-400 underline hover:text-blue-300",target:"_blank",rel:"noopener noreferrer",children:a[9]},t)):e.push(a[9]);}n=a.index+a[0].length;}return n<r.length&&e.push(r.slice(n)),e.length>0?e:[r]}function pt(r){let e=r.split(`
|
|
2
|
+
`),o=[],n=0;for(;n<e.length;){let a=e[n];if(a.trim()===""){n++;continue}if(/^(-{3,}|\*{3,}|_{3,})$/.test(a.trim())){o.push({type:"hr"}),n++;continue}let c=a.match(/^(#{1,6})\s+(.+)/);if(c){o.push({type:"heading",level:c[1].length,content:c[2]}),n++;continue}if(a.trim().startsWith("```")){let s=a.trim().slice(3).trim(),i=[];for(n++;n<e.length&&!e[n].trim().startsWith("```");)i.push(e[n]),n++;o.push({type:"code",content:i.join(`
|
|
3
|
+
`),lang:s||void 0}),n++;continue}if(/^\s*[-*+]\s/.test(a)){let s=[];for(;n<e.length&&/^\s*[-*+]\s/.test(e[n]);)s.push(e[n].replace(/^\s*[-*+]\s+/,"")),n++;o.push({type:"ul",items:s});continue}if(/^\s*\d+[.)]\s/.test(a)){let s=[];for(;n<e.length&&/^\s*\d+[.)]\s/.test(e[n]);)s.push(e[n].replace(/^\s*\d+[.)]\s+/,"")),n++;o.push({type:"ol",items:s});continue}let t=[];for(;n<e.length&&e[n].trim()!==""&&!e[n].match(/^#{1,6}\s/)&&!e[n].trim().startsWith("```")&&!/^\s*[-*+]\s/.test(e[n])&&!/^\s*\d+[.)]\s/.test(e[n]);)t.push(e[n]),n++;t.length>0&&o.push({type:"paragraph",content:t.join(" ")});}return o}var ht={1:"text-2xl font-bold mt-6 mb-3",2:"text-xl font-bold mt-5 mb-2",3:"text-lg font-semibold mt-4 mb-2",4:"text-base font-semibold mt-3 mb-1",5:"text-sm font-semibold mt-2 mb-1",6:"text-sm font-medium mt-2 mb-1"};function yt(r,e){switch(r.type){case "hr":return jsx("hr",{className:"my-4 border-border"},`b${e}`);case "heading":{let o=Math.min(Math.max(r.level||1,1),6),n=`h${o}`;return jsx(n,{className:T("text-foreground",ht[o]),children:B(r.content||"")},`b${e}`)}case "paragraph":return jsx("p",{className:"mb-3 leading-relaxed text-foreground",children:B(r.content||"")},`b${e}`);case "code":return jsx("pre",{className:"mb-3 overflow-x-auto rounded-lg bg-muted p-4 text-sm font-mono leading-relaxed text-foreground",children:jsx("code",{children:r.content})},`b${e}`);case "ul":return jsx("ul",{className:"mb-3 ml-5 list-disc space-y-1 text-foreground",children:r.items?.map((o,n)=>jsx("li",{className:"leading-relaxed",children:B(o)},`li${e}-${n}`))},`b${e}`);case "ol":return jsx("ol",{className:"mb-3 ml-5 list-decimal space-y-1 text-foreground",children:r.items?.map((o,n)=>jsx("li",{className:"leading-relaxed",children:B(o)},`li${e}-${n}`))},`b${e}`);default:return null}}function Q({content:r,className:e}){let o=pt(r);return jsx("div",{className:T("text-sm",e),children:o.map((n,a)=>yt(n,a))})}function Re({open:r,className:e}){return jsx("svg",{width:"16",height:"16",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:T("shrink-0 transition-transform duration-150",r?"rotate-0":"-rotate-90",e),children:jsx("path",{d:"M16.134 6.16a.5.5 0 1 1 .732.68l-6.5 7-.077.068a.5.5 0 0 1-.655-.068l-6.5-7-.062-.08a.5.5 0 0 1 .718-.667l.076.067L10 12.767z"})})}function xe({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M8.5 2a6.5 6.5 0 0 1 4.935 10.728l4.419 4.419.064.078a.5.5 0 0 1-.693.693l-.079-.064-4.419-4.42A6.5 6.5 0 1 1 8.5 2m0 1a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11"})})}function X({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M15.147 4.146a.5.5 0 0 1 .707.707L10.707 10l5.147 5.147a.5.5 0 0 1-.63.771l-.078-.064L10 10.707l-5.146 5.147a.5.5 0 0 1-.708-.707L9.293 10 4.146 4.853a.5.5 0 0 1 .708-.707L10 9.293z"})})}function ve({size:r=20,className:e}){return jsx("svg",{width:r,height:r,viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:e,children:jsx("path",{d:"M10 3a.5.5 0 0 1 .5.5v6h6l.1.01a.5.5 0 0 1 0 .98l-.1.01h-6v6a.5.5 0 0 1-1 0v-6h-6a.5.5 0 0 1 0-1h6v-6A.5.5 0 0 1 10 3"})})}function wt(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M6.5 3A2.5 2.5 0 0 0 4 5.5v9A2.5 2.5 0 0 0 6.5 17h7a2.5 2.5 0 0 0 2.5-2.5v-7A2.5 2.5 0 0 0 13.5 5H11V3.5a.5.5 0 0 0-1 0V5H6.5ZM5 5.5A1.5 1.5 0 0 1 6.5 4H9v1H6.5A1.5 1.5 0 0 0 5 6.5v8A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 13.5 6H11V4h2.5A2.5 2.5 0 0 1 16 6.5v8a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-9Z"})})}function bt(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M5.5 3A2.5 2.5 0 0 0 3 5.5v9A2.5 2.5 0 0 0 5.5 17h9a2.5 2.5 0 0 0 2.5-2.5v-9A2.5 2.5 0 0 0 14.5 3h-9ZM4 5.5A1.5 1.5 0 0 1 5.5 4h9A1.5 1.5 0 0 1 16 5.5v9a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 4 14.5v-9ZM7 7.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5Z"})})}function Rt(){return jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M10 2a.5.5 0 0 1 .354.146l3 3a.5.5 0 0 1-.708.708L10.5 3.707V12.5a.5.5 0 0 1-1 0V3.707L7.354 5.854a.5.5 0 1 1-.708-.708l3-3A.5.5 0 0 1 10 2ZM4 13.5a.5.5 0 0 1 1 0v1A1.5 1.5 0 0 0 6.5 16h7a1.5 1.5 0 0 0 1.5-1.5v-1a.5.5 0 0 1 1 0v1a2.5 2.5 0 0 1-2.5 2.5h-7A2.5 2.5 0 0 1 4 14.5v-1Z"})})}function Se(){let[r,e]=useState(false);return useEffect(()=>{if(typeof window>"u")return;let o=()=>e(window.innerWidth<768);return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),r}function Ce({onClose:r,children:e,title:o}){let n=Se(),a=useRef(r);return a.current=r,useEffect(()=>{let c=t=>{t.key==="Escape"&&a.current();};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[]),n?jsxs("div",{className:"fixed inset-0 z-50 flex items-end justify-center",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full max-h-[90vh] overflow-y-auto rounded-t-2xl bg-[#1a1a1a] p-5 pb-8 animate-in slide-in-from-bottom duration-200",onClick:c=>c.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-4 h-1 w-10 rounded-full bg-zinc-600"}),jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsx("h2",{className:"text-lg font-semibold text-foreground",children:o}),jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(X,{size:20})})]}),e]})]}):jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full max-w-lg overflow-y-auto rounded-2xl bg-[#1a1a1a] p-6 shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:c=>c.stopPropagation(),children:[jsxs("div",{className:"flex items-center justify-between mb-5",children:[jsx("h2",{className:"text-lg font-semibold text-foreground",children:o}),jsx("button",{onClick:r,className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(X,{size:20})})]}),e]})]})}function vt(r){let e=r.split(`
|
|
4
|
+
`),o="",n="",c=false;for(let t=0;t<e.length;t++){let s=e[t].trim();if(t===0&&s==="---"){c=true;continue}if(c){s==="---"&&(c=false,true);continue}if(!o){let i=s.match(/^#{1,2}\s+(.+)/);if(i){o=i[1].trim();continue}}if(o&&!n){if(!s||s.startsWith("#")||s==="---"||s==="***"||s==="___")continue;n=s.replace(/\*\*/g,"").replace(/`/g,"").trim();break}}return o?{title:o,description:n}:null}function St({onClose:r,onCreated:e,config:o}){let[n,a]=useState(""),[c,t]=useState(""),[s,i]=useState(""),[u,d]=useState(false),[m,f]=useState(null),[g,p]=useState(false),w=h=>{if(i(h),!n.trim()&&!c.trim()&&h.trim().length>10){let v=vt(h);v&&(a(v.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")),t(v.description),p(true));}};return jsx(Ce,{title:"Write skill instructions",onClose:r,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-name",className:"text-sm text-muted-foreground",children:"Skill name"}),jsx("input",{id:"skill-name",value:n,onChange:h=>a(h.target.value),placeholder:"weekly-status-report",className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-desc",className:"text-sm text-muted-foreground",children:"Description"}),jsx("textarea",{id:"skill-desc",value:c,onChange:h=>t(h.target.value),placeholder:"Generate weekly status reports from recent work.",rows:3,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),jsxs("div",{className:"space-y-1.5",children:[jsx("label",{htmlFor:"skill-instructions",className:"text-sm text-muted-foreground",children:"Instructions"}),jsx("textarea",{id:"skill-instructions",value:s,onChange:h=>w(h.target.value),placeholder:"Summarize my recent work in three sections: wins, blockers, and next steps.",rows:8,className:"w-full rounded-lg border border-zinc-700 bg-[#252525] px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-zinc-500"})]}),m&&jsx("p",{className:"text-sm text-red-500",children:m}),jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[jsx("button",{onClick:r,className:"rounded-lg border border-zinc-700 px-4 py-2 text-sm text-foreground hover:bg-zinc-800",children:"Cancel"}),jsx("button",{onClick:async()=>{if(n.trim()){d(true),f(null);try{let h=o.apiBaseUrl||"",v=g?s.trim():`# ${n.trim()}
|
|
4
5
|
|
|
5
|
-
${
|
|
6
|
+
${c.trim()}
|
|
6
7
|
|
|
7
8
|
---
|
|
8
9
|
|
|
9
|
-
${a.trim()}`,S=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n.trim(),description:u.trim(),skill_md:v,content_type:"code"})});if(!S.ok){let T=`Failed to register skill (${S.status})`;try{let R=await S.json();R.error&&(T=R.error);}catch{}throw new Error(T)}e?.(),t();}catch(p){m(p instanceof Error?p.message:"Failed to create skill");}finally{d(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 gt({onClose:t,onCreated:e,config:o}){let n=useRef(null),[s,u]=useState(false),[r,a]=useState(false),[l,c]=useState(null),d=async m=>{a(true),c(null);try{let g=await m.text(),p=o.apiBaseUrl||"",v=m.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),S=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:v,skill_md:g,content_type:"code"})});if(!S.ok){let T=`Failed to register skill (${S.status})`;try{let R=await S.json();R.error&&(T=R.error);}catch{}throw new Error(T)}e?.(),t();}catch(g){c(g instanceof Error?g.message:"Upload failed");}finally{a(false);}};return jsx(he,{title:"Upload skill",onClose:t,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{onDragOver:m=>{m.preventDefault(),u(true);},onDragLeave:()=>u(false),onDrop:m=>{m.preventDefault(),u(false);let g=m.dataTransfer.files[0];g&&d(g);},onClick:()=>n.current?.click(),className:C("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",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(ge,{size:20,className:"text-muted-foreground"})}),jsx("p",{className:"text-sm text-muted-foreground",children:r?"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:m=>{let g=m.target.files?.[0];g&&d(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 pt({onClose:t,onSelect:e}){let o=pe(),n=useRef(null),s=useRef(t);s.current=t,useEffect(()=>{if(o)return;let r=a=>{n.current&&a.target instanceof Node&&!n.current.contains(a.target)&&s.current();};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[o]);let u=[{id:"create-with-geoff",icon:jsx(ut,{}),label:"Create with Geoff"},{id:"write",icon:jsx(dt,{}),label:"Write skill instructions"},{id:"upload",icon:jsx(ft,{}),label:"Upload a skill"}];return o?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:r=>r.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),u.map(r=>jsxs("button",{onClick:()=>{e(r.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:[r.icon,r.label]},r.id))]})]}):jsx("div",{ref:n,className:"absolute right-2 top-11 z-50 w-56 overflow-hidden rounded-xl border border-zinc-700 bg-[#2a2a2a] shadow-xl animate-in fade-in zoom-in-95 duration-100",children:u.map(r=>jsxs("button",{onClick:()=>{e(r.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:[r.icon,r.label]},r.id))})}function ht({entry:t,selected:e,onSelect:o,depth:n=0}){return jsxs("button",{onClick:()=>o(t),className:C("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+n*16}px`},children:[jsx("span",{className:"truncate flex-1",children:t.path.split("/").pop()}),t.isDir&&jsx(me,{className:"ml-auto text-muted-foreground"})]})}function yt({repo:t,selected:e,expanded:o,onSelect:n,onToggle:s,children:u}){return jsxs("div",{children:[jsxs("button",{onClick:()=>{n(),s();},className:C("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsx(me,{open:o}),jsx(FileText,{className:"h-4 w-4 shrink-0"}),jsx("span",{className:"truncate",children:t.name})]}),o&&u]})}function kt({entry:t,content:e,loading:o,repoName:n}){let[s,u]=useState(false),r=useRef(null);useEffect(()=>()=>{r.current&&clearTimeout(r.current);},[]);let[a,l]=useState(false),c=async()=>{if(e)try{await navigator.clipboard.writeText(e),u(!0),l(!1),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>u(!1),2e3);}catch{l(true),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>l(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(o)return jsx("div",{className:"flex h-full items-center justify-center",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let d=t.path.split("/").pop()||t.path,f=/\.(md|mdx)$/i.test(d);return jsxs("div",{className:"flex h-full flex-col px-3",children:[jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[jsx("h3",{className:"text-sm sm:text-lg font-semibold text-foreground",children:d}),jsx("button",{onClick:c,"aria-label":"Copy file content",className:C("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:f?jsx(V,{content:e||""}):jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function xt({config:t,category:e,className:o,style:n}){let{repos:s,loading:u,error:r,refresh:a}=A(t),[l,c]=useState(null),[d,f]=useState(null),[m,g]=useState(null),[p,v]=useState(null),[S,T]=useState(false),[R,q]=useState(""),[ye,G]=useState(false),[Y,Q]=useState(false),[X,M]=useState(null),ke=s.find(y=>y.repo_id===l),{entries:xe,getFileContent:ee}=U(t,d),te=s.filter(y=>!R||y.name.toLowerCase().includes(R.toLowerCase())),we=useCallback(async y=>{if(!y.isDir){g(y),T(true);try{let N=await ee(y.cid);v(N);}catch(N){let ve=N instanceof Error?N.message:"Unknown error";v(`Failed to load file: ${ve}`);}finally{T(false);}}},[ee]);useEffect(()=>{s.length>0&&!l&&(c(s[0].repo_id),f(s[0].repo_id));},[s,l]);let be=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"):M(y);};return jsxs("div",{className:C("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:ye?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(ue,{size:16,className:"shrink-0 text-muted-foreground"}),jsx("input",{type:"text",value:R,onChange:y=>q(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:()=>{G(false),q("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(Z,{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:()=>G(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsx(ue,{size:20})}),jsx("button",{onClick:()=>Q(!Y),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(ge,{size:20})})]})}),Y&&jsx(pt,{onClose:()=>Q(false),onSelect:be}),jsx("div",{className:"flex-1 overflow-y-auto p-2",children:u?jsx("div",{className:"flex items-center justify-center py-8",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):r?jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:r}):te.length===0?jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:R?"No matching items":"No items yet"}):jsx("div",{className:"space-y-0.5",children:te.map(y=>jsx(yt,{repo:y,selected:l===y.repo_id,expanded:d===y.repo_id,onSelect:()=>{c(y.repo_id),g(null),v(null);},onToggle:()=>f(d===y.repo_id?null:y.repo_id),children:jsx("div",{className:"ml-10 pl-1",children:xe.map(N=>jsx(ht,{entry:N,selected:m?.path===N.path,onSelect:we,depth:N.path.split("/").length-1},N.path))})},y.repo_id))})})]}),jsx("div",{className:"flex-1 min-w-0",children:jsx(kt,{entry:m,content:p,loading:S,repoName:ke?.name||""})}),X==="write"&&jsx(mt,{config:t,onClose:()=>M(null),onCreated:a}),X==="upload"&&jsx(gt,{config:t,onClose:()=>M(null),onCreated:a})]})}
|
|
10
|
-
export{
|
|
10
|
+
${s.trim()}`,E=await fetch(`${h}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n.trim(),description:c.trim(),skill_md:v,content_type:"code"})});if(!E.ok){let N=`Failed to register skill (${E.status})`;try{let _=await E.json();_.error&&(N=_.error);}catch{}throw new Error(N)}e?.(),r();}catch(h){f(h instanceof Error?h.message:"Failed to create skill");}finally{d(false);}}},disabled:u||!n.trim(),className:"rounded-lg bg-zinc-600 px-4 py-2 text-sm font-medium text-white hover:bg-zinc-500 disabled:opacity-50",children:u?"Creating...":"Create"})]})]})})}function Ct({onClose:r,onCreated:e,config:o}){let n=useRef(null),[a,c]=useState(false),[t,s]=useState(false),[i,u]=useState(null),d=async f=>{s(true),u(null);try{let g=await f.text(),p=o.apiBaseUrl||"",w=f.name.replace(/\.[^.]+$/,"").replace(/[^a-zA-Z0-9-_]/g,"-"),k=await fetch(`${p}/api/skills`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:w,skill_md:g,content_type:"code"})});if(!k.ok){let h=`Failed to register skill (${k.status})`;try{let v=await k.json();v.error&&(h=v.error);}catch{}throw new Error(h)}e?.(),r();}catch(g){u(g instanceof Error?g.message:"Upload failed");}finally{s(false);}};return jsx(Ce,{title:"Upload skill",onClose:r,children:jsxs("div",{className:"space-y-4",children:[jsxs("div",{onDragOver:f=>{f.preventDefault(),c(true);},onDragLeave:()=>c(false),onDrop:f=>{f.preventDefault(),c(false);let g=f.dataTransfer.files[0];g&&d(g);},onClick:()=>n.current?.click(),className:T("flex cursor-pointer flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed p-10 transition-colors",a?"border-zinc-400 bg-zinc-800/50":"border-zinc-700 hover:border-zinc-500"),children:[jsx("div",{className:"rounded-lg border border-zinc-600 p-2",children:jsx(ve,{size:20,className:"text-muted-foreground"})}),jsx("p",{className:"text-sm text-muted-foreground",children:t?"Uploading...":"Drag and drop or click to upload"})]}),jsx("input",{ref:n,type:"file",accept:".md,.zip,.skill,.txt,.yml,.yaml",className:"hidden","aria-label":"Upload skill file",onChange:f=>{let g=f.target.files?.[0];g&&d(g);}}),i&&jsx("p",{className:"text-sm text-red-500",children:i}),jsxs("div",{className:"space-y-2 text-xs text-muted-foreground",children:[jsx("p",{className:"font-medium text-foreground/70",children:"File requirements"}),jsxs("ul",{className:"list-disc pl-5 space-y-1",children:[jsx("li",{children:".md file must contain skill name and description formatted in YAML"}),jsx("li",{children:".zip or .skill file must include a SKILL.md file"})]})]})]})})}function Nt({onClose:r,onSelect:e}){let o=Se(),n=useRef(null),a=useRef(r);a.current=r,useEffect(()=>{if(o)return;let t=s=>{n.current&&s.target instanceof Node&&!n.current.contains(s.target)&&a.current();};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[o]);let c=[{id:"create-with-geoff",icon:jsx(wt,{}),label:"Create with Geoff"},{id:"write",icon:jsx(bt,{}),label:"Write skill instructions"},{id:"upload",icon:jsx(Rt,{}),label:"Upload a skill"}];return o?jsxs("div",{className:"fixed inset-0 z-50 flex items-end",onClick:r,children:[jsx("div",{className:"fixed inset-0 bg-black/50"}),jsxs("div",{className:"relative z-10 w-full rounded-t-2xl bg-[#1a1a1a] p-4 pb-8 animate-in slide-in-from-bottom duration-200",onClick:t=>t.stopPropagation(),children:[jsx("div",{className:"mx-auto mb-3 h-1 w-10 rounded-full bg-zinc-600"}),c.map(t=>jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 rounded-lg px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-800",children:[t.icon,t.label]},t.id))]})]}):jsx("div",{ref:n,className:"absolute right-2 top-11 z-50 w-56 overflow-hidden rounded-xl border border-zinc-700 bg-[#2a2a2a] shadow-xl animate-in fade-in zoom-in-95 duration-100",children:c.map(t=>jsxs("button",{onClick:()=>{e(t.id),r();},className:"flex w-full items-center gap-3 px-4 py-3 text-sm text-foreground transition-colors hover:bg-zinc-700/50",children:[t.icon,t.label]},t.id))})}function Tt({entry:r,selected:e,onSelect:o,depth:n=0}){return jsxs("button",{onClick:()=>o(r),className:T("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),style:{paddingLeft:`${8+n*16}px`},children:[jsx("span",{className:"truncate flex-1",children:r.path.split("/").pop()}),r.isDir&&jsx(Re,{className:"ml-auto text-muted-foreground"})]})}function Pt({repo:r,selected:e,expanded:o,onSelect:n,onToggle:a,children:c}){return jsxs("div",{children:[jsxs("button",{onClick:()=>{n(),a();},className:T("flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium transition-colors",e?"bg-[#141414] text-foreground":"text-muted-foreground hover:bg-muted/50 hover:text-foreground"),children:[jsx(Re,{open:o}),jsx(FileText,{className:"h-4 w-4 shrink-0"}),jsx("span",{className:"truncate",children:r.name})]}),o&&c]})}function Et({entry:r,content:e,loading:o,repoName:n}){let[a,c]=useState(false),t=useRef(null);useEffect(()=>()=>{t.current&&clearTimeout(t.current);},[]);let[s,i]=useState(false),u=async()=>{if(e)try{await navigator.clipboard.writeText(e),c(!0),i(!1),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>c(!1),2e3);}catch{i(true),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>i(false),2e3);}};if(!r)return jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a file to view its content"});if(o)return jsx("div",{className:"flex h-full items-center justify-center",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})});let d=r.path.split("/").pop()||r.path,m=/\.(md|mdx)$/i.test(d);return jsxs("div",{className:"flex h-full flex-col px-3",children:[jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[jsx("h3",{className:"text-sm sm:text-lg font-semibold text-foreground",children:d}),jsx("button",{onClick:u,"aria-label":"Copy file content",className:T("rounded p-1 transition-colors",a?"text-green-500":s?"text-red-500":"text-muted-foreground hover:text-foreground"),children:jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",className:"shrink-0",children:jsx("path",{d:"M12.5 3A1.5 1.5 0 0 1 14 4.5V6h1.5A1.5 1.5 0 0 1 17 7.5v8a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 6 15.5V14H4.5A1.5 1.5 0 0 1 3 12.5v-8A1.5 1.5 0 0 1 4.5 3zm1.5 9.5a1.5 1.5 0 0 1-1.5 1.5H7v1.5a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5H14zM4.5 4a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5z"})})})]}),jsx("div",{className:"flex-1 overflow-auto p-4",children:m?jsx(Q,{content:e||""}):jsx("pre",{className:"whitespace-pre-wrap text-sm text-foreground font-mono leading-relaxed",children:e||""})})]})}function _t({config:r,category:e,className:o,style:n}){let{repos:a,loading:c,error:t,hasMore:s,loadMore:i,reset:u}=K(r,{pageSize:50}),[d,m]=useState(null),[f,g]=useState(null),[p,w]=useState(null),[k,h]=useState(null),[v,E]=useState(false),[N,_]=useState(""),[Te,re]=useState(false),[ne,se]=useState(false),[oe,U]=useState(null),Pe=a.find(b=>b.repo_id===d),{entries:Ee,getFileContent:ae}=F(r,f),ie=a.filter(b=>!N||b.name.toLowerCase().includes(N.toLowerCase())),_e=useCallback(async b=>{if(!b.isDir){w(b),E(true);try{let P=await ae(b.cid);h(P);}catch(P){let $e=P instanceof Error?P.message:"Unknown error";h(`Failed to load file: ${$e}`);}finally{E(false);}}},[ae]);useEffect(()=>{a.length>0&&!d&&(m(a[0].repo_id),g(a[0].repo_id));},[a,d]);let Me=b=>{b==="create-with-geoff"?window.open(`https://www.geoff.ai/?p=${encodeURIComponent("Let's create a skill together using your skill-creator skill. First ask me what the skill should do.")}`,"_blank","noopener,noreferrer"):U(b);};return jsxs("div",{className:T("flex flex-1 h-full min-h-0",o),style:n,children:[jsxs("div",{className:"relative flex w-96 shrink-0 flex-col border-r",children:[jsx("div",{className:"flex h-12 items-center gap-2 px-3",children:Te?jsxs(Fragment,{children:[jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-md border bg-muted/50 px-2 py-1",children:[jsx(xe,{size:16,className:"shrink-0 text-muted-foreground"}),jsx("input",{type:"text",value:N,onChange:b=>_(b.target.value),placeholder:"Search",autoFocus:true,"aria-label":"Search items",className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),jsx("button",{onClick:()=>{re(false),_("");},className:"rounded p-1 text-muted-foreground hover:text-foreground",children:jsx(X,{size:16})})]}):jsxs(Fragment,{children:[jsx("h3",{className:"flex-1 text-sm sm:text-lg font-semibold text-foreground capitalize",children:e||"Items"}),jsx("button",{onClick:()=>re(true),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Search",children:jsx(xe,{size:20})}),jsx("button",{onClick:()=>se(!ne),className:"rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Add new",children:jsx(ve,{size:20})})]})}),ne&&jsx(Nt,{onClose:()=>se(false),onSelect:Me}),jsx("div",{className:"flex-1 overflow-y-auto p-2",children:c?jsx("div",{className:"flex items-center justify-center py-8",children:jsx(Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):t?jsx("p",{className:"px-2 py-4 text-xs text-red-500",children:t}):ie.length===0?jsx("p",{className:"px-2 py-4 text-xs text-muted-foreground",children:N?"No matching items":"No items yet"}):jsx("div",{className:"space-y-0.5",children:ie.map(b=>jsx(Pt,{repo:b,selected:d===b.repo_id,expanded:f===b.repo_id,onSelect:()=>{m(b.repo_id),w(null),h(null);},onToggle:()=>g(f===b.repo_id?null:b.repo_id),children:jsx("div",{className:"ml-10 pl-1",children:Ee.map(P=>jsx(Tt,{entry:P,selected:p?.path===P.path,onSelect:_e,depth:P.path.split("/").length-1},P.path))})},b.repo_id))})})]}),jsx("div",{className:"flex-1 min-w-0",children:jsx(Et,{entry:p,content:k,loading:v,repoName:Pe?.name||""})}),oe==="write"&&jsx(St,{config:r,onClose:()=>U(null),onCreated:u}),oe==="upload"&&jsx(Ct,{config:r,onClose:()=>U(null),onCreated:u})]})}async function Ne(r,e,o,n){let a={"Content-Type":"application/json",...o?.headers};n&&(a.Authorization=`Bearer ${n}`);let c=await fetch(`${r}${e}`,{...o,headers:a});if(!c.ok){let t=`HTTP ${c.status}`;try{let s=await c.json();s.error&&(t=s.error);}catch{}throw new Error(t)}return c.json()}function zt({config:r,repoId:e,onAuthRequired:o,className:n,style:a}){let c=r.apiBaseUrl,t=r.apiKey,[s,i]=useState({stars:0,starred:false,repo_id:e}),[u,d]=useState(false),[m,f]=useState(null),g=useRef(true),p=c.includes("/cpx/rack")?"":"/api/rack";useEffect(()=>(g.current=true,Ne(c,`${p}/${e}/stars`,void 0,t).then(k=>{g.current&&i(k);}).catch(()=>{}),()=>{g.current=false;}),[c,e,t,p]);let w=useCallback(async k=>{if(k.preventDefault(),k.stopPropagation(),!t){o?.();return}d(true),f(null);try{let h=s.starred?"DELETE":"POST",v=await Ne(c,`${p}/${e}/star`,{method:h},t);g.current&&i({stars:v.stars,starred:v.starred,repo_id:e});}catch(h){g.current&&f(h.message);}finally{g.current&&d(false);}},[c,e,t,s.starred,o]);return jsxs("button",{onClick:w,disabled:u,title:m||(s.starred?"Unstar (100k tokens)":"Star (100k tokens)"),className:n,style:{display:"inline-flex",alignItems:"center",gap:"4px",background:"none",border:"none",cursor:u?"wait":"pointer",padding:"4px 8px",fontSize:"12px",fontFamily:"inherit",color:s.starred?"#f59e0b":"#91918d",transition:"color 150ms",opacity:u?.5:1,...a},children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:s.starred?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})}),jsx("span",{children:s.stars})]})}
|
|
11
|
+
export{Q as Markdown,_t as RackBrowser,zt as StarButton,pe as estimateCost,ot as useNetworkStats,K as usePaginatedRepos,R as useRackClient,Ve as useRackRegister,Je as useRackSession,He as useRepoPush,F as useRepoTree,Be as useRepos,Ye as useSkillStats,ut as useStar,tt as useTensorStats,it as useTrending};
|