Files
poimen-workflows/pkg/db/models.go
T
Test 0da90fdd7a
ci / test (push) Failing after 2m11s
feat: database layer + canvas validator/converter + LLM inference activities
- Add pkg/db models and CRUD methods for workflows
- Add internal/routing canvas validator (DAG check, connectivity)
- Add internal/routing canvas converter (Canvas → WorkflowSpec)
- Register LLMInferenceActivity and LLMBatchInferenceActivity
- Update api/server and cmd/server with database integration
- Add K8s environment variable support
- Update activity knowledge base with LLM activities
- Add .env.example configuration template
2026-09-05 00:43:30 -07:00

114 lines
4.3 KiB
Go

package db
import (
"time"
)
// WorkflowNode represents a React Flow node in the canvas
type WorkflowNode struct {
ID string `json:"id"`
Label string `json:"label"`
Type string `json:"type"` // "activity"
Position map[string]interface{} `json:"position"`
Data map[string]interface{} `json:"data"`
}
// WorkflowEdge represents a React Flow edge in the canvas
type WorkflowEdge struct {
ID string `json:"id"`
Source string `json:"source"`
Target string `json:"target"`
Data map[string]interface{} `json:"data"`
}
// Canvas represents the full React Flow canvas (nodes + edges)
type Canvas struct {
Nodes []WorkflowNode `json:"nodes"`
Edges []WorkflowEdge `json:"edges"`
}
// Workflow represents a workflow definition in the database
type Workflow struct {
ID string `db:"id"`
CustomerID string `db:"customer_id"`
Name string `db:"name"`
Description string `db:"description"`
Status string `db:"status"` // "draft", "active", "archived"
Version int `db:"version"`
Nodes []byte `db:"nodes"` // JSONB stored as []byte
Edges []byte `db:"edges"` // JSONB stored as []byte
CreatedBy string `db:"created_by"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
LastExecutedAt *time.Time `db:"last_executed_at"`
}
// WorkflowExecution represents a workflow execution run
type WorkflowExecution struct {
ID string `db:"id"`
WorkflowID string `db:"workflow_id"`
CustomerID string `db:"customer_id"`
TemporalID string `db:"temporal_id"` // Temporal execution ID
Status string `db:"status"` // "pending", "running", "success", "failed", "cancelled"
Inputs []byte `db:"inputs"` // JSONB
Outputs []byte `db:"outputs"` // JSONB
StartedAt time.Time `db:"started_at"`
CompletedAt *time.Time `db:"completed_at"`
DurationMs *int `db:"duration_ms"`
ErrorMessage string `db:"error_message"`
ErrorCount int `db:"error_count"`
}
// ExecutionLog represents a detailed activity log entry
type ExecutionLog struct {
ID int64 `db:"id"`
ExecutionID string `db:"execution_id"`
NodeID string `db:"node_id"` // From canvas node ID
ActivityName string `db:"activity_name"` // "CloneRepo", "AnalyzeCode", etc
Level string `db:"level"` // "info", "warn", "error", "debug"
Message string `db:"message"`
Metadata []byte `db:"metadata"` // JSONB
LoggedAt time.Time `db:"logged_at"`
}
// ActivityTrace represents per-activity execution metrics
type ActivityTrace struct {
ID int64 `db:"id"`
ExecutionID string `db:"execution_id"`
NodeID string `db:"node_id"`
ActivityName string `db:"activity_name"`
Parameters []byte `db:"parameters"` // JSONB
Result []byte `db:"result"` // JSONB
StartedAt time.Time `db:"started_at"`
CompletedAt *time.Time `db:"completed_at"`
DurationMs *int `db:"duration_ms"`
Attempt int `db:"attempt"`
RetryReason string `db:"retry_reason"`
Status string `db:"status"` // "running", "success", "failed", "skipped"
ErrorMessage string `db:"error_message"`
}
// WorkflowStats represents aggregated workflow metrics
type WorkflowStats struct {
WorkflowID string `db:"workflow_id"`
CustomerID string `db:"customer_id"`
TotalRuns int `db:"total_runs"`
SuccessfulRuns int `db:"successful_runs"`
FailedRuns int `db:"failed_runs"`
AvgDurationMs float64 `db:"avg_duration_ms"`
MinDurationMs *int `db:"min_duration_ms"`
MaxDurationMs *int `db:"max_duration_ms"`
Last30dRuns int `db:"last_30d_runs"`
Last30dSuccessRate float64 `db:"last_30d_success_rate"`
UpdatedAt time.Time `db:"updated_at"`
}
// WorkflowMemoryLink represents a connection between execution and memory nodes
type WorkflowMemoryLink struct {
ExecutionID string `db:"execution_id"`
MemoryNodeSha string `db:"memory_node_sha"`
Relationship string `db:"relationship"` // "generated", "used", "learned", "failed_on"
CreatedAt time.Time `db:"created_at"`
Notes string `db:"notes"`
}