GitHubLoslegen

Die API-Referenz stammt aus den Go-Doc-Kommentaren im Quellcode und ist auf Englisch verfasst.

package genparams

import "github.com/nsgo-dev/game/pkg/tooling/genparams"

Übersicht

Package genparams is experimental: its API and documented formats may change in a minor release. See the API stability policy. 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

Konstanten

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.

Funktionen

func ValidateOverrideKey(canonical string) error

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.

Typen

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(schema json.RawMessage, overrides map[string]string) (*Map, error)

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 (m *Map) CanonicalKeys() []string

CanonicalKeys lists the mapped canonical keys in sorted order.

func (m *Map) Declares(wireKey string) bool

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 (m *Map) Emit(values map[string]any) (map[string]any, error)

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.

func (m *Map) Param(key string) (*Param, bool)

Param returns the canonical key's resolved parameter.

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.

func (p *Param) Validate(value any) (any, error)

Validate checks a canonical request value against the parameter's schema constraints and returns the wire value to send. It reports the canonical key and the constraint in every error, and never mentions the wire key: the caller chose the value in canonical terms.

type ValueKind int

ValueKind classifies a canonical parameter's Go value.

const (
	KindString ValueKind = iota
	KindBool
	KindInt
	KindFloat
	KindInt64
	KindList
)

The value kinds canonical parameters carry. KindList and KindInt64 cover the reference list and the seed; the rest map onto JSON numbers, strings and booleans.