Merge branch 'worktree-agent-a773715d74288076a'

This commit is contained in:
sam committed 2026-11-21 14:59:56 +11:00
commit ca279a200a
6 files changed
+178 -26

No files matched your search

@@ -46,6 +46,44 @@ 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 known contract with its group. Upsert refuses any
// contract not in this table, so every stored package has a group.
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, or "" for an unknown one.
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"`
@@ -75,6 +113,9 @@ func (s *Store) List(ctx context.Context, orgID string) ([]Accepted, error) {
// Upsert records an accepted connector, replacing an earlier acceptance.
func (s *Store) Upsert(ctx context.Context, a Accepted) error {
if GroupOf(a.Contract) == "" {
return fmt.Errorf("accept %q: unknown contract %q", a.Name, a.Contract)
}
if _, err := s.db.NamedExecContext(ctx, `
INSERT INTO connectors.accepted (org_id, name, path, sha256, egress, env, settings, contract, credentials, args, url, tools)
VALUES (:org_id, :name, :path, :sha256, :egress, :env, :settings, :contract, :credentials, :args, :url, :tools)
+2 -1
View File
@@ -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{},
}
+40 -8
View File
@@ -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,