inference

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 22 Imported by: 4 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package inference bridges the portable res/int/inference contract with the Ext plugin engine. It declares the inference.provider/v1 plugin contract and supplies host and guest helpers so any res/int/inference Provider can be served as an Ext plugin guest and invoked by a host through a plugin session.

The package depends only on res/int/inference (the contract) and pkg/ext-go/engine (the plugin mechanics). It knows nothing about CTX, CTN, Cymonkey, or any concrete provider.

Package inference guest-side helpers register a res/int/inference.Provider as an Ext plugin guest serving inference.provider/v1.

Package inference host-side helpers call inference.provider/v1 operations through a plugin session.

Package inference guest-side operation declarations for inference.provider/v1.

Package inference guest-side stream bridging for the stream and synthesize operations, which open ext.stream instances.

Index

Constants

View Source
const (
	OpCapabilities = "capabilities" // observation
	OpHealth       = "health"       // observation
	OpGenerate     = "generate"     // action
	OpStream       = "stream"       // action (opens an ext.stream of GenerationEvent)
	OpEmbed        = "embed"        // action
	OpTranscribe   = "transcribe"   // action
	OpSynthesize   = "synthesize"   // action (opens an ext.stream of audio bytes)
	OpModels       = "models"       // observation
	OpClose        = "close"        // action
)

Operation names for the inference.provider/v1 contract. Surfaces are admission classifications with no built-in authority.

View Source
const ContractName = "inference.provider"

ContractName is the recorded plugin contract name (see docs/contract-names.md).

View Source
const ContractVersion = "v1"

ContractVersion is the contract version.

Variables

View Source
var ContractRef = plugin.ContractRef{Name: ContractName, Version: ContractVersion}

ContractRef is the exact contract reference for inference.provider/v1.

Functions

func CapabilityOperation

func CapabilityOperation(c inference.Capability) (string, bool)

CapabilityOperation maps a res/int/inference capability to its contract operation. A provider that does not advertise a capability must return ErrUnsupported for that operation.

func DecodeAudio added in v0.2.0

func DecodeAudio(item json.RawMessage) ([]byte, error)

DecodeAudio decodes one item of a synthesis stream opened by Client.Synthesize into the audio bytes it carries.

func DecodeEvent added in v0.2.0

func DecodeEvent(item json.RawMessage) (inference.GenerationEvent, error)

DecodeEvent decodes one item of a generation stream opened by Client.Stream. The last event of a stream that ends without error is a completed event carrying the response.

func DecodeStructuredOutput

func DecodeStructuredOutput[T any](response domain.GenerationResponse, schema json.RawMessage) (T, error)

func Descriptor

func Descriptor(id plugin.Identity) plugin.Descriptor

Descriptor builds the plugin Descriptor for an inference provider plugin given its identity. The provider advertises exactly the operations it supports through res/int/inference.ProviderInfo.Capabilities; the descriptor declares the complete contract surface and the guest enforces support at call time.

func Open

func Operations

func Operations() []plugin.Operation

Operations returns the full declared operation set for the contract, with surfaces. Stream and synthesize declare progress because they may emit stream frames before completion.

func PackageExecutable

func PackageExecutable(options ExecutablePackage) (packagekit.Manifest, error)

PackageExecutable copies a compiled guest into a sealed ext.package/v1 directory. The caller reviews and installs the resulting package separately.

func RegisterProvider

func RegisterProvider(r *author.Registry, p inference.Provider, authorize func(context.Context, plugin.Request) error) (*plugin.Descriptor, error)

RegisterProvider registers all inference.provider/v1 operations on the author registry and returns the plugin Descriptor. The authorize callback is required by the engine and must enforce the host's policy. RegisterProvider creates an internal ext.stream service for stream and synthesize operations.

func ServeCurrentExecutable

func ServeCurrentExecutable(ctx context.Context, id, version string, provider inference.Provider, authorize func(context.Context, plugin.Request) error) error

ServeCurrentExecutable pins the guest identity to the running executable.

func ServeStdio

func ServeStdio(ctx context.Context, id plugin.Identity, provider inference.Provider, authorize func(context.Context, plugin.Request) error) error

ServeStdio serves one caller-configured provider over the Ext JSON-line transport. The caller supplies the reviewed identity and admission policy.

func ValidateStructuredOutput

func ValidateStructuredOutput(response domain.GenerationResponse, schema json.RawMessage) error

ValidateStructuredOutput validates completed model output with the Ext engine's bounded, offline JSON Schema implementation.

Types

type Backend

type Backend = plugin.Backend

type Client

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

Client calls inference.provider/v1 operations on a plugin session.

func NewClient

func NewClient(caller author.Caller) *Client

NewClient wraps a plugin session caller as an inference provider client.

func (*Client) Capabilities

func (c *Client) Capabilities(ctx context.Context) (inference.ProviderInfo, error)

Capabilities returns the provider's metadata.

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

Close releases the provider.

func (*Client) Embed

Embed returns embeddings for the inputs.

func (*Client) Generate

Generate runs one generation pass and returns the complete response.

func (*Client) Health

func (c *Client) Health(ctx context.Context) (health, error)

Health reports whether the provider is healthy and ready.

func (*Client) Models

func (c *Client) Models(ctx context.Context) ([]inference.ModelInfo, error)

Models lists the models the provider can serve.

func (*Client) Stream

Stream opens an ext.stream of GenerationEvent and returns its reader. The returned stream.Client reads from the provider's generation stream via the ext.stream protocol; DecodeEvent decodes each item. A stream that ends without error ends with a completed event carrying the final GenerationResponse.

func (*Client) Synthesize

func (c *Client) Synthesize(ctx context.Context, req inference.SpeechRequest) (*stream.Client, error)

Synthesize opens an ext.stream of audio and returns its reader; DecodeAudio turns each item back into bytes.

func (*Client) Transcribe

Transcribe transcribes audio.

type DescriptorType

type DescriptorType = plugin.Descriptor

type ExecutablePackage

type ExecutablePackage struct {
	ID, Version, Binary, OutputDir, OS, Arch string
}

ExecutablePackage describes one compiled inference guest to package. Empty OS and Arch use the current platform. The output directory must not exist.

type Identity

type Identity = plugin.Identity

Host and guest construction types are re-exported here so inference programs depend on the integration module instead of importing the engine directly.

type Options

type Options = plugin.Options

type Provider

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

Provider adapts a res/int/inference.Provider to the plugin guest contract. The guest declares the full inference.provider/v1 surface and routes each operation to the provider. A provider returns inference.ErrUnsupported for any operation it does not advertise.

type Request

type Request = plugin.Request

type Session

type Session = plugin.Session

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL