core/plugin/deps.go
Alex Dunmow 7eb3e27053 feat: converge BlockNote renderer, add datasources bridge, rename ServiceDeps to CoreServices
SDK renderer now has full feature parity with the host: text alignment,
checkListItem, toggleListItem, video, audio, file, statement blocks,
and text/background color inline styles. New datasources.Datasources
interface lets plugins resolve buckets directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-03 10:18:32 +08:00

99 lines
3.1 KiB
Go

package plugin
import (
"context"
"connectrpc.com/connect"
"git.dev.alexdunmow.com/block/core/ai"
"git.dev.alexdunmow.com/block/core/auth"
"git.dev.alexdunmow.com/block/core/content"
"git.dev.alexdunmow.com/block/core/crypto"
"git.dev.alexdunmow.com/block/core/datasources"
"git.dev.alexdunmow.com/block/core/gating"
"git.dev.alexdunmow.com/block/core/menus"
"git.dev.alexdunmow.com/block/core/settings"
"git.dev.alexdunmow.com/block/core/subscriptions"
"github.com/google/uuid"
)
// CoreServices provides CMS capabilities to plugins.
type CoreServices struct {
// Capability interfaces — typed access to CMS functionality
Content content.Content
Settings settings.Settings
Gating gating.Gating
Crypto crypto.Crypto
Menus menus.Menus
Datasources datasources.Datasources
PublicUsers auth.PublicUsers
Subscriptions subscriptions.Subscriptions
// Database — for plugin's own sqlc queries
Pool Pool
// RPC interceptors — core-provided Connect handler options
Interceptors connect.Option
// Site configuration
MediaPath string
AppURL string
// AI
ToolRegistry ai.ToolRegistry
AITextCall func(ctx context.Context, taskKey, systemPrompt, userMessage string) (string, error)
// Email
EmailSender EmailSender
// Plugin interop
Bridge PluginBridge
// Core RPC services — pre-built bindings for CMS-provided services
CoreServiceBindings CoreServiceBindings
ReviewSubmitter ReviewSubmitter
BadgeRefresher BadgeRefresher
SettingsUpdater settings.Updater
// Extension points — typed as narrow interfaces where possible
JobRunner JobRunner
EmbeddingService EmbeddingService
RAGService RAGService
}
// JobRunner submits background jobs for async processing.
type JobRunner interface {
Submit(ctx context.Context, jobType string, config []byte) error
}
// EmbeddingService generates and manages text embeddings.
type EmbeddingService interface {
GenerateEmbedding(ctx context.Context, text string) ([]float32, error)
EmbedContent(ctx context.Context, sourceType string, sourceID uuid.UUID, text string) (bool, error)
IsAvailable() bool
}
// ContentFetcher retrieves the title and full text for a content item so the
// RAG service can re-index it after changes. Plugins register one per content type.
type ContentFetcher func(ctx context.Context, contentID uuid.UUID) (title string, text string, err error)
// RAGService provides retrieval-augmented generation for AI agents.
type RAGService interface {
Query(ctx context.Context, query string, limit int) ([]RAGResult, error)
RegisterContentFetcher(contentType string, fetcher ContentFetcher)
OnContentChanged(ctx context.Context, contentType string, contentID uuid.UUID)
}
// RAGResult is a single result from a RAG query.
type RAGResult struct {
Content string
Score float64
Metadata map[string]string
}
// BadgeRefresher recomputes badges for a data table row.
// The CMS handles loading the table schema, aggregating ratings,
// evaluating badge rules, and persisting the updated badge list.
type BadgeRefresher interface {
RefreshBadges(ctx context.Context, tableID, rowID uuid.UUID) error
}