mirror of
https://github.com/hanzoai/bot-hub.git
synced 2026-11-02 20:16:38 +00:00
Every route mounts under /v1/skills, the address api.hanzo.ai routes to this API; auth, personas, users, tokens, upload, integrations, search and whoami are sub-resources and RESERVED keeps them from being slugs. The web, the OG renderers, the CLI's default registry, /.well-known/bothub.json and openapi.json name api.hanzo.ai. Sign-in calls back to api.hanzo.ai/v1/skills/auth/callback and hands the token over in the fragment. The store starts again. docker-entrypoint.sh read Base's port from BASE_PORT, which Kubernetes sets to tcp://<ip>:<port> in a namespace holding a Service named base; Base now listens on 127.0.0.1:8090, fixed. The collections migration is rewritten for the Base the Dockerfile pins (1.5.91): flat field options, declared created/updated, and the users collection every Base already has, extended rather than created twice. Reads are anonymous against public rules, since Base takes IAM credentials only and no longer serves password sign-in; writes answer 503 saying so. The catalogue migration, generated by scripts/catalog.mjs, publishes the 83 skills in hanzoai/bot@8be8f1dc7b. /health reports the store, so the probes restart a pod whose Base is gone. cache.ts decides caching once: an anonymous 2xx GET is public for a minute (five at the edge) with a weak ETag and 304s; a credential, a write or an error is private, no-store. Filter values go through lit(). Embeddings go through api.hanzo.ai and are skipped without a key. k8s/ was a second declaration of the deployment; universe is the one.
97 lines
2.7 KiB
TypeScript
97 lines
2.7 KiB
TypeScript
import { initWasm, Resvg } from '@resvg/resvg-wasm'
|
|
import { defineEventHandler, getQuery, setHeader } from 'h3'
|
|
|
|
import { fetchSkillOgMeta } from '../../og/fetchSkillOgMeta'
|
|
import {
|
|
FONT_MONO,
|
|
FONT_SANS,
|
|
getFontBuffers,
|
|
getMarkDataUrl,
|
|
getResvgWasm,
|
|
} from '../../og/ogAssets'
|
|
import { buildSkillOgSvg } from '../../og/skillOgSvg'
|
|
|
|
type OgQuery = {
|
|
slug?: string
|
|
owner?: string
|
|
version?: string
|
|
title?: string
|
|
description?: string
|
|
v?: string
|
|
}
|
|
|
|
let wasmInitPromise: Promise<void> | null = null
|
|
|
|
function cleanString(value: unknown) {
|
|
if (typeof value !== 'string') return ''
|
|
return value.trim()
|
|
}
|
|
|
|
function getApiBase() {
|
|
return (process.env.VITE_API_URL ?? '').trim() || 'https://api.hanzo.ai'
|
|
}
|
|
|
|
async function ensureWasm() {
|
|
if (!wasmInitPromise) {
|
|
wasmInitPromise = getResvgWasm().then((wasm) => initWasm(wasm))
|
|
}
|
|
await wasmInitPromise
|
|
}
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const query = getQuery(event) as OgQuery
|
|
const slug = cleanString(query.slug)
|
|
if (!slug) {
|
|
setHeader(event, 'Content-Type', 'text/plain; charset=utf-8')
|
|
return 'Missing `slug` query param.'
|
|
}
|
|
|
|
const ownerFromQuery = cleanString(query.owner)
|
|
const versionFromQuery = cleanString(query.version)
|
|
const titleFromQuery = cleanString(query.title)
|
|
const descriptionFromQuery = cleanString(query.description)
|
|
|
|
const needFetch = !titleFromQuery || !descriptionFromQuery || !ownerFromQuery || !versionFromQuery
|
|
const meta = needFetch ? await fetchSkillOgMeta(slug, getApiBase()) : null
|
|
|
|
const owner = ownerFromQuery || meta?.owner || ''
|
|
const version = versionFromQuery || meta?.version || ''
|
|
const title = titleFromQuery || meta?.displayName || slug
|
|
const description = descriptionFromQuery || meta?.summary || ''
|
|
|
|
const ownerLabel = owner ? `@${owner}` : 'bothub'
|
|
const versionLabel = version ? `v${version}` : 'latest'
|
|
const footer = owner ? `hub.hanzo.bot/${owner}/${slug}` : `hub.hanzo.bot/skills/${slug}`
|
|
|
|
const cacheKey = version ? 'public, max-age=31536000, immutable' : 'public, max-age=3600'
|
|
setHeader(event, 'Cache-Control', cacheKey)
|
|
setHeader(event, 'Content-Type', 'image/png')
|
|
|
|
const [markDataUrl, fontBuffers] = await Promise.all([
|
|
getMarkDataUrl(),
|
|
ensureWasm().then(() => getFontBuffers()),
|
|
])
|
|
|
|
const svg = buildSkillOgSvg({
|
|
markDataUrl,
|
|
title,
|
|
description,
|
|
ownerLabel,
|
|
versionLabel,
|
|
footer,
|
|
})
|
|
|
|
const resvg = new Resvg(svg, {
|
|
fitTo: { mode: 'width', value: 1200 },
|
|
font: {
|
|
fontBuffers,
|
|
defaultFontFamily: FONT_SANS,
|
|
sansSerifFamily: FONT_SANS,
|
|
monospaceFamily: FONT_MONO,
|
|
},
|
|
})
|
|
const png = resvg.render().asPng()
|
|
resvg.free()
|
|
return png
|
|
})
|