chore: delete code no binary or test reaches
This commit is contained in:
1 parent
7986ccb3f7
commit
01acb97f96
34 files changed
+1
-1483
No files matched your search
@@ -19,15 +19,6 @@ type Live struct {
|
||||
engine atomic.Pointer[Engine]
|
||||
}
|
||||
|
||||
// NewLive builds the first engine from load.
|
||||
func NewLive(ctx context.Context, load func(context.Context) ([]access.Policy, error), log *slog.Logger) (*Live, error) {
|
||||
l := NewPending(load, log)
|
||||
if err := l.Reload(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return l, nil
|
||||
}
|
||||
|
||||
// NewPending returns a chain whose engine refuses every request until Run or
|
||||
// Reload loads the stored policies, so a process that starts before its State
|
||||
// Store is closed rather than opened.
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
// Package embedding implements the internal/domain/embedding.Client
|
||||
// contract over the ai-sdk provider SDKs already vendored for chat, so
|
||||
// this capability is config-driven the same way chat model roles already
|
||||
// are (a providers table + a role in [models]).
|
||||
package embedding
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
sdkembed "github.com/samcharles93/ai-sdk/embed"
|
||||
"github.com/samcharles93/ai-sdk/provider/cohere"
|
||||
"github.com/samcharles93/ai-sdk/provider/gemini"
|
||||
"github.com/samcharles93/ai-sdk/provider/mistral"
|
||||
"github.com/samcharles93/ai-sdk/provider/ollama"
|
||||
"github.com/samcharles93/ai-sdk/provider/openai"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
domainembedding "github.com/samcharles93/archie-core/internal/domain/embedding"
|
||||
)
|
||||
|
||||
// DefaultTimeout bounds one embedding request when Options.Timeout is
|
||||
// unset.
|
||||
const DefaultTimeout = 30 * time.Second
|
||||
|
||||
// Options configures New.
|
||||
type Options struct {
|
||||
// Getenv resolves a provider's APIKeyEnv to its credential. Defaults to
|
||||
// os.Getenv; overridable for tests.
|
||||
Getenv func(string) string
|
||||
// Timeout bounds one embedding request. Defaults to DefaultTimeout.
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
// New builds an embedding client from the embedding model alias and its provider. It
|
||||
// returns (nil, false) when unavailable. Provider secrets must already be
|
||||
// resolved.
|
||||
func New(cfg config.Config, opts Options) (domainembedding.Client, bool) {
|
||||
getenv := opts.Getenv
|
||||
if getenv == nil {
|
||||
getenv = os.Getenv
|
||||
}
|
||||
timeout := opts.Timeout
|
||||
if timeout <= 0 {
|
||||
timeout = DefaultTimeout
|
||||
}
|
||||
|
||||
ref, err := config.ResolveModel(cfg.Models, "", config.PurposeEmbedding)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
providerID, modelID, ok := parseModelRef(ref)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
provider, ok := cfg.Providers[providerID]
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
apiKey := ""
|
||||
if provider.APIKeyEnv != "" {
|
||||
apiKey = strings.TrimSpace(getenv(provider.APIKeyEnv))
|
||||
if apiKey == "" {
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
|
||||
sdkProvider, err := newSDKProvider(provider.Class, apiKey, provider.BaseURL, &http.Client{Timeout: timeout})
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
return &client{provider: sdkembed.NewClient(sdkProvider), model: modelID}, true
|
||||
}
|
||||
|
||||
// parseModelRef splits a "provider/model" role value the same way
|
||||
// ai-sdk/runtime.Runtime.ParseModelRef does, without depending on a
|
||||
// Runtime instance.
|
||||
func parseModelRef(ref string) (providerID, modelID string, ok bool) {
|
||||
ref = strings.TrimSpace(ref)
|
||||
if ref == "" {
|
||||
return "", "", false
|
||||
}
|
||||
providerID, modelID, hasSlash := strings.Cut(ref, "/")
|
||||
providerID, modelID = strings.TrimSpace(providerID), strings.TrimSpace(modelID)
|
||||
if !hasSlash || providerID == "" || modelID == "" {
|
||||
return "", "", false
|
||||
}
|
||||
return providerID, modelID, true
|
||||
}
|
||||
|
||||
// newSDKProvider builds the ai-sdk embed provider for class. Unsupported
|
||||
// classes, including azure, return an error.
|
||||
func newSDKProvider(class, apiKey, baseURL string, httpClient *http.Client) (sdkembed.Provider, error) {
|
||||
switch class {
|
||||
case "openai", "openai-compatible":
|
||||
return openai.New(openai.Config{APIKey: apiKey, BaseURL: baseURL, HTTPClient: httpClient})
|
||||
case "gemini":
|
||||
return gemini.New(gemini.Config{APIKey: apiKey, BaseURL: baseURL, HTTPClient: httpClient})
|
||||
case "ollama":
|
||||
return ollama.New(ollama.Config{BaseURL: baseURL, HTTPClient: httpClient}), nil
|
||||
case "cohere":
|
||||
return cohere.New(cohere.Config{APIKey: apiKey, BaseURL: baseURL, HTTPClient: httpClient})
|
||||
case "mistral":
|
||||
return mistral.New(mistral.Config{APIKey: apiKey, BaseURL: baseURL, HTTPClient: httpClient})
|
||||
default:
|
||||
return nil, fmt.Errorf("embedding: provider class %q does not support embeddings", class)
|
||||
}
|
||||
}
|
||||
|
||||
// client adapts an ai-sdk embed.Client to domainembedding.Client.
|
||||
type client struct {
|
||||
provider *sdkembed.Client
|
||||
model string
|
||||
}
|
||||
|
||||
func (c *client) Embed(ctx context.Context, texts []string) ([]domainembedding.Vector, error) {
|
||||
if len(texts) == 0 {
|
||||
return nil, domainembedding.ErrEmptyInput
|
||||
}
|
||||
resp, err := c.provider.Embed(ctx, sdkembed.Request{Model: c.model, Inputs: texts})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("embedding: %w", err)
|
||||
}
|
||||
vectors := make([]domainembedding.Vector, len(texts))
|
||||
for _, e := range resp.Embeddings {
|
||||
if e.Index < 0 || e.Index >= len(vectors) {
|
||||
continue
|
||||
}
|
||||
vectors[e.Index] = domainembedding.Vector(e.Vector)
|
||||
}
|
||||
return vectors, nil
|
||||
}
|
||||
@@ -18,8 +18,7 @@ var _ messaging.ChatContract = (*Client)(nil)
|
||||
|
||||
// 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.
|
||||
// role and is re-addressed from the owning session on arrival.
|
||||
type Client struct{ client pb.ChatServiceClient }
|
||||
|
||||
func NewClient(conn grpc.ClientConnInterface) *Client {
|
||||
|
||||
@@ -3,115 +3,10 @@ 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 Gateway's session
|
||||
// RPCs. Role is derived from the session.
|
||||
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
|
||||
|
||||
@@ -51,24 +51,6 @@ type Plan struct {
|
||||
ContextSources []spec.ContextSource
|
||||
}
|
||||
|
||||
// DecodePublished reads the descriptor from an image's manifest annotations
|
||||
// and holds it to the published form: strict decoding, full validation, and
|
||||
// no unexpanded build-phase args.
|
||||
func DecodePublished(annotations map[string]string) (*spec.Descriptor, error) {
|
||||
raw, ok := annotations[spec.AnnotationDescriptor]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("image is not a kit: no %s annotation", spec.AnnotationDescriptor)
|
||||
}
|
||||
d, err := spec.Decode([]byte(raw))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := spec.ValidatePublished([]byte(raw), d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
// SelectCapability applies Archie's runtime policy before composition.
|
||||
func SelectCapability(_ context.Context, _ spec.Descriptor, c spec.Capability) spec.CapabilityDecision {
|
||||
reason, err := refusalReason(c)
|
||||
|
||||
@@ -184,11 +184,6 @@ type DiskProbe struct {
|
||||
Statfs func(string, *syscall.Statfs_t) error
|
||||
}
|
||||
|
||||
// NewDiskProbe returns a single-path disk probe.
|
||||
func NewDiskProbe(path string) *DiskProbe {
|
||||
return NewDiskProbeTargets([]DiskTarget{{Name: "work", Path: path}})
|
||||
}
|
||||
|
||||
// NewDiskProbeTargets returns a disk probe for the supplied, stable-ordered targets.
|
||||
func NewDiskProbeTargets(targets []DiskTarget) *DiskProbe {
|
||||
return &DiskProbe{Targets: append([]DiskTarget(nil), targets...), Threshold: DefaultDiskThreshold, Statfs: syscall.Statfs}
|
||||
@@ -292,56 +287,3 @@ type GatewayProbe struct {
|
||||
Channels func() []ChannelState
|
||||
CountSessions sessionCounter
|
||||
}
|
||||
|
||||
// NewGatewayProbe returns a gateway probe. Either function may be nil.
|
||||
func NewGatewayProbe(channels func() []ChannelState, countSessions sessionCounter) *GatewayProbe {
|
||||
return &GatewayProbe{Channels: channels, CountSessions: countSessions}
|
||||
}
|
||||
|
||||
func (p *GatewayProbe) Name() string { return "gateway" }
|
||||
|
||||
func (p *GatewayProbe) Check(ctx context.Context) health.Result {
|
||||
configChannels := 0
|
||||
runningChannels := 0
|
||||
failed := false
|
||||
if p.Channels != nil {
|
||||
for _, c := range p.Channels() {
|
||||
if c.Configured {
|
||||
configChannels++
|
||||
}
|
||||
if c.Configured && c.State == "running" {
|
||||
runningChannels++
|
||||
}
|
||||
if c.Configured && c.State == "failed" {
|
||||
failed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
sessions := 0
|
||||
if p.CountSessions != nil {
|
||||
sessions = p.CountSessions(ctx)
|
||||
}
|
||||
|
||||
switch {
|
||||
case configChannels == 0:
|
||||
return health.Result{
|
||||
Status: health.StatusDegraded,
|
||||
Detail: "no gateway channels configured, " + fmt.Sprintf("%d sessions", sessions),
|
||||
}
|
||||
case failed:
|
||||
return health.Result{
|
||||
Status: health.StatusDegraded,
|
||||
Detail: fmt.Sprintf("channel failed, %d/%d running, %d sessions", runningChannels, configChannels, sessions),
|
||||
}
|
||||
case runningChannels == 0:
|
||||
return health.Result{
|
||||
Status: health.StatusDegraded,
|
||||
Detail: fmt.Sprintf("gateway not running, %d/%d channels up, %d sessions", runningChannels, configChannels, sessions),
|
||||
}
|
||||
default:
|
||||
return health.Result{
|
||||
Status: health.StatusOK,
|
||||
Detail: fmt.Sprintf("%d/%d channels running, %d sessions, not draining", runningChannels, configChannels, sessions),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user