mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-22 13:01:11 +03:00
5df09a15b8
* feat: Require workspace ID for API key operations - Added validation to ensure `activeWorkspaceId` is present in user requests for all API key operations (get, create, update, import, delete). - Updated `getWorkspaceSearchOptions` and `getWorkspaceSearchOptionsFromReq` to throw an error if `workspaceId` is not provided. - Modified service methods to enforce `workspaceId` as a required parameter for database operations related to API keys. * feat: Enforce workspace ID as a required field across multiple interfaces and services - Updated various interfaces to make `workspaceId` a mandatory field instead of optional. - Enhanced assistant and export-import service methods to require `workspaceId` for operations, ensuring proper validation and error handling. - Modified database entity definitions to reflect the change in `workspaceId` from optional to required. - Improved error handling in controllers to check for `activeWorkspaceId` before proceeding with requests. * Require workspace ID in various controllers and services - Updated controllers for credentials, datasets, document stores, evaluations, evaluators, and variables to enforce the presence of `workspaceId`. - Enhanced error handling to throw appropriate errors when `workspaceId` is not provided. - Modified service methods to accept `workspaceId` as a mandatory parameter for operations, ensuring consistent validation across the application. * Update EvaluatorRunner and index to require workspaceId for evaluator retrieval - Modified the runAdditionalEvaluators function to accept workspaceId as a parameter. * lint fixes * Enhancement/Integrate workspaceId in chatflow and flow-config services - Updated chatflow and flow-config controllers to require workspaceId for fetching chatflows. - Modified service methods to accept workspaceId as a parameter, ensuring proper context for chatflow retrieval. * lint fix * get rid of redundant isApiKeyValidated * refactor: update permission checks for chatflows and agentflows routes - Enhanced permission checks in chatflows routes to include agentflows permissions for create, read, update, and delete operations. - Updated navigation paths in authentication views to redirect to the home page instead of chatflows after successful login or registration. * fix(DefaultRedirect.jsx): add redirect unauthenticated users to login * fix(RequireAuth.jsx): check permissions for routes without display property * fix(DefaultRedirect.jsx): WorkspaceSwitcher api spam * fix(routes/chatflows/index.ts): use checkAnyPermission for chatflow/has-changed/:id/:lastUpdatedDateTime * fix(routes/chatflows/index.ts): use checkAnyPermission for delete request chatflow/:id * fix(controllers/text-to-speech/index.ts): add workspace ID validation in generateTextToSpeech * fix(controllers/internal-predictions/index.ts): add chatflow retrieval and validation using workspaceId * feat(services\credentials\index.ts): add filter by workspaceId for getCredentialById * chore(routes/chat-messages/index.ts): unused chat-messages route * feat(services/chatflows/index.ts): add filter by workspaceId for deleteChatflow * feat(services/marketplaces/index.ts): add filter by workspaceId for deleteCustomTemplate * feat(tools): add filter by workspaceId for read, update, and delete --------- Co-authored-by: Vinod Paidimarry <vinodkiran@outlook.in> Co-authored-by: Yau <33013947+chungyau97@users.noreply.github.com> Co-authored-by: chungyau97 <chungyau97@gmail.com>
437 lines
8.6 KiB
TypeScript
437 lines
8.6 KiB
TypeScript
import {
|
|
IAction,
|
|
ICommonObject,
|
|
IFileUpload,
|
|
IHumanInput,
|
|
INode,
|
|
INodeData as INodeDataFromComponent,
|
|
INodeExecutionData,
|
|
INodeParams,
|
|
IServerSideEventStreamer
|
|
} from 'flowise-components'
|
|
import { DataSource } from 'typeorm'
|
|
import { CachePool } from './CachePool'
|
|
import { Telemetry } from './utils/telemetry'
|
|
import { UsageCacheManager } from './UsageCacheManager'
|
|
|
|
export type MessageType = 'apiMessage' | 'userMessage'
|
|
|
|
export type ChatflowType = 'CHATFLOW' | 'MULTIAGENT' | 'ASSISTANT' | 'AGENTFLOW'
|
|
|
|
export type AssistantType = 'CUSTOM' | 'OPENAI' | 'AZURE'
|
|
|
|
export type ExecutionState = 'INPROGRESS' | 'FINISHED' | 'ERROR' | 'TERMINATED' | 'TIMEOUT' | 'STOPPED'
|
|
|
|
export enum MODE {
|
|
QUEUE = 'queue',
|
|
MAIN = 'main'
|
|
}
|
|
|
|
export enum ChatType {
|
|
INTERNAL = 'INTERNAL',
|
|
EXTERNAL = 'EXTERNAL',
|
|
EVALUATION = 'EVALUATION'
|
|
}
|
|
|
|
export enum ChatMessageRatingType {
|
|
THUMBS_UP = 'THUMBS_UP',
|
|
THUMBS_DOWN = 'THUMBS_DOWN'
|
|
}
|
|
|
|
export enum Platform {
|
|
OPEN_SOURCE = 'open source',
|
|
CLOUD = 'cloud',
|
|
ENTERPRISE = 'enterprise'
|
|
}
|
|
|
|
export enum UserPlan {
|
|
STARTER = 'STARTER',
|
|
PRO = 'PRO',
|
|
FREE = 'FREE'
|
|
}
|
|
|
|
/**
|
|
* Databases
|
|
*/
|
|
export interface IChatFlow {
|
|
id: string
|
|
name: string
|
|
flowData: string
|
|
updatedDate: Date
|
|
createdDate: Date
|
|
deployed?: boolean
|
|
isPublic?: boolean
|
|
apikeyid?: string
|
|
analytic?: string
|
|
speechToText?: string
|
|
textToSpeech?: string
|
|
chatbotConfig?: string
|
|
followUpPrompts?: string
|
|
apiConfig?: string
|
|
category?: string
|
|
type?: ChatflowType
|
|
workspaceId: string
|
|
}
|
|
|
|
export interface IChatMessage {
|
|
id: string
|
|
role: MessageType
|
|
content: string
|
|
chatflowid: string
|
|
executionId?: string
|
|
sourceDocuments?: string
|
|
usedTools?: string
|
|
fileAnnotations?: string
|
|
agentReasoning?: string
|
|
fileUploads?: string
|
|
artifacts?: string
|
|
chatType: string
|
|
chatId: string
|
|
memoryType?: string
|
|
sessionId?: string
|
|
createdDate: Date
|
|
leadEmail?: string
|
|
action?: string | null
|
|
followUpPrompts?: string
|
|
}
|
|
|
|
export interface IChatMessageFeedback {
|
|
id: string
|
|
content?: string
|
|
chatflowid: string
|
|
chatId: string
|
|
messageId: string
|
|
rating: ChatMessageRatingType
|
|
createdDate: Date
|
|
}
|
|
|
|
export interface ITool {
|
|
id: string
|
|
name: string
|
|
description: string
|
|
color: string
|
|
iconSrc?: string
|
|
schema?: string
|
|
func?: string
|
|
updatedDate: Date
|
|
createdDate: Date
|
|
workspaceId: string
|
|
}
|
|
|
|
export interface IAssistant {
|
|
id: string
|
|
details: string
|
|
credential: string
|
|
iconSrc?: string
|
|
updatedDate: Date
|
|
createdDate: Date
|
|
workspaceId: string
|
|
}
|
|
|
|
export interface ICredential {
|
|
id: string
|
|
name: string
|
|
credentialName: string
|
|
encryptedData: string
|
|
updatedDate: Date
|
|
createdDate: Date
|
|
workspaceId: string
|
|
}
|
|
|
|
export interface IVariable {
|
|
id: string
|
|
name: string
|
|
value: string
|
|
type: string
|
|
updatedDate: Date
|
|
createdDate: Date
|
|
workspaceId: string
|
|
}
|
|
|
|
export interface ILead {
|
|
id: string
|
|
name?: string
|
|
email?: string
|
|
phone?: string
|
|
chatflowid: string
|
|
chatId: string
|
|
createdDate: Date
|
|
}
|
|
|
|
export interface IUpsertHistory {
|
|
id: string
|
|
chatflowid: string
|
|
result: string
|
|
flowData: string
|
|
date: Date
|
|
}
|
|
|
|
export interface IExecution {
|
|
id: string
|
|
executionData: string
|
|
state: ExecutionState
|
|
agentflowId: string
|
|
sessionId: string
|
|
isPublic?: boolean
|
|
action?: string
|
|
createdDate: Date
|
|
updatedDate: Date
|
|
stoppedDate: Date
|
|
workspaceId: string
|
|
}
|
|
|
|
export interface IComponentNodes {
|
|
[key: string]: INode
|
|
}
|
|
|
|
export interface IComponentCredentials {
|
|
[key: string]: INode
|
|
}
|
|
|
|
export interface IVariableDict {
|
|
[key: string]: string
|
|
}
|
|
|
|
export interface INodeDependencies {
|
|
[key: string]: number
|
|
}
|
|
|
|
export interface INodeDirectedGraph {
|
|
[key: string]: string[]
|
|
}
|
|
|
|
export interface INodeData extends INodeDataFromComponent {
|
|
inputAnchors: INodeParams[]
|
|
inputParams: INodeParams[]
|
|
outputAnchors: INodeParams[]
|
|
}
|
|
|
|
export interface IReactFlowNode {
|
|
id: string
|
|
position: {
|
|
x: number
|
|
y: number
|
|
}
|
|
type: string
|
|
data: INodeData
|
|
positionAbsolute: {
|
|
x: number
|
|
y: number
|
|
}
|
|
z: number
|
|
handleBounds: {
|
|
source: any
|
|
target: any
|
|
}
|
|
width: number
|
|
height: number
|
|
selected: boolean
|
|
dragging: boolean
|
|
parentNode?: string
|
|
extent?: string
|
|
}
|
|
|
|
export interface IReactFlowEdge {
|
|
source: string
|
|
sourceHandle: string
|
|
target: string
|
|
targetHandle: string
|
|
type: string
|
|
id: string
|
|
data: {
|
|
label: string
|
|
}
|
|
}
|
|
|
|
export interface IReactFlowObject {
|
|
nodes: IReactFlowNode[]
|
|
edges: IReactFlowEdge[]
|
|
viewport: {
|
|
x: number
|
|
y: number
|
|
zoom: number
|
|
}
|
|
}
|
|
|
|
export interface IExploredNode {
|
|
[key: string]: {
|
|
remainingLoop: number
|
|
lastSeenDepth: number
|
|
}
|
|
}
|
|
|
|
export interface INodeQueue {
|
|
nodeId: string
|
|
depth: number
|
|
}
|
|
|
|
export interface IDepthQueue {
|
|
[key: string]: number
|
|
}
|
|
|
|
export interface IAgentflowExecutedData {
|
|
nodeLabel: string
|
|
nodeId: string
|
|
data: INodeExecutionData
|
|
previousNodeIds: string[]
|
|
status?: ExecutionState
|
|
}
|
|
|
|
export interface IMessage {
|
|
message: string
|
|
type: MessageType
|
|
role?: MessageType
|
|
content?: string
|
|
}
|
|
|
|
export interface IncomingInput {
|
|
question: string
|
|
overrideConfig?: ICommonObject
|
|
chatId?: string
|
|
sessionId?: string
|
|
stopNodeId?: string
|
|
uploads?: IFileUpload[]
|
|
leadEmail?: string
|
|
history?: IMessage[]
|
|
action?: IAction
|
|
streaming?: boolean
|
|
}
|
|
|
|
export interface IncomingAgentflowInput extends Omit<IncomingInput, 'question'> {
|
|
question?: string
|
|
form?: Record<string, any>
|
|
humanInput?: IHumanInput
|
|
}
|
|
|
|
export interface IActiveChatflows {
|
|
[key: string]: {
|
|
startingNodes: IReactFlowNode[]
|
|
endingNodeData?: INodeData
|
|
inSync: boolean
|
|
overrideConfig?: ICommonObject
|
|
chatId?: string
|
|
}
|
|
}
|
|
|
|
export interface IActiveCache {
|
|
[key: string]: Map<any, any>
|
|
}
|
|
|
|
export interface IOverrideConfig {
|
|
node: string
|
|
nodeId: string
|
|
label: string
|
|
name: string
|
|
type: string
|
|
schema?: ICommonObject[] | Record<string, string>
|
|
}
|
|
|
|
export type ICredentialDataDecrypted = ICommonObject
|
|
|
|
// Plain credential object sent to server
|
|
export interface ICredentialReqBody {
|
|
name: string
|
|
credentialName: string
|
|
plainDataObj: ICredentialDataDecrypted
|
|
workspaceId: string
|
|
}
|
|
|
|
// Decrypted credential object sent back to client
|
|
export interface ICredentialReturnResponse extends ICredential {
|
|
plainDataObj: ICredentialDataDecrypted
|
|
}
|
|
|
|
export interface IUploadFileSizeAndTypes {
|
|
fileTypes: string[]
|
|
maxUploadSize: number
|
|
}
|
|
|
|
export interface IApiKey {
|
|
id: string
|
|
keyName: string
|
|
apiKey: string
|
|
apiSecret: string
|
|
updatedDate: Date
|
|
workspaceId: string
|
|
}
|
|
|
|
export interface ICustomTemplate {
|
|
id: string
|
|
name: string
|
|
flowData: string
|
|
updatedDate: Date
|
|
createdDate: Date
|
|
description?: string
|
|
type?: string
|
|
badge?: string
|
|
framework?: string
|
|
usecases?: string
|
|
workspaceId: string
|
|
}
|
|
|
|
export interface IFlowConfig {
|
|
chatflowid: string
|
|
chatflowId: string
|
|
chatId: string
|
|
sessionId: string
|
|
chatHistory: IMessage[]
|
|
apiMessageId: string
|
|
overrideConfig?: ICommonObject
|
|
state?: ICommonObject
|
|
runtimeChatHistoryLength?: number
|
|
}
|
|
|
|
export interface IPredictionQueueAppServer {
|
|
appDataSource: DataSource
|
|
componentNodes: IComponentNodes
|
|
sseStreamer: IServerSideEventStreamer
|
|
telemetry: Telemetry
|
|
cachePool: CachePool
|
|
usageCacheManager: UsageCacheManager
|
|
}
|
|
|
|
export interface IExecuteFlowParams extends IPredictionQueueAppServer {
|
|
incomingInput: IncomingInput
|
|
chatflow: IChatFlow
|
|
chatId: string
|
|
orgId: string
|
|
workspaceId: string
|
|
subscriptionId: string
|
|
productId: string
|
|
baseURL: string
|
|
isInternal: boolean
|
|
isEvaluation?: boolean
|
|
evaluationRunId?: string
|
|
signal?: AbortController
|
|
files?: Express.Multer.File[]
|
|
fileUploads?: IFileUpload[]
|
|
uploadedFilesContent?: string
|
|
isUpsert?: boolean
|
|
isRecursive?: boolean
|
|
parentExecutionId?: string
|
|
iterationContext?: ICommonObject
|
|
isTool?: boolean
|
|
}
|
|
|
|
export interface INodeOverrides {
|
|
[key: string]: {
|
|
label: string
|
|
name: string
|
|
type: string
|
|
enabled: boolean
|
|
}[]
|
|
}
|
|
|
|
export interface IVariableOverride {
|
|
id: string
|
|
name: string
|
|
type: 'static' | 'runtime'
|
|
enabled: boolean
|
|
}
|
|
|
|
// DocumentStore related
|
|
export * from './Interface.DocumentStore'
|
|
|
|
// Evaluations related
|
|
export * from './Interface.Evaluation'
|