89 lines
3.2 KiB
Go
89 lines
3.2 KiB
Go
package gateway
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/binding"
|
|
"github.com/samcharles93/archie-core/internal/domain/eventtype"
|
|
"github.com/samcharles93/archie-core/internal/tools"
|
|
)
|
|
|
|
// IntegrationSource is what the integration tools read, in the caller's org.
|
|
type IntegrationSource interface {
|
|
Resource(ctx context.Context, kind string) (json.RawMessage, error)
|
|
EventTypes(ctx context.Context) ([]eventtype.EventType, error)
|
|
Bindings(ctx context.Context) ([]binding.Binding, error)
|
|
}
|
|
|
|
// readableKinds are the settings that shape what a workflow can do and what
|
|
// starts it. Provider, channel and connection settings are left out: they
|
|
// carry endpoints and secret references an agent has no use for.
|
|
var readableKinds = []string{
|
|
"workflow-execution-settings", "workflow-enablement", "agent-profiles", "skills",
|
|
"schedules", "eda-playbooks", "credential-bindings", "identity-grants",
|
|
}
|
|
|
|
// IntegrationTools returns read-only tools for investigating what starts
|
|
// workflows and how they can be customised. Nil source registers none.
|
|
func IntegrationTools(source IntegrationSource) []tools.ToolEntry {
|
|
if source == nil {
|
|
return nil
|
|
}
|
|
return []tools.ToolEntry{
|
|
{
|
|
Name: "settings_get",
|
|
Toolset: "workflows",
|
|
Description: "Return one settings document as JSON. Kinds: " + strings.Join(readableKinds, ", ") + ".",
|
|
Classification: tools.ClassIdempotent,
|
|
Schema: tools.JSONSchema{
|
|
"type": "object",
|
|
"properties": map[string]any{"kind": map[string]any{"type": "string", "enum": readableKinds}},
|
|
"required": []any{"kind"},
|
|
},
|
|
Handler: func(ctx context.Context, input map[string]any) (any, error) {
|
|
kind := asString(input["kind"])
|
|
if !slices.Contains(readableKinds, kind) {
|
|
return nil, fmt.Errorf("settings_get: %q is not readable; use one of %s", kind, strings.Join(readableKinds, ", "))
|
|
}
|
|
value, err := source.Resource(ctx, kind)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("settings_get: %w", err)
|
|
}
|
|
return value, nil
|
|
},
|
|
},
|
|
{
|
|
Name: "event_types_list",
|
|
Toolset: "workflows",
|
|
Description: "List the named event types: each one's source, the rule that recognises it and the fields its payload carries.",
|
|
Classification: tools.ClassIdempotent,
|
|
Schema: tools.JSONSchema{"type": "object", "properties": map[string]any{}},
|
|
Handler: func(ctx context.Context, _ map[string]any) (any, error) {
|
|
types, err := source.EventTypes(ctx)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("event_types_list: %w", err)
|
|
}
|
|
return types, nil
|
|
},
|
|
},
|
|
{
|
|
Name: "bindings_list",
|
|
Toolset: "workflows",
|
|
Description: "List the bindings that start workflows from events: what each matches, its filter and the workflow it runs.",
|
|
Classification: tools.ClassIdempotent,
|
|
Schema: tools.JSONSchema{"type": "object", "properties": map[string]any{}},
|
|
Handler: func(ctx context.Context, _ map[string]any) (any, error) {
|
|
bindings, err := source.Bindings(ctx)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("bindings_list: %w", err)
|
|
}
|
|
return bindings, nil
|
|
},
|
|
},
|
|
}
|
|
}
|