Documentation
¶
Overview ¶
Package protocol maps HTTP surfaces and wire events onto relaykit DTOs.
relaykit deliberately stops at the DTO boundary: it neither parses nor emits SSE. Everything below the DTO — framing, event names, the `data: [DONE]` sentinel — is protocol plumbing and therefore lives here.
Index ¶
- func ClientModel(format types.RelayFormat, request any, pathModel string) string
- func DecodeRequest(format types.RelayFormat, body []byte) (any, error)
- func DecodeStreamEvent(format types.RelayFormat, event Event) (value any, done bool, err error)
- func EncodeResponse(value any) ([]byte, error)
- func IsStreamRequest(format types.RelayFormat, request any, path string) bool
- func MatchInbound(path string) (types.RelayFormat, string, bool)
- func SetModel(request any, model string)
- type Event
- type Reader
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientModel ¶
func ClientModel(format types.RelayFormat, request any, pathModel string) string
ClientModel reads the model name a client asked for. For Gemini the caller must supply the name parsed from the path.
func DecodeRequest ¶
func DecodeRequest(format types.RelayFormat, body []byte) (any, error)
DecodeRequest parses a client body into the relaykit DTO for its protocol.
func DecodeStreamEvent ¶
DecodeStreamEvent parses one upstream SSE frame into a relaykit DTO.
done reports the end of the stream; the caller stops reading once it is true. Frames the converter cannot represent are skipped (done=false, value=nil, err=nil) rather than failing the whole stream, because upstreams routinely emit keep-alives and vendor-specific event types.
func EncodeResponse ¶
EncodeResponse serialises a converted DTO for the client.
func IsStreamRequest ¶
func IsStreamRequest(format types.RelayFormat, request any, path string) bool
IsStreamRequest reports whether the decoded request asked for streaming. Each protocol carries the flag differently: a body field for OpenAI and Claude, the URL method for Gemini.
func MatchInbound ¶
func MatchInbound(path string) (types.RelayFormat, string, bool)
MatchInbound resolves the client protocol from a request path. The second return is the model name extracted from the path, which only Gemini uses.
Types ¶
type Event ¶
Event is one decoded SSE frame.
func EncodeStreamEvent ¶
func EncodeStreamEvent(format types.RelayFormat, value any) ([]Event, error)
EncodeStreamEvent renders a converted DTO as downstream SSE frame(s).
Claude Messages and OpenAI Responses frame every event with a matching `event:` line; OpenAI Chat and Gemini send bare data frames.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader decodes an SSE byte stream into frames.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer emits SSE frames.
func (*Writer) WriteComment ¶
WriteComment emits an SSE comment, used as a keep-alive ping.
func (*Writer) WriteData ¶
WriteData emits a data-only frame, used by the OpenAI Chat and Gemini surfaces.