Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
c5064429
authored
Dec 02, 2024
by
heheer
Committed by
GitHub
Dec 02, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix simple snapshot init & auto excute when change app (#3293)
parent
1cef206c
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
49 additions
and
36 deletions
+49
-36
projects/app/src/components/core/chat/ChatContainer/ChatBox/index.tsx
+9
-1
projects/app/src/pages/app/detail/components/SimpleApp/Edit.tsx
+13
-2
projects/app/src/pages/app/detail/components/SimpleApp/Header.tsx
+0
-1
projects/app/src/pages/app/detail/components/SimpleApp/index.tsx
+0
-10
projects/app/src/pages/app/detail/components/SimpleApp/useSnapshots.tsx
+3
-7
projects/app/src/pages/chat/index.tsx
+9
-5
projects/app/src/pages/chat/share.tsx
+8
-5
projects/app/src/pages/chat/team.tsx
+7
-5
No files found.
projects/app/src/components/core/chat/ChatContainer/ChatBox/index.tsx
View file @
c5064429
...
@@ -845,7 +845,15 @@ const ChatBox = ({
...
@@ -845,7 +845,15 @@ const ChatBox = ({
hideInUI
:
true
hideInUI
:
true
});
});
}
}
},
[
isReady
,
chatStarted
,
autoExecute
?.
open
,
chatRecords
,
isChatRecordsLoaded
]);
},
[
chatStarted
,
chatRecords
,
isChatRecordsLoaded
,
sendPrompt
,
isReady
,
autoExecute
.
open
,
autoExecute
.
defaultPrompt
]);
// output data
// output data
useImperativeHandle
(
ChatBoxRef
,
()
=>
({
useImperativeHandle
(
ChatBoxRef
,
()
=>
({
...
...
projects/app/src/pages/app/detail/components/SimpleApp/Edit.tsx
View file @
c5064429
import
React
from
'react'
;
import
React
from
'react'
;
import
{
Box
}
from
'@chakra-ui/react'
;
import
{
Box
}
from
'@chakra-ui/react'
;
import
{
useLocalStorageState
,
useMount
}
from
'ahooks'
;
import
{
use
DebounceEffect
,
use
LocalStorageState
,
useMount
}
from
'ahooks'
;
import
{
useDatasetStore
}
from
'@/web/core/dataset/store/dataset'
;
import
{
useDatasetStore
}
from
'@/web/core/dataset/store/dataset'
;
import
{
appWorkflow2Form
}
from
'@fastgpt/global/core/app/utils'
;
import
{
appWorkflow2Form
}
from
'@fastgpt/global/core/app/utils'
;
...
@@ -62,12 +62,23 @@ const Edit = ({
...
@@ -62,12 +62,23 @@ const Edit = ({
const
{
appDetail
}
=
useContextSelector
(
AppContext
,
(
v
)
=>
v
);
const
{
appDetail
}
=
useContextSelector
(
AppContext
,
(
v
)
=>
v
);
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
//
旧的编辑记录,直接重置到新的变量中
//
Reset old edit history to new variables
const
[
oldPast
,
setOldPast
]
=
useLocalStorageState
<
SimpleAppSnapshotType
[]
>
(
const
[
oldPast
,
setOldPast
]
=
useLocalStorageState
<
SimpleAppSnapshotType
[]
>
(
`
${
appDetail
.
_id
}
-past-simple`
,
`
${
appDetail
.
_id
}
-past-simple`
,
{}
{}
);
);
// Save snapshot to local
useDebounceEffect
(
()
=>
{
saveSnapshot
({
appForm
});
},
[
appForm
],
{
wait
:
500
}
);
// Init app form
// Init app form
useMount
(()
=>
{
useMount
(()
=>
{
// show selected dataset
// show selected dataset
...
...
projects/app/src/pages/app/detail/components/SimpleApp/Header.tsx
View file @
c5064429
...
@@ -9,7 +9,6 @@ import { useRouter } from 'next/router';
...
@@ -9,7 +9,6 @@ import { useRouter } from 'next/router';
import
RouteTab
from
'../RouteTab'
;
import
RouteTab
from
'../RouteTab'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
{
AppSimpleEditFormType
}
from
'@fastgpt/global/core/app/type'
;
import
{
AppSimpleEditFormType
}
from
'@fastgpt/global/core/app/type'
;
import
{
AppTypeEnum
}
from
'@fastgpt/global/core/app/constants'
;
import
{
form2AppWorkflow
}
from
'@/web/core/app/utils'
;
import
{
form2AppWorkflow
}
from
'@/web/core/app/utils'
;
import
{
TabEnum
}
from
'../context'
;
import
{
TabEnum
}
from
'../context'
;
import
MyIcon
from
'@fastgpt/web/components/common/Icon'
;
import
MyIcon
from
'@fastgpt/web/components/common/Icon'
;
...
...
projects/app/src/pages/app/detail/components/SimpleApp/index.tsx
View file @
c5064429
...
@@ -23,16 +23,6 @@ const SimpleEdit = () => {
...
@@ -23,16 +23,6 @@ const SimpleEdit = () => {
);
);
const
[
appForm
,
setAppForm
]
=
useState
(
getDefaultAppForm
());
const
[
appForm
,
setAppForm
]
=
useState
(
getDefaultAppForm
());
// Save snapshot to local
useDebounceEffect
(
()
=>
{
saveSnapshot
({
appForm
});
},
[
appForm
],
{
wait
:
500
}
);
useBeforeunload
({
useBeforeunload
({
tip
:
t
(
'common:core.common.tip.leave page'
)
tip
:
t
(
'common:core.common.tip.leave page'
)
...
...
projects/app/src/pages/app/detail/components/SimpleApp/useSnapshots.tsx
View file @
c5064429
...
@@ -34,11 +34,9 @@ export const compareSimpleAppSnapshot = (
...
@@ -34,11 +34,9 @@ export const compareSimpleAppSnapshot = (
questionGuide
:
appForm1
.
chatConfig
?.
questionGuide
||
false
,
questionGuide
:
appForm1
.
chatConfig
?.
questionGuide
||
false
,
ttsConfig
:
appForm1
.
chatConfig
?.
ttsConfig
||
undefined
,
ttsConfig
:
appForm1
.
chatConfig
?.
ttsConfig
||
undefined
,
whisperConfig
:
appForm1
.
chatConfig
?.
whisperConfig
||
undefined
,
whisperConfig
:
appForm1
.
chatConfig
?.
whisperConfig
||
undefined
,
scheduledTriggerConfig
:
appForm1
.
chatConfig
?.
scheduledTriggerConfig
||
undefined
,
chatInputGuide
:
appForm1
.
chatConfig
?.
chatInputGuide
||
undefined
,
chatInputGuide
:
appForm1
.
chatConfig
?.
chatInputGuide
||
undefined
,
fileSelectConfig
:
appForm1
.
chatConfig
?.
fileSelectConfig
||
undefined
,
fileSelectConfig
:
appForm1
.
chatConfig
?.
fileSelectConfig
||
undefined
,
instruction
:
appForm1
.
chatConfig
?.
instruction
||
''
,
instruction
:
appForm1
.
chatConfig
?.
instruction
||
''
autoExecute
:
appForm1
.
chatConfig
?.
autoExecute
||
undefined
},
},
{
{
welcomeText
:
appForm2
.
chatConfig
?.
welcomeText
||
''
,
welcomeText
:
appForm2
.
chatConfig
?.
welcomeText
||
''
,
...
@@ -46,11 +44,9 @@ export const compareSimpleAppSnapshot = (
...
@@ -46,11 +44,9 @@ export const compareSimpleAppSnapshot = (
questionGuide
:
appForm2
.
chatConfig
?.
questionGuide
||
false
,
questionGuide
:
appForm2
.
chatConfig
?.
questionGuide
||
false
,
ttsConfig
:
appForm2
.
chatConfig
?.
ttsConfig
||
undefined
,
ttsConfig
:
appForm2
.
chatConfig
?.
ttsConfig
||
undefined
,
whisperConfig
:
appForm2
.
chatConfig
?.
whisperConfig
||
undefined
,
whisperConfig
:
appForm2
.
chatConfig
?.
whisperConfig
||
undefined
,
scheduledTriggerConfig
:
appForm2
.
chatConfig
?.
scheduledTriggerConfig
||
undefined
,
chatInputGuide
:
appForm2
.
chatConfig
?.
chatInputGuide
||
undefined
,
chatInputGuide
:
appForm2
.
chatConfig
?.
chatInputGuide
||
undefined
,
fileSelectConfig
:
appForm2
.
chatConfig
?.
fileSelectConfig
||
undefined
,
fileSelectConfig
:
appForm2
.
chatConfig
?.
fileSelectConfig
||
undefined
,
instruction
:
appForm2
.
chatConfig
?.
instruction
||
''
,
instruction
:
appForm2
.
chatConfig
?.
instruction
||
''
autoExecute
:
appForm2
.
chatConfig
?.
autoExecute
||
undefined
}
}
)
)
)
{
)
{
...
@@ -58,7 +54,7 @@ export const compareSimpleAppSnapshot = (
...
@@ -58,7 +54,7 @@ export const compareSimpleAppSnapshot = (
return
false
;
return
false
;
}
}
return
isEqual
(
appForm1
,
appForm2
);
return
isEqual
(
{
...
appForm1
,
chatConfig
:
undefined
},
{
...
appForm2
,
chatConfig
:
undefined
}
);
};
};
export
const
useSimpleAppSnapshots
=
(
appId
:
string
)
=>
{
export
const
useSimpleAppSnapshots
=
(
appId
:
string
)
=>
{
...
...
projects/app/src/pages/chat/index.tsx
View file @
c5064429
...
@@ -63,15 +63,20 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
...
@@ -63,15 +63,20 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
// Load chat init data
// Load chat init data
const
[
chatData
,
setChatData
]
=
useState
<
InitChatResponse
>
(
defaultChatData
);
const
[
chatData
,
setChatData
]
=
useState
<
InitChatResponse
>
(
defaultChatData
);
const
{
loading
:
isLoading
}
=
useRequest2
(
const
{
loading
}
=
useRequest2
(
async
()
=>
{
async
()
=>
{
if
(
!
appId
||
forbidLoadChat
.
current
)
return
;
if
(
!
appId
||
forbidLoadChat
.
current
)
return
;
const
res
=
await
getInitChatInfo
({
appId
,
chatId
});
const
res
=
await
getInitChatInfo
({
appId
,
chatId
});
res
.
userAvatar
=
userInfo
?.
avatar
;
res
.
userAvatar
=
userInfo
?.
avatar
;
setChatData
(
res
);
// Wait for state update to complete
setChatBoxData
(
res
);
await
new
Promise
((
resolve
)
=>
{
setChatData
(
res
);
setChatBoxData
(
res
);
setTimeout
(
resolve
,
0
);
});
// reset chat variables
// reset chat variables
resetVariables
({
resetVariables
({
variables
:
res
.
variables
variables
:
res
.
variables
...
@@ -136,8 +141,6 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
...
@@ -136,8 +141,6 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
},
},
[
chatId
,
appId
,
onUpdateHistoryTitle
,
forbidLoadChat
]
[
chatId
,
appId
,
onUpdateHistoryTitle
,
forbidLoadChat
]
);
);
const
loading
=
isLoading
;
const
RenderHistorySlider
=
useMemo
(()
=>
{
const
RenderHistorySlider
=
useMemo
(()
=>
{
const
Children
=
(
const
Children
=
(
<
ChatHistorySlider
confirmClearText=
{
t
(
'common:core.chat.Confirm to clear history'
)
}
/>
<
ChatHistorySlider
confirmClearText=
{
t
(
'common:core.chat.Confirm to clear history'
)
}
/>
...
@@ -210,6 +213,7 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
...
@@ -210,6 +213,7 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
feedbackType=
{
'user'
}
feedbackType=
{
'user'
}
onStartChat=
{
onStartChat
}
onStartChat=
{
onStartChat
}
chatType=
{
'chat'
}
chatType=
{
'chat'
}
isReady=
{
!
loading
}
showRawSource
showRawSource
showNodeStatus
showNodeStatus
/>
/>
...
...
projects/app/src/pages/chat/share.tsx
View file @
c5064429
...
@@ -88,7 +88,7 @@ const OutLink = (props: Props) => {
...
@@ -88,7 +88,7 @@ const OutLink = (props: Props) => {
const
initSign
=
useRef
(
false
);
const
initSign
=
useRef
(
false
);
const
[
chatData
,
setChatData
]
=
useState
<
InitChatResponse
>
(
defaultChatData
);
const
[
chatData
,
setChatData
]
=
useState
<
InitChatResponse
>
(
defaultChatData
);
const
{
data
,
loading
:
isLoading
}
=
useRequest2
(
const
{
data
,
loading
}
=
useRequest2
(
async
()
=>
{
async
()
=>
{
const
shareId
=
outLinkAuthData
.
shareId
;
const
shareId
=
outLinkAuthData
.
shareId
;
const
outLinkUid
=
outLinkAuthData
.
outLinkUid
;
const
outLinkUid
=
outLinkAuthData
.
outLinkUid
;
...
@@ -100,8 +100,12 @@ const OutLink = (props: Props) => {
...
@@ -100,8 +100,12 @@ const OutLink = (props: Props) => {
outLinkUid
outLinkUid
});
});
setChatData
(
res
);
await
new
Promise
((
resolve
)
=>
{
setChatBoxData
(
res
);
setChatData
(
res
);
setChatBoxData
(
res
);
setTimeout
(
resolve
,
0
);
});
resetVariables
({
resetVariables
({
variables
:
res
.
variables
variables
:
res
.
variables
});
});
...
@@ -231,8 +235,6 @@ const OutLink = (props: Props) => {
...
@@ -231,8 +235,6 @@ const OutLink = (props: Props) => {
);
);
},
[
isOpenSlider
,
isPc
,
onCloseSlider
,
showHistory
,
t
]);
},
[
isOpenSlider
,
isPc
,
onCloseSlider
,
showHistory
,
t
]);
const
loading
=
isLoading
;
return
(
return
(
<>
<>
<
NextHead
title=
{
props
.
appName
||
'AI'
}
desc=
{
props
.
appIntro
}
icon=
{
props
.
appAvatar
}
/>
<
NextHead
title=
{
props
.
appName
||
'AI'
}
desc=
{
props
.
appIntro
}
icon=
{
props
.
appAvatar
}
/>
...
@@ -280,6 +282,7 @@ const OutLink = (props: Props) => {
...
@@ -280,6 +282,7 @@ const OutLink = (props: Props) => {
feedbackType=
{
'user'
}
feedbackType=
{
'user'
}
onStartChat=
{
startChat
}
onStartChat=
{
startChat
}
chatType=
"share"
chatType=
"share"
isReady=
{
!
loading
}
showRawSource=
{
showRawSource
}
showRawSource=
{
showRawSource
}
showNodeStatus=
{
showNodeStatus
}
showNodeStatus=
{
showNodeStatus
}
/>
/>
...
...
projects/app/src/pages/chat/team.tsx
View file @
c5064429
...
@@ -69,14 +69,17 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
...
@@ -69,14 +69,17 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
// get chat app info
// get chat app info
const
[
chatData
,
setChatData
]
=
useState
<
InitChatResponse
>
(
defaultChatData
);
const
[
chatData
,
setChatData
]
=
useState
<
InitChatResponse
>
(
defaultChatData
);
const
{
loading
:
isLoading
}
=
useRequest2
(
const
{
loading
}
=
useRequest2
(
async
()
=>
{
async
()
=>
{
if
(
!
appId
||
forbidLoadChat
.
current
)
return
;
if
(
!
appId
||
forbidLoadChat
.
current
)
return
;
const
res
=
await
getTeamChatInfo
({
teamId
,
appId
,
chatId
,
teamToken
});
const
res
=
await
getTeamChatInfo
({
teamId
,
appId
,
chatId
,
teamToken
});
setChatData
(
res
);
await
new
Promise
((
resolve
)
=>
{
setChatBoxData
(
res
);
setChatData
(
res
);
setChatBoxData
(
res
);
setTimeout
(
resolve
,
0
);
});
// reset chat records
// reset chat records
resetVariables
({
resetVariables
({
variables
:
res
.
variables
variables
:
res
.
variables
...
@@ -177,8 +180,6 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
...
@@ -177,8 +180,6 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
);
);
},
[
appId
,
isOpenSlider
,
isPc
,
onCloseSlider
,
t
]);
},
[
appId
,
isOpenSlider
,
isPc
,
onCloseSlider
,
t
]);
const
loading
=
isLoading
;
return
(
return
(
<
Flex
h=
{
'100%'
}
>
<
Flex
h=
{
'100%'
}
>
<
NextHead
title=
{
chatData
.
app
.
name
}
icon=
{
chatData
.
app
.
avatar
}
></
NextHead
>
<
NextHead
title=
{
chatData
.
app
.
name
}
icon=
{
chatData
.
app
.
avatar
}
></
NextHead
>
...
@@ -226,6 +227,7 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
...
@@ -226,6 +227,7 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
feedbackType=
{
'user'
}
feedbackType=
{
'user'
}
onStartChat=
{
startChat
}
onStartChat=
{
startChat
}
chatType=
"team"
chatType=
"team"
isReady=
{
!
loading
}
showRawSource
showRawSource
showNodeStatus
showNodeStatus
/>
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment