Files
handler-base/messages/messages.go
Billy D. 13ef1df109
Some checks failed
CI / Lint (push) Failing after 3m2s
CI / Test (push) Successful in 3m44s
CI / Release (push) Has been skipped
CI / Notify Downstream (chat-handler) (push) Has been skipped
CI / Notify Downstream (pipeline-bridge) (push) Has been skipped
CI / Notify Downstream (stt-module) (push) Has been skipped
CI / Notify Downstream (tts-module) (push) Has been skipped
CI / Notify Downstream (voice-assistant) (push) Has been skipped
CI / Notify (push) Successful in 1s
feat!: replace msgpack with protobuf for all NATS messages
BREAKING CHANGE: All NATS message serialization now uses Protocol Buffers.
- Added proto/messages/v1/messages.proto with 22 message types
- Generated Go code at gen/messagespb/
- messages/ package now exports type aliases to proto types
- natsutil.Publish/Request/Decode use proto.Marshal/Unmarshal
- Removed legacy MessageHandler, OnMessage, wrapMapHandler
- TypedMessageHandler now returns (proto.Message, error)
- EffectiveQuery is now a free function: messages.EffectiveQuery(req)
- Removed msgpack dependency entirely
2026-02-21 14:58:05 -05:00

70 lines
2.6 KiB
Go

// Package messages re-exports protobuf message types and provides NATS
// subject constants plus helper functions.
//
// The canonical type definitions live in the generated package
// gen/messagespb (from proto/messages/v1/messages.proto).
// This package provides type aliases so existing callers can keep using
// messages.ChatRequest, etc., while the wire format is now protobuf.
package messages
import (
"time"
pb "git.daviestechlabs.io/daviestechlabs/handler-base/gen/messagespb"
)
// ════════════════════════════════════════════════════════════════════════════
// Type aliases — use these or import gen/messagespb directly.
// ════════════════════════════════════════════════════════════════════════════
// Common
type ErrorResponse = pb.ErrorResponse
// Chat
type LoginEvent = pb.LoginEvent
type GreetingRequest = pb.GreetingRequest
type GreetingResponse = pb.GreetingResponse
type ChatRequest = pb.ChatRequest
type ChatResponse = pb.ChatResponse
type ChatStreamChunk = pb.ChatStreamChunk
// Voice
type VoiceRequest = pb.VoiceRequest
type VoiceResponse = pb.VoiceResponse
type DocumentSource = pb.DocumentSource
// TTS
type TTSRequest = pb.TTSRequest
type TTSAudioChunk = pb.TTSAudioChunk
type TTSFullResponse = pb.TTSFullResponse
type TTSStatus = pb.TTSStatus
type TTSVoiceInfo = pb.TTSVoiceInfo
type TTSVoiceListResponse = pb.TTSVoiceListResponse
type TTSVoiceRefreshResponse = pb.TTSVoiceRefreshResponse
// STT
type STTStreamMessage = pb.STTStreamMessage
type STTTranscription = pb.STTTranscription
type STTInterrupt = pb.STTInterrupt
// Pipeline
type PipelineTrigger = pb.PipelineTrigger
type PipelineStatus = pb.PipelineStatus
// ════════════════════════════════════════════════════════════════════════════
// Helpers
// ════════════════════════════════════════════════════════════════════════════
// EffectiveQuery returns Message or falls back to Query.
func EffectiveQuery(c *ChatRequest) string {
if c.GetMessage() != "" {
return c.GetMessage()
}
return c.GetQuery()
}
// Timestamp returns the current Unix timestamp.
func Timestamp() int64 {
return time.Now().Unix()
}