transcribev1

import transcribev1 "pocketone.dev/ext/contracts/llm/transcribe/v1"

Package transcribev1 is the llm.transcribe/v1 contract: a model writes down what's said in audio.

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

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

Variables

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

Contract is llm.transcribe/v1.

var W = extkit.NewWire(Contract, "llm", func(inner Transcribe, g *extkit.Guard[Transcribe]) Transcribe {
	return &guardTranscribe{inner, g}
},
	extkit.Op[Transcribe]{
		Name:   "transcribe",
		Desc:   "Writes down what's said in the audio.",
		Method: "POST",
		Path:   "transcribe",
		In:     reflect.TypeOf(TranscribeInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Transcribe, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in TranscribeInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Transcribe(ctx, a, in)
		},
	},
	extkit.Op[Transcribe]{
		Name:   "models",
		Desc:   "Lists the transcription 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 Transcribe, 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.transcribe/v1's wire side: routes at /api/_c/llm.transcribe/v1/<op>, action hooks, MCP tools and the client.

Functions

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.

OnTranscribe

func OnTranscribe(owner any, fn func(e *extkit.CallEvent, in *TranscribeInput) error)

OnTranscribe binds fn to transcribe 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.transcribe/v1 over HTTP, for the CLI and other apps. It implements Transcribe; 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.transcribe/v1 on the app at baseURL with token (a PocketBase auth token or an API token).

Client.Models

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

Client.Transcribe

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

Result

type Result struct {
	Text     string    `json:"text"`
	Language string    `json:"language,omitempty"`
	Model    string    `json:"model"`
	Usage    llm.Usage `json:"usage"`
}

Result is what was said.

Transcribe

type Transcribe interface {
	// Transcribe writes down what's said in the audio.
	//
	//op: POST transcribe
	Transcribe(ctx context.Context, a extkit.Auth, in TranscribeInput) (Result, error)
	// Models lists the transcription 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)
}

Transcribe turns audio into text.

TranscribeInput

type TranscribeInput struct {
	Model string   `json:"model"` // "provider/model", required
	Audio llm.File `json:"audio"` // its Name's extension (story.mp3) or Type tells the provider the format
	// Language is the spoken language as an ISO code ("en"), when known; empty lets the model tell.
	Language string `json:"language,omitempty"`
	// Prompt is text that helps the model (names, words it might not know), for models that take one.
	Prompt  string      `json:"prompt,omitempty"`
	Options llm.Options `json:"options,omitempty"`
}

TranscribeInput is the audio, with hints.