imagev1

import imagev1 "pocketone.dev/ext/contracts/llm/image/v1"

Package imagev1 is the llm.image/v1 contract: a model makes pictures from a prompt, and from reference pictures.

A wire contract at /api/_c/llm.image/v1. In pb_hooks it's $llm.image.

Source: ext/contracts/llm/image/v1.

Variables

var Contract = extkit.NewContract[Image]("llm.image/v1", extkit.One).JS(extkit.JSHooks, nil).JSTypes(jsTypes)

Contract is llm.image/v1.

var W = extkit.NewWire(Contract, "llm", func(inner Image, g *extkit.Guard[Image]) Image {
	return &guardImage{inner, g}
},
	extkit.Op[Image]{
		Name:   "generate",
		Desc:   "Makes pictures from a prompt, and from the reference pictures it's given.",
		Method: "POST",
		Path:   "generate",
		In:     reflect.TypeOf(GenerateInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Image, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in GenerateInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Generate(ctx, a, in)
		},
	},
	extkit.Op[Image]{
		Name:   "models",
		Desc:   "Lists the image models of every provider in Settings → LLM.",
		Method: "GET",
		Path:   "models",
		Scope:  "llm:read",
		In:     reflect.TypeOf(llm.ModelsInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Image, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in llm.ModelsInput
			if err := extkit.DecodeQuery(req.Query, &in); err != nil {
				return nil, err
			}
			return impl.Models(ctx, a, in)
		},
	},
)

W is llm.image/v1's wire side: routes at /api/_c/llm.image/v1/<op>, action hooks, MCP tools and the client.

Functions

OnGenerate

func OnGenerate(owner any, fn func(e *extkit.CallEvent, in *GenerateInput) error)

OnGenerate binds fn to generate calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnModels

func OnModels(owner any, fn func(e *extkit.CallEvent, in *llm.ModelsInput) error)

OnModels binds fn to models calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

Types

Client

type Client struct {
	// contains filtered or unexported fields
}

Client is llm.image/v1 over HTTP, for the CLI and other apps. It implements Image; the token it was made with is the credential, so the extkit.Auth argument is ignored.

NewClient

func NewClient(baseURL, token string, hc *http.Client) *Client

NewClient calls llm.image/v1 on the app at baseURL with token (a PocketBase auth token or an API token).

Client.Generate

func (c *Client) Generate(ctx context.Context, _ extkit.Auth, in GenerateInput) (Result, error)

Client.Models

func (c *Client) Models(ctx context.Context, _ extkit.Auth, in llm.ModelsInput) (llm.Models, error)

GenerateInput

type GenerateInput struct {
	Model  string `json:"model"` // "provider/model", required
	Prompt string `json:"prompt"`
	N      int    `json:"n,omitempty"`    // how many (default 1)
	Size   string `json:"size,omitempty"` // "1024x1024"
	// AspectRatio is "16:9", "1:1"... for models that take one instead of a size.
	AspectRatio string `json:"aspectRatio,omitempty"`
	// References are pictures the model draws from: one to change as the prompt says, or one whose style and
	// characters a new scene keeps ("same style and characters; show them ..."). Only a model whose ModelInfo lists
	// llm.FeatureReferenceImages takes them; any other answers not_supported or the provider's own error.
	References []llm.File  `json:"references,omitempty"`
	Options    llm.Options `json:"options,omitempty"`
}

GenerateInput is what to draw.

Image

type Image interface {
	// Generate makes pictures from a prompt, and from the reference pictures it's given.
	//
	//op: POST generate
	Generate(ctx context.Context, a extkit.Auth, in GenerateInput) (Result, error)
	// Models lists the image models of every provider in Settings → LLM.
	//
	//op: GET models scope=llm:read
	Models(ctx context.Context, a extkit.Auth, in llm.ModelsInput) (llm.Models, error)
}

Image makes pictures.

Result

type Result struct {
	Files []llm.File `json:"files"`
	Model string     `json:"model"`
	Usage llm.Usage  `json:"usage"`
}

Result is the pictures made.