core/plugin/deps.go
Alex Dunmow d270bc8582 feat: extend EmbeddingService and RAGService interfaces for .so plugins
Add EmbedContent/IsAvailable to EmbeddingService and
RegisterContentFetcher/OnContentChanged to RAGService so .so plugins
can use embedding and RAG capabilities through SDK interfaces instead
of type-asserting CMS concrete types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-02 09:25:44 +08:00

84 lines
2.5 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/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"
)
// ServiceDeps provides dependencies that plugins need for RPC service handlers.
type ServiceDeps struct {
// Capability interfaces — typed access to CMS functionality
Content content.Content
Settings settings.Settings
Gating gating.Gating
Crypto crypto.Crypto
Menus menus.Menus
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
// 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
}