mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-04 02:49:57 +08:00
feat(server): adapt gemini3.1 preview (#14583)
#### PR Dependency Tree * **PR #14583** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added Gemini 3.1 Pro Preview support (text, image, audio) and new GPT‑5 variants as defaults; centralized persistent telemetry state for more reliable client identity. * **UX** * Improved model submenu placement in chat preferences. * More robust mindmap parsing, preview, regeneration and replace behavior. * **Chores** * Bumped AI SDK and related dependencies. * **Tests** * Expanded/updated tests and increased timeouts for flaky flows. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -14,11 +14,13 @@ test.describe('AIAction/CheckCodeError', () => {
|
||||
}) => {
|
||||
const { checkCodeError } = await utils.editor.askAIWithCode(
|
||||
page,
|
||||
'consloe.log("Hello,World!");',
|
||||
'console.log("Hello,World!"',
|
||||
'javascript'
|
||||
);
|
||||
const { answer, responses } = await checkCodeError();
|
||||
await expect(answer).toHaveText(/console/);
|
||||
const answerText = await answer.innerText();
|
||||
expect(answerText).toMatch(/syntax|parenthesis|unexpected|missing/i);
|
||||
expect(answerText).not.toMatch(/No syntax errors were found/i);
|
||||
await expect(responses).toEqual(
|
||||
new Set(['insert-below', 'replace-selection'])
|
||||
);
|
||||
|
||||
@@ -33,6 +33,6 @@ test.describe('expand mindmap node', () => {
|
||||
await expect(async () => {
|
||||
const newChild = await utils.editor.getMindMapNode(page, id!, [0, 0, 0]);
|
||||
expect(newChild).toBeDefined();
|
||||
}).toPass({ timeout: 20000 });
|
||||
}).toPass({ timeout: 60000 });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,7 +17,10 @@ test.describe('AIAction/ExplainSelection', () => {
|
||||
'LLM(AI)'
|
||||
);
|
||||
const { answer, responses } = await explainSelection();
|
||||
await expect(answer).toHaveText(/Large Language Model/, { timeout: 20000 });
|
||||
await expect(answer).toHaveText(
|
||||
/Large Language Model|LLM|artificial intelligence/i,
|
||||
{ timeout: 20000 }
|
||||
);
|
||||
expect(responses).toEqual(new Set(['insert-below', 'replace-selection']));
|
||||
});
|
||||
|
||||
@@ -33,7 +36,10 @@ test.describe('AIAction/ExplainSelection', () => {
|
||||
);
|
||||
|
||||
const { answer, responses } = await explainSelection();
|
||||
await expect(answer).toHaveText(/Large Language Model/, { timeout: 20000 });
|
||||
await expect(answer).toHaveText(
|
||||
/Large Language Model|LLM|artificial intelligence/i,
|
||||
{ timeout: 20000 }
|
||||
);
|
||||
expect(responses).toEqual(new Set(['insert-below']));
|
||||
});
|
||||
|
||||
@@ -49,7 +55,10 @@ test.describe('AIAction/ExplainSelection', () => {
|
||||
);
|
||||
|
||||
const { answer, responses } = await explainSelection();
|
||||
await expect(answer).toHaveText(/Large Language Model/, { timeout: 20000 });
|
||||
await expect(answer).toHaveText(
|
||||
/Large Language Model|LLM|artificial intelligence/i,
|
||||
{ timeout: 20000 }
|
||||
);
|
||||
expect(responses).toEqual(new Set(['insert-below']));
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ import { expect } from '@playwright/test';
|
||||
import { test } from '../base/base-test';
|
||||
|
||||
test.describe('AIAction/GeneratePresentation', () => {
|
||||
test.describe.configure({ timeout: 240000 });
|
||||
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
|
||||
@@ -3,6 +3,8 @@ import { expect } from '@playwright/test';
|
||||
import { test } from '../base/base-test';
|
||||
|
||||
test.describe('AIAction/MakeItReal', () => {
|
||||
test.describe.configure({ timeout: 180000 });
|
||||
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
|
||||
@@ -74,13 +74,13 @@ test.describe('AIChatWith/Attachments', () => {
|
||||
buffer: buffer2,
|
||||
},
|
||||
],
|
||||
`What is Attachment${randomStr1}? What is Attachment${randomStr2}?`
|
||||
`Which animal is Attachment${randomStr1} and which animal is Attachment${randomStr2}? Answer with both attachment names.`
|
||||
);
|
||||
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
content: `What is Attachment${randomStr1}? What is Attachment${randomStr2}?`,
|
||||
content: `Which animal is Attachment${randomStr1} and which animal is Attachment${randomStr2}? Answer with both attachment names.`,
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
@@ -89,14 +89,11 @@ test.describe('AIChatWith/Attachments', () => {
|
||||
]);
|
||||
|
||||
await expect(async () => {
|
||||
const { content, message } =
|
||||
await utils.chatPanel.getLatestAssistantMessage(page);
|
||||
const { content } = await utils.chatPanel.getLatestAssistantMessage(page);
|
||||
expect(content).toMatch(new RegExp(`Attachment${randomStr1}`));
|
||||
expect(content).toMatch(new RegExp(`Attachment${randomStr2}`));
|
||||
const footnoteCount = await message
|
||||
.locator('affine-footnote-node')
|
||||
.count();
|
||||
expect(footnoteCount > 0 || /sources?/i.test(content)).toBe(true);
|
||||
expect(content).toMatch(/cat/i);
|
||||
expect(content).toMatch(/dog/i);
|
||||
}).toPass({ timeout: 20000 });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,21 +4,39 @@ import { expect } from '@playwright/test';
|
||||
|
||||
import { test } from '../base/base-test';
|
||||
|
||||
type MindmapSnapshot = {
|
||||
childCount: number;
|
||||
count: number;
|
||||
id: string | null;
|
||||
};
|
||||
|
||||
test.describe('AIChatWith/EdgelessMindMap', () => {
|
||||
test.describe.configure({ timeout: 180000 });
|
||||
|
||||
test.beforeEach(async ({ loggedInPage: page, utils }) => {
|
||||
await utils.testUtils.setupTestEnvironment(page);
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
});
|
||||
|
||||
test('should support replace mindmap with the regenerated one', async ({
|
||||
test('should preview the regenerated mindmap before replacing it', async ({
|
||||
loggedInPage: page,
|
||||
utils,
|
||||
}) => {
|
||||
let id: string;
|
||||
let originalChildCount: number;
|
||||
const { regenerateMindMap } = await utils.editor.askAIWithEdgeless(
|
||||
page,
|
||||
async () => {
|
||||
id = await utils.editor.createMindmap(page);
|
||||
originalChildCount = await page.evaluate(mindmapId => {
|
||||
const edgelessBlock = document.querySelector(
|
||||
'affine-edgeless-root'
|
||||
) as EdgelessRootBlockComponent;
|
||||
const mindmap = edgelessBlock.gfx.getElementById(mindmapId) as {
|
||||
tree: { children?: unknown[] };
|
||||
} | null;
|
||||
return mindmap?.tree.children?.length ?? 0;
|
||||
}, id);
|
||||
},
|
||||
async () => {
|
||||
const { id: rootId } = await utils.editor.getMindMapNode(
|
||||
@@ -30,22 +48,134 @@ test.describe('AIChatWith/EdgelessMindMap', () => {
|
||||
}
|
||||
);
|
||||
|
||||
const { answer } = await regenerateMindMap();
|
||||
await expect(answer.locator('mini-mindmap-preview')).toBeVisible();
|
||||
const replace = answer.getByTestId('answer-replace');
|
||||
await replace.click();
|
||||
const { answer, responses } = await regenerateMindMap();
|
||||
expect(responses).toEqual(new Set(['replace-selection']));
|
||||
await expect
|
||||
.poll(
|
||||
async () => {
|
||||
return answer
|
||||
.locator('mini-mindmap-preview')
|
||||
.evaluate(async preview => {
|
||||
const walk = (root: ParentNode): Element[] => {
|
||||
const results: Element[] = [];
|
||||
|
||||
// Expect original mindmap to be replaced
|
||||
const mindmaps = await page.evaluate(() => {
|
||||
for (const element of root.querySelectorAll('*')) {
|
||||
results.push(element);
|
||||
if (element.shadowRoot) {
|
||||
results.push(...walk(element.shadowRoot));
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
};
|
||||
|
||||
await customElements.whenDefined('mini-mindmap-preview');
|
||||
|
||||
const previewElement =
|
||||
preview instanceof HTMLElement
|
||||
? (preview as HTMLElement & {
|
||||
updateComplete?: Promise<unknown>;
|
||||
})
|
||||
: null;
|
||||
|
||||
await previewElement?.updateComplete;
|
||||
await new Promise(resolve =>
|
||||
requestAnimationFrame(() => resolve(null))
|
||||
);
|
||||
|
||||
const shadowRoot = previewElement?.shadowRoot ?? null;
|
||||
const descendants = walk(shadowRoot ?? preview);
|
||||
const surface = descendants.find(
|
||||
element =>
|
||||
element instanceof HTMLElement &&
|
||||
element.classList.contains('affine-mini-mindmap-surface')
|
||||
) as HTMLElement | undefined;
|
||||
const surfaceRect = surface?.getBoundingClientRect();
|
||||
|
||||
return {
|
||||
hasShadowRoot: !!shadowRoot,
|
||||
hasRootBlock: descendants.some(
|
||||
element =>
|
||||
element.tagName.toLowerCase() === 'mini-mindmap-root-block'
|
||||
),
|
||||
hasSurfaceBlock: descendants.some(
|
||||
element =>
|
||||
element.tagName.toLowerCase() ===
|
||||
'mini-mindmap-surface-block'
|
||||
),
|
||||
surfaceReady:
|
||||
!!surface &&
|
||||
(surfaceRect?.width ?? 0) > 0 &&
|
||||
(surfaceRect?.height ?? 0) > 0,
|
||||
};
|
||||
});
|
||||
},
|
||||
{ timeout: 15_000 }
|
||||
)
|
||||
.toEqual({
|
||||
hasShadowRoot: true,
|
||||
hasRootBlock: true,
|
||||
hasSurfaceBlock: true,
|
||||
surfaceReady: true,
|
||||
});
|
||||
const replace = answer.getByTestId('answer-replace');
|
||||
await expect(replace).toBeVisible();
|
||||
await replace.click({ force: true });
|
||||
|
||||
await expect
|
||||
.poll(
|
||||
async () => {
|
||||
return page.evaluate<MindmapSnapshot>(() => {
|
||||
const edgelessBlock = document.querySelector(
|
||||
'affine-edgeless-root'
|
||||
) as EdgelessRootBlockComponent;
|
||||
const mindmaps = edgelessBlock?.gfx.gfxElements.filter(
|
||||
(el: GfxModel) => 'type' in el && el.type === 'mindmap'
|
||||
) as unknown as Array<{
|
||||
id: string;
|
||||
tree: {
|
||||
children?: unknown[];
|
||||
element: { text?: { toString(): string } };
|
||||
};
|
||||
}>;
|
||||
|
||||
const mindmap = mindmaps?.[0];
|
||||
return {
|
||||
count: mindmaps?.length ?? 0,
|
||||
id: mindmap?.id ?? null,
|
||||
childCount: mindmap?.tree.children?.length ?? 0,
|
||||
};
|
||||
});
|
||||
},
|
||||
{ timeout: 15_000 }
|
||||
)
|
||||
.toMatchObject({
|
||||
count: 1,
|
||||
});
|
||||
|
||||
const replacedMindmap = await page.evaluate<MindmapSnapshot>(() => {
|
||||
const edgelessBlock = document.querySelector(
|
||||
'affine-edgeless-root'
|
||||
) as EdgelessRootBlockComponent;
|
||||
const mindmaps = edgelessBlock?.gfx.gfxElements
|
||||
.filter((el: GfxModel) => 'type' in el && el.type === 'mindmap')
|
||||
.map((el: GfxModel) => el.id);
|
||||
return mindmaps;
|
||||
const mindmaps = edgelessBlock?.gfx.gfxElements.filter(
|
||||
(el: GfxModel) => 'type' in el && el.type === 'mindmap'
|
||||
) as unknown as Array<{
|
||||
id: string;
|
||||
tree: {
|
||||
children?: unknown[];
|
||||
element: { text?: { toString(): string } };
|
||||
};
|
||||
}>;
|
||||
const mindmap = mindmaps?.[0];
|
||||
|
||||
return {
|
||||
count: mindmaps?.length ?? 0,
|
||||
id: mindmap?.id ?? null,
|
||||
childCount: mindmap?.tree.children?.length ?? 0,
|
||||
};
|
||||
});
|
||||
expect(mindmaps).toHaveLength(1);
|
||||
expect(mindmaps?.[0]).not.toBe(id!);
|
||||
|
||||
expect(replacedMindmap.childCount).toBeGreaterThan(originalChildCount!);
|
||||
expect(replacedMindmap.childCount).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -90,17 +90,34 @@ export class EditorUtils {
|
||||
return answer;
|
||||
}
|
||||
|
||||
private static createAction(page: Page, action: () => Promise<void>) {
|
||||
private static createAction(
|
||||
page: Page,
|
||||
action: () => Promise<void>,
|
||||
options?: { responseTimeoutMs?: number }
|
||||
) {
|
||||
return async () => {
|
||||
const responseTimeoutMs = options?.responseTimeoutMs ?? 60000;
|
||||
|
||||
await action();
|
||||
await this.waitForAiAnswer(page);
|
||||
await page.getByTestId('ai-generating').waitFor({
|
||||
state: 'hidden',
|
||||
timeout: 2 * 60000,
|
||||
});
|
||||
|
||||
const responses = new Set<string>();
|
||||
const answer = await this.waitForAiAnswer(page);
|
||||
const responsesMenu = answer.getByTestId('answer-responses');
|
||||
await responsesMenu.isVisible();
|
||||
await responsesMenu.scrollIntoViewIfNeeded({ timeout: 60000 });
|
||||
await responsesMenu.waitFor({
|
||||
state: 'visible',
|
||||
timeout: responseTimeoutMs,
|
||||
});
|
||||
await responsesMenu.scrollIntoViewIfNeeded({
|
||||
timeout: responseTimeoutMs,
|
||||
});
|
||||
await responsesMenu
|
||||
.getByTestId('answer-insert-below-loading')
|
||||
.waitFor({ state: 'hidden' });
|
||||
.waitFor({ state: 'hidden', timeout: responseTimeoutMs });
|
||||
|
||||
if (await responsesMenu.getByTestId('answer-insert-below').isVisible()) {
|
||||
responses.add('insert-below');
|
||||
@@ -458,8 +475,10 @@ export class EditorUtils {
|
||||
generateOutline: this.createAction(page, () =>
|
||||
page.getByTestId('action-generate-outline').click()
|
||||
),
|
||||
generatePresentation: this.createAction(page, () =>
|
||||
page.getByTestId('action-generate-presentation').click()
|
||||
generatePresentation: this.createAction(
|
||||
page,
|
||||
() => page.getByTestId('action-generate-presentation').click(),
|
||||
{ responseTimeoutMs: 120000 }
|
||||
),
|
||||
imageProcessing: this.createAction(page, () =>
|
||||
page.getByTestId('action-image-processing').click()
|
||||
@@ -634,8 +653,10 @@ export class EditorUtils {
|
||||
generateOutline: this.createAction(page, () =>
|
||||
page.getByTestId('action-generate-outline').click()
|
||||
),
|
||||
generatePresentation: this.createAction(page, () =>
|
||||
page.getByTestId('action-generate-presentation').click()
|
||||
generatePresentation: this.createAction(
|
||||
page,
|
||||
() => page.getByTestId('action-generate-presentation').click(),
|
||||
{ responseTimeoutMs: 120000 }
|
||||
),
|
||||
imageProcessing: this.createAction(page, () =>
|
||||
page.getByTestId('action-image-processing').click()
|
||||
|
||||
@@ -280,6 +280,27 @@ export async function loginUserDirectly(
|
||||
}
|
||||
}
|
||||
|
||||
async function dismissBlockingModal(page: Page) {
|
||||
const modal = page.locator('modal-transition-container [data-modal="true"]');
|
||||
if (
|
||||
!(await modal
|
||||
.first()
|
||||
.isVisible()
|
||||
.catch(() => false))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const closeButton = page.getByTestId('modal-close-button').last();
|
||||
if (await closeButton.isVisible().catch(() => false)) {
|
||||
await closeButton.click({ timeout: 5000 });
|
||||
} else {
|
||||
await page.keyboard.press('Escape');
|
||||
}
|
||||
|
||||
await expect(modal.first()).toBeHidden({ timeout: 10000 });
|
||||
}
|
||||
|
||||
export async function enableCloudWorkspace(page: Page) {
|
||||
await clickSideBarSettingButton(page);
|
||||
await page.getByTestId('workspace-setting:preference').click();
|
||||
@@ -288,6 +309,7 @@ export async function enableCloudWorkspace(page: Page) {
|
||||
// wait for upload and delete local workspace
|
||||
await page.waitForTimeout(2000);
|
||||
await waitForAllPagesLoad(page);
|
||||
await dismissBlockingModal(page);
|
||||
await clickNewPageButton(page);
|
||||
}
|
||||
|
||||
@@ -303,6 +325,7 @@ export async function enableCloudWorkspaceFromShareButton(page: Page) {
|
||||
// wait for upload and delete local workspace
|
||||
await page.waitForTimeout(2000);
|
||||
await waitForEditorLoad(page);
|
||||
await dismissBlockingModal(page);
|
||||
await clickNewPageButton(page);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,10 @@ export async function clickNewPageButton(page: Page, title?: string) {
|
||||
}
|
||||
|
||||
export async function waitForEmptyEditor(page: Page) {
|
||||
await expect(page.locator('.doc-title-container-empty')).toBeVisible();
|
||||
await page.waitForSelector(
|
||||
'.doc-title-container-empty, doc-title .inline-editor',
|
||||
{ timeout: 20000 }
|
||||
);
|
||||
}
|
||||
|
||||
export function getBlockSuiteEditorTitle(page: Page) {
|
||||
|
||||
Reference in New Issue
Block a user