The Web UI and messaging channels now read and write Archie's runtime settings through one versioned, audited control-plane API hosted on the State Store's existing gRPC server: catalog, query, command, watch. Each feature owns its resource, validation and commands; storage only writes versions and audit records. Workflows move with it. Definitions become portable YAML compiled through a closed, typed step registry and stored as a control-plane resource, so the yaegi interpretation paths (internal/gate, wfeval, wfextract, gateeval, gateextract, skillbuild) are deleted rather than carried. The UI process reads definitions as data: the JSON projection lives in internal/domain/workflow/task so a dashboard decodes the stored collection without linking the workflow engine, which cmd/archie-ui's deletion gate forbids. Shipped definitions ride the catalog descriptor rather than a bespoke REST route, keeping the API to its four operations. archie-messaging gains -state-store-target/-state-store-token and reads channel settings from the database, failing closed when the State Store is unreachable: the database is authoritative for those settings.
70 lines
2.7 KiB
Go
70 lines
2.7 KiB
Go
package controlplane
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
"github.com/samcharles93/archie-core/internal/store"
|
|
)
|
|
|
|
const WorkflowExecutionSettingsKind = "workflow-execution-settings"
|
|
|
|
type executionSettingsDocument struct {
|
|
MaxModelToolSteps int `json:"max_model_tool_steps"`
|
|
MaxRuntimeSeconds int64 `json:"max_runtime_seconds"`
|
|
MaxConsecutiveGateFailures int `json:"max_consecutive_gate_failures"`
|
|
}
|
|
|
|
// ImportWorkflowExecutionSettings preserves the focused bootstrap API for callers
|
|
// that do not own the complete legacy configuration document.
|
|
func (s *Server) ImportWorkflowExecutionSettings(ctx context.Context, settings workflow.ExecutionSettings) (int64, error) {
|
|
resource, err := s.store.Resource(ctx, WorkflowExecutionSettingsKind)
|
|
if err == nil {
|
|
return resource.Version, nil
|
|
}
|
|
if !errors.Is(err, store.ErrResourceNotFound) {
|
|
return 0, err
|
|
}
|
|
value, err := encodeSettings(settings)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
value, err = workflowDefinition().Decode(value)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
resource, err = s.store.PutResource(ctx, store.ResourceWrite{Kind: WorkflowExecutionSettingsKind, Value: value, Actor: "system:migration", Source: "legacy-config", RequestID: "import:" + WorkflowExecutionSettingsKind, ExpectedVersion: 0, At: time.Now().UTC()})
|
|
return resource.Version, err
|
|
}
|
|
|
|
func workflowDefinition() Definition {
|
|
return Definition{
|
|
Kind: WorkflowExecutionSettingsKind, Title: "Workflow execution settings", ApplyMode: "live", Schema: objectSchema,
|
|
Seed: func(cfg config.Config) any {
|
|
return executionSettingsDocument{cfg.Budgets.MaxSteps, int64(time.Duration(cfg.Budgets.WallClock) / time.Second), cfg.Budgets.GateMaxFailures}
|
|
},
|
|
Validate: func(input []byte) error { _, err := decodeSettings(input); return err },
|
|
}
|
|
}
|
|
|
|
func encodeSettings(s workflow.ExecutionSettings) ([]byte, error) {
|
|
return json.Marshal(executionSettingsDocument{s.MaxModelToolSteps, int64(s.MaxRuntime / time.Second), s.MaxConsecutiveGateFailures})
|
|
}
|
|
|
|
func decodeSettings(value []byte) (workflow.ExecutionSettings, error) {
|
|
var document executionSettingsDocument
|
|
if err := json.Unmarshal(value, &document); err != nil {
|
|
return workflow.ExecutionSettings{}, fmt.Errorf("%w: invalid JSON: %w", ErrValidation, err)
|
|
}
|
|
settings := workflow.ExecutionSettings{MaxModelToolSteps: document.MaxModelToolSteps, MaxRuntime: time.Duration(document.MaxRuntimeSeconds) * time.Second, MaxConsecutiveGateFailures: document.MaxConsecutiveGateFailures}
|
|
if err := settings.Validate(); err != nil {
|
|
return workflow.ExecutionSettings{}, fmt.Errorf("%w: %w", ErrValidation, err)
|
|
}
|
|
return settings, nil
|
|
}
|