genparams

package
v0.4.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

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.

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

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 (*Map) CanonicalKeys

func (m *Map) CanonicalKeys() []string

CanonicalKeys lists the mapped canonical keys in sorted order.

func (*Map) Declares

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 (*Map) Emit

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.

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>

func (*Map) Param

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

Param returns the canonical key's resolved parameter.

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.

func (*Param) Validate

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL