mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-08 10:26:50 +08:00
Feature/newnew workflow loop node (#14863)
Co-authored-by: arkunzz <4873204@qq.com>
This commit is contained in:
@@ -8,6 +8,9 @@ import type {
|
||||
IterationFinishedResponse,
|
||||
IterationNextResponse,
|
||||
IterationStartedResponse,
|
||||
LoopFinishedResponse,
|
||||
LoopNextResponse,
|
||||
LoopStartedResponse,
|
||||
NodeFinishedResponse,
|
||||
NodeStartedResponse,
|
||||
ParallelBranchFinishedResponse,
|
||||
@@ -54,6 +57,9 @@ export type IOnTextChunk = (textChunk: TextChunkResponse) => void
|
||||
export type IOnTTSChunk = (messageId: string, audioStr: string, audioType?: string) => void
|
||||
export type IOnTTSEnd = (messageId: string, audioStr: string, audioType?: string) => void
|
||||
export type IOnTextReplace = (textReplace: TextReplaceResponse) => void
|
||||
export type IOnLoopStarted = (workflowStarted: LoopStartedResponse) => void
|
||||
export type IOnLoopNext = (workflowStarted: LoopNextResponse) => void
|
||||
export type IOnLoopFinished = (workflowFinished: LoopFinishedResponse) => void
|
||||
export type IOnAgentLog = (agentLog: AgentLogResponse) => void
|
||||
|
||||
export type IOtherOptions = {
|
||||
@@ -86,6 +92,9 @@ export type IOtherOptions = {
|
||||
onTTSChunk?: IOnTTSChunk
|
||||
onTTSEnd?: IOnTTSEnd
|
||||
onTextReplace?: IOnTextReplace
|
||||
onLoopStart?: IOnLoopStarted
|
||||
onLoopNext?: IOnLoopNext
|
||||
onLoopFinish?: IOnLoopFinished
|
||||
onAgentLog?: IOnAgentLog
|
||||
}
|
||||
|
||||
@@ -125,6 +134,9 @@ const handleStream = (
|
||||
onIterationStart?: IOnIterationStarted,
|
||||
onIterationNext?: IOnIterationNext,
|
||||
onIterationFinish?: IOnIterationFinished,
|
||||
onLoopStart?: IOnLoopStarted,
|
||||
onLoopNext?: IOnLoopNext,
|
||||
onLoopFinish?: IOnLoopFinished,
|
||||
onNodeRetry?: IOnNodeRetry,
|
||||
onParallelBranchStarted?: IOnParallelBranchStarted,
|
||||
onParallelBranchFinished?: IOnParallelBranchFinished,
|
||||
@@ -218,6 +230,15 @@ const handleStream = (
|
||||
else if (bufferObj.event === 'iteration_completed') {
|
||||
onIterationFinish?.(bufferObj as IterationFinishedResponse)
|
||||
}
|
||||
else if (bufferObj.event === 'loop_started') {
|
||||
onLoopStart?.(bufferObj as LoopStartedResponse)
|
||||
}
|
||||
else if (bufferObj.event === 'loop_next') {
|
||||
onLoopNext?.(bufferObj as LoopNextResponse)
|
||||
}
|
||||
else if (bufferObj.event === 'loop_completed') {
|
||||
onLoopFinish?.(bufferObj as LoopFinishedResponse)
|
||||
}
|
||||
else if (bufferObj.event === 'node_retry') {
|
||||
onNodeRetry?.(bufferObj as NodeFinishedResponse)
|
||||
}
|
||||
@@ -332,6 +353,9 @@ export const ssePost = (
|
||||
onAgentLog,
|
||||
onError,
|
||||
getAbortController,
|
||||
onLoopStart,
|
||||
onLoopNext,
|
||||
onLoopFinish,
|
||||
} = otherOptions
|
||||
const abortController = new AbortController()
|
||||
|
||||
@@ -361,7 +385,7 @@ export const ssePost = (
|
||||
options.body = JSON.stringify(body)
|
||||
|
||||
const accessToken = getAccessToken(isPublicAPI)
|
||||
options.headers!.set('Authorization', `Bearer ${accessToken}`)
|
||||
;(options.headers as Headers).set('Authorization', `Bearer ${accessToken}`)
|
||||
|
||||
globalThis.fetch(urlWithPrefix, options as RequestInit)
|
||||
.then((res) => {
|
||||
@@ -400,7 +424,31 @@ export const ssePost = (
|
||||
return
|
||||
}
|
||||
onData?.(str, isFirstMessage, moreInfo)
|
||||
}, onCompleted, onThought, onMessageEnd, onMessageReplace, onFile, onWorkflowStarted, onWorkflowFinished, onNodeStarted, onNodeFinished, onIterationStart, onIterationNext, onIterationFinish, onNodeRetry, onParallelBranchStarted, onParallelBranchFinished, onTextChunk, onTTSChunk, onTTSEnd, onTextReplace, onAgentLog)
|
||||
},
|
||||
onCompleted,
|
||||
onThought,
|
||||
onMessageEnd,
|
||||
onMessageReplace,
|
||||
onFile,
|
||||
onWorkflowStarted,
|
||||
onWorkflowFinished,
|
||||
onNodeStarted,
|
||||
onNodeFinished,
|
||||
onIterationStart,
|
||||
onIterationNext,
|
||||
onIterationFinish,
|
||||
onLoopStart,
|
||||
onLoopNext,
|
||||
onLoopFinish,
|
||||
onNodeRetry,
|
||||
onParallelBranchStarted,
|
||||
onParallelBranchFinished,
|
||||
onTextChunk,
|
||||
onTTSChunk,
|
||||
onTTSEnd,
|
||||
onTextReplace,
|
||||
onAgentLog,
|
||||
)
|
||||
}).catch((e) => {
|
||||
if (e.toString() !== 'AbortError: The user aborted a request.' && !e.toString().errorMessage.includes('TypeError: Cannot assign to read only property'))
|
||||
Toast.notify({ type: 'error', message: e })
|
||||
|
||||
@@ -1,4 +1,26 @@
|
||||
import type { IOnCompleted, IOnData, IOnError, IOnFile, IOnIterationFinished, IOnIterationNext, IOnIterationStarted, IOnMessageEnd, IOnMessageReplace, IOnNodeFinished, IOnNodeStarted, IOnTTSChunk, IOnTTSEnd, IOnTextChunk, IOnTextReplace, IOnThought, IOnWorkflowFinished, IOnWorkflowStarted } from './base'
|
||||
import type {
|
||||
IOnCompleted,
|
||||
IOnData,
|
||||
IOnError,
|
||||
IOnFile,
|
||||
IOnIterationFinished,
|
||||
IOnIterationNext,
|
||||
IOnIterationStarted,
|
||||
IOnLoopFinished,
|
||||
IOnLoopNext,
|
||||
IOnLoopStarted,
|
||||
IOnMessageEnd,
|
||||
IOnMessageReplace,
|
||||
IOnNodeFinished,
|
||||
IOnNodeStarted,
|
||||
IOnTTSChunk,
|
||||
IOnTTSEnd,
|
||||
IOnTextChunk,
|
||||
IOnTextReplace,
|
||||
IOnThought,
|
||||
IOnWorkflowFinished,
|
||||
IOnWorkflowStarted,
|
||||
} from './base'
|
||||
import {
|
||||
del as consoleDel, get as consoleGet, patch as consolePatch, post as consolePost,
|
||||
delPublic as del, getPublic as get, patchPublic as patch, postPublic as post, ssePost,
|
||||
@@ -78,6 +100,9 @@ export const sendWorkflowMessage = async (
|
||||
onIterationStart,
|
||||
onIterationNext,
|
||||
onIterationFinish,
|
||||
onLoopStart,
|
||||
onLoopNext,
|
||||
onLoopFinish,
|
||||
onTextChunk,
|
||||
onTextReplace,
|
||||
}: {
|
||||
@@ -88,6 +113,9 @@ export const sendWorkflowMessage = async (
|
||||
onIterationStart: IOnIterationStarted
|
||||
onIterationNext: IOnIterationNext
|
||||
onIterationFinish: IOnIterationFinished
|
||||
onLoopStart: IOnLoopStarted
|
||||
onLoopNext: IOnLoopNext
|
||||
onLoopFinish: IOnLoopFinished
|
||||
onTextChunk: IOnTextChunk
|
||||
onTextReplace: IOnTextReplace
|
||||
},
|
||||
@@ -99,7 +127,21 @@ export const sendWorkflowMessage = async (
|
||||
...body,
|
||||
response_mode: 'streaming',
|
||||
},
|
||||
}, { onNodeStarted, onWorkflowStarted, onWorkflowFinished, isPublicAPI: !isInstalledApp, onNodeFinished, onIterationStart, onIterationNext, onIterationFinish, onTextChunk, onTextReplace })
|
||||
}, {
|
||||
onNodeStarted,
|
||||
onWorkflowStarted,
|
||||
onWorkflowFinished,
|
||||
isPublicAPI: !isInstalledApp,
|
||||
onNodeFinished,
|
||||
onIterationStart,
|
||||
onIterationNext,
|
||||
onIterationFinish,
|
||||
onLoopStart,
|
||||
onLoopNext,
|
||||
onLoopFinish,
|
||||
onTextChunk,
|
||||
onTextReplace,
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchAppInfo = async () => {
|
||||
|
||||
@@ -42,6 +42,10 @@ export const getIterationSingleNodeRunUrl = (isChatFlow: boolean, appId: string,
|
||||
return `apps/${appId}/${isChatFlow ? 'advanced-chat/' : ''}workflows/draft/iteration/nodes/${nodeId}/run`
|
||||
}
|
||||
|
||||
export const getLoopSingleNodeRunUrl = (isChatFlow: boolean, appId: string, nodeId: string) => {
|
||||
return `apps/${appId}/${isChatFlow ? 'advanced-chat/' : ''}workflows/draft/loop/nodes/${nodeId}/run`
|
||||
}
|
||||
|
||||
export const publishWorkflow = (url: string) => {
|
||||
return post<CommonResponse & { created_at: number }>(url)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user