core

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 6 Imported by: 1 module, 0 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 core folds Responses events without owning credentials or transports. Event folding and continuation rules derive from CPA CodexReflow/CodexComp.

Index

Constants

View Source
const EncryptedReasoningInclude = encInclude
View Source
const MaxStreamBufferSize = maxStreamBufferSize

Variables

This section is empty.

Functions

func ContinuationTrigger

func ContinuationTrigger(usage, summed Object, maxTier, minimum int) string

func ContinueReplay

func ContinueReplay(tail []any, reasoning []Object, marker string) []any

func Eligible

func Eligible(body Object) bool

Eligible is a conservative text-model naming rule; it does not claim a model's actual capabilities. Runtime decisions also require usable reasoning state.

func InContinueWindow

func InContinueWindow(n *int, maxTier int) bool

func ReasoningTokens

func ReasoningTokens(usage Object) *int

These operations are also used by host adapters whose stream lifecycle is controlled externally. They share Session's algorithms without host SDKs.

func SumUsage

func SumUsage(acc, usage Object)

func TierN

func TierN(tokens *int) *int

func ToFloat

func ToFloat(value any) float64

Types

type BufferedItem

type BufferedItem struct {
	Index  int
	Item   Object
	Events []Object
}

type Config

type Config struct {
	MaxContinue      int    `json:"max_continue"`
	MaxTierN         int    `json:"max_tier_n"`
	MaxBufferedBytes int    `json:"max_buffered_bytes"`
	MarkerText       string `json:"marker_text"`
}

func DefaultConfig

func DefaultConfig() Config

func (Config) Validate

func (c Config) Validate() error

type ContinuationDecision

type ContinuationDecision struct {
	Continue   bool
	Trigger    string
	StopReason string
}

type ContinuationPolicy

type ContinuationPolicy struct {
	MaxContinue        int
	MaxTierN           int
	MinReasoningTokens int
	Replayable         bool
	GuardHostedTools   bool
}

type Decision

type Decision struct {
	Next   Object
	Events []Object
	Result Result
}

type Decoder

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

Decoder accepts arbitrary chunks without owning or buffering a transport. It has the same bounded framing rules as Reader.

func (*Decoder) Finish

func (d *Decoder) Finish() error

func (*Decoder) Push

func (d *Decoder) Push(chunk []byte) ([]Object, error)

type EventDecoder

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

eventDecoder accepts the host's raw WebSocket JSON events and SSE data: payloads (with or without trailing newlines). JSON boundaries, not searching for "data:" within arbitrary bytes, delimit events. Its incremental scanner avoids rescanning a large JSON string after every fragmented host read.

func (*EventDecoder) BufferedBytes

func (d *EventDecoder) BufferedBytes() int

BufferedBytes reports resource use, never the buffered payload.

func (*EventDecoder) Feed

func (d *EventDecoder) Feed(payload []byte) error

func (*EventDecoder) Finish

func (d *EventDecoder) Finish() error

func (*EventDecoder) Next

func (d *EventDecoder) Next() (map[string]any, bool, error)

type EventPolicy

type EventPolicy struct {
	Strict           bool
	MaxBufferedBytes int
}

EventPolicy selects protocol-boundary behavior, not a transport or host SDK. Strict callers own cloned events and normalize response IDs. Legacy hosts may retain their existing event ownership and permissive framing contract.

type FoldState

type FoldState struct {
	RoundNo        int
	OutputIndex    int
	Sequence       int
	BaseResponse   Object
	FinalOutput    []Object
	RoundReasoning []Object
	Kinds          map[int]string
	Indexes        map[int]int
	Buffered       []BufferedItem
	BufferedBytes  int
	Terminal       Object
	Usage          Object
	SummedUsage    Object
	FirstUsage     Object
	RoundsInfo     []Object
}

FoldState is the transport-independent accumulator shared by Session and host adapters. A single request owns it; callers must serialize access. State can contain private input/output and must never be logged wholesale.

func (*FoldState) DecideContinuation

func (f *FoldState) DecideContinuation(policy ContinuationPolicy) ContinuationDecision

func (*FoldState) Flush

func (f *FoldState) Flush(emit func(Object) error, normalizeID bool) error

func (*FoldState) HasEncryptedContent

func (f *FoldState) HasEncryptedContent() bool

func (*FoldState) Process

func (f *FoldState) Process(ev Object, policy EventPolicy, emit func(Object) error) error

Process forwards reasoning and buffers final text/client tools until a continuation decision is known. The emitter must not retain mutable events.

func (*FoldState) RecordRound

func (f *FoldState) RecordRound(terminal, usage Object, includeTier bool)

func (*FoldState) ResetRound

func (f *FoldState) ResetRound()

func (*FoldState) Stamp

func (f *FoldState) Stamp(ev Object, normalizeID bool) Object

type Object

type Object = map[string]any

func AgentUsage

func AgentUsage(first, summed, final Object, flushed bool) Object

func Clone

func Clone(in Object) (Object, error)

func CloneUsage

func CloneUsage(usage Object) Object

func CommentaryNudge

func CommentaryNudge(marker string) Object

func FailedEvent

func FailedEvent(status int, detail string) Object

func NextRoundBody

func NextRoundBody(base Object, input []any) Object

func TerminalEvent

func TerminalEvent(upstream, base Object, output []Object, usage Object, rounds []Object, billed Object, stopped, incomplete string) Object

type Reader

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

Reader incrementally decodes SSE or raw JSON frames. It owns no transport.

func NewReader

func NewReader(r io.Reader) *Reader

func (*Reader) Next

func (r *Reader) Next() (Object, error)

type Result

type Result struct {
	VisibleID   string
	UpstreamID  string
	Status      string
	Rounds      int
	StopReason  string
	BilledUsage Object
	// ReplayRequest includes the last actual input and output, including hidden
	// continuation nudges. Keep in bounded memory only; never log or persist it.
	ReplayRequest Object
}

type Session

type Session struct {
	FoldState
	// contains filtered or unexported fields
}

func New

func New(config Config, request Object, replayBase Object) (*Session, error)

New starts one client request. replayBase is the complete effective request, when an adapter has resolved previous_response_id from its scoped cache. An unresolved parent is passed through without an unsafe partial replay.

func (*Session) Abort

func (s *Session) Abort(reason string) Object

Abort emits an incomplete result. Reasons are fixed codes, not upstream bodies.

func (*Session) Finish

func (s *Session) Finish() (Decision, error)

Finish returns the next upstream body or the one final downstream result.

func (*Session) HasTerminal

func (s *Session) HasTerminal() bool

func (*Session) Push

func (s *Session) Push(ev Object) ([]Object, error)

Push owns a clone of ev and delegates event folding to the shared core.

func (*Session) Rounds

func (s *Session) Rounds() int

Rounds is the number of upstream attempts opened for this client request.

func (*Session) String

func (s *Session) String() string

Jump to

Keyboard shortcuts

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