-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Features - toeverything/blocksuite#6679 @pengx17 - toeverything/blocksuite#6620 @doouding - toeverything/blocksuite#6602 @golok727 - toeverything/blocksuite#6661 @Flrande - toeverything/blocksuite#6591 @fundon - toeverything/blocksuite#6634 @golok727 - toeverything/blocksuite#6626 @regischen - toeverything/blocksuite#6630 @Saul-Mirone - toeverything/blocksuite#6605 @donteatfriedrice - toeverything/blocksuite#6614 @zzj3720 - toeverything/blocksuite#6508 @doouding - toeverything/blocksuite#6578 @donteatfriedrice - toeverything/blocksuite#6572 @zzj3720 - toeverything/blocksuite#6571 @golok727 - toeverything/blocksuite#6573 @fundon - toeverything/blocksuite#6580 @Flrande - toeverything/blocksuite#6540 @golok727 - toeverything/blocksuite#6567 @Flrande - toeverything/blocksuite#6565 @zzj3720 - toeverything/blocksuite#6561 @zzj3720 ## Bugfix - toeverything/blocksuite#6677 @donteatfriedrice - toeverything/blocksuite#6681 @fundon - toeverything/blocksuite#6673 @fundon - toeverything/blocksuite#6652 @fundon - toeverything/blocksuite#6641 @fourdim - toeverything/blocksuite#6649 @golok727 - toeverything/blocksuite#6648 @doouding - toeverything/blocksuite#6662 @Flrande - toeverything/blocksuite#6659 @zkwolf - toeverything/blocksuite#6644 @doouding - toeverything/blocksuite#6633 @golok727 - toeverything/blocksuite#6632 @golok727 - toeverything/blocksuite#6622 @RubaXa - toeverything/blocksuite#6622 @RubaXa - toeverything/blocksuite#6622 @RubaXa - toeverything/blocksuite#6622 @RubaXa - toeverything/blocksuite#6622 @RubaXa - toeverything/blocksuite#6600 @fourdim - toeverything/blocksuite#6617 @zzj3720 - toeverything/blocksuite#6618 @Flrande - toeverything/blocksuite#6576 @fundon - toeverything/blocksuite#6595 @fundon - toeverything/blocksuite#6596 @zzj3720 - toeverything/blocksuite#6574 @fundon - toeverything/blocksuite#6593 @Saul-Mirone - toeverything/blocksuite#6588 @zzj3720 - toeverything/blocksuite#6590 @zzj3720 - toeverything/blocksuite#6589 @zzj3720 - toeverything/blocksuite#6584 @lawvs - toeverything/blocksuite#6579 @fundon - toeverything/blocksuite#6538 @golok727 - toeverything/blocksuite#6570 @zzj3720 - toeverything/blocksuite#6569 @zzj3720 - toeverything/blocksuite#6564 @zzj3720 - toeverything/blocksuite#6563 @zzj3720 ## Refactor - toeverything/blocksuite#6683 @doodlewind - toeverything/blocksuite#6668 @Flrande - toeverything/blocksuite#6635 @donteatfriedrice - toeverything/blocksuite#6653 @fundon - toeverything/blocksuite#6615 @Flrande - toeverything/blocksuite#6534 @Saul-Mirone - toeverything/blocksuite#6553 @golok727 ## Misc - chore(examples): cleanup types - toeverything/blocksuite#6664 @fourdim - toeverything/blocksuite#6657 @fourdim - toeverything/blocksuite#6654 @fourdim - toeverything/blocksuite#6587 @Saul-Mirone - toeverything/blocksuite#6562 @donteatfriedrice
- Loading branch information
Showing
21 changed files
with
975 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { assertExists } from '@blocksuite/global/utils'; | ||
import { AIProvider } from '@blocksuite/presets'; | ||
|
||
import { textToTextStream } from './request'; | ||
|
||
export function setupAIProvider() { | ||
AIProvider.provideAction('chat', options => { | ||
assertExists(options.stream); | ||
return textToTextStream({ | ||
docId: options.docId, | ||
workspaceId: options.workspaceId, | ||
prompt: options.input, | ||
}); | ||
}); | ||
|
||
AIProvider.provideAction('summary', options => { | ||
assertExists(options.stream); | ||
const prompt = ` | ||
Summarize the key points from the following content in a clear and concise manner, | ||
suitable for a reader who is seeking a quick understanding of the original content. | ||
Ensure to capture the main ideas and any significant details without unnecessary elaboration: | ||
${options.input} | ||
`; | ||
return textToTextStream({ | ||
docId: options.docId, | ||
workspaceId: options.workspaceId, | ||
prompt, | ||
}); | ||
}); | ||
|
||
AIProvider.provideAction('translate', options => { | ||
assertExists(options.stream); | ||
const prompt = `Translate the following content to ${options.lang}: ${options.input}`; | ||
return textToTextStream({ | ||
docId: options.docId, | ||
workspaceId: options.workspaceId, | ||
prompt, | ||
}); | ||
}); | ||
|
||
AIProvider.provideAction('changeTone', options => { | ||
assertExists(options.stream); | ||
const prompt = `Change the tone of the following content to ${options.tone}: ${options.input}`; | ||
return textToTextStream({ | ||
docId: options.docId, | ||
workspaceId: options.workspaceId, | ||
prompt, | ||
}); | ||
}); | ||
|
||
AIProvider.provideAction('improveWriting', options => { | ||
assertExists(options.stream); | ||
const prompt = `Improve the writing of the following content: ${options.input}`; | ||
return textToTextStream({ | ||
docId: options.docId, | ||
workspaceId: options.workspaceId, | ||
prompt, | ||
}); | ||
}); | ||
|
||
AIProvider.provideAction('improveGrammar', options => { | ||
assertExists(options.stream); | ||
const prompt = `Improve the grammar of the following content: ${options.input}`; | ||
return textToTextStream({ | ||
docId: options.docId, | ||
workspaceId: options.workspaceId, | ||
prompt, | ||
}); | ||
}); | ||
|
||
AIProvider.provideAction('fixSpelling', options => { | ||
assertExists(options.stream); | ||
const prompt = `Fix the spelling of the following content: ${options.input}`; | ||
return textToTextStream({ | ||
docId: options.docId, | ||
workspaceId: options.workspaceId, | ||
prompt, | ||
}); | ||
}); | ||
|
||
AIProvider.provideAction('createHeadings', options => { | ||
assertExists(options.stream); | ||
const prompt = `Create headings for the following content: ${options.input}`; | ||
return textToTextStream({ | ||
docId: options.docId, | ||
workspaceId: options.workspaceId, | ||
prompt, | ||
}); | ||
}); | ||
|
||
AIProvider.provideAction('makeLonger', options => { | ||
assertExists(options.stream); | ||
const prompt = `Make the following content longer: ${options.input}`; | ||
return textToTextStream({ | ||
docId: options.docId, | ||
workspaceId: options.workspaceId, | ||
prompt, | ||
}); | ||
}); | ||
|
||
AIProvider.provideAction('makeShorter', options => { | ||
assertExists(options.stream); | ||
const prompt = `Make the following content shorter: ${options.input}`; | ||
return textToTextStream({ | ||
docId: options.docId, | ||
workspaceId: options.workspaceId, | ||
prompt, | ||
}); | ||
}); | ||
|
||
AIProvider.provideAction('checkCodeErrors', options => { | ||
assertExists(options.stream); | ||
const prompt = `Check the code errors in the following content: ${options.input}`; | ||
return textToTextStream({ | ||
docId: options.docId, | ||
workspaceId: options.workspaceId, | ||
prompt, | ||
}); | ||
}); | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/request.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getBaseUrl } from '@affine/graphql'; | ||
import { CopilotClient, toTextStream } from '@blocksuite/presets'; | ||
|
||
const TIMEOUT = 5000; | ||
|
||
export function textToTextStream({ | ||
docId, | ||
workspaceId, | ||
prompt, | ||
}: { | ||
docId: string; | ||
workspaceId: string; | ||
prompt: string; | ||
}): BlockSuitePresets.TextStream { | ||
const client = new CopilotClient(getBaseUrl()); | ||
return { | ||
[Symbol.asyncIterator]: async function* () { | ||
const session = await client.createSession({ | ||
workspaceId, | ||
docId, | ||
promptName: 'Summary', // placeholder | ||
}); | ||
const eventSource = client.textToTextStream(prompt, session); | ||
yield* toTextStream(eventSource, { timeout: TIMEOUT }); | ||
}, | ||
}; | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/frontend/core/src/components/blocksuite/block-suite-editor/ai/spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { getAISpecs } from '@blocksuite/presets'; | ||
|
||
import { setupAIProvider } from './provider'; | ||
|
||
export function getParsedAISpecs() { | ||
setupAIProvider(); | ||
return getAISpecs(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/frontend/core/src/modules/multi-tab-sidebar/entities/sidebar-tab.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/frontend/core/src/modules/multi-tab-sidebar/entities/sidebar-tabs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import type { SidebarTab } from './sidebar-tab'; | ||
import { copilotTab } from './tabs/copilot'; | ||
import { chatTab } from './tabs/chat'; | ||
import { framePanelTab } from './tabs/frame'; | ||
import { journalTab } from './tabs/journal'; | ||
import { outlineTab } from './tabs/outline'; | ||
|
||
// the list of all possible tabs in affine. | ||
// order matters (determines the order of the tabs) | ||
export const sidebarTabs: SidebarTab[] = [ | ||
chatTab, | ||
journalTab, | ||
outlineTab, | ||
framePanelTab, | ||
copilotTab, | ||
]; |
File renamed without changes.
40 changes: 40 additions & 0 deletions
40
packages/frontend/core/src/modules/multi-tab-sidebar/entities/tabs/chat.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { assertExists } from '@blocksuite/global/utils'; | ||
import { AiIcon } from '@blocksuite/icons'; | ||
import { ChatPanel } from '@blocksuite/presets'; | ||
import { useCallback, useRef } from 'react'; | ||
|
||
import type { SidebarTab, SidebarTabProps } from '../sidebar-tab'; | ||
import * as styles from './chat.css'; | ||
|
||
// A wrapper for CopilotPanel | ||
const EditorChatPanel = ({ editor }: SidebarTabProps) => { | ||
const chatPanelRef = useRef<ChatPanel | null>(null); | ||
|
||
const onRefChange = useCallback((container: HTMLDivElement | null) => { | ||
if (container) { | ||
assertExists(chatPanelRef.current, 'chat panel should be initialized'); | ||
container.append(chatPanelRef.current); | ||
} | ||
}, []); | ||
|
||
if (!editor) { | ||
return; | ||
} | ||
|
||
if (!chatPanelRef.current) { | ||
chatPanelRef.current = new ChatPanel(); | ||
} | ||
|
||
if (editor !== chatPanelRef.current?.editor) { | ||
(chatPanelRef.current as ChatPanel).editor = editor; | ||
// (copilotPanelRef.current as CopilotPanel).fitPadding = [20, 20, 20, 20]; | ||
} | ||
|
||
return <div className={styles.root} ref={onRefChange} />; | ||
}; | ||
|
||
export const chatTab: SidebarTab = { | ||
name: 'chat', | ||
icon: <AiIcon />, | ||
Component: EditorChatPanel, | ||
}; |
Oops, something went wrong.