vision

package
v0.64.1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package vision turns verified image bytes into bounded text.

Index

Constants

View Source
const (
	// MaxImageDim is retained for legacy inline tool rendering. Canonical
	// baselines preserve source dimensions unless their encoded payload exceeds
	// MaxRendererPayloadBytes.
	MaxImageDim = 2000
	// MaxRendererPayloadBytes is the hard provider image payload ceiling.
	MaxRendererPayloadBytes = 5 * 1024 * 1024
	// MaxImageInputBytes aliases the canonical session-ingress ceiling. Together
	// with MaxImagePixels, it protects model and Xberg paths from compressed-byte
	// and decompression-bomb inputs.
	MaxImageInputBytes = ai.MaxImageInputBytes
	MaxImagePixels     = 50_000_000
)
View Source
const (
	// BaselineVLMTimeout leaves five seconds of Enricher's 15 second message
	// budget for Xberg after a slow model attempt.
	BaselineVLMTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

func ExtractWithXberg

func ExtractWithXberg(ctx context.Context, path string) (string, error)

ExtractWithXberg shells out to the Xberg CLI to extract text from a file. It returns an error when the binary is missing or extraction fails.

func NormalizeXbergBaseline

func NormalizeXbergBaseline(text string) string

NormalizeXbergBaseline makes local OCR conform to the same durable contract without inventing scene understanding that Xberg does not provide.

func PrepareInline

func PrepareInline(data []byte, cfg image.Config, mime string) ([]byte, string, error)

PrepareInline preserves the old read-tool behavior: fit to MaxImageDim.

func PrepareRendererPayloadContext

func PrepareRendererPayloadContext(ctx context.Context, data []byte, cfg image.Config, mime string) ([]byte, string, error)

PrepareRendererPayloadContext keeps original pixels and dimensions untouched whenever they fit the renderer payload ceiling. Both baseline rendering and active provider hydration use this adaptive payload preparation. Only a hard payload overflow causes reduction; no fixed dimension ceiling or tiling is applied. The standard-library decode/encode calls themselves are not interruptible, so it checks ctx around each potentially expensive step.

func ValidateBudget

func ValidateBudget(data []byte) (image.Config, error)

ValidateBudget rejects unsafe image bytes before full decode for callers that do not have a declared MIME to compare.

func ValidateImage

func ValidateImage(data []byte, declaredMIME string) (image.Config, string, error)

ValidateImage validates the security budget and requires the declared MIME to match the decoder's actual format. Canonical media never trusts an extension or provider-supplied content type.

Types

type BaselineRenderer

type BaselineRenderer interface {
	Baseline(context.Context, Request) (ai.ImageBaseline, error)
}

BaselineRenderer is the narrow contract session-media enrichment needs. Implementations must honor ctx promptly. Enricher protects its message deadline from non-cooperative renderers, but at most two abandoned calls may continue in the background until their implementation returns.

type Options

type Options struct {
	Model  ai.Model
	APIKey string
	Build  StreamBuilder
}

Options configures a Service.

type Request

type Request struct {
	Data     []byte
	MimeType string
}

Request is one image to render as stable baseline text.

type Service

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

Service owns one resolved baseline provider. Canonical enrichment resolves a fresh Service for each image-bearing message so deployment settings are not runner-snapshot state.

func New

func New(opts Options) *Service

New creates a service. A missing or invalid model is intentionally an Xberg-only service rather than a construction error.

func NewFromSnapshot

func NewFromSnapshot(snap *config.Snapshot, build StreamBuilder) *Service

NewFromSnapshot builds a service from one current application snapshot.

func (*Service) Baseline

func (s *Service) Baseline(ctx context.Context, req Request) (ai.ImageBaseline, error)

Baseline produces the sole canonical generic OCR + scene representation. A ready result is returned only after an explicit clean stop and exact contract validation. Model failures fall back to Xberg using the verified same bytes.

func (*Service) ModelConfigured

func (s *Service) ModelConfigured() bool

type StreamBuilder

type StreamBuilder func(api, apiKey, baseURL string) (providers.StreamFunc, error)

StreamBuilder constructs a provider stream for one API/credential pair.

Jump to

Keyboard shortcuts

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