fix: Fixed an issue where the first message would be displayed when sending the second message #2625 (#2626)

### What problem does this PR solve?

fix: Fixed an issue where the first message would be displayed when
sending the second message #2625

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [ ] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):
This commit is contained in:
balibabu
2024-09-27 18:20:19 +08:00
committed by GitHub
parent 34abcf7704
commit ca2de896c7
15 changed files with 267 additions and 213 deletions

View File

@ -224,6 +224,7 @@ export const useSendMessageWithSse = (
const send = useCallback(
async (
body: any,
controller?: AbortController,
): Promise<{ response: Response; data: ResponseType } | undefined> => {
try {
setDone(false);
@ -234,6 +235,7 @@ export const useSendMessageWithSse = (
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
signal: controller?.signal,
});
const res = response.clone().json();
@ -249,6 +251,7 @@ export const useSendMessageWithSse = (
const { done, value } = x;
if (done) {
console.info('done');
setAnswer({} as IAnswer);
break;
}
try {
@ -268,9 +271,12 @@ export const useSendMessageWithSse = (
}
console.info('done?');
setDone(true);
setAnswer({} as IAnswer);
return { data: await res, response };
} catch (e) {
setDone(true);
setAnswer({} as IAnswer);
console.warn(e);
}
},