Compare commits

...

3 Commits

Author SHA1 Message Date
Alex Dunmow
243711e717 chore: update plugin SDK compatibility 2026-08-19 22:51:23 +08:00
Alex Dunmow
1766770d62 chore(plugin): update pluginsdk to v0.3.3 2026-08-10 23:44:54 +08:00
Alex Dunmow
057677ab7f refactor: replace any with concrete types where shapes are known (check-safety 2e)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-10 02:44:26 +08:00
4 changed files with 28 additions and 22 deletions

View File

@ -2,38 +2,41 @@ package main
import (
"context"
"encoding/json"
"fmt"
"html"
"strings"
)
type smartBlockGeneration struct {
ID string `json:"id"`
Template string `json:"template"`
}
type smartBlockMeta struct {
Generations []smartBlockGeneration `json:"generations"`
CurrentGenerationID string `json:"currentGenerationId"`
}
// SmartBlockFunc renders a Smart Block by substituting {{field}} placeholders with content values.
func SmartBlockFunc(ctx context.Context, content map[string]any) string {
// Get metadata
meta, ok := content["_meta"].(map[string]any)
if !ok {
rawMeta, err := json.Marshal(content["_meta"])
if err != nil {
return renderEmptyState()
}
var meta smartBlockMeta
if err := json.Unmarshal(rawMeta, &meta); err != nil {
return renderEmptyState()
}
generations, ok := meta["generations"].([]any)
if !ok || len(generations) == 0 {
if len(meta.Generations) == 0 || meta.CurrentGenerationID == "" {
return renderEmptyState()
}
currentID, _ := meta["currentGenerationId"].(string)
if currentID == "" {
return renderEmptyState()
}
// Find the current generation
var template string
for _, gen := range generations {
genMap, ok := gen.(map[string]any)
if !ok {
continue
}
if genMap["id"] == currentID {
template, _ = genMap["template"].(string)
for _, gen := range meta.Generations {
if gen.ID == meta.CurrentGenerationID {
template = gen.Template
break
}
}

2
go.mod
View File

@ -2,7 +2,7 @@ module git.dev.alexdunmow.com/block/smartblock
go 1.26.4
require git.dev.alexdunmow.com/block/pluginsdk v0.2.5
require git.dev.alexdunmow.com/block/pluginsdk v0.3.5
require (
connectrpc.com/connect v1.20.0 // indirect

4
go.sum
View File

@ -1,7 +1,7 @@
connectrpc.com/connect v1.20.0 h1:6TNDAB+WeNd2uolWNlYczB5E0KNNaVMNUEx8JEUsPmQ=
connectrpc.com/connect v1.20.0/go.mod h1:A2ygJrukXwWy32vkCAAHNVguZrqZ+jeZ9rGRnGR4dN4=
git.dev.alexdunmow.com/block/pluginsdk v0.2.5 h1:01d+5stAywSENScafnNKyMc2ZM5GGFt+hCBKuKTFJW4=
git.dev.alexdunmow.com/block/pluginsdk v0.2.5/go.mod h1:Z+eG+WZxAP0jfreLqlGcc0kkWKt8RWevzWyWn8d+dhM=
git.dev.alexdunmow.com/block/pluginsdk v0.3.5 h1:h8YZTgnB/+WQ1yPS5MbJr2aPKuv/kudr93nQowwH8nM=
git.dev.alexdunmow.com/block/pluginsdk v0.3.5/go.mod h1:Z+eG+WZxAP0jfreLqlGcc0kkWKt8RWevzWyWn8d+dhM=
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

View File

@ -2,8 +2,11 @@
name = "smartblock"
display_name = "Smart Block"
scope = "@ninja"
version = "1.0.1"
version = "1.0.3"
description = "AI-powered block that generates custom content structures from natural-language prompts and renders them by substituting {{field}} placeholders."
kind = "plugin"
categories = ["developer"]
tags = ["ai", "content", "blocks", "generative"]
[compatibility]
block_core = ">=0.3.4"