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.
146 lines
5.3 KiB
Go
146 lines
5.3 KiB
Go
package gatewayrpc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
pb "github.com/samcharles93/archie-core/internal/contracts/gateway/v1"
|
|
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
|
)
|
|
|
|
var _ messaging.SessionStore = (*StoreClient)(nil)
|
|
|
|
// 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.
|
|
//
|
|
// Role does not cross the wire (the proto is unchanged by the messaging
|
|
// migration). Both sides derive it from the owning session instead -- the
|
|
// server on write, this client on read -- so they agree without a proto
|
|
// change.
|
|
type StoreClient struct{ client pb.ChatServiceClient }
|
|
|
|
func NewStoreClient(conn grpc.ClientConnInterface) *StoreClient {
|
|
return &StoreClient{client: pb.NewChatServiceClient(conn)}
|
|
}
|
|
|
|
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
|
|
}
|
|
if !v.Found {
|
|
return nil, nil
|
|
}
|
|
s := sessionValue(v.Session)
|
|
return &s, nil
|
|
}
|
|
|
|
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) ([]messaging.SessionContext, error) {
|
|
v, e := c.client.GetSessionsByChannel(ctx, &pb.GetSessionsByChannelRequest{Platform: p, ChannelId: ch})
|
|
if e != nil {
|
|
return nil, e
|
|
}
|
|
return mapValues(v.Sessions, sessionValue), nil
|
|
}
|
|
|
|
func (c *StoreClient) Delete(ctx context.Context, id string) error {
|
|
_, e := c.client.DeleteSession(ctx, &pb.DeleteSessionRequest{SessionId: id})
|
|
return e
|
|
}
|
|
|
|
func (c *StoreClient) Touch(ctx context.Context, id string) error {
|
|
_, e := c.client.TouchSession(ctx, &pb.TouchSessionRequest{SessionId: id})
|
|
return e
|
|
}
|
|
|
|
func (c *StoreClient) List(ctx context.Context) ([]messaging.SessionContext, error) {
|
|
v, e := c.client.ListSessions(ctx, &pb.ListSessionsRequest{})
|
|
if e != nil {
|
|
return nil, e
|
|
}
|
|
return mapValues(v.Sessions, sessionValue), nil
|
|
}
|
|
|
|
func (c *StoreClient) SaveMessage(ctx context.Context, id string, m messaging.Message) error {
|
|
_, e := c.client.SaveMessage(ctx, &pb.SaveMessageRequest{SessionId: id, Message: storedProto(m)})
|
|
return e
|
|
}
|
|
|
|
func (c *StoreClient) DeleteRecentMessages(ctx context.Context, id string, n int) (int, error) {
|
|
v, e := c.client.DeleteRecentMessages(ctx, &pb.DeleteRecentMessagesRequest{SessionId: id, Limit: int64(n)})
|
|
return int(v.Deleted), e
|
|
}
|
|
|
|
func (c *StoreClient) MessageCount(ctx context.Context, id string) (int, error) {
|
|
v, e := c.client.MessageCount(ctx, &pb.MessageCountRequest{SessionId: id})
|
|
return int(v.Count), e
|
|
}
|
|
|
|
func (c *StoreClient) SaveMessages(ctx context.Context, id string, m []messaging.Message) error {
|
|
_, e := c.client.SaveMessages(ctx, &pb.SaveMessagesRequest{SessionId: id, Messages: mapValues(m, storedProto)})
|
|
return e
|
|
}
|
|
|
|
func (c *StoreClient) ReplaceMessages(ctx context.Context, id string, m []messaging.Message, s []string) error {
|
|
_, e := c.client.ReplaceMessages(ctx, &pb.ReplaceMessagesRequest{SessionId: id, Messages: mapValues(m, storedProto), Superseded: s})
|
|
return e
|
|
}
|
|
|
|
func (c *StoreClient) RecentMessages(ctx context.Context, id string, n int) ([]messaging.Message, error) {
|
|
// No store-RecentMessages RPC exists; the chat contract serves the same
|
|
// history in-process and over the wire. Re-address it (see
|
|
// addressRecords).
|
|
v, err := c.client.RecentMessages(ctx, &pb.RecentMessagesRequest{SessionId: id, Limit: int64(n)})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return addressRecords(ctx, c.client, id, v.Messages)
|
|
}
|
|
|
|
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 messaging.MessagePage{}, e
|
|
}
|
|
msgs, err := addressRecords(ctx, c.client, id, v.Messages)
|
|
if err != nil {
|
|
return messaging.MessagePage{}, err
|
|
}
|
|
return messaging.MessagePage{Messages: msgs, NextOffset: int(v.NextOffset), HasMore: v.HasMore, Truncated: v.Truncated}, nil
|
|
}
|
|
|
|
func (c *StoreClient) Close() error { return nil }
|
|
|
|
// addressRecords restores the canonical fields the wire drops -- role and
|
|
// conversation address -- from the owning session, which is where the
|
|
// server derived them from on the way out. A missing session yields zero
|
|
// values, matching the store's LEFT JOIN for orphaned rows.
|
|
func addressRecords(ctx context.Context, client pb.ChatServiceClient, id string, msgs []*pb.Message) ([]messaging.Message, error) {
|
|
var botUser string
|
|
var conv messaging.ConversationID
|
|
v, err := client.GetSession(ctx, &pb.GetSessionRequest{SessionId: id})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if v.Found {
|
|
sc := sessionValue(v.Session)
|
|
botUser = sc.Source.BotUser
|
|
conv = messaging.ConversationID{ChannelID: sc.Source.ChannelID, ThreadID: sc.Source.ThreadID}
|
|
}
|
|
out := make([]messaging.Message, 0, len(msgs))
|
|
for _, m := range msgs {
|
|
stored := storedValue(m)
|
|
stored.ConversationID = conv
|
|
stored.Role = messaging.RoleForSender(stored.Sender, botUser)
|
|
out = append(out, stored)
|
|
}
|
|
return out, nil
|
|
}
|