Files
archie/internal/gateway/messaging_convert.go
T
sam e3b1a859a8 feat(gateway): flip channel boundary onto messaging.Message
Replaced gateway.Message as the currency at the channel-facing boundary
with the canonical internal/domain/messaging.Message. Channel adapters
now build the record directly (RoleUser, ConversationID, Sender) and the
Router hands it back unchanged, so nothing converts between two shapes in
process. gateway.Message is deleted; the dashboard route that had no home
in the record lives in a new Inbound envelope (Message + transport-only
Page), which reaches the system prompt and is never persisted.

Role is now set at construction instead of derived at the store boundary,
and the assistant reply is a direct messaging.Message (RoleAssistant,
Sender=botUser). The gRPC proto is unchanged: pb.Message still carries no
role, and both sides keep deriving it from the owning session's bot
identity via gateway.RoleForSender (ToStoredMessage/FromStoredMessage are
deleted).

Adds tests that the old shape could not express: Page reaches the system
prompt but not the persisted record, and a channel-built Inbound round-trips
with the Role the channel set.

Refs: archie-core-9g5e
2026-09-09 01:05:36 +10:00

34 lines
1.4 KiB
Go

package gateway
import (
"github.com/samcharles93/archie-core/internal/domain/messaging"
)
// This file holds the one piece of the old channel-facing Message that
// outlived it: the role derivation.
//
// messaging.Message is the canonical persisted record and is now also the
// currency at the channel-facing boundary. Channel adapters build it
// directly and set Role themselves (always messaging.RoleUser -- a channel
// carries only what a person said), and the gateway sets
// messaging.RoleAssistant on the reply it generates, so nothing converts
// between two shapes of a message in process any more.
//
// The wire is the exception. pb.Message carries no role, so both sides of
// the gRPC contract derive it from the owning session's bot identity
// instead of adding a field to the proto -- see
// internal/infrastructure/gatewayrpc. Because both derive from the same
// session, they agree.
// RoleForSender reports the role of a message written by sender in a
// session whose bot identity is botUser. It is the comparison this package
// already makes elsewhere (compressTurnHistory, messagesToCompressed,
// PriorReply, and the sessioncurator adapter): a message sent by the
// session's bot is the assistant's, anything else is the user's.
func RoleForSender(sender, botUser string) messaging.Role {
if sender == botUser {
return messaging.RoleAssistant
}
return messaging.RoleUser
}