feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
634
backend/domain/workflow/entity/vo/canvas.go
Normal file
634
backend/domain/workflow/entity/vo/canvas.go
Normal file
@@ -0,0 +1,634 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package vo
|
||||
|
||||
import (
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/crossdomain/model"
|
||||
)
|
||||
|
||||
type Canvas struct {
|
||||
Nodes []*Node `json:"nodes"`
|
||||
Edges []*Edge `json:"edges"`
|
||||
Versions any `json:"versions"`
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
ID string `json:"id"`
|
||||
Type BlockType `json:"type"`
|
||||
Meta any `json:"meta"`
|
||||
Data *Data `json:"data"`
|
||||
Blocks []*Node `json:"blocks,omitempty"`
|
||||
Edges []*Edge `json:"edges,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
|
||||
parent *Node
|
||||
}
|
||||
|
||||
func (n *Node) SetParent(parent *Node) {
|
||||
n.parent = parent
|
||||
}
|
||||
|
||||
func (n *Node) Parent() *Node {
|
||||
return n.parent
|
||||
}
|
||||
|
||||
type NodeMeta struct {
|
||||
Title string `json:"title,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
SubTitle string `json:"subTitle,omitempty"`
|
||||
MainColor string `json:"mainColor,omitempty"`
|
||||
}
|
||||
|
||||
type Edge struct {
|
||||
SourceNodeID string `json:"sourceNodeID"`
|
||||
TargetNodeID string `json:"targetNodeID"`
|
||||
SourcePortID string `json:"sourcePortID,omitempty"`
|
||||
TargetPortID string `json:"targetPortID,omitempty"`
|
||||
}
|
||||
|
||||
type Data struct {
|
||||
Meta *NodeMeta `json:"nodeMeta,omitempty"`
|
||||
Outputs []any `json:"outputs,omitempty"` // either []*Variable or []*Param
|
||||
Inputs *Inputs `json:"inputs,omitempty"`
|
||||
Size any `json:"size,omitempty"`
|
||||
}
|
||||
|
||||
type Inputs struct {
|
||||
InputParameters []*Param `json:"inputParameters"`
|
||||
Content *BlockInput `json:"content"`
|
||||
TerminatePlan *TerminatePlan `json:"terminatePlan,omitempty"`
|
||||
StreamingOutput bool `json:"streamingOutput,omitempty"`
|
||||
CallTransferVoice bool `json:"callTransferVoice,omitempty"`
|
||||
ChatHistoryWriting string `json:"chatHistoryWriting,omitempty"`
|
||||
LLMParam any `json:"llmParam,omitempty"` // The LLMParam type may be one of the LLMParam or IntentDetectorLLMParam type or QALLMParam type
|
||||
FCParam *FCParam `json:"fcParam,omitempty"`
|
||||
SettingOnError *SettingOnError `json:"settingOnError,omitempty"`
|
||||
|
||||
LoopType LoopType `json:"loopType,omitempty"`
|
||||
LoopCount *BlockInput `json:"loopCount,omitempty"`
|
||||
VariableParameters []*Param `json:"variableParameters,omitempty"`
|
||||
|
||||
Branches []*struct {
|
||||
Condition struct {
|
||||
Logic LogicType `json:"logic"`
|
||||
Conditions []*Condition `json:"conditions"`
|
||||
} `json:"condition"`
|
||||
} `json:"branches,omitempty"`
|
||||
|
||||
NodeBatchInfo *NodeBatch `json:"batch,omitempty"` // node in batch mode
|
||||
|
||||
*TextProcessor
|
||||
*SubWorkflow
|
||||
*IntentDetector
|
||||
*DatabaseNode
|
||||
*HttpRequestNode
|
||||
*KnowledgeIndexer
|
||||
*CodeRunner
|
||||
*PluginAPIParam
|
||||
*VariableAggregator
|
||||
*VariableAssigner
|
||||
*QA
|
||||
*Batch
|
||||
*Comment
|
||||
|
||||
OutputSchema string `json:"outputSchema,omitempty"`
|
||||
}
|
||||
|
||||
type Comment struct {
|
||||
SchemaType string `json:"schemaType,omitempty"`
|
||||
Note any `json:"note,omitempty"`
|
||||
}
|
||||
|
||||
type TextProcessor struct {
|
||||
Method TextProcessingMethod `json:"method,omitempty"`
|
||||
ConcatParams []*Param `json:"concatParams,omitempty"`
|
||||
SplitParams []*Param `json:"splitParams,omitempty"`
|
||||
}
|
||||
|
||||
type VariableAssigner struct {
|
||||
VariableTypeMap map[string]any `json:"variableTypeMap,omitempty"`
|
||||
}
|
||||
|
||||
type LLMParam = []*Param
|
||||
type IntentDetectorLLMParam = map[string]any
|
||||
type QALLMParam struct {
|
||||
GenerationDiversity string `json:"generationDiversity"`
|
||||
MaxTokens int `json:"maxTokens"`
|
||||
ModelName string `json:"modelName"`
|
||||
ModelType int64 `json:"modelType"`
|
||||
ResponseFormat model.ResponseFormat `json:"responseFormat"`
|
||||
SystemPrompt string `json:"systemPrompt"`
|
||||
Temperature float64 `json:"temperature"`
|
||||
TopP float64 `json:"topP"`
|
||||
}
|
||||
|
||||
type QA struct {
|
||||
AnswerType QAAnswerType `json:"answer_type"`
|
||||
Limit int `json:"limit,omitempty"`
|
||||
ExtractOutput bool `json:"extra_output,omitempty"`
|
||||
OptionType QAOptionType `json:"option_type,omitempty"`
|
||||
Options []struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"options,omitempty"`
|
||||
Question string `json:"question,omitempty"`
|
||||
DynamicOption *BlockInput `json:"dynamic_option,omitempty"`
|
||||
}
|
||||
|
||||
type QAAnswerType string
|
||||
|
||||
const (
|
||||
QAAnswerTypeOption QAAnswerType = "option"
|
||||
QAAnswerTypeText QAAnswerType = "text"
|
||||
)
|
||||
|
||||
type QAOptionType string
|
||||
|
||||
const (
|
||||
QAOptionTypeStatic QAOptionType = "static"
|
||||
QAOptionTypeDynamic QAOptionType = "dynamic"
|
||||
)
|
||||
|
||||
type RequestParameter struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
type FCParam struct {
|
||||
WorkflowFCParam *struct {
|
||||
WorkflowList []struct {
|
||||
WorkflowID string `json:"workflow_id"`
|
||||
WorkflowVersion string `json:"workflow_version"`
|
||||
PluginID string `json:"plugin_id"`
|
||||
PluginVersion string `json:"plugin_version"`
|
||||
IsDraft bool `json:"is_draft"`
|
||||
FCSetting *struct {
|
||||
RequestParameters []*workflow.APIParameter `json:"request_params"`
|
||||
ResponseParameters []*workflow.APIParameter `json:"response_params"`
|
||||
} `json:"fc_setting,omitempty"`
|
||||
} `json:"workflowList,omitempty"`
|
||||
} `json:"workflowFCParam,omitempty"`
|
||||
PluginFCParam *struct {
|
||||
PluginList []struct {
|
||||
PluginID string `json:"plugin_id"`
|
||||
ApiId string `json:"api_id"`
|
||||
ApiName string `json:"api_name"`
|
||||
PluginVersion string `json:"plugin_version"`
|
||||
IsDraft bool `json:"is_draft"`
|
||||
FCSetting *struct {
|
||||
RequestParameters []*workflow.APIParameter `json:"request_params"`
|
||||
ResponseParameters []*workflow.APIParameter `json:"response_params"`
|
||||
} `json:"fc_setting,omitempty"`
|
||||
}
|
||||
} `json:"pluginFCParam,omitempty"`
|
||||
|
||||
KnowledgeFCParam *struct {
|
||||
GlobalSetting *struct {
|
||||
SearchMode int64 `json:"search_mode"`
|
||||
TopK int64 `json:"top_k"`
|
||||
MinScore float64 `json:"min_score"`
|
||||
UseNL2SQL bool `json:"use_nl2_sql"`
|
||||
UseRewrite bool `json:"use_rewrite"`
|
||||
UseRerank bool `json:"use_rerank"`
|
||||
NoRecallReplyCustomizePrompt string `json:"no_recall_reply_customize_prompt"`
|
||||
NoRecallReplyMode int64 `json:"no_recall_reply_mode"`
|
||||
} `json:"global_setting,omitempty"`
|
||||
KnowledgeList []*struct {
|
||||
ID string `json:"id"`
|
||||
} `json:"knowledgeList,omitempty"`
|
||||
} `json:"knowledgeFCParam,omitempty"`
|
||||
}
|
||||
|
||||
type Batch struct {
|
||||
BatchSize *BlockInput `json:"batchSize,omitempty"`
|
||||
ConcurrentSize *BlockInput `json:"concurrentSize,omitempty"`
|
||||
}
|
||||
|
||||
type NodeBatch struct {
|
||||
BatchEnable bool `json:"batchEnable"`
|
||||
BatchSize int64 `json:"batchSize"`
|
||||
ConcurrentSize int64 `json:"concurrentSize"`
|
||||
InputLists []*Param `json:"inputLists,omitempty"`
|
||||
}
|
||||
|
||||
type IntentDetectorLLMConfig struct {
|
||||
ModelName string `json:"modelName"`
|
||||
ModelType int `json:"modelType"`
|
||||
Temperature *float64 `json:"temperature"`
|
||||
TopP *float64 `json:"topP"`
|
||||
MaxTokens int `json:"maxTokens"`
|
||||
ResponseFormat int64 `json:"responseFormat"`
|
||||
SystemPrompt BlockInput `json:"systemPrompt"`
|
||||
}
|
||||
|
||||
type VariableAggregator struct {
|
||||
MergeGroups []*Param `json:"mergeGroups,omitempty"`
|
||||
}
|
||||
|
||||
type PluginAPIParam struct {
|
||||
APIParams []*Param `json:"apiParam"`
|
||||
}
|
||||
|
||||
type CodeRunner struct {
|
||||
Code string `json:"code"`
|
||||
Language int64 `json:"language"`
|
||||
}
|
||||
|
||||
type KnowledgeIndexer struct {
|
||||
DatasetParam []*Param `json:"datasetParam,omitempty"`
|
||||
StrategyParam StrategyParam `json:"strategyParam,omitempty"`
|
||||
}
|
||||
|
||||
type StrategyParam struct {
|
||||
ParsingStrategy struct {
|
||||
ParsingType string `json:"parsingType,omitempty"`
|
||||
ImageExtraction bool `json:"imageExtraction"`
|
||||
TableExtraction bool `json:"tableExtraction"`
|
||||
ImageOcr bool `json:"imageOcr"`
|
||||
} `json:"parsingStrategy,omitempty"`
|
||||
ChunkStrategy struct {
|
||||
ChunkType string `json:"chunkType,omitempty"`
|
||||
SeparatorType string `json:"separatorType,omitempty"`
|
||||
Separator string `json:"separator,omitempty"`
|
||||
MaxToken int64 `json:"maxToken,omitempty"`
|
||||
Overlap float64 `json:"overlap,omitempty"`
|
||||
} `json:"chunkStrategy,omitempty"`
|
||||
IndexStrategy any `json:"indexStrategy"`
|
||||
}
|
||||
|
||||
type HttpRequestNode struct {
|
||||
APIInfo APIInfo `json:"apiInfo,omitempty"`
|
||||
Body Body `json:"body,omitempty"`
|
||||
Headers []*Param `json:"headers"`
|
||||
Params []*Param `json:"params"`
|
||||
Auth *Auth `json:"auth"`
|
||||
Setting *HttpRequestSetting `json:"setting"`
|
||||
}
|
||||
|
||||
type APIInfo struct {
|
||||
Method string `json:"method"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
type Body struct {
|
||||
BodyType string `json:"bodyType"`
|
||||
BodyData *BodyData `json:"bodyData"`
|
||||
}
|
||||
type BodyData struct {
|
||||
Json string `json:"json,omitempty"`
|
||||
FormData *struct {
|
||||
Data []*Param `json:"data"`
|
||||
} `json:"formData,omitempty"`
|
||||
FormURLEncoded []*Param `json:"formURLEncoded,omitempty"`
|
||||
RawText string `json:"rawText,omitempty"`
|
||||
Binary struct {
|
||||
FileURL *BlockInput `json:"fileURL"`
|
||||
} `json:"binary"`
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
AuthType string `json:"authType"`
|
||||
AuthData struct {
|
||||
CustomData struct {
|
||||
AddTo string `json:"addTo"`
|
||||
Data []*Param `json:"data,omitempty"`
|
||||
} `json:"customData"`
|
||||
BearerTokenData []*Param `json:"bearerTokenData,omitempty"`
|
||||
} `json:"authData"`
|
||||
|
||||
AuthOpen bool `json:"authOpen"`
|
||||
}
|
||||
|
||||
type HttpRequestSetting struct {
|
||||
Timeout int64 `json:"timeout"`
|
||||
RetryTimes int64 `json:"retryTimes"`
|
||||
}
|
||||
|
||||
type DatabaseNode struct {
|
||||
DatabaseInfoList []*DatabaseInfo `json:"databaseInfoList,omitempty"`
|
||||
SQL string `json:"sql,omitempty"`
|
||||
SelectParam *SelectParam `json:"selectParam,omitempty"`
|
||||
|
||||
InsertParam *InsertParam `json:"insertParam,omitempty"`
|
||||
|
||||
DeleteParam *DeleteParam `json:"deleteParam,omitempty"`
|
||||
|
||||
UpdateParam *UpdateParam `json:"updateParam,omitempty"`
|
||||
}
|
||||
|
||||
type DatabaseLogicType string
|
||||
|
||||
const (
|
||||
DatabaseLogicAnd DatabaseLogicType = "AND"
|
||||
DatabaseLogicOr DatabaseLogicType = "OR"
|
||||
)
|
||||
|
||||
type DBCondition struct {
|
||||
ConditionList [][]*Param `json:"conditionList,omitempty"`
|
||||
Logic DatabaseLogicType `json:"logic"`
|
||||
}
|
||||
|
||||
type UpdateParam struct {
|
||||
Condition DBCondition `json:"condition"`
|
||||
FieldInfo [][]*Param `json:"fieldInfo"`
|
||||
}
|
||||
|
||||
type DeleteParam struct {
|
||||
Condition DBCondition `json:"condition"`
|
||||
}
|
||||
|
||||
type InsertParam struct {
|
||||
FieldInfo [][]*Param `json:"fieldInfo"`
|
||||
}
|
||||
|
||||
type SelectParam struct {
|
||||
Condition *DBCondition `json:"condition,omitempty"` // may be nil
|
||||
OrderByList []struct {
|
||||
FieldID int64 `json:"fieldID"`
|
||||
IsAsc bool `json:"isAsc"`
|
||||
} `json:"orderByList,omitempty"`
|
||||
Limit int64 `json:"limit"`
|
||||
FieldList []struct {
|
||||
FieldID int64 `json:"fieldID"`
|
||||
IsDistinct bool `json:"isDistinct"`
|
||||
} `json:"fieldList,omitempty"`
|
||||
}
|
||||
|
||||
type DatabaseInfo struct {
|
||||
DatabaseInfoID string `json:"databaseInfoID"`
|
||||
}
|
||||
|
||||
type IntentDetector struct {
|
||||
ChatHistorySetting *ChatHistorySetting `json:"chatHistorySetting,omitempty"`
|
||||
Intents []*Intent `json:"intents,omitempty"`
|
||||
Mode string `json:"mode,omitempty"`
|
||||
}
|
||||
type ChatHistorySetting struct {
|
||||
EnableChatHistory bool `json:"enableChatHistory,omitempty"`
|
||||
ChatHistoryRound int64 `json:"chatHistoryRound,omitempty"`
|
||||
}
|
||||
|
||||
type Intent struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
type Param struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Input *BlockInput `json:"input,omitempty"`
|
||||
Left *BlockInput `json:"left,omitempty"`
|
||||
Right *BlockInput `json:"right,omitempty"`
|
||||
Variables []*BlockInput `json:"variables,omitempty"`
|
||||
}
|
||||
|
||||
type Variable struct {
|
||||
Name string `json:"name"`
|
||||
Type VariableType `json:"type"`
|
||||
Required bool `json:"required,omitempty"`
|
||||
AssistType AssistType `json:"assistType,omitempty"`
|
||||
Schema any `json:"schema,omitempty"` // either []*Variable (for object) or *Variable (for list)
|
||||
Description string `json:"description,omitempty"`
|
||||
ReadOnly bool `json:"readOnly,omitempty"`
|
||||
DefaultValue any `json:"defaultValue,omitempty"`
|
||||
}
|
||||
|
||||
type BlockInput struct {
|
||||
Type VariableType `json:"type,omitempty" yaml:"Type,omitempty"`
|
||||
AssistType AssistType `json:"assistType,omitempty" yaml:"AssistType,omitempty"`
|
||||
Schema any `json:"schema,omitempty" yaml:"Schema,omitempty"` // either *BlockInput(or *Variable) for list or []*Variable (for object)
|
||||
Value *BlockInputValue `json:"value,omitempty" yaml:"Value,omitempty"`
|
||||
}
|
||||
|
||||
type BlockInputValue struct {
|
||||
Type BlockInputValueType `json:"type"`
|
||||
Content any `json:"content,omitempty"` // either string for text such as template, or BlockInputReference
|
||||
RawMeta any `json:"rawMeta,omitempty"`
|
||||
}
|
||||
|
||||
type BlockInputReference struct {
|
||||
BlockID string `json:"blockID"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Path []string `json:"path,omitempty"`
|
||||
Source RefSourceType `json:"source"`
|
||||
}
|
||||
|
||||
type Condition struct {
|
||||
Operator OperatorType `json:"operator"`
|
||||
Left *Param `json:"left"`
|
||||
Right *Param `json:"right,omitempty"`
|
||||
}
|
||||
|
||||
type SubWorkflow struct {
|
||||
WorkflowID string `json:"workflowId,omitempty"`
|
||||
WorkflowVersion string `json:"workflowVersion,omitempty"`
|
||||
TerminationType int `json:"type,omitempty"`
|
||||
SpaceID string `json:"spaceId,omitempty"`
|
||||
}
|
||||
|
||||
// BlockType is the enumeration of node types for front-end canvas schema.
|
||||
// To add a new BlockType, start from a really big number such as 1000, to avoid conflict with future extensions.
|
||||
type BlockType string
|
||||
|
||||
func (b BlockType) String() string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
const (
|
||||
BlockTypeBotStart BlockType = "1"
|
||||
BlockTypeBotEnd BlockType = "2"
|
||||
BlockTypeBotLLM BlockType = "3"
|
||||
BlockTypeBotAPI BlockType = "4"
|
||||
BlockTypeBotCode BlockType = "5"
|
||||
BlockTypeBotDataset BlockType = "6"
|
||||
BlockTypeCondition BlockType = "8"
|
||||
BlockTypeBotSubWorkflow BlockType = "9"
|
||||
BlockTypeDatabase BlockType = "12"
|
||||
BlockTypeBotMessage BlockType = "13"
|
||||
BlockTypeBotText BlockType = "15"
|
||||
BlockTypeQuestion BlockType = "18"
|
||||
BlockTypeBotBreak BlockType = "19"
|
||||
BlockTypeBotLoopSetVariable BlockType = "20"
|
||||
BlockTypeBotLoop BlockType = "21"
|
||||
BlockTypeBotIntent BlockType = "22"
|
||||
BlockTypeBotDatasetWrite BlockType = "27"
|
||||
BlockTypeBotInput BlockType = "30"
|
||||
BlockTypeBotBatch BlockType = "28"
|
||||
BlockTypeBotContinue BlockType = "29"
|
||||
BlockTypeBotComment BlockType = "31"
|
||||
BlockTypeBotVariableMerge BlockType = "32"
|
||||
BlockTypeBotAssignVariable BlockType = "40"
|
||||
BlockTypeDatabaseUpdate BlockType = "42"
|
||||
BlockTypeDatabaseSelect BlockType = "43"
|
||||
BlockTypeDatabaseDelete BlockType = "44"
|
||||
BlockTypeBotHttp BlockType = "45"
|
||||
BlockTypeDatabaseInsert BlockType = "46"
|
||||
BlockTypeJsonSerialization BlockType = "58"
|
||||
BlockTypeJsonDeserialization BlockType = "59"
|
||||
BlockTypeBotDatasetDelete BlockType = "60"
|
||||
)
|
||||
|
||||
type VariableType string
|
||||
|
||||
const (
|
||||
VariableTypeString VariableType = "string"
|
||||
VariableTypeInteger VariableType = "integer"
|
||||
VariableTypeFloat VariableType = "float"
|
||||
VariableTypeBoolean VariableType = "boolean"
|
||||
VariableTypeObject VariableType = "object"
|
||||
VariableTypeList VariableType = "list"
|
||||
)
|
||||
|
||||
type AssistType = int64
|
||||
|
||||
const (
|
||||
AssistTypeNotSet AssistType = 0
|
||||
AssistTypeDefault AssistType = 1
|
||||
AssistTypeImage AssistType = 2
|
||||
AssistTypeDoc AssistType = 3
|
||||
AssistTypeCode AssistType = 4
|
||||
AssistTypePPT AssistType = 5
|
||||
AssistTypeTXT AssistType = 6
|
||||
AssistTypeExcel AssistType = 7
|
||||
AssistTypeAudio AssistType = 8
|
||||
AssistTypeZip AssistType = 9
|
||||
AssistTypeVideo AssistType = 10
|
||||
AssistTypeSvg AssistType = 11
|
||||
AssistTypeVoice AssistType = 12
|
||||
|
||||
AssistTypeTime AssistType = 10000
|
||||
)
|
||||
|
||||
type BlockInputValueType string
|
||||
|
||||
const (
|
||||
BlockInputValueTypeLiteral BlockInputValueType = "literal"
|
||||
BlockInputValueTypeRef BlockInputValueType = "ref"
|
||||
BlockInputValueTypeObjectRef BlockInputValueType = "object_ref"
|
||||
)
|
||||
|
||||
type RefSourceType string
|
||||
|
||||
const (
|
||||
RefSourceTypeBlockOutput RefSourceType = "block-output" // 代表引用了某个 Block 的输出隐式声明的变量
|
||||
RefSourceTypeGlobalApp RefSourceType = "global_variable_app"
|
||||
RefSourceTypeGlobalSystem RefSourceType = "global_variable_system"
|
||||
RefSourceTypeGlobalUser RefSourceType = "global_variable_user"
|
||||
)
|
||||
|
||||
type TerminatePlan string
|
||||
|
||||
const (
|
||||
ReturnVariables TerminatePlan = "returnVariables"
|
||||
UseAnswerContent TerminatePlan = "useAnswerContent"
|
||||
)
|
||||
|
||||
type ErrorProcessType int
|
||||
|
||||
const (
|
||||
ErrorProcessTypeThrow ErrorProcessType = 1
|
||||
ErrorProcessTypeDefault ErrorProcessType = 2
|
||||
ErrorProcessTypeExceptionBranch ErrorProcessType = 3
|
||||
)
|
||||
|
||||
type SettingOnError struct {
|
||||
DataOnErr string `json:"dataOnErr,omitempty"`
|
||||
Switch bool `json:"switch,omitempty"`
|
||||
ProcessType *ErrorProcessType `json:"processType,omitempty"`
|
||||
RetryTimes int64 `json:"retryTimes,omitempty"`
|
||||
TimeoutMs int64 `json:"timeoutMs,omitempty"`
|
||||
Ext *struct {
|
||||
BackupLLMParam string `json:"backupLLMParam,omitempty"` // only for LLM Node, marshaled from QALLMParam
|
||||
} `json:"ext,omitempty"`
|
||||
}
|
||||
|
||||
type LogicType int
|
||||
|
||||
const (
|
||||
_ LogicType = iota
|
||||
OR
|
||||
AND
|
||||
)
|
||||
|
||||
type OperatorType int
|
||||
|
||||
const (
|
||||
_ OperatorType = iota
|
||||
Equal
|
||||
NotEqual
|
||||
LengthGreaterThan
|
||||
LengthGreaterThanEqual
|
||||
LengthLessThan
|
||||
LengthLessThanEqual
|
||||
Contain
|
||||
NotContain
|
||||
Empty
|
||||
NotEmpty
|
||||
True
|
||||
False
|
||||
GreaterThan
|
||||
GreaterThanEqual
|
||||
LessThan
|
||||
LessThanEqual
|
||||
)
|
||||
|
||||
type TextProcessingMethod string
|
||||
|
||||
const (
|
||||
Concat TextProcessingMethod = "concat"
|
||||
Split TextProcessingMethod = "split"
|
||||
)
|
||||
|
||||
type LoopType string
|
||||
|
||||
const (
|
||||
LoopTypeArray LoopType = "array"
|
||||
LoopTypeCount LoopType = "count"
|
||||
LoopTypeInfinite LoopType = "infinite"
|
||||
)
|
||||
|
||||
type WorkflowIdentity struct {
|
||||
ID string `json:"id"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
func (c *Canvas) GetAllSubWorkflowIdentities() []*WorkflowIdentity {
|
||||
workflowEntities := make([]*WorkflowIdentity, 0)
|
||||
|
||||
var collectSubWorkFlowEntities func(nodes []*Node)
|
||||
collectSubWorkFlowEntities = func(nodes []*Node) {
|
||||
for _, n := range nodes {
|
||||
if n.Type == BlockTypeBotSubWorkflow {
|
||||
workflowEntities = append(workflowEntities, &WorkflowIdentity{
|
||||
ID: n.Data.Inputs.WorkflowID,
|
||||
Version: n.Data.Inputs.WorkflowVersion,
|
||||
})
|
||||
}
|
||||
if len(n.Blocks) > 0 {
|
||||
collectSubWorkFlowEntities(n.Blocks)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
collectSubWorkFlowEntities(c.Nodes)
|
||||
|
||||
return workflowEntities
|
||||
}
|
||||
|
||||
func GenerateNodeIDForBatchMode(key string) string {
|
||||
return key + "_inner"
|
||||
}
|
||||
|
||||
func IsGeneratedNodeForBatchMode(key string, parentKey string) bool {
|
||||
return key == GenerateNodeIDForBatchMode(parentKey)
|
||||
}
|
||||
103
backend/domain/workflow/entity/vo/curd.go
Normal file
103
backend/domain/workflow/entity/vo/curd.go
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package vo
|
||||
|
||||
type Page struct {
|
||||
Size int32 `json:"size"`
|
||||
Page int32 `json:"page"`
|
||||
}
|
||||
|
||||
func (p *Page) Offset() int {
|
||||
if p.Page == 0 {
|
||||
return 0
|
||||
}
|
||||
return int((p.Page - 1) * p.Size)
|
||||
}
|
||||
|
||||
func (p *Page) Limit() int {
|
||||
return int(p.Size)
|
||||
}
|
||||
|
||||
type PublishStatus string
|
||||
|
||||
const (
|
||||
UnPublished PublishStatus = "UnPublished"
|
||||
HasPublished PublishStatus = "HasPublished"
|
||||
)
|
||||
|
||||
type WorkFlowType string
|
||||
|
||||
const (
|
||||
User WorkFlowType = "user"
|
||||
Official WorkFlowType = "official"
|
||||
)
|
||||
|
||||
type QueryToolInfoOption struct {
|
||||
Page *Page
|
||||
IDs []int64
|
||||
}
|
||||
|
||||
type Locator uint8
|
||||
|
||||
const (
|
||||
FromDraft Locator = iota
|
||||
FromSpecificVersion
|
||||
FromLatestVersion
|
||||
)
|
||||
|
||||
type GetPolicy struct {
|
||||
ID int64
|
||||
QType Locator
|
||||
MetaOnly bool
|
||||
Version string
|
||||
CommitID string
|
||||
}
|
||||
|
||||
type DeletePolicy struct {
|
||||
ID *int64
|
||||
IDs []int64
|
||||
AppID *int64
|
||||
}
|
||||
|
||||
type MGetPolicy struct {
|
||||
MetaQuery
|
||||
|
||||
QType Locator
|
||||
MetaOnly bool
|
||||
Versions map[int64]string
|
||||
}
|
||||
|
||||
type MGetReferencePolicy struct {
|
||||
ReferredIDs []int64
|
||||
ReferringIDs []int64
|
||||
ReferringBizType []ReferringBizType
|
||||
ReferType []ReferType
|
||||
}
|
||||
|
||||
type ReferType uint8
|
||||
|
||||
const (
|
||||
ReferTypeSubWorkflow ReferType = 1
|
||||
ReferTypeTool ReferType = 2
|
||||
)
|
||||
|
||||
type ReferringBizType uint8
|
||||
|
||||
const (
|
||||
ReferringBizTypeWorkflow ReferringBizType = 1
|
||||
ReferringBizTypeAgent ReferringBizType = 2
|
||||
)
|
||||
70
backend/domain/workflow/entity/vo/draft.go
Normal file
70
backend/domain/workflow/entity/vo/draft.go
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package vo
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/sonic"
|
||||
)
|
||||
|
||||
type DraftInfo struct {
|
||||
*DraftMeta
|
||||
|
||||
Canvas string
|
||||
InputParamsStr string
|
||||
OutputParamsStr string
|
||||
|
||||
CommitID string
|
||||
}
|
||||
|
||||
type CanvasInfo struct {
|
||||
Canvas string
|
||||
InputParams []*NamedTypeInfo
|
||||
OutputParams []*NamedTypeInfo
|
||||
InputParamsStr string
|
||||
OutputParamsStr string
|
||||
}
|
||||
|
||||
func (c *CanvasInfo) Unmarshal() error {
|
||||
if c.InputParamsStr != "" && len(c.InputParams) == 0 {
|
||||
var input []*NamedTypeInfo
|
||||
err := sonic.UnmarshalString(c.InputParamsStr, &input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.InputParams = input
|
||||
}
|
||||
|
||||
if c.OutputParamsStr != "" && len(c.OutputParams) == 0 {
|
||||
var output []*NamedTypeInfo
|
||||
err := sonic.UnmarshalString(c.OutputParamsStr, &output)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.OutputParams = output
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type DraftMeta struct {
|
||||
TestRunSuccess bool
|
||||
Modified bool
|
||||
Timestamp time.Time
|
||||
IsSnapshot bool // if true, this is a snapshot of a previous draft content, not the latest draft
|
||||
}
|
||||
67
backend/domain/workflow/entity/vo/execution.go
Normal file
67
backend/domain/workflow/entity/vo/execution.go
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package vo
|
||||
|
||||
type ExecuteConfig struct {
|
||||
ID int64
|
||||
From Locator
|
||||
Version string
|
||||
CommitID string
|
||||
Operator int64
|
||||
Mode ExecuteMode
|
||||
AppID *int64
|
||||
AgentID *int64
|
||||
ConnectorID int64
|
||||
ConnectorUID string
|
||||
TaskType TaskType
|
||||
SyncPattern SyncPattern
|
||||
InputFailFast bool // whether to fail fast if input conversion has warnings
|
||||
BizType BizType
|
||||
Cancellable bool
|
||||
}
|
||||
|
||||
type ExecuteMode string
|
||||
|
||||
const (
|
||||
ExecuteModeDebug ExecuteMode = "debug"
|
||||
ExecuteModeRelease ExecuteMode = "release"
|
||||
ExecuteModeNodeDebug ExecuteMode = "node_debug"
|
||||
)
|
||||
|
||||
type TaskType string
|
||||
|
||||
const (
|
||||
TaskTypeForeground TaskType = "foreground"
|
||||
TaskTypeBackground TaskType = "background"
|
||||
)
|
||||
|
||||
type SyncPattern string
|
||||
|
||||
const (
|
||||
SyncPatternSync SyncPattern = "sync"
|
||||
SyncPatternAsync SyncPattern = "async"
|
||||
SyncPatternStream SyncPattern = "stream"
|
||||
)
|
||||
|
||||
var DebugURLTpl = "http://127.0.0.1:3000/work_flow?execute_id=%d&space_id=%d&workflow_id=%d&execute_mode=2"
|
||||
|
||||
type BizType string
|
||||
|
||||
const (
|
||||
BizTypeAgent BizType = "agent"
|
||||
BizTypeWorkflow BizType = "workflow"
|
||||
)
|
||||
83
backend/domain/workflow/entity/vo/meta.go
Normal file
83
backend/domain/workflow/entity/vo/meta.go
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package vo
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/workflow"
|
||||
)
|
||||
|
||||
type ContentType = workflow.WorkFlowType
|
||||
type Tag = workflow.Tag
|
||||
type Mode = workflow.WorkflowMode
|
||||
|
||||
type Meta struct {
|
||||
// the following fields are immutable
|
||||
SpaceID int64
|
||||
CreatorID int64
|
||||
CreatedAt time.Time
|
||||
ContentType ContentType
|
||||
Tag *Tag
|
||||
AppID *int64
|
||||
SourceID *int64
|
||||
AuthorID int64
|
||||
|
||||
// the following fields are mutable
|
||||
Name string
|
||||
Desc string
|
||||
IconURI string
|
||||
IconURL string
|
||||
Mode Mode
|
||||
UpdatedAt *time.Time
|
||||
UpdaterID *int64
|
||||
DeletedAt *time.Time
|
||||
HasPublished bool
|
||||
LatestPublishedVersion *string
|
||||
}
|
||||
|
||||
type MetaCreate struct {
|
||||
Name string
|
||||
Desc string
|
||||
IconURI string
|
||||
SpaceID int64
|
||||
CreatorID int64
|
||||
ContentType ContentType
|
||||
AppID *int64
|
||||
Mode Mode
|
||||
InitCanvasSchema string
|
||||
}
|
||||
|
||||
type MetaUpdate struct {
|
||||
Name *string
|
||||
Desc *string
|
||||
IconURI *string
|
||||
HasPublished *bool
|
||||
LatestPublishedVersion *string
|
||||
}
|
||||
|
||||
type MetaQuery struct {
|
||||
IDs []int64
|
||||
SpaceID *int64
|
||||
Page *Page
|
||||
Name *string
|
||||
PublishStatus *PublishStatus
|
||||
AppID *int64
|
||||
LibOnly bool
|
||||
NeedTotalNumber bool
|
||||
DescByUpdate bool
|
||||
}
|
||||
602
backend/domain/workflow/entity/vo/node.go
Normal file
602
backend/domain/workflow/entity/vo/node.go
Normal file
@@ -0,0 +1,602 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package vo
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/cloudwego/eino/compose"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/sonic"
|
||||
"github.com/coze-dev/coze-studio/backend/types/errno"
|
||||
)
|
||||
|
||||
type NodeKey string
|
||||
|
||||
type FieldInfo struct {
|
||||
Path compose.FieldPath `json:"path"`
|
||||
Source FieldSource `json:"source"`
|
||||
}
|
||||
|
||||
type Reference struct {
|
||||
FromNodeKey NodeKey `json:"from_node_key,omitempty"`
|
||||
FromPath compose.FieldPath `json:"from_path"`
|
||||
|
||||
VariableType *GlobalVarType `json:"variable_type,omitempty"`
|
||||
}
|
||||
|
||||
type FieldSource struct {
|
||||
Ref *Reference `json:"ref,omitempty"`
|
||||
Val any `json:"val,omitempty"`
|
||||
}
|
||||
|
||||
type ImplicitNodeDependency struct {
|
||||
NodeID string
|
||||
FieldPath compose.FieldPath
|
||||
TypeInfo *TypeInfo
|
||||
}
|
||||
|
||||
type TypeInfo struct {
|
||||
Type DataType `json:"type"`
|
||||
ElemTypeInfo *TypeInfo `json:"elem_type_info,omitempty"`
|
||||
FileType *FileSubType `json:"file_type,omitempty"`
|
||||
Required bool `json:"required,omitempty"`
|
||||
Desc string `json:"desc,omitempty"`
|
||||
Properties map[string]*TypeInfo `json:"properties,omitempty"`
|
||||
}
|
||||
type NamedTypeInfo struct {
|
||||
Name string `json:"name"`
|
||||
Type DataType `json:"type"`
|
||||
ElemTypeInfo *NamedTypeInfo `json:"elem_type_info,omitempty"`
|
||||
FileType *FileSubType `json:"file_type,omitempty"`
|
||||
Required bool `json:"required,omitempty"`
|
||||
Desc string `json:"desc,omitempty"`
|
||||
Properties []*NamedTypeInfo `json:"properties,omitempty"`
|
||||
}
|
||||
|
||||
type ErrorLevel string
|
||||
|
||||
const (
|
||||
LevelWarn ErrorLevel = "Warn"
|
||||
LevelError ErrorLevel = "Error"
|
||||
LevelCancel ErrorLevel = "pending" // forget about why it's called 'pending', somebody named it and it's now part of the protocol
|
||||
)
|
||||
|
||||
type WorkflowError interface {
|
||||
errorx.StatusError
|
||||
DebugURL() string
|
||||
Level() ErrorLevel
|
||||
OpenAPICode() int
|
||||
AppendDebug(exeID, spaceID, workflowID int64) WorkflowError
|
||||
ChangeErrLevel(newLevel ErrorLevel) WorkflowError
|
||||
}
|
||||
|
||||
type wfErr struct {
|
||||
errorx.StatusError
|
||||
exeID int64
|
||||
spaceID int64
|
||||
workflowID int64
|
||||
cause error
|
||||
}
|
||||
|
||||
func (w *wfErr) DebugURL() string {
|
||||
if w.StatusError.Extra() == nil {
|
||||
return fmt.Sprintf(DebugURLTpl, w.exeID, w.spaceID, w.workflowID)
|
||||
}
|
||||
|
||||
debugURL, ok := w.StatusError.Extra()["debug_url"]
|
||||
if ok {
|
||||
return debugURL
|
||||
}
|
||||
|
||||
return fmt.Sprintf(DebugURLTpl, w.exeID, w.spaceID, w.workflowID)
|
||||
}
|
||||
|
||||
func (w *wfErr) Level() ErrorLevel {
|
||||
if w.StatusError.Extra() == nil {
|
||||
return LevelError
|
||||
}
|
||||
|
||||
level, ok := w.StatusError.Extra()["level"]
|
||||
if ok {
|
||||
return ErrorLevel(level)
|
||||
}
|
||||
|
||||
return LevelError
|
||||
}
|
||||
|
||||
func (w *wfErr) Error() string {
|
||||
if w.cause == nil {
|
||||
return w.StatusError.Error()
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s, cause: %s", w.StatusError.Error(), w.cause.Error())
|
||||
}
|
||||
|
||||
func (w *wfErr) OpenAPICode() int {
|
||||
return errno.CodeForOpenAPI(w)
|
||||
}
|
||||
|
||||
func (w *wfErr) AppendDebug(exeID, spaceID, workflowID int64) WorkflowError {
|
||||
w.exeID = exeID
|
||||
w.spaceID = spaceID
|
||||
w.workflowID = workflowID
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *wfErr) Unwrap() error {
|
||||
return w.cause
|
||||
}
|
||||
|
||||
func (w *wfErr) ChangeErrLevel(newLevel ErrorLevel) WorkflowError {
|
||||
w.StatusError.Extra()["level"] = string(newLevel)
|
||||
return w
|
||||
}
|
||||
|
||||
func NewError(code int, opts ...errorx.Option) WorkflowError {
|
||||
opts = append(opts, errorx.Extra("level", string(LevelError)))
|
||||
e := errorx.New(int32(code), opts...)
|
||||
var sErr errorx.StatusError
|
||||
_ = errors.As(e, &sErr)
|
||||
wfe := &wfErr{
|
||||
StatusError: sErr,
|
||||
}
|
||||
|
||||
return wfe
|
||||
}
|
||||
|
||||
func WrapError(code int, err error, opts ...errorx.Option) WorkflowError {
|
||||
opts = append(opts, errorx.Extra("level", string(LevelError)))
|
||||
e := errorx.WrapByCode(err, int32(code), opts...)
|
||||
var sErr errorx.StatusError
|
||||
_ = errors.As(e, &sErr)
|
||||
wfe := &wfErr{
|
||||
StatusError: sErr,
|
||||
cause: err,
|
||||
}
|
||||
return wfe
|
||||
}
|
||||
|
||||
func WrapWithDebug(code int, err error, exeID, spaceID, workflowID int64, opts ...errorx.Option) WorkflowError {
|
||||
debugURL := fmt.Sprintf(DebugURLTpl, exeID, spaceID, workflowID)
|
||||
opts = append(opts, errorx.Extra("debug_url", debugURL))
|
||||
return WrapError(code, err, opts...)
|
||||
}
|
||||
|
||||
func NewWarn(code int, opts ...errorx.Option) WorkflowError {
|
||||
opts = append(opts, errorx.Extra("level", string(LevelWarn)))
|
||||
e := errorx.New(int32(code), opts...)
|
||||
var sErr errorx.StatusError
|
||||
_ = errors.As(e, &sErr)
|
||||
wfe := &wfErr{
|
||||
StatusError: sErr,
|
||||
}
|
||||
|
||||
return wfe
|
||||
}
|
||||
|
||||
func WrapWarn(code int, err error, opts ...errorx.Option) WorkflowError {
|
||||
opts = append(opts, errorx.Extra("level", string(LevelWarn)))
|
||||
e := errorx.WrapByCode(err, int32(code), opts...)
|
||||
var sErr errorx.StatusError
|
||||
_ = errors.As(e, &sErr)
|
||||
wfe := &wfErr{
|
||||
StatusError: sErr,
|
||||
cause: err,
|
||||
}
|
||||
return wfe
|
||||
}
|
||||
|
||||
func WrapIfNeeded(code int, err error, opts ...errorx.Option) WorkflowError {
|
||||
var wfe WorkflowError
|
||||
if errors.As(err, &wfe) {
|
||||
return wfe
|
||||
}
|
||||
return WrapError(code, err, opts...)
|
||||
}
|
||||
|
||||
var CancelErr = newCancel()
|
||||
|
||||
func newCancel() WorkflowError {
|
||||
e := errorx.New(errno.ErrWorkflowCanceledByUser, errorx.Extra("level", string(LevelCancel)))
|
||||
var sErr errorx.StatusError
|
||||
_ = errors.As(e, &sErr)
|
||||
wfe := &wfErr{
|
||||
StatusError: sErr,
|
||||
}
|
||||
return wfe
|
||||
}
|
||||
|
||||
var NodeTimeoutErr = newNodeTimeout()
|
||||
|
||||
func newNodeTimeout() WorkflowError {
|
||||
e := errorx.New(errno.ErrNodeTimeout, errorx.Extra("level", string(LevelError)))
|
||||
var sErr errorx.StatusError
|
||||
_ = errors.As(e, &sErr)
|
||||
wfe := &wfErr{
|
||||
StatusError: sErr,
|
||||
}
|
||||
return wfe
|
||||
}
|
||||
|
||||
var WorkflowTimeoutErr = newWorkflowTimeout()
|
||||
|
||||
func newWorkflowTimeout() WorkflowError {
|
||||
e := errorx.New(errno.ErrWorkflowTimeout, errorx.Extra("level", string(LevelError)))
|
||||
var sErr errorx.StatusError
|
||||
_ = errors.As(e, &sErr)
|
||||
wfe := &wfErr{
|
||||
StatusError: sErr,
|
||||
}
|
||||
return wfe
|
||||
}
|
||||
|
||||
func UnwrapRootErr(err error) error {
|
||||
var (
|
||||
rootE = err
|
||||
currentE error
|
||||
)
|
||||
for {
|
||||
currentE = errors.Unwrap(rootE)
|
||||
if currentE == nil {
|
||||
break
|
||||
}
|
||||
rootE = currentE
|
||||
}
|
||||
|
||||
return rootE
|
||||
}
|
||||
|
||||
type DataType string
|
||||
|
||||
const (
|
||||
DataTypeString DataType = "string" // string
|
||||
DataTypeInteger DataType = "integer" // int64
|
||||
DataTypeNumber DataType = "number" // float64
|
||||
DataTypeBoolean DataType = "boolean" // bool
|
||||
DataTypeTime DataType = "time" // time.Time
|
||||
DataTypeObject DataType = "object" // map[string]any
|
||||
DataTypeArray DataType = "list" // []any
|
||||
DataTypeFile DataType = "file" // string (url)
|
||||
)
|
||||
|
||||
// Zero creates a zero value
|
||||
func (t *TypeInfo) Zero() any {
|
||||
switch t.Type {
|
||||
case DataTypeString:
|
||||
return ""
|
||||
case DataTypeInteger:
|
||||
return int64(0)
|
||||
case DataTypeNumber:
|
||||
return float64(0)
|
||||
case DataTypeBoolean:
|
||||
return false
|
||||
case DataTypeTime:
|
||||
return ""
|
||||
case DataTypeObject:
|
||||
var m map[string]any
|
||||
return m
|
||||
case DataTypeArray:
|
||||
var a []any
|
||||
return a
|
||||
case DataTypeFile:
|
||||
return ""
|
||||
default:
|
||||
panic("impossible")
|
||||
}
|
||||
}
|
||||
|
||||
func (n *NamedTypeInfo) ToParameterInfo() (*schema.ParameterInfo, error) {
|
||||
param := &schema.ParameterInfo{
|
||||
Type: convertDataType(n.Type),
|
||||
Desc: n.Desc,
|
||||
Required: n.Required,
|
||||
}
|
||||
|
||||
if n.Type == DataTypeObject {
|
||||
param.SubParams = make(map[string]*schema.ParameterInfo, len(n.Properties))
|
||||
for _, subT := range n.Properties {
|
||||
subParam, err := subT.ToParameterInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
param.SubParams[subT.Name] = subParam
|
||||
}
|
||||
} else if n.Type == DataTypeArray {
|
||||
elemParam, err := n.ElemTypeInfo.ToParameterInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
param.ElemInfo = elemParam
|
||||
}
|
||||
|
||||
return param, nil
|
||||
}
|
||||
|
||||
func (n *NamedTypeInfo) ToVariable() (*Variable, error) {
|
||||
|
||||
variableType, err := convertVariableType(n.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
v := &Variable{
|
||||
Name: n.Name,
|
||||
Type: variableType,
|
||||
Required: n.Required,
|
||||
}
|
||||
|
||||
if n.Type == DataTypeFile && n.FileType != nil {
|
||||
v.AssistType = toAssistType(*n.FileType)
|
||||
}
|
||||
|
||||
if n.Type == DataTypeArray && n.ElemTypeInfo != nil {
|
||||
ele, err := n.ElemTypeInfo.ToVariable()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v.Schema = ele
|
||||
}
|
||||
|
||||
if n.Type == DataTypeObject && len(n.Properties) > 0 {
|
||||
varList := make([]*Variable, 0, len(n.Properties))
|
||||
for _, p := range n.Properties {
|
||||
v, err := p.ToVariable()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
varList = append(varList, v)
|
||||
}
|
||||
v.Schema = varList
|
||||
}
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func toAssistType(f FileSubType) AssistType {
|
||||
switch f {
|
||||
case FileTypeDefault:
|
||||
return AssistTypeDefault
|
||||
case FileTypeImage:
|
||||
return AssistTypeImage
|
||||
case FileTypeSVG:
|
||||
return AssistTypeSvg
|
||||
case FileTypeAudio:
|
||||
return AssistTypeAudio
|
||||
case FileTypeVideo:
|
||||
return AssistTypeVideo
|
||||
case FileTypeDocument:
|
||||
return AssistTypeDoc
|
||||
case FileTypePPT:
|
||||
return AssistTypePPT
|
||||
case FileTypeExcel:
|
||||
return AssistTypeExcel
|
||||
case FileTypeTxt:
|
||||
return AssistTypeTXT
|
||||
case FileTypeCode:
|
||||
return AssistTypeCode
|
||||
case FileTypeZip:
|
||||
return AssistTypeZip
|
||||
default:
|
||||
return AssistTypeNotSet
|
||||
}
|
||||
}
|
||||
|
||||
func convertVariableType(d DataType) (VariableType, error) {
|
||||
switch d {
|
||||
case DataTypeString, DataTypeTime, DataTypeFile:
|
||||
return VariableTypeString, nil
|
||||
case DataTypeNumber:
|
||||
return VariableTypeFloat, nil
|
||||
case DataTypeInteger:
|
||||
return VariableTypeInteger, nil
|
||||
case DataTypeBoolean:
|
||||
return VariableTypeBoolean, nil
|
||||
case DataTypeObject:
|
||||
return VariableTypeObject, nil
|
||||
case DataTypeArray:
|
||||
return VariableTypeList, nil
|
||||
default:
|
||||
return "", fmt.Errorf("unknown variable type: %v", d)
|
||||
}
|
||||
}
|
||||
|
||||
func convertDataType(d DataType) schema.DataType {
|
||||
switch d {
|
||||
case DataTypeString, DataTypeTime, DataTypeFile:
|
||||
return schema.String
|
||||
case DataTypeNumber:
|
||||
return schema.Number
|
||||
case DataTypeInteger:
|
||||
return schema.Integer
|
||||
case DataTypeBoolean:
|
||||
return schema.Boolean
|
||||
case DataTypeObject:
|
||||
return schema.Object
|
||||
case DataTypeArray:
|
||||
return schema.Array
|
||||
default:
|
||||
panic("unknown data type")
|
||||
}
|
||||
}
|
||||
|
||||
func TypeInfoToJSONSchema(tis map[string]*TypeInfo, structName *string) (string, error) {
|
||||
schema_ := map[string]any{
|
||||
"type": "object",
|
||||
"properties": make(map[string]any),
|
||||
"required": []string{},
|
||||
}
|
||||
|
||||
if structName != nil {
|
||||
schema_["title"] = *structName
|
||||
}
|
||||
|
||||
properties := schema_["properties"].(map[string]any)
|
||||
for key, typeInfo := range tis {
|
||||
if typeInfo == nil {
|
||||
continue
|
||||
}
|
||||
sc, err := typeInfoToJSONSchema(typeInfo)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
properties[key] = sc
|
||||
if typeInfo.Required {
|
||||
schema_["required"] = append(schema_["required"].([]string), key)
|
||||
}
|
||||
}
|
||||
|
||||
jsonBytes, err := sonic.Marshal(schema_)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(jsonBytes), nil
|
||||
}
|
||||
|
||||
func typeInfoToJSONSchema(info *TypeInfo) (map[string]interface{}, error) {
|
||||
|
||||
sc := make(map[string]interface{})
|
||||
|
||||
switch info.Type {
|
||||
case DataTypeString:
|
||||
sc["type"] = "string"
|
||||
case DataTypeInteger:
|
||||
sc["type"] = "integer"
|
||||
case DataTypeNumber:
|
||||
sc["type"] = "number"
|
||||
case DataTypeBoolean:
|
||||
sc["type"] = "boolean"
|
||||
case DataTypeTime:
|
||||
sc["type"] = "string"
|
||||
sc["format"] = "date-time"
|
||||
case DataTypeObject:
|
||||
sc["type"] = "object"
|
||||
case DataTypeArray:
|
||||
sc["type"] = "array"
|
||||
case DataTypeFile:
|
||||
sc["type"] = "string"
|
||||
if info.FileType != nil {
|
||||
sc["contentMediaType"] = string(*info.FileType)
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("impossible")
|
||||
}
|
||||
|
||||
if info.Desc != "" {
|
||||
sc["description"] = info.Desc
|
||||
}
|
||||
|
||||
if info.Type == DataTypeArray && info.ElemTypeInfo != nil {
|
||||
itemsSchema, err := typeInfoToJSONSchema(info.ElemTypeInfo)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to convert array element type: %v", err)
|
||||
}
|
||||
sc["items"] = itemsSchema
|
||||
}
|
||||
if info.Type == DataTypeObject && info.Properties != nil {
|
||||
properties := make(map[string]interface{})
|
||||
required := make([]string, 0)
|
||||
|
||||
for name, propInfo := range info.Properties {
|
||||
propSchema, err := typeInfoToJSONSchema(propInfo)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to convert property %s: %v", name, err)
|
||||
}
|
||||
|
||||
properties[name] = propSchema
|
||||
|
||||
if propInfo.Required {
|
||||
required = append(required, name)
|
||||
}
|
||||
}
|
||||
|
||||
sc["properties"] = properties
|
||||
|
||||
if len(required) > 0 {
|
||||
sc["required"] = required
|
||||
}
|
||||
}
|
||||
|
||||
return sc, nil
|
||||
}
|
||||
|
||||
type FileSubType string
|
||||
|
||||
const (
|
||||
FileTypeDefault FileSubType = "default"
|
||||
FileTypeImage FileSubType = "image"
|
||||
FileTypeSVG FileSubType = "svg"
|
||||
FileTypeAudio FileSubType = "audio"
|
||||
FileTypeVideo FileSubType = "video"
|
||||
FileTypeVoice FileSubType = "voice"
|
||||
FileTypeDocument FileSubType = "doc"
|
||||
FileTypePPT FileSubType = "ppt"
|
||||
FileTypeExcel FileSubType = "excel"
|
||||
FileTypeTxt FileSubType = "txt"
|
||||
FileTypeCode FileSubType = "code"
|
||||
FileTypeZip FileSubType = "zip"
|
||||
)
|
||||
|
||||
type NodeProperty struct {
|
||||
Type string
|
||||
IsEnableChatHistory bool
|
||||
IsEnableUserQuery bool
|
||||
IsRefGlobalVariable bool
|
||||
SubWorkflow map[string]*NodeProperty
|
||||
}
|
||||
|
||||
func (f *FieldInfo) IsRefGlobalVariable() bool {
|
||||
if f.Source.Ref != nil && f.Source.Ref.VariableType != nil {
|
||||
return *f.Source.Ref.VariableType == GlobalUser || *f.Source.Ref.VariableType == GlobalSystem || *f.Source.Ref.VariableType == GlobalAPP
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ParseVariable(v any) (*Variable, error) {
|
||||
if va, ok := v.(*Variable); ok {
|
||||
return va, nil
|
||||
}
|
||||
|
||||
m, ok := v.(map[string]any)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid content type: %T when parse Variable", v)
|
||||
}
|
||||
|
||||
marshaled, err := sonic.Marshal(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
p := &Variable{}
|
||||
if err := sonic.Unmarshal(marshaled, p); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
type GlobalVarType string
|
||||
|
||||
const (
|
||||
ParentIntermediate GlobalVarType = "parent_intermediate"
|
||||
GlobalUser GlobalVarType = "global_user"
|
||||
GlobalSystem GlobalVarType = "global_system"
|
||||
GlobalAPP GlobalVarType = "global_app"
|
||||
)
|
||||
147
backend/domain/workflow/entity/vo/node_test.go
Normal file
147
backend/domain/workflow/entity/vo/node_test.go
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package vo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestTypeInfoToJSONSchema(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
typeInfo map[string]*TypeInfo
|
||||
validate func(t *testing.T, schema string)
|
||||
}{
|
||||
{
|
||||
name: "Basic Data Types",
|
||||
typeInfo: map[string]*TypeInfo{
|
||||
"stringField": {Type: DataTypeString},
|
||||
"intField": {Type: DataTypeInteger},
|
||||
"numField": {Type: DataTypeNumber},
|
||||
"boolField": {Type: DataTypeBoolean},
|
||||
"timeField": {Type: DataTypeTime},
|
||||
},
|
||||
validate: func(t *testing.T, schema string) {
|
||||
var schemaObj map[string]any
|
||||
err := json.Unmarshal([]byte(schema), &schemaObj)
|
||||
assert.NoError(t, err)
|
||||
|
||||
props := schemaObj["properties"].(map[string]any)
|
||||
|
||||
// 验证字符串字段
|
||||
stringProp := props["stringField"].(map[string]any)
|
||||
assert.Equal(t, "string", stringProp["type"])
|
||||
|
||||
// 验证整数字段
|
||||
intProp := props["intField"].(map[string]any)
|
||||
assert.Equal(t, "integer", intProp["type"])
|
||||
|
||||
// 验证数字字段
|
||||
numProp := props["numField"].(map[string]any)
|
||||
assert.Equal(t, "number", numProp["type"])
|
||||
|
||||
// 验证布尔字段
|
||||
boolProp := props["boolField"].(map[string]any)
|
||||
assert.Equal(t, "boolean", boolProp["type"])
|
||||
|
||||
// 验证时间字段
|
||||
timeProp := props["timeField"].(map[string]any)
|
||||
assert.Equal(t, "string", timeProp["type"])
|
||||
assert.Equal(t, "date-time", timeProp["format"])
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Complex Data Types",
|
||||
typeInfo: map[string]*TypeInfo{
|
||||
"objectField": {Type: DataTypeObject},
|
||||
"arrayField": {
|
||||
Type: DataTypeArray,
|
||||
ElemTypeInfo: &TypeInfo{Type: DataTypeString},
|
||||
},
|
||||
"fileField": {
|
||||
Type: DataTypeFile,
|
||||
FileType: fileSubTypePtr(FileTypeImage),
|
||||
},
|
||||
},
|
||||
validate: func(t *testing.T, schema string) {
|
||||
var schemaObj map[string]any
|
||||
err := json.Unmarshal([]byte(schema), &schemaObj)
|
||||
assert.NoError(t, err)
|
||||
|
||||
props := schemaObj["properties"].(map[string]any)
|
||||
|
||||
// 验证对象字段
|
||||
objProp := props["objectField"].(map[string]any)
|
||||
assert.Equal(t, "object", objProp["type"])
|
||||
|
||||
// 验证数组字段
|
||||
arrProp := props["arrayField"].(map[string]any)
|
||||
assert.Equal(t, "array", arrProp["type"])
|
||||
items := arrProp["items"].(map[string]any)
|
||||
assert.Equal(t, "string", items["type"])
|
||||
|
||||
// 验证文件字段
|
||||
fileProp := props["fileField"].(map[string]any)
|
||||
assert.Equal(t, "string", fileProp["type"])
|
||||
assert.Equal(t, "image", fileProp["contentMediaType"])
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Nested Array",
|
||||
typeInfo: map[string]*TypeInfo{
|
||||
"nestedArray": {
|
||||
Type: DataTypeArray,
|
||||
ElemTypeInfo: &TypeInfo{Type: DataTypeObject},
|
||||
},
|
||||
},
|
||||
validate: func(t *testing.T, schema string) {
|
||||
var schemaObj map[string]any
|
||||
err := json.Unmarshal([]byte(schema), &schemaObj)
|
||||
assert.NoError(t, err)
|
||||
|
||||
props := schemaObj["properties"].(map[string]any)
|
||||
|
||||
// 验证嵌套数组字段
|
||||
arrProp := props["nestedArray"].(map[string]any)
|
||||
assert.Equal(t, "array", arrProp["type"])
|
||||
items := arrProp["items"].(map[string]any)
|
||||
assert.Equal(t, "object", items["type"])
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
schema, err := TypeInfoToJSONSchema(tt.typeInfo, nil)
|
||||
assert.NoError(t, err)
|
||||
tt.validate(t, schema)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 辅助函数,用于创建 DataType 指针
|
||||
func stringPtr(dt DataType) *DataType {
|
||||
return &dt
|
||||
}
|
||||
|
||||
// 辅助函数,用于创建 FileSubType 指针
|
||||
func fileSubTypePtr(fst FileSubType) *FileSubType {
|
||||
return &fst
|
||||
}
|
||||
50
backend/domain/workflow/entity/vo/plugin_tool_info.go
Normal file
50
backend/domain/workflow/entity/vo/plugin_tool_info.go
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package vo
|
||||
|
||||
import (
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/sonic"
|
||||
)
|
||||
|
||||
type WorkFlowAsToolInfo struct {
|
||||
ID int64
|
||||
Name string
|
||||
Desc string
|
||||
IconURL string
|
||||
PublishStatus PublishStatus
|
||||
VersionName string
|
||||
CreatorID int64
|
||||
InputParams []*NamedTypeInfo
|
||||
CreatedAt int64
|
||||
UpdatedAt *int64
|
||||
}
|
||||
|
||||
type ToolDetailInfo struct {
|
||||
ApiDetailData *workflow.ApiDetailData
|
||||
ToolInputs any
|
||||
ToolOutputs any
|
||||
}
|
||||
|
||||
func (t *ToolDetailInfo) MarshalJSON() ([]byte, error) {
|
||||
bs, _ := sonic.Marshal(t.ApiDetailData)
|
||||
result := make(map[string]any)
|
||||
_ = sonic.Unmarshal(bs, &result)
|
||||
result["inputs"] = t.ToolInputs
|
||||
result["outputs"] = t.ToolOutputs
|
||||
return sonic.Marshal(result)
|
||||
}
|
||||
29
backend/domain/workflow/entity/vo/validate_info.go
Normal file
29
backend/domain/workflow/entity/vo/validate_info.go
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package vo
|
||||
|
||||
type ValidateTreeConfig struct {
|
||||
CanvasSchema string
|
||||
AppID *int64
|
||||
AgentID *int64
|
||||
}
|
||||
|
||||
type ValidateIssue struct {
|
||||
WorkflowName string
|
||||
WorkflowID int64
|
||||
IssueMessages []string
|
||||
}
|
||||
43
backend/domain/workflow/entity/vo/version_info.go
Normal file
43
backend/domain/workflow/entity/vo/version_info.go
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package vo
|
||||
|
||||
import "time"
|
||||
|
||||
type VersionInfo struct {
|
||||
*VersionMeta
|
||||
|
||||
CanvasInfo
|
||||
|
||||
CommitID string
|
||||
}
|
||||
|
||||
type PublishPolicy struct {
|
||||
ID int64
|
||||
Version string
|
||||
VersionDescription string
|
||||
CreatorID int64
|
||||
CommitID string
|
||||
Force bool
|
||||
}
|
||||
|
||||
type VersionMeta struct {
|
||||
Version string
|
||||
VersionDescription string
|
||||
VersionCreatedAt time.Time
|
||||
VersionCreatorID int64
|
||||
}
|
||||
43
backend/domain/workflow/entity/vo/workflow_copy.go
Normal file
43
backend/domain/workflow/entity/vo/workflow_copy.go
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package vo
|
||||
|
||||
type PluginEntity struct {
|
||||
PluginID int64
|
||||
PluginVersion *string // nil or "0" means draft, "" means latest/online version, otherwise is specific version
|
||||
}
|
||||
|
||||
type DependenceResource struct {
|
||||
PluginIDs []int64
|
||||
KnowledgeIDs []int64
|
||||
DatabaseIDs []int64
|
||||
}
|
||||
|
||||
type ExternalResourceRelated struct {
|
||||
PluginMap map[int64]*PluginEntity
|
||||
PluginToolMap map[int64]int64
|
||||
|
||||
KnowledgeMap map[int64]int64
|
||||
DatabaseMap map[int64]int64
|
||||
}
|
||||
|
||||
type CopyWorkflowPolicy struct {
|
||||
TargetSpaceID *int64
|
||||
TargetAppID *int64
|
||||
ModifiedCanvasSchema *string
|
||||
ShouldModifyWorkflowName bool
|
||||
}
|
||||
98
backend/domain/workflow/entity/vo/workflow_info.go
Normal file
98
backend/domain/workflow/entity/vo/workflow_info.go
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package vo
|
||||
|
||||
import (
|
||||
"github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/workflow"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/sonic"
|
||||
)
|
||||
|
||||
type ReleasedWorkflowData struct {
|
||||
WorkflowList []*workflow.ReleasedWorkflow
|
||||
Inputs map[string]any
|
||||
Outputs map[string]any
|
||||
}
|
||||
|
||||
func (r *ReleasedWorkflowData) MarshalJSON() ([]byte, error) {
|
||||
inputs := r.Inputs
|
||||
outputs := r.Outputs
|
||||
bs, _ := sonic.Marshal(r.WorkflowList)
|
||||
workflowsListMap := make([]map[string]any, 0, len(r.WorkflowList))
|
||||
_ = sonic.Unmarshal(bs, &workflowsListMap)
|
||||
for _, m := range workflowsListMap {
|
||||
if wId, ok := m["workflow_id"]; ok {
|
||||
m["inputs"] = inputs[wId.(string)]
|
||||
m["outputs"] = outputs[wId.(string)]
|
||||
}
|
||||
}
|
||||
|
||||
result := map[string]interface{}{
|
||||
"workflow_list": workflowsListMap,
|
||||
"total": len(r.WorkflowList),
|
||||
}
|
||||
|
||||
return sonic.Marshal(result)
|
||||
|
||||
}
|
||||
|
||||
type WorkflowDetailDataList struct {
|
||||
List []*workflow.WorkflowDetailData
|
||||
Inputs map[string]any
|
||||
Outputs map[string]any
|
||||
}
|
||||
|
||||
func (r *WorkflowDetailDataList) MarshalJSON() ([]byte, error) {
|
||||
inputs := r.Inputs
|
||||
outputs := r.Outputs
|
||||
bs, _ := sonic.Marshal(r.List)
|
||||
wfList := make([]map[string]any, 0, len(r.List))
|
||||
_ = sonic.Unmarshal(bs, &wfList)
|
||||
|
||||
for _, m := range wfList {
|
||||
if wId, ok := m["workflow_id"]; ok {
|
||||
m["inputs"] = inputs[wId.(string)]
|
||||
m["outputs"] = outputs[wId.(string)]
|
||||
}
|
||||
}
|
||||
|
||||
return sonic.Marshal(wfList)
|
||||
|
||||
}
|
||||
|
||||
type WorkflowDetailInfoDataList struct {
|
||||
List []*workflow.WorkflowDetailInfoData
|
||||
|
||||
Inputs map[string]any
|
||||
Outputs map[string]any
|
||||
}
|
||||
|
||||
func (r *WorkflowDetailInfoDataList) MarshalJSON() ([]byte, error) {
|
||||
inputs := r.Inputs
|
||||
outputs := r.Outputs
|
||||
bs, _ := sonic.Marshal(r.List)
|
||||
wfList := make([]map[string]any, 0, len(r.List))
|
||||
_ = sonic.Unmarshal(bs, &wfList)
|
||||
|
||||
for _, m := range wfList {
|
||||
if wId, ok := m["workflow_id"]; ok {
|
||||
m["inputs"] = inputs[wId.(string)]
|
||||
m["outputs"] = outputs[wId.(string)]
|
||||
}
|
||||
}
|
||||
return sonic.Marshal(wfList)
|
||||
|
||||
}
|
||||
24
backend/domain/workflow/entity/vo/workflow_publish.go
Normal file
24
backend/domain/workflow/entity/vo/workflow_publish.go
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package vo
|
||||
|
||||
type ReleaseWorkflowConfig struct {
|
||||
Version string
|
||||
PluginIDs []int64
|
||||
|
||||
ConnectorIDs []int64
|
||||
}
|
||||
24
backend/domain/workflow/entity/vo/workflow_tool.go
Normal file
24
backend/domain/workflow/entity/vo/workflow_tool.go
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package vo
|
||||
|
||||
import "github.com/coze-dev/coze-studio/backend/api/model/ocean/cloud/workflow"
|
||||
|
||||
type WorkflowToolConfig struct {
|
||||
InputParametersConfig []*workflow.APIParameter
|
||||
OutputParametersConfig []*workflow.APIParameter
|
||||
}
|
||||
Reference in New Issue
Block a user