entity

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AssetRefTypeTaskInput      = "task_input"
	AssetRefTypeTaskNode       = "task_node"
	AssetRefTypeTaskResult     = "task_result"
	AssetRefTypeCreativeDetail = "creative_detail"
	AssetRefTypeAdminCatalog   = "admin_catalog"
)

Common ref_type values.

Variables

This section is empty.

Functions

This section is empty.

Types

type AwaitBindingModel

type AwaitBindingModel struct {
	ID int64 `gorm:"primaryKey"`

	TaskID            int64  `gorm:"not null;index"`
	RootTaskID        int64  `gorm:"not null;index"`
	NodeName          string `gorm:"type:varchar(100);not null;index"`
	WorkflowVersionID int64  `gorm:"not null;index"`

	AwaitType string `gorm:"type:varchar(50);not null;index"`
	Source    string `gorm:"type:varchar(50);not null"`
	Status    string `gorm:"type:varchar(30);not null;index"`

	Provider       *string `gorm:"type:varchar(50);index"`
	ProviderTaskID *string `gorm:"type:varchar(255);index"`
	APITaskID      *string `gorm:"type:varchar(255);index"`
	ExternalTaskID *string `gorm:"type:varchar(255);index"`

	SignalName    *string `gorm:"type:varchar(100);index"`
	MessageName   *string `gorm:"type:varchar(100);index"`
	CallbackToken *string `gorm:"type:varchar(255);index"`

	CorrelationJSON datatypes.JSON `gorm:"type:jsonb"`
	ConfigJSON      datatypes.JSON `gorm:"type:jsonb"`

	LastEventID      *string        `gorm:"type:varchar(255);index"`
	LastEventSource  *string        `gorm:"type:varchar(50)"`
	LastEventPayload datatypes.JSON `gorm:"type:jsonb"`

	ResultPayload datatypes.JSON `gorm:"type:jsonb"`
	ErrorMessage  *string        `gorm:"type:text"`

	FallbackPollEnabled bool       `gorm:"not null;default:false"`
	FallbackPollTool    *string    `gorm:"type:varchar(100)"`
	PollAttempts        int        `gorm:"not null;default:0"`
	MaxPollAttempts     int        `gorm:"not null;default:0"`
	LastPolledAt        *time.Time `gorm:"index"`
	NextPollAt          *time.Time `gorm:"index"`

	WaitingStartedAt *time.Time `gorm:"index"`
	TimeoutAt        *time.Time `gorm:"index"`
	CompletedAt      *time.Time `gorm:"index"`
	FailedAt         *time.Time `gorm:"index"`
	CanceledAt       *time.Time `gorm:"index"`

	CreatedAt time.Time
	UpdatedAt time.Time
}

func (AwaitBindingModel) TableName

func (AwaitBindingModel) TableName() string

type StorageObject

