### TL;DR
Refactor space-triggered AI Widget activation logic from `keydown` to `keypress` event listeners
### Background
The `keydown` event triggered by a space may originate from:
1. Normal space insertion
2. Space triggered by input method confirming candidate words
In scenarios like (2), some browsers (see [ISSUE](https://github.com/toeverything/AFFiNE/issues/11541)) and input method callbacks produce events identical to scenario (1),making it impossible to distinguish between the two.
To fix this, the space-activated AI listener uses the `keypress` event:
In scenario 2, `event.which !== 32` (may be `30430` or other values) can be used to differentiate from scenario 1.
> CLOSE BS-3081
### TL:DR
By sharing initialization logic, accelerate test case execution.
### What Changed
* Global setup for copilot e2e
* Login
* Create Workspace
* Enable fully parallel for ci
### Optimization Comparison
Comparing with PR [fix(core): ask AI input box in the whiteboard is blocked by the menu …](https://github.com/toeverything/AFFiNE/pull/11634):
| | Shard 1 |2|3|4|5|6|7|8|
| ------|----|----|----|----|----|---|---|--|
|Before|15min|14min|14min|14min|14min|13min|15min|10min|
|After|8min|11min|8min|8min|8min|8min|8min|7min|
### Trade-Off
Since all copilot use cases currently share a single user and workspace, some test cases need to focus on **isolation** and **independence**.
For example, when testing Embedding-related workflows:
* Different document contents should be used to avoid interference.
* After each test case execution, **cleanup** operations are also required.
* Some tests should be configured to **serial** mode.
```ts
test.describe.configure({ mode: 'serial' });
test.describe('AIChatWith/Collections', () => {
test.beforeEach(async ({ loggedInPage: page, utils }) => {
await utils.testUtils.setupTestEnvironment(page);
await utils.chatPanel.openChatPanel(page);
await utils.editor.clearAllCollections(page);
await utils.testUtils.createNewPage(page);
});
test.afterEach(async ({ loggedInPage: page, utils }) => {
// clear all collections
await utils.editor.clearAllCollections(page);
});
test('should support chat with collection', async ({
loggedInPage: page,
utils,
}) => {
// Create two collections
await utils.editor.createCollectionAndDoc(
page,
'Collection 1',
'CollectionAAaa is a cute dog'
);
await utils.chatPanel.chatWithCollections(page, ['Collection 1']);
await utils.chatPanel.makeChat(page, 'What is CollectionAAaa(Use English)');
// ...
});
test('should support chat with multiple collections', async ({
loggedInPage: page,
utils,
}) => {
// Create two collections
await utils.editor.createCollectionAndDoc(
page,
'Collection 2',
'CollectionEEee is a cute cat'
);
await utils.editor.createCollectionAndDoc(
page,
'Collection 3',
'CollectionFFff is a cute dog'
);
await utils.chatPanel.chatWithCollections(page, [
'Collection 2',
'Collection 3',
]);
await utils.chatPanel.makeChat(
page,
'What is CollectionEEee? What is CollectionFFff?(Use English)'
);
// ...
});
});
```
> CLOSE AI-51
### TL;DR
Split and enhance copilot e2e tests.
### What Changed
#### Tests Structure
The e2e tests are organized into the following categories:
1. **Basic Tests (`/basic`)**: Tests for verifying core AI capabilities including feature onboarding, authorization workflows, and basic chat interactions.
2. **Chat Interaction Tests (`/chat-with`)**: Tests for verifying the AI's interaction with various object types, such as attachments, images, text content, Edgeless elements, etc.
3. **AI Action Tests (`/ai-action`)**: Tests for verifying the AI's actions, such as text translation, gramma correction, etc.
4. **Insertion Tests (`/insertion`)**: Tests for verifying answer insertion functionality.
#### Tests Writing
Writing a copilot test cases is easier and clear
e.g.
```ts
test('support chat with specified doc', async ({ page, utils }) => {
// Initialize the doc
await focusDocTitle(page);
await page.keyboard.insertText('Test Doc');
await page.keyboard.press('Enter');
await page.keyboard.insertText('EEee is a cute cat');
await utils.chatPanel.chatWithDoc(page, 'Test Doc');
await utils.chatPanel.makeChat(page, 'What is EEee?');
await utils.chatPanel.waitForHistory(page, [
{
role: 'user',
content: 'What is EEee?',
},
{
role: 'assistant',
status: 'success',
},
]);
const { content } = await utils.chatPanel.getLatestAssistantMessage(page);
expect(content).toMatch(/EEee/);
});
```
#### Summary
||Cases|
|------|----|
|Before|19||
|After|151||
> Close BS-2769
### TL;DR
Refactor style of user chat message
> CLOSE AF-2323 AF-2324 AF-2325
### What Changed
* Refactor style of user message.
* Refactor style of image message.
### TL;DR
Added "Save as doc" option to Edgeless editor actions.
### What changed?
- Renamed `SAVE_CHAT_TO_BLOCK_ACTION` to `SAVE_AS_BLOCK` and updated its title from "Save chat to block" to "Save as block"
- Renamed `CREATE_AS_DOC` to `SAVE_AS_DOC` and updated its title from "Create as a doc" to "Save as doc"
- Added `SAVE_AS_DOC` to the `EdgelessEditorActions` array, making this option available in the Edgeless editor
### TL;DR
Refactor the insert below functionality to work with page mode and edgeless mode
* Page Mode
- Insert content below the current selection
- If nothing selected, insert content below the last block
* EdgeLess Mode
- If no note block is currently selected, create the content as a new note block.
- Otherwise, insert content into the selected note
Close BS-2760
### What changed?
- Created separate insert handlers for page and edgeless modes with context-aware behavior
- Added support for inserting content when nothing is selected by targeting the last content block
- Added special handling for edgeless mode to support inserting below selected note blocks
- Removed the "Replace selection" action and consolidated insert functionality
- Optimized the clickable area of the action button
Close [BS-2791](https://linear.app/affine-design/issue/BS-2791).
### What Changed?
- Add status filed to `CopilotContextDoc` to querying document embedding processing progress.
- Change `ChipState` from `success` to `finished` to better align with backend server status.
- Add `pollContextDocsAndFiles` API for embedding status polling.
### About Polling
- Set the minimum interval to 1 second and the maximum interval to 30 seconds
- Use exponential backoff and increase the interval by 50% after each poll
- Make sure the interval does not exceed the maximum
Support issue [BS-2353](https://linear.app/affine-design/issue/BS-2353).
### What changed?
- Remove `Open AI Chat` menu item.
- Remove `chat-cards` web component.
- Add `extractAll` function for page and edgeless doc full content extract.