Convert the bundled backend/internal/plugins/smartblock package into a standalone reactor-mode wasm plugin: - package smartblock -> package main; add wasip1 main.go with wasmguest.Serve(Registration). - Add go.mod (module git.dev.alexdunmow.com/block/smartblock) pinning block/core v0.18.2; no replace directives. - Flesh out plugin.mod (scope=ninja, kind=plugin, categories, tags, display_name, description). - Point web/eslint.config.js at ../../../cms/web/eslint.config.js and switch @block-ninja/ui from workspace:* to the ^0.1.0 registry version; rebuild web/dist. - Add .gitignore (*.bnp, *.wasm, web/node_modules). Behavior unchanged: registers the "smart" block; assets served from web/dist. Builds to smartblock-1.0.0.bnp; check-safety passes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"io/fs"
|
|
"net/http"
|
|
|
|
"git.dev.alexdunmow.com/block/core/blocks"
|
|
"git.dev.alexdunmow.com/block/core/templates"
|
|
)
|
|
|
|
//go:embed all:web/dist/assets
|
|
var distAssets embed.FS
|
|
|
|
//go:embed plugin.mod
|
|
var pluginModBytes []byte
|
|
|
|
// Register is the plugin entry point that registers the Smart Block.
|
|
// Returns an error if registration fails.
|
|
func Register(tr templates.TemplateRegistry, br blocks.BlockRegistry) error {
|
|
// Register the Smart Block
|
|
br.Register(SmartBlockMeta, SmartBlockFunc)
|
|
return nil
|
|
}
|
|
|
|
// SmartBlockMeta defines the Smart Block metadata
|
|
var SmartBlockMeta = blocks.BlockMeta{
|
|
Key: "smart",
|
|
Title: "Smart Block",
|
|
Description: "AI-powered block that generates custom content structures from natural language prompts",
|
|
Source: "smartblock",
|
|
EditorJS: "remoteEntry.js",
|
|
}
|
|
|
|
// AssetsHandler serves static assets including the Module Federation remote entry.
|
|
// This is called by the plugin loader to mount assets at /api/plugins/smartblock/
|
|
func AssetsHandler() http.Handler {
|
|
// Create a sub-filesystem pointing to web/dist/assets
|
|
subFS, err := fs.Sub(distAssets, "web/dist/assets")
|
|
if err != nil {
|
|
// Fallback to 404 handler if embed fails
|
|
return http.NotFoundHandler()
|
|
}
|
|
|
|
return http.FileServer(http.FS(subFS))
|
|
}
|