mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
fix: add @typescript-eslint/no-floating-promises rule (#2764)
Co-authored-by: himself65 <himself65@outlook.com>
This commit is contained in:
@@ -12,47 +12,48 @@ import { openAIApiKeyAtom, useChatAtoms } from '../core/hooks';
|
||||
import { detailContentActionsStyle, detailContentStyle } from './index.css';
|
||||
|
||||
if (typeof window === 'undefined') {
|
||||
import('@blocksuite/blocks').then(({ FormatQuickBar }) => {
|
||||
FormatQuickBar.customElements.push((_page, getSelection) => {
|
||||
const div = document.createElement('div');
|
||||
const root = createRoot(div);
|
||||
import('@blocksuite/blocks')
|
||||
.then(({ FormatQuickBar }) => {
|
||||
FormatQuickBar.customElements.push((_page, getSelection) => {
|
||||
const div = document.createElement('div');
|
||||
const root = createRoot(div);
|
||||
|
||||
const AskAI = (): ReactElement => {
|
||||
const { conversationAtom } = useChatAtoms();
|
||||
const call = useSetAtom(conversationAtom);
|
||||
const AskAI = (): ReactElement => {
|
||||
const { conversationAtom } = useChatAtoms();
|
||||
const call = useSetAtom(conversationAtom);
|
||||
const onClickAskAI = useCallback(() => {
|
||||
const selection = getSelection();
|
||||
if (selection != null) {
|
||||
const text = selection.models
|
||||
.map(model => {
|
||||
return model.text?.toString();
|
||||
})
|
||||
.filter((v): v is string => Boolean(v))
|
||||
.join('\n');
|
||||
console.log('selected text:', text);
|
||||
call(
|
||||
`I selected some text from the document: \n"${text}."`
|
||||
).catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
}, [call]);
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={() => {
|
||||
const selection = getSelection();
|
||||
if (selection != null) {
|
||||
const text = selection.models
|
||||
.map(model => {
|
||||
return model.text?.toString();
|
||||
})
|
||||
.filter((v): v is string => Boolean(v))
|
||||
.join('\n');
|
||||
console.log('selected text:', text);
|
||||
void call(
|
||||
`I selected some text from the document: \n"${text}."`
|
||||
);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Ask AI
|
||||
</div>
|
||||
return <div onClick={onClickAskAI}>Ask AI</div>;
|
||||
};
|
||||
root.render(
|
||||
<StrictMode>
|
||||
<Provider store={rootStore}>
|
||||
<AskAI />
|
||||
</Provider>
|
||||
</StrictMode>
|
||||
);
|
||||
};
|
||||
root.render(
|
||||
<StrictMode>
|
||||
<Provider store={rootStore}>
|
||||
<AskAI />
|
||||
</Provider>
|
||||
</StrictMode>
|
||||
);
|
||||
return div;
|
||||
return div;
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const Actions = () => {
|
||||
|
||||
@@ -49,9 +49,14 @@ const getConversationAtom = (chat: ConversationChain) => {
|
||||
throw new Error();
|
||||
}
|
||||
const memory = chat.memory as BufferMemory;
|
||||
void memory.chatHistory.getMessages().then(messages => {
|
||||
setAtom(messages);
|
||||
});
|
||||
memory.chatHistory
|
||||
.getMessages()
|
||||
.then(messages => {
|
||||
setAtom(messages);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
const llmStart = (): void => {
|
||||
setAtom(conversations => [...conversations, new AIChatMessage('')]);
|
||||
};
|
||||
@@ -86,9 +91,14 @@ const getConversationAtom = (chat: ConversationChain) => {
|
||||
});
|
||||
// refresh messages
|
||||
const memory = chat.memory as BufferMemory;
|
||||
void memory.chatHistory.getMessages().then(messages => {
|
||||
set(conversationBaseAtom, messages);
|
||||
});
|
||||
memory.chatHistory
|
||||
.getMessages()
|
||||
.then(messages => {
|
||||
set(conversationBaseAtom, messages);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
);
|
||||
conversationWeakMap.set(chat, conversationAtom);
|
||||
|
||||
Reference in New Issue
Block a user