mirror of
https://github.com/langgenius/dify.git
synced 2026-03-07 08:35:58 +08:00
Merge remote-tracking branch 'origin/main' into feat/trigger
This commit is contained in:
37
web/app/components/workflow/utils/data-source.ts
Normal file
37
web/app/components/workflow/utils/data-source.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import type {
|
||||
InputVar,
|
||||
ToolWithProvider,
|
||||
} from '../types'
|
||||
import type { DataSourceNodeType } from '../nodes/data-source/types'
|
||||
import { CollectionType } from '@/app/components/tools/types'
|
||||
import { toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema'
|
||||
|
||||
export const getDataSourceCheckParams = (
|
||||
toolData: DataSourceNodeType,
|
||||
dataSourceList: ToolWithProvider[],
|
||||
language: string,
|
||||
) => {
|
||||
const { plugin_id, provider_type, datasource_name } = toolData
|
||||
const isBuiltIn = provider_type === CollectionType.builtIn
|
||||
const currentDataSource = dataSourceList.find(item => item.plugin_id === plugin_id)
|
||||
const currentDataSourceItem = currentDataSource?.tools.find(tool => tool.name === datasource_name)
|
||||
const formSchemas = currentDataSourceItem ? toolParametersToFormSchemas(currentDataSourceItem.parameters) : []
|
||||
|
||||
return {
|
||||
dataSourceInputsSchema: (() => {
|
||||
const formInputs: InputVar[] = []
|
||||
formSchemas.forEach((item: any) => {
|
||||
formInputs.push({
|
||||
label: item.label[language] || item.label.en_US,
|
||||
variable: item.variable,
|
||||
type: item.type,
|
||||
required: item.required,
|
||||
hide: item.hide,
|
||||
})
|
||||
})
|
||||
return formInputs
|
||||
})(),
|
||||
notAuthed: isBuiltIn && !!currentDataSource?.allow_delete && !currentDataSource?.is_authorized,
|
||||
language,
|
||||
}
|
||||
}
|
||||
43
web/app/components/workflow/utils/gen-node-meta-data.ts
Normal file
43
web/app/components/workflow/utils/gen-node-meta-data.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { BlockClassificationEnum } from '@/app/components/workflow/block-selector/types'
|
||||
import type { BlockEnum } from '@/app/components/workflow/types'
|
||||
|
||||
export type GenNodeMetaDataParams = {
|
||||
classification?: BlockClassificationEnum
|
||||
sort: number
|
||||
type: BlockEnum
|
||||
title?: string
|
||||
author?: string
|
||||
helpLinkUri?: string
|
||||
isRequired?: boolean
|
||||
isUndeletable?: boolean
|
||||
isStart?: boolean
|
||||
isSingleton?: boolean
|
||||
isTypeFixed?: boolean
|
||||
}
|
||||
export const genNodeMetaData = ({
|
||||
classification = BlockClassificationEnum.Default,
|
||||
sort,
|
||||
type,
|
||||
title = '',
|
||||
author = 'Dify',
|
||||
helpLinkUri,
|
||||
isRequired = false,
|
||||
isUndeletable = false,
|
||||
isStart = false,
|
||||
isSingleton = false,
|
||||
isTypeFixed = false,
|
||||
}: GenNodeMetaDataParams) => {
|
||||
return {
|
||||
classification,
|
||||
sort,
|
||||
type,
|
||||
title,
|
||||
author,
|
||||
helpLinkUri: helpLinkUri || type,
|
||||
isRequired,
|
||||
isUndeletable,
|
||||
isStart,
|
||||
isSingleton,
|
||||
isTypeFixed,
|
||||
}
|
||||
}
|
||||
@ -6,3 +6,5 @@ export * from './common'
|
||||
export * from './tool'
|
||||
export * from './workflow'
|
||||
export * from './variable'
|
||||
export * from './gen-node-meta-data'
|
||||
export * from './data-source'
|
||||
|
||||
@ -135,6 +135,13 @@ export const getTopLeftNodePosition = (nodes: Node[]) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const getNestedNodePosition = (node: Node, parentNode: Node) => {
|
||||
return {
|
||||
x: node.position.x - parentNode.position.x,
|
||||
y: node.position.y - parentNode.position.y,
|
||||
}
|
||||
}
|
||||
|
||||
export const hasRetryNode = (nodeType?: BlockEnum) => {
|
||||
return nodeType === BlockEnum.LLM || nodeType === BlockEnum.Tool || nodeType === BlockEnum.HttpRequest || nodeType === BlockEnum.Code
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@ import type { ToolNodeType } from '../nodes/tool/types'
|
||||
import { CollectionType } from '@/app/components/tools/types'
|
||||
import { toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema'
|
||||
import { canFindTool } from '@/utils'
|
||||
import type { StructuredOutput } from '@/app/components/workflow/nodes/llm/types'
|
||||
import { Type } from '@/app/components/workflow/nodes/llm/types'
|
||||
|
||||
export const getToolCheckParams = (
|
||||
toolData: ToolNodeType,
|
||||
@ -41,3 +43,25 @@ export const getToolCheckParams = (
|
||||
language,
|
||||
}
|
||||
}
|
||||
|
||||
export const CHUNK_TYPE_MAP = {
|
||||
general_chunks: 'GeneralStructureChunk',
|
||||
parent_child_chunks: 'ParentChildStructureChunk',
|
||||
qa_chunks: 'QAStructureChunk',
|
||||
}
|
||||
|
||||
export const wrapStructuredVarItem = (outputItem: any, matchedSchemaType: string): StructuredOutput => {
|
||||
const dataType = Type.object
|
||||
return {
|
||||
schema: {
|
||||
type: dataType,
|
||||
properties: {
|
||||
[outputItem.name]: {
|
||||
...outputItem.value,
|
||||
schemaType: matchedSchemaType,
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,8 +16,6 @@ import type {
|
||||
import {
|
||||
BlockEnum,
|
||||
} from '../types'
|
||||
import type { IterationNodeType } from '../nodes/iteration/types'
|
||||
import type { LoopNodeType } from '../nodes/loop/types'
|
||||
|
||||
export const canRunBySingle = (nodeType: BlockEnum, isChildNode: boolean) => {
|
||||
// child node means in iteration or loop. Set value to iteration(or loop) may cause variable not exit problem in backend.
|
||||
@ -39,6 +37,11 @@ export const canRunBySingle = (nodeType: BlockEnum, isChildNode: boolean) => {
|
||||
|| nodeType === BlockEnum.IfElse
|
||||
|| nodeType === BlockEnum.VariableAggregator
|
||||
|| nodeType === BlockEnum.Assigner
|
||||
|| nodeType === BlockEnum.DataSource
|
||||
}
|
||||
|
||||
export const isSupportCustomRunForm = (nodeType: BlockEnum) => {
|
||||
return nodeType === BlockEnum.DataSource
|
||||
}
|
||||
|
||||
type ConnectedSourceOrTargetNodesChange = {
|
||||
@ -93,16 +96,8 @@ export const getNodesConnectedSourceOrTargetHandleIdsMap = (changes: ConnectedSo
|
||||
return nodesConnectedSourceOrTargetHandleIdsMap
|
||||
}
|
||||
|
||||
export const getValidTreeNodes = (nodes: Node[], edges: Edge[]) => {
|
||||
// Find all start nodes (Start and Trigger nodes)
|
||||
const startNodes = nodes.filter(node =>
|
||||
node.data.type === BlockEnum.Start
|
||||
|| node.data.type === BlockEnum.TriggerSchedule
|
||||
|| node.data.type === BlockEnum.TriggerWebhook
|
||||
|| node.data.type === BlockEnum.TriggerPlugin,
|
||||
)
|
||||
|
||||
if (startNodes.length === 0) {
|
||||
export const getValidTreeNodes = (startNode: Node, nodes: Node[], edges: Edge[]) => {
|
||||
if (!startNode) {
|
||||
return {
|
||||
validNodes: [],
|
||||
maxDepth: 0,
|
||||
@ -143,11 +138,18 @@ export const getValidTreeNodes = (nodes: Node[], edges: Edge[]) => {
|
||||
}
|
||||
}
|
||||
|
||||
// Start traversal from all start nodes
|
||||
startNodes.forEach((startNode) => {
|
||||
if (!list.find(n => n.id === startNode.id))
|
||||
traverse(startNode, 1)
|
||||
})
|
||||
// const startNodes = nodes.filter(node =>
|
||||
// node.data.type === BlockEnum.Start
|
||||
// || node.data.type === BlockEnum.TriggerSchedule
|
||||
// || node.data.type === BlockEnum.TriggerWebhook
|
||||
// || node.data.type === BlockEnum.TriggerPlugin,
|
||||
// )
|
||||
|
||||
// // Start traversal from all start nodes
|
||||
// startNodes.forEach((startNode) => {
|
||||
// if (!list.find(n => n.id === startNode.id))
|
||||
// traverse(startNode, 1)
|
||||
// })
|
||||
|
||||
return {
|
||||
validNodes: uniqBy(list, 'id'),
|
||||
@ -198,24 +200,7 @@ type NodeStreamInfo = {
|
||||
upstreamNodes: Set<string>
|
||||
downstreamEdges: Set<string>
|
||||
}
|
||||
export const getParallelInfo = (nodes: Node[], edges: Edge[], parentNodeId?: string) => {
|
||||
let startNode
|
||||
|
||||
if (parentNodeId) {
|
||||
const parentNode = nodes.find(node => node.id === parentNodeId)
|
||||
if (!parentNode)
|
||||
throw new Error('Parent node not found')
|
||||
|
||||
startNode = nodes.find(node => node.id === (parentNode.data as (IterationNodeType | LoopNodeType)).start_node_id)
|
||||
}
|
||||
else {
|
||||
startNode = nodes.find(node =>
|
||||
node.data.type === BlockEnum.Start
|
||||
|| node.data.type === BlockEnum.TriggerSchedule
|
||||
|| node.data.type === BlockEnum.TriggerWebhook
|
||||
|| node.data.type === BlockEnum.TriggerPlugin,
|
||||
)
|
||||
}
|
||||
export const getParallelInfo = (startNode: Node, nodes: Node[], edges: Edge[]) => {
|
||||
if (!startNode)
|
||||
throw new Error('Start node not found')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user