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,
} from './error';
export enum Endpoint {
Stream = 'stream',
StreamObject = 'stream-object',
Workflow = 'workflow',
Images = 'images',
}
type OptionsField<T extends GraphQLQuery> =
RequestOptions<T>['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({

View File

@@ -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;

View File

@@ -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,
});
});