type StorageObject struct {
	ID int64 `gorm:"primaryKey" json:"id"`

	Bucket string `gorm:"type:varchar(128);not null;uniqueIndex:uk_storage_object_bucket_key,priority:1" json:"bucket"`
	OSSKey string `gorm:"type:text;not null;uniqueIndex:uk_storage_object_bucket_key,priority:2" json:"oss_key"`
	URL    string `gorm:"type:text;not null;default:''" json:"url"`

	OwnerType string `gorm:"type:varchar(32);not null;index:idx_storage_object_owner,priority:1" json:"owner_type"`
	OwnerID   int64  `gorm:"not null;index:idx_storage_object_owner,priority:2" json:"owner_id"`

	AssetClass string `gorm:"type:varchar(32);not null;index" json:"asset_class"`
	AssetKind  string `gorm:"type:varchar(32);not null;index" json:"asset_kind"`
	Visibility string `gorm:"type:varchar(32);not null;index" json:"visibility"`
	Source     string `gorm:"type:varchar(32);not null;index" json:"source"`

	BusinessType string `gorm:"type:varchar(64);not null;default:'';index" json:"business_type"`
	BusinessID   *int64 `gorm:"index" json:"business_id,omitempty"`
	TaskID       *int64 `gorm:"index" json:"task_id,omitempty"`
	NodeName     string `gorm:"type:varchar(128);not null;default:'';index" json:"node_name"`
	UploadID     string `gorm:"type:varchar(128);not null;default:'';index" json:"upload_id"`

	Status           StorageObjectStatus `gorm:"type:varchar(32);not null;default:'pending';index" json:"status"`
	Protect          bool                `gorm:"not null;default:false;index" json:"protect"`
	RefCount         int                 `gorm:"not null;default:0" json:"ref_count"`
	SizeBytes        int64               `gorm:"not null;default:0" json:"size_bytes"`
	ContentType      string              `gorm:"type:varchar(128);not null;default:''" json:"content_type"`
	SHA256           string              `gorm:"type:varchar(128);not null;default:'';index" json:"sha256"`
	OriginalFilename string              `gorm:"type:varchar(255);not null;default:''" json:"original_filename"`
	RetentionUntil   *time.Time          `gorm:"index" json:"retention_until,omitempty"`
	DeleteAttempts   int                 `gorm:"not null;default:0;index" json:"delete_attempts"`
	LastDeleteError  string              `gorm:"type:text;not null;default:''" json:"last_delete_error"`
	LastDeleteAt     *time.Time          `gorm:"index" json:"last_delete_at,omitempty"`

	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
}

func (StorageObject) TableName

func (StorageObject) TableName() string

type StorageObjectRef

