refactor: how to add a node type in workflow (#558)

This commit is contained in:
shentongmartin
2025-08-05 14:02:33 +08:00
committed by GitHub
parent 5dafd81a3f
commit bb6ff0026b
96 changed files with 8305 additions and 8717 deletions

View File

@@ -1,4 +1,5 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,58 +17,85 @@
package entity
import (
"fmt"
"strconv"
)
type NodeType string
func (nt NodeType) IDStr() string {
m := NodeMetaByNodeType(nt)
if m == nil {
return ""
}
return fmt.Sprintf("%d", m.ID)
}
func IDStrToNodeType(s string) NodeType {
id, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return ""
}
for _, m := range NodeTypeMetas {
if m.ID == id {
return m.Key
}
}
return ""
}
type NodeTypeMeta struct {
ID int64 `json:"id"`
Name string `json:"name"`
Type NodeType `json:"type"`
Category string `json:"category"`
Color string `json:"color"`
Desc string `json:"desc"`
IconURL string `json:"icon_url"`
SupportBatch bool `json:"support_batch"`
Disabled bool `json:"disabled,omitempty"`
EnUSName string `json:"en_us_name,omitempty"`
EnUSDescription string `json:"en_us_description,omitempty"`
ID int64
Key NodeType
DisplayKey string
Name string `json:"name"`
Category string `json:"category"`
Color string `json:"color"`
Desc string `json:"desc"`
IconURL string `json:"icon_url"`
SupportBatch bool `json:"support_batch"`
Disabled bool `json:"disabled,omitempty"`
EnUSName string `json:"en_us_name,omitempty"`
EnUSDescription string `json:"en_us_description,omitempty"`
ExecutableMeta
}
func (ntm *NodeTypeMeta) GetDisplayKey() string {
if len(ntm.DisplayKey) > 0 {
return ntm.DisplayKey
}
return string(ntm.Key)
}
type Category struct {
Key string `json:"key"`
Name string `json:"name"`
EnUSName string `json:"en_us_name"`
}
type StreamingParadigm string
const (
Invoke StreamingParadigm = "invoke"
Stream StreamingParadigm = "stream"
Collect StreamingParadigm = "collect"
Transform StreamingParadigm = "transform"
)
type ExecutableMeta struct {
IsComposite bool `json:"is_composite,omitempty"`
DefaultTimeoutMS int64 `json:"default_timeout_ms,omitempty"` // default timeout in milliseconds, 0 means no timeout
PreFillZero bool `json:"pre_fill_zero,omitempty"`
PostFillNil bool `json:"post_fill_nil,omitempty"`
CallbackEnabled bool `json:"callback_enabled,omitempty"` // is false, Eino framework will inject callbacks for this node
MayUseChatModel bool `json:"may_use_chat_model,omitempty"`
InputSourceAware bool `json:"input_source_aware,omitempty"` // whether this node needs to know the runtime status of its input sources
StreamingParadigms map[StreamingParadigm]bool `json:"streaming_paradigms,omitempty"`
StreamSourceEOFAware bool `json:"needs_stream_source_eof,omitempty"` // whether this node needs to be aware stream sources' SourceEOF error
/*
IncrementalOutput indicates that the node's output is intended for progressive, user-facing streaming.
This distinguishes nodes that actually stream text to the user (e.g., 'Exit', 'Output')
from those that are merely capable of streaming internally (defined by StreamingParadigms),
whose output is consumed by other nodes.
In essence, nodes with IncrementalOutput are a subset of those defined in StreamingParadigms.
When set to true, stream chunks from the node are persisted in real-time and can be fetched by get_process.
*/
IsComposite bool `json:"is_composite,omitempty"`
DefaultTimeoutMS int64 `json:"default_timeout_ms,omitempty"` // default timeout in milliseconds, 0 means no timeout
PreFillZero bool `json:"pre_fill_zero,omitempty"`
PostFillNil bool `json:"post_fill_nil,omitempty"`
MayUseChatModel bool `json:"may_use_chat_model,omitempty"`
InputSourceAware bool `json:"input_source_aware,omitempty"` // whether this node needs to know the runtime status of its input sources
StreamSourceEOFAware bool `json:"needs_stream_source_eof,omitempty"` // whether this node needs to be aware stream sources' SourceEOF error
// IncrementalOutput indicates that the node's output is intended for progressive, user-facing streaming.
// This distinguishes nodes that actually stream text to the user (e.g., 'Exit', 'Output')
//from those that are merely capable of streaming internally (defined by StreamingParadigms),
// In essence, nodes with IncrementalOutput are a subset of those defined in StreamingParadigms.
// When set to true, stream chunks from the node are persisted in real-time and can be fetched by get_process.
IncrementalOutput bool `json:"incremental_output,omitempty"`
// UseCtxCache indicates that the node would require a newly initialized ctx cache for each invocation.
// example use cases:
// - write warnings to the ctx cache during Invoke, and read from the ctx within Callback output converter
UseCtxCache bool `json:"use_ctx_cache"`
}
type PluginNodeMeta struct {
@@ -125,9 +153,700 @@ const (
NodeTypeSubWorkflow NodeType = "SubWorkflow"
NodeTypeJsonSerialization NodeType = "JsonSerialization"
NodeTypeJsonDeserialization NodeType = "JsonDeserialization"
NodeTypeComment NodeType = "Comment"
)
const (
EntryNodeKey = "100001"
ExitNodeKey = "900001"
)
var Categories = []Category{
{
Key: "", // this is the default category. some of the most important nodes belong here, such as LLM, plugin, sub-workflow
Name: "",
EnUSName: "",
},
{
Key: "logic",
Name: "业务逻辑",
EnUSName: "Logic",
},
{
Key: "input&output",
Name: "输入&输出",
EnUSName: "Input&Output",
},
{
Key: "database",
Name: "数据库",
EnUSName: "Database",
},
{
Key: "data",
Name: "知识库&数据",
EnUSName: "Data",
},
{
Key: "image",
Name: "图像处理",
EnUSName: "Image",
},
{
Key: "audio&video",
Name: "音视频处理",
EnUSName: "Audio&Video",
},
{
Key: "utilities",
Name: "组件",
EnUSName: "Utilities",
},
{
Key: "conversation_management",
Name: "会话管理",
EnUSName: "Conversation management",
},
{
Key: "conversation_history",
Name: "会话历史",
EnUSName: "Conversation history",
},
{
Key: "message",
Name: "消息",
EnUSName: "Message",
},
}
// NodeTypeMetas holds the metadata for all available node types.
// It is initialized with built-in node types and potentially extended by loading from external sources.
var NodeTypeMetas = map[NodeType]*NodeTypeMeta{
NodeTypeEntry: {
ID: 1,
Key: NodeTypeEntry,
DisplayKey: "Start",
Name: "开始",
Category: "input&output",
Desc: "工作流的起始节点,用于设定启动工作流需要的信息",
Color: "#5C62FF",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Start-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
PostFillNil: true,
},
EnUSName: "Start",
EnUSDescription: "The starting node of the workflow, used to set the information needed to initiate the workflow.",
},
NodeTypeExit: {
ID: 2,
Key: NodeTypeExit,
DisplayKey: "End",
Name: "结束",
Category: "input&output",
Desc: "工作流的最终节点,用于返回工作流运行后的结果信息",
Color: "#5C62FF",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-End-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
InputSourceAware: true,
StreamSourceEOFAware: true,
IncrementalOutput: true,
},
EnUSName: "End",
EnUSDescription: "The final node of the workflow, used to return the result information after the workflow runs.",
},
NodeTypeLLM: {
ID: 3,
Key: NodeTypeLLM,
DisplayKey: "LLM",
Name: "大模型",
Category: "",
Desc: "调用大语言模型,使用变量和提示词生成回复",
Color: "#5C62FF",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-LLM-v2.jpg",
SupportBatch: true,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 3 * 60 * 1000, // 3 minutes
PreFillZero: true,
PostFillNil: true,
InputSourceAware: true,
MayUseChatModel: true,
},
EnUSName: "LLM",
EnUSDescription: "Invoke the large language model, generate responses using variables and prompt words.",
},
NodeTypePlugin: {
ID: 4,
Key: NodeTypePlugin,
DisplayKey: "Api",
Name: "插件",
Category: "",
Desc: "通过添加工具访问实时数据和执行外部操作",
Color: "#CA61FF",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Plugin-v2.jpg",
SupportBatch: true,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 3 * 60 * 1000, // 3 minutes
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Plugin",
EnUSDescription: "Used to access external real-time data and perform operations",
},
NodeTypeCodeRunner: {
ID: 5,
Key: NodeTypeCodeRunner,
DisplayKey: "Code",
Name: "代码",
Category: "logic",
Desc: "编写代码,处理输入变量来生成返回值",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Code-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
UseCtxCache: true,
},
EnUSName: "Code",
EnUSDescription: "Write code to process input variables to generate return values.",
},
NodeTypeKnowledgeRetriever: {
ID: 6,
Key: NodeTypeKnowledgeRetriever,
DisplayKey: "Dataset",
Name: "知识库检索",
Category: "data",
Desc: "在选定的知识中,根据输入变量召回最匹配的信息,并以列表形式返回",
Color: "#FF811A",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-KnowledgeQuery-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Knowledge retrieval",
EnUSDescription: "In the selected knowledge, the best matching information is recalled based on the input variable and returned as an Array.",
},
NodeTypeSelector: {
ID: 8,
Key: NodeTypeSelector,
DisplayKey: "If",
Name: "选择器",
Category: "logic",
Desc: "连接多个下游分支,若设定的条件成立则仅运行对应的分支,若均不成立则只运行“否则”分支",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Condition-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{},
EnUSName: "Condition",
EnUSDescription: "Connect multiple downstream branches. Only the corresponding branch will be executed if the set conditions are met. If none are met, only the 'else' branch will be executed.",
},
NodeTypeSubWorkflow: {
ID: 9,
Key: NodeTypeSubWorkflow,
DisplayKey: "SubWorkflow",
Name: "工作流",
Category: "",
Desc: "集成已发布工作流,可以执行嵌套子任务",
Color: "#00B83E",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Workflow-v2.jpg",
SupportBatch: true,
ExecutableMeta: ExecutableMeta{},
EnUSName: "Workflow",
EnUSDescription: "Add published workflows to execute subtasks",
},
NodeTypeDatabaseCustomSQL: {
ID: 12,
Key: NodeTypeDatabaseCustomSQL,
DisplayKey: "End",
Name: "SQL自定义",
Category: "database",
Desc: "基于用户自定义的 SQL 完成对数据库的增删改查操作",
Color: "#FF811A",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Database-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "SQL Customization",
EnUSDescription: "Complete the operations of adding, deleting, modifying and querying the database based on user-defined SQL",
},
NodeTypeOutputEmitter: {
ID: 13,
Key: NodeTypeOutputEmitter,
DisplayKey: "Message",
Name: "输出",
Category: "input&output",
Desc: "节点从“消息”更名为“输出”,支持中间过程的消息输出,支持流式和非流式两种方式",
Color: "#5C62FF",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Output-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
InputSourceAware: true,
StreamSourceEOFAware: true,
IncrementalOutput: true,
},
EnUSName: "Output",
EnUSDescription: "The node is renamed from \"message\" to \"output\", Supports message output in the intermediate process and streaming and non-streaming methods",
},
NodeTypeTextProcessor: {
ID: 15,
Key: NodeTypeTextProcessor,
DisplayKey: "Text",
Name: "文本处理",
Category: "utilities",
Desc: "用于处理多个字符串类型变量的格式",
Color: "#3071F2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-StrConcat-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
InputSourceAware: true,
},
EnUSName: "Text Processing",
EnUSDescription: "The format used for handling multiple string-type variables.",
},
NodeTypeQuestionAnswer: {
ID: 18,
Key: NodeTypeQuestionAnswer,
DisplayKey: "Question",
Name: "问答",
Category: "utilities",
Desc: "支持中间向用户提问问题,支持预置选项提问和开放式问题提问两种方式",
Color: "#3071F2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Direct-Question-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
MayUseChatModel: true,
},
EnUSName: "Question",
EnUSDescription: "Support asking questions to the user in the middle of the conversation, with both preset options and open-ended questions",
},
NodeTypeBreak: {
ID: 19,
Key: NodeTypeBreak,
DisplayKey: "Break",
Name: "终止循环",
Category: "logic",
Desc: "用于立即终止当前所在的循环,跳出循环体",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Break-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{},
EnUSName: "Break",
EnUSDescription: "Used to immediately terminate the current loop and jump out of the loop",
},
NodeTypeVariableAssignerWithinLoop: {
ID: 20,
Key: NodeTypeVariableAssignerWithinLoop,
DisplayKey: "LoopSetVariable",
Name: "设置变量",
Category: "logic",
Desc: "用于重置循环变量的值,使其下次循环使用重置后的值",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-LoopSetVariable-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{},
EnUSName: "Set Variable",
EnUSDescription: "Used to reset the value of the loop variable so that it uses the reset value in the next iteration",
},
NodeTypeLoop: {
ID: 21,
Key: NodeTypeLoop,
DisplayKey: "Loop",
Name: "循环",
Category: "logic",
Desc: "用于通过设定循环次数和逻辑,重复执行一系列任务",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Loop-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
IsComposite: true,
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Loop",
EnUSDescription: "Used to repeatedly execute a series of tasks by setting the number of iterations and logic",
},
NodeTypeIntentDetector: {
ID: 22,
Key: NodeTypeIntentDetector,
DisplayKey: "Intent",
Name: "意图识别",
Category: "logic",
Desc: "用于用户输入的意图识别,并将其与预设意图选项进行匹配。",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Intent-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
MayUseChatModel: true,
},
EnUSName: "Intent recognition",
EnUSDescription: "Used for recognizing the intent in user input and matching it with preset intent options.",
},
NodeTypeKnowledgeIndexer: {
ID: 27,
Key: NodeTypeKnowledgeIndexer,
DisplayKey: "DatasetWrite",
Name: "知识库写入",
Category: "data",
Desc: "写入节点可以添加 文本类型 的知识库,仅可以添加一个知识库",
Color: "#FF811A",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-KnowledgeWriting-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Knowledge writing",
EnUSDescription: "The write node can add a knowledge base of type text. Only one knowledge base can be added.",
},
NodeTypeBatch: {
ID: 28,
Key: NodeTypeBatch,
DisplayKey: "Batch",
Name: "批处理",
Category: "logic",
Desc: "通过设定批量运行次数和逻辑,运行批处理体内的任务",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Batch-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
IsComposite: true,
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Batch",
EnUSDescription: "By setting the number of batch runs and logic, run the tasks in the batch body.",
},
NodeTypeContinue: {
ID: 29,
Key: NodeTypeContinue,
DisplayKey: "Continue",
Name: "继续循环",
Category: "logic",
Desc: "用于终止当前循环,执行下次循环",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Continue-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{},
EnUSName: "Continue",
EnUSDescription: "Used to immediately terminate the current loop and execute next loop",
},
NodeTypeInputReceiver: {
ID: 30,
Key: NodeTypeInputReceiver,
DisplayKey: "Input",
Name: "输入",
Category: "input&output",
Desc: "支持中间过程的信息输入",
Color: "#5C62FF",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Input-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
PostFillNil: true,
},
EnUSName: "Input",
EnUSDescription: "Support intermediate information input",
},
NodeTypeComment: {
ID: 31,
Key: "",
Name: "注释",
Category: "", // Not found in cate_list
Desc: "comment_desc", // Placeholder from JSON
Color: "",
IconURL: "comment_icon", // Placeholder from JSON
SupportBatch: false, // supportBatch: 1
EnUSName: "Comment",
},
NodeTypeVariableAggregator: {
ID: 32,
Key: NodeTypeVariableAggregator,
Name: "变量聚合",
Category: "logic",
Desc: "对多个分支的输出进行聚合处理",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/VariableMerge-icon.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
PostFillNil: true,
InputSourceAware: true,
UseCtxCache: true,
},
EnUSName: "Variable Merge",
EnUSDescription: "Aggregate the outputs of multiple branches.",
},
NodeTypeMessageList: {
ID: 37,
Key: NodeTypeMessageList,
Name: "查询消息列表",
Category: "message",
Desc: "用于查询消息列表",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Conversation-List.jpeg",
SupportBatch: false,
Disabled: true,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Query message list",
EnUSDescription: "Used to query the message list",
},
NodeTypeClearMessage: {
ID: 38,
Key: NodeTypeClearMessage,
Name: "清除上下文",
Category: "conversation_history",
Desc: "用于清空会话历史清空后LLM看到的会话历史为空",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Conversation-Delete.jpeg",
SupportBatch: false,
Disabled: true,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Clear conversation history",
EnUSDescription: "Used to clear conversation history. After clearing, the conversation history visible to the LLM node will be empty.",
},
NodeTypeCreateConversation: {
ID: 39,
Key: NodeTypeCreateConversation,
Name: "创建会话",
Category: "conversation_management",
Desc: "用于创建会话",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Conversation-Create.jpeg",
SupportBatch: false,
Disabled: true,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Create conversation",
EnUSDescription: "This node is used to create a conversation.",
},
NodeTypeVariableAssigner: {
ID: 40,
Key: NodeTypeVariableAssigner,
DisplayKey: "AssignVariable",
Name: "变量赋值",
Category: "data",
Desc: "用于给支持写入的变量赋值,包括应用变量、用户变量",
Color: "#FF811A",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/Variable.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{},
EnUSName: "Variable assign",
EnUSDescription: "Assigns values to variables that support the write operation, including app and user variables.",
},
NodeTypeDatabaseUpdate: {
ID: 42,
Key: NodeTypeDatabaseUpdate,
DisplayKey: "DatabaseUpdate",
Name: "更新数据",
Category: "database",
Desc: "修改表中已存在的数据记录,用户指定更新条件和内容来更新数据",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-database-update.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
},
EnUSName: "Update Data",
EnUSDescription: "Modify the existing data records in the table, and the user specifies the update conditions and contents to update the data",
},
NodeTypeDatabaseQuery: {
ID: 43,
Key: NodeTypeDatabaseQuery,
DisplayKey: "DatabaseSelect",
Name: "查询数据",
Category: "database",
Desc: "从表获取数据,用户可定义查询条件、选择列等,输出符合条件的数据",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icaon-database-select.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
},
EnUSName: "Query Data",
EnUSDescription: "Query data from the table, and the user can define query conditions, select columns, etc., and output the data that meets the conditions",
},
NodeTypeDatabaseDelete: {
ID: 44,
Key: NodeTypeDatabaseDelete,
DisplayKey: "DatabaseDelete",
Name: "删除数据",
Category: "database",
Desc: "从表中删除数据记录,用户指定删除条件来删除符合条件的记录",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-database-delete.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
},
EnUSName: "Delete Data",
EnUSDescription: "Delete data records from the table, and the user specifies the deletion conditions to delete the records that meet the conditions",
},
NodeTypeHTTPRequester: {
ID: 45,
Key: NodeTypeHTTPRequester,
DisplayKey: "Http",
Name: "HTTP 请求",
Category: "utilities",
Desc: "用于发送API请求从接口返回数据",
Color: "#3071F2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-HTTP.png",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "HTTP request",
EnUSDescription: "It is used to send API requests and return data from the interface.",
},
NodeTypeDatabaseInsert: {
ID: 46,
Key: NodeTypeDatabaseInsert,
DisplayKey: "DatabaseInsert",
Name: "新增数据",
Category: "database",
Desc: "向表添加新数据记录,用户输入数据内容后插入数据库",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-database-insert.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
},
EnUSName: "Add Data",
EnUSDescription: "Add new data records to the table, and insert them into the database after the user enters the data content",
},
NodeTypeJsonSerialization: {
// ID is the unique identifier of this node type. Used in various front-end APIs.
ID: 58,
// Key is the unique NodeType of this node. Used in backend code as well as saved in DB.
Key: NodeTypeJsonSerialization,
// DisplayKey is the string used in frontend to identify this node.
// Example use cases:
// - used during querying test-run results for nodes
// - used in returned messages from streaming openAPI Runs.
// If empty, will use Key as DisplayKey.
DisplayKey: "ToJSON",
// Name is the node in ZH_CN, will be displayed on Canvas.
Name: "JSON 序列化",
// Category is the category of this node, determines which category this node will be displayed in.
Category: "utilities",
// Desc is the desc in ZH_CN, will be displayed as tooltip on Canvas.
Desc: "用于把变量转化为JSON字符串",
// Color is the color of the upper edge of the node displayed on Canvas.
Color: "F2B600",
// IconURL is the URL of the icon displayed on Canvas.
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-to_json.png",
// SupportBatch indicates whether this node can set batch mode.
// NOTE: ultimately it's frontend that decides which node can enable batch mode.
SupportBatch: false,
// ExecutableMeta configures certain common aspects of request-time behaviors for this node.
ExecutableMeta: ExecutableMeta{
// DefaultTimeoutMS configures the default timeout for this node, in milliseconds. 0 means no timeout.
DefaultTimeoutMS: 60 * 1000, // 1 minute
// PreFillZero decides whether to pre-fill zero value for any missing fields in input.
PreFillZero: true,
// PostFillNil decides whether to post-fill nil value for any missing fields in output.
PostFillNil: true,
},
// EnUSName is the name in EN_US, will be displayed on Canvas if language of Coze-Studio is set to EnUS.
EnUSName: "JSON serialization",
// EnUSDescription is the description in EN_US, will be displayed on Canvas if language of Coze-Studio is set to EnUS.
EnUSDescription: "Convert variable to JSON string",
},
NodeTypeJsonDeserialization: {
ID: 59,
Key: NodeTypeJsonDeserialization,
DisplayKey: "FromJSON",
Name: "JSON 反序列化",
Category: "utilities",
Desc: "用于将JSON字符串解析为变量",
Color: "F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-from_json.png",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
UseCtxCache: true,
},
EnUSName: "JSON deserialization",
EnUSDescription: "Parse JSON string to variable",
},
NodeTypeKnowledgeDeleter: {
ID: 60,
Key: NodeTypeKnowledgeDeleter,
DisplayKey: "KnowledgeDelete",
Name: "知识库删除",
Category: "data",
Desc: "用于删除知识库中的文档",
Color: "#FF811A",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icons-dataset-delete.png",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
},
EnUSName: "Knowledge delete",
EnUSDescription: "The delete node can delete a document in knowledge base.",
},
NodeTypeLambda: {
ID: 1000,
Key: NodeTypeLambda,
Name: "Lambda",
EnUSName: "Comment",
},
}
// PluginNodeMetas holds metadata for specific plugin API entity.
var PluginNodeMetas []*PluginNodeMeta
// PluginCategoryMetas holds metadata for plugin category entity.
var PluginCategoryMetas []*PluginCategoryMeta
func NodeMetaByNodeType(t NodeType) *NodeTypeMeta {
if m, ok := NodeTypeMetas[t]; ok {
return m
}
return nil
}

