feat(connectors): group extensions as platform, integration or agent (#2084)
This commit is contained in:
6 files changed
+176
-26
No files matched your search
@@ -46,6 +46,45 @@ const (
|
||||
ContractGuard = "guard"
|
||||
)
|
||||
|
||||
// Group says what an extension is for, so the dashboard can list the
|
||||
// extensions an operator sets up together.
|
||||
type Group string
|
||||
|
||||
// Groups of extensions. Workflows and playbooks are content and have none.
|
||||
const (
|
||||
GroupPlatform Group = "platform"
|
||||
GroupIntegration Group = "integration"
|
||||
GroupAgent Group = "agent"
|
||||
)
|
||||
|
||||
// Contracts lists every contract with its group. Everything that enumerates
|
||||
// contracts reads this table, and GroupOf is the only way to look a group up,
|
||||
// so a contract without a group cannot be served.
|
||||
func Contracts() []ContractGroup {
|
||||
return []ContractGroup{
|
||||
{ContractConnector, GroupIntegration},
|
||||
{ContractSecretEngine, GroupPlatform},
|
||||
{ContractGuard, GroupPlatform},
|
||||
{ContractMCP, GroupAgent},
|
||||
}
|
||||
}
|
||||
|
||||
// ContractGroup pairs a contract with its group.
|
||||
type ContractGroup struct {
|
||||
Contract string
|
||||
Group Group
|
||||
}
|
||||
|
||||
// GroupOf returns the group of a contract in Contracts.
|
||||
func GroupOf(contract string) Group {
|
||||
for _, c := range Contracts() {
|
||||
if c.Contract == contract {
|
||||
return c.Group
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Credential is a credential's sealed fields.
|
||||
type Credential struct {
|
||||
OrgID string `db:"org_id"`
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
type ExtensionView struct {
|
||||
Name string `json:"name"`
|
||||
Contract string `json:"contract"`
|
||||
Group string `json:"group" enum:"platform,integration,agent"`
|
||||
State string `json:"state"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
@@ -61,7 +62,7 @@ func (m *Module) list(contract string) func(context.Context, *struct{}) (*httpap
|
||||
|
||||
func (m *Module) viewOf(a store.Accepted) (ExtensionView, error) {
|
||||
view := ExtensionView{
|
||||
Name: a.Name, Contract: a.Contract, Digest: a.SHA256, Path: a.Path, URL: a.URL,
|
||||
Name: a.Name, Contract: a.Contract, Group: string(store.GroupOf(a.Contract)), Digest: a.SHA256, Path: a.Path, URL: a.URL,
|
||||
Args: a.Args, Egress: a.Egress, Env: a.Env, Tools: a.Tools,
|
||||
Settings: map[string]string{}, Credentials: map[string]string{}, SettingsSchema: []Setting{},
|
||||
}
|
||||
|
||||
@@ -254,16 +254,48 @@ func (m *Module) Close() {
|
||||
m.host.Close()
|
||||
}
|
||||
|
||||
// extensionKinds is the one table of accepted-package kinds: the contract each
|
||||
// serves, its API path and its names. The group comes from the contract.
|
||||
func extensionKinds() []extensionKind {
|
||||
return []extensionKind{
|
||||
{store.ContractConnector, "/api/connectors", "connector", "connector", "connectors", "Connectors"},
|
||||
{store.ContractSecretEngine, "/api/secret-engines", "secret-engine", "secret engine", "secret engines", "Secret engines"},
|
||||
{store.ContractGuard, "/api/guards", "guard", "guard", "guards", "Guards"},
|
||||
{store.ContractMCP, "/api/mcp-servers", "mcp-server", "MCP server", "MCP servers", "MCP servers"},
|
||||
}
|
||||
}
|
||||
|
||||
type extensionKind struct {
|
||||
contract, path, noun, singular, plural, tag string
|
||||
}
|
||||
|
||||
// ExtensionKind is one kind of accepted package and the group it belongs to.
|
||||
type ExtensionKind struct {
|
||||
Kind string `json:"kind" doc:"The API path segment that lists this kind"`
|
||||
Label string `json:"label"`
|
||||
Singular string `json:"singular"`
|
||||
Group string `json:"group" enum:"platform,integration,agent"`
|
||||
}
|
||||
|
||||
func listExtensionKinds(context.Context, *struct{}) (*httpapi.Reply[[]ExtensionKind], error) {
|
||||
kinds := extensionKinds()
|
||||
out := make([]ExtensionKind, 0, len(kinds))
|
||||
for _, k := range kinds {
|
||||
out = append(out, ExtensionKind{
|
||||
Kind: strings.TrimPrefix(k.path, "/api/"), Label: k.tag, Singular: k.singular,
|
||||
Group: string(store.GroupOf(k.contract)),
|
||||
})
|
||||
}
|
||||
return httpapi.OK(out), nil
|
||||
}
|
||||
|
||||
// Register adds the API for accepted packages and credentials.
|
||||
func (m *Module) Register(api huma.API) {
|
||||
for _, k := range []struct {
|
||||
contract, path, noun, plural, tag string
|
||||
}{
|
||||
{store.ContractConnector, "/api/connectors", "connector", "connectors", "Connectors"},
|
||||
{store.ContractSecretEngine, "/api/secret-engines", "secret-engine", "secret engines", "Secret engines"},
|
||||
{store.ContractGuard, "/api/guards", "guard", "guards", "Guards"},
|
||||
{store.ContractMCP, "/api/mcp-servers", "mcp-server", "MCP servers", "MCP servers"},
|
||||
} {
|
||||
huma.Register(api, huma.Operation{
|
||||
OperationID: "list-extension-kinds", Method: http.MethodGet, Path: "/api/extension-kinds",
|
||||
Summary: "List the kinds of extension and the group each belongs to", Tags: []string{"Connectors"},
|
||||
}, listExtensionKinds)
|
||||
for _, k := range extensionKinds() {
|
||||
tags := []string{k.tag}
|
||||
huma.Register(api, huma.Operation{
|
||||
OperationID: "list-" + k.noun + "s", Method: http.MethodGet, Path: k.path,
|
||||
|
||||
Reference in new issue
Block a user