Documentation
¶
Overview ¶
Package portal provides the asset portal data layer for persisting AI-generated artifacts (JSX dashboards, HTML reports, SVG charts).
Index ¶
- func RequirePortalAuth(auth *Authenticator) func(http.Handler) http.Handler
- func ValidateAssetName(name string) error
- func ValidateContentType(ct string) error
- func ValidateDescription(desc string) error
- func ValidateEmail(email string) error
- func ValidateTags(tags []string) error
- type Asset
- type AssetFilter
- type AssetStore
- type AssetUpdate
- type AuditMetrics
- type Authenticator
- type AuthenticatorOption
- type Deps
- type Handler
- type InsightReader
- type PersonaInfo
- type PersonaResolver
- type Provenance
- type ProvenanceToolCall
- type RateLimitConfig
- type RateLimiter
- type S3Client
- type Share
- type ShareStore
- type ShareSummary
- type SharedAsset
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequirePortalAuth ¶
func RequirePortalAuth(auth *Authenticator) func(http.Handler) http.Handler
RequirePortalAuth creates middleware that enforces portal authentication.
func ValidateAssetName ¶
ValidateAssetName checks that a name is non-empty and within length limits.
func ValidateContentType ¶
ValidateContentType checks that a content type is non-empty.
func ValidateDescription ¶
ValidateDescription checks that a description is within length limits.
func ValidateEmail ¶ added in v0.35.9
ValidateEmail checks that an email address has a basic valid format.
func ValidateTags ¶
ValidateTags checks tag count and individual tag length.
Types ¶
type Asset ¶
type Asset struct {
ID string `json:"id"`
OwnerID string `json:"owner_id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
ContentType string `json:"content_type"`
S3Bucket string `json:"s3_bucket"`
S3Key string `json:"s3_key"`
SizeBytes int64 `json:"size_bytes"`
Tags []string `json:"tags"`
Provenance Provenance `json:"provenance"`
SessionID string `json:"session_id,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `json:"deleted_at,omitempty"`
}
Asset represents a persisted AI-generated artifact.
type AssetFilter ¶
type AssetFilter struct {
OwnerID string `json:"owner_id,omitempty"`
ContentType string `json:"content_type,omitempty"`
Tag string `json:"tag,omitempty"`
Limit int `json:"limit,omitempty"`
Offset int `json:"offset,omitempty"`
}
AssetFilter defines filtering criteria for listing assets.
func (*AssetFilter) EffectiveLimit ¶
func (f *AssetFilter) EffectiveLimit() int
EffectiveLimit returns the limit with defaults applied.
type AssetStore ¶
type AssetStore interface {
Insert(ctx context.Context, asset Asset) error
Get(ctx context.Context, id string) (*Asset, error)
List(ctx context.Context, filter AssetFilter) ([]Asset, int, error)
Update(ctx context.Context, id string, updates AssetUpdate) error
SoftDelete(ctx context.Context, id string) error
}
AssetStore persists and queries portal assets.
func NewNoopAssetStore ¶
func NewNoopAssetStore() AssetStore
NewNoopAssetStore creates a no-op AssetStore for use when no database is available.
func NewPostgresAssetStore ¶
func NewPostgresAssetStore(db *sql.DB) AssetStore
NewPostgresAssetStore creates a new PostgreSQL asset store.
type AssetUpdate ¶
type AssetUpdate struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
ContentType string `json:"content_type,omitempty"`
S3Key string `json:"s3_key,omitempty"`
SizeBytes int64 `json:"size_bytes,omitempty"`
HasContent bool `json:"-"` // set when content replacement provides SizeBytes (even if 0)
}
AssetUpdate holds mutable fields for updating an asset. Pointer fields distinguish "no change" (nil) from "clear to empty" (pointer to "").
type AuditMetrics ¶ added in v0.36.0
type AuditMetrics interface {
Timeseries(ctx context.Context, filter audit.TimeseriesFilter) ([]audit.TimeseriesBucket, error)
Breakdown(ctx context.Context, filter audit.BreakdownFilter) ([]audit.BreakdownEntry, error)
Overview(ctx context.Context, filter audit.MetricsFilter) (*audit.Overview, error)
}
AuditMetrics provides aggregate audit metrics scoped to individual users.
type Authenticator ¶
type Authenticator struct {
// contains filtered or unexported fields
}
Authenticator wraps the platform's middleware.Authenticator chain for HTTP portal requests. Unlike the admin authenticator, it does not require a specific persona — any authenticated user can access the portal.
func NewAuthenticator ¶
func NewAuthenticator(auth middleware.Authenticator, opts ...AuthenticatorOption) *Authenticator
NewAuthenticator creates a Authenticator.
func (*Authenticator) Authenticate ¶
func (pa *Authenticator) Authenticate(r *http.Request) (*User, error)
Authenticate extracts credentials from the HTTP request and delegates to the platform authenticator. It checks browser session cookies first, then falls back to token-based authentication.
type AuthenticatorOption ¶
type AuthenticatorOption func(*Authenticator)
AuthenticatorOption configures the portal authenticator.
func WithBrowserAuth ¶
func WithBrowserAuth(ba *browsersession.Authenticator) AuthenticatorOption
WithBrowserAuth adds cookie-based authentication.
type Deps ¶
type Deps struct {
AssetStore AssetStore
S3Client S3Client
S3Bucket string
PublicBaseURL string
RateLimit RateLimitConfig
OIDCEnabled bool
AdminRoles []string // roles that grant admin access in the portal
AuditMetrics AuditMetrics
InsightStore InsightReader
PersonaResolver PersonaResolver
}
Deps holds dependencies for the portal handler.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler provides portal REST API endpoints.
func NewHandler ¶
NewHandler creates a new portal API handler.
type InsightReader ¶ added in v0.36.0
type InsightReader interface {
List(ctx context.Context, filter knowledge.InsightFilter) ([]knowledge.Insight, int, error)
Stats(ctx context.Context, filter knowledge.InsightFilter) (*knowledge.InsightStats, error)
}
InsightReader provides read-only access to user insights.
type PersonaInfo ¶ added in v0.36.0
type PersonaInfo struct {
Name string
Tools []string // resolved tool names from Allow/Deny patterns
}
PersonaInfo holds resolved persona details for the current user.
type PersonaResolver ¶ added in v0.36.0
type PersonaResolver func(roles []string) *PersonaInfo
PersonaResolver resolves a user's roles to their persona info.
type Provenance ¶
type Provenance struct {
ToolCalls []ProvenanceToolCall `json:"tool_calls,omitempty"`
SessionID string `json:"session_id,omitempty"`
UserID string `json:"user_id,omitempty"`
}
Provenance records the tool call history that produced an artifact.
type ProvenanceToolCall ¶
type ProvenanceToolCall struct {
ToolName string `json:"tool_name"`
Timestamp string `json:"timestamp"`
Summary string `json:"summary,omitempty"`
}
ProvenanceToolCall records a single tool invocation in the provenance chain.
type RateLimitConfig ¶
type RateLimitConfig struct {
RequestsPerMinute int `yaml:"requests_per_minute"`
BurstSize int `yaml:"burst_size"`
}
RateLimitConfig configures the rate limiter.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter provides per-IP token bucket rate limiting.
func NewRateLimiter ¶
func NewRateLimiter(cfg RateLimitConfig) *RateLimiter
NewRateLimiter creates a rate limiter from config.
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(ip string) bool
Allow checks whether a request from the given IP should be allowed.
func (*RateLimiter) Cleanup ¶
func (rl *RateLimiter) Cleanup(maxAge time.Duration)
Cleanup removes stale entries older than the given duration.
func (*RateLimiter) Close ¶
func (rl *RateLimiter) Close()
Close stops the background cleanup goroutine.
func (*RateLimiter) Middleware ¶
func (rl *RateLimiter) Middleware(next http.Handler) http.Handler
Middleware wraps an http.Handler with rate limiting.
type S3Client ¶
type S3Client interface {
PutObject(ctx context.Context, bucket, key string, data []byte, contentType string) error
GetObject(ctx context.Context, bucket, key string) ([]byte, string, error)
DeleteObject(ctx context.Context, bucket, key string) error
Close() error
}
S3Client abstracts the S3 operations needed by the portal toolkit.
func NewS3ClientAdapter ¶
NewS3ClientAdapter creates an S3Client backed by an mcp-s3 Client.
type ShareStore ¶
type ShareStore interface {
}
ShareStore persists and queries share links.
func NewNoopShareStore ¶
func NewNoopShareStore() ShareStore
NewNoopShareStore creates a no-op ShareStore for use when no database is available.
func NewPostgresShareStore ¶
func NewPostgresShareStore(db *sql.DB) ShareStore
NewPostgresShareStore creates a new PostgreSQL share store.
type ShareSummary ¶ added in v0.37.0
type ShareSummary struct {
}
ShareSummary indicates what kinds of active shares exist for an asset.
type SharedAsset ¶
type SharedAsset struct {
}
SharedAsset combines an Asset with share metadata for "shared with me" results.