d1f39ae57e
- Added ConfigSchema, InputSchema, OutputSchema, and DefaultInputs to AIWorkflowNodeSpecResponse. - Implemented BuildAIWorkflowNodeSpecs to include variable contracts for start and send_reply nodes. - Introduced applyAutoInputMappings to automatically map inputs based on node connections. - Enhanced validation to check for required input mappings in workflows. - Updated workflow editor to support variable selection for node inputs. - Translated node names and labels to Chinese for better localization. - Added tests for variable mapping and validation logic.
80 lines
2.5 KiB
Go
80 lines
2.5 KiB
Go
package registry
|
|
|
|
import "agent-desk/internal/ai/workflow/dsl"
|
|
|
|
type NodeRiskLevel string
|
|
|
|
const (
|
|
NodeRiskLevelLow NodeRiskLevel = "low"
|
|
NodeRiskLevelMedium NodeRiskLevel = "medium"
|
|
NodeRiskLevelHigh NodeRiskLevel = "high"
|
|
)
|
|
|
|
type VariableType string
|
|
|
|
const (
|
|
VariableTypeString VariableType = "string"
|
|
VariableTypeInteger VariableType = "integer"
|
|
VariableTypeBoolean VariableType = "boolean"
|
|
VariableTypeObject VariableType = "object"
|
|
VariableTypeStringArray VariableType = "array<string>"
|
|
VariableTypeIntegerArray VariableType = "array<int>"
|
|
VariableTypeObjectArray VariableType = "array<object>"
|
|
VariableTypeAny VariableType = "any"
|
|
)
|
|
|
|
type VariableSpec struct {
|
|
Name string `json:"name"`
|
|
Type VariableType `json:"type"`
|
|
Required bool `json:"required,omitempty"`
|
|
Description string `json:"description"`
|
|
}
|
|
|
|
type NodeSpec struct {
|
|
Type string `json:"type"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
RiskLevel NodeRiskLevel `json:"riskLevel"`
|
|
Interruptible bool `json:"interruptible"`
|
|
RequiresConfirmationPredecessor bool `json:"requiresConfirmationPredecessor"`
|
|
ConfigSchema any `json:"configSchema,omitempty"`
|
|
InputSchema []VariableSpec `json:"inputSchema,omitempty"`
|
|
OutputSchema []VariableSpec `json:"outputSchema,omitempty"`
|
|
DefaultInputs map[string]dsl.VariableSelector `json:"defaultInputs,omitempty"`
|
|
}
|
|
|
|
type Registry struct {
|
|
specsByType map[string]NodeSpec
|
|
specs []NodeSpec
|
|
}
|
|
|
|
func NewRegistry(specs ...NodeSpec) *Registry {
|
|
ret := &Registry{
|
|
specsByType: make(map[string]NodeSpec, len(specs)),
|
|
specs: make([]NodeSpec, 0, len(specs)),
|
|
}
|
|
for _, spec := range specs {
|
|
if spec.Type == "" {
|
|
continue
|
|
}
|
|
ret.specsByType[spec.Type] = spec
|
|
ret.specs = append(ret.specs, spec)
|
|
}
|
|
return ret
|
|
}
|
|
|
|
func (r *Registry) Get(nodeType string) (NodeSpec, bool) {
|
|
if r == nil {
|
|
return NodeSpec{}, false
|
|
}
|
|
spec, ok := r.specsByType[nodeType]
|
|
return spec, ok
|
|
}
|
|
|
|
func (r *Registry) List() []NodeSpec {
|
|
if r == nil {
|
|
return nil
|
|
}
|
|
return append([]NodeSpec(nil), r.specs...)
|
|
}
|