feat: Go backend, enhanced search, new widgets, Docker deploy
Major changes: - Add Go backend (backend/) with microservices architecture - Enhanced master-agents-svc: reranker, content-classifier, stealth-crawler, proxy-manager, media-search, fastClassifier, language detection - New web-svc widgets: KnowledgeCard, ProductCard, ProfileCard, VideoCard, UnifiedCard, CardGallery, InlineImageGallery, SourcesPanel, RelatedQuestions - Improved discover-svc with discover-db integration - Docker deployment improvements (Caddyfile, vendor.sh, BUILD.md) - Library-svc: project_id schema migration - Remove deprecated finance-svc and travel-svc - Localization improvements across services Made-with: Cursor
This commit is contained in:
104
backend/internal/computer/connectors/connector.go
Normal file
104
backend/internal/computer/connectors/connector.go
Normal file
@@ -0,0 +1,104 @@
|
||||
package connectors
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Connector interface {
|
||||
ID() string
|
||||
Name() string
|
||||
Description() string
|
||||
Execute(ctx context.Context, action string, params map[string]interface{}) (interface{}, error)
|
||||
GetActions() []Action
|
||||
Validate(params map[string]interface{}) error
|
||||
}
|
||||
|
||||
type Action struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Schema map[string]interface{} `json:"schema"`
|
||||
Required []string `json:"required"`
|
||||
}
|
||||
|
||||
type ConnectorHub struct {
|
||||
connectors map[string]Connector
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
func NewConnectorHub() *ConnectorHub {
|
||||
return &ConnectorHub{
|
||||
connectors: make(map[string]Connector),
|
||||
}
|
||||
}
|
||||
|
||||
func (h *ConnectorHub) Register(connector Connector) {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
h.connectors[connector.ID()] = connector
|
||||
}
|
||||
|
||||
func (h *ConnectorHub) Unregister(id string) {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
delete(h.connectors, id)
|
||||
}
|
||||
|
||||
func (h *ConnectorHub) Get(id string) (Connector, error) {
|
||||
h.mu.RLock()
|
||||
defer h.mu.RUnlock()
|
||||
|
||||
connector, ok := h.connectors[id]
|
||||
if !ok {
|
||||
return nil, errors.New("connector not found: " + id)
|
||||
}
|
||||
return connector, nil
|
||||
}
|
||||
|
||||
func (h *ConnectorHub) List() []Connector {
|
||||
h.mu.RLock()
|
||||
defer h.mu.RUnlock()
|
||||
|
||||
result := make([]Connector, 0, len(h.connectors))
|
||||
for _, c := range h.connectors {
|
||||
result = append(result, c)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (h *ConnectorHub) Execute(ctx context.Context, connectorID, action string, params map[string]interface{}) (interface{}, error) {
|
||||
connector, err := h.Get(connectorID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := connector.Validate(params); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return connector.Execute(ctx, action, params)
|
||||
}
|
||||
|
||||
type ConnectorInfo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Actions []Action `json:"actions"`
|
||||
}
|
||||
|
||||
func (h *ConnectorHub) GetInfo() []ConnectorInfo {
|
||||
h.mu.RLock()
|
||||
defer h.mu.RUnlock()
|
||||
|
||||
result := make([]ConnectorInfo, 0, len(h.connectors))
|
||||
for _, c := range h.connectors {
|
||||
result = append(result, ConnectorInfo{
|
||||
ID: c.ID(),
|
||||
Name: c.Name(),
|
||||
Description: c.Description(),
|
||||
Actions: c.GetActions(),
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user