type StorageObjectRef struct {
	ID      int64  `gorm:"primaryKey" json:"id"`
	AssetID int64  `gorm:"not null;index:idx_storage_object_refs_asset" json:"asset_id"`
	RefType string `gorm:"type:varchar(64);not null;index:idx_storage_object_refs_ref,priority:1" json:"ref_type"`
	RefID   int64  `gorm:"not null;index:idx_storage_object_refs_ref,priority:2" json:"ref_id"`
	// RefNode is the workflow node name when ref_type is task_node.
	RefNode     string    `gorm:"type:varchar(128);not null;default:''" json:"ref_node"`
	Role        string    `gorm:"type:varchar(128);not null;default:''" json:"role"`
	OwnerUserID int64     `gorm:"index:idx_storage_object_refs_owner;default:0" json:"owner_user_id"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

StorageObjectRef records explicit references from business entities to assets. Used for deletion-safety checks, cleanup scheduling, and access auditing.

func (StorageObjectRef) TableName

func (StorageObjectRef) TableName() string

type StorageObjectStatus

type StorageObjectStatus string
const (
	StorageObjectStatusPending     StorageObjectStatus = "pending"
	StorageObjectStatusActive      StorageObjectStatus = "active"
	StorageObjectStatusDeleting    StorageObjectStatus = "deleting"
	StorageObjectStatusDeleted     StorageObjectStatus = "deleted"
	StorageObjectStatusQuarantined StorageObjectStatus = "quarantined"
)

type TaskCostTraceModel

type TaskCostTraceModel struct {
	ID int64 `gorm:"primaryKey"`

	TaskID        int64  `gorm:"not null;index"`
	RootTaskID    int64  `gorm:"not null;index"`
	NodeRuntimeID *int64 `gorm:"index"`

	WorkflowName string `gorm:"type:varchar(120);index"`
	NodeName     string `gorm:"type:varchar(100);index"`
	StepName     string `gorm:"type:varchar(100);index"`

	ResourceType string `gorm:"type:varchar(50);not null;index"`
	Provider     string `gorm:"type:varchar(50);not null;index"`
	Model        string `gorm:"type:varchar(120)"`

	ProviderRequestID string `gorm:"type:varchar(255);index"`
	UsageQuantity     float64
	UsageUnit         string  `gorm:"type:varchar(32);not null"`
	UnitPrice         float64 `gorm:"not null;default:0"`
	EstimatedCost     float64 `gorm:"not null;default:0;index"`
	ActualCost        float64 `gorm:"not null;default:0"`
	Currency          string  `gorm:"type:varchar(8);not null;default:'CNY'"`
	Status            string  `gorm:"type:varchar(32);not null;default:'estimated';index"`
	IdempotencyKey    string  `gorm:"type:varchar(255);not null;uniqueIndex"`

	TracePayload datatypes.JSON `gorm:"type:jsonb"`

	CreatedAt time.Time `gorm:"index"`
	UpdatedAt time.Time
}

func (TaskCostTraceModel) TableName

func (TaskCostTraceModel) TableName() string

type TaskEventModel

type TaskEventModel struct {
	ID         int64          `gorm:"primaryKey"`
	TaskID     int64          `gorm:"not null;index"`
	RootTaskID int64          `gorm:"not null;index"`
	Step       string         `gorm:"type:varchar(100);not null"`
	Message    string         `gorm:"type:text;"`
	Error      string         `gorm:"type:text;"`
	Meta       datatypes.JSON `gorm:"type:jsonb"`
	Type       string         `gorm:"type:varchar(100)"`

	Progress  float64
	Level     string
	NodeIndex int
	NodeTotal int

	Grade string `gorm:"type:varchar(16);not null;default:'persistent'"`

	CreatedAt time.Time `gorm:"index"`
}

func (TaskEventModel) TableName

func (TaskEventModel) TableName() string

type TaskModel

type TaskModel struct {
	ID     int64 `gorm:"primaryKey"`
	UserID int64 `gorm:"index;not null"`

	// 当前任务属于哪个工作流模版
	WorkflowDefinitionID int64

	Type   string `gorm:"type:varchar(100);not null"`
	Status string `gorm:"type:varchar(30);not null;index"`

	InputJSON  datatypes.JSON `gorm:"type:jsonb"`
	OutputJSON datatypes.JSON `gorm:"type:jsonb"`

	ParentID *int64 `gorm:"index"`
	RootID   int64  `gorm:"index"`

	RetryCount   int     `gorm:"not null;default:0"`
	ErrorMessage *string `gorm:"type:text"`

	// WorkflowVersionID 表示当前使用的那个版本的工作流,对应WorkflowVersion表
	WorkflowVersionID int64 `gorm:"index"`

	// 任务抢占字段
	WorkerID  string
	StartedAt time.Time

	SubKey     *string `gorm:"type:varchar(255);uniqueIndex"` // 恢复子工作流的key
	ParentNode *string `json:"parent_node"`                   // 当前任务所属的父节点
	MapIndex   *int    `json:"-"`                             // 在 map node 中执行的位置

	Progress float64 `json:"progress"` // 任务进度

	BaseRunID  int64   `gorm:"index"`
	ForkedFrom *int64  `gorm:"index"`
	RunDepth   int     `gorm:"not null;default:0"`
	EditAction *string `gorm:"type:varchar(64);index"`
	EditLabel  *string `gorm:"type:varchar(255)"`

	// ===== patch / resume =====
	ResumeFrom *string        // 本次 fork 从哪个节点开始恢复
	PatchJSON  datatypes.JSON `gorm:"type:jsonb"` // []RuntimePatch 的 JSON

	// ===== 业务归属字段 =====
	EntryType         string `json:"entry_type"` // tool / template / workflow
	ToolDefinitionID  *int64 `json:"tool_definition_id"`
	ToolModeID        *int64 `json:"tool_mode_id"`
	ToolModeVersionID *int64 `json:"tool_mode_version_id"`
	TemplateID        *int64 `json:"template_id"`
	TemplateVersionID *int64 `json:"template_version_id"`

	// 展示冗余字段(方便列表页直出)
	EntryTitle    *string `json:"entry_title"`    // 比如“视频生成”
	EntrySubtitle *string `json:"entry_subtitle"` // 比如“图生视频”
	RouteKey      *string `json:"route_key"`      // video_generation
	ModeKey       *string `json:"mode_key"`       // image_to_video

	EstimatedCostTotal float64 `gorm:"not null;default:0"`
	ActualCostTotal    float64 `gorm:"not null;default:0"`
	CostStatus         string  `gorm:"type:varchar(32);not null;default:'none'"`

	CreatedAt time.Time
	UpdatedAt time.Time
}

TaskModel 任务实例 每一次运行工作流,都会产生一个 Task。

func (TaskModel) TableName

func (TaskModel) TableName() string

type TaskNodeModel

type TaskNodeModel struct {
	ID       int64  `gorm:"primaryKey"`
	TaskID   int64  `gorm:"not null;index;uniqueIndex:uniq_task_node"`
	NodeName string `gorm:"type:varchar(100);not null;uniqueIndex:uniq_task_node"`
	State    string `gorm:"type:varchar(30);not null;index:idx_state_heartbeat"`

	StartedAt  *time.Time
	FinishedAt *time.Time
	Error      *string `gorm:"type:text"`

	LastHeartbeat  *time.Time     `gorm:"index:idx_state_heartbeat"` // 节点心跳时间, idx_state_heartbeat联合索引(state,state_heartbeat)
	OutputJSON     datatypes.JSON `gorm:"type:jsonb"`                // 存储该节点的输出结果
	InputHash      string         `gorm:"type:text"`                 // 存储上次执行成功时的“指纹”
	CheckpointJSON datatypes.JSON `gorm:"type:jsonb"`
	Index          int
	BizIndex       int
	Weight         float64 `gorm:"type:float"` // 节点权重0~1

	ActivatedEdgesJSON []byte `json:"activated_edges_json"` // 存储已经激活的边

	CreatedAt time.Time
	UpdatedAt time.Time

	// ===== 新增 =====
	OutputHash       string  `gorm:"type:text"`
	ReusedFromTaskID *int64  `gorm:"index"`
	ReusedFromNode   *string `gorm:"type:varchar(100)"`
	IsInjected       bool    `gorm:"not null;default:false"`
	IsDirty          bool    `gorm:"not null;default:false;index"`
	DirtyReason      *string `gorm:"type:varchar(64)"`
	CheckpointedAt   *time.Time
	ReuseKind        string `json:"reuse_kind"`
}

TaskNodeModel 任务运行时的节点

func (TaskNodeModel) TableName

func (TaskNodeModel) TableName() string

type WorkflowModel

type WorkflowModel struct {
	ID          int64 `gorm:"primaryKey"`
	UserID      *int64
	Name        string
	Description string
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

WorkflowModel 表示一个逻辑工作流

func (WorkflowModel) TableName

func (WorkflowModel) TableName() string

type WorkflowVersionModel

type WorkflowVersionModel struct {
	ID         int64 `gorm:"primaryKey"`
	WorkflowID int64
	Version    int64
	// Definition 表示一个 WorkflowModel
	// {
	//  "nodes": [
	//    {
	//      "id": "start",
	//      "type": "start"
	//    },
	//    {
	//      "id": "llm1",
	//      "type": "llm",
	//      "depends": ["start"],
	//      "config": {
	//          "model":"gpt4",
	//          "prompt":"写一个视频脚本"
	//      }
	//    }
	//  ]
	//}
	DefinitionJSON datatypes.JSON `gorm:"type:jsonb"`
	Hash           string         `gorm:"type:varchar(64)"`
	CreatedAt      time.Time
}

WorkflowVersionModel 表示这个工作流某个发布版本的执行快照

func (WorkflowVersionModel) TableName

func (WorkflowVersionModel) TableName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL