Documentation
¶
Overview ¶
Package genjob is experimental: its API and documented formats may change in a minor release; see https://nsgo.games/docs/stability/.
Package genjob defines the durable, versioned record for an asset generation request.
Index ¶
Examples ¶
Constants ¶
const CurrentVersion = 2
CurrentVersion is the newest job record schema version (2), the one new records are written in. Version 2 adds the secondary files of a candidate.
const Version = 1
Version is the oldest job record schema version Parse reads (1). Encode writes a record in the version it holds.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Candidate ¶
type Candidate struct {
FileName string `yaml:"file"`
MediaType string `yaml:"mediaType"`
Bytes int64 `yaml:"bytes"`
SHA256 string `yaml:"sha256"`
// Files lists the candidate's secondary outputs, such as a normal map, a material draft, a sprite atlas or a tileset draft, each stored beside job.yaml. Version 2 only.
Files []File `yaml:"files,omitempty"`
}
Candidate records one validated output stored beside job.yaml.
type File ¶
type File struct {
FileName string `yaml:"file"`
Path string `yaml:"path"`
MediaType string `yaml:"mediaType"`
Bytes int64 `yaml:"bytes"`
SHA256 string `yaml:"sha256"`
}
File records one secondary output of a candidate stored beside job.yaml and the project-relative path it is written to when the candidate is picked.
type Job ¶
type Job struct {
Version int `yaml:"version"`
RequestID string `yaml:"requestId"`
Generator string `yaml:"generator"`
Tool string `yaml:"tool"`
Kind string `yaml:"kind"`
Target string `yaml:"target"`
Parameters map[string]string `yaml:"parameters,omitempty"`
Fingerprint string `yaml:"fingerprint"`
State State `yaml:"state"`
Phase string `yaml:"phase"`
RemoteTask string `yaml:"remoteTask,omitempty"`
Error string `yaml:"error,omitempty"`
Candidates []Candidate `yaml:"candidates,omitempty"`
}
Job is the canonical record stored at .game/generated/<request-id>/job.yaml.
func Parse ¶
Parse decodes and validates one strict generation job YAML document, refusing unknown and duplicate fields and a second document. Its errors are *loaderr.Error values with the line and field at fault.
Example ¶
ExampleParse reads a job record, writes it back unchanged and refuses an invalid state.
package main
import (
"bytes"
"fmt"
"github.com/nsgo-dev/game/pkg/loaderr"
"github.com/nsgo-dev/game/pkg/tooling/genjob"
)
const jobYAML = `version: 1
requestId: req_123
generator: pixel-gen
tool: generate
kind: images
target: art/slime.png
parameters:
count: "2"
prompt: a slime
fingerprint: 3f79bb7b435b05321651daefd374cdc681dc06faa65e374e38337b88ca046dea
state: completed
phase: downloaded
candidates:
- file: candidate-01.png
mediaType: image/png
bytes: 10240
sha256: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
`
// ExampleParse reads a job record, writes it back unchanged and refuses an invalid state.
func main() {
job, err := genjob.Parse([]byte(jobYAML))
if err != nil {
fmt.Println(err)
return
}
fmt.Println(job.RequestID, job.State, job.Target)
fmt.Println("prompt:", job.Parameters["prompt"])
fmt.Println("candidate:", job.Candidates[0].FileName, job.Candidates[0].Bytes)
out, err := genjob.Encode(job)
fmt.Println("round trip unchanged:", err == nil && bytes.Equal(out, []byte(jobYAML)))
job.State = "paused"
if e, ok := loaderr.As(genjob.Validate(job)); ok {
fmt.Println(e.Field+":", e.Problem)
}
}
Output: req_123 completed art/slime.png prompt: a slime candidate: candidate-01.png 10240 round trip unchanged: true state: genjob: invalid state "paused"
type State ¶
type State string
State is the lifecycle state of a generation job.
const ( // StateQueued is a request accepted but not started. StateQueued State = "queued" // StateRunning is a request the generator is working on. StateRunning State = "running" // StateCompleted is a request whose candidates are stored beside job.yaml. StateCompleted State = "completed" // StateCancelled is a request the editor or the person cancelled. StateCancelled State = "cancelled" // StateFailed is a request that failed; Error says why. StateFailed State = "failed" )
The lifecycle states a job record holds.