Documentation
¶
Overview ¶
Package imagegen makes pictures with agent CLIs (Codex by default): a Codex job runs `codex exec` and watches the folder Codex saves each picture to (~/.codex/generated_images/<thread>/), so every picture is known the moment it is drawn, not when the run ends. Codex's --json stream says nothing of pictures; the folder does.
A job belongs to whoever asked: a chat (an agent's generate_images call), a Sinopia design. Its pictures are copied into the job's own folder (and into the asker's folder when one is named), where the page shows them from.
Index ¶
Constants ¶
const ( // MaxCount is the most pictures one job draws. MaxCount = 8 // RunTimeout bounds one job. RunTimeout = 12 * time.Minute // MaxRunning is how many jobs draw at once on a machine. MaxRunning = 4 )
const ( // ToolGenerate and ToolWait are the agents' MCP tools. ToolGenerate = "generate_images" ToolWait = "wait_images" // WaitMax is how long a call waits for the pictures; CodexWaitMax is the most for a Codex caller, which ends a // tool call at a minute. WaitMax = 5 * time.Minute CodexWaitMax = 55 * time.Second )
Variables ¶
var ( ErrBadRequest = errors.New("bad request") ErrBusy = errors.New("busy") )
ErrBadRequest is a request that cannot be drawn; ErrBusy, one that waits for the jobs already drawing.
var BusyPoll = 2 * time.Second
BusyPoll is how often a call that found every slot drawing tries again.
var ErrNoMedia = errors.New("Higgsfield is not connected: the person connects «Higgsfield (MCP)» in Settings → Connections")
ErrNoMedia: a request for Higgsfield on a machine where it is not connected.
Functions ¶
Types ¶
type Image ¶
type Image struct {
N int `json:"n"`
Path string `json:"path"`
// Copy is the picture in the asker's folder ("" when none was asked or the copy failed).
Copy string `json:"copy,omitempty"`
}
Image is one picture drawn.
type Media ¶
type Media interface {
// Available says whether the provider is connected on this machine.
Available() bool
// Draw makes one picture and gives the path of its file.
Draw(ctx context.Context, d MediaDraw) (string, error)
}
Media draws pictures with a media provider of the person's (Higgsfield: their plan's credits), one picture a call. It is the same service the agents' generate_images uses with a provider, so its price checks and daily cap hold here too.
type MediaDraw ¶
type MediaDraw struct {
// Model is the provider's model ("" for its default).
Model string
Prompt string
// Ratio is the frame, "1:1", "16:9", … ("" for the model's own).
Ratio string
// Reference is a picture file the model starts from ("" for none): the picture being changed, the marks on it.
Reference string
}
MediaDraw is one picture asked of a media provider.
type Mode ¶
type Mode string
Mode says how a job changes its source.
const ( // ModeText changes the picture as the words say. ModeText Mode = "text" // ModeMark follows what is drawn on the picture. ModeMark Mode = "mark" // ModeNote changes the area in a frame. ModeNote Mode = "note" // ModeErase removes what is painted over. ModeErase Mode = "erase" // ModeCut removes the background. ModeCut Mode = "cut" // ModeSize recomposes the picture to another format. ModeSize Mode = "size" )
type Provider ¶
type Provider string
Provider selects the CLI that draws the pictures. Antigravity is experimental.
type Request ¶
type Request struct {
Provider Provider `json:"provider,omitempty"`
// Model is the provider's model (Higgsfield only; "" for its default).
Model string `json:"model,omitempty"`
Prompt string `json:"prompt"`
Count int `json:"count"`
Shape Shape `json:"shape,omitempty"`
// Transparent asks for a transparent background.
Transparent bool `json:"transparent,omitempty"`
// Conv is the chat that asked ("" for none); Owner says who else did (e.g. "design:<id>").
Conv string `json:"conv,omitempty"`
Owner string `json:"owner,omitempty"`
// CopyTo is a folder the pictures are also copied into ("" for none), as <Name>-<n>.png.
CopyTo string `json:"copyTo,omitempty"`
// SaveOK says, right before each copy, whether CopyTo (its links followed) may still receive the pictures; a
// request with CopyTo and no SaveOK copies nothing.
SaveOK func(real string) bool `json:"-"`
Name string `json:"name,omitempty"`
// Source is a picture to change instead of drawing a new one ("" for a new one): see edit.go. Mode says how, Format
// is the frame of ModeSize, Overlay a PNG with what the person drew on it. SourceOK says, when the job starts,
// whether this source may be read; a request with a Source and no SourceOK is refused.
Source string `json:"source,omitempty"`
Mode Mode `json:"mode,omitempty"`
Format string `json:"format,omitempty"`
Overlay []byte `json:"overlay,omitempty"`
SourceOK func(string) bool `json:"-"`
}
Request is what to draw.
type Service ¶
type Service struct {
// Dir is where the jobs' pictures are kept: <Dir>/<job id>/<n>.png.
Dir string
// CodexHome is Codex's folder (~/.codex).
CodexHome string
// Env is the environment `codex exec` runs with (the agents' sign-in included); nil for this process's.
Env func() []string
// Binary is the codex binary; "" for "codex".
Binary string
// DefaultProvider is used when a request omits provider; empty means Codex.
DefaultProvider Provider
// AntigravityBinary is the official agy executable (empty: agy on PATH).
AntigravityBinary string
// AntigravityHome is its application data directory (empty: ~/.gemini/antigravity-cli).
AntigravityHome string
// AntigravityEnv is separate from Codex's Env; nil inherits this process's environment.
AntigravityEnv func() []string
// Media draws the pictures of provider Higgsfield (nil: it is refused).
Media Media
// Changed is told a job's new state; nil for nothing.
Changed func(Snapshot)
// contains filtered or unexported fields
}
Service runs and remembers the jobs.
type Snapshot ¶
type Snapshot struct {
Provider Provider `json:"provider,omitempty"`
Model string `json:"model,omitempty"`
ID string `json:"id"`
Prompt string `json:"prompt"`
Count int `json:"count"`
Shape Shape `json:"shape,omitempty"`
Conv string `json:"conv,omitempty"`
Owner string `json:"owner,omitempty"`
// Source and Mode: the picture this job changes, and how; absent for a new picture.
Source string `json:"source,omitempty"`
Mode Mode `json:"mode,omitempty"`
State State `json:"state"`
Images []Image `json:"images"`
Error string `json:"error,omitempty"`
StartedAt int64 `json:"startedAt"`
EndedAt int64 `json:"endedAt,omitempty"`
}
Snapshot is a job as it is now.
type Tools ¶
type Tools struct {
S *Service
// Caller is the calling chat ("" when it could not be told), Why says why not.
Caller, Why string
// Cwd is the chat's folder, a relative save_to is taken from.
Cwd string
// Codex is true for a Codex caller.
Codex bool
// Allowed says whether a folder may receive the pictures (inside the workspace).
Allowed func(path string) bool
// Readable says whether a picture may be changed (source).
Readable func(path string) bool
// Media draws a picture with a media provider (Higgsfield) when a call names a provider or a model of its own; nil: the
// provider and model arguments are refused.
Media interface {
Image(ctx context.Context, args *jsvalue.Object) *jsvalue.Object
}
}
Tools are the picture tools for one calling agent.