Centralize generic LLM schema assets

This commit is contained in:
2026-08-05 00:34:56 +00:00
parent f4c05c34ef
commit a57f83e30d
6 changed files with 1089 additions and 5 deletions

View File

@@ -2,17 +2,17 @@ package llm
import (
"crypto/sha256"
"embed"
"encoding/hex"
"encoding/json"
"fmt"
"io/fs"
"sort"
"strings"
rootassets "gitea.maximumdirect.net/eric/notarius/assets"
)
//go:embed assets/schemas/*.json
var schemaAssets embed.FS
var schemaAssets = mustSubFS(rootassets.FS(), "generic")
// ResponseSchemaKey identifies one structured response schema.
type ResponseSchemaKey string
@@ -49,17 +49,25 @@ var responseSchemaRegistry = map[ResponseSchemaKey]ResponseSchema{
ID: "notarius.test_artifact",
Version: schemaVersionV1,
Name: "notarius_test_artifact_v1",
AssetPath: "assets/schemas/test_artifact.v1.json",
AssetPath: "schemas/test_artifact.v1.json",
}),
TestValidatorDecisionSchemaKey: mustLoadResponseSchema(schemaAssets, ResponseSchemaDefinition{
Key: TestValidatorDecisionSchemaKey,
ID: "notarius.test_validator_decision",
Version: schemaVersionV1,
Name: "notarius_test_validator_decision_v1",
AssetPath: "assets/schemas/test_validator_decision.v1.json",
AssetPath: "schemas/test_validator_decision.v1.json",
}),
}
func mustSubFS(fsys fs.FS, dir string) fs.FS {
sub, err := fs.Sub(fsys, dir)
if err != nil {
panic(fmt.Errorf("scope embedded assets to %s: %w", dir, err))
}
return sub
}
// RegisteredResponseSchemas returns all registered response schemas sorted by key.
func RegisteredResponseSchemas() []ResponseSchema {
keys := make([]string, 0, len(responseSchemaRegistry))