feat: expose workflow runtime through HTTP and Go SDK

This commit is contained in:
2026-09-18 06:51:08 +08:00
parent af1ae4cb21
commit b9e4191c6b
50 changed files with 2221 additions and 143 deletions

View File

@@ -0,0 +1,63 @@
package instance
import (
"context"
"encoding/json"
"git.yuntuo.hk/k2safe/orbit/internal/fault"
core "git.yuntuo.hk/k2safe/orbit/model"
"git.yuntuo.hk/k2safe/orbit/platform/auth"
"git.yuntuo.hk/k2safe/orbit/pulse/service"
"time"
)
const AuditAction = "workflows:audit:read"
type OperationSummary struct {
// ID 不可改写的审计记录标识。
ID core.ID `json:"id"`
// WorkflowID 本页授权流程标识。
WorkflowID core.ID `json:"workflow_id"`
// OperationID 服务端管理操作身份,不是调用方原始幂等键。
OperationID core.ID `json:"operation_id"`
// ActorID 实际认证主体标识,不接受请求体自报。
ActorID string `json:"actor_id"`
// Action 管理动作,例如workflow.task.review、workflow.step.retry、workflow.control、workflow.advanced。
Action string `json:"action"`
// CreatedAt 不可变审计创建时间,UTC微秒精度。
CreatedAt time.Time `json:"created_at"`
}
type OperationView struct {
OperationSummary
// Reason 实际提交的操作原因。
Reason string `json:"reason"`
// EvidenceRef 操作证据引用;非核查类操作可能为空。
EvidenceRef string `json:"evidence_ref,omitempty"`
// Before 操作前的受控状态摘要,不包含完整业务输入。
Before json.RawMessage `json:"before"`
// After 操作后摘要、核查声明或关联新激活和任务,不包含凭据秘密。
After json.RawMessage `json:"after"`
}
type OperationPage struct {
// Items 按创建时间及审计ID倒序排列,不返回原因与摘要正文。
Items []OperationSummary `json:"items"`
// NextCursor 必须沿相同流程继续使用,空表示本次已无下一页。
NextCursor string `json:"next_cursor,omitempty"`
}
func (s *Service) ListOperations(ctx context.Context, t auth.Token, id core.ID, in service.HistoryPageInput) (OperationPage, error) {
if in.Limit == 0 {
in.Limit = 20
}
if id.Validate() != nil || in.Limit < 1 || in.Limit > 100 || len(in.Cursor) > 1024 {
return OperationPage{}, fault.Invalid("invalid workflow history query")
}
return s.store.ListOperations(ctx, t, id, in)
}
func (s *Service) GetOperation(ctx context.Context, t auth.Token, id, operation core.ID) (OperationView, error) {
if id.Validate() != nil || operation.Validate() != nil {
return OperationView{}, fault.Invalid("invalid workflow operation identity")
}
return s.store.GetOperation(ctx, t, id, operation)
}