Skip to content

Commit 0e213a2

Browse files
authored
chore(core): remove useless enum AIActionType (#1725)
1 parent 3e87f45 commit 0e213a2

File tree

14 files changed

+39
-145
lines changed

14 files changed

+39
-145
lines changed

apps/chrome-extension/src/extension/recorder/utils.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
AIActionType,
32
type AIArgs,
43
callAIWithObjectResponse,
54
callAIWithStringResponse,
@@ -321,7 +320,7 @@ export const generateRecordTitle = async (
321320
const response = await callAIWithObjectResponse<{
322321
title: string;
323322
description: string;
324-
}>([prompt[0], prompt[1]], AIActionType.EXTRACT_DATA, modelConfig);
323+
}>([prompt[0], prompt[1]], modelConfig);
325324
if (response?.content) {
326325
return {
327326
title: response.content.title as string,
@@ -624,11 +623,7 @@ const generateAIMindmap = async (
624623
},
625624
];
626625

627-
const response = await callAIWithStringResponse(
628-
prompt,
629-
AIActionType.EXTRACT_DATA,
630-
modelConfig,
631-
);
626+
const response = await callAIWithStringResponse(prompt, modelConfig);
632627

633628
if (response?.content && typeof response.content === 'string') {
634629
return response.content as string;

packages/core/src/ai-model/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export {
3131
type ConversationHistoryOptions,
3232
} from './conversation-history';
3333

34-
export { AIActionType, type AIArgs } from '../common';
34+
export type { AIArgs } from '../common';
3535

3636
export {
3737
getMidsceneLocationSchema,

packages/core/src/ai-model/inspect.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ import type {
2323
ChatCompletionUserMessageParam,
2424
} from 'openai/resources/index';
2525
import type { TMultimodalPrompt, TUserPrompt } from '../common';
26-
import {
27-
AIActionType,
28-
adaptBboxToRect,
29-
expandSearchArea,
30-
mergeRects,
31-
} from '../common';
26+
import { adaptBboxToRect, expandSearchArea, mergeRects } from '../common';
3227
import {
3328
extractDataQueryPrompt,
3429
systemPromptToExtract,
@@ -200,7 +195,7 @@ export async function AiLocateElement(options: {
200195
msgs.push(...addOns);
201196
}
202197

203-
const res = await callAIFn(msgs, AIActionType.INSPECT_ELEMENT, modelConfig);
198+
const res = await callAIFn(msgs, modelConfig);
204199

205200
const rawResponse = JSON.stringify(res.content);
206201

@@ -315,7 +310,6 @@ export async function AiLocateSection(options: {
315310

316311
const result = await callAIWithObjectResponse<AISectionLocatorResponse>(
317312
msgs,
318-
AIActionType.EXTRACT_DATA,
319313
modelConfig,
320314
);
321315

@@ -436,7 +430,6 @@ export async function AiExtractElementInfo<T>(options: {
436430

437431
const result = await callAIWithObjectResponse<AIDataExtractionResponse<T>>(
438432
msgs,
439-
AIActionType.EXTRACT_DATA,
440433
modelConfig,
441434
);
442435
return {
@@ -465,11 +458,7 @@ export async function AiJudgeOrderSensitive(
465458
},
466459
];
467460

468-
const result = await callAIFn(
469-
msgs,
470-
AIActionType.INSPECT_ELEMENT, // Reuse existing action type for now
471-
modelConfig,
472-
);
461+
const result = await callAIFn(msgs, modelConfig);
473462

474463
return {
475464
isOrderSensitive: result.content.isOrderSensitive ?? false,

packages/core/src/ai-model/llm-planning.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { getDebug } from '@midscene/shared/logger';
1212
import { assert } from '@midscene/shared/utils';
1313
import type { ChatCompletionMessageParam } from 'openai/resources/index';
1414
import {
15-
AIActionType,
1615
buildYamlFlowFromPlans,
1716
fillBboxParam,
1817
findAllMidsceneLocatorField,
@@ -133,7 +132,6 @@ export async function plan(
133132
reasoning_content,
134133
} = await callAIWithObjectResponse<RawResponsePlanningAIResponse>(
135134
msgs,
136-
AIActionType.PLAN,
137135
modelConfig,
138136
{
139137
deepThink: opts.deepThink === 'unset' ? undefined : opts.deepThink,

packages/core/src/ai-model/prompt/playwright-generator.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
import { PLAYWRIGHT_EXAMPLE_CODE } from '@midscene/shared/constants';
66
import type { IModelConfig } from '@midscene/shared/env';
77
import type { ChatCompletionMessageParam } from 'openai/resources/index';
8-
import { AIActionType, callAI, callAIWithStringResponse } from '../index';
8+
import { callAI, callAIWithStringResponse } from '../index';
99
// Import shared utilities and types from yaml-generator
1010
import {
1111
type ChromeRecordedEvent,
@@ -126,11 +126,7 @@ ${PLAYWRIGHT_EXAMPLE_CODE}`;
126126
},
127127
];
128128

129-
const response = await callAIWithStringResponse(
130-
prompt,
131-
AIActionType.TEXT,
132-
modelConfig,
133-
);
129+
const response = await callAIWithStringResponse(prompt, modelConfig);
134130

135131
if (response?.content && typeof response.content === 'string') {
136132
return response.content;
@@ -212,17 +208,13 @@ ${PLAYWRIGHT_EXAMPLE_CODE}`;
212208

213209
if (options.stream && options.onChunk) {
214210
// Use streaming
215-
return await callAI(prompt, AIActionType.TEXT, modelConfig, {
211+
return await callAI(prompt, modelConfig, {
216212
stream: true,
217213
onChunk: options.onChunk,
218214
});
219215
} else {
220216
// Fallback to non-streaming
221-
const response = await callAIWithStringResponse(
222-
prompt,
223-
AIActionType.TEXT,
224-
modelConfig,
225-
);
217+
const response = await callAIWithStringResponse(prompt, modelConfig);
226218

227219
if (response?.content && typeof response.content === 'string') {
228220
return {

packages/core/src/ai-model/prompt/yaml-generator.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type {
55
import { YAML_EXAMPLE_CODE } from '@midscene/shared/constants';
66
import type { IModelConfig } from '@midscene/shared/env';
77
import {
8-
AIActionType,
98
type ChatCompletionMessageParam,
109
callAI,
1110
callAIWithStringResponse,
@@ -342,11 +341,7 @@ Important: Return ONLY the raw YAML content. Do NOT wrap the response in markdow
342341
});
343342
}
344343

345-
const response = await callAIWithStringResponse(
346-
prompt,
347-
AIActionType.TEXT,
348-
modelConfig,
349-
);
344+
const response = await callAIWithStringResponse(prompt, modelConfig);
350345

351346
if (response?.content && typeof response.content === 'string') {
352347
return response.content;
@@ -433,17 +428,13 @@ Important: Return ONLY the raw YAML content. Do NOT wrap the response in markdow
433428

434429
if (options.stream && options.onChunk) {
435430
// Use streaming
436-
return await callAI(prompt, AIActionType.TEXT, modelConfig, {
431+
return await callAI(prompt, modelConfig, {
437432
stream: true,
438433
onChunk: options.onChunk,
439434
});
440435
} else {
441436
// Fallback to non-streaming
442-
const response = await callAIWithStringResponse(
443-
prompt,
444-
AIActionType.TEXT,
445-
modelConfig,
446-
);
437+
const response = await callAIWithStringResponse(prompt, modelConfig);
447438

448439
if (response?.content && typeof response.content === 'string') {
449440
return {

packages/core/src/ai-model/service-caller/index.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ import { jsonrepair } from 'jsonrepair';
2121
import OpenAI from 'openai';
2222
import type { ChatCompletionMessageParam } from 'openai/resources/index';
2323
import type { Stream } from 'openai/streaming';
24-
import type { AIActionType, AIArgs } from '../../common';
24+
import type { AIArgs } from '../../common';
2525

2626
async function createChatClient({
27-
AIActionTypeValue,
2827
modelConfig,
2928
}: {
30-
AIActionTypeValue: AIActionType;
3129
modelConfig: IModelConfig;
3230
}): Promise<{
3331
completion: OpenAI.Chat.Completions;
@@ -204,7 +202,6 @@ async function createChatClient({
204202

205203
export async function callAI(
206204
messages: ChatCompletionMessageParam[],
207-
AIActionTypeValue: AIActionType,
208205
modelConfig: IModelConfig,
209206
options?: {
210207
stream?: boolean;
@@ -219,7 +216,6 @@ export async function callAI(
219216
}> {
220217
const { completion, modelName, modelDescription, uiTarsVersion, vlMode } =
221218
await createChatClient({
222-
AIActionTypeValue,
223219
modelConfig,
224220
});
225221

@@ -425,7 +421,6 @@ export async function callAI(
425421

426422
export async function callAIWithObjectResponse<T>(
427423
messages: ChatCompletionMessageParam[],
428-
AIActionTypeValue: AIActionType,
429424
modelConfig: IModelConfig,
430425
options?: {
431426
deepThink?: DeepThinkOption;
@@ -436,7 +431,7 @@ export async function callAIWithObjectResponse<T>(
436431
usage?: AIUsageInfo;
437432
reasoning_content?: string;
438433
}> {
439-
const response = await callAI(messages, AIActionTypeValue, modelConfig, {
434+
const response = await callAI(messages, modelConfig, {
440435
deepThink: options?.deepThink,
441436
});
442437
assert(response, 'empty response');
@@ -456,10 +451,9 @@ export async function callAIWithObjectResponse<T>(
456451

457452
export async function callAIWithStringResponse(
458453
msgs: AIArgs,
459-
AIActionTypeValue: AIActionType,
460454
modelConfig: IModelConfig,
461455
): Promise<{ content: string; usage?: AIUsageInfo }> {
462-
const { content, usage } = await callAI(msgs, AIActionTypeValue, modelConfig);
456+
const { content, usage } = await callAI(msgs, modelConfig);
463457
return { content, usage };
464458
}
465459

packages/core/src/ai-model/ui-tars-planning.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { getDebug } from '@midscene/shared/logger';
1010
import { transformHotkeyInput } from '@midscene/shared/us-keyboard-layout';
1111
import { assert } from '@midscene/shared/utils';
1212
import { actionParser } from '@ui-tars/action-parser';
13-
import { AIActionType } from '../common';
1413
import type { ConversationHistory } from './conversation-history';
1514
import { getSummary, getUiTarsPlanningPrompt } from './prompt/ui-tars-planning';
1615
import { callAIWithStringResponse } from './service-caller/index';
@@ -85,7 +84,6 @@ export async function uiTarsPlanning(
8584
},
8685
...conversationHistory.snapshot(),
8786
],
88-
AIActionType.INSPECT_ELEMENT,
8987
modelConfig,
9088
);
9189
const convertedText = convertBboxToCoordinates(res.content);

packages/core/src/common.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ import { z } from 'zod';
2121

2222
export type AIArgs = ChatCompletionMessageParam[];
2323

24-
export enum AIActionType {
25-
ASSERT = 0,
26-
INSPECT_ELEMENT = 1,
27-
EXTRACT_DATA = 2,
28-
PLAN = 3,
29-
DESCRIBE_ELEMENT = 4,
30-
TEXT = 5,
31-
}
32-
3324
const defaultBboxSize = 20; // must be even number
3425
const debugInspectUtils = getDebug('ai:common');
3526
type AdaptBboxInput = number[] | string[] | string | (number[] | string[])[];

packages/core/src/service/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '@/ai-model/index';
66
import { AiLocateSection } from '@/ai-model/inspect';
77
import { elementDescriberInstruction } from '@/ai-model/prompt/describe';
8-
import { AIActionType, type AIArgs, expandSearchArea } from '@/common';
8+
import { type AIArgs, expandSearchArea } from '@/common';
99
import type {
1010
AIDescribeElementResponse,
1111
AIUsageInfo,
@@ -343,11 +343,7 @@ export default class Service {
343343
const callAIFn = this
344344
.aiVendorFn as typeof callAIWithObjectResponse<AIDescribeElementResponse>;
345345

346-
const res = await callAIFn(
347-
msgs,
348-
AIActionType.DESCRIBE_ELEMENT,
349-
modelConfig,
350-
);
346+
const res = await callAIFn(msgs, modelConfig);
351347

352348
const { content } = res;
353349
assert(!content.error, `describe failed: ${content.error}`);

0 commit comments

Comments
 (0)