{"modulePath":"github.com/pyrycode/pyrycode","version":"v0.43.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package turnbridge\n\nPackage 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.\n\n## Functions\n\n```go\nfunc BuildTurnState(conversationID string, state TurnState) (typ string, payload protocol.TurnStatePayload)\n```\nBuildTurnState 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.\n\n```go\nfunc MapEvent(ev turnevent.Event, tc TurnContext) (typ string, payload any, ok bool)\n```\nMapEvent maps one neutral turnevent.Event plus explicit turn context to the matching v2 interactive wire payload and its envelope type discriminant.\n\nok 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.\n\npayload 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.\n\n## Types\n\n```go\ntype TurnContext struct {\n\tConversationID string\n\tTurnID         string\n\t// Seq is the per-turn assistant-delta ordering counter. It is consumed\n\t// ONLY by the TextChunk -\u003e assistant_delta mapping and ignored for every\n\t// other event kind; the consumer advances it.\n\tSeq int\n}\n```\nTurnContext 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.\n\n```go\ntype TurnState string\n```\nTurnState 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).\n\n```go\nconst (\n\tStateThinking   TurnState = \"thinking\"\n\tStateResponding TurnState = \"responding\"\n\tStateIdle       TurnState = \"idle\"\n)\n```\n\n","path":"github.com/pyrycode/pyrycode/internal/turnbridge","name":"turnbridge","synopsis":"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.","isRedistributable":true}
