feat: edit and resubmit messages (#592)

This commit is contained in:
Jeremy 2024-12-05 15:29:33 +03:00 committed by GitHub
parent 2e479ccce7
commit 64d1aad2bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 302 additions and 25 deletions

View file

@ -5,9 +5,18 @@ import { useSWRConfig } from 'swr';
import type { Suggestion } from '@/lib/db/schema';
import type { UIBlock } from './block';
import { useUserMessageId } from '@/hooks/use-user-message-id';
type StreamingDelta = {
type: 'text-delta' | 'title' | 'id' | 'suggestion' | 'clear' | 'finish';
type:
| 'text-delta'
| 'title'
| 'id'
| 'suggestion'
| 'clear'
| 'finish'
| 'user-message-id';
content: string | Suggestion;
};
@ -23,6 +32,8 @@ export function useBlockStream({
Array<Suggestion>
>([]);
const { setUserMessageIdFromServer } = useUserMessageId();
useEffect(() => {
if (optimisticSuggestions && optimisticSuggestions.length > 0) {
const [optimisticSuggestion] = optimisticSuggestions;
@ -37,6 +48,11 @@ export function useBlockStream({
const delta = mostRecentDelta as StreamingDelta;
if (delta.type === 'user-message-id') {
setUserMessageIdFromServer(delta.content as string);
return;
}
setBlock((draftBlock) => {
switch (delta.type) {
case 'id':