generated from coulomb/repo-seed
Convert all remaining `<- paramOrNothing / param / paramOrDefault /
currentUserOrNothing` monadic binds to `let` — these functions are pure
(ImplicitParams-based) in IHP v1.5, so `<-` is a type error in an IO
do-block.
Controllers fixed:
AgentDelegations, AiGovernancePolicies, Annotations, ApiConsumers,
CollectiveProposals, DecisionRecords, DeploymentRecords,
HubCapabilityManifests, HubRoutingRules, InstitutionalKnowledge,
OutcomeCorrelations, RequirementCandidates, TypeRegistries,
WebhookSubscriptions, Widgets,
Api/V2/{Annotations,InteractionEvents,Token}
WebhookSubscriptions: remove orphaned `Right () ->` case arm that was
left inside a bare `unless` block (structural parse error).
Also carries forward all in-progress fixes from the working tree:
helpers (AgentBridge, ApiRateLimit, BottleneckDetector,
CrossHubPropagation, FrictionScore),
views (CanSelect instances, HSX lambda extraction, formFor wrappers),
env/build (envrc GHCi perms, flake.nix Tailwind + GHC resource limits,
static/app.css additional Tailwind output).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
81 lines
3.1 KiB
Haskell
81 lines
3.1 KiB
Haskell
module Web.Controller.Api.V2.HubRegistry where
|
|
|
|
-- GET /api/v2/hub-registry — list hubs with active manifest summary + GAAF indicator
|
|
-- GET /api/v2/hub-registry/:hubId — single hub detail
|
|
|
|
import Web.Types
|
|
import Generated.Types
|
|
import IHP.Prelude
|
|
import IHP.ControllerPrelude
|
|
import Data.Aeson (object, (.=), Value)
|
|
import Web.Controller.Api.V2.Auth (requireApiConsumer)
|
|
import Application.Helper.ApiRateLimit (checkRateLimitAndLog)
|
|
|
|
instance Controller ApiV2HubRegistryController where
|
|
|
|
action ApiV2IndexHubRegistryAction = do
|
|
consumer <- requireApiConsumer
|
|
checkRateLimitAndLog consumer "GET" "/api/v2/hub-registry"
|
|
hubs <- query @Hub |> orderByAsc #name |> fetch
|
|
rows <- mapM buildHubJson hubs
|
|
renderJson rows
|
|
|
|
action ApiV2ShowHubRegistryAction { hubId } = do
|
|
consumer <- requireApiConsumer
|
|
checkRateLimitAndLog consumer "GET" ("/api/v2/hub-registry/" <> tshow hubId)
|
|
hub <- fetch hubId
|
|
mManifest <- query @HubCapabilityManifest
|
|
|> filterWhere (#hubId, hubId)
|
|
|> filterWhere (#status, "active")
|
|
|> fetchOneOrNothing
|
|
mSnapshot <- query @HubHealthSnapshot
|
|
|> filterWhere (#hubId, hubId)
|
|
|> orderByDesc #computedAt
|
|
|> limit 1
|
|
|> fetchOneOrNothing
|
|
renderJson (hubDetailJson hub mManifest mSnapshot)
|
|
|
|
-- | Build a summary JSON object for a hub including manifest and health data.
|
|
buildHubJson :: (?modelContext :: ModelContext) => Hub -> IO Value
|
|
buildHubJson hub = do
|
|
mManifest <- query @HubCapabilityManifest
|
|
|> filterWhere (#hubId, hub.id)
|
|
|> filterWhere (#status, "active")
|
|
|> fetchOneOrNothing
|
|
mSnapshot <- query @HubHealthSnapshot
|
|
|> filterWhere (#hubId, hub.id)
|
|
|> orderByDesc #computedAt
|
|
|> limit 1
|
|
|> fetchOneOrNothing
|
|
pure $ hubDetailJson hub mManifest mSnapshot
|
|
|
|
hubDetailJson :: Hub -> Maybe HubCapabilityManifest -> Maybe HubHealthSnapshot -> Value
|
|
hubDetailJson hub mManifest mSnapshot =
|
|
let gaafIndicator = case mManifest of
|
|
Nothing -> "no_manifest" :: Text
|
|
Just m | m.status == "active" -> "compliant"
|
|
| otherwise -> "draft_only"
|
|
in object
|
|
[ "id" .= hub.id
|
|
, "name" .= hub.name
|
|
, "slug" .= hub.slug
|
|
, "domain" .= hub.domain
|
|
, "hubKind" .= hub.hubKind
|
|
, "gaafStatus" .= gaafIndicator
|
|
, "manifest" .= fmap manifestSummary mManifest
|
|
, "healthScore" .= fmap (.healthScore) mSnapshot
|
|
, "healthAt" .= fmap (.computedAt) mSnapshot
|
|
]
|
|
|
|
manifestSummary :: HubCapabilityManifest -> Value
|
|
manifestSummary m = object
|
|
[ "id" .= m.id
|
|
, "manifestVersion" .= m.manifestVersion
|
|
, "status" .= m.status
|
|
, "declaredWidgetTypes" .= m.declaredWidgetTypes
|
|
, "declaredEventTypes" .= m.declaredEventTypes
|
|
, "declaredAnnotationCategories" .= m.declaredAnnotationCategories
|
|
, "declaredPolicyScopes" .= m.declaredPolicyScopes
|
|
, "activatedAt" .= m.activatedAt
|
|
]
|