fix(core): ai make it real ci timeout (#12954)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## 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.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com>
This commit is contained in:
Wu Yue
2025-06-28 20:56:12 +08:00
committed by GitHub
parent f88e1dffb6
commit a4680d236d
4 changed files with 25 additions and 28 deletions

View File

@@ -34,6 +34,13 @@ import {
UnauthorizedError, UnauthorizedError,
} from './error'; } from './error';
export enum Endpoint {
Stream = 'stream',
StreamObject = 'stream-object',
Workflow = 'workflow',
Images = 'images',
}
type OptionsField<T extends GraphQLQuery> = type OptionsField<T extends GraphQLQuery> =
RequestOptions<T>['variables'] extends { options: infer U } ? U : never; RequestOptions<T>['variables'] extends { options: infer U } ? U : never;
@@ -415,7 +422,7 @@ export class CopilotClient {
webSearch?: boolean; webSearch?: boolean;
modelId?: string; modelId?: string;
}, },
endpoint = 'stream' endpoint = Endpoint.Stream
) { ) {
let url = `/api/copilot/chat/${sessionId}/${endpoint}`; let url = `/api/copilot/chat/${sessionId}/${endpoint}`;
const queryString = this.paramsToQueryString({ const queryString = this.paramsToQueryString({
@@ -435,7 +442,7 @@ export class CopilotClient {
sessionId: string, sessionId: string,
messageId?: string, messageId?: string,
seed?: string, seed?: string,
endpoint = 'images' endpoint = Endpoint.Images
) { ) {
let url = `/api/copilot/chat/${sessionId}/${endpoint}`; let url = `/api/copilot/chat/${sessionId}/${endpoint}`;
const queryString = this.paramsToQueryString({ const queryString = this.paramsToQueryString({

View File

@@ -1,7 +1,7 @@
import { partition } from 'lodash-es'; import { partition } from 'lodash-es';
import { AIProvider } from './ai-provider'; import { AIProvider } from './ai-provider';
import type { CopilotClient } from './copilot-client'; import { type CopilotClient, Endpoint } from './copilot-client';
import { delay, toTextStream } from './event-source'; import { delay, toTextStream } from './event-source';
const TIMEOUT = 50000; const TIMEOUT = 50000;
@@ -16,7 +16,7 @@ export type TextToTextOptions = {
stream?: boolean; stream?: boolean;
signal?: AbortSignal; signal?: AbortSignal;
retry?: boolean; retry?: boolean;
workflow?: boolean; endpoint?: Endpoint;
isRootSession?: boolean; isRootSession?: boolean;
postfix?: (text: string) => string; postfix?: (text: string) => string;
reasoning?: boolean; reasoning?: boolean;
@@ -114,7 +114,7 @@ export function textToText({
signal, signal,
timeout = TIMEOUT, timeout = TIMEOUT,
retry = false, retry = false,
workflow = false, endpoint = Endpoint.Stream,
postfix, postfix,
reasoning, reasoning,
webSearch, webSearch,
@@ -142,7 +142,7 @@ export function textToText({
webSearch, webSearch,
modelId, modelId,
}, },
workflow ? 'workflow' : 'stream-object' endpoint
); );
AIProvider.LAST_ACTION_SESSIONID = sessionId; AIProvider.LAST_ACTION_SESSIONID = sessionId;
@@ -219,7 +219,7 @@ export function toImage({
signal, signal,
timeout = TIMEOUT, timeout = TIMEOUT,
retry = false, retry = false,
workflow = false, endpoint,
client, client,
}: ToImageOptions) { }: ToImageOptions) {
let messageId: string | undefined; let messageId: string | undefined;
@@ -238,7 +238,7 @@ export function toImage({
sessionId, sessionId,
messageId, messageId,
seed, seed,
workflow ? 'workflow' : undefined endpoint
); );
AIProvider.LAST_ACTION_SESSIONID = sessionId; AIProvider.LAST_ACTION_SESSIONID = sessionId;

View File

@@ -11,7 +11,7 @@ import {
import { z } from 'zod'; import { z } from 'zod';
import { AIProvider } from './ai-provider'; import { AIProvider } from './ai-provider';
import type { CopilotClient } from './copilot-client'; import { type CopilotClient, Endpoint } from './copilot-client';
import type { PromptKey } from './prompt'; import type { PromptKey } from './prompt';
import { textToText, toImage } from './request'; import { textToText, toImage } from './request';
import { setupTracker } from './tracker'; import { setupTracker } from './tracker';
@@ -101,6 +101,7 @@ export function setupAIProvider(
files: contexts?.files, files: contexts?.files,
searchMode: webSearch ? 'MUST' : 'AUTO', searchMode: webSearch ? 'MUST' : 'AUTO',
}, },
endpoint: Endpoint.StreamObject,
}); });
}); });
@@ -356,7 +357,7 @@ export function setupAIProvider(
content: options.input, content: options.input,
// 3 minutes // 3 minutes
timeout: 180000, 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, content: options.input,
// 3 minutes // 3 minutes
timeout: 180000, timeout: 180000,
workflow: true, endpoint: Endpoint.Workflow,
postfix, postfix,
}); });
}); });
@@ -517,13 +518,14 @@ Could you make a new website based on these notes and send back just the html fi
promptName, promptName,
...options, ...options,
}); });
const isWorkflow = !!promptName?.startsWith('workflow:');
return toImage({ return toImage({
...options, ...options,
client, client,
sessionId, sessionId,
content: options.input, content: options.input,
timeout: 180000, timeout: 180000,
workflow: !!promptName?.startsWith('workflow:'), endpoint: isWorkflow ? Endpoint.Workflow : Endpoint.Images,
}); });
}); });

