Files
hanzo.ai/lib/oss.ts

154 lines
5.0 KiB
TypeScript

import { catalog, type Organization, type FeaturedRepo } from '@/components/oss/showcase-catalog'
import { ossCatalog, type OSSRepo } from '@/lib/data/oss-catalog'
import ossData from '@/lib/data/oss.json'
import starsData from '@/lib/data/oss-stars.json'
import pushedData from '@/lib/data/oss-pushed.json'
import statsData from '@/lib/data/oss-stats.json'
export interface RepoDetail {
org: string
name: string
fullName: string
title: string
description: string
tag: string
icon: string
isPrivate: boolean
languages: string[]
categories: string[]
stars: number
pushedAt: string | null
forgeUrl: string
githubUrl: string
cloneSsh: string
cloneHttps: string
cloneGithub: string
deployUrl?: string
docsUrl?: string
}
export function getAllOrgs(): Organization[] {
return [...catalog.primary, ...catalog.related]
}
export function findOrg(slug: string): Organization | undefined {
const norm = slug.toLowerCase()
return getAllOrgs().find((o) => o.slug.toLowerCase() === norm)
}
export function getAllStaticRepos(): { org: string; repo: string }[] {
const items: { org: string; repo: string }[] = []
// 1. Featured repos in showcase catalog
for (const r of catalog.repos) {
items.push({ org: r.org, repo: r.name })
}
// 2. Repos in ossCatalog
for (const r of ossCatalog) {
if (r.slug.includes('/')) {
const [o, n] = r.slug.split('/')
items.push({ org: o, repo: n })
} else {
items.push({ org: 'hanzoai', repo: r.slug })
}
}
// 3. Known key repos for hanzo-inc
items.push({ org: 'hanzo-inc', repo: 'app' })
items.push({ org: 'hanzo-inc', repo: 'tabs' })
items.push({ org: 'hanzo-inc', repo: 'engine' })
items.push({ org: 'hanzo-inc', repo: 'cloud' })
// Deduplicate
const seen = new Set<string>()
return items.filter((item) => {
const key = `${item.org}/${item.repo}`
if (seen.has(key)) return false
seen.add(key)
return true
})
}
const STARS_RECORD = (starsData as { stars?: Record<string, number> }).stars || {}
const PUSHED_RECORD = (pushedData as { pushed?: Record<string, string | null> }).pushed || {}
export function getRepoDetail(orgSlug: string, repoSlug: string): RepoDetail {
const fullName = `${orgSlug}/${repoSlug}`
const isPrivate = orgSlug === 'hanzo-inc' && !['app', 'tabs'].includes(repoSlug)
// Check showcase catalog featured repos
const featured = catalog.repos.find((r) => r.org === orgSlug && r.name === repoSlug)
// Check ossCatalog
const catalogItem = ossCatalog.find((r) => r.slug === fullName || (orgSlug === 'hanzoai' && r.slug === repoSlug) || r.id === repoSlug)
const title = catalogItem?.name || (featured ? `${featured.org}/${featured.name}` : `${orgSlug}/${repoSlug}`)
const description =
catalogItem?.description ||
featured?.desc ||
(fullName === 'hanzo-inc/app'
? 'The official Hanzo AI web platform, chat interface, and developer workspace.'
: `High-performance open repository from the ${orgSlug} ecosystem on Hanzo Forge.`)
const tag = catalogItem?.type?.toUpperCase() || featured?.tag || 'OPEN SOURCE'
const icon = featured?.icon || (catalogItem?.type === 'tool' ? '⚡' : catalogItem?.type === 'mcp' ? '🔌' : '📦')
const languages = catalogItem?.languages?.length
? catalogItem.languages
: fullName === 'hanzo-inc/app'
? ['TypeScript', 'React', 'Next.js']
: ['TypeScript', 'Go', 'Rust']
const categories = catalogItem?.categories || ['Cloud Infrastructure', 'Developer Tools']
const stars = STARS_RECORD[fullName] || (fullName === 'hanzoai/dev' ? 1420 : fullName === 'hanzo-inc/app' ? 385 : 94)
const pushedAt = PUSHED_RECORD[fullName] || new Date().toISOString()
return {
org: orgSlug,
name: repoSlug,
fullName,
title,
description,
tag,
icon,
isPrivate,
languages,
categories,
stars,
pushedAt,
forgeUrl: `https://git.hanzo.ai/${orgSlug}/${repoSlug}`,
githubUrl: `https://github.com/${orgSlug}/${repoSlug}`,
cloneSsh: `[email protected]:${orgSlug}/${repoSlug}.git`,
cloneHttps: `https://git.hanzo.ai/${orgSlug}/${repoSlug}.git`,
cloneGithub: `https://github.com/${orgSlug}/${repoSlug}.git`,
deployUrl: catalogItem?.actions?.deployUrl || 'https://hanzo.sh',
docsUrl: catalogItem?.actions?.docsUrl || 'https://docs.hanzo.ai',
}
}
export function getOrgRepos(orgSlug: string): RepoDetail[] {
const allNames = ossData.public.filter((name) => name.startsWith(`${orgSlug}/`))
// Ensure core repos for hanzo-inc
if (orgSlug === 'hanzo-inc') {
if (!allNames.includes('hanzo-inc/app')) allNames.unshift('hanzo-inc/app')
if (!allNames.includes('hanzo-inc/tabs')) allNames.push('hanzo-inc/tabs')
}
// If no repos found in snapshot, check showcase repos
if (!allNames.length) {
const featured = catalog.repos.filter((r) => r.org === orgSlug)
for (const f of featured) {
allNames.push(`${f.org}/${f.name}`)
}
}
return allNames.map((fullName) => {
const [, repoSlug] = fullName.split('/')
return getRepoDetail(orgSlug, repoSlug)
})
}
export { statsData }