Documentation
¶
Overview ¶
Package extensions — adapters.go bridges external service interfaces to the applier's narrower interfaces. This avoids importing heavy plugin packages directly.
Package extensions — applier.go implements content application logic. When a campaign owner enables an extension, the applier reads the manifest's contributes section and creates the declared content (entity types, tags, entity packs) in the campaign. All created records are tracked via provenance so they can be identified and optionally removed on uninstall.
Package extensions manages user-installable content extensions. Extensions are declarative content packs (no code execution) that provide calendar presets, entity type templates, entity packs, tag collections, marker icon packs, themes, and reference data. Site admins install extensions; campaign owners enable them per-campaign.
Index ¶
- Constants
- Variables
- func ExtensionTablePrefix(slug string) string
- func ParseExtensionSQL(slug, sql string) ([]string, error)
- func RegisterAdminRoutes(adminGroup *echo.Group, h *Handler, reauth echo.MiddlewareFunc)
- func RegisterAssetRoutes(e *echo.Echo, h *Handler)
- func RegisterCampaignRoutes(e *echo.Echo, h *Handler, campaignSvc campaigns.CampaignService, ...)
- func RegisterWASMAdminRoutes(adminGroup *echo.Group, wh *WASMHandler)
- func RegisterWASMCampaignRoutes(e *echo.Echo, wh *WASMHandler, campaignSvc campaigns.CampaignService, ...)
- func ValidateCSS(content []byte) error
- func ValidateExtensionSQL(slug, sql string) error
- func ValidateExtractedFiles(dir string) error
- func ValidateManifest(m *ExtensionManifest) error
- func ValidateSVG(content []byte) error
- func ValidateZipEntry(name string) error
- func WithCampaignID(ctx context.Context, campaignID string) context.Context
- func WithExtensionID(ctx context.Context, extID string) context.Context
- type ActivityRecorder
- type CalendarPreset
- type CalendarReader
- type CalendarWriter
- type CampaignExtension
- type ContentApplier
- type EntityPack
- type EntityReader
- type EntityTypeCreateInput
- type EntityTypeCreator
- type EntityTypeResult
- type EntityTypeTemplate
- type EntityWriter
- type Extension
- type ExtensionData
- type ExtensionManifest
- type ExtensionMigration
- type ExtensionRepository
- type ExtensionService
- type Handler
- func (h *Handler) DisableExtension(c *echo.Context) error
- func (h *Handler) EnableExtension(c *echo.Context) error
- func (h *Handler) GetExtension(c *echo.Context) error
- func (h *Handler) GetWidgetBlockInfos(ctx context.Context, campaignID string) []WidgetBlockInfo
- func (h *Handler) GetWidgetScriptURLs(ctx context.Context, campaignID string) []string
- func (h *Handler) InstallExtension(c *echo.Context) error
- func (h *Handler) ListCampaignExtensions(c *echo.Context) error
- func (h *Handler) ListExtensions(c *echo.Context) error
- func (h *Handler) ListMarkerIcons(c *echo.Context) error
- func (h *Handler) ListThemes(c *echo.Context) error
- func (h *Handler) ListWidgets(c *echo.Context) error
- func (h *Handler) PreviewExtension(c *echo.Context) error
- func (h *Handler) RenderCampaignExtensionList(ctx context.Context, cc *campaigns.CampaignContext) (templ.Component, error)
- func (h *Handler) RescanExtensions(c *echo.Context) error
- func (h *Handler) ServeAsset(c *echo.Context) error
- func (h *Handler) SetActivityRecorder(r ActivityRecorder)
- func (h *Handler) UninstallExtension(c *echo.Context) error
- func (h *Handler) UpdateExtension(c *echo.Context) error
- type HookDispatcher
- func (d *HookDispatcher) Dispatch(ctx context.Context, event HookEvent)
- func (d *HookDispatcher) DispatchCalendarEventCreated(ctx context.Context, campaignID string, payload json.RawMessage)
- func (d *HookDispatcher) DispatchCalendarEventDeleted(ctx context.Context, campaignID string, payload json.RawMessage)
- func (d *HookDispatcher) DispatchCalendarEventUpdated(ctx context.Context, campaignID string, payload json.RawMessage)
- func (d *HookDispatcher) DispatchCampaignDeleted(ctx context.Context, campaignID string)
- func (d *HookDispatcher) DispatchEntityCreated(ctx context.Context, campaignID string, payload json.RawMessage)
- func (d *HookDispatcher) DispatchEntityDeleted(ctx context.Context, campaignID string, payload json.RawMessage)
- func (d *HookDispatcher) DispatchEntityUpdated(ctx context.Context, campaignID string, payload json.RawMessage)
- func (d *HookDispatcher) DispatchTagAdded(ctx context.Context, campaignID string, payload json.RawMessage)
- func (d *HookDispatcher) DispatchTagRemoved(ctx context.Context, campaignID string, payload json.RawMessage)
- type HookEvent
- type HostEnvironment
- func (h *HostEnvironment) BuildHostFunctions(capabilities map[string]bool) []extism.HostFunction
- func (h *HostEnvironment) ClearCallContext(extID, slug string)
- func (h *HostEnvironment) DrainLogs(extID, slug string) []string
- func (h *HostEnvironment) SetCalendarWriter(w CalendarWriter)
- func (h *HostEnvironment) SetCallContext(extID, slug, campaignID string)
- func (h *HostEnvironment) SetEntityWriter(w EntityWriter)
- func (h *HostEnvironment) SetPluginManager(pm *PluginManager)
- func (h *HostEnvironment) SetRelationWriter(w RelationWriter)
- func (h *HostEnvironment) SetTagWriter(w TagWriter)
- type KVStore
- type ManifestAuthor
- type ManifestCompat
- type ManifestContributes
- type ManifestDependency
- type MarkerIcon
- type MarkerIconPack
- type MigrationRunner
- func (r *MigrationRunner) DropExtensionTables(ctx context.Context, slug string, others []string) error
- func (r *MigrationRunner) GetAppliedVersions(ctx context.Context, extensionID string) ([]int, error)
- func (r *MigrationRunner) RunDown(ctx context.Context, extensionID, slug string, migrations []ExtensionMigration) error
- func (r *MigrationRunner) RunUp(ctx context.Context, extensionID, slug string, migrations []ExtensionMigration) error
- type PackEntityCreator
- type PackEntry
- type PluginManager
- func (pm *PluginManager) Call(ctx context.Context, extID, slug, function string, input json.RawMessage) (*WASMCallResponse, error)
- func (pm *PluginManager) GetPlugin(extID, slug string) (*WASMPluginInfo, bool)
- func (pm *PluginManager) ListPlugins() []WASMPluginInfo
- func (pm *PluginManager) Load(ctx context.Context, extID string, contrib WASMContribution) error
- func (pm *PluginManager) PluginsForHook(hookType string) []pluginHookTarget
- func (pm *PluginManager) Reload(ctx context.Context, extID, slug string) error
- func (pm *PluginManager) Unload(ctx context.Context, extID, slug string) error
- func (pm *PluginManager) UnloadAll(ctx context.Context)
- type Provenance
- type ReferenceCategory
- type ReferenceDataPack
- type RelationType
- type RelationWriter
- type TagCollection
- type TagCreator
- type TagReader
- type TagResult
- type TagTemplate
- type TagWriter
- type TemplateField
- type Theme
- type WASMCallRequest
- type WASMCallResponse
- type WASMCapability
- type WASMConfigField
- type WASMContribution
- type WASMHandler
- func (h *WASMHandler) CallWASMPlugin(c *echo.Context) error
- func (h *WASMHandler) GetWASMPlugin(c *echo.Context) error
- func (h *WASMHandler) ListCampaignWASMPlugins(c *echo.Context) error
- func (h *WASMHandler) ListWASMPlugins(c *echo.Context) error
- func (h *WASMHandler) ReloadWASMPlugin(c *echo.Context) error
- func (h *WASMHandler) SetActivityRecorder(r ActivityRecorder)
- func (h *WASMHandler) StopWASMPlugin(c *echo.Context) error
- type WASMLimits
- type WASMPlugin
- type WASMPluginInfo
- type WASMPluginLoader
- type WidgetBlockInfo
- type WidgetConfigField
- type WidgetContribution
Constants ¶
const ( StatusActive = "active" StatusDisabled = "disabled" )
ExtensionStatus constants.
const ( DefaultMaxZipSize = 50 * 1024 * 1024 // 50 MB. DefaultMaxExtractedSize = 100 * 1024 * 1024 // 100 MB. DefaultMaxFiles = 1000 DefaultMaxFileSize = 20 * 1024 * 1024 // 20 MB per file. DefaultMaxCSSSize = 500 * 1024 // 500 KB per CSS file. DefaultMaxEntityPack = 10000 // Max entities in a pack. )
Security limits for extension installation.
const ( WASMStatusLoaded = "loaded" WASMStatusStopped = "stopped" WASMStatusError = "error" )
WASMPluginStatus constants.
const ( HookEntityCreated = "entity.created" HookEntityUpdated = "entity.updated" HookEntityDeleted = "entity.deleted" HookCalendarEventCreated = "calendar.event_created" HookCalendarEventUpdated = "calendar.event_updated" HookCalendarEventDeleted = "calendar.event_deleted" HookTagAdded = "tag.added" HookTagRemoved = "tag.removed" HookCampaignDeleted = "campaign.deleted" )
Hook event type constants.
Variables ¶
var AllCapabilities = map[string]bool{ string(CapLog): true, string(CapEntityRead): true, string(CapEntityWrite): true, string(CapCalendarRead): true, string(CapCalendarWrite): true, string(CapTagRead): true, string(CapTagWrite): true, string(CapRelationWrite): true, string(CapKVStore): true, string(CapMessage): true, }
AllCapabilities lists all valid capability strings for validation.
var ValidHookTypes = map[string]bool{ HookEntityCreated: true, HookEntityUpdated: true, HookEntityDeleted: true, HookCalendarEventCreated: true, HookCalendarEventUpdated: true, HookCalendarEventDeleted: true, HookTagAdded: true, HookTagRemoved: true, HookCampaignDeleted: true, }
ValidHookTypes lists all valid hook event types.
Functions ¶
func ExtensionTablePrefix ¶
ExtensionTablePrefix is the prefix every table of the extension with this slug carries.
func ParseExtensionSQL ¶
ParseExtensionSQL checks an extension migration against the allowlist and returns its statements as they must be executed. The first violation is returned as the error.
func RegisterAdminRoutes ¶
func RegisterAdminRoutes(adminGroup *echo.Group, h *Handler, reauth echo.MiddlewareFunc)
RegisterAdminRoutes adds extension management routes to the admin group. All routes require site admin authentication; installing, replacing or uninstalling also needs a recent password confirmation (reauth), since it changes what code every campaign can run.
func RegisterAssetRoutes ¶
RegisterAssetRoutes adds the static asset serving route. This is public (assets are referenced in CSS/HTML for all users).
func RegisterCampaignRoutes ¶
func RegisterCampaignRoutes(e *echo.Echo, h *Handler, campaignSvc campaigns.CampaignService, authSvc auth.AuthService)
RegisterCampaignRoutes adds per-campaign extension routes. Requires campaign Owner role for enable/disable operations.
func RegisterWASMAdminRoutes ¶
func RegisterWASMAdminRoutes(adminGroup *echo.Group, wh *WASMHandler)
RegisterWASMAdminRoutes adds WASM plugin management routes to the admin group. All routes require site admin authentication.
func RegisterWASMCampaignRoutes ¶
func RegisterWASMCampaignRoutes(e *echo.Echo, wh *WASMHandler, campaignSvc campaigns.CampaignService, authSvc auth.AuthService)
RegisterWASMCampaignRoutes adds per-campaign WASM plugin routes. Requires campaign membership for listing and Scribe+ for calling.
func ValidateCSS ¶
ValidateCSS checks that extension CSS is safe (no @import, no external url(), no expression(), no behavior:).
func ValidateExtensionSQL ¶
ValidateExtensionSQL reports whether an extension migration passes the allowlist.
func ValidateExtractedFiles ¶
ValidateExtractedFiles performs post-extraction validation on content files. Checks CSS and SVG files for unsafe content.
func ValidateManifest ¶
func ValidateManifest(m *ExtensionManifest) error
ValidateManifest checks that a manifest has all required fields and valid values.
func ValidateSVG ¶
ValidateSVG checks that an SVG file doesn't contain embedded scripts by parsing it as XML. This is more robust than string matching because it handles character encoding, CDATA sections, XML entities, and other tricks that can bypass regex-based detection.
func ValidateZipEntry ¶
ValidateZipEntry checks that a zip entry path is safe (no traversal, no absolute paths, allowed file type).
func WithCampaignID ¶
WithCampaignID returns a context with the campaign ID set for WASM calls.
Types ¶
type ActivityRecorder ¶
type ActivityRecorder interface {
RecordAdminChange(c *echo.Context, action, targetType, targetID, label string)
}
ActivityRecorder is the slice of the admin change log this plugin writes to. It is declared here, not imported from the admin plugin, so the plugins stay independent; app wiring supplies an adapter that stamps the signed-in admin. Recording is best-effort: implementations must not fail the request.
type CalendarPreset ¶
type CalendarPreset struct {
Slug string `json:"slug"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
File string `json:"file"` // Relative path to JSON file.
}
CalendarPreset is a complete calendar configuration.
type CalendarReader ¶
type CalendarReader interface {
GetCalendarJSON(ctx context.Context, campaignID string) (json.RawMessage, error)
ListEventsJSON(ctx context.Context, campaignID string, limit int) (json.RawMessage, error)
}
CalendarReader provides read-only access to calendar data for WASM host functions.
func NewWASMCalendarAdapter ¶
func NewWASMCalendarAdapter( getCalendar func(ctx context.Context, campaignID string) (json.RawMessage, error), listEvents func(ctx context.Context, campaignID string, limit int) (json.RawMessage, error), ) CalendarReader
NewWASMCalendarAdapter creates a CalendarReader from function closures.
type CalendarWriter ¶
type CalendarWriter interface {
CreateEventJSON(ctx context.Context, campaignID string, input json.RawMessage) (json.RawMessage, error)
}
CalendarWriter provides write access to calendar events for WASM host functions.
func NewWASMCalendarWriteAdapter ¶
func NewWASMCalendarWriteAdapter( createEvent func(ctx context.Context, campaignID string, input json.RawMessage) (json.RawMessage, error), ) CalendarWriter
NewWASMCalendarWriteAdapter creates a CalendarWriter from a function closure.
type CampaignExtension ¶
type CampaignExtension struct {
CampaignID string `json:"campaign_id"`
ExtensionID string `json:"extension_id"`
Enabled bool `json:"enabled"`
AppliedContents json.RawMessage `json:"applied_contents,omitempty"` // Tracks which contributes were imported.
EnabledAt time.Time `json:"enabled_at"`
EnabledBy *string `json:"enabled_by,omitempty"`
// Joined fields for display.
ExtID string `json:"ext_id,omitempty"`
ExtName string `json:"ext_name,omitempty"`
ExtVersion string `json:"ext_version,omitempty"`
ExtStatus string `json:"ext_status,omitempty"`
}
CampaignExtension tracks per-campaign extension activation.
type ContentApplier ¶
type ContentApplier interface {
// Apply reads the extension manifest and creates content in the campaign.
// userID is the owner who turned the extension on; created pages are theirs.
Apply(ctx context.Context, campaignID, userID string, ext *Extension, manifest *ExtensionManifest) error
// SetWASMLoader injects the WASM plugin loader for auto-loading plugins.
SetWASMLoader(loader WASMPluginLoader)
// SetPackEntityCreator injects the page creator entity packs need.
SetPackEntityCreator(creator PackEntityCreator)
}
ContentApplier applies extension content to a campaign when enabled. Implementations call out to other domain services (entities, tags, etc.) and record provenance for each created record.
func NewContentApplier ¶
func NewContentApplier( extDir string, repo ExtensionRepository, entityTypes EntityTypeCreator, tags TagCreator, ) ContentApplier
NewContentApplier creates an applier with the given service dependencies. Pass nil for any service that isn't available (the applier will skip those content types).
type EntityPack ¶
type EntityPack struct {
Slug string `json:"slug"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
EntityTypeSlug string `json:"entity_type_slug"`
File string `json:"file"` // Relative path to JSON file.
Count int `json:"count,omitempty"`
}
EntityPack is a collection of pre-made entities.
type EntityReader ¶
type EntityReader interface {
GetEntityJSON(ctx context.Context, campaignID, entityID string) (json.RawMessage, error)
SearchEntitiesJSON(ctx context.Context, campaignID, query string, limit int) (json.RawMessage, error)
ListEntityTypesJSON(ctx context.Context, campaignID string) (json.RawMessage, error)
}
EntityReader provides read-only access to entities for WASM host functions. Here and in the writers below, campaignID is the campaign the extension was called for; an implementation must refuse any entity outside it, since the entity ids come from the extension.
func NewWASMEntityAdapter ¶
func NewWASMEntityAdapter( getByID func(ctx context.Context, campaignID, id string) (json.RawMessage, error), search func(ctx context.Context, campaignID, query string, limit int) (json.RawMessage, error), listTypes func(ctx context.Context, campaignID string) (json.RawMessage, error), ) EntityReader
NewWASMEntityAdapter creates an EntityReader from function closures.
type EntityTypeCreateInput ¶
type EntityTypeCreateInput struct {
Name string
NamePlural string
Icon string
Color string
PresetCategory string // Optional preset category (e.g., "character", "item").
}
EntityTypeCreateInput mirrors entities.CreateEntityTypeInput to avoid importing the entities package directly.
type EntityTypeCreator ¶
type EntityTypeCreator interface {
CreateEntityType(ctx context.Context, campaignID string, input EntityTypeCreateInput) (EntityTypeResult, error)
}
EntityTypeCreator is the subset of the entity service needed by the applier.
func NewEntityTypeAdapter ¶
func NewEntityTypeAdapter( create func(ctx context.Context, campaignID string, name, namePlural, icon, color, presetCategory string) (int, string, error), ) EntityTypeCreator
NewEntityTypeAdapter creates an adapter from a creation function. The caller extracts the function from the concrete entity service.
type EntityTypeResult ¶
EntityTypeResult is the minimal result needed from entity type creation.
type EntityTypeTemplate ¶
type EntityTypeTemplate struct {
Slug string `json:"slug"`
Name string `json:"name"`
NamePlural string `json:"name_plural"`
Icon string `json:"icon"`
Color string `json:"color"`
Category string `json:"category,omitempty"` // Preset category (e.g., "character", "item", "creature").
Fields []TemplateField `json:"fields,omitempty"`
}
EntityTypeTemplate is a pre-configured entity type with fields.
type EntityWriter ¶
type EntityWriter interface {
UpdateFieldsJSON(ctx context.Context, campaignID, entityID string, fieldsData json.RawMessage) error
}
EntityWriter provides write access to entity fields for WASM host functions.
func NewWASMEntityWriteAdapter ¶
func NewWASMEntityWriteAdapter( updateFields func(ctx context.Context, campaignID, entityID string, fieldsData json.RawMessage) error, ) EntityWriter
NewWASMEntityWriteAdapter creates an EntityWriter from a function closure.
type Extension ¶
type Extension struct {
ID string `json:"id"`
ExtID string `json:"ext_id"` // Manifest ID (e.g., "dnd5e-srd-monsters").
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Manifest json.RawMessage `json:"manifest"` // Full manifest.json for reference.
InstalledBy string `json:"installed_by"`
Status string `json:"status"` // "active" or "disabled".
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Extension represents an installed content extension (site-wide).
type ExtensionData ¶
type ExtensionData struct {
ID int64 `json:"id"`
CampaignID string `json:"campaign_id"`
ExtensionID string `json:"extension_id"`
Namespace string `json:"namespace"` // e.g., "relation_types", "marker_icons".
DataKey string `json:"data_key"`
DataValue json.RawMessage `json:"data_value"`
}
ExtensionData holds extension-specific key-value data that doesn't fit existing tables (e.g., relation type suggestions, marker icon metadata).
type ExtensionManifest ¶
type ExtensionManifest struct {
ManifestVersion int `json:"manifest_version"`
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Author *ManifestAuthor `json:"author,omitempty"`
License string `json:"license,omitempty"`
Homepage string `json:"homepage,omitempty"`
Repository string `json:"repository,omitempty"`
Keywords []string `json:"keywords,omitempty"`
Icon string `json:"icon,omitempty"`
Compatibility *ManifestCompat `json:"compatibility,omitempty"`
RequiresAddons []string `json:"requires_addons,omitempty"`
Dependencies []ManifestDependency `json:"dependencies,omitempty"`
Conflicts []string `json:"conflicts,omitempty"`
Contributes *ManifestContributes `json:"contributes,omitempty"`
}
ExtensionManifest describes a content extension's metadata, compatibility, dependencies, and what content it contributes. Parsed from manifest.json.
func ExtractZip ¶
func ExtractZip(zipPath, targetDir string) (*ExtensionManifest, error)
ExtractZip safely extracts a zip file to the target directory. Validates every entry for path safety and file type. Returns the parsed manifest from the extracted contents.
func ParseManifest ¶
func ParseManifest(data []byte) (*ExtensionManifest, error)
ParseManifest parses and validates a manifest.json byte slice.
type ExtensionMigration ¶
type ExtensionMigration struct {
Version int // Sequential version number (1, 2, 3...).
UpSQL string // SQL to apply (create tables, add columns, etc.).
DownSQL string // SQL to reverse (drop tables, remove columns, etc.).
}
ExtensionMigration represents a single numbered migration for an extension.
func ParseMigrations ¶
func ParseMigrations(dir string) ([]ExtensionMigration, error)
ParseMigrations reads numbered SQL migration files from a directory. Files must follow the pattern NNN_description.up.sql / NNN_description.down.sql. Returns migrations sorted by version number.
type ExtensionRepository ¶
type ExtensionRepository interface {
// Extension CRUD.
Create(ctx context.Context, ext *Extension) error
FindByID(ctx context.Context, id string) (*Extension, error)
FindByExtID(ctx context.Context, extID string) (*Extension, error)
List(ctx context.Context) ([]Extension, error)
UpdateVersion(ctx context.Context, id, version string, manifest json.RawMessage) error
UpdateStatus(ctx context.Context, id, status string) error
Delete(ctx context.Context, id string) error
// Campaign extension CRUD.
EnableForCampaign(ctx context.Context, ce *CampaignExtension) error
DisableForCampaign(ctx context.Context, campaignID, extensionID string) error
GetCampaignExtension(ctx context.Context, campaignID, extensionID string) (*CampaignExtension, error)
ListForCampaign(ctx context.Context, campaignID string) ([]CampaignExtension, error)
UpdateAppliedContents(ctx context.Context, campaignID, extensionID string, contents json.RawMessage) error
CountCampaignsUsing(ctx context.Context, extensionID string) (int, error)
RemoveFromAllCampaigns(ctx context.Context, extensionID string) error
// Provenance tracking.
CreateProvenance(ctx context.Context, p *Provenance) error
CreateProvenanceBatch(ctx context.Context, records []Provenance) error
ListProvenance(ctx context.Context, campaignID, extensionID string) ([]Provenance, error)
DeleteProvenance(ctx context.Context, campaignID, extensionID string) error
// Extension data.
SetData(ctx context.Context, d *ExtensionData) error
GetData(ctx context.Context, campaignID, extensionID, namespace, key string) (*ExtensionData, error)
ListData(ctx context.Context, campaignID, extensionID, namespace string) ([]ExtensionData, error)
DeleteData(ctx context.Context, campaignID, extensionID string) error
DeleteDataByKey(ctx context.Context, campaignID, extensionID, namespace, key string) error
}
ExtensionRepository handles persistence for extensions and related tables.
func NewExtensionRepository ¶
func NewExtensionRepository(db *sql.DB) ExtensionRepository
NewExtensionRepository creates a new extension repository.
type ExtensionService ¶
type ExtensionService interface {
// Admin operations (site-wide).
Install(ctx context.Context, zipPath, userID string) (*Extension, error)
Uninstall(ctx context.Context, extID string) error
Update(ctx context.Context, zipPath, extID string) (*Extension, error)
List(ctx context.Context) ([]Extension, error)
GetByExtID(ctx context.Context, extID string) (*Extension, error)
Rescan(ctx context.Context) (int, error)
// Campaign operations.
ListForCampaign(ctx context.Context, campaignID string) ([]CampaignExtension, error)
EnableForCampaign(ctx context.Context, campaignID, extID, userID string) error
DisableForCampaign(ctx context.Context, campaignID, extID string) error
GetCampaignExtension(ctx context.Context, campaignID, extID string) (*CampaignExtension, error)
PreviewContributes(ctx context.Context, extID string) (*ManifestContributes, error)
// LoadEnabledPlugins loads the WASM plugins of every active extension a
// campaign has enabled. Plugins live only in memory, so this runs at
// startup; it returns how many loaded.
LoadEnabledPlugins(ctx context.Context, loader WASMPluginLoader) int
// Provenance.
RecordProvenance(ctx context.Context, campaignID, extensionID, tableName, recordID, recordType string) error
ListProvenance(ctx context.Context, campaignID, extensionID string) ([]Provenance, error)
// Extension data.
SetData(ctx context.Context, campaignID, extensionID, namespace, key string, value json.RawMessage) error
ListData(ctx context.Context, campaignID, extensionID, namespace string) ([]ExtensionData, error)
// Configuration.
SetApplier(applier ContentApplier)
SetMigrationRunner(runner *MigrationRunner)
}
ExtensionService handles business logic for extension management.
func NewExtensionService ¶
func NewExtensionService(repo ExtensionRepository, extDir string) ExtensionService
NewExtensionService creates a new extension service.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves HTTP endpoints for extension management.
func NewHandler ¶
func NewHandler(svc ExtensionService, extDir string) *Handler
NewHandler creates a new extension handler.
func (*Handler) DisableExtension ¶
DisableExtension disables an extension for a campaign. POST /campaigns/:id/extensions/:extID/disable
func (*Handler) EnableExtension ¶
EnableExtension enables an extension for a campaign. POST /campaigns/:id/extensions/:extID/enable
func (*Handler) GetExtension ¶
GetExtension returns details for a single extension. GET /admin/extensions/:extID
func (*Handler) GetWidgetBlockInfos ¶
func (h *Handler) GetWidgetBlockInfos(ctx context.Context, campaignID string) []WidgetBlockInfo
GetWidgetBlockInfos returns metadata for all enabled extension widgets in a campaign, suitable for populating the template editor's block palette.
func (*Handler) GetWidgetScriptURLs ¶
GetWidgetScriptURLs returns the script URLs for all enabled extension widgets in a campaign. Used by the layout injector to inject <script> tags.
func (*Handler) InstallExtension ¶
InstallExtension handles zip upload for installing a new extension. POST /admin/extensions/install
func (*Handler) ListCampaignExtensions ¶
ListCampaignExtensions returns extensions available for a campaign. GET /campaigns/:id/extensions
func (*Handler) ListExtensions ¶
ListExtensions returns all installed extensions and built-in game systems. GET /admin/extensions
func (*Handler) ListMarkerIcons ¶
ListMarkerIcons returns all extension marker icon packs for a campaign. GET /campaigns/:id/extensions/marker-icons
func (*Handler) ListThemes ¶
ListThemes returns all extension themes for a campaign. GET /campaigns/:id/extensions/themes
func (*Handler) ListWidgets ¶
ListWidgets returns all extension widgets for a campaign. GET /campaigns/:id/extensions/widgets
func (*Handler) PreviewExtension ¶
PreviewExtension returns what an extension will contribute when enabled. GET /campaigns/:id/extensions/:extID/preview
func (*Handler) RenderCampaignExtensionList ¶
func (h *Handler) RenderCampaignExtensionList(ctx context.Context, cc *campaigns.CampaignContext) (templ.Component, error)
RenderCampaignExtensionList loads the per-campaign installed Content Packs and returns the list-fragment templ component for the campaigns plugin to embed in its Extensions hub. Implements `campaigns.ContentPacksCardRenderer`. No packs installed renders an empty list card; an error bubbles up so the hub can degrade gracefully (rendering without the Content Packs card).
func (*Handler) RescanExtensions ¶
RescanExtensions discovers extensions from the filesystem. POST /admin/extensions/rescan
func (*Handler) ServeAsset ¶
ServeAsset serves static assets from an extension's directory. GET /extensions/:extID/assets/*filepath
func (*Handler) SetActivityRecorder ¶
func (h *Handler) SetActivityRecorder(r ActivityRecorder)
SetActivityRecorder wires the admin change log. Optional: nil disables it.
func (*Handler) UninstallExtension ¶
UninstallExtension removes an extension site-wide. DELETE /admin/extensions/:extID
type HookDispatcher ¶
type HookDispatcher struct {
// contains filtered or unexported fields
}
HookDispatcher fires events to WASM plugins that have registered for them. Hooks are dispatched asynchronously in a fire-and-forget manner — plugin failures do not affect the originating operation.
func NewHookDispatcher ¶
func NewHookDispatcher(manager *PluginManager) *HookDispatcher
NewHookDispatcher creates a hook dispatcher backed by the plugin manager.
func (*HookDispatcher) Dispatch ¶
func (d *HookDispatcher) Dispatch(ctx context.Context, event HookEvent)
Dispatch sends a hook event to all loaded WASM plugins that listen for it. The dispatch runs each plugin call in a goroutine so the caller is not blocked. Errors are logged but never returned — hooks are best-effort.
A write a plugin made itself is not announced (see announced).
func (*HookDispatcher) DispatchCalendarEventCreated ¶
func (d *HookDispatcher) DispatchCalendarEventCreated(ctx context.Context, campaignID string, payload json.RawMessage)
DispatchCalendarEventCreated fires the calendar.event_created hook.
func (*HookDispatcher) DispatchCalendarEventDeleted ¶
func (d *HookDispatcher) DispatchCalendarEventDeleted(ctx context.Context, campaignID string, payload json.RawMessage)
DispatchCalendarEventDeleted fires the calendar.event_deleted hook.
func (*HookDispatcher) DispatchCalendarEventUpdated ¶
func (d *HookDispatcher) DispatchCalendarEventUpdated(ctx context.Context, campaignID string, payload json.RawMessage)
DispatchCalendarEventUpdated fires the calendar.event_updated hook.
func (*HookDispatcher) DispatchCampaignDeleted ¶
func (d *HookDispatcher) DispatchCampaignDeleted(ctx context.Context, campaignID string)
DispatchCampaignDeleted fires the campaign.deleted hook so WASM plugins can clean up in-memory caches or other campaign-scoped state.
func (*HookDispatcher) DispatchEntityCreated ¶
func (d *HookDispatcher) DispatchEntityCreated(ctx context.Context, campaignID string, payload json.RawMessage)
DispatchEntityCreated fires the entity.created hook.
func (*HookDispatcher) DispatchEntityDeleted ¶
func (d *HookDispatcher) DispatchEntityDeleted(ctx context.Context, campaignID string, payload json.RawMessage)
DispatchEntityDeleted fires the entity.deleted hook.
func (*HookDispatcher) DispatchEntityUpdated ¶
func (d *HookDispatcher) DispatchEntityUpdated(ctx context.Context, campaignID string, payload json.RawMessage)
DispatchEntityUpdated fires the entity.updated hook.
func (*HookDispatcher) DispatchTagAdded ¶
func (d *HookDispatcher) DispatchTagAdded(ctx context.Context, campaignID string, payload json.RawMessage)
DispatchTagAdded fires the tag.added hook.
func (*HookDispatcher) DispatchTagRemoved ¶
func (d *HookDispatcher) DispatchTagRemoved(ctx context.Context, campaignID string, payload json.RawMessage)
DispatchTagRemoved fires the tag.removed hook.
type HookEvent ¶
type HookEvent struct {
Type string `json:"type"` // e.g., "entity.created", "calendar.event_created".
CampaignID string `json:"campaign_id"`
Payload json.RawMessage `json:"payload"`
Timestamp time.Time `json:"timestamp"`
}
HookEvent represents an event that WASM plugins can register to receive.
type HostEnvironment ¶
type HostEnvironment struct {
// contains filtered or unexported fields
}
HostEnvironment holds the service adapters that provide data to WASM plugins through host functions. It manages per-call context (campaign ID, plugin identity) and collects plugin log output.
func NewHostEnvironment ¶
func NewHostEnvironment( entityReader EntityReader, calendarReader CalendarReader, tagReader TagReader, kvStore KVStore, ) *HostEnvironment
NewHostEnvironment creates a new host environment with the given service adapters. Write adapters are set via setter methods after construction (they may not be available during initial wiring).
func (*HostEnvironment) BuildHostFunctions ¶
func (h *HostEnvironment) BuildHostFunctions(capabilities map[string]bool) []extism.HostFunction
BuildHostFunctions creates the Extism host function definitions based on the plugin's declared capabilities. Only functions matching the capability set are included, enforcing the principle of least privilege.
func (*HostEnvironment) ClearCallContext ¶
func (h *HostEnvironment) ClearCallContext(extID, slug string)
ClearCallContext removes the call context after a plugin call completes.
func (*HostEnvironment) DrainLogs ¶
func (h *HostEnvironment) DrainLogs(extID, slug string) []string
DrainLogs returns and clears accumulated log messages for a plugin.
func (*HostEnvironment) SetCalendarWriter ¶
func (h *HostEnvironment) SetCalendarWriter(w CalendarWriter)
SetCalendarWriter injects the calendar write adapter.
func (*HostEnvironment) SetCallContext ¶
func (h *HostEnvironment) SetCallContext(extID, slug, campaignID string)
SetCallContext sets the campaign and extension context for a plugin call. Must be called before invoking a WASM function.
func (*HostEnvironment) SetEntityWriter ¶
func (h *HostEnvironment) SetEntityWriter(w EntityWriter)
SetEntityWriter injects the entity write adapter.
func (*HostEnvironment) SetPluginManager ¶
func (h *HostEnvironment) SetPluginManager(pm *PluginManager)
SetPluginManager sets the back-reference for plugin-to-plugin messaging.
func (*HostEnvironment) SetRelationWriter ¶
func (h *HostEnvironment) SetRelationWriter(w RelationWriter)
SetRelationWriter injects the relation write adapter.
func (*HostEnvironment) SetTagWriter ¶
func (h *HostEnvironment) SetTagWriter(w TagWriter)
SetTagWriter injects the tag write adapter.
type KVStore ¶
type KVStore interface {
Get(ctx context.Context, campaignID, extensionID, key string) (json.RawMessage, error)
Set(ctx context.Context, campaignID, extensionID, key string, value json.RawMessage) error
Delete(ctx context.Context, campaignID, extensionID, key string) error
}
KVStore provides per-plugin key-value storage backed by the extension_data table.
func NewKVStore ¶
func NewKVStore(repo ExtensionRepository) KVStore
NewKVStore creates a KV store backed by the extension_data repository.
type ManifestAuthor ¶
type ManifestAuthor struct {
Name string `json:"name"`
Email string `json:"email,omitempty"`
URL string `json:"url,omitempty"`
}
ManifestAuthor identifies the extension creator.
type ManifestCompat ¶
type ManifestCompat struct {
Minimum string `json:"minimum"`
Maximum string `json:"maximum,omitempty"`
Verified string `json:"verified,omitempty"`
}
ManifestCompat specifies Chronicle version requirements.
type ManifestContributes ¶
type ManifestContributes struct {
EntityTypeTemplates []EntityTypeTemplate `json:"entity_type_templates,omitempty"`
EntityPacks []EntityPack `json:"entity_packs,omitempty"`
CalendarPresets []CalendarPreset `json:"calendar_presets,omitempty"`
TagCollections []TagCollection `json:"tag_collections,omitempty"`
RelationTypes []RelationType `json:"relation_types,omitempty"`
MarkerIconPacks []MarkerIconPack `json:"marker_icon_packs,omitempty"`
Themes []Theme `json:"themes,omitempty"`
ReferenceData []ReferenceDataPack `json:"reference_data,omitempty"`
Widgets []WidgetContribution `json:"widgets,omitempty"`
WASMPlugins []WASMContribution `json:"wasm_plugins,omitempty"`
}
ManifestContributes declares what content this extension provides. Follows the VS Code "contributes" pattern.
type ManifestDependency ¶
ManifestDependency specifies another extension this one depends on.
type MarkerIcon ¶
type MarkerIcon struct {
ID string `json:"id"`
Name string `json:"name"`
File string `json:"file"` // Relative path to SVG/PNG.
}
MarkerIcon defines a single custom marker icon.
type MarkerIconPack ¶
type MarkerIconPack struct {
Slug string `json:"slug"`
Name string `json:"name"`
Icons []MarkerIcon `json:"icons"`
}
MarkerIconPack is a set of custom map marker icons.
type MigrationRunner ¶
type MigrationRunner struct {
// contains filtered or unexported fields
}
MigrationRunner manages per-extension schema migrations. It runs numbered SQL files from an extension's migrations/ directory, tracks applied versions in extension_schema_versions, and validates all SQL through the security validator to prevent modifications to core tables.
func NewMigrationRunner ¶
func NewMigrationRunner(db *sql.DB) *MigrationRunner
NewMigrationRunner creates a migration runner backed by the given database.
func (*MigrationRunner) DropExtensionTables ¶
func (r *MigrationRunner) DropExtensionTables(ctx context.Context, slug string, others []string) error
DropExtensionTables drops all tables prefixed with ext_<slug>_ as a safety net during uninstall. This catches any tables that weren't covered by down migrations. A table that carries the longer prefix of another installed extension (others) is that extension's and is kept.
func (*MigrationRunner) GetAppliedVersions ¶
func (r *MigrationRunner) GetAppliedVersions(ctx context.Context, extensionID string) ([]int, error)
GetAppliedVersions returns all version numbers applied for an extension, sorted ascending.
func (*MigrationRunner) RunDown ¶
func (r *MigrationRunner) RunDown(ctx context.Context, extensionID, slug string, migrations []ExtensionMigration) error
RunDown reverses all applied migrations in descending version order. Each down migration's SQL is validated before execution.
func (*MigrationRunner) RunUp ¶
func (r *MigrationRunner) RunUp(ctx context.Context, extensionID, slug string, migrations []ExtensionMigration) error
RunUp applies unapplied migrations in order. Each migration's SQL is validated against the extension slug before execution to prevent core table modifications.
type PackEntityCreator ¶
type PackEntityCreator interface {
// EntityTypeIDBySlug finds a campaign's entity type by slug.
EntityTypeIDBySlug(ctx context.Context, campaignID, slug string) (int, error)
// CreatePackEntity creates one page. It returns the new page's id even
// when the page was created but its body could not be saved.
CreatePackEntity(ctx context.Context, campaignID, userID string, typeID int, e PackEntry) (string, error)
}
PackEntityCreator creates the pages an entity pack holds. Implemented in internal/app over the entities service.
type PackEntry ¶
type PackEntry struct {
Name string `json:"name"`
TypeLabel string `json:"type_label,omitempty"`
Entry string `json:"entry,omitempty"` // Markdown body.
Fields map[string]any `json:"fields,omitempty"` // Custom field values by key.
// Private defaults to true: a pack may hold spoilers, so its pages start
// GM-only and the owner reveals them. "private": false opts out.
Private *bool `json:"private,omitempty"`
}
PackEntry is one page in an entity pack file. The file is a JSON array of these.
type PluginManager ¶
type PluginManager struct {
// contains filtered or unexported fields
}
PluginManager manages the lifecycle of WASM logic extensions. It loads, unloads, and calls WASM plugins via the Extism SDK with capability-based security: each plugin only receives host functions matching its declared capabilities.
func NewPluginManager ¶
func NewPluginManager(extDir string, hostEnv *HostEnvironment) *PluginManager
NewPluginManager creates a new WASM plugin manager.
func (*PluginManager) Call ¶
func (pm *PluginManager) Call(ctx context.Context, extID, slug, function string, input json.RawMessage) (*WASMCallResponse, error)
Call invokes a named function on a WASM plugin with the given input. The call is wrapped with a timeout derived from the plugin's limits.
func (*PluginManager) GetPlugin ¶
func (pm *PluginManager) GetPlugin(extID, slug string) (*WASMPluginInfo, bool)
GetPlugin returns info about a specific plugin.
func (*PluginManager) ListPlugins ¶
func (pm *PluginManager) ListPlugins() []WASMPluginInfo
ListPlugins returns info about all loaded plugins.
func (*PluginManager) Load ¶
func (pm *PluginManager) Load(ctx context.Context, extID string, contrib WASMContribution) error
Load loads a WASM plugin from its extension directory. The plugin is instantiated with only the host functions matching its declared capabilities.
func (*PluginManager) PluginsForHook ¶
func (pm *PluginManager) PluginsForHook(hookType string) []pluginHookTarget
PluginsForHook returns all loaded plugins that listen for a given hook event type.
func (*PluginManager) Reload ¶
func (pm *PluginManager) Reload(ctx context.Context, extID, slug string) error
Reload unloads and reloads a plugin from disk.
func (*PluginManager) Unload ¶
func (pm *PluginManager) Unload(ctx context.Context, extID, slug string) error
Unload stops and removes a WASM plugin.
func (*PluginManager) UnloadAll ¶
func (pm *PluginManager) UnloadAll(ctx context.Context)
UnloadAll stops all loaded WASM plugins. Called during graceful shutdown.
type Provenance ¶
type Provenance struct {
ID int64 `json:"id"`
CampaignID string `json:"campaign_id"`
ExtensionID string `json:"extension_id"`
TableName string `json:"table_name"` // e.g., "entity_types", "entities", "tags".
RecordID string `json:"record_id"` // PK of the created record.
RecordType string `json:"record_type"` // Sub-type hint (e.g., "entity_pack:srd-monsters").
CreatedAt time.Time `json:"created_at"`
}
Provenance tracks which extension created which database record. Enables clean uninstall and "provided by extension X" attribution.
type ReferenceCategory ¶
type ReferenceCategory struct {
Slug string `json:"slug"`
Name string `json:"name"`
Icon string `json:"icon,omitempty"`
File string `json:"file"` // Relative path to JSON file.
}
ReferenceCategory defines a category within a reference data pack.
type ReferenceDataPack ¶
type ReferenceDataPack struct {
Slug string `json:"slug"`
Name string `json:"name"`
Categories []ReferenceCategory `json:"categories"`
}
ReferenceDataPack extends the module system with additional reference data.
type RelationType ¶
type RelationType struct {
Type string `json:"type"`
ReverseType string `json:"reverse_type"`
Description string `json:"description,omitempty"`
}
RelationType defines a suggested relation type pair.
type RelationWriter ¶
type RelationWriter interface {
CreateRelationJSON(ctx context.Context, campaignID string, input json.RawMessage) (json.RawMessage, error)
}
RelationWriter provides write access to entity relations for WASM host functions.
func NewWASMRelationWriteAdapter ¶
func NewWASMRelationWriteAdapter( createRelation func(ctx context.Context, campaignID string, input json.RawMessage) (json.RawMessage, error), ) RelationWriter
NewWASMRelationWriteAdapter creates a RelationWriter from a function closure.
type TagCollection ¶
type TagCollection struct {
Slug string `json:"slug"`
Name string `json:"name"`
Tags []TagTemplate `json:"tags"`
}
TagCollection is a set of pre-defined tags.
type TagCreator ¶
type TagCreator interface {
CreateTag(ctx context.Context, campaignID string, name, color string, dmOnly bool) (TagResult, error)
}
TagCreator is the subset of the tag service needed by the applier.
func NewTagAdapter ¶
func NewTagAdapter( create func(ctx context.Context, campaignID string, name, color string, dmOnly bool) (int, error), ) TagCreator
NewTagAdapter creates an adapter from a creation function.
type TagReader ¶
type TagReader interface {
ListTagsJSON(ctx context.Context, campaignID string) (json.RawMessage, error)
}
TagReader provides read-only access to tags for WASM host functions.
func NewWASMTagAdapter ¶
func NewWASMTagAdapter( listTags func(ctx context.Context, campaignID string) (json.RawMessage, error), ) TagReader
NewWASMTagAdapter creates a TagReader from a function closure.
type TagResult ¶
type TagResult struct {
ID int
}
TagResult is the minimal result from tag creation.
type TagTemplate ¶
type TagTemplate struct {
Name string `json:"name"`
Color string `json:"color,omitempty"`
Parent string `json:"parent,omitempty"`
}
TagTemplate defines a single tag within a collection.
type TagWriter ¶
type TagWriter interface {
SetEntityTagsJSON(ctx context.Context, entityID, campaignID string, tagIDs json.RawMessage) error
GetEntityTagsJSON(ctx context.Context, campaignID, entityID string) (json.RawMessage, error)
}
TagWriter provides write access to entity tags for WASM host functions.
func NewWASMTagWriteAdapter ¶
func NewWASMTagWriteAdapter( setTags func(ctx context.Context, entityID, campaignID string, tagIDs json.RawMessage) error, getTags func(ctx context.Context, campaignID, entityID string) (json.RawMessage, error), ) TagWriter
NewWASMTagWriteAdapter creates a TagWriter from function closures.
type TemplateField ¶
type TemplateField struct {
Key string `json:"key"`
Label string `json:"label"`
Type string `json:"type"`
Group string `json:"group,omitempty"`
Options []string `json:"options,omitempty"`
}
TemplateField defines a custom field within an entity type template.
type Theme ¶
type Theme struct {
Slug string `json:"slug"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
File string `json:"file"` // Relative path to CSS file.
Preview string `json:"preview,omitempty"` // Relative path to preview image.
}
Theme is a CSS theme override.
type WASMCallRequest ¶
type WASMCallRequest struct {
CampaignID string `json:"campaign_id"`
Function string `json:"function"`
Input json.RawMessage `json:"input,omitempty"`
}
WASMCallRequest is sent from the host to invoke a WASM plugin function.
type WASMCallResponse ¶
type WASMCallResponse struct {
Output json.RawMessage `json:"output,omitempty"`
Logs []string `json:"logs,omitempty"`
Error string `json:"error,omitempty"`
}
WASMCallResponse is returned from a WASM plugin function invocation.
type WASMCapability ¶
type WASMCapability string
WASMCapability defines a group of related host functions. Plugins declare which capabilities they need; the runtime only exposes the matching host functions.
const ( // CapLog allows calling chronicle_log host function. CapLog WASMCapability = "log" // CapEntityRead allows get_entity, search_entities, list_entity_types. CapEntityRead WASMCapability = "entity_read" // CapEntityWrite allows update_entity_fields. CapEntityWrite WASMCapability = "entity_write" // CapCalendarRead allows get_calendar, list_events. CapCalendarRead WASMCapability = "calendar_read" // CapCalendarWrite allows create_event. CapCalendarWrite WASMCapability = "calendar_write" // CapTagRead allows list_tags, get_entity_tags. CapTagRead WASMCapability = "tag_read" // CapTagWrite allows set_entity_tags. CapTagWrite WASMCapability = "tag_write" // CapRelationWrite allows create_relation. CapRelationWrite WASMCapability = "relation_write" // CapKVStore allows kv_get, kv_set, kv_delete for per-plugin storage. CapKVStore WASMCapability = "kv_store" // CapMessage allows send_message for plugin-to-plugin communication. CapMessage WASMCapability = "message" )
Capability constants — each grants access to a set of host functions.
type WASMConfigField ¶
type WASMConfigField struct {
Key string `json:"key"`
Label string `json:"label"`
Type string `json:"type"` // "string", "number", "boolean".
Default string `json:"default,omitempty"`
Description string `json:"description,omitempty"`
}
WASMConfigField describes a configuration option for a WASM plugin.
type WASMContribution ¶
type WASMContribution struct {
Slug string `json:"slug"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
File string `json:"file"` // Relative path to .wasm file.
Capabilities []string `json:"capabilities"` // Required host function groups.
Config []WASMConfigField `json:"config,omitempty"`
Hooks []string `json:"hooks,omitempty"` // Events this plugin listens to.
MemoryLimitMB int `json:"memory_limit_mb,omitempty"` // Override default 16 MB.
TimeoutSecs int `json:"timeout_secs,omitempty"` // Override default 30s.
}
WASMContribution declares a WASM logic plugin in the extension manifest. Included in ManifestContributes.WASMPlugins.
type WASMHandler ¶
type WASMHandler struct {
// contains filtered or unexported fields
}
WASMHandler serves HTTP endpoints for WASM plugin management and invocation.
func NewWASMHandler ¶
func NewWASMHandler(manager *PluginManager, dispatcher *HookDispatcher, extSvc ExtensionService) *WASMHandler
NewWASMHandler creates a new WASM handler.
func (*WASMHandler) CallWASMPlugin ¶
func (h *WASMHandler) CallWASMPlugin(c *echo.Context) error
CallWASMPlugin invokes a function on a WASM plugin in the context of a campaign. POST /campaigns/:id/extensions/wasm/:extID/:slug/call
func (*WASMHandler) GetWASMPlugin ¶
func (h *WASMHandler) GetWASMPlugin(c *echo.Context) error
GetWASMPlugin returns info about a specific WASM plugin. GET /admin/extensions/wasm/plugins/:extID/:slug
func (*WASMHandler) ListCampaignWASMPlugins ¶
func (h *WASMHandler) ListCampaignWASMPlugins(c *echo.Context) error
ListCampaignWASMPlugins returns WASM plugins available for a campaign (from enabled extensions that have WASM contributions). GET /campaigns/:id/extensions/wasm/plugins
func (*WASMHandler) ListWASMPlugins ¶
func (h *WASMHandler) ListWASMPlugins(c *echo.Context) error
ListWASMPlugins returns info about all loaded WASM plugins. GET /admin/extensions/wasm/plugins
func (*WASMHandler) ReloadWASMPlugin ¶
func (h *WASMHandler) ReloadWASMPlugin(c *echo.Context) error
ReloadWASMPlugin reloads a WASM plugin from disk. POST /admin/extensions/wasm/plugins/:extID/:slug/reload
func (*WASMHandler) SetActivityRecorder ¶
func (h *WASMHandler) SetActivityRecorder(r ActivityRecorder)
SetActivityRecorder wires the admin change log for the WASM endpoints. Optional: nil disables it.
func (*WASMHandler) StopWASMPlugin ¶
func (h *WASMHandler) StopWASMPlugin(c *echo.Context) error
StopWASMPlugin unloads a WASM plugin. POST /admin/extensions/wasm/plugins/:extID/:slug/stop
type WASMLimits ¶
type WASMLimits struct {
MemoryLimitBytes uint64 // Default 16 MB.
TimeoutMS int64 // Default 30000 (30s).
FuelLimit uint64 // Instruction fuel limit (0 = unlimited).
}
WASMLimits defines resource limits for WASM plugin execution.
func DefaultWASMLimits ¶
func DefaultWASMLimits() WASMLimits
DefaultWASMLimits returns the default resource limits for WASM plugins.
type WASMPlugin ¶
type WASMPlugin struct {
ID string `json:"id"`
ExtID string `json:"ext_id"` // Manifest ID of the parent extension.
Name string `json:"name"`
Version string `json:"version"`
WASMFile string `json:"wasm_file"` // Relative path to .wasm file within extension.
Status string `json:"status"` // "loaded", "stopped", "error".
Capabilities []string `json:"capabilities"` // Declared capabilities from manifest.
Config json.RawMessage `json:"config,omitempty"` // Plugin-specific config.
LoadedAt time.Time `json:"loaded_at"`
ErrorMsg string `json:"error_msg,omitempty"`
}
WASMPlugin represents a loaded WASM logic extension. WASM plugins are sandboxed backend modules that execute via Extism/wazero with capability-based security: they can only call host functions that the manifest declares in its capabilities list.
type WASMPluginInfo ¶
type WASMPluginInfo struct {
ExtID string `json:"ext_id"`
Slug string `json:"slug"`
Name string `json:"name"`
Version string `json:"version"`
Status string `json:"status"`
Capabilities []string `json:"capabilities"`
Hooks []string `json:"hooks"`
LoadedAt time.Time `json:"loaded_at"`
ErrorMsg string `json:"error_msg,omitempty"`
}
WASMPluginInfo is a summary returned by the plugin manager for admin display.
type WASMPluginLoader ¶
type WASMPluginLoader interface {
Load(ctx context.Context, extID string, contrib WASMContribution) error
}
WASMPluginLoader loads WASM plugins when extensions are enabled. Set via SetWASMLoader after the plugin manager is created.
type WidgetBlockInfo ¶
type WidgetBlockInfo struct {
Slug string `json:"slug"`
Name string `json:"name"`
Icon string `json:"icon"`
Description string `json:"description"`
// TileSizes are the sizes the widget declared for tile sections.
TileSizes []string `json:"tile_sizes,omitempty"`
}
WidgetBlockInfo describes an extension widget for use as a layout block. Returned by GetWidgetBlockInfos for consumption by the entities block registry adapter.
type WidgetConfigField ¶
type WidgetConfigField struct {
Key string `json:"key"`
Label string `json:"label"`
Type string `json:"type"` // "string", "number", "boolean", "select".
Default string `json:"default,omitempty"`
Options []string `json:"options,omitempty"` // For type "select".
Description string `json:"description,omitempty"`
}
WidgetConfigField describes a configuration option exposed via data-* attributes on the widget's DOM element.
type WidgetContribution ¶
type WidgetContribution struct {
Slug string `json:"slug"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Icon string `json:"icon,omitempty"` // FontAwesome class.
File string `json:"file"` // Relative path to JS file.
Config []WidgetConfigField `json:"config,omitempty"` // Configurable data-* attributes.
// TileSizes are the "WxH" sizes the widget supports in a tile section on
// a 4-column grid; the first is its default. Empty means it cannot be a
// tile. The widget is told its current size by data-tile-w / data-tile-h.
TileSizes []string `json:"tile_sizes,omitempty"`
}
WidgetContribution declares a browser-side widget that an extension provides. Widget JS files are loaded into campaign pages when the extension is enabled. Widgets register via Chronicle.register() and mount to data-widget elements.