sidequestion

package
v0.9.52 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HistoryLimit = 20

	SystemPolicy = `` /* 683-byte string literal not displayed */

	ToolAttemptResponse = "Side questions cannot use tools. Ask using only the supplied conversation context."
)

Variables

This section is empty.

Functions

func BuildMessages

func BuildMessages(snapshot []llm.Message, history []Entry, question, providerName, model string, runtimeInputLimit int) ([]llm.Message, error)

BuildMessages constructs a bounded provider request. It preserves the exact main-session prefix whenever possible for prompt-cache reuse, then drops old side history before trimming main history at complete user-turn boundaries.

func CloneMessages

func CloneMessages(messages []llm.Message) []llm.Message

CloneMessages returns a point-in-time deep copy without changing provider protocol metadata. Request construction performs sanitization once after all context fragments have been assembled.

func PrepareContextSnapshot

func PrepareContextSnapshot(messages []llm.Message) []llm.Message

PrepareContextSnapshot returns a provider-safe point-in-time deep copy. It preserves cache anchors while removing incomplete tool protocol fragments.

Types

type Anchor added in v0.9.52

type Anchor struct {
	Messages        []llm.Message
	Provider        runboundary.ProviderContext
	DurableAnchorID int64
	Durable         bool
}

Anchor is the main-conversation boundary a side lane branches from. It is one value with one owner: the messages, the provider state they were captured with, and the provider/model identity that state belongs to always travel together, so new identity can never end up attached to an old snapshot.

func (Anchor) Clone added in v0.9.52

func (a Anchor) Clone() Anchor

Clone returns a detached copy safe to retain across turns.

type Entry

type Entry struct {
	Question  string    `json:"question"`
	Response  string    `json:"response"`
	CreatedAt time.Time `json:"created_at"`
	Usage     llm.Usage `json:"usage"`
}

func AppendHistory

func AppendHistory(history []Entry, entry Entry) []Entry

type Lane added in v0.9.52

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

Lane is one side discussion: the boundary it branched from, its own transcript, and — when the provider can branch from a captured boundary — its own provider session carried across turns.

A lane is a lifecycle object, not data. Callers must cancel any running turn and then Close it on panel close, panel clear, and every boundary invalidation.

func (*Lane) Anchor added in v0.9.52

func (l *Lane) Anchor() Anchor

Anchor returns the boundary this lane branched from.

func (*Lane) Close added in v0.9.52

func (l *Lane) Close()

Close releases the lane's provider and drops its anchor and transcript. A turn that is still running owns the provider lifetime and releases it itself, so callers should cancel before closing to avoid a detached background process.

func (*Lane) Continuing added in v0.9.52

func (l *Lane) Continuing() bool

Continuing reports whether the lane holds its own provider session. While it does, the lane is anchored: it no longer re-reads the main boundary.

func (*Lane) PrepareTurn added in v0.9.52

func (l *Lane) PrepareTurn(request TurnRequest) (*Turn, error)

PrepareTurn decides, for one question, whether the lane continues, is created by branching the anchor's provider session, or falls back to a bounded replay.

Eligibility lives here, once, rather than at each call site.

func (*Lane) ProviderState added in v0.9.52

func (l *Lane) ProviderState() []byte

ProviderState returns the lane provider's exported transport state. The live clone is not serializable; this is, which is what promotion needs.

func (*Lane) RequestPrefix added in v0.9.52

func (l *Lane) RequestPrefix() []llm.Message

RequestPrefix returns everything the lane's provider has already been given, plus its replies. The next turn appends to it so the provider's recorded resume offset and transcript digest still line up.

func (*Lane) Transcript added in v0.9.52

func (l *Lane) Transcript() []llm.Message

Transcript returns the lane's own conversation, without the main transcript it branched from. Promotion writes exactly these into a child session.

func (*Lane) Usage added in v0.9.52

func (l *Lane) Usage() []llm.Usage

Usage returns per-turn usage for the lane's own exchanges.

type Result

type Result struct {
	Response  string    `json:"response"`
	Usage     llm.Usage `json:"usage"`
	Synthetic bool      `json:"synthetic"`
}

type Turn added in v0.9.52

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

Turn is one prepared lane turn.

func (*Turn) Abandon added in v0.9.52

func (t *Turn) Abandon()

Abandon releases a prepared turn that will never run. A branch created for it is dropped; an already established lane session is kept, because nothing was sent to it.

func (*Turn) Mode added in v0.9.52

func (t *Turn) Mode() TurnMode

Mode reports how this turn reaches the model.

func (*Turn) Request added in v0.9.52

func (t *Turn) Request() llm.Request

Request exposes the prepared provider request for assertions and debugging.

func (*Turn) Run added in v0.9.52

func (t *Turn) Run(ctx context.Context, emit func(llm.Event)) (result Result, err error)

Run performs this turn's single provider request and folds the result back into the lane.

Ephemeral is decided here and nowhere else: only a turn whose provider came from the boundary fork seam runs non-ephemerally, so a Responses helper turn can never chain onto the live conversation by convention or by mistake.

type TurnMode added in v0.9.52

type TurnMode int

TurnMode reports how one lane turn reaches the model.

const (
	// TurnReplay rebuilds a bounded standalone request from the anchor.
	TurnReplay TurnMode = iota
	// TurnFork creates the lane by branching the anchor's provider session.
	TurnFork
	// TurnResume continues the lane's own provider session.
	TurnResume
)

func (TurnMode) String added in v0.9.52

func (m TurnMode) String() string

type TurnRequest added in v0.9.52

type TurnRequest struct {
	Question        string
	Anchor          Anchor
	History         []Entry
	ProviderKey     string
	Model           string
	ReasoningEffort string
	ReasoningMode   string
	// InputLimit is the runtime's own input budget, when it has one. Zero falls
	// back to the provider/model helper budget.
	InputLimit int
	// AllowFork gates lane creation from the anchor's live provider session.
	AllowFork bool
	// ForkStillAllowed is re-evaluated immediately before a branch streams. The
	// gate cannot be a single snapshot: a main run can start between preparing a
	// branch and launching it, and branching a session another process is writing
	// is exactly what AllowFork exists to avoid. Returning false downgrades the
	// prepared branch to the bounded replay path.
	ForkStillAllowed func() bool
	// ForkSource is the live provider the lane branches from. It is never used
	// for the request itself, and is never mutated.
	ForkSource llm.Provider
	// NewProvider builds a standalone provider for the bounded replay path.
	NewProvider func(providerKey, model string) (llm.Provider, error)
	// SessionID is the term-llm session a promoted lane belongs to. Empty for an
	// unpromoted lane, which keeps its turns out of session state entirely.
	SessionID string
}

TurnRequest is everything one lane turn needs. Both the TUI and the web runtime build this instead of repeating the provider/budget/request prelude.

Jump to

Keyboard shortcuts

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