feat(gateway): extract ChatContract service
This commit is contained in:
1 parent
34cb25f130
commit
0a6496d2cd
20 files changed
+525
-79
No files matched your search
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/gateway/v1"
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
)
|
||||
|
||||
var _ gateway.ChatContract = (*Client)(nil)
|
||||
@@ -76,6 +77,14 @@ func (c *Client) SetPersona(ctx context.Context, id, name string) (bool, error)
|
||||
return v.Found, nil
|
||||
}
|
||||
|
||||
func (c *Client) ApplyTaskAction(ctx context.Context, identity string, taskID int64, action taskstate.Action) (gateway.TaskActionResult, error) {
|
||||
v, err := c.client.ApplyTaskAction(ctx, &pb.ApplyTaskActionRequest{Identity: identity, TaskId: taskID, Action: string(action)})
|
||||
if err != nil {
|
||||
return gateway.TaskActionResult{}, err
|
||||
}
|
||||
return gateway.TaskActionResult{TaskID: v.TaskId, Action: v.Action, Message: v.Message}, nil
|
||||
}
|
||||
|
||||
func (c *Client) Stream(ctx context.Context, msg gateway.Message) (<-chan gateway.ChatEvent, error) {
|
||||
stream, err := c.client.Stream(ctx, &pb.StreamRequest{Message: messageProto(msg)})
|
||||
if err != nil {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/gateway/v1"
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
)
|
||||
|
||||
type server struct {
|
||||
@@ -74,6 +75,14 @@ func (s *server) SetPersona(ctx context.Context, r *pb.SetPersonaRequest) (*pb.S
|
||||
return &pb.SetPersonaResponse{Found: v}, nil
|
||||
}
|
||||
|
||||
func (s *server) ApplyTaskAction(ctx context.Context, r *pb.ApplyTaskActionRequest) (*pb.ApplyTaskActionResponse, error) {
|
||||
v, err := s.chat.ApplyTaskAction(ctx, r.Identity, r.TaskId, taskstate.Action(r.Action))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.ApplyTaskActionResponse{TaskId: v.TaskID, Action: v.Action, Message: v.Message}, nil
|
||||
}
|
||||
|
||||
func (s *server) Stream(r *pb.StreamRequest, out grpc.ServerStreamingServer[pb.StreamResponse]) error {
|
||||
events, err := s.chat.Stream(out.Context(), messageValue(r.Message))
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user