Files
archie/internal/gateway/chat_contract.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

64 lines
2.1 KiB
Go

package gateway
import (
"context"
"github.com/samcharles93/archie-core/internal/domain/messaging"
"github.com/samcharles93/archie-core/internal/taskstate"
)
// ChatContract is the conversational boundary consumed by channel frontends.
// Results are snapshots: callers must not rely on shared object identity.
type ChatContract interface { //nolint:interfacebloat // wire contract intentionally covers the complete Gateway facade
Snapshot(context.Context) (ChatSnapshot, error)
GetSession(context.Context, string) (SessionContext, bool, error)
RecentMessages(context.Context, string, int) ([]messaging.Message, error)
RecentTurns(context.Context, string, int) ([]TurnRecord, error)
Route(context.Context, Inbound) (ChatReply, error)
// Stream emits started, delta/tool/media, then done or error, in order.
// Callers must drain the stream or cancel the context. Cancellation closes it.
Stream(context.Context, Inbound) (<-chan ChatEvent, error)
Cancel(context.Context, string) (ChatCancellation, error)
SetPersona(context.Context, string, string) (bool, error)
ChatTaskActionContract
}
// ChatTaskActionContract is the operator task mutation capability exposed by
// the Gateway. It is separate so read/turn consumers do not need to model it.
type ChatTaskActionContract interface {
ApplyTaskAction(context.Context, string, int64, taskstate.Action) (TaskActionResult, error)
}
type ChatSnapshot struct {
Sessions []SessionContext
Models []string
ModelsByProvider map[string][]string
Providers []string
ActiveModel string
ActiveProvider string
Personas []string
ActivePersonas map[string]string
RestartAvailable bool
CancellationAvailable bool
PersonasAvailable bool
}
type ChatReply struct {
Text string
SessionID string
}
type ChatCancellation struct {
Cancelled bool
Dropped int
}
// ChatEvent contains values only; Text holds the error message for error events.
type ChatEvent struct {
Kind string
Text string
SessionID string
Tool ToolCallEvent
Media MediaEvent
}