localturn

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package localturn defines the trusted extension contract for generic proxy-local turn handling.

Handlers are explicitly contributed via FeatureBundle and frozen into an immutable runtime snapshot. Match is a pure examination of the normalized canonical ingress call; it may only claim complete message indexes with bounded reason codes. Handle returns bounded assistant text (≤64KiB) from which core constructs the canonical assistant message and local stream. No arbitrary streams or provider calls are produced by handlers.

Handler.FailureMode uses pkg/lipsdk/hooks.FailureMode (FailOpen/FailClosed) applied to Match errors before claim; after claim all failures are fail-closed by the runtime. Package localturn does not import internal packages.

Index

Constants

View Source
const (
	MaxReasonCodeBytes = 64
	MaxReplyTextBytes  = 64 * 1024
	MaxHandlerIDBytes  = 128
)

Bounds: consistent with steering's 64KiB cap.

View Source
const (
	FailureModeUnspecified = hooks.FailureModeUnspecified
	FailOpen               = hooks.FailOpen
	FailClosed             = hooks.FailClosed
)

Variables

This section is empty.

Functions

func IsNilHandler

func IsNilHandler(h Handler) bool

IsNilHandler reports whether h is nil or a typed-nil handler value.

func ValidateHandlerID

func ValidateHandlerID(id string) error

ValidateHandlerID reports whether id is a bounded ascii identifier for a handler. Exported for feature-bundle validation; keeps vet/lint from flagging unused helper.

Types

type FailureMode

type FailureMode = hooks.FailureMode

Re-export hooks failure mode for convenience; handlers must not import internal.

type HandleInput

type HandleInput struct {
	Call  lipapi.Call
	Meta  Meta
	Match MatchResult
}

HandleInput is the input to Handler.Handle after successful source tagging.

type Handler

type Handler interface {
	ID() string
	Order() int
	FailureMode() hooks.FailureMode
	Match(ctx context.Context, call lipapi.Call, meta Meta) (MatchResult, error)
	Handle(ctx context.Context, input HandleInput) (Reply, error)
}

Handler is the generic local-turn extension seam contributed via FeatureBundle.

func MaterializeSorted

func MaterializeSorted(in []Handler) []Handler

MaterializeSorted returns a defensive copy of handlers sorted by Order ascending and then ID. Stable sorting preserves original order for exact ties.

type MatchResult

type MatchResult struct {
	Claimed bool
	Indexes []int
	Reason  ReasonCode
}

MatchResult claims zero or more complete normalized source messages for local handling. When Claimed is false, the handler passes and Indexes/Reasons must be empty. When Claimed is true, Indexes identifies the complete message indexes in the normalized ingress call and Reason is the bounded identifier for source tagging.

func (MatchResult) Validate

func (m MatchResult) Validate(meta Meta) error

Validate reports whether the match result is well-formed for the given Meta. It enforces: claimed => non-empty indexes with bounded reason and each index in range, all indexes are distinct, non-claimed => empty indexes and empty reason.

type Meta

type Meta struct {
	TraceID      string
	MessageCount int
}

Meta carries authoritative per-request context for Match. MessageCount is the number of complete normalized messages in the ingress call available for claiming. Handlers must not claim indexes outside [0, MessageCount).

type ReasonCode

type ReasonCode string

ReasonCode is a bounded non-secret identifier for diagnostics.

func (ReasonCode) Validate

func (r ReasonCode) Validate() error

Validate reports whether the reason code is a bounded ascii identifier.

type Reply

type Reply struct {
	Text string
}

Reply is the bounded assistant text returned by a local-turn handler. Core constructs the canonical assistant message, tags it, and builds the local finite EventStream from this content. Role is always assistant.

func (Reply) Validate

func (r Reply) Validate() error

Validate reports whether the reply is well-formed.

Jump to

Keyboard shortcuts

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