core/plugin/provisioner.go
Alex Dunmow 7c20538a4e feat: WO-PS-009 SDK plugin types
- plugin/types.go: Pool, EmailSender, JobHandlerFunc, Dependency,
  AdminPage, AIAction, MasterPageDefinition, status/source constants,
  MediaAnalyzedEvent, ModerationDecisionEvent, MediaHooksProvider,
  DirectoryExtensions
- plugin/deps.go: ServiceDeps with typed capability interfaces
  (Content, Settings, Gating, Crypto, ToolRegistry, JobRunner,
  EmbeddingService, RAGService)
- plugin/registration.go: PluginRegistration, RegisterFunc
- plugin/service.go: ConnectServiceBinding with generics, ServiceMount,
  ServiceRegistration
- plugin/provisioner.go: Provisioner interface with all config types
- plugin/css_manifest.go: CSSManifest, MergedCSSManifest, MergeCSSManifests
- plugin/version.go: ParseModVersion, CompareVersions
- plugin/topo_sort.go: TopologicalSort (Kahn's algorithm)
- plugin/block_registry.go: PluginBlockRegistry (auto-prefixing wrapper)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-30 22:41:52 +08:00

108 lines
2.8 KiB
Go

package plugin
import (
"context"
"encoding/json"
"github.com/google/uuid"
)
// Provisioner allows plugins to ensure required resources exist on startup.
// All methods are idempotent — they check first and only create if missing.
type Provisioner interface {
EnsureDataTable(config DataTableConfig) error
MergeSiteSettings(defaults map[string]any) error
EnsureSetting(key string, defaultValue map[string]any) error
EnsurePage(config PageConfig) error
OverrideSiteSettings(overrides map[string]any) error
EnsureMenuItem(menuName string, config MenuItemConfig) error
RegisterEmbeddingConfig(config EmbeddingConfigDef) error
EnsureEmbed(config EmbedConfig) error
EnsureJobSchedule(config JobScheduleConfig) error
UpdateDataTableRowField(ctx context.Context, rowID uuid.UUID, fieldKey string, value map[string]any) error
DisableOrphanedJobSchedules(registeredTypes []string) error
EnsurePlugin(name string) error
EnsureCustomColor(config CustomColorConfig) error
}
// DataTableConfig defines a data table to provision.
type DataTableConfig struct {
Key string
Name string
Description string
Schema json.RawMessage
PrimaryKey string
}
// PageConfig defines a page to provision.
type PageConfig struct {
Slug string
ParentSlug string
Title string
TemplateKey string
Blocks []PageBlockConfig
DetailSourceType string
DetailSourceKey string
DetailSlugField string
ReconcileBlocks bool
ReconcileTemplate bool
}
// PageBlockConfig defines a block within a provisioned page.
type PageBlockConfig struct {
BlockKey string
Title string
Content map[string]any
HtmlContent *string
Slot string
SortOrder int32
}
// EmbeddingConfigDef defines embedding text generation for a data table.
type EmbeddingConfigDef struct {
TableKey string
TextTemplate string
Enabled bool
}
// MenuItemConfig defines a menu item to provision.
type MenuItemConfig struct {
Label string
URL string
PageSlug string
SortOrder int32
}
// EmbedConfig defines an embeddable component template.
type EmbedConfig struct {
Key string
Title string
Description string
Icon string
LabelField string
Template string
RenderFunc func(ctx context.Context, content map[string]any) string
DataSource EmbedDataSource
}
// EmbedDataSource specifies where embed data comes from.
type EmbedDataSource struct {
Type string
TableKey string
}
// JobScheduleConfig defines a cron schedule for a background job.
type JobScheduleConfig struct {
JobType string
CronExpression string
Config json.RawMessage
}
// CustomColorConfig defines a custom theme color variable.
type CustomColorConfig struct {
Name string
LightValue string
DarkValue string
Source string
}