fix(gatewayrpc): sender_id and rate_limited cross the chat wire

This commit is contained in:
sam committed 2026-10-04 17:18:38 +11:00
1 parent 5b3441c553
commit 7efc96bf70
6 files changed
+61 -11

No files matched your search

+30 -8
View File
@@ -166,7 +166,10 @@ type Message struct {
// file. The bytes ride only on the inbound request (see Media.data); a
// stored Media with tool_name empty is a sender attachment, and the
// tool_name on tool-produced events stays a stream-only field.
Media []*Media `protobuf:"bytes,11,rep,name=media,proto3" json:"media,omitempty"`
Media []*Media `protobuf:"bytes,11,rep,name=media,proto3" json:"media,omitempty"`
// sender_id is the channel-native stable ID of the person who sent the
// message; the Gateway keys per-person rate limits and slash access on it.
SenderId string `protobuf:"bytes,12,opt,name=sender_id,json=senderId,proto3" json:"sender_id,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -278,6 +281,13 @@ func (x *Message) GetMedia() []*Media {
return nil
}
func (x *Message) GetSenderId() string {
if x != nil {
return x.SenderId
}
return ""
}
type ToolCall struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
@@ -1185,9 +1195,12 @@ func (x *RouteRequest) GetMessage() *Message {
}
type RouteResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Text string `protobuf:"bytes,1,opt,name=text,proto3" json:"text,omitempty"`
SessionId string `protobuf:"bytes,2,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"`
state protoimpl.MessageState `protogen:"open.v1"`
Text string `protobuf:"bytes,1,opt,name=text,proto3" json:"text,omitempty"`
SessionId string `protobuf:"bytes,2,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"`
// rate_limited marks text as the inbound rate-limit reply, not a dispatch
// outcome.
RateLimited bool `protobuf:"varint,3,opt,name=rate_limited,json=rateLimited,proto3" json:"rate_limited,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -1236,6 +1249,13 @@ func (x *RouteResponse) GetSessionId() string {
return ""
}
func (x *RouteResponse) GetRateLimited() bool {
if x != nil {
return x.RateLimited
}
return false
}
type StreamRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Message *Message `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
@@ -2892,7 +2912,7 @@ const file_gateway_v1_chat_proto_rawDesc = "" +
"\n" +
"created_at\x18\t \x01(\v2\x1a.google.protobuf.TimestampR\tcreatedAt\x12@\n" +
"\x0elast_active_at\x18\n" +
" \x01(\v2\x1a.google.protobuf.TimestampR\flastActiveAt\"\xcd\x02\n" +
" \x01(\v2\x1a.google.protobuf.TimestampR\flastActiveAt\"\xea\x02\n" +
"\aMessage\x12\x1d\n" +
"\n" +
"message_id\x18\x01 \x01(\tR\tmessageId\x12\x1b\n" +
@@ -2908,7 +2928,8 @@ const file_gateway_v1_chat_proto_rawDesc = "" +
"budget_key\x18\t \x01(\tR\tbudgetKey\x12\x1a\n" +
"\bplatform\x18\n" +
" \x01(\tR\bplatform\x12'\n" +
"\x05media\x18\v \x03(\v2\x11.gateway.v1.MediaR\x05media\"|\n" +
"\x05media\x18\v \x03(\v2\x11.gateway.v1.MediaR\x05media\x12\x1b\n" +
"\tsender_id\x18\f \x01(\tR\bsenderId\"|\n" +
"\bToolCall\x12\x0e\n" +
"\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" +
"\x04name\x18\x02 \x01(\tR\x04name\x12\x1e\n" +
@@ -2999,11 +3020,12 @@ const file_gateway_v1_chat_proto_rawDesc = "" +
"\x13RecentTurnsResponse\x12&\n" +
"\x05turns\x18\x01 \x03(\v2\x10.gateway.v1.TurnR\x05turns\"=\n" +
"\fRouteRequest\x12-\n" +
"\amessage\x18\x01 \x01(\v2\x13.gateway.v1.MessageR\amessage\"B\n" +
"\amessage\x18\x01 \x01(\v2\x13.gateway.v1.MessageR\amessage\"e\n" +
"\rRouteResponse\x12\x12\n" +
"\x04text\x18\x01 \x01(\tR\x04text\x12\x1d\n" +
"\n" +
"session_id\x18\x02 \x01(\tR\tsessionId\">\n" +
"session_id\x18\x02 \x01(\tR\tsessionId\x12!\n" +
"\frate_limited\x18\x03 \x01(\bR\vrateLimited\">\n" +
"\rStreamRequest\x12-\n" +
"\amessage\x18\x01 \x01(\v2\x13.gateway.v1.MessageR\amessage\"\xaa\x01\n" +
"\x0eStreamResponse\x12\x12\n" +
+1 -1
View File
@@ -63,7 +63,7 @@ func (c *Client) Route(ctx context.Context, in messaging.Inbound) (messaging.Cha
if err != nil {
return messaging.ChatReply{}, err
}
return messaging.ChatReply{Text: v.Text, SessionID: v.SessionId}, nil
return messaging.ChatReply{Text: v.Text, SessionID: v.SessionId, RateLimited: v.RateLimited}, nil
}
func (c *Client) Cancel(ctx context.Context, id string) (messaging.ChatCancellation, error) {
+1 -1
View File
@@ -72,7 +72,7 @@ func (s *server) Route(ctx context.Context, r *pb.RouteRequest) (*pb.RouteRespon
if err != nil {
return nil, err
}
return &pb.RouteResponse{Text: v.Text, SessionId: v.SessionID}, nil
return &pb.RouteResponse{Text: v.Text, SessionId: v.SessionID, RateLimited: v.RateLimited}, nil
}
func (s *server) Cancel(ctx context.Context, r *pb.CancelRequest) (*pb.CancelResponse, error) {
@@ -33,6 +33,7 @@ func storedProto(m messaging.Message) *pb.Message {
ChannelId: m.ConversationID.ChannelID,
ThreadId: m.ConversationID.ThreadID,
From: m.Sender,
SenderId: m.SenderID,
Text: m.Text,
At: timestamp(m.At),
Media: attachmentProtoList(m.Media),
@@ -50,6 +51,7 @@ func storedValue(v *pb.Message) messaging.Message {
SourceID: v.SourceId,
ConversationID: messaging.ConversationID{ChannelID: v.ChannelId, ThreadID: v.ThreadId},
Sender: v.From,
SenderID: v.SenderId,
Text: v.Text,
At: timeValue(v.At),
Media: attachmentValueList(v.GetMedia()),
@@ -0,0 +1,17 @@
package gatewayrpc
import (
"testing"
"github.com/samcharles93/archie-core/internal/domain/messaging"
)
// TestChatWireKeepsGatewayInputs pins the fields the Gateway decides on
// across the messaging-to-gateway hop.
func TestChatWireKeepsGatewayInputs(t *testing.T) {
in := messaging.Inbound{Message: messaging.Message{SenderID: "42"}, BudgetKey: "/hooks/a", Platform: "telegram"}
got := inboundValue(inboundProto(in))
if got.Message.SenderID != "42" || got.BudgetKey != "/hooks/a" || got.Platform != "telegram" {
t.Fatalf("inbound round trip lost a field: %+v", got)
}
}
+10 -1
View File
@@ -68,6 +68,9 @@ message Message {
// stored Media with tool_name empty is a sender attachment, and the
// tool_name on tool-produced events stays a stream-only field.
repeated Media media = 11;
// sender_id is the channel-native stable ID of the person who sent the
// message; the Gateway keys per-person rate limits and slash access on it.
string sender_id = 12;
}
message ToolCall {
string id = 1;
@@ -135,7 +138,13 @@ message RecentMessagesResponse { repeated Message messages = 1; }
message RecentTurnsRequest { string session_id = 1; int64 limit = 2; }
message RecentTurnsResponse { repeated Turn turns = 1; }
message RouteRequest { Message message = 1; }
message RouteResponse { string text = 1; string session_id = 2; }
message RouteResponse {
string text = 1;
string session_id = 2;
// rate_limited marks text as the inbound rate-limit reply, not a dispatch
// outcome.
bool rate_limited = 3;
}
message StreamRequest { Message message = 1; }
message StreamResponse {
string kind = 1;