Skip to content

Commit c737531

Browse files
committed
support workflow events
1 parent 2bd93dc commit c737531

File tree

119 files changed

+40066
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+40066
-24
lines changed

app/components/index.tsx

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import Sidebar from '@/app/components/sidebar'
1111
import ConfigSence from '@/app/components/config-scence'
1212
import Header from '@/app/components/header'
1313
import { fetchAppParams, fetchChatList, fetchConversations, generationConversationName, sendChatMessage, updateFeedback } from '@/service'
14-
import type { ConversationItem, Feedbacktype, IChatItem, PromptConfig, VisionFile, VisionSettings } from '@/types/app'
15-
import { Resolution, TransferMethod } from '@/types/app'
14+
import type { ChatItem, ConversationItem, Feedbacktype, PromptConfig, VisionFile, VisionSettings } from '@/types/app'
15+
import { Resolution, TransferMethod, WorkflowRunningStatus } from '@/types/app'
1616
import Chat from '@/app/components/chat'
1717
import { setLocaleOnClient } from '@/i18n/client'
1818
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
@@ -124,7 +124,7 @@ const Main: FC = () => {
124124
if (!isNewConversation && !conversationIdChangeBecauseOfNew && !isResponsing) {
125125
fetchChatList(currConversationId).then((res: any) => {
126126
const { data } = res
127-
const newChatList: IChatItem[] = generateNewChatListWithOpenstatement(notSyncToStateIntroduction, notSyncToStateInputs)
127+
const newChatList: ChatItem[] = generateNewChatListWithOpenstatement(notSyncToStateIntroduction, notSyncToStateInputs)
128128

129129
data.forEach((item: any) => {
130130
newChatList.push({
@@ -168,7 +168,7 @@ const Main: FC = () => {
168168
/*
169169
* chat info. chat is under conversation.
170170
*/
171-
const [chatList, setChatList, getChatList] = useGetState<IChatItem[]>([])
171+
const [chatList, setChatList, getChatList] = useGetState<ChatItem[]>([])
172172
const chatListDomRef = useRef<HTMLDivElement>(null)
173173
useEffect(() => {
174174
// scroll to bottom
@@ -300,10 +300,10 @@ const Main: FC = () => {
300300
placeholderAnswerId,
301301
questionItem,
302302
}: {
303-
responseItem: IChatItem
303+
responseItem: ChatItem
304304
questionId: string
305305
placeholderAnswerId: string
306-
questionItem: IChatItem
306+
questionItem: ChatItem
307307
}) => {
308308
// closesure new list is outdated.
309309
const newListWithAnswer = produce(
@@ -362,7 +362,7 @@ const Main: FC = () => {
362362
let isAgentMode = false
363363

364364
// answer
365-
const responseItem: IChatItem = {
365+
const responseItem: ChatItem = {
366366
id: `${Date.now()}`,
367367
content: '',
368368
agent_thoughts: [],
@@ -526,6 +526,52 @@ const Main: FC = () => {
526526
draft.splice(draft.findIndex(item => item.id === placeholderAnswerId), 1)
527527
}))
528528
},
529+
onWorkflowStarted: ({ workflow_run_id, task_id }) => {
530+
// taskIdRef.current = task_id
531+
responseItem.workflow_run_id = workflow_run_id
532+
responseItem.workflowProcess = {
533+
status: WorkflowRunningStatus.Running,
534+
tracing: [],
535+
}
536+
setChatList(produce(getChatList(), (draft) => {
537+
const currentIndex = draft.findIndex(item => item.id === responseItem.id)
538+
draft[currentIndex] = {
539+
...draft[currentIndex],
540+
...responseItem,
541+
}
542+
}))
543+
},
544+
onWorkflowFinished: ({ data }) => {
545+
responseItem.workflowProcess!.status = data.status as WorkflowRunningStatus
546+
setChatList(produce(getChatList(), (draft) => {
547+
const currentIndex = draft.findIndex(item => item.id === responseItem.id)
548+
draft[currentIndex] = {
549+
...draft[currentIndex],
550+
...responseItem,
551+
}
552+
}))
553+
},
554+
onNodeStarted: ({ data }) => {
555+
responseItem.workflowProcess!.tracing!.push(data as any)
556+
setChatList(produce(getChatList(), (draft) => {
557+
const currentIndex = draft.findIndex(item => item.id === responseItem.id)
558+
draft[currentIndex] = {
559+
...draft[currentIndex],
560+
...responseItem,
561+
}
562+
}))
563+
},
564+
onNodeFinished: ({ data }) => {
565+
const currentIndex = responseItem.workflowProcess!.tracing!.findIndex(item => item.node_id === data.node_id)
566+
responseItem.workflowProcess!.tracing[currentIndex] = data as any
567+
setChatList(produce(getChatList(), (draft) => {
568+
const currentIndex = draft.findIndex(item => item.id === responseItem.id)
569+
draft[currentIndex] = {
570+
...draft[currentIndex],
571+
...responseItem,
572+
}
573+
}))
574+
},
529575
})
530576
}
531577

next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const nextConfig = {
44
// Configure pageExtensions to include md and mdx
55
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
66
experimental: {
7-
appDir: true,
7+
// appDir: true,
88
},
99
// fix all before production. Now it slow the develop speed.
1010
eslint: {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@heroicons/react": "^2.0.16",
1919
"@mdx-js/loader": "^2.3.0",
2020
"@mdx-js/react": "^2.3.0",
21+
"@monaco-editor/react": "^4.6.0",
2122
"@tailwindcss/line-clamp": "^0.4.2",
2223
"@types/node": "18.15.0",
2324
"@types/react": "18.0.28",
@@ -27,7 +28,7 @@
2728
"axios": "^1.3.5",
2829
"classnames": "^2.3.2",
2930
"copy-to-clipboard": "^3.3.3",
30-
"dify-client": "^2.2.0",
31+
"dify-client": "^2.3.1",
3132
"eslint": "8.36.0",
3233
"eslint-config-next": "13.4.0",
3334
"eventsource-parser": "^1.0.0",
Binary file not shown.

public/vs/base/common/worker/simpleWorker.nls.de.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/vs/base/common/worker/simpleWorker.nls.es.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/vs/base/common/worker/simpleWorker.nls.fr.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/vs/base/common/worker/simpleWorker.nls.it.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/vs/base/common/worker/simpleWorker.nls.ja.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/vs/base/common/worker/simpleWorker.nls.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/vs/base/common/worker/simpleWorker.nls.ko.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/vs/base/common/worker/simpleWorker.nls.ru.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/vs/base/common/worker/simpleWorker.nls.zh-cn.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/vs/base/common/worker/simpleWorker.nls.zh-tw.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)