Documentation
¶
Overview ¶
Package genparams is experimental: its API and documented formats may change in a minor release; see https://nsgo.games/docs/stability/.
Package genparams maps an MCP generator tool's advertised JSON Schema onto a canonical generation parameter vocabulary, validates a canonical request against it before any paid call, and emits the wire arguments the tool's schema names.
A generator server connected through Generated Assets advertises its generation tool's parameters in `tools/list`. This package resolves each schema property onto one canonical key through a built-in alias table plus the generator entry's own `params` overrides, so a game drives every generator through the same names while each server still receives its own wire spelling. A tool whose schema is absent or empty maps to nothing, which the editor treats as the legacy private argument set.
Canonical keys describe what a value means, never which provider carries it: the same `aspectRatio` means the same thing whether the server spells it `aspect_ratio` or nests it under `options`. Values are validated against the constraints the schema declares (type, enum, minimum, maximum, required) before the editor calls the tool, so an out-of-range value is refused with the canonical key and the allowed range instead of failing a paid call.
Index ¶
Examples ¶
Constants ¶
const ( // KeyPrompt is the text the generator renders or speaks. KeyPrompt = "prompt" // KeyNegativePrompt is text the generator avoids. KeyNegativePrompt = "negativePrompt" // KeySeed is the random seed the generator starts from. KeySeed = "seed" // KeyCount is how many candidates one request produces. KeyCount = "count" // KeyWidth is the output width in pixels. KeyWidth = "width" // KeyHeight is the output height in pixels. KeyHeight = "height" // KeyAspectRatio is the output aspect ratio as a "W:H" string (for example "16:9"). KeyAspectRatio = "aspectRatio" // KeyBackground selects opaque or transparent output ("opaque", "transparent"). KeyBackground = "background" // KeyReferenceImages lists the references the generator conditions on. KeyReferenceImages = "referenceImages" // KeyDuration is how long a generated sound or animation plays, in seconds. KeyDuration = "duration" // KeyLoop is whether the output loops. KeyLoop = "loop" // KeyVoice is the voice identifier a speech generator speaks with. KeyVoice = "voice" // KeyInstrumental is whether a music generator omits vocals. KeyInstrumental = "instrumental" // KeyFrameCount is how many frames an animation clip contains. KeyFrameCount = "frameCount" // KeyFaceLimit is how many faces a 3D model may carry. KeyFaceLimit = "faceLimit" // KeyRequestID is the stable idempotency key for a generation request. KeyRequestID = "requestId" )
Canonical parameter keys. A key names a value's meaning across every generator server; the wire spelling is each tool's own.
Variables ¶
This section is empty.
Functions ¶
func ValidateOverrideKey ¶
ValidateOverrideKey reports whether a generator entry's params override may name the canonical key, so configuration is refused before a server connects. The wire key it points at is checked against the schema later.
Types ¶
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is a tool's schema resolved onto canonical keys. The zero Map is the legacy private argument set: the editor sends its historical arguments and validates nothing.
func MapSchema ¶
MapSchema resolves a generation tool's JSON Schema onto canonical keys. The overrides name canonical keys the built-in alias table does not cover or spell differently, as canonical key to wire key; a dotted wire key targets a property nested one object deep. The returned Map holds every property the schema declares (including ones left unmapped, through Declares), so the caller can pass a tool its private arguments.
func (*Map) CanonicalKeys ¶
CanonicalKeys lists the mapped canonical keys in sorted order.
func (*Map) Declares ¶
Declares reports whether the schema declares the named property, so a caller may pass the tool a private argument outside the canonical vocabulary (the target path, the asset kind, a model name) when the schema names it.
func (*Map) Emit ¶
Emit builds the wire arguments for a canonical request. The values map is keyed by canonical key; a required parameter the map lacks, and any value that fails its schema constraints, is an error and nothing is emitted. The emitted map is fresh: nested size objects are built along dotted wire paths without touching the caller's maps.
Example ¶
MapSchema resolves a generator tool's wire property names onto canonical keys; Emit validates the values and rebuilds the wire arguments the server expects.
package main
import (
"encoding/json"
"fmt"
"github.com/nsgo-dev/game/pkg/tooling/genparams"
)
func main() {
m, err := genparams.MapSchema(json.RawMessage(`{
"type": "object",
"properties": {
"prompt": {"type": "string"},
"num_images": {"type": "integer", "minimum": 1, "maximum": 4}
},
"required": ["prompt"]
}`), nil)
if err != nil {
fmt.Println(err)
return
}
out, err := m.Emit(map[string]any{
genparams.KeyPrompt: "a slime",
genparams.KeyCount: 2,
})
if err != nil {
fmt.Println(err)
return
}
wire, err := json.Marshal(out)
fmt.Println(string(wire), err)
}
Output: {"num_images":2,"prompt":"a slime"} <nil>
type Param ¶
type Param struct {
// Key is the canonical key, one of the Key* constants.
Key string
// WireKey is the schema property the server expects, either resolved from
// the alias table or named by the generator entry's params override. A
// dotted path ("size.width") targets a property nested one object deep.
WireKey string
// Kind is the canonical value's kind.
Kind ValueKind
// Enum lists the string values the schema allows, when it declares them.
Enum []string
// NumberEnum lists the numeric values the schema allows for an integer or number parameter, when it declares them (a duration of 5 or 10 seconds, for example).
NumberEnum []float64
// Min and Max bound numeric values the schema allows; nil leaves that side
// unbounded.
Min *float64
Max *float64
// Required reports whether the schema lists the property as required.
Required bool
}
Param is one schema property resolved onto a canonical key.