View File

@@ -12,10 +12,7 @@ test.describe('AIAction/MakeItReal', () => {
loggedInPage: page, loggedInPage: page,
utils, utils,
}) => { }) => {
const { makeItReal } = await utils.editor.askAIWithText( const { makeItReal } = await utils.editor.askAIWithText(page, 'Hello');
page,
'AFFiNE is a workspace with fully merged docs'
);
const { answer, responses } = await makeItReal(); const { answer, responses } = await makeItReal();
await expect(answer.locator('iframe')).toBeVisible({ timeout: 30000 }); await expect(answer.locator('iframe')).toBeVisible({ timeout: 30000 });
expect(responses).toEqual(new Set(['insert-below'])); expect(responses).toEqual(new Set(['insert-below']));
@@ -28,10 +25,7 @@ test.describe('AIAction/MakeItReal', () => {
const { makeItReal } = await utils.editor.askAIWithEdgeless( const { makeItReal } = await utils.editor.askAIWithEdgeless(
page, page,
async () => { async () => {
await utils.editor.createEdgelessText( await utils.editor.createEdgelessText(page, 'Hello');
page,
'AFFiNE is a workspace with fully merged docs'
);
} }
); );
const { answer, responses } = await makeItReal(); const { answer, responses } = await makeItReal();
@@ -46,10 +40,7 @@ test.describe('AIAction/MakeItReal', () => {
const { makeItReal } = await utils.editor.askAIWithEdgeless( const { makeItReal } = await utils.editor.askAIWithEdgeless(
page, page,
async () => { async () => {
await utils.editor.createEdgelessNote( await utils.editor.createEdgelessNote(page, 'Hello');
page,
'AFFiNE is a workspace with fully merged docs'
);
} }
); );
const { answer, responses } = await makeItReal(); const { answer, responses } = await makeItReal();
@@ -77,10 +68,7 @@ test.describe('AIAction/MakeItReal', () => {
loggedInPage: page, loggedInPage: page,
utils, utils,
}) => { }) => {
const { makeItReal } = await utils.editor.askAIWithText( const { makeItReal } = await utils.editor.askAIWithText(page, 'Hello');
page,
'AFFiNE is a workspace with fully merged docs'
);
const { answer } = await makeItReal(); const { answer } = await makeItReal();
const insert = answer.getByTestId('answer-insert-below'); const insert = answer.getByTestId('answer-insert-below');
await insert.click(); await insert.click();