refactor(ui): sever the archie-ui binary from every daemon runtime package
Completes the objective deletion gate for the UI Service (archie-core-8cda.5.6): go list -deps ./cmd/archie-ui now links zero banned packages -- no modernc.org/sqlite, no internal/store, gateway, channels, memory, secret, agentexec, tools, skill, yaegiutil, curator, or the workflow engine. The closure shrinks from 68 to 26 archie-core packages. Each cut is a producer-side move; no consumer-side defensive shims. - Store contracts (TaskStore family, value types, sentinels) moved from internal/store to internal/domain/storecontract -- the approved contract location per state-store-contract rev. 2d, and NOT internal/contracts: that tree is buf generate output and tools/proto.sh check deletes hand-written files there. internal/store keeps aliases; sentinel message strings are byte-identical and remain the wire contract. - Chat contracts (ChatContract, sessions, turns, streaming, commands) moved from internal/gateway to internal/domain/messaging; gateway keeps aliases. ToolCallEvent rendering helpers become gateway functions (methods cannot live on alias types). - Task vocabulary (Task, statuses, mid-run Store, Definition) split into internal/domain/workflow/task; the pipeline engine stays in package workflow with aliases, so daemon-side callers are unchanged. - overlay.DeniedKeys moved to internal/infrastructure/configuration: webui referenced the constant and that dragged the overlay SQLite store in. - webui.Server's concrete runtime handles become webui-owned view interfaces with daemon-side bootstrap adapters: channel lifecycle (internal/channels/status), MemoryStatus, CuratorStatus, and a SkillCatalog seam replacing the direct skill.DefaultRoots/CatalogRoots calls. Each degrades to an empty page when unwired. - config.SecretRef moved into internal/config (config vocabulary); internal/secret keeps an alias and Registry.Resolve absorbs the zero-value short-circuit. Docs: state-store-contract rev. 2d relocation record; ui-service-boundary deletion gate marked satisfied; ARCHITECTURE.md package map rows.
This commit is contained in:
1 parent
3699f51f9b
commit
da28ddb5e6
84 files changed
+1492
-1053
No files matched your search
@@ -22,8 +22,8 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
storev1 "github.com/samcharles93/archie-core/internal/contracts/store/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/binding"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/events"
|
||||
"github.com/samcharles93/archie-core/internal/webhookguard"
|
||||
)
|
||||
@@ -37,7 +37,7 @@ type Receiver struct {
|
||||
// Captures persists what arrives. Nil answers 503 rather than failing
|
||||
// the process it is mounted in: capture is a precondition for the
|
||||
// no-code playbook epic, not a hard dependency of the daemon.
|
||||
Captures storev1.CaptureStore
|
||||
Captures storecontract.CaptureStore
|
||||
// Limiter is the per-remote-address token bucket applied before a body
|
||||
// is read. Nil disables rate limiting, which composition never does in
|
||||
// production.
|
||||
@@ -45,7 +45,7 @@ type Receiver struct {
|
||||
// Bindings resolves the armed binding whose secret authenticates a
|
||||
// source. Nil disables per-source HMAC verification and every event
|
||||
// records as authenticated=false.
|
||||
Bindings storev1.BindingDispatcher
|
||||
Bindings storecontract.BindingDispatcher
|
||||
// Retention and MaxEvents are passed straight to InsertCapture's
|
||||
// prune-on-write bounds. See config.CaptureConfig.
|
||||
Retention time.Duration
|
||||
@@ -135,7 +135,7 @@ func (rc *Receiver) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
redactedBody = body
|
||||
}
|
||||
|
||||
c := storev1.CapturedEvent{
|
||||
c := storecontract.CapturedEvent{
|
||||
ReceivedAt: time.Now().UTC(),
|
||||
Source: source,
|
||||
RemoteAddr: r.RemoteAddr,
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
)
|
||||
|
||||
// Defaults applied to absent input. Named so a reader can find the value
|
||||
@@ -221,7 +220,7 @@ func applyForgeDefaults(cfg *config.Config) {
|
||||
cfg.Forge.Host = defaultForgeHost
|
||||
}
|
||||
if cfg.Forge.Token.Engine == "" && cfg.Forge.Token.Key == "" && cfg.Forge.TokenEnv != "" {
|
||||
cfg.Forge.Token = secret.SecretRef{Engine: "env", Key: cfg.Forge.TokenEnv}
|
||||
cfg.Forge.Token = config.SecretRef{Engine: "env", Key: cfg.Forge.TokenEnv}
|
||||
}
|
||||
if cfg.Forge.Intake == "" {
|
||||
cfg.Forge.Intake = config.ForgeIntakePoll
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
)
|
||||
|
||||
// Recognised enum values, named so validation and its error message cannot
|
||||
@@ -108,7 +107,7 @@ func validateImage(cfg *config.Config) error {
|
||||
if p.Class == "" {
|
||||
return fmt.Errorf("%w: image.hosted.%s.class is required when enabled", ErrInvalidInput, name)
|
||||
}
|
||||
if p.APIKeyEnv == "" && p.APIKey == (secret.SecretRef{}) {
|
||||
if p.APIKeyEnv == "" && p.APIKey == (config.SecretRef{}) {
|
||||
return fmt.Errorf("%w: image.hosted.%s requires api_key_env or api_key when enabled", ErrInvalidInput, name)
|
||||
}
|
||||
}
|
||||
@@ -222,7 +221,7 @@ func validateForgeIntake(cfg *config.Config) error {
|
||||
return fmt.Errorf("%w: forge.intake %q (want %s)", ErrInvalidInput, cfg.Forge.Intake, list(forgeIntakes))
|
||||
}
|
||||
if intake == config.ForgeIntakeWebhook || intake == config.ForgeIntakeBoth {
|
||||
if cfg.Forge.WebhookSecret == (secret.SecretRef{}) {
|
||||
if cfg.Forge.WebhookSecret == (config.SecretRef{}) {
|
||||
return fmt.Errorf("%w: forge.webhook_secret is required when forge.intake is %q", ErrInvalidInput, intake)
|
||||
}
|
||||
if cfg.Forge.WebhookAddr == "" {
|
||||
@@ -265,7 +264,7 @@ func validateIdentities(identities []config.IdentityConfig) error {
|
||||
if !oneOf(id.Forge.Type, forgeTypes) {
|
||||
return fmt.Errorf("%w: identities[%d].forge.type %q (want %s)", ErrInvalidInput, i, id.Forge.Type, list(forgeTypes))
|
||||
}
|
||||
if !ForgeDisabled(id.Forge.Type) && id.Forge.Token == (secret.SecretRef{}) {
|
||||
if !ForgeDisabled(id.Forge.Type) && id.Forge.Token == (config.SecretRef{}) {
|
||||
return fmt.Errorf("%w: identities[%d].forge.token is required (each identity needs its own secret reference; unlike the top-level [forge], there is no default)", ErrInvalidInput, i)
|
||||
}
|
||||
if err := validateRepos(id.Repos); err != nil {
|
||||
|
||||
@@ -10,13 +10,12 @@ import (
|
||||
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/gateway/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
)
|
||||
|
||||
var _ gateway.ChatContract = (*Client)(nil)
|
||||
var _ messaging.ChatContract = (*Client)(nil)
|
||||
|
||||
// Client implements gateway.ChatContract over the chat service. The proto
|
||||
// Client implements messaging.ChatContract over the chat service. The proto
|
||||
// is unchanged by the messaging migration, so history crosses without its
|
||||
// role and is re-addressed from the owning session on arrival; StoreClient
|
||||
// serves the SessionStore view over the same RPCs.
|
||||
@@ -26,18 +25,18 @@ func NewClient(conn grpc.ClientConnInterface) *Client {
|
||||
return &Client{client: pb.NewChatServiceClient(conn)}
|
||||
}
|
||||
|
||||
func (c *Client) Snapshot(ctx context.Context) (gateway.ChatSnapshot, error) {
|
||||
func (c *Client) Snapshot(ctx context.Context) (messaging.ChatSnapshot, error) {
|
||||
v, err := c.client.Snapshot(ctx, &pb.SnapshotRequest{})
|
||||
if err != nil {
|
||||
return gateway.ChatSnapshot{}, err
|
||||
return messaging.ChatSnapshot{}, err
|
||||
}
|
||||
return snapshotValue(v), nil
|
||||
}
|
||||
|
||||
func (c *Client) GetSession(ctx context.Context, id string) (gateway.SessionContext, bool, error) {
|
||||
func (c *Client) GetSession(ctx context.Context, id string) (messaging.SessionContext, bool, error) {
|
||||
v, err := c.client.GetSession(ctx, &pb.GetSessionRequest{SessionId: id})
|
||||
if err != nil {
|
||||
return gateway.SessionContext{}, false, err
|
||||
return messaging.SessionContext{}, false, err
|
||||
}
|
||||
return sessionValue(v.Session), v.Found, nil
|
||||
}
|
||||
@@ -50,7 +49,7 @@ func (c *Client) RecentMessages(ctx context.Context, id string, n int) ([]messag
|
||||
return addressRecords(ctx, c.client, id, v.Messages)
|
||||
}
|
||||
|
||||
func (c *Client) RecentTurns(ctx context.Context, id string, n int) ([]gateway.TurnRecord, error) {
|
||||
func (c *Client) RecentTurns(ctx context.Context, id string, n int) ([]messaging.TurnRecord, error) {
|
||||
v, err := c.client.RecentTurns(ctx, &pb.RecentTurnsRequest{SessionId: id, Limit: int64(n)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -58,20 +57,20 @@ func (c *Client) RecentTurns(ctx context.Context, id string, n int) ([]gateway.T
|
||||
return mapValues(v.Turns, turnValue), nil
|
||||
}
|
||||
|
||||
func (c *Client) Route(ctx context.Context, in gateway.Inbound) (gateway.ChatReply, error) {
|
||||
func (c *Client) Route(ctx context.Context, in messaging.Inbound) (messaging.ChatReply, error) {
|
||||
v, err := c.client.Route(ctx, &pb.RouteRequest{Message: inboundProto(in)})
|
||||
if err != nil {
|
||||
return gateway.ChatReply{}, err
|
||||
return messaging.ChatReply{}, err
|
||||
}
|
||||
return gateway.ChatReply{Text: v.Text, SessionID: v.SessionId}, nil
|
||||
return messaging.ChatReply{Text: v.Text, SessionID: v.SessionId}, nil
|
||||
}
|
||||
|
||||
func (c *Client) Cancel(ctx context.Context, id string) (gateway.ChatCancellation, error) {
|
||||
func (c *Client) Cancel(ctx context.Context, id string) (messaging.ChatCancellation, error) {
|
||||
v, err := c.client.Cancel(ctx, &pb.CancelRequest{SessionId: id})
|
||||
if err != nil {
|
||||
return gateway.ChatCancellation{}, err
|
||||
return messaging.ChatCancellation{}, err
|
||||
}
|
||||
return gateway.ChatCancellation{Cancelled: v.Cancelled, Dropped: int(v.Dropped)}, nil
|
||||
return messaging.ChatCancellation{Cancelled: v.Cancelled, Dropped: int(v.Dropped)}, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetPersona(ctx context.Context, id, name string) (bool, error) {
|
||||
@@ -82,28 +81,28 @@ 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) {
|
||||
func (c *Client) ApplyTaskAction(ctx context.Context, identity string, taskID int64, action taskstate.Action) (messaging.TaskActionResult, error) {
|
||||
v, err := c.client.ApplyTaskAction(ctx, &pb.ApplyTaskActionRequest{Identity: identity, TaskId: taskID, Action: string(action)})
|
||||
if err != nil {
|
||||
return gateway.TaskActionResult{}, taskActionError(err)
|
||||
return messaging.TaskActionResult{}, taskActionError(err)
|
||||
}
|
||||
return gateway.TaskActionResult{TaskID: v.TaskId, Action: v.Action, Message: v.Message}, nil
|
||||
return messaging.TaskActionResult{TaskID: v.TaskId, Action: v.Action, Message: v.Message}, nil
|
||||
}
|
||||
|
||||
func (c *Client) ApplyOperatorTaskAction(ctx context.Context, taskID int64, action taskstate.Action) (gateway.TaskActionResult, error) {
|
||||
func (c *Client) ApplyOperatorTaskAction(ctx context.Context, taskID int64, action taskstate.Action) (messaging.TaskActionResult, error) {
|
||||
v, err := c.client.ApplyOperatorTaskAction(ctx, &pb.ApplyOperatorTaskActionRequest{TaskId: taskID, Action: string(action)})
|
||||
if err != nil {
|
||||
return gateway.TaskActionResult{}, taskActionError(err)
|
||||
return messaging.TaskActionResult{}, taskActionError(err)
|
||||
}
|
||||
return gateway.TaskActionResult{TaskID: v.TaskId, Action: v.Action, Message: v.Message}, nil
|
||||
return messaging.TaskActionResult{TaskID: v.TaskId, Action: v.Action, Message: v.Message}, nil
|
||||
}
|
||||
|
||||
func (c *Client) Stream(ctx context.Context, in gateway.Inbound) (<-chan gateway.ChatEvent, error) {
|
||||
func (c *Client) Stream(ctx context.Context, in messaging.Inbound) (<-chan messaging.ChatEvent, error) {
|
||||
stream, err := c.client.Stream(ctx, &pb.StreamRequest{Message: inboundProto(in)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make(chan gateway.ChatEvent)
|
||||
out := make(chan messaging.ChatEvent)
|
||||
go func() {
|
||||
defer close(out)
|
||||
for {
|
||||
@@ -111,9 +110,9 @@ func (c *Client) Stream(ctx context.Context, in gateway.Inbound) (<-chan gateway
|
||||
if errors.Is(err, io.EOF) {
|
||||
return
|
||||
}
|
||||
var event gateway.ChatEvent
|
||||
var event messaging.ChatEvent
|
||||
if err != nil {
|
||||
event = gateway.ChatEvent{Kind: "error", Text: err.Error()}
|
||||
event = messaging.ChatEvent{Kind: "error", Text: err.Error()}
|
||||
} else {
|
||||
event = eventValue(v)
|
||||
}
|
||||
|
||||
@@ -9,25 +9,24 @@ import (
|
||||
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/gateway/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
)
|
||||
|
||||
type server struct {
|
||||
pb.UnimplementedChatServiceServer
|
||||
chat gateway.ChatContract
|
||||
sessions gateway.SessionStore
|
||||
chat messaging.ChatContract
|
||||
sessions messaging.SessionStore
|
||||
}
|
||||
|
||||
func RegisterServer(registrar grpc.ServiceRegistrar, chat gateway.ChatContract, sessions ...gateway.SessionStore) {
|
||||
var ss gateway.SessionStore
|
||||
func RegisterServer(registrar grpc.ServiceRegistrar, chat messaging.ChatContract, sessions ...messaging.SessionStore) {
|
||||
var ss messaging.SessionStore
|
||||
if len(sessions) > 0 {
|
||||
ss = sessions[0]
|
||||
}
|
||||
pb.RegisterChatServiceServer(registrar, &server{chat: chat, sessions: ss})
|
||||
}
|
||||
|
||||
func (s *server) sessionStore() (gateway.SessionStore, error) {
|
||||
func (s *server) sessionStore() (messaging.SessionStore, error) {
|
||||
if s.sessions == nil {
|
||||
return nil, status.Error(codes.Unavailable, "session store unavailable")
|
||||
}
|
||||
@@ -150,9 +149,9 @@ func (s *server) ListSessions(ctx context.Context, _ *pb.ListSessionsRequest) (*
|
||||
|
||||
// storedMessages converts wire messages to canonical records, deriving
|
||||
// roles from the owning session's bot identity (see
|
||||
// gateway.RoleForSender). The wire carries no role; both sides derive from
|
||||
// messaging.RoleForSender). The wire carries no role; both sides derive from
|
||||
// the same session, so they agree.
|
||||
func (s *server) storedMessages(ctx context.Context, ss gateway.SessionStore, sessionID string, msgs []*pb.Message) ([]messaging.Message, error) {
|
||||
func (s *server) storedMessages(ctx context.Context, ss messaging.SessionStore, sessionID string, msgs []*pb.Message) ([]messaging.Message, error) {
|
||||
var botUser string
|
||||
if sc, err := ss.Get(ctx, sessionID); err != nil {
|
||||
return nil, err
|
||||
@@ -162,7 +161,7 @@ func (s *server) storedMessages(ctx context.Context, ss gateway.SessionStore, se
|
||||
out := make([]messaging.Message, 0, len(msgs))
|
||||
for _, m := range msgs {
|
||||
stored := storedValue(m)
|
||||
stored.Role = gateway.RoleForSender(stored.Sender, botUser)
|
||||
stored.Role = messaging.RoleForSender(stored.Sender, botUser)
|
||||
out = append(out, stored)
|
||||
}
|
||||
return out, nil
|
||||
@@ -227,7 +226,7 @@ func (s *server) SearchMessages(ctx context.Context, r *pb.SearchMessagesRequest
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
v, e := ss.SearchMessages(ctx, r.SessionId, gateway.MessageQuery{Query: r.Query, Limit: int(r.Limit), Offset: int(r.Offset)})
|
||||
v, e := ss.SearchMessages(ctx, r.SessionId, messaging.MessageQuery{Query: r.Query, Limit: int(r.Limit), Offset: int(r.Offset)})
|
||||
return &pb.SearchMessagesResponse{Messages: mapValues(v.Messages, storedProto), NextOffset: int64(v.NextOffset), HasMore: v.HasMore, Truncated: v.Truncated}, e
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,11 @@ import (
|
||||
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/gateway/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
)
|
||||
|
||||
var _ gateway.SessionStore = (*StoreClient)(nil)
|
||||
var _ messaging.SessionStore = (*StoreClient)(nil)
|
||||
|
||||
// StoreClient implements gateway.SessionStore over the chat service's
|
||||
// StoreClient implements messaging.SessionStore over the chat service's
|
||||
// session-store RPCs. It is separate from Client (the ChatContract view)
|
||||
// because the two contracts serve different reads over the same messages.
|
||||
//
|
||||
@@ -26,7 +25,7 @@ func NewStoreClient(conn grpc.ClientConnInterface) *StoreClient {
|
||||
return &StoreClient{client: pb.NewChatServiceClient(conn)}
|
||||
}
|
||||
|
||||
func (c *StoreClient) Get(ctx context.Context, id string) (*gateway.SessionContext, error) {
|
||||
func (c *StoreClient) Get(ctx context.Context, id string) (*messaging.SessionContext, error) {
|
||||
v, err := c.client.GetSession(ctx, &pb.GetSessionRequest{SessionId: id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -38,12 +37,12 @@ func (c *StoreClient) Get(ctx context.Context, id string) (*gateway.SessionConte
|
||||
return &s, nil
|
||||
}
|
||||
|
||||
func (c *StoreClient) Save(ctx context.Context, s gateway.SessionContext) error {
|
||||
func (c *StoreClient) Save(ctx context.Context, s messaging.SessionContext) error {
|
||||
_, e := c.client.SaveSession(ctx, &pb.SaveSessionRequest{Session: sessionProto(s)})
|
||||
return e
|
||||
}
|
||||
|
||||
func (c *StoreClient) GetByChannel(ctx context.Context, p, ch string) ([]gateway.SessionContext, error) {
|
||||
func (c *StoreClient) GetByChannel(ctx context.Context, p, ch string) ([]messaging.SessionContext, error) {
|
||||
v, e := c.client.GetSessionsByChannel(ctx, &pb.GetSessionsByChannelRequest{Platform: p, ChannelId: ch})
|
||||
if e != nil {
|
||||
return nil, e
|
||||
@@ -61,7 +60,7 @@ func (c *StoreClient) Touch(ctx context.Context, id string) error {
|
||||
return e
|
||||
}
|
||||
|
||||
func (c *StoreClient) List(ctx context.Context) ([]gateway.SessionContext, error) {
|
||||
func (c *StoreClient) List(ctx context.Context) ([]messaging.SessionContext, error) {
|
||||
v, e := c.client.ListSessions(ctx, &pb.ListSessionsRequest{})
|
||||
if e != nil {
|
||||
return nil, e
|
||||
@@ -105,16 +104,16 @@ func (c *StoreClient) RecentMessages(ctx context.Context, id string, n int) ([]m
|
||||
return addressRecords(ctx, c.client, id, v.Messages)
|
||||
}
|
||||
|
||||
func (c *StoreClient) SearchMessages(ctx context.Context, id string, q gateway.MessageQuery) (gateway.MessagePage, error) {
|
||||
func (c *StoreClient) SearchMessages(ctx context.Context, id string, q messaging.MessageQuery) (messaging.MessagePage, error) {
|
||||
v, e := c.client.SearchMessages(ctx, &pb.SearchMessagesRequest{SessionId: id, Query: q.Query, Limit: int64(q.Limit), Offset: int64(q.Offset)})
|
||||
if e != nil {
|
||||
return gateway.MessagePage{}, e
|
||||
return messaging.MessagePage{}, e
|
||||
}
|
||||
msgs, err := addressRecords(ctx, c.client, id, v.Messages)
|
||||
if err != nil {
|
||||
return gateway.MessagePage{}, err
|
||||
return messaging.MessagePage{}, err
|
||||
}
|
||||
return gateway.MessagePage{Messages: msgs, NextOffset: int(v.NextOffset), HasMore: v.HasMore, Truncated: v.Truncated}, nil
|
||||
return messaging.MessagePage{Messages: msgs, NextOffset: int(v.NextOffset), HasMore: v.HasMore, Truncated: v.Truncated}, nil
|
||||
}
|
||||
|
||||
func (c *StoreClient) Close() error { return nil }
|
||||
@@ -139,7 +138,7 @@ func addressRecords(ctx context.Context, client pb.ChatServiceClient, id string,
|
||||
for _, m := range msgs {
|
||||
stored := storedValue(m)
|
||||
stored.ConversationID = conv
|
||||
stored.Role = gateway.RoleForSender(stored.Sender, botUser)
|
||||
stored.Role = messaging.RoleForSender(stored.Sender, botUser)
|
||||
out = append(out, stored)
|
||||
}
|
||||
return out, nil
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
storev1 "github.com/samcharles93/archie-core/internal/contracts/store/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/domain/taskactions"
|
||||
)
|
||||
|
||||
@@ -22,7 +22,7 @@ var taskActionCodes = []struct {
|
||||
}{
|
||||
{code: codes.NotFound, err: taskactions.ErrNotFound},
|
||||
{code: codes.FailedPrecondition, err: taskactions.ErrConflict},
|
||||
{code: codes.Aborted, err: storev1.ErrStaleTransition},
|
||||
{code: codes.Aborted, err: storecontract.ErrStaleTransition},
|
||||
{code: codes.Unavailable, err: taskactions.ErrUnavailable},
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/gateway/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
)
|
||||
|
||||
func timestamp(t time.Time) *timestamppb.Timestamp {
|
||||
@@ -26,7 +25,7 @@ func timeValue(t *timestamppb.Timestamp) time.Time {
|
||||
|
||||
// storedProto renders a canonical record in its wire shape. The role stays
|
||||
// off the wire: each side derives it from the owning session's bot identity
|
||||
// (see gateway.RoleForSender), so pb.Message needs no role field.
|
||||
// (see messaging.RoleForSender), so pb.Message needs no role field.
|
||||
func storedProto(m messaging.Message) *pb.Message {
|
||||
return &pb.Message{
|
||||
MessageId: string(m.ID),
|
||||
@@ -58,7 +57,7 @@ func storedValue(v *pb.Message) messaging.Message {
|
||||
// inboundProto renders a channel message and its transport context in wire
|
||||
// shape. Page rides along; the record's role does not, for the reason
|
||||
// storedProto gives.
|
||||
func inboundProto(v gateway.Inbound) *pb.Message {
|
||||
func inboundProto(v messaging.Inbound) *pb.Message {
|
||||
m := storedProto(v.Message)
|
||||
m.Page = v.Page
|
||||
return m
|
||||
@@ -68,16 +67,16 @@ func inboundProto(v gateway.Inbound) *pb.Message {
|
||||
// RoleUser without consulting the session: this is a message a channel
|
||||
// frontend is delivering on a person's behalf, which is the only kind of
|
||||
// message Route and Stream accept.
|
||||
func inboundValue(v *pb.Message) gateway.Inbound {
|
||||
func inboundValue(v *pb.Message) messaging.Inbound {
|
||||
if v == nil {
|
||||
return gateway.Inbound{}
|
||||
return messaging.Inbound{}
|
||||
}
|
||||
msg := storedValue(v)
|
||||
msg.Role = messaging.RoleUser
|
||||
return gateway.Inbound{Message: msg, Page: v.Page}
|
||||
return messaging.Inbound{Message: msg, Page: v.Page}
|
||||
}
|
||||
|
||||
func toolProto(v gateway.ToolCallEvent) *pb.ToolCall {
|
||||
func toolProto(v messaging.ToolCallEvent) *pb.ToolCall {
|
||||
return &pb.ToolCall{
|
||||
Id: v.ID,
|
||||
Name: v.Name,
|
||||
@@ -87,11 +86,11 @@ func toolProto(v gateway.ToolCallEvent) *pb.ToolCall {
|
||||
}
|
||||
}
|
||||
|
||||
func toolValue(v *pb.ToolCall) gateway.ToolCallEvent {
|
||||
func toolValue(v *pb.ToolCall) messaging.ToolCallEvent {
|
||||
if v == nil {
|
||||
return gateway.ToolCallEvent{}
|
||||
return messaging.ToolCallEvent{}
|
||||
}
|
||||
return gateway.ToolCallEvent{
|
||||
return messaging.ToolCallEvent{
|
||||
ID: v.Id,
|
||||
Name: v.Name,
|
||||
Parameters: v.Parameters,
|
||||
@@ -100,7 +99,7 @@ func toolValue(v *pb.ToolCall) gateway.ToolCallEvent {
|
||||
}
|
||||
}
|
||||
|
||||
func turnProto(v gateway.TurnRecord) *pb.Turn {
|
||||
func turnProto(v messaging.TurnRecord) *pb.Turn {
|
||||
return &pb.Turn{
|
||||
TurnId: v.TurnID,
|
||||
SessionId: v.SessionID,
|
||||
@@ -115,11 +114,11 @@ func turnProto(v gateway.TurnRecord) *pb.Turn {
|
||||
}
|
||||
}
|
||||
|
||||
func turnValue(v *pb.Turn) gateway.TurnRecord {
|
||||
func turnValue(v *pb.Turn) messaging.TurnRecord {
|
||||
if v == nil {
|
||||
return gateway.TurnRecord{}
|
||||
return messaging.TurnRecord{}
|
||||
}
|
||||
return gateway.TurnRecord{
|
||||
return messaging.TurnRecord{
|
||||
TurnID: v.TurnId,
|
||||
SessionID: v.SessionId,
|
||||
SourceID: v.SourceId,
|
||||
@@ -129,7 +128,7 @@ func turnValue(v *pb.Turn) gateway.TurnRecord {
|
||||
PartialText: v.PartialText,
|
||||
ResponseText: v.ResponseText,
|
||||
Error: v.Error, CreatedAt: timeValue(v.CreatedAt),
|
||||
UpdatedAt: timeValue(v.UpdatedAt), Status: gateway.TurnStatus(v.Status), Attempt: int(v.Attempt), ToolCalls: mapValues(v.ToolCalls, toolValue),
|
||||
UpdatedAt: timeValue(v.UpdatedAt), Status: messaging.TurnStatus(v.Status), Attempt: int(v.Attempt), ToolCalls: mapValues(v.ToolCalls, toolValue),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,15 +143,15 @@ func mapValues[A, B any](in []A, f func(A) B) []B {
|
||||
return out
|
||||
}
|
||||
|
||||
func sessionProto(v gateway.SessionContext) *pb.Session {
|
||||
func sessionProto(v messaging.SessionContext) *pb.Session {
|
||||
return &pb.Session{SessionId: v.SessionID, Platform: v.Source.Platform, BotUser: v.Source.BotUser, ChannelId: v.Source.ChannelID, ThreadId: v.Source.ThreadID, Title: v.Title, ParentSessionId: v.ParentSessionID, BranchName: v.BranchName, CreatedAt: timestamp(v.CreatedAt), LastActiveAt: timestamp(v.LastActiveAt)}
|
||||
}
|
||||
|
||||
func sessionValue(v *pb.Session) gateway.SessionContext {
|
||||
func sessionValue(v *pb.Session) messaging.SessionContext {
|
||||
if v == nil {
|
||||
return gateway.SessionContext{}
|
||||
return messaging.SessionContext{}
|
||||
}
|
||||
return gateway.SessionContext{SessionID: v.SessionId, Source: gateway.SessionSource{Platform: v.Platform, BotUser: v.BotUser, ChannelID: v.ChannelId, ThreadID: v.ThreadId}, Title: v.Title, ParentSessionID: v.ParentSessionId, BranchName: v.BranchName, CreatedAt: timeValue(v.CreatedAt), LastActiveAt: timeValue(v.LastActiveAt)}
|
||||
return messaging.SessionContext{SessionID: v.SessionId, Source: messaging.SessionSource{Platform: v.Platform, BotUser: v.BotUser, ChannelID: v.ChannelId, ThreadID: v.ThreadId}, Title: v.Title, ParentSessionID: v.ParentSessionId, BranchName: v.BranchName, CreatedAt: timeValue(v.CreatedAt), LastActiveAt: timeValue(v.LastActiveAt)}
|
||||
}
|
||||
|
||||
func int64Pointer(v *int) *int64 {
|
||||
@@ -171,27 +170,27 @@ func intPointer(v *int64) *int {
|
||||
return &n
|
||||
}
|
||||
|
||||
func mediaProto(v gateway.MediaEvent) *pb.Media {
|
||||
func mediaProto(v messaging.MediaEvent) *pb.Media {
|
||||
a := v.Attachment
|
||||
return &pb.Media{ToolName: v.ToolName, Type: a.Type, FileId: a.FileID, Url: a.URL, Path: a.Path, MimeType: a.MIMEType, FileName: a.FileName, FileSize: a.FileSize, Width: int64Pointer(a.Width), Height: int64Pointer(a.Height), Duration: int64Pointer(a.Duration)}
|
||||
}
|
||||
|
||||
func mediaValue(v *pb.Media) gateway.MediaEvent {
|
||||
func mediaValue(v *pb.Media) messaging.MediaEvent {
|
||||
if v == nil {
|
||||
return gateway.MediaEvent{}
|
||||
return messaging.MediaEvent{}
|
||||
}
|
||||
return gateway.MediaEvent{ToolName: v.ToolName, Attachment: gateway.MediaAttachment{Type: v.Type, FileID: v.FileId, URL: v.Url, Path: v.Path, MIMEType: v.MimeType, FileName: v.FileName, FileSize: v.FileSize, Width: intPointer(v.Width), Height: intPointer(v.Height), Duration: intPointer(v.Duration)}}
|
||||
return messaging.MediaEvent{ToolName: v.ToolName, Attachment: messaging.MediaAttachment{Type: v.Type, FileID: v.FileId, URL: v.Url, Path: v.Path, MIMEType: v.MimeType, FileName: v.FileName, FileSize: v.FileSize, Width: intPointer(v.Width), Height: intPointer(v.Height), Duration: intPointer(v.Duration)}}
|
||||
}
|
||||
|
||||
func eventProto(v gateway.ChatEvent) *pb.StreamResponse {
|
||||
func eventProto(v messaging.ChatEvent) *pb.StreamResponse {
|
||||
return &pb.StreamResponse{Kind: v.Kind, Text: v.Text, SessionId: v.SessionID, Tool: toolProto(v.Tool), Media: mediaProto(v.Media)}
|
||||
}
|
||||
|
||||
func eventValue(v *pb.StreamResponse) gateway.ChatEvent {
|
||||
return gateway.ChatEvent{Kind: v.Kind, Text: v.Text, SessionID: v.SessionId, Tool: toolValue(v.Tool), Media: mediaValue(v.Media)}
|
||||
func eventValue(v *pb.StreamResponse) messaging.ChatEvent {
|
||||
return messaging.ChatEvent{Kind: v.Kind, Text: v.Text, SessionID: v.SessionId, Tool: toolValue(v.Tool), Media: mediaValue(v.Media)}
|
||||
}
|
||||
|
||||
func snapshotProto(v gateway.ChatSnapshot) *pb.SnapshotResponse {
|
||||
func snapshotProto(v messaging.ChatSnapshot) *pb.SnapshotResponse {
|
||||
groups := make(map[string]*pb.StringList, len(v.ModelsByProvider))
|
||||
for k, list := range v.ModelsByProvider {
|
||||
groups[k] = &pb.StringList{Values: list}
|
||||
@@ -199,10 +198,10 @@ func snapshotProto(v gateway.ChatSnapshot) *pb.SnapshotResponse {
|
||||
return &pb.SnapshotResponse{Sessions: mapValues(v.Sessions, sessionProto), Models: v.Models, ModelsByProvider: groups, Providers: v.Providers, ActiveModel: v.ActiveModel, ActiveProvider: v.ActiveProvider, Personas: v.Personas, ActivePersonas: v.ActivePersonas, RestartAvailable: v.RestartAvailable, CancellationAvailable: v.CancellationAvailable, PersonasAvailable: v.PersonasAvailable}
|
||||
}
|
||||
|
||||
func snapshotValue(v *pb.SnapshotResponse) gateway.ChatSnapshot {
|
||||
func snapshotValue(v *pb.SnapshotResponse) messaging.ChatSnapshot {
|
||||
groups := make(map[string][]string, len(v.ModelsByProvider))
|
||||
for k, list := range v.ModelsByProvider {
|
||||
groups[k] = list.GetValues()
|
||||
}
|
||||
return gateway.ChatSnapshot{Sessions: mapValues(v.Sessions, sessionValue), Models: v.Models, ModelsByProvider: groups, Providers: v.Providers, ActiveModel: v.ActiveModel, ActiveProvider: v.ActiveProvider, Personas: v.Personas, ActivePersonas: v.ActivePersonas, RestartAvailable: v.RestartAvailable, CancellationAvailable: v.CancellationAvailable, PersonasAvailable: v.PersonasAvailable}
|
||||
return messaging.ChatSnapshot{Sessions: mapValues(v.Sessions, sessionValue), Models: v.Models, ModelsByProvider: groups, Providers: v.Providers, ActiveModel: v.ActiveModel, ActiveProvider: v.ActiveProvider, Personas: v.Personas, ActivePersonas: v.ActivePersonas, RestartAvailable: v.RestartAvailable, CancellationAvailable: v.CancellationAvailable, PersonasAvailable: v.PersonasAvailable}
|
||||
}
|
||||
@@ -9,17 +9,17 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
||||
storev1 "github.com/samcharles93/archie-core/internal/contracts/store/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/binding"
|
||||
"github.com/samcharles93/archie-core/internal/domain/mapping"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
"github.com/samcharles93/archie-core/internal/events"
|
||||
)
|
||||
|
||||
// Client is the single remote adapter wrapping one StateStoreServiceClient,
|
||||
// asserted against whichever narrow Go interfaces its caller needs -- exactly
|
||||
// as gatewayrpc.Client asserts both gateway.ChatContract and
|
||||
// gateway.SessionStore. See docs/prds/state-store-contract.md §2.
|
||||
// as gatewayrpc.Client asserts both messaging.ChatContract and
|
||||
// messaging.SessionStore. See docs/prds/state-store-contract.md §2.
|
||||
type Client struct {
|
||||
client pb.StateStoreServiceClient
|
||||
}
|
||||
@@ -34,14 +34,14 @@ func NewClient(conn grpc.ClientConnInterface) *Client {
|
||||
func (c *Client) Close() error { return nil }
|
||||
|
||||
var (
|
||||
_ workflow.Store = (*Client)(nil)
|
||||
_ storev1.TaskStore = (*Client)(nil)
|
||||
_ storev1.CaptureStore = (*Client)(nil)
|
||||
_ storev1.MappingStore = (*Client)(nil)
|
||||
_ storev1.BindingStore = (*Client)(nil)
|
||||
_ storev1.BindingDispatcher = (*Client)(nil)
|
||||
_ storev1.BindingTaskCreator = (*Client)(nil)
|
||||
_ storev1.ConfigSnapshotStore = (*Client)(nil)
|
||||
_ task.Store = (*Client)(nil)
|
||||
_ storecontract.TaskStore = (*Client)(nil)
|
||||
_ storecontract.CaptureStore = (*Client)(nil)
|
||||
_ storecontract.MappingStore = (*Client)(nil)
|
||||
_ storecontract.BindingStore = (*Client)(nil)
|
||||
_ storecontract.BindingDispatcher = (*Client)(nil)
|
||||
_ storecontract.BindingTaskCreator = (*Client)(nil)
|
||||
_ storecontract.ConfigSnapshotStore = (*Client)(nil)
|
||||
)
|
||||
|
||||
// Lifecycle
|
||||
@@ -54,7 +54,7 @@ func (c *Client) EnqueueIssue(ctx context.Context, owner, repo string, number in
|
||||
return r.Inserted, nil
|
||||
}
|
||||
|
||||
func (c *Client) EnqueueChatTask(ctx context.Context, owner, repo, title, body, wf, identity string) (*workflow.Task, error) {
|
||||
func (c *Client) EnqueueChatTask(ctx context.Context, owner, repo, title, body, wf, identity string) (*task.Task, error) {
|
||||
r, err := c.client.EnqueueChatTask(ctx, &pb.EnqueueChatTaskRequest{Owner: owner, Repo: repo, Title: title, Body: body, Workflow: wf, Identity: identity})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
@@ -62,7 +62,7 @@ func (c *Client) EnqueueChatTask(ctx context.Context, owner, repo, title, body,
|
||||
return taskValue(r.Task), nil
|
||||
}
|
||||
|
||||
func (c *Client) ClaimNext(ctx context.Context) (*workflow.Task, error) {
|
||||
func (c *Client) ClaimNext(ctx context.Context) (*task.Task, error) {
|
||||
r, err := c.client.ClaimNext(ctx, &pb.ClaimNextRequest{})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
@@ -73,7 +73,7 @@ func (c *Client) ClaimNext(ctx context.Context) (*workflow.Task, error) {
|
||||
return taskValue(r.Task), nil
|
||||
}
|
||||
|
||||
func (c *Client) ClaimByIssue(ctx context.Context, owner, repo string, number int) (*workflow.Task, error) {
|
||||
func (c *Client) ClaimByIssue(ctx context.Context, owner, repo string, number int) (*task.Task, error) {
|
||||
r, err := c.client.ClaimByIssue(ctx, &pb.ClaimByIssueRequest{Owner: owner, Repo: repo, Number: int64(number)})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
@@ -89,7 +89,7 @@ func (c *Client) Transition(ctx context.Context, taskID int64, from, to, detail
|
||||
return unmapError(err)
|
||||
}
|
||||
|
||||
func (c *Client) Update(ctx context.Context, t *workflow.Task) error {
|
||||
func (c *Client) Update(ctx context.Context, t *task.Task) error {
|
||||
_, err := c.client.Update(ctx, &pb.UpdateRequest{Task: taskProto(t)})
|
||||
return unmapError(err)
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func (c *Client) RetryTask(ctx context.Context, taskID int64, fromStatus, wf str
|
||||
|
||||
// Queries
|
||||
|
||||
func (c *Client) TaskByIssue(ctx context.Context, owner, repo string, number int) (*workflow.Task, error) {
|
||||
func (c *Client) TaskByIssue(ctx context.Context, owner, repo string, number int) (*task.Task, error) {
|
||||
r, err := c.client.TaskByIssue(ctx, &pb.TaskByIssueRequest{Owner: owner, Repo: repo, Number: int64(number)})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
@@ -135,7 +135,7 @@ func (c *Client) TaskByIssue(ctx context.Context, owner, repo string, number int
|
||||
return taskValue(r.Task), nil
|
||||
}
|
||||
|
||||
func (c *Client) TaskByID(ctx context.Context, taskID int64) (*workflow.Task, error) {
|
||||
func (c *Client) TaskByID(ctx context.Context, taskID int64) (*task.Task, error) {
|
||||
r, err := c.client.TaskByID(ctx, &pb.TaskByIDRequest{TaskId: taskID})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
@@ -146,7 +146,7 @@ func (c *Client) TaskByID(ctx context.Context, taskID int64) (*workflow.Task, er
|
||||
return taskValue(r.Task), nil
|
||||
}
|
||||
|
||||
func (c *Client) OpenPRs(ctx context.Context) ([]workflow.Task, error) {
|
||||
func (c *Client) OpenPRs(ctx context.Context) ([]task.Task, error) {
|
||||
r, err := c.client.OpenPRs(ctx, &pb.OpenPRsRequest{})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
@@ -162,7 +162,7 @@ func (c *Client) ClearTerminalTasks(ctx context.Context) (int64, error) {
|
||||
return r.Count, nil
|
||||
}
|
||||
|
||||
func (c *Client) Tasks(ctx context.Context, limit int) ([]workflow.Task, error) {
|
||||
func (c *Client) Tasks(ctx context.Context, limit int) ([]task.Task, error) {
|
||||
r, err := c.client.Tasks(ctx, &pb.TasksRequest{Limit: int64(limit)})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
@@ -213,7 +213,7 @@ func (c *Client) TaskEvents(ctx context.Context, taskID int64) ([]events.Event,
|
||||
return mapValues(r.Events, eventValue), nil
|
||||
}
|
||||
|
||||
func (c *Client) WorkflowStats(ctx context.Context) ([]storev1.WorkflowStat, error) {
|
||||
func (c *Client) WorkflowStats(ctx context.Context) ([]storecontract.WorkflowStat, error) {
|
||||
r, err := c.client.WorkflowStats(ctx, &pb.WorkflowStatsRequest{})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
@@ -221,7 +221,7 @@ func (c *Client) WorkflowStats(ctx context.Context) ([]storev1.WorkflowStat, err
|
||||
return mapValues(r.Stats, workflowStatValue), nil
|
||||
}
|
||||
|
||||
func (c *Client) StageStats(ctx context.Context) ([]storev1.StageStat, error) {
|
||||
func (c *Client) StageStats(ctx context.Context) ([]storecontract.StageStat, error) {
|
||||
r, err := c.client.StageStats(ctx, &pb.StageStatsRequest{})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
@@ -229,7 +229,7 @@ func (c *Client) StageStats(ctx context.Context) ([]storev1.StageStat, error) {
|
||||
return mapValues(r.Stats, stageStatValue), nil
|
||||
}
|
||||
|
||||
func (c *Client) TokensByDay(ctx context.Context, days int) ([]storev1.DayTokens, error) {
|
||||
func (c *Client) TokensByDay(ctx context.Context, days int) ([]storecontract.DayTokens, error) {
|
||||
r, err := c.client.TokensByDay(ctx, &pb.TokensByDayRequest{Days: int64(days)})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
@@ -239,7 +239,7 @@ func (c *Client) TokensByDay(ctx context.Context, days int) ([]storev1.DayTokens
|
||||
|
||||
// Capture
|
||||
|
||||
func (c *Client) InsertCapture(ctx context.Context, ce storev1.CapturedEvent, retention time.Duration, maxEvents int) (int64, error) {
|
||||
func (c *Client) InsertCapture(ctx context.Context, ce storecontract.CapturedEvent, retention time.Duration, maxEvents int) (int64, error) {
|
||||
r, err := c.client.InsertCapture(ctx, &pb.InsertCaptureRequest{Capture: capturedEventProto(ce), RetentionSeconds: int64(retention.Seconds()), MaxEvents: int64(maxEvents)})
|
||||
if err != nil {
|
||||
return 0, unmapError(err)
|
||||
@@ -253,7 +253,7 @@ func (c *Client) InsertCapture(ctx context.Context, ce storev1.CapturedEvent, re
|
||||
// PutConfigSnapshot publishes the dashboard's configuration projection. The
|
||||
// server admits it on the administrative token only; a task-scoped grant
|
||||
// cannot reach it (see TaskGrants).
|
||||
func (c *Client) PutConfigSnapshot(ctx context.Context, snapshot storev1.ConfigSnapshot) error {
|
||||
func (c *Client) PutConfigSnapshot(ctx context.Context, snapshot storecontract.ConfigSnapshot) error {
|
||||
_, err := c.client.PutConfigSnapshot(ctx, &pb.PutConfigSnapshotRequest{Snapshot: configSnapshotProto(snapshot)})
|
||||
if err != nil {
|
||||
return unmapError(err)
|
||||
@@ -263,23 +263,23 @@ func (c *Client) PutConfigSnapshot(ctx context.Context, snapshot storev1.ConfigS
|
||||
|
||||
// ConfigSnapshot reads the published projection. found is false, with a nil
|
||||
// error, before a daemon has published one.
|
||||
func (c *Client) ConfigSnapshot(ctx context.Context) (storev1.ConfigSnapshot, bool, error) {
|
||||
func (c *Client) ConfigSnapshot(ctx context.Context) (storecontract.ConfigSnapshot, bool, error) {
|
||||
reply, err := c.client.GetConfigSnapshot(ctx, &pb.GetConfigSnapshotRequest{})
|
||||
if err != nil {
|
||||
return storev1.ConfigSnapshot{}, false, unmapError(err)
|
||||
return storecontract.ConfigSnapshot{}, false, unmapError(err)
|
||||
}
|
||||
if !reply.Found {
|
||||
return storev1.ConfigSnapshot{}, false, nil
|
||||
return storecontract.ConfigSnapshot{}, false, nil
|
||||
}
|
||||
return configSnapshotValue(reply.Snapshot), true, nil
|
||||
}
|
||||
|
||||
func (c *Client) ListCaptures(ctx context.Context, limit int) ([]storev1.CapturedEvent, error) {
|
||||
func (c *Client) ListCaptures(ctx context.Context, limit int) ([]storecontract.CapturedEvent, error) {
|
||||
stream, err := c.client.StreamCaptures(ctx, &pb.StreamCapturesRequest{Limit: int64(limit)})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
}
|
||||
var captures []storev1.CapturedEvent
|
||||
var captures []storecontract.CapturedEvent
|
||||
for {
|
||||
r, err := stream.Recv()
|
||||
if errors.Is(err, io.EOF) {
|
||||
@@ -394,12 +394,12 @@ func (c *Client) RecordDispatch(ctx context.Context, bindingID, bindingVersion,
|
||||
|
||||
// ListUndispatchedCaptures calls StreamUndispatchedCaptures; see ListCaptures
|
||||
// above.
|
||||
func (c *Client) ListUndispatchedCaptures(ctx context.Context, sources []string, limit int) ([]storev1.CapturedEvent, error) {
|
||||
func (c *Client) ListUndispatchedCaptures(ctx context.Context, sources []string, limit int) ([]storecontract.CapturedEvent, error) {
|
||||
stream, err := c.client.StreamUndispatchedCaptures(ctx, &pb.StreamUndispatchedCapturesRequest{Sources: sources, Limit: int64(limit)})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
}
|
||||
var captures []storev1.CapturedEvent
|
||||
var captures []storecontract.CapturedEvent
|
||||
for {
|
||||
r, err := stream.Recv()
|
||||
if errors.Is(err, io.EOF) {
|
||||
@@ -414,7 +414,7 @@ func (c *Client) ListUndispatchedCaptures(ctx context.Context, sources []string,
|
||||
|
||||
// BindingTaskCreator
|
||||
|
||||
func (c *Client) EnqueueBindingTask(ctx context.Context, owner, repo, title, body, wf, identity string, bindingID int64, bindingVersion int) (*workflow.Task, error) {
|
||||
func (c *Client) EnqueueBindingTask(ctx context.Context, owner, repo, title, body, wf, identity string, bindingID int64, bindingVersion int) (*task.Task, error) {
|
||||
r, err := c.client.EnqueueBindingTask(ctx, &pb.EnqueueBindingTaskRequest{Owner: owner, Repo: repo, Title: title, Body: body, Workflow: wf, Identity: identity, BindingId: bindingID, BindingVersion: int64(bindingVersion)})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
@@ -422,11 +422,11 @@ func (c *Client) EnqueueBindingTask(ctx context.Context, owner, repo, title, bod
|
||||
return taskValue(r.Task), nil
|
||||
}
|
||||
|
||||
func derefTasks(in []*pb.Task) []workflow.Task {
|
||||
func derefTasks(in []*pb.Task) []task.Task {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := make([]workflow.Task, len(in))
|
||||
out := make([]task.Task, len(in))
|
||||
for i, t := range in {
|
||||
out[i] = *taskValue(t)
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
||||
storev1 "github.com/samcharles93/archie-core/internal/contracts/store/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/binding"
|
||||
"github.com/samcharles93/archie-core/internal/domain/mapping"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
)
|
||||
|
||||
// Unavailable-capability errors, mirroring gatewayrpc's missing-session-store
|
||||
@@ -40,13 +40,13 @@ func timeSeconds(s int64) time.Duration { return time.Duration(s) * time.Second
|
||||
// nil Mappings/Bindings/BindingDispatcher/BindingTaskCreator as "disabled".
|
||||
type Deps struct {
|
||||
Grants *TaskGrants
|
||||
Tasks storev1.TaskStore
|
||||
Captures storev1.CaptureStore
|
||||
ConfigSnapshots storev1.ConfigSnapshotStore
|
||||
Mappings storev1.MappingStore
|
||||
Bindings storev1.BindingStore
|
||||
BindingDispatcher storev1.BindingDispatcher
|
||||
BindingTaskCreator storev1.BindingTaskCreator
|
||||
Tasks storecontract.TaskStore
|
||||
Captures storecontract.CaptureStore
|
||||
ConfigSnapshots storecontract.ConfigSnapshotStore
|
||||
Mappings storecontract.MappingStore
|
||||
Bindings storecontract.BindingStore
|
||||
BindingDispatcher storecontract.BindingDispatcher
|
||||
BindingTaskCreator storecontract.BindingTaskCreator
|
||||
Log *slog.Logger
|
||||
}
|
||||
|
||||
@@ -277,14 +277,14 @@ func (s *server) TokensByDay(ctx context.Context, r *pb.TokensByDayRequest) (*pb
|
||||
|
||||
// Capture
|
||||
|
||||
func (s *server) capture() (storev1.CaptureStore, error) {
|
||||
func (s *server) capture() (storecontract.CaptureStore, error) {
|
||||
if s.deps.Captures == nil {
|
||||
return nil, errCaptureUnavailable
|
||||
}
|
||||
return s.deps.Captures, nil
|
||||
}
|
||||
|
||||
func (s *server) configSnapshots() (storev1.ConfigSnapshotStore, error) {
|
||||
func (s *server) configSnapshots() (storecontract.ConfigSnapshotStore, error) {
|
||||
if s.deps.ConfigSnapshots == nil {
|
||||
return nil, errConfigSnapshotsUnavailable
|
||||
}
|
||||
@@ -364,7 +364,7 @@ func (s *server) StreamCaptures(r *pb.StreamCapturesRequest, stream pb.StateStor
|
||||
|
||||
// Mapping
|
||||
|
||||
func (s *server) mapping() (storev1.MappingStore, error) {
|
||||
func (s *server) mapping() (storecontract.MappingStore, error) {
|
||||
if s.deps.Mappings == nil {
|
||||
return nil, errMappingUnavailable
|
||||
}
|
||||
@@ -431,7 +431,7 @@ func (s *server) DeleteMapping(ctx context.Context, r *pb.DeleteMappingRequest)
|
||||
|
||||
// Binding
|
||||
|
||||
func (s *server) binding() (storev1.BindingStore, error) {
|
||||
func (s *server) binding() (storecontract.BindingStore, error) {
|
||||
if s.deps.Bindings == nil {
|
||||
return nil, errBindingUnavailable
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
)
|
||||
|
||||
// TaskGrants lives in the State Store process. Restart invalidates all worker
|
||||
@@ -91,7 +91,7 @@ func (g *TaskGrants) taskFor(token string) int64 {
|
||||
}
|
||||
|
||||
// authorizesTaskScopedCall reports whether req -- a call to one of the three
|
||||
// workflow.Store RPCs a task grant may ever authorize -- targets taskID.
|
||||
// task.Store RPCs a task grant may ever authorize -- targets taskID.
|
||||
// Every other RPC (including RegisterTaskGrant/RevokeTaskGrant themselves)
|
||||
// falls through to false: a task grant can only ever narrow, never expand.
|
||||
func authorizesTaskScopedCall(fullMethod string, req any, taskID int64) bool {
|
||||
@@ -202,7 +202,7 @@ type GrantIssuer struct {
|
||||
Client *Client
|
||||
}
|
||||
|
||||
func (g *GrantIssuer) Issue(task *workflow.Task) (string, func(), error) {
|
||||
func (g *GrantIssuer) Issue(task *task.Task) (string, func(), error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
token, err := g.Client.RegisterTaskGrant(ctx, task.ID, defaultGrantLifetime)
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
||||
storev1 "github.com/samcharles93/archie-core/internal/contracts/store/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/binding"
|
||||
"github.com/samcharles93/archie-core/internal/domain/mapping"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
"github.com/samcharles93/archie-core/internal/events"
|
||||
)
|
||||
|
||||
@@ -44,7 +44,7 @@ func mapValues[A, B any](in []A, f func(A) B) []B {
|
||||
return out
|
||||
}
|
||||
|
||||
func taskProto(t *workflow.Task) *pb.Task { //nolint:dupl // mirror-image field-by-field proto<->domain mapping; taskValue below reverses every assignment, so line-level duplication is unavoidable without reflection
|
||||
func taskProto(t *task.Task) *pb.Task { //nolint:dupl // mirror-image field-by-field proto<->domain mapping; taskValue below reverses every assignment, so line-level duplication is unavoidable without reflection
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -60,11 +60,11 @@ func taskProto(t *workflow.Task) *pb.Task { //nolint:dupl // mirror-image field-
|
||||
}
|
||||
}
|
||||
|
||||
func taskValue(t *pb.Task) *workflow.Task { //nolint:dupl // see taskProto above
|
||||
func taskValue(t *pb.Task) *task.Task { //nolint:dupl // see taskProto above
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
return &workflow.Task{
|
||||
return &task.Task{
|
||||
ID: t.Id, Owner: t.Owner, Repo: t.Repo, IssueNumber: int(t.IssueNumber),
|
||||
Title: t.Title, Body: t.Body, Labels: t.Labels, Status: t.Status,
|
||||
Workflow: t.Workflow, Stage: t.Stage, Branch: t.Branch, Plan: t.Plan, Notes: t.Notes,
|
||||
@@ -119,7 +119,7 @@ func eventValue(e *pb.Event) events.Event {
|
||||
}
|
||||
}
|
||||
|
||||
func capturedEventProto(c storev1.CapturedEvent) *pb.CapturedEvent {
|
||||
func capturedEventProto(c storecontract.CapturedEvent) *pb.CapturedEvent {
|
||||
return &pb.CapturedEvent{
|
||||
Id: c.ID, ReceivedAt: timestamp(c.ReceivedAt), Source: c.Source,
|
||||
RemoteAddr: c.RemoteAddr, ContentType: c.ContentType, Headers: c.Headers,
|
||||
@@ -127,11 +127,11 @@ func capturedEventProto(c storev1.CapturedEvent) *pb.CapturedEvent {
|
||||
}
|
||||
}
|
||||
|
||||
func capturedEventValue(c *pb.CapturedEvent) storev1.CapturedEvent {
|
||||
func capturedEventValue(c *pb.CapturedEvent) storecontract.CapturedEvent {
|
||||
if c == nil {
|
||||
return storev1.CapturedEvent{}
|
||||
return storecontract.CapturedEvent{}
|
||||
}
|
||||
return storev1.CapturedEvent{
|
||||
return storecontract.CapturedEvent{
|
||||
ID: c.Id, ReceivedAt: timeValue(c.ReceivedAt), Source: c.Source,
|
||||
RemoteAddr: c.RemoteAddr, ContentType: c.ContentType, Headers: c.Headers,
|
||||
Body: c.Body, Authenticated: c.Authenticated,
|
||||
@@ -193,7 +193,7 @@ func bindingValue(b *pb.Binding) binding.Binding {
|
||||
}
|
||||
}
|
||||
|
||||
func workflowStatProto(w storev1.WorkflowStat) *pb.WorkflowStat {
|
||||
func workflowStatProto(w storecontract.WorkflowStat) *pb.WorkflowStat {
|
||||
return &pb.WorkflowStat{
|
||||
Workflow: w.Workflow, Runs: int64(w.Runs), Merged: int64(w.Merged),
|
||||
PrOpen: int64(w.PROpen), Parked: int64(w.Parked), AvgTokens: int64(w.AvgTokens),
|
||||
@@ -201,37 +201,37 @@ func workflowStatProto(w storev1.WorkflowStat) *pb.WorkflowStat {
|
||||
}
|
||||
}
|
||||
|
||||
func workflowStatValue(w *pb.WorkflowStat) storev1.WorkflowStat {
|
||||
func workflowStatValue(w *pb.WorkflowStat) storecontract.WorkflowStat {
|
||||
if w == nil {
|
||||
return storev1.WorkflowStat{}
|
||||
return storecontract.WorkflowStat{}
|
||||
}
|
||||
return storev1.WorkflowStat{
|
||||
return storecontract.WorkflowStat{
|
||||
Workflow: w.Workflow, Runs: int(w.Runs), Merged: int(w.Merged),
|
||||
PROpen: int(w.PrOpen), Parked: int(w.Parked), AvgTokens: int(w.AvgTokens),
|
||||
AvgSteps: w.AvgSteps, TotalToken: int(w.TotalTokens),
|
||||
}
|
||||
}
|
||||
|
||||
func stageStatProto(s storev1.StageStat) *pb.StageStat {
|
||||
func stageStatProto(s storecontract.StageStat) *pb.StageStat {
|
||||
return &pb.StageStat{Workflow: s.Workflow, Stage: s.Stage, Runs: int64(s.Runs), AvgMs: int64(s.AvgMs), Errors: int64(s.Errors)}
|
||||
}
|
||||
|
||||
func stageStatValue(s *pb.StageStat) storev1.StageStat {
|
||||
func stageStatValue(s *pb.StageStat) storecontract.StageStat {
|
||||
if s == nil {
|
||||
return storev1.StageStat{}
|
||||
return storecontract.StageStat{}
|
||||
}
|
||||
return storev1.StageStat{Workflow: s.Workflow, Stage: s.Stage, Runs: int(s.Runs), AvgMs: int(s.AvgMs), Errors: int(s.Errors)}
|
||||
return storecontract.StageStat{Workflow: s.Workflow, Stage: s.Stage, Runs: int(s.Runs), AvgMs: int(s.AvgMs), Errors: int(s.Errors)}
|
||||
}
|
||||
|
||||
func dayTokensProto(d storev1.DayTokens) *pb.DayTokens {
|
||||
func dayTokensProto(d storecontract.DayTokens) *pb.DayTokens {
|
||||
return &pb.DayTokens{Day: d.Day, Tokens: int64(d.Tokens)}
|
||||
}
|
||||
|
||||
func dayTokensValue(d *pb.DayTokens) storev1.DayTokens {
|
||||
func dayTokensValue(d *pb.DayTokens) storecontract.DayTokens {
|
||||
if d == nil {
|
||||
return storev1.DayTokens{}
|
||||
return storecontract.DayTokens{}
|
||||
}
|
||||
return storev1.DayTokens{Day: d.Day, Tokens: int(d.Tokens)}
|
||||
return storecontract.DayTokens{Day: d.Day, Tokens: int(d.Tokens)}
|
||||
}
|
||||
|
||||
// Canonical public phrases for sentinel errors (rev. 2c §7). These strings
|
||||
@@ -271,17 +271,17 @@ func mapError(err error) error {
|
||||
return status.Error(codes.DeadlineExceeded, context.DeadlineExceeded.Error())
|
||||
}
|
||||
switch {
|
||||
case errors.Is(err, storev1.ErrStaleTransition):
|
||||
case errors.Is(err, storecontract.ErrStaleTransition):
|
||||
return status.Error(codes.FailedPrecondition, msgStaleTransition)
|
||||
case errors.Is(err, storev1.ErrBindingNotFound):
|
||||
case errors.Is(err, storecontract.ErrBindingNotFound):
|
||||
return status.Error(codes.NotFound, msgBindingNotFound)
|
||||
case errors.Is(err, storev1.ErrMappingNotFound):
|
||||
case errors.Is(err, storecontract.ErrMappingNotFound):
|
||||
return status.Error(codes.NotFound, msgMappingNotFound)
|
||||
case errors.Is(err, storev1.ErrBindingOverlap):
|
||||
case errors.Is(err, storecontract.ErrBindingOverlap):
|
||||
return status.Error(codes.FailedPrecondition, msgBindingOverlap)
|
||||
case errors.Is(err, storev1.ErrBindingTransition):
|
||||
case errors.Is(err, storecontract.ErrBindingTransition):
|
||||
return status.Error(codes.FailedPrecondition, msgBindingTransition)
|
||||
case errors.Is(err, storev1.ErrAlreadyDispatched):
|
||||
case errors.Is(err, storecontract.ErrAlreadyDispatched):
|
||||
return status.Error(codes.AlreadyExists, msgAlreadyDispatched)
|
||||
default:
|
||||
return status.Error(codes.Internal, msgInternal)
|
||||
@@ -289,7 +289,7 @@ func mapError(err error) error {
|
||||
}
|
||||
|
||||
// unmapError rehydrates a gRPC status error back to the store sentinel it
|
||||
// came from, so a caller's errors.Is(err, storev1.ErrX) keeps working across
|
||||
// came from, so a caller's errors.Is(err, storecontract.ErrX) keeps working across
|
||||
// the wire. A non-status error (e.g. a transport failure) is returned
|
||||
// unchanged.
|
||||
//
|
||||
@@ -317,22 +317,22 @@ func unmapError(err error) error {
|
||||
case codes.FailedPrecondition:
|
||||
switch st.Message() {
|
||||
case msgStaleTransition:
|
||||
return storev1.ErrStaleTransition
|
||||
return storecontract.ErrStaleTransition
|
||||
case msgBindingOverlap:
|
||||
return storev1.ErrBindingOverlap
|
||||
return storecontract.ErrBindingOverlap
|
||||
case msgBindingTransition:
|
||||
return storev1.ErrBindingTransition
|
||||
return storecontract.ErrBindingTransition
|
||||
}
|
||||
case codes.NotFound:
|
||||
switch st.Message() {
|
||||
case msgBindingNotFound:
|
||||
return storev1.ErrBindingNotFound
|
||||
return storecontract.ErrBindingNotFound
|
||||
case msgMappingNotFound:
|
||||
return storev1.ErrMappingNotFound
|
||||
return storecontract.ErrMappingNotFound
|
||||
}
|
||||
case codes.AlreadyExists:
|
||||
if st.Message() == msgAlreadyDispatched {
|
||||
return storev1.ErrAlreadyDispatched
|
||||
return storecontract.ErrAlreadyDispatched
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("state store: %s: %w", st.Message(), err)
|
||||
@@ -341,7 +341,7 @@ func unmapError(err error) error {
|
||||
// configSnapshotProto and configSnapshotValue carry the dashboard's
|
||||
// configuration projection. document crosses as bytes, unread by either side
|
||||
// of this hop: the store holds it and the page renders it.
|
||||
func configSnapshotProto(snapshot storev1.ConfigSnapshot) *pb.ConfigSnapshot {
|
||||
func configSnapshotProto(snapshot storecontract.ConfigSnapshot) *pb.ConfigSnapshot {
|
||||
return &pb.ConfigSnapshot{
|
||||
Schema: snapshot.Schema,
|
||||
Document: snapshot.Document,
|
||||
@@ -349,11 +349,11 @@ func configSnapshotProto(snapshot storev1.ConfigSnapshot) *pb.ConfigSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
func configSnapshotValue(snapshot *pb.ConfigSnapshot) storev1.ConfigSnapshot {
|
||||
func configSnapshotValue(snapshot *pb.ConfigSnapshot) storecontract.ConfigSnapshot {
|
||||
if snapshot == nil {
|
||||
return storev1.ConfigSnapshot{}
|
||||
return storecontract.ConfigSnapshot{}
|
||||
}
|
||||
return storev1.ConfigSnapshot{
|
||||
return storecontract.ConfigSnapshot{
|
||||
Schema: snapshot.Schema,
|
||||
Document: snapshot.Document,
|
||||
PublishedAt: timeValue(snapshot.PublishedAt),
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/nats-io/nats.go"
|
||||
|
||||
storev1 "github.com/samcharles93/archie-core/internal/contracts/store/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/domain/taskactions"
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
"github.com/samcharles93/archie-core/internal/natsrpc"
|
||||
@@ -49,7 +49,7 @@ var actionErrorKinds = []struct {
|
||||
}{
|
||||
{kind: "not_found", err: taskactions.ErrNotFound},
|
||||
{kind: "conflict", err: taskactions.ErrConflict},
|
||||
{kind: "stale_transition", err: storev1.ErrStaleTransition},
|
||||
{kind: "stale_transition", err: storecontract.ErrStaleTransition},
|
||||
{kind: "unavailable", err: taskactions.ErrUnavailable},
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
storev1 "github.com/samcharles93/archie-core/internal/contracts/store/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/domain/taskactions"
|
||||
)
|
||||
|
||||
type Store struct{ storev1.TaskStore }
|
||||
type Store struct{ storecontract.TaskStore }
|
||||
|
||||
func (s Store) TaskByID(ctx context.Context, id int64) (*taskactions.Task, error) {
|
||||
t, err := s.TaskStore.TaskByID(ctx, id)
|
||||
|
||||
Reference in new issue
Block a user