From a4680d236d2287ff19bfbecb0920f5cb0838d58d Mon Sep 17 00:00:00 2001 From: Wu Yue Date: Sat, 28 Jun 2025 20:56:12 +0800 Subject: [PATCH] fix(core): ai make it real ci timeout (#12954) ## Summary by CodeRabbit * **Refactor** * Replaced the boolean flag for selecting AI workflow endpoints with a clear and flexible enum, enhancing clarity and maintainability for AI-powered features. * **Tests** * Simplified example text in AI action tests to improve consistency. Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com> --- .../blocksuite/ai/provider/copilot-client.ts | 11 ++++++++-- .../src/blocksuite/ai/provider/request.ts | 12 +++++------ .../blocksuite/ai/provider/setup-provider.tsx | 10 ++++++---- .../e2e/ai-action/make-it-real.spec.ts | 20 ++++--------------- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/packages/frontend/core/src/blocksuite/ai/provider/copilot-client.ts b/packages/frontend/core/src/blocksuite/ai/provider/copilot-client.ts index 7583a0f8f4..5304dde0b8 100644 --- a/packages/frontend/core/src/blocksuite/ai/provider/copilot-client.ts +++ b/packages/frontend/core/src/blocksuite/ai/provider/copilot-client.ts @@ -34,6 +34,13 @@ import { UnauthorizedError, } from './error'; +export enum Endpoint { + Stream = 'stream', + StreamObject = 'stream-object', + Workflow = 'workflow', + Images = 'images', +} + type OptionsField = RequestOptions['variables'] extends { options: infer U } ? U : never; @@ -415,7 +422,7 @@ export class CopilotClient { webSearch?: boolean; modelId?: string; }, - endpoint = 'stream' + endpoint = Endpoint.Stream ) { let url = `/api/copilot/chat/${sessionId}/${endpoint}`; const queryString = this.paramsToQueryString({ @@ -435,7 +442,7 @@ export class CopilotClient { sessionId: string, messageId?: string, seed?: string, - endpoint = 'images' + endpoint = Endpoint.Images ) { let url = `/api/copilot/chat/${sessionId}/${endpoint}`; const queryString = this.paramsToQueryString({ diff --git a/packages/frontend/core/src/blocksuite/ai/provider/request.ts b/packages/frontend/core/src/blocksuite/ai/provider/request.ts index edc0bba5c8..aaa0410618 100644 --- a/packages/frontend/core/src/blocksuite/ai/provider/request.ts +++ b/packages/frontend/core/src/blocksuite/ai/provider/request.ts @@ -1,7 +1,7 @@ import { partition } from 'lodash-es'; import { AIProvider } from './ai-provider'; -import type { CopilotClient } from './copilot-client'; +import { type CopilotClient, Endpoint } from './copilot-client'; import { delay, toTextStream } from './event-source'; const TIMEOUT = 50000; @@ -16,7 +16,7 @@ export type TextToTextOptions = { stream?: boolean; signal?: AbortSignal; retry?: boolean; - workflow?: boolean; + endpoint?: Endpoint; isRootSession?: boolean; postfix?: (text: string) => string; reasoning?: boolean; @@ -114,7 +114,7 @@ export function textToText({ signal, timeout = TIMEOUT, retry = false, - workflow = false, + endpoint = Endpoint.Stream, postfix, reasoning, webSearch, @@ -142,7 +142,7 @@ export function textToText({ webSearch, modelId, }, - workflow ? 'workflow' : 'stream-object' + endpoint ); AIProvider.LAST_ACTION_SESSIONID = sessionId; @@ -219,7 +219,7 @@ export function toImage({ signal, timeout = TIMEOUT, retry = false, - workflow = false, + endpoint, client, }: ToImageOptions) { let messageId: string | undefined; @@ -238,7 +238,7 @@ export function toImage({ sessionId, messageId, seed, - workflow ? 'workflow' : undefined + endpoint ); AIProvider.LAST_ACTION_SESSIONID = sessionId; diff --git a/packages/frontend/core/src/blocksuite/ai/provider/setup-provider.tsx b/packages/frontend/core/src/blocksuite/ai/provider/setup-provider.tsx index 51758b8b5a..58d45d7ace 100644 --- a/packages/frontend/core/src/blocksuite/ai/provider/setup-provider.tsx +++ b/packages/frontend/core/src/blocksuite/ai/provider/setup-provider.tsx @@ -11,7 +11,7 @@ import { import { z } from 'zod'; import { AIProvider } from './ai-provider'; -import type { CopilotClient } from './copilot-client'; +import { type CopilotClient, Endpoint } from './copilot-client'; import type { PromptKey } from './prompt'; import { textToText, toImage } from './request'; import { setupTracker } from './tracker'; @@ -101,6 +101,7 @@ export function setupAIProvider( files: contexts?.files, searchMode: webSearch ? 'MUST' : 'AUTO', }, + endpoint: Endpoint.StreamObject, }); }); @@ -356,7 +357,7 @@ export function setupAIProvider( content: options.input, // 3 minutes timeout: 180000, - workflow: true, + endpoint: Endpoint.Workflow, }); }); @@ -482,7 +483,7 @@ Could you make a new website based on these notes and send back just the html fi content: options.input, // 3 minutes timeout: 180000, - workflow: true, + endpoint: Endpoint.Workflow, postfix, }); }); @@ -517,13 +518,14 @@ Could you make a new website based on these notes and send back just the html fi promptName, ...options, }); + const isWorkflow = !!promptName?.startsWith('workflow:'); return toImage({ ...options, client, sessionId, content: options.input, timeout: 180000, - workflow: !!promptName?.startsWith('workflow:'), + endpoint: isWorkflow ? Endpoint.Workflow : Endpoint.Images, }); }); diff --git a/tests/affine-cloud-copilot/e2e/ai-action/make-it-real.spec.ts b/tests/affine-cloud-copilot/e2e/ai-action/make-it-real.spec.ts index 1b659e6619..8efca253dd 100644 --- a/tests/affine-cloud-copilot/e2e/ai-action/make-it-real.spec.ts +++ b/tests/affine-cloud-copilot/e2e/ai-action/make-it-real.spec.ts @@ -12,10 +12,7 @@ test.describe('AIAction/MakeItReal', () => { loggedInPage: page, utils, }) => { - const { makeItReal } = await utils.editor.askAIWithText( - page, - 'AFFiNE is a workspace with fully merged docs' - ); + const { makeItReal } = await utils.editor.askAIWithText(page, 'Hello'); const { answer, responses } = await makeItReal(); await expect(answer.locator('iframe')).toBeVisible({ timeout: 30000 }); expect(responses).toEqual(new Set(['insert-below'])); @@ -28,10 +25,7 @@ test.describe('AIAction/MakeItReal', () => { const { makeItReal } = await utils.editor.askAIWithEdgeless( page, async () => { - await utils.editor.createEdgelessText( - page, - 'AFFiNE is a workspace with fully merged docs' - ); + await utils.editor.createEdgelessText(page, 'Hello'); } ); const { answer, responses } = await makeItReal(); @@ -46,10 +40,7 @@ test.describe('AIAction/MakeItReal', () => { const { makeItReal } = await utils.editor.askAIWithEdgeless( page, async () => { - await utils.editor.createEdgelessNote( - page, - 'AFFiNE is a workspace with fully merged docs' - ); + await utils.editor.createEdgelessNote(page, 'Hello'); } ); const { answer, responses } = await makeItReal(); @@ -77,10 +68,7 @@ test.describe('AIAction/MakeItReal', () => { loggedInPage: page, utils, }) => { - const { makeItReal } = await utils.editor.askAIWithText( - page, - 'AFFiNE is a workspace with fully merged docs' - ); + const { makeItReal } = await utils.editor.askAIWithText(page, 'Hello'); const { answer } = await makeItReal(); const insert = answer.getByTestId('answer-insert-below'); await insert.click();