Compare commits

..

No commits in common. "243711e717d2554c90e3a689393a61180052303b" and "3064ef1b4058faed61cfc5038b628ac77b2906ef" have entirely different histories.

4 changed files with 22 additions and 28 deletions

View File

@ -2,41 +2,38 @@ 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 {
rawMeta, err := json.Marshal(content["_meta"])
if err != nil {
return renderEmptyState()
}
var meta smartBlockMeta
if err := json.Unmarshal(rawMeta, &meta); err != nil {
// Get metadata
meta, ok := content["_meta"].(map[string]any)
if !ok {
return renderEmptyState()
}
if len(meta.Generations) == 0 || meta.CurrentGenerationID == "" {
generations, ok := meta["generations"].([]any)
if !ok || len(generations) == 0 {
return renderEmptyState()
}
currentID, _ := meta["currentGenerationId"].(string)
if currentID == "" {
return renderEmptyState()
}
// Find the current generation
var template string
for _, gen := range meta.Generations {
if gen.ID == meta.CurrentGenerationID {
template = gen.Template
for _, gen := range generations {
genMap, ok := gen.(map[string]any)
if !ok {
continue
}
if genMap["id"] == currentID {
template, _ = genMap["template"].(string)
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.3.5
require git.dev.alexdunmow.com/block/pluginsdk v0.2.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.3.5 h1:h8YZTgnB/+WQ1yPS5MbJr2aPKuv/kudr93nQowwH8nM=
git.dev.alexdunmow.com/block/pluginsdk v0.3.5/go.mod h1:Z+eG+WZxAP0jfreLqlGcc0kkWKt8RWevzWyWn8d+dhM=
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=
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,11 +2,8 @@
name = "smartblock"
display_name = "Smart Block"
scope = "@ninja"
version = "1.0.3"
version = "1.0.1"
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"