dashboard

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dashboard is the runtime bridge half of the end-user dashboard for the nodestore stack: the state sink ui* widget executors push into (nodebase.BindUIWidgetSink / nodebase.PushUIState in nodes/uishare.go), the per-workflow widget manifest + retained state registry, and the websocket endpoint dashboard clients sync through. Dashboard PAGE serving (HTML shells, navigation) is a nodeadmin responsibility — this package is deliberately only the runtime state bridge.

Engine-agnostic by construction

The hub holds a nodebase.NodeHost, never a concrete runner: no noderunner imports, so the package travels with the nodebase repo. Composition happens at the mount site — nodeadmin.New constructs the hub with the engine as Host and installs it as the engine's deploy observer (the hub's WorkflowActivated/WorkflowStopped methods satisfy noderunner.DeployObserver structurally; a host without an observer seam still works — scopes are created lazily through NodeHost.RunningFlow).

Wire protocol (JSON text frames on <mount>/ws?flow=ID)

Server → client:

{"type":"manifest","workflow":"<id>","widgets":[...],"state":{"<node>":{...}}}
{"type":"update","node":"<nodeID>","state":{...}}
{"type":"close","reason":"undeployed"}
{"type":"error","message":"..."}

Client → server:

{"type":"input","node":"<nodeID>","msg":{...}}      msg becomes msg.Payload
{"type":"input","node":"<nodeID>","payload":<any>}  shorthand; Data={"payload":v}

"input" messages are injected via NodeHost.InjectMessage addressed from the widget node, so they travel downstream exactly as if the widget node emitted them. Only node ids present in the manifest are accepted.

A JSON snapshot of a flow's manifest + state is also served at <mount>/manifest?flow=ID for page shells that render before opening the socket.

Auth: when Options.Authenticator (or the host's HTTPAuthFunc) is set, both endpoints require it and failures get a Basic-auth challenge. With no authenticator the surface is open — same policy as the admin UI without credentials.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub is the dashboard runtime bridge: the nodebase.UIWidgetSink ui* executors push state into, the per-workflow registry of widget manifests + retained state + client sessions, and the websocket endpoint clients sync through. It holds only a nodebase.NodeHost — it is engine-agnostic and travels with the nodebase.

The hub satisfies the run-lifecycle observer contract structurally (WorkflowActivated/WorkflowStopped take nodestore types only): a host that can install a deploy observer (e.g. noderunner's engine.SetDeployObserver) wires it at mount time; nodeadmin does so. Scope creation also happens lazily via host.RunningFlow, so a host without an observer seam still serves dashboards for running flows.

func New

func New(opts Options) (*Hub, error)

New returns a *Hub serving the websocket bridge at <mount>/ws and a JSON manifest snapshot at <mount>/manifest, bound to the host's UIWidgetSink seam — after New, ui* executors on this host push state through the hub (see nodebase.BindUIWidgetSink).

The caller wires run-lifecycle observation when the host supports it (e.g. engine.SetDeployObserver(hub) for noderunner); scopes are otherwise created lazily via Host.RunningFlow.

Mount with a prefix strip so the hub stays mount-agnostic:

hub, err := dashboard.New(dashboard.Options{Host: engine})
mux.Handle("/dashboard/", http.StripPrefix("/dashboard", hub))

func (*Hub) Close

func (h *Hub) Close()

Close unbinds the hub from the sink seam and closes every session — call on host teardown.

func (*Hub) Flows

func (h *Hub) Flows() []string

Flows lists the workflow IDs that currently have a dashboard — used to resolve the dashboard when no ?flow= is given (single-dashboard deployments pick it automatically).

func (*Hub) HasWidget

func (h *Hub) HasWidget(workflowID, nodeID string) bool

HasWidget reports whether nodeID is a widget in the workflow's current manifest — client "input" messages may only target widgets.

func (*Hub) Manifest

func (h *Hub) Manifest(workflowID string) (Manifest, bool)

Manifest returns the current widget manifest + state for a running workflow, resolving the scope lazily (see scopeFor). ok=false when the workflow has no dashboard scope. Used to pick the default flow and to validate widget ids for client input.

func (*Hub) ServeHTTP

func (h *Hub) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP authenticates then routes to the ws or manifest handler. Paths are relative to the mount point (see New).

func (*Hub) UpdateWidget

func (h *Hub) UpdateWidget(workflowID, nodeID string, state map[string]interface{})

UpdateWidget implements nodebase.UIWidgetSink: stores the widget's state and broadcasts it to every session of the workflow — the engine→client half of the dashboard contract. Widget executors reach it through nodebase.PushUIState. Unknown workflows are resolved lazily via host.RunningFlow (executor pushes only happen inside a run, so the flow is running by definition); a host that reports the flow not running drops the update.

func (*Hub) WorkflowActivated

func (h *Hub) WorkflowActivated(workflow nodestore.WorkflowInterface)

WorkflowActivated is the deploy-observer notification a host wires (structurally compatible with noderunner.DeployObserver): the workflow's widget manifest is (re)published so connected clients see the fresh layout after any deploy — initial, full or partial.

func (*Hub) WorkflowStopped

func (h *Hub) WorkflowStopped(workflowID string)

WorkflowStopped is the deploy-observer notification fired on undeploy (StopWorkflow and failed-activation alike): the workflow's scope is torn down.

type Manifest

type Manifest struct {
	Workflow string                            `json:"workflow"`
	Widgets  []nodebase.UIWidgetManifest       `json:"widgets"`
	State    map[string]map[string]interface{} `json:"state"`
}

Manifest is the snapshot a connecting dashboard client receives: the workflow's widget list plus each widget's last pushed state (late-join replay).

type Options

type Options struct {
	// Host is the NodeHost the dashboard runs against (required):
	// the seam widget executors push through and the hub injects
	// client input into.
	Host nodebase.NodeHost

	// Authenticator authenticates requests for both endpoints; nil
	// falls back to the host's HTTPAuthFunc. When both are nil the
	// dashboard is unauthenticated.
	Authenticator func(r *http.Request) (username string, ok bool)

	// AllowedOrigins restricts websocket upgrade Origin hosts
	// (websocket.Accept OriginPatterns, e.g. []string{"example.com",
	// "*.example.com"}). Empty keeps the legacy any-origin behaviour
	// (CSWSH exposure — set it on internet-facing deployments).
	AllowedOrigins []string
}

Options configures the dashboard hub.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL