musicv1
import musicv1 "pocketone.dev/ext/contracts/llm/music/v1"
Package musicv1 is the llm.music/v1 contract: a model makes music from a prompt (and lyrics). Music takes a while, so it's a job: create starts it (or waits for it, with wait), get follows it, content fetches its files.
A wire contract at /api/_c/llm.music/v1. In pb_hooks it's $llm.music.
Source: ext/contracts/llm/music/v1.
Variables
var Contract = extkit.NewContract[Music]("llm.music/v1", extkit.One).JS(extkit.JSHooks, nil).JSTypes(jsTypes)
Contract is llm.music/v1.
var W = extkit.NewWire(Contract, "llm", func(inner Music, g *extkit.Guard[Music]) Music {
return &guardMusic{inner, g}
},
extkit.Op[Music]{
Name: "create",
Desc: "Starts making music. With Wait it returns once the job is done (or failed), its files included; otherwise at once, to follow with Get.",
Method: "POST",
Path: "create",
In: reflect.TypeOf(CreateInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Music, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in CreateInput
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Create(ctx, a, in)
},
},
extkit.Op[Music]{
Name: "get",
Desc: "Says how a job is going.",
Method: "POST",
Path: "get",
Scope: "llm:read",
In: reflect.TypeOf(llm.JobRef{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Music, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in llm.JobRef
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Get(ctx, a, in)
},
},
extkit.Op[Music]{
Name: "content",
Desc: "Fetches one of a done job's files.",
Method: "POST",
Path: "content",
Scope: "llm:read",
In: reflect.TypeOf(llm.ContentInput{}),
Out: extkit.OutJSON,
Invoke: func(ctx context.Context, impl Music, a extkit.Auth, req extkit.OpRequest) (any, error) {
var in llm.ContentInput
if err := extkit.DecodeInput(req.JSON, &in); err != nil {
return nil, err
}
return impl.Content(ctx, a, in)
},
},
extkit.Op[Music]{
Name: "models",
Desc: "Lists the music 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 Music, 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.music/v1's wire side: routes at /api/_c/llm.music/v1/<op>, action hooks, MCP tools and the client.
Functions
OnContent
func OnContent(owner any, fn func(e *extkit.CallEvent, in *llm.ContentInput) error)
OnContent binds fn to content 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.
OnCreate
func OnCreate(owner any, fn func(e *extkit.CallEvent, in *CreateInput) error)
OnCreate binds fn to create 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.
OnGet
func OnGet(owner any, fn func(e *extkit.CallEvent, in *llm.JobRef) error)
OnGet binds fn to get 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.music/v1 over HTTP, for the CLI and other apps. It implements Music; 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.music/v1 on the app at baseURL with token (a PocketBase auth token or an API token).
Client.Content
func (c *Client) Content(ctx context.Context, _ extkit.Auth, in llm.ContentInput) (llm.File, error)
Client.Create
func (c *Client) Create(ctx context.Context, _ extkit.Auth, in CreateInput) (llm.Job, error)
Client.Get
func (c *Client) Get(ctx context.Context, _ extkit.Auth, in llm.JobRef) (llm.Job, error)
Client.Models
func (c *Client) Models(ctx context.Context, _ extkit.Auth, in llm.ModelsInput) (llm.Models, error)
CreateInput
type CreateInput struct {
Model string `json:"model"` // "provider/model", required
Prompt string `json:"prompt"` // the style: "gentle lullaby, music box and soft strings"
Lyrics string `json:"lyrics,omitempty"`
// Seconds is how long (the provider's default when 0).
Seconds float64 `json:"seconds,omitempty"`
// Wait is how long to wait for the job, as a duration ("5m"); "" returns at once.
Wait string `json:"wait,omitempty"`
Options llm.Options `json:"options,omitempty"`
}
CreateInput is the music to make.
Music
type Music interface {
// Create starts making music. With Wait it returns once the job is done (or failed), its files included;
// otherwise at once, to follow with Get.
//
//op: POST create
Create(ctx context.Context, a extkit.Auth, in CreateInput) (llm.Job, error)
// Get says how a job is going.
//
//op: POST get scope=llm:read
Get(ctx context.Context, a extkit.Auth, in llm.JobRef) (llm.Job, error)
// Content fetches one of a done job's files.
//
//op: POST content scope=llm:read
Content(ctx context.Context, a extkit.Auth, in llm.ContentInput) (llm.File, error)
// Models lists the music 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)
}
Music makes music.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.