turnbridge

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 7 Imported by: 0 modules, 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 turnbridge adapts the neutral internal turn-event model (internal/turnevent, #606) OUT to the v2 interactive wire payloads (#607): MapEvent shapes one turnevent.Event into a typed payload, and BuildTurnState shapes the turn_state payload the lifecycle machine drives. It is a pure value-to-value adapter — no I/O, no state, no envelope-ID minting, no clock read, no sealing. Every one of those belongs to the consumer (the turn-lifecycle integration slice); keeping them out is what makes this table-testable and isolates it from the lifecycle state machine. See cmd/pyry's interactiveTurnEmitterV2.emit for the consumer shape that wraps a payload into an Envelope.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTurnState

func BuildTurnState(conversationID string, state TurnState) (typ string, payload protocol.TurnStatePayload)

BuildTurnState shapes a turn_state payload for the given conversation and target state. The consumer's lifecycle machine decides WHICH state applies (e.g. observing a ThoughtChunk means "thinking") and calls this; the adapter only shapes the payload. The return type is concrete (not any) because it is monomorphic — the consumer needs no type assertion.

func MapEvent

func MapEvent(ev turnevent.Event, tc TurnContext) (typ string, payload any, ok bool)

MapEvent maps one neutral turnevent.Event plus explicit turn context to the matching v2 interactive wire payload and its envelope type discriminant.

ok is false for events with no wire representation: ThoughtChunk (ADR 025 — #607 defines no thought-text envelope; thinking surfaces as a turn_state transition the consumer drives via BuildTurnState, and the thought text is NOT forwarded) and any nil/unknown Event. The consumer drops + debug-logs those. Pure; safe on a zero-value Event.

payload is one of the protocol.*Payload value structs, or nil when ok is false. It is any because the payloads share no marker interface; the consumer json.Marshals it directly (same path as protocol.MessagePayload). The consumer owns the envelope ID, TS, marshal, and seal — none happen here.

Types

type TurnContext

type TurnContext struct {
	ConversationID string
	TurnID         string
	// Seq is the per-turn assistant-delta ordering counter. It is consumed
	// ONLY by the TextChunk -> assistant_delta mapping and ignored for every
	// other event kind; the consumer advances it.
	Seq int
}

TurnContext is the per-event turn addressing the consumer supplies to MapEvent. The adapter never derives these — which conversation / turn / seq applies to a given event is a turn-lifecycle decision owned by the consumer.

type TurnState

type TurnState string

TurnState is the coarse turn-lifecycle state BuildTurnState shapes into a turn_state payload. String-backed so the call site is enum-safe; the wire field itself stays a plain string (#607).

const (
	StateThinking   TurnState = "thinking"
	StateResponding TurnState = "responding"
	StateIdle       TurnState = "idle"
)

Jump to

Keyboard shortcuts

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