Docs_archive
Marketplace architecture
Source docs/MARKETPLACE_ARCHITECTURE.md · All_docs
Scope: Agent discovery and bookmarks inside the Hive Next.js app (
app/).
Not the standalone HTTP service underservices/registry/(seeCDC_REGISTRY_PUBLIC.md).
Layers
- Connected registries (
connected_registriestable) — per-instance URLs of Hive registry APIs (GET /v1/records,GET /v1/records/{handle}). - Catalog aggregation (
src/lib/marketplace/catalog.ts) — fetches handles, expands records in bounded parallelism, enriches from Agent Cards, merges into one list. - Redis cache — key
marketplace:catalog:v1(viahive:cache:prefix), TTL ~90s; invalidated on registry CRUD and operatorPOST /api/marketplace/refresh. - Registry stats — each
POST /api/marketplace/refreshcallssyncAllConnectedRegistryStats()so every row inconnected_registriesgetsrecord_count,last_sync_at, andlast_sync_statusfromGET /v1/records(even whenwarm=0, cache bust + stats only). - HTTP API —
GET /api/marketplace(viewer+),POST /api/marketplace/refresh(operator+),GET /api/marketplace/{handle}(optional?registryId=<uuid>when the same handle exists on multiple registries). Response includesnormalized(same shape as catalog agents),localStats(deploy counts on this Hive), andpricingEnforcementfrom env. - Mesh pins (
mesh_agent_pins) — user-scoped bookmarks to remote Agent Card URLs + optional JSON-RPC / mesh descriptor (Internet-of-agents shortcuts). - Optional registry / card metadata — Catalog agents may include
documentationUrl,sourceUrl,version,publishedAt/updatedAt,inputModalities/outputModalities, andpricing(display-only:label,currency,inputTokensPerMillion,outputTokensPerMillion,notes). Sources: registry record fields (documentationUrl,pricing, …),metadata.pricingon Agent Cards, orhivePricing/pricingon the card JSON. Seerecord-metadata.ts,agent-card-merge.ts,pricing-display.ts. - Local deploy stats — Table
marketplace_agent_local_stats(registry_id,handle,deploy_count,last_deployed_at). Incremented on successfulPOST /api/agents/import/deploywhenmarketplaceOrigin.registryIdandregistryHandleare set (migration0009). - Pricing policy —
MARKETPLACE_PRICING_ENFORCEMENT=warnadds a deploy-step notice inImportAgentModalwhen the catalog entry has no parsedpricing; enforcement remains display-only (no billing).
Buyer configuration (buyerInputs)
So deployers see the same checklist before and after install (catalog page, detail page, import preview + review):
- Registry record — array on any of:
buyerInputs,buyerConfiguration,configurationInputs,requiredInputs,hiveBuyerInputs. - Agent Card —
metadata.hiveBuyerInputsormetadata.buyerInputs, or roothiveBuyerInputs/buyerInputs. Card entries override the same logical item (matched byid, elsekey, elselabel) as the record.
Each object may include: id, label, optional key (env var), kind (env | secret | url | text | choice), description, required, example, and options for choice. Env-like kinds are merged with the manifest’s envVarsRequired for the Environment variables textarea in ImportAgentModal.
Code: src/lib/marketplace/buyer-inputs.ts — populates MarketplaceAgent.buyerInputs in the catalog and normalized.buyerInputs on GET /api/marketplace/{handle}.
Registry-side enforcement (publish)
The HTTP registry (services/registry) can reject or warn on writes when publisher configuration is incomplete:
POST /v1/records/validate— dry-run (schema + readiness report, no store). SameAuthorization: BearerasPOST /v1/records.REGISTRY_PUBLISH_READINESS=off|warn|enforce(defaultoff).enforcereturns 422publish_readiness_failedon failed checks.REGISTRY_PUBLISH_REQUIRE_ATTESTATION=1— requirespublishAttestation(confirmedBuyerConfiguration: true,confirmedAt).REGISTRY_PUBLISH_FETCH_AGENT_CARD=1— optional cross-check: fetch Agent Card, resolve embedded / linked hive-agent-manifest, ensureruntime.envVarsRequiredkeys appear inbuyerInputs.REGISTRY_PUBLISH_ATTESTATION_HMAC_SECRET— when set,publishAttestation.hmacSha256Hexmust verify (HMAC-SHA256 hex over stable JSON of{ handle, updatedAt, buyerInputs }).REGISTRY_PUBLISH_FETCH_HOST_ALLOWLIST— comma-separated hostnames; if non-empty, outbound readiness fetches are limited to those hosts (plus built-in SSRF checks).REGISTRY_PUBLISH_FETCH_MAX_REDIRECTS(default 5),REGISTRY_PUBLISH_FETCH_CACHE_TTL_MS/REGISTRY_PUBLISH_FETCH_CACHE_MAX— redirect cap and in-memory fetch cache for readiness.
See docs/CDC_REGISTRY_PUBLIC.md § 6.2.1 and docs/openapi/registry-v1.yaml.
Import and deploy (catalog provenance)
POST /api/agents/import— resolves a URL or registry handle; returnsImportPreview(sourceType,manifest,warnings,envVarsRequired). The UI maps this into the import wizard.POST /api/agents/import/deploy— body:manifest,sourceType, optionalsourceUrl, optionalmarketplaceOrigin(registryHandle, optionalregistryId,registryName,registryUrl), andoverrides(name, env, limits, GPU, confidential).- When
marketplaceOriginis present, the created agent getsagents.source_type = marketplaceandconfig.marketplaceset to that object (audit log includes the same). ImportAgentModalpassesmarketplaceContextfrom/marketplaceand/marketplace/[handle]so deploy-from-catalog is traced end-to-end. Imports from Agents → Import omit it (url-importorregistryin DB).agent.importedsystem events include wiresourceTypeplus optionalrecordedSource(url-import|marketplace|registry) matching the DB row.GET /api/agents— optional query:sourceType(local|url-import|marketplace|registry),q(case-insensitive substring on name + image; wildcards%/_stripped). Combined with the usual owner scope. Index:agents_source_type_idx(migration0007).
Scaling notes
- Per-registry handle cap (
MARKETPLACE_MAX_HANDLES_PER_REGISTRY) avoids unbounded fan-out. - Record fetches use a small concurrency pool per registry.
- V2 (implemented): Postgres index
marketplace_catalog_rows,MARKETPLACE_CATALOG_SOURCE=db,POST /api/marketplace/index-rebuild,npm run marketplace:index-sync, API pagination +meta.tags, marketplace UI infinite scroll. See MARKETPLACE_V2_SCALING.md for worker/CI/discovery/reputation/billing roadmap.
UI entry points (English)
- Layout — Tabs Catalog (
/marketplace) and Registries (/marketplace/registries). Operators manage registries on the Registries tab (same panel as Settings → Marketplace); viewers see a short explanation and a link to Settings. /marketplace— federated catalog; pin, deploy, Details per agent. With multiple registries, use Registry pills to filter the grid. Details links include?registryId=when known so duplicate handles resolve to the correct registry. Deploy finishes by opening the new agent’s/agents/{id}page./marketplace/[handle]— Provenance, on this Hive deploy stats, pricing & modalities, filterable skills, links, raw registry record + Agent Card JSON; deploy routes to/agents/{id}after success.- Settings → Marketplace — connect registries (admin), toggle enabled (admin), refresh (updates DB stats + cache).
- Agents — Source menu filters the list via
GET /api/agents?sourceType=; table pills (Imported / Marketplace / Registry); Import and New agent → Import redirect to the new agent after deploy. Overview links back to/marketplace/[handle]whenconfig.marketplaceis set.