View File

@@ -1,867 +0,0 @@
/*
* 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 entity
import (
"github.com/coze-dev/coze-studio/backend/pkg/i18n"
"github.com/coze-dev/coze-studio/backend/pkg/lang/ternary"
)
var Categories = []Category{
{
Key: "", // this is the default category. some of the most important nodes belong here, such as LLM, plugin, sub-workflow
Name: "",
EnUSName: "",
},
{
Key: "logic",
Name: "业务逻辑",
EnUSName: "Logic",
},
{
Key: "input&output",
Name: "输入&输出",
EnUSName: "Input&Output",
},
{
Key: "database",
Name: "数据库",
EnUSName: "Database",
},
{
Key: "data",
Name: "知识库&数据",
EnUSName: "Data",
},
{
Key: "image",
Name: "图像处理",
EnUSName: "Image",
},
{
Key: "audio&video",
Name: "音视频处理",
EnUSName: "Audio&Video",
},
{
Key: "utilities",
Name: "组件",
EnUSName: "Utilities",
},
{
Key: "conversation_management",
Name: "会话管理",
EnUSName: "Conversation management",
},
{
Key: "conversation_history",
Name: "会话历史",
EnUSName: "Conversation history",
},
{
Key: "message",
Name: "消息",
EnUSName: "Message",
},
}
// NodeTypeMetas holds the metadata for all available node types.
// It is initialized with built-in types and potentially extended by loading from external sources.
var NodeTypeMetas = []*NodeTypeMeta{
{
ID: 1,
Name: "开始",
Type: NodeTypeEntry,
Category: "input&output", // Mapped from cate_list
Desc: "工作流的起始节点,用于设定启动工作流需要的信息",
Color: "#5C62FF",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Start-v2.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
PostFillNil: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Start",
EnUSDescription: "The starting node of the workflow, used to set the information needed to initiate the workflow.",
},
{
ID: 2,
Name: "结束",
Type: NodeTypeExit,
Category: "input&output", // Mapped from cate_list
Desc: "工作流的最终节点,用于返回工作流运行后的结果信息",
Color: "#5C62FF",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-End-v2.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
CallbackEnabled: true,
InputSourceAware: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true, Transform: true},
StreamSourceEOFAware: true,
IncrementalOutput: true,
},
EnUSName: "End",
EnUSDescription: "The final node of the workflow, used to return the result information after the workflow runs.",
},
{
ID: 3,
Name: "大模型",
Type: NodeTypeLLM,
Category: "", // Mapped from cate_list
Desc: "调用大语言模型,使用变量和提示词生成回复",
Color: "#5C62FF",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-LLM-v2.jpg",
SupportBatch: true, // supportBatch: 2
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 3 * 60 * 1000, // 3 minutes
PreFillZero: true,
PostFillNil: true,
CallbackEnabled: true,
InputSourceAware: true,
MayUseChatModel: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true, Stream: true},
},
EnUSName: "LLM",
EnUSDescription: "Invoke the large language model, generate responses using variables and prompt words.",
},
{
ID: 4,
Name: "插件",
Type: NodeTypePlugin,
Category: "", // Mapped from cate_list
Desc: "通过添加工具访问实时数据和执行外部操作",
Color: "#CA61FF",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Plugin-v2.jpg",
SupportBatch: true, // supportBatch: 2
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 3 * 60 * 1000, // 3 minutes
PreFillZero: true,
PostFillNil: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Plugin",
EnUSDescription: "Used to access external real-time data and perform operations",
},
{
ID: 5,
Name: "代码",
Type: NodeTypeCodeRunner,
Category: "logic", // Mapped from cate_list
Desc: "编写代码,处理输入变量来生成返回值",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Code-v2.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
CallbackEnabled: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Code",
EnUSDescription: "Write code to process input variables to generate return values.",
},
{
ID: 6,
Name: "知识库检索",
Type: NodeTypeKnowledgeRetriever,
Category: "data", // Mapped from cate_list
Desc: "在选定的知识中,根据输入变量召回最匹配的信息,并以列表形式返回",
Color: "#FF811A",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-KnowledgeQuery-v2.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Knowledge retrieval",
EnUSDescription: "In the selected knowledge, the best matching information is recalled based on the input variable and returned as an Array.",
},
{
ID: 8,
Name: "选择器",
Type: NodeTypeSelector,
Category: "logic", // Mapped from cate_list
Desc: "连接多个下游分支,若设定的条件成立则仅运行对应的分支,若均不成立则只运行“否则”分支",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Condition-v2.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
CallbackEnabled: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Condition",
EnUSDescription: "Connect multiple downstream branches. Only the corresponding branch will be executed if the set conditions are met. If none are met, only the 'else' branch will be executed.",
},
{
ID: 9,
Name: "工作流",
Type: NodeTypeSubWorkflow,
Category: "", // Mapped from cate_list
Desc: "集成已发布工作流,可以执行嵌套子任务",
Color: "#00B83E",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Workflow-v2.jpg",
SupportBatch: true, // supportBatch: 2
ExecutableMeta: ExecutableMeta{
CallbackEnabled: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Workflow",
EnUSDescription: "Add published workflows to execute subtasks",
},
{
ID: 12,
Name: "SQL自定义",
Type: NodeTypeDatabaseCustomSQL,
Category: "database", // Mapped from cate_list
Desc: "基于用户自定义的 SQL 完成对数据库的增删改查操作",
Color: "#FF811A",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Database-v2.jpg",
SupportBatch: false, // supportBatch: 2
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "SQL Customization",
EnUSDescription: "Complete the operations of adding, deleting, modifying and querying the database based on user-defined SQL",
},
{
ID: 13,
Name: "输出",
Type: NodeTypeOutputEmitter,
Category: "input&output", // Mapped from cate_list
Desc: "节点从“消息”更名为“输出”,支持中间过程的消息输出,支持流式和非流式两种方式",
Color: "#5C62FF",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Output-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
CallbackEnabled: true,
InputSourceAware: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true, Stream: true},
StreamSourceEOFAware: true,
IncrementalOutput: true,
},
EnUSName: "Output",
EnUSDescription: "The node is renamed from \"message\" to \"output\", Supports message output in the intermediate process and streaming and non-streaming methods",
},
{
ID: 15,
Name: "文本处理",
Type: NodeTypeTextProcessor,
Category: "utilities", // Mapped from cate_list
Desc: "用于处理多个字符串类型变量的格式",
Color: "#3071F2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-StrConcat-v2.jpg",
SupportBatch: false, // supportBatch: 2
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
CallbackEnabled: true,
InputSourceAware: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Text Processing",
EnUSDescription: "The format used for handling multiple string-type variables.",
},
{
ID: 18,
Name: "问答",
Type: NodeTypeQuestionAnswer,
Category: "utilities", // Mapped from cate_list
Desc: "支持中间向用户提问问题,支持预置选项提问和开放式问题提问两种方式",
Color: "#3071F2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Direct-Question-v2.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
CallbackEnabled: true,
MayUseChatModel: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Question",
EnUSDescription: "Support asking questions to the user in the middle of the conversation, with both preset options and open-ended questions",
},
{
ID: 19,
Name: "终止循环",
Type: NodeTypeBreak,
Category: "logic", // Mapped from cate_list
Desc: "用于立即终止当前所在的循环,跳出循环体",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Break-v2.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Break",
EnUSDescription: "Used to immediately terminate the current loop and jump out of the loop",
},
{
ID: 20,
Name: "设置变量",
Type: NodeTypeVariableAssignerWithinLoop,
Category: "logic", // Mapped from cate_list
Desc: "用于重置循环变量的值,使其下次循环使用重置后的值",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-LoopSetVariable-v2.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Set Variable",
EnUSDescription: "Used to reset the value of the loop variable so that it uses the reset value in the next iteration",
},
{
ID: 21,
Name: "循环",
Type: NodeTypeLoop,
Category: "logic", // Mapped from cate_list
Desc: "用于通过设定循环次数和逻辑,重复执行一系列任务",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Loop-v2.jpg",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
IsComposite: true,
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
CallbackEnabled: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Loop",
EnUSDescription: "Used to repeatedly execute a series of tasks by setting the number of iterations and logic",
},
{
ID: 22,
Name: "意图识别",
Type: NodeTypeIntentDetector,
Category: "logic", // Mapped from cate_list
Desc: "用于用户输入的意图识别,并将其与预设意图选项进行匹配。",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Intent-v2.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
CallbackEnabled: true,
MayUseChatModel: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Intent recognition",
EnUSDescription: "Used for recognizing the intent in user input and matching it with preset intent options.",
},
{
ID: 27,
Name: "知识库写入",
Type: NodeTypeKnowledgeIndexer,
Category: "data", // Mapped from cate_list
Desc: "写入节点可以添加 文本类型 的知识库,仅可以添加一个知识库",
Color: "#FF811A",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-KnowledgeWriting-v2.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Knowledge writing",
EnUSDescription: "The write node can add a knowledge base of type text. Only one knowledge base can be added.",
},
{
ID: 28,
Name: "批处理",
Type: NodeTypeBatch,
Category: "logic", // Mapped from cate_list
Desc: "通过设定批量运行次数和逻辑,运行批处理体内的任务",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Batch-v2.jpg",
SupportBatch: false, // supportBatch: 1 (Corrected from previous assumption)
ExecutableMeta: ExecutableMeta{
IsComposite: true,
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
CallbackEnabled: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Batch",
EnUSDescription: "By setting the number of batch runs and logic, run the tasks in the batch body.",
},
{
ID: 29,
Name: "继续循环",
Type: NodeTypeContinue,
Category: "logic", // Mapped from cate_list
Desc: "用于终止当前循环,执行下次循环",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Continue-v2.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Continue",
EnUSDescription: "Used to immediately terminate the current loop and execute next loop",
},
{
ID: 30,
Name: "输入",
Type: NodeTypeInputReceiver,
Category: "input&output", // Mapped from cate_list
Desc: "支持中间过程的信息输入",
Color: "#5C62FF",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Input-v2.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
PostFillNil: true,
CallbackEnabled: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Input",
EnUSDescription: "Support intermediate information input",
},
{
ID: 31,
Name: "注释",
Type: "",
Category: "", // Not found in cate_list
Desc: "comment_desc", // Placeholder from JSON
Color: "",
IconURL: "comment_icon", // Placeholder from JSON
SupportBatch: false, // supportBatch: 1
EnUSName: "Comment",
},
{
ID: 32,
Name: "变量聚合",
Type: NodeTypeVariableAggregator,
Category: "logic", // Mapped from cate_list
Desc: "对多个分支的输出进行聚合处理",
Color: "#00B2B2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/VariableMerge-icon.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
PostFillNil: true,
CallbackEnabled: true,
InputSourceAware: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true, Transform: true},
},
EnUSName: "Variable Merge",
EnUSDescription: "Aggregate the outputs of multiple branches.",
},
{
ID: 37,
Name: "查询消息列表",
Type: NodeTypeMessageList,
Category: "message", // Mapped from cate_list
Desc: "用于查询消息列表",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Conversation-List.jpeg",
SupportBatch: false, // supportBatch: 1
Disabled: true,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Query message list",
EnUSDescription: "Used to query the message list",
},
{
ID: 38,
Name: "清除上下文",
Type: NodeTypeClearMessage,
Category: "conversation_history", // Mapped from cate_list
Desc: "用于清空会话历史清空后LLM看到的会话历史为空",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Conversation-Delete.jpeg",
SupportBatch: false, // supportBatch: 1
Disabled: true,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Clear conversation history",
EnUSDescription: "Used to clear conversation history. After clearing, the conversation history visible to the LLM node will be empty.",
},
{
ID: 39,
Name: "创建会话",
Type: NodeTypeCreateConversation,
Category: "conversation_management", // Mapped from cate_list
Desc: "用于创建会话",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Conversation-Create.jpeg",
SupportBatch: false, // supportBatch: 1
Disabled: true,
ExecutableMeta: ExecutableMeta{
PreFillZero: true,
PostFillNil: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Create conversation",
EnUSDescription: "This node is used to create a conversation.",
},
{
ID: 40,
Name: "变量赋值",
Type: NodeTypeVariableAssigner,
Category: "data", // Mapped from cate_list
Desc: "用于给支持写入的变量赋值,包括应用变量、用户变量",
Color: "#FF811A",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/Variable.jpg",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Variable assign",
EnUSDescription: "Assigns values to variables that support the write operation, including app and user variables.",
},
{
ID: 42,
Name: "更新数据",
Type: NodeTypeDatabaseUpdate,
Category: "database", // Mapped from cate_list
Desc: "修改表中已存在的数据记录,用户指定更新条件和内容来更新数据",
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-database-update.jpg", // Corrected Icon URL from JSON
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
CallbackEnabled: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Update Data",
EnUSDescription: "Modify the existing data records in the table, and the user specifies the update conditions and contents to update the data",
},
{
ID: 43,
Name: "查询数据", // Corrected Name from JSON (was "insert data")
Type: NodeTypeDatabaseQuery,
Category: "database", // Mapped from cate_list
Desc: "从表获取数据,用户可定义查询条件、选择列等,输出符合条件的数据", // Corrected Desc from JSON
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icaon-database-select.jpg", // Corrected Icon URL from JSON
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
CallbackEnabled: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Query Data",
EnUSDescription: "Query data from the table, and the user can define query conditions, select columns, etc., and output the data that meets the conditions",
},
{
ID: 44,
Name: "删除数据",
Type: NodeTypeDatabaseDelete,
Category: "database", // Mapped from cate_list
Desc: "从表中删除数据记录,用户指定删除条件来删除符合条件的记录", // Corrected Desc from JSON
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-database-delete.jpg", // Corrected Icon URL from JSON
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
CallbackEnabled: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Delete Data",
EnUSDescription: "Delete data records from the table, and the user specifies the deletion conditions to delete the records that meet the conditions",
},
{
ID: 45,
Name: "HTTP 请求",
Type: NodeTypeHTTPRequester,
Category: "utilities", // Mapped from cate_list
Desc: "用于发送API请求从接口返回数据", // Corrected Desc from JSON
Color: "#3071F2",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-HTTP.png", // Corrected Icon URL from JSON
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
CallbackEnabled: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "HTTP request",
EnUSDescription: "It is used to send API requests and return data from the interface.",
},
{
ID: 46,
Name: "新增数据", // Corrected Name from JSON (was "Query Data")
Type: NodeTypeDatabaseInsert,
Category: "database", // Mapped from cate_list
Desc: "向表添加新数据记录,用户输入数据内容后插入数据库", // Corrected Desc from JSON
Color: "#F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-database-insert.jpg", // Corrected Icon URL from JSON
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
CallbackEnabled: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Add Data",
EnUSDescription: "Add new data records to the table, and insert them into the database after the user enters the data content",
},
{
ID: 58,
Name: "JSON 序列化",
Type: NodeTypeJsonSerialization,
Category: "utilities",
Desc: "用于把变量转化为JSON字符串",
Color: "F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-to_json.png",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
CallbackEnabled: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "JSON serialization",
EnUSDescription: "Convert variable to JSON string",
},
{
ID: 59,
Name: "JSON 反序列化",
Type: NodeTypeJsonDeserialization,
Category: "utilities",
Desc: "用于将JSON字符串解析为变量",
Color: "F2B600",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-from_json.png",
SupportBatch: false,
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
CallbackEnabled: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "JSON deserialization",
EnUSDescription: "Parse JSON string to variable",
},
{
ID: 60,
Name: "知识库删除",
Type: NodeTypeKnowledgeDeleter,
Category: "data", // Mapped from cate_list
Desc: "用于删除知识库中的文档",
Color: "#FF811A",
IconURL: "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icons-dataset-delete.png",
SupportBatch: false, // supportBatch: 1
ExecutableMeta: ExecutableMeta{
DefaultTimeoutMS: 60 * 1000, // 1 minute
PreFillZero: true,
PostFillNil: true,
StreamingParadigms: map[StreamingParadigm]bool{Invoke: true},
},
EnUSName: "Knowledge delete",
EnUSDescription: "The delete node can delete a document in knowledge base.",
},
// --- End of nodes parsed from template_list ---
}
// PluginNodeMetas holds metadata for specific plugin API entity.
var PluginNodeMetas []*PluginNodeMeta
// PluginCategoryMetas holds metadata for plugin category entity.
var PluginCategoryMetas []*PluginCategoryMeta
func NodeMetaByNodeType(t NodeType) *NodeTypeMeta {
for _, meta := range NodeTypeMetas {
if meta.Type == t {
return meta
}
}
return nil
}
const defaultZhCNInitCanvasJsonSchema = `{
"nodes": [
{
"id": "100001",
"type": "1",
"meta": {
"position": {
"x": 0,
"y": 0
}
},
"data": {
"nodeMeta": {
"description": "工作流的起始节点,用于设定启动工作流需要的信息",
"icon": "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Start.png",
"subTitle": "",
"title": "开始"
},
"outputs": [
{
"type": "string",
"name": "input",
"required": false
}
],
"trigger_parameters": [
{
"type": "string",
"name": "input",
"required": false
}
]
}
},
{
"id": "900001",
"type": "2",
"meta": {
"position": {
"x": 1000,
"y": 0
}
},
"data": {
"nodeMeta": {
"description": "工作流的最终节点,用于返回工作流运行后的结果信息",
"icon": "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-End.png",
"subTitle": "",
"title": "结束"
},
"inputs": {
"terminatePlan": "returnVariables",
"inputParameters": [
{
"name": "output",
"input": {
"type": "string",
"value": {
"type": "ref",
"content": {
"source": "block-output",
"blockID": "",
"name": ""
}
}
}
}
]
}
}
}
],
"edges": [],
"versions": {
"loop": "v2"
}
}`
const defaultEnUSInitCanvasJsonSchema = `{
"nodes": [
{
"id": "100001",
"type": "1",
"meta": {
"position": {
"x": 0,
"y": 0
}
},
"data": {
"nodeMeta": {
"description": "The starting node of the workflow, used to set the information needed to initiate the workflow.",
"icon": "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Start.png",
"subTitle": "",
"title": "Start"
},
"outputs": [
{
"type": "string",
"name": "input",
"required": false
}
],
"trigger_parameters": [
{
"type": "string",
"name": "input",
"required": false
}
]
}
},
{
"id": "900001",
"type": "2",
"meta": {
"position": {
"x": 1000,
"y": 0
}
},
"data": {
"nodeMeta": {
"description": "The final node of the workflow, used to return the result information after the workflow runs.",
"icon": "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-End.png",
"subTitle": "",
"title": "End"
},
"inputs": {
"terminatePlan": "returnVariables",
"inputParameters": [
{
"name": "output",
"input": {
"type": "string",
"value": {
"type": "ref",
"content": {
"source": "block-output",
"blockID": "",
"name": ""
}
}
}
}
]
}
}
}
],
"edges": [],
"versions": {
"loop": "v2"
}
}`
func GetDefaultInitCanvasJsonSchema(locale i18n.Locale) string {
return ternary.IFElse(locale == i18n.LocaleEN, defaultEnUSInitCanvasJsonSchema, defaultZhCNInitCanvasJsonSchema)
}

View File

@@ -19,24 +19,48 @@ 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"
"github.com/coze-dev/coze-studio/backend/pkg/i18n"
"github.com/coze-dev/coze-studio/backend/pkg/lang/ternary"
)
// Canvas is the definition of FRONTEND schema for a workflow.
type Canvas struct {
Nodes []*Node `json:"nodes"`
Edges []*Edge `json:"edges"`
Versions any `json:"versions"`
}
// Node represents a node within a workflow canvas.
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"`
// ID is the unique node ID within the workflow.
// In normal use cases, this ID is generated by frontend.
// It does NOT need to be unique between parent workflow and sub workflows.
// The Entry node and Exit node of a workflow always have fixed node IDs: 100001 and 900001.
ID string `json:"id"`
parent *Node
// Type is the Node Type of this node instance.
// It corresponds to the string value of 'ID' field of NodeMeta.
Type string `json:"type"`
// Meta holds meta data used by frontend, such as the node's position within canvas.
Meta any `json:"meta"`
// Data holds the actual configurations of a node, such as inputs, outputs and exception handling.
// It also holds exclusive configurations for different node types, such as LLM configurations.
Data *Data `json:"data"`
// Blocks holds the sub nodes of this node.
// It is only used when the node type is Composite, such as NodeTypeBatch and NodeTypeLoop.
Blocks []*Node `json:"blocks,omitempty"`
// Edges are the connections between nodes.
// Strictly corresponds to connections drawn on canvas.
Edges []*Edge `json:"edges,omitempty"`
// Version is the version of this node type's schema.
Version string `json:"version,omitempty"`
parent *Node // if this node is within a composite node, coze will set this. No need to set manually
}
func (n *Node) SetParent(parent *Node) {
@@ -47,7 +71,7 @@ func (n *Node) Parent() *Node {
return n.parent
}
type NodeMeta struct {
type NodeMetaFE struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Icon string `json:"icon,omitempty"`
@@ -62,52 +86,88 @@ type Edge struct {
TargetPortID string `json:"targetPortID,omitempty"`
}
// Data holds the actual configuration of a Node.
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"`
// Meta is the meta data of this node. Only used by frontend.
Meta *NodeMetaFE `json:"nodeMeta,omitempty"`
// Outputs configures the output fields and their types.
// Outputs can be either []*Variable (most of the cases, just fields and types),
// or []*Param (used by composite nodes as they need to refer to outputs of sub nodes)
Outputs []any `json:"outputs,omitempty"`
// Inputs configures ALL input information of a node,
// including fixed input fields and dynamic input fields defined by user.
Inputs *Inputs `json:"inputs,omitempty"`
// Size configures the size of this node in frontend.
// Only used by NodeTypeComment.
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"`
// InputParameters are the fields defined by user for this particular node.
InputParameters []*Param `json:"inputParameters"`
// SettingOnError configures common error handling strategy for nodes.
// NOTE: enable in frontend node's form first.
SettingOnError *SettingOnError `json:"settingOnError,omitempty"`
// NodeBatchInfo configures batch mode for nodes.
// NOTE: not to be confused with NodeTypeBatch.
NodeBatchInfo *NodeBatch `json:"batch,omitempty"`
// LLMParam may be one of the LLMParam or IntentDetectorLLMParam or SimpleLLMParam.
// Shared between most nodes requiring an ChatModel to function.
LLMParam any `json:"llmParam,omitempty"`
*OutputEmitter // exclusive configurations for NodeTypeEmitter and NodeTypeExit in Answer mode
*Exit // exclusive configurations for NodeTypeExit
*LLM // exclusive configurations for NodeTypeLLM
*Loop // exclusive configurations for NodeTypeLoop
*Selector // exclusive configurations for NodeTypeSelector
*TextProcessor // exclusive configurations for NodeTypeTextProcessor
*SubWorkflow // exclusive configurations for NodeTypeSubWorkflow
*IntentDetector // exclusive configurations for NodeTypeIntentDetector
*DatabaseNode // exclusive configurations for various Database nodes
*HttpRequestNode // exclusive configurations for NodeTypeHTTPRequester
*Knowledge // exclusive configurations for various Knowledge nodes
*CodeRunner // exclusive configurations for NodeTypeCodeRunner
*PluginAPIParam // exclusive configurations for NodeTypePlugin
*VariableAggregator // exclusive configurations for NodeTypeVariableAggregator
*VariableAssigner // exclusive configurations for NodeTypeVariableAssigner
*QA // exclusive configurations for NodeTypeQuestionAnswer
*Batch // exclusive configurations for NodeTypeBatch
*Comment // exclusive configurations for NodeTypeComment
*InputReceiver // exclusive configurations for NodeTypeInputReceiver
}
type OutputEmitter struct {
Content *BlockInput `json:"content"`
StreamingOutput bool `json:"streamingOutput,omitempty"`
}
type Exit struct {
TerminatePlan *TerminatePlan `json:"terminatePlan,omitempty"`
}
type LLM struct {
FCParam *FCParam `json:"fcParam,omitempty"`
}
type Loop struct {
LoopType LoopType `json:"loopType,omitempty"`
LoopCount *BlockInput `json:"loopCount,omitempty"`
VariableParameters []*Param `json:"variableParameters,omitempty"`
}
type Selector struct {
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 {
@@ -127,7 +187,7 @@ type VariableAssigner struct {
type LLMParam = []*Param
type IntentDetectorLLMParam = map[string]any
type QALLMParam struct {
type SimpleLLMParam struct {
GenerationDiversity string `json:"generationDiversity"`
MaxTokens int `json:"maxTokens"`
ModelName string `json:"modelName"`
@@ -248,7 +308,7 @@ type CodeRunner struct {
Language int64 `json:"language"`
}
type KnowledgeIndexer struct {
type Knowledge struct {
DatasetParam []*Param `json:"datasetParam,omitempty"`
StrategyParam StrategyParam `json:"strategyParam,omitempty"`
}
@@ -384,23 +444,54 @@ type ChatHistorySetting struct {
type Intent struct {
Name string `json:"name"`
}
// Param is a node's field with type and source info.
type Param struct {
Name string `json:"name,omitempty"`
Input *BlockInput `json:"input,omitempty"`
Left *BlockInput `json:"left,omitempty"`
Right *BlockInput `json:"right,omitempty"`
// Name is the field's name.
Name string `json:"name,omitempty"`
// Input is the configurations for normal, singular field.
Input *BlockInput `json:"input,omitempty"`
// Left is the configurations for the left half of an expression,
// such as an assignment in NodeTypeVariableAssigner.
Left *BlockInput `json:"left,omitempty"`
// Right is the configuration for the right half of an expression.
Right *BlockInput `json:"right,omitempty"`
// Variables are configurations for a group of fields.
// Only used in NodeTypeVariableAggregator.
Variables []*BlockInput `json:"variables,omitempty"`
}
// Variable is the configuration of a node's field, either input or output.
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"`
// Name is the field's name as defined on canvas.
Name string `json:"name"`
// Type is the field's data type, such as string, integer, number, object, array, etc.
Type VariableType `json:"type"`
// Required is set to true if you checked the 'required box' on this field
Required bool `json:"required,omitempty"`
// AssistType is the 'secondary' type of string fields, such as different types of file and image, or time.
AssistType AssistType `json:"assistType,omitempty"`
// Schema contains detailed info for sub-fields of an object field, or element type of an array.
Schema any `json:"schema,omitempty"` // either []*Variable (for object) or *Variable (for list)
// Description describes the field's intended use. Used on Entry node. Useful for workflow tools.
Description string `json:"description,omitempty"`
// ReadOnly indicates a field is not to be set by Node's business logic.
// e.g. the ErrorBody field when exception strategy is configured.
ReadOnly bool `json:"readOnly,omitempty"`
// DefaultValue configures the 'default value' if this field is missing in input.
// Effective only in Entry node.
DefaultValue any `json:"defaultValue,omitempty"`
}
type BlockInput struct {
@@ -436,48 +527,6 @@ type SubWorkflow struct {
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 (
@@ -536,19 +585,31 @@ const (
type ErrorProcessType int
const (
ErrorProcessTypeThrow ErrorProcessType = 1
ErrorProcessTypeDefault ErrorProcessType = 2
ErrorProcessTypeExceptionBranch ErrorProcessType = 3
ErrorProcessTypeThrow ErrorProcessType = 1 // throws the error as usual
ErrorProcessTypeReturnDefaultData ErrorProcessType = 2 // return DataOnErr configured in SettingOnError
ErrorProcessTypeExceptionBranch ErrorProcessType = 3 // executes the exception branch on error
)
// SettingOnError contains common error handling strategy.
type SettingOnError struct {
DataOnErr string `json:"dataOnErr,omitempty"`
Switch bool `json:"switch,omitempty"`
// DataOnErr defines the JSON result to be returned on error.
DataOnErr string `json:"dataOnErr,omitempty"`
// Switch defines whether ANY error handling strategy is active.
// If set to false, it's equivalent to set ProcessType = ErrorProcessTypeThrow
Switch bool `json:"switch,omitempty"`
// ProcessType determines the error handling strategy for this node.
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
// RetryTimes determines how many times to retry. 0 means no retry.
// If positive, any retries will be executed immediately after error.
RetryTimes int64 `json:"retryTimes,omitempty"`
// TimeoutMs sets the timeout duration in millisecond.
// If any retry happens, ALL retry attempts accumulates to the same timeout threshold.
TimeoutMs int64 `json:"timeoutMs,omitempty"`
// Ext sets any extra settings specific to NodeType
Ext *struct {
// BackupLLMParam is only for LLM Node, marshaled from SimpleLLMParam.
// If retry happens, the backup LLM will be used instead of the main LLM.
BackupLLMParam string `json:"backupLLMParam,omitempty"`
} `json:"ext,omitempty"`
}
@@ -597,32 +658,8 @@ const (
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
type InputReceiver struct {
OutputSchema string `json:"outputSchema,omitempty"`
}
func GenerateNodeIDForBatchMode(key string) string {
@@ -632,3 +669,163 @@ func GenerateNodeIDForBatchMode(key string) string {
func IsGeneratedNodeForBatchMode(key string, parentKey string) bool {
return key == GenerateNodeIDForBatchMode(parentKey)
}
const defaultZhCNInitCanvasJsonSchema = `{
"nodes": [
{
"id": "100001",
"type": "1",
"meta": {
"position": {
"x": 0,
"y": 0
}
},
"data": {
"nodeMeta": {
"description": "工作流的起始节点,用于设定启动工作流需要的信息",
"icon": "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Start.png",
"subTitle": "",
"title": "开始"
},
"outputs": [
{
"type": "string",
"name": "input",
"required": false
}
],
"trigger_parameters": [
{
"type": "string",
"name": "input",
"required": false
}
]
}
},
{
"id": "900001",
"type": "2",
"meta": {
"position": {
"x": 1000,
"y": 0
}
},
"data": {
"nodeMeta": {
"description": "工作流的最终节点,用于返回工作流运行后的结果信息",
"icon": "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-End.png",
"subTitle": "",
"title": "结束"
},
"inputs": {
"terminatePlan": "returnVariables",
"inputParameters": [
{
"name": "output",
"input": {
"type": "string",
"value": {
"type": "ref",
"content": {
"source": "block-output",
"blockID": "",
"name": ""
}
}
}
}
]
}
}
}
],
"edges": [],
"versions": {
"loop": "v2"
}
}`
const defaultEnUSInitCanvasJsonSchema = `{
"nodes": [
{
"id": "100001",
"type": "1",
"meta": {
"position": {
"x": 0,
"y": 0
}
},
"data": {
"nodeMeta": {
"description": "The starting node of the workflow, used to set the information needed to initiate the workflow.",
"icon": "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-Start.png",
"subTitle": "",
"title": "Start"
},
"outputs": [
{
"type": "string",
"name": "input",
"required": false
}
],
"trigger_parameters": [
{
"type": "string",
"name": "input",
"required": false
}
]
}
},
{
"id": "900001",
"type": "2",
"meta": {
"position": {
"x": 1000,
"y": 0
}
},
"data": {
"nodeMeta": {
"description": "The final node of the workflow, used to return the result information after the workflow runs.",
"icon": "https://lf3-static.bytednsdoc.com/obj/eden-cn/dvsmryvd_avi_dvsm/ljhwZthlaukjlkulzlp/icon/icon-End.png",
"subTitle": "",
"title": "End"
},
"inputs": {
"terminatePlan": "returnVariables",
"inputParameters": [
{
"name": "output",
"input": {
"type": "string",
"value": {
"type": "ref",
"content": {
"source": "block-output",
"blockID": "",
"name": ""
}
}
}
}
]
}
}
}
],
"edges": [],
"versions": {
"loop": "v2"
}
}`
func GetDefaultInitCanvasJsonSchema(locale i18n.Locale) string {
return ternary.IFElse(locale == i18n.LocaleEN, defaultEnUSInitCanvasJsonSchema, defaultZhCNInitCanvasJsonSchema)
}

View File

@@ -47,12 +47,6 @@ type FieldSource struct {
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"`

View File

@@ -69,13 +69,6 @@ type IDVersionPair struct {
Version string
}
type Stage uint8
const (
StageDraft Stage = 1
StagePublished Stage = 2
)
type WorkflowBasic struct {
ID int64
Version string