Skip to content

Commit 4381c8b

Browse files
authored
Merge branch 'main' into fix/tavily-api-key-param
2 parents 9e9408d + f05af6c commit 4381c8b

8 files changed

Lines changed: 397 additions & 230 deletions

File tree

packages/server/src/Interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ export interface IExecution {
189189

190190
export type ScheduleInputMode = 'text' | 'form' | 'none'
191191

192+
export type StartInputType = 'chatInput' | 'formInput' | 'webhookTrigger' | 'scheduleInput'
193+
192194
export interface IScheduleRecord {
193195
id: string
194196
triggerType: string

packages/server/src/controllers/webhook-listener/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { StatusCodes } from 'http-status-codes'
33
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
44
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
55
import { getWebhookListenerRegistry } from '../../services/webhook-listener'
6-
import { IReactFlowObject } from '../../Interface'
6+
import { IReactFlowObject, StartInputType } from '../../Interface'
77
import chatflowsService from '../../services/chatflows'
88
import logger from '../../utils/logger'
99

@@ -16,7 +16,8 @@ const assertChatflowIsWebhookTriggered = async (chatflowid: string, workspaceId?
1616
}
1717
const parsedFlowData: IReactFlowObject = JSON.parse(chatflow.flowData)
1818
const startNode = parsedFlowData.nodes.find((node) => node.data.name === 'startAgentflow')
19-
if (startNode?.data?.inputs?.startInputType !== 'webhookTrigger') {
19+
const startInputType = startNode?.data?.inputs?.startInputType as StartInputType | undefined
20+
if (startInputType !== 'webhookTrigger') {
2021
throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, `Chatflow ${chatflowid} is not configured as a webhook trigger`)
2122
}
2223
}

packages/server/src/services/chatflows/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ICommonObject, removeFolderFromStorage } from 'flowise-components'
33
import { StatusCodes } from 'http-status-codes'
44
import { Brackets, In, QueryRunner } from 'typeorm'
55
import { validate as isValidUUID } from 'uuid'
6-
import { ChatflowType, IReactFlowObject, ScheduleInputMode } from '../../Interface'
6+
import { ChatflowType, IReactFlowObject, ScheduleInputMode, StartInputType } from '../../Interface'
77
import { FLOWISE_COUNTER_STATUS, FLOWISE_METRIC_COUNTERS } from '../../Interface.Metrics'
88
import { UsageCacheManager } from '../../UsageCacheManager'
99
import { ChatFlow, EnumChatflowType } from '../../database/entities/ChatFlow'
@@ -381,7 +381,7 @@ const saveChatflow = async (
381381
const parsedFlowData: IReactFlowObject = JSON.parse(flowData)
382382
const nodes = (parsedFlowData.nodes || []).filter((node) => node.data.name !== 'stickyNoteAgentflow')
383383
const startNode = nodes.find((node) => node.data.name === 'startAgentflow')
384-
const startInputType = startNode?.data?.inputs?.startInputType as 'chatInput' | 'formInput' | 'scheduleInput'
384+
const startInputType = startNode?.data?.inputs?.startInputType as StartInputType | undefined
385385
if (startInputType === 'scheduleInput') {
386386
const scheduleInputMode = startNode?.data?.inputs?.scheduleInputMode as ScheduleInputMode | undefined
387387
if (!scheduleInputMode) {
@@ -493,7 +493,7 @@ const updateChatflow = async (
493493
const parsedFlowData: IReactFlowObject = JSON.parse(flowData)
494494
const nodes = (parsedFlowData.nodes || []).filter((node) => node.data.name !== 'stickyNoteAgentflow')
495495
const startNode = nodes.find((node) => node.data.name === 'startAgentflow')
496-
const startInputType = startNode?.data?.inputs?.startInputType as 'chatInput' | 'formInput' | 'scheduleInput'
496+
const startInputType = startNode?.data?.inputs?.startInputType as StartInputType | undefined
497497
if (startInputType === 'scheduleInput') {
498498
const scheduleInputMode = startNode?.data?.inputs?.scheduleInputMode as ScheduleInputMode | undefined
499499
if (!scheduleInputMode) {

packages/server/src/services/mcp-endpoint/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { createMockRequest } from '../../utils/mockRequest'
1111
import mcpServerService from '../mcp-server/index'
1212
import { ChatFlow } from '../../database/entities/ChatFlow'
1313
import logger from '../../utils/logger'
14-
import { ChatType, IMcpServerConfig, IReactFlowObject } from '../../Interface'
14+
import { ChatType, IMcpServerConfig, IReactFlowObject, StartInputType } from '../../Interface'
1515

1616
/**
1717
* Build the MCP tool name from config + chatflow
@@ -49,7 +49,7 @@ function getToolInputType(chatflow: ChatFlow): 'question' | 'form' {
4949
const flowData: IReactFlowObject = JSON.parse(chatflow.flowData)
5050
const nodes = flowData.nodes || []
5151
const startNode = nodes.find((node) => node.data.name === 'startAgentflow')
52-
const startInputType = startNode?.data?.inputs?.startInputType as 'chatInput' | 'formInput'
52+
const startInputType = startNode?.data?.inputs?.startInputType as StartInputType | undefined
5353
return startInputType === 'formInput' ? 'form' : 'question'
5454
} catch (error) {
5555
logger.error(`Failed to parse flowData for chatflow ${chatflow.id}: ${getErrorMessage(error)}`)

packages/server/src/services/schedule/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
canScheduleEnable
2020
} from './utils'
2121
import { ICommonObject } from 'flowise-components'
22-
import { ScheduleInputMode } from '../../Interface'
22+
import { ScheduleInputMode, StartInputType } from '../../Interface'
2323

2424
export {
2525
validateCronExpression,
@@ -220,7 +220,8 @@ const getScheduleStatus = async (
220220
try {
221221
const parsedFlowData = JSON.parse(chatflow.flowData)
222222
const startNode = (parsedFlowData.nodes || []).find((n: any) => n.data?.name === 'startAgentflow')
223-
if (!startNode || startNode.data?.inputs?.startInputType !== 'scheduleInput') {
223+
const startInputType = startNode?.data?.inputs?.startInputType as StartInputType | undefined
224+
if (!startNode || startInputType !== 'scheduleInput') {
224225
return { record, canEnable: false, reason: 'Flow is not configured as a scheduled flow' }
225226
}
226227

packages/server/src/services/webhook/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { StatusCodes } from 'http-status-codes'
2-
import { IReactFlowObject } from '../../Interface'
2+
import { IReactFlowObject, StartInputType } from '../../Interface'
33
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
44
import { getErrorMessage } from '../../errors/utils'
55
import { verifyWebhookSignature, verifyPlainToken } from '../../utils/signatureVerification'
@@ -23,7 +23,7 @@ const validateWebhookChatflow = async (
2323

2424
const parsedFlowData: IReactFlowObject = JSON.parse(chatflow.flowData)
2525
const startNode = parsedFlowData.nodes.find((node) => node.data.name === 'startAgentflow')
26-
const startInputType = startNode?.data?.inputs?.startInputType
26+
const startInputType = startNode?.data?.inputs?.startInputType as StartInputType | undefined
2727

2828
if (startInputType !== 'webhookTrigger') {
2929
throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Chatflow ${chatflowId} is not configured as a webhook trigger`)

packages/server/src/utils/buildAgentflow.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import {
3030
IComponentNodes,
3131
INodeOverrides,
3232
IVariableOverride,
33-
INodeDirectedGraph
33+
INodeDirectedGraph,
34+
StartInputType
3435
} from '../Interface'
3536
import {
3637
RUNTIME_MESSAGES_LENGTH_VAR_PREFIX,
@@ -60,6 +61,8 @@ import { Telemetry } from './telemetry'
6061
import { getWorkspaceSearchOptions } from '../enterprise/utils/ControllerServiceUtils'
6162
import { UsageCacheManager } from '../UsageCacheManager'
6263
import { generateTTSForResponseStream, shouldAutoPlayTTS } from './buildChatflow'
64+
import { InternalFlowiseError } from '../errors/internalFlowiseError'
65+
import { StatusCodes } from 'http-status-codes'
6366

6467
interface IWaitingNode {
6568
nodeId: string
@@ -1592,10 +1595,26 @@ export const executeAgentFlow = async ({
15921595
const { graph, nodeDependencies } = constructGraphs(nodes, edges)
15931596
const { graph: reversedGraph } = constructGraphs(nodes, edges, { isReversed: true })
15941597
const startNode = nodes.find((node) => node.data.name === 'startAgentflow')
1595-
const startInputType = startNode?.data.inputs?.startInputType as 'chatInput' | 'formInput' | 'webhookTrigger'
1598+
const startInputType = startNode?.data.inputs?.startInputType as StartInputType | undefined
15961599
if (!startInputType && !isRecursive) {
15971600
throw new Error('Start input type not found')
15981601
}
1602+
1603+
if (!isRecursive) {
1604+
if (startInputType === 'webhookTrigger' && chatType !== ChatType.WEBHOOK) {
1605+
const configuredMethod = ((startNode?.data?.inputs?.webhookMethod as string) || 'POST').toUpperCase()
1606+
throw new InternalFlowiseError(
1607+
StatusCodes.BAD_REQUEST,
1608+
`This flow is configured as a Webhook Trigger. Call ${configuredMethod} /api/v1/webhook/${chatflowid} instead of the prediction API.`
1609+
)
1610+
}
1611+
if (startInputType === 'scheduleInput' && chatType !== ChatType.SCHEDULED) {
1612+
throw new InternalFlowiseError(
1613+
StatusCodes.BAD_REQUEST,
1614+
`This flow is configured as a Scheduled Trigger. It is fired by the scheduler and cannot be invoked via the API. Change the Start node Input Type to Chat or Form to call it from the prediction API.`
1615+
)
1616+
}
1617+
}
15991618
// @ts-ignore
16001619
if (isTool) sseStreamer = undefined // If the request is from ChatflowTool, don't stream the response
16011620

0 commit comments

Comments
 (0)