-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow.go
More file actions
62 lines (56 loc) · 1.79 KB
/
workflow.go
File metadata and controls
62 lines (56 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package engine
import (
"encoding/json"
"fmt"
"github.com/LAA-Software-Engineering/agentic-control-plane/internal/schema"
"github.com/LAA-Software-Engineering/agentic-control-plane/internal/spec"
)
func lookupWorkflow(g *spec.ProjectGraph, name string) (*spec.WorkflowResource, error) {
if g == nil || g.Workflows == nil {
return nil, fmt.Errorf("engine: unknown workflow %q", name)
}
wf, ok := g.Workflows[name]
if !ok || wf == nil {
return nil, fmt.Errorf("engine: unknown workflow %q", name)
}
return wf, nil
}
// ValidateWorkflowInput validates input against the workflow's input.schema when configured.
func ValidateWorkflowInput(projectRoot string, wf *spec.WorkflowResource, input map[string]any) error {
return validateWorkflowInput(projectRoot, wf, input)
}
func validateWorkflowInput(projectRoot string, wf *spec.WorkflowResource, input map[string]any) error {
if wf == nil || wf.Spec.Input == nil {
return nil
}
sref := wf.Spec.Input.Schema
if sref == "" {
return nil
}
path, err := schema.ResolveSchemaPath(projectRoot, sref)
if err != nil {
return fmt.Errorf("engine: workflow input schema: %w", err)
}
raw, err := json.Marshal(input)
if err != nil {
return fmt.Errorf("engine: marshal workflow input: %w", err)
}
if err := schema.Validate(path, raw); err != nil {
return fmt.Errorf("engine: workflow input: %w", err)
}
return nil
}
func buildWorkflowOutput(wf *spec.WorkflowResource, ictx Context) (map[string]any, error) {
if wf == nil || wf.Spec.Output == nil || wf.Spec.Output.Value == nil {
return map[string]any{}, nil
}
v, err := InterpolateWalk(wf.Spec.Output.Value, ictx)
if err != nil {
return nil, err
}
out, ok := v.(map[string]any)
if !ok {
return nil, fmt.Errorf("engine: workflow output value must interpolate to an object")
}
return out, nil
}