4.2 KiB
4.2 KiB
id, title, status, wave, depends_on, plan
| id | title | status | wave | depends_on | plan | ||||
|---|---|---|---|---|---|---|---|---|---|
| task-17 | Backend HTTP API + proxies + bundle + boot payload + health + wiring | done | B |
|
docs/plans/plugins/plan.md |
Backend HTTP API + proxies + bundle + boot payload + health + wiring
Title
The full backend surface for native-UI plugins: management + plugin-facing API, auth/capability middleware, state + secrets, webhook proxy, JS bundle proxy, boot-payload active-plugin list, health monitor, and backendapp wiring.
Inputs
- Spec
docs/specs/plugins/requirements/plugins.md(API surface, permissions, security). PLUGIN-API.md: boot payloadplugins: [{id,name,bundleUrl,styleUrls?}],bundleUrl=/api/plugins/{id}/bundle; bundle proxied to plugin'sui.bundle.- Reuse: task-05
Service(Provide, Registry(), Get, List, Enable/Disable, AuthenticatePlugin, RevealWebhookSecret, StateStore(), SetDeliverer, SetStatus/UpdateLastHealthCheck), task-06delivery.Deliverer, task-16 manifestui.bundle. - Routing precedent:
internal/jira/handlers.goRegisterRoutes(router, dispatcher, svc, log). Reverse-proxy + header stripping precedent:internal/agentctl/server/api/(read its AGENTS.md). - Wiring precedent:
internal/backendapp/services.goinitJiraService+provideServices;helpers.gorouteParams+registerRoutes. Boot payload producer:internal/webapp/payload.go(BootPayload) — add active plugins.
Acceptance
internal/plugins/handlers.goRegisterRoutes(router, svc, deliverer, log):- Management:
POST /api/plugins/register,GET /api/plugins,GET/:id,PATCH/:id,DELETE/:id,POST/:id/enable,POST/:id/disable. Register returns cleartext creds once. GET /api/plugins/tools(aggregate declared tools; listing only).GET /api/plugins/:id/bundle+GET /api/plugins/:id/ui/*→ reverse proxy to plugin base_url (bundle →ui.bundlepath). Strip iframe-blocking headers onui/*; bundle served withContent-Type: text/javascript. Only for active plugins.POST /api/plugins/:id/webhooks/:key→ webhook reverse proxy (active + key declared).
- Management:
internal/plugins/client.go:InvokeTool(ctx, record, tool, input, callCtx)(30s) +Health(ctx, record);internal/plugins/proxy.go: the reverse proxies.internal/plugins/middleware.go:PluginAuth(svc)(Bearer api_key → plugin identity) +RequireCapability(kind, resource)(403 with capability name). Plugin-facing: state API (/api/plugins/:id/state*, needsstatecap, always scoped to authed plugin id), secrets API (/api/plugins/:id/secrets/:ref, needssecretscap → secretadapter). Office read/write endpoints deferred (comment).internal/plugins/health.go:HealthMonitor30s/5s, 3 fails → error + emitplugin.health.degradedbus event, recovery → active +deliverer.Flush(id), updateslast_health_check.- Boot payload:
internal/webapp/payload.gogainsPlugins []ActivePluginPayload({ID,Name,BundleURL,StyleURLs}) populated from active plugins that haveui.bundle. Gate onfeatures.plugins. Add the mapping wherever office data is mapped into the payload; add a getter on the plugins Service likeActiveUIPlugins() []Record. - Wiring:
initPluginsServicein services.go callingplugins.Provide(...)withsecretadapter.New(secretsStore)as the vault; constructdelivery.Deliverer,svc.SetDeliverer(d), startHealthMonitorand deliverer viaaddCleanup; fields onServices+routeParams;registerRoutescallsplugins.RegisterRoutes(...)gated onp.features.Plugins.
Files
apps/backend/internal/plugins/handlers.go,middleware.go,client.go,proxy.go,health.go,dto.go(+_test.goeach)- edits:
internal/backendapp/services.go,internal/backendapp/helpers.go,internal/webapp/payload.go
Verification
go test ./internal/plugins/... ./internal/backendapp/... ./internal/webapp/...(apps/backend)make -C apps/backend build lint
Output contract
Full route table, proxy header behavior, boot-payload shape (so task-18/19 match),
wiring points. Ensure make -C apps/backend build test lint pass. This closes the backend.
Dependencies
task-05 (done), task-06, task-16, task-10.