core/plugin/deps.go
Alex Dunmow 917eee13a2 feat: add menus, subscriptions, public users, and plugin bridge to SDK
New capability interfaces:
- menus.Menus: menu/nav access (GetMenuByName, GetMenuItems)
- subscriptions.Subscriptions: tier/plan access (GetUserTierLevel, GetTierBySlug, ListActivePlans)
- auth.PublicUsers: public user profiles (GetByUsername, GetByID)
- plugin.PluginBridge: inter-plugin service registry with typed GetServiceAs[T] helper

All added to ServiceDeps for plugin consumption.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-01 12:36:13 +08:00

75 lines
2.0 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"
)
// 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)
}
// RAGService provides retrieval-augmented generation for AI agents.
type RAGService interface {
Query(ctx context.Context, query string, limit int) ([]RAGResult, error)
}
// RAGResult is a single result from a RAG query.
type RAGResult struct {
Content string
Score float64
Metadata map[string]string
}