mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 19:00:59 +03:00
Chore/refractor (#4454)
* markdown files and env examples cleanup * components update * update jsonlines description * server refractor * update telemetry * add execute custom node * add ui refractor * add username and password authenticate * correctly retrieve past images in agentflowv2 * disable e2e temporarily * add existing username and password authenticate * update migration to default workspace * update todo * blob storage migrating * throw error on agent tool call error * add missing execution import * add referral * chore: add error message when importData is undefined * migrate api keys to db * fix: data too long for column executionData * migrate api keys from json to db at init * add info on account setup * update docstore missing fields --------- Co-authored-by: chungyau97 <chungyau97@gmail.com>
This commit is contained in:
@@ -52,6 +52,8 @@ import { utilAddChatMessage } from './addChatMesage'
|
||||
import { CachePool } from '../CachePool'
|
||||
import { ChatMessage } from '../database/entities/ChatMessage'
|
||||
import { Telemetry } from './telemetry'
|
||||
import { getWorkspaceSearchOptions } from '../enterprise/utils/ControllerServiceUtils'
|
||||
import { UsageCacheManager } from '../UsageCacheManager'
|
||||
|
||||
interface IWaitingNode {
|
||||
nodeId: string
|
||||
@@ -99,9 +101,11 @@ interface IExecuteNodeParams {
|
||||
chatId: string
|
||||
sessionId: string
|
||||
apiMessageId: string
|
||||
evaluationRunId?: string
|
||||
isInternal: boolean
|
||||
pastChatHistory: IMessage[]
|
||||
appDataSource: DataSource
|
||||
usageCacheManager: UsageCacheManager
|
||||
telemetry: Telemetry
|
||||
componentNodes: IComponentNodes
|
||||
cachePool: CachePool
|
||||
@@ -122,6 +126,9 @@ interface IExecuteNodeParams {
|
||||
parentExecutionId?: string
|
||||
isRecursive?: boolean
|
||||
iterationContext?: ICommonObject
|
||||
orgId: string
|
||||
workspaceId: string
|
||||
subscriptionId: string
|
||||
}
|
||||
|
||||
interface IExecuteAgentFlowParams extends Omit<IExecuteFlowParams, 'incomingInput'> {
|
||||
@@ -142,13 +149,15 @@ const addExecution = async (
|
||||
appDataSource: DataSource,
|
||||
agentflowId: string,
|
||||
agentFlowExecutedData: IAgentflowExecutedData[],
|
||||
sessionId: string
|
||||
sessionId: string,
|
||||
workspaceId: string
|
||||
) => {
|
||||
const newExecution = new Execution()
|
||||
const bodyExecution = {
|
||||
agentflowId,
|
||||
state: 'INPROGRESS',
|
||||
sessionId,
|
||||
workspaceId,
|
||||
executionData: JSON.stringify(agentFlowExecutedData)
|
||||
}
|
||||
Object.assign(newExecution, bodyExecution)
|
||||
@@ -164,9 +173,10 @@ const addExecution = async (
|
||||
* @param {Partial<IExecution>} data
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const updateExecution = async (appDataSource: DataSource, executionId: string, data?: Partial<IExecution>) => {
|
||||
const updateExecution = async (appDataSource: DataSource, executionId: string, workspaceId: string, data?: Partial<IExecution>) => {
|
||||
const execution = await appDataSource.getRepository(Execution).findOneBy({
|
||||
id: executionId
|
||||
id: executionId,
|
||||
workspaceId
|
||||
})
|
||||
|
||||
if (!execution) {
|
||||
@@ -770,9 +780,11 @@ const executeNode = async ({
|
||||
chatId,
|
||||
sessionId,
|
||||
apiMessageId,
|
||||
evaluationRunId,
|
||||
parentExecutionId,
|
||||
pastChatHistory,
|
||||
appDataSource,
|
||||
usageCacheManager,
|
||||
telemetry,
|
||||
componentNodes,
|
||||
cachePool,
|
||||
@@ -792,7 +804,10 @@ const executeNode = async ({
|
||||
analyticHandlers,
|
||||
isInternal,
|
||||
isRecursive,
|
||||
iterationContext
|
||||
iterationContext,
|
||||
orgId,
|
||||
workspaceId,
|
||||
subscriptionId
|
||||
}: IExecuteNodeParams): Promise<{
|
||||
result: any
|
||||
shouldStop?: boolean
|
||||
@@ -824,7 +839,7 @@ const executeNode = async ({
|
||||
}
|
||||
|
||||
// Get available variables and resolve them
|
||||
const availableVariables = await appDataSource.getRepository(Variable).find()
|
||||
const availableVariables = await appDataSource.getRepository(Variable).findBy(getWorkspaceSearchOptions(workspaceId))
|
||||
|
||||
// Prepare flow config
|
||||
let updatedState = cloneDeep(agentflowRuntime.state)
|
||||
@@ -902,6 +917,9 @@ const executeNode = async ({
|
||||
|
||||
// Prepare run parameters
|
||||
const runParams = {
|
||||
orgId,
|
||||
workspaceId,
|
||||
subscriptionId,
|
||||
chatId,
|
||||
sessionId,
|
||||
chatflowid: chatflow.id,
|
||||
@@ -909,6 +927,7 @@ const executeNode = async ({
|
||||
logger,
|
||||
appDataSource,
|
||||
databaseEntities,
|
||||
usageCacheManager,
|
||||
componentNodes,
|
||||
cachePool,
|
||||
analytic: chatflow.analytic,
|
||||
@@ -922,7 +941,8 @@ const executeNode = async ({
|
||||
analyticHandlers,
|
||||
parentTraceIds,
|
||||
humanInputAction,
|
||||
iterationContext
|
||||
iterationContext,
|
||||
evaluationRunId
|
||||
}
|
||||
|
||||
// Execute node
|
||||
@@ -982,7 +1002,9 @@ const executeNode = async ({
|
||||
incomingInput,
|
||||
chatflow: iterationChatflow,
|
||||
chatId,
|
||||
evaluationRunId,
|
||||
appDataSource,
|
||||
usageCacheManager,
|
||||
telemetry,
|
||||
cachePool,
|
||||
sseStreamer,
|
||||
@@ -996,7 +1018,10 @@ const executeNode = async ({
|
||||
iterationContext: {
|
||||
...iterationContext,
|
||||
agentflowRuntime
|
||||
}
|
||||
},
|
||||
orgId,
|
||||
workspaceId,
|
||||
subscriptionId
|
||||
})
|
||||
|
||||
// Store the result
|
||||
@@ -1023,7 +1048,7 @@ const executeNode = async ({
|
||||
if (parentExecutionId) {
|
||||
try {
|
||||
logger.debug(` 📝 Updating parent execution ${parentExecutionId} with iteration ${i + 1} data`)
|
||||
await updateExecution(appDataSource, parentExecutionId, {
|
||||
await updateExecution(appDataSource, parentExecutionId, workspaceId, {
|
||||
executionData: JSON.stringify(agentFlowExecutedData)
|
||||
})
|
||||
} catch (error) {
|
||||
@@ -1192,8 +1217,10 @@ export const executeAgentFlow = async ({
|
||||
incomingInput,
|
||||
chatflow,
|
||||
chatId,
|
||||
evaluationRunId,
|
||||
appDataSource,
|
||||
telemetry,
|
||||
usageCacheManager,
|
||||
cachePool,
|
||||
sseStreamer,
|
||||
baseURL,
|
||||
@@ -1204,7 +1231,10 @@ export const executeAgentFlow = async ({
|
||||
isRecursive = false,
|
||||
parentExecutionId,
|
||||
iterationContext,
|
||||
isTool = false
|
||||
isTool = false,
|
||||
orgId,
|
||||
workspaceId,
|
||||
subscriptionId
|
||||
}: IExecuteAgentFlowParams) => {
|
||||
logger.debug('\n🚀 Starting flow execution')
|
||||
|
||||
@@ -1281,7 +1311,8 @@ export const executeAgentFlow = async ({
|
||||
const previousExecutions = await appDataSource.getRepository(Execution).find({
|
||||
where: {
|
||||
sessionId,
|
||||
agentflowId: chatflowid
|
||||
agentflowId: chatflowid,
|
||||
workspaceId
|
||||
},
|
||||
order: {
|
||||
createdDate: 'DESC'
|
||||
@@ -1344,7 +1375,7 @@ export const executeAgentFlow = async ({
|
||||
agentflowRuntime.state = (lastState as ICommonObject) ?? {}
|
||||
|
||||
// Update execution state to INPROGRESS
|
||||
await updateExecution(appDataSource, previousExecution.id, {
|
||||
await updateExecution(appDataSource, previousExecution.id, workspaceId, {
|
||||
state: 'INPROGRESS'
|
||||
})
|
||||
newExecution = previousExecution
|
||||
@@ -1357,7 +1388,7 @@ export const executeAgentFlow = async ({
|
||||
// For recursive calls with a valid parent execution ID, don't create a new execution
|
||||
// Instead, fetch the parent execution to use it
|
||||
const parentExecution = await appDataSource.getRepository(Execution).findOne({
|
||||
where: { id: parentExecutionId }
|
||||
where: { id: parentExecutionId, workspaceId }
|
||||
})
|
||||
|
||||
if (parentExecution) {
|
||||
@@ -1365,7 +1396,7 @@ export const executeAgentFlow = async ({
|
||||
newExecution = parentExecution
|
||||
} else {
|
||||
console.warn(` ⚠️ Parent execution ID ${parentExecutionId} not found, will create new execution`)
|
||||
newExecution = await addExecution(appDataSource, chatflowid, agentFlowExecutedData, sessionId)
|
||||
newExecution = await addExecution(appDataSource, chatflowid, agentFlowExecutedData, sessionId, workspaceId)
|
||||
parentExecutionId = newExecution.id
|
||||
}
|
||||
} else {
|
||||
@@ -1374,7 +1405,7 @@ export const executeAgentFlow = async ({
|
||||
checkForMultipleStartNodes(startingNodeIds, isRecursive, nodes)
|
||||
|
||||
// Only create a new execution if this is not a recursive call
|
||||
newExecution = await addExecution(appDataSource, chatflowid, agentFlowExecutedData, sessionId)
|
||||
newExecution = await addExecution(appDataSource, chatflowid, agentFlowExecutedData, sessionId, workspaceId)
|
||||
parentExecutionId = newExecution.id
|
||||
}
|
||||
|
||||
@@ -1430,6 +1461,8 @@ export const executeAgentFlow = async ({
|
||||
try {
|
||||
if (chatflow.analytic) {
|
||||
analyticHandlers = AnalyticHandler.getInstance({ inputs: {} } as any, {
|
||||
orgId,
|
||||
workspaceId,
|
||||
appDataSource,
|
||||
databaseEntities,
|
||||
componentNodes,
|
||||
@@ -1486,10 +1519,12 @@ export const executeAgentFlow = async ({
|
||||
chatId,
|
||||
sessionId,
|
||||
apiMessageId,
|
||||
evaluationRunId,
|
||||
parentExecutionId,
|
||||
isInternal,
|
||||
pastChatHistory,
|
||||
appDataSource,
|
||||
usageCacheManager,
|
||||
telemetry,
|
||||
componentNodes,
|
||||
cachePool,
|
||||
@@ -1508,7 +1543,10 @@ export const executeAgentFlow = async ({
|
||||
parentTraceIds,
|
||||
analyticHandlers,
|
||||
isRecursive,
|
||||
iterationContext
|
||||
iterationContext,
|
||||
orgId,
|
||||
workspaceId,
|
||||
subscriptionId
|
||||
})
|
||||
|
||||
if (executionResult.agentFlowExecutedData) {
|
||||
@@ -1607,7 +1645,7 @@ export const executeAgentFlow = async ({
|
||||
if (!isRecursive) {
|
||||
sseStreamer?.streamAgentFlowExecutedDataEvent(chatId, agentFlowExecutedData)
|
||||
|
||||
await updateExecution(appDataSource, newExecution.id, {
|
||||
await updateExecution(appDataSource, newExecution.id, workspaceId, {
|
||||
executionData: JSON.stringify(agentFlowExecutedData),
|
||||
state: errorStatus
|
||||
})
|
||||
@@ -1642,7 +1680,7 @@ export const executeAgentFlow = async ({
|
||||
|
||||
// Only update execution record if this is not a recursive call
|
||||
if (!isRecursive) {
|
||||
await updateExecution(appDataSource, newExecution.id, {
|
||||
await updateExecution(appDataSource, newExecution.id, workspaceId, {
|
||||
executionData: JSON.stringify(agentFlowExecutedData),
|
||||
state: status
|
||||
})
|
||||
@@ -1744,6 +1782,8 @@ export const executeAgentFlow = async ({
|
||||
if (chatflow.followUpPrompts) {
|
||||
const followUpPromptsConfig = JSON.parse(chatflow.followUpPrompts)
|
||||
const followUpPrompts = await generateFollowUpPrompts(followUpPromptsConfig, apiMessage.content, {
|
||||
orgId,
|
||||
workspaceId,
|
||||
chatId,
|
||||
chatflowid,
|
||||
appDataSource,
|
||||
@@ -1760,13 +1800,17 @@ export const executeAgentFlow = async ({
|
||||
|
||||
logger.debug(`[server]: Finished running agentflow ${chatflowid}`)
|
||||
|
||||
await telemetry.sendTelemetry('prediction_sent', {
|
||||
version: await getAppVersion(),
|
||||
chatflowId: chatflowid,
|
||||
chatId,
|
||||
type: isInternal ? ChatType.INTERNAL : ChatType.EXTERNAL,
|
||||
flowGraph: getTelemetryFlowObj(nodes, edges)
|
||||
})
|
||||
await telemetry.sendTelemetry(
|
||||
'prediction_sent',
|
||||
{
|
||||
version: await getAppVersion(),
|
||||
chatflowId: chatflowid,
|
||||
chatId,
|
||||
type: isInternal ? ChatType.INTERNAL : ChatType.EXTERNAL,
|
||||
flowGraph: getTelemetryFlowObj(nodes, edges)
|
||||
},
|
||||
orgId
|
||||
)
|
||||
|
||||
/*** Prepare response ***/
|
||||
let result: ICommonObject = {}
|
||||
|
||||
Reference in New Issue
Block a user