Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move username and ID out of AssistantMessage #25964

Merged
merged 3 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
80 changes: 40 additions & 40 deletions api/gen/proto/go/assist/v1/assist.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 7 additions & 12 deletions api/proto/teleport/assist/v1/assist.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,29 @@ message GetAssistantMessagesRequest {
// ConversationId identifies a conversation.
// It's used to tie all messages in a one conversation.
string conversation_id = 1;

// username is a username of the user who sent the message.
string username = 2;
}

// AssistantMessage is a message sent to the assistant service. The conversation
// must be created first.
message AssistantMessage {
// ConversationId is used to tie all messages into a conversation.
string conversation_id = 1;

// username is a username of the user who sent the message.
string username = 2;

// type is a type of message. It can be Chat response/query or a command to run.
string type = 3;

string type = 1;
// CreatedTime is the time when the event occurred.
google.protobuf.Timestamp created_time = 4;

google.protobuf.Timestamp created_time = 2;
// payload is a JSON message
string payload = 5;
string payload = 3;
}

// CreateAssistantMessageRequest is a request to the assistant service.
message CreateAssistantMessageRequest {
// message is a message sent to the assistant service.
AssistantMessage message = 1;
// ConversationId is used to tie all messages into a conversation.
string conversation_id = 2;
// username is a username of the user who sent the message.
string username = 3;
}

// GetAssistantMessagesResponse is a response from the assistant service.
Expand Down
2 changes: 1 addition & 1 deletion lib/auth/assist/assistv1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ func (a *Service) GetAssistantMessages(ctx context.Context, req *assist.GetAssis

// CreateAssistantMessage adds the message to the backend.
func (a *Service) CreateAssistantMessage(ctx context.Context, req *assist.CreateAssistantMessageRequest) (*emptypb.Empty, error) {
return nil, trace.Wrap(a.backend.CreateAssistantMessage(ctx, req))
return &emptypb.Empty{}, trace.Wrap(a.backend.CreateAssistantMessage(ctx, req))
}
9 changes: 6 additions & 3 deletions lib/services/local/assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,14 @@ func (s *AssistService) GetAssistantMessages(ctx context.Context, req *assist.Ge

// CreateAssistantMessage adds the message to the backend.
func (s *AssistService) CreateAssistantMessage(ctx context.Context, req *assist.CreateAssistantMessageRequest) error {
msg := req.GetMessage()
if msg.Username == "" {
if req.Username == "" {
return trace.BadParameter("missing username")
}
if req.ConversationId == "" {
return trace.BadParameter("missing conversation ID")
}

msg := req.GetMessage()
value, err := json.Marshal(msg)
if err != nil {
return trace.Wrap(err)
Expand All @@ -224,7 +227,7 @@ func (s *AssistService) CreateAssistantMessage(ctx context.Context, req *assist.
messageID := uuid.New().String()

item := backend.Item{
Key: backend.Key(assistantMessagePrefix, msg.Username, msg.ConversationId, messageID),
Key: backend.Key(assistantMessagePrefix, req.Username, req.ConversationId, messageID),
Value: value,
}

Expand Down
10 changes: 5 additions & 5 deletions lib/services/local/assistant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func TestAssistantCRUD(t *testing.T) {

t.Run("create message", func(t *testing.T) {
msg := &assist.CreateAssistantMessageRequest{
Username: username,
ConversationId: conversationID,
Message: &assist.AssistantMessage{
Username: username,
CreatedTime: timestamppb.New(time.Now()),
ConversationId: conversationID,
Payload: "foo",
Type: "USER_MSG",
CreatedTime: timestamppb.New(time.Now()),
Payload: "foo",
Type: "USER_MSG",
},
}
err := identity.CreateAssistantMessage(ctx, msg)
Expand Down