Skip to content

Commit 68b4004

Browse files
yuyutaotaozhoushaw
andauthored
chore: rename files in core module (#277)
--------- Co-authored-by: zhouxiao.shaw <[email protected]>
1 parent 74774c6 commit 68b4004

25 files changed

+35
-635
lines changed

apps/site/docs/zh/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Midscene.js - AI 加持,带来愉悦的 UI 自动化体验
22

3-
UI 自动化太难维护了。UI 自动化脚本里往往到处都是选择器,比如 `#ids``data-test``.selectors`。在需要重构的时候,这可能会让人感到非常头疼,尽管在这种情况下,UI 自动化应该能够发挥作用。
3+
传统 UI 自动化太难维护了。自动化脚本里往往到处都是选择器,比如 `#ids``data-test``.selectors`。在需要重构的时候,这可能会让人感到非常头疼,尽管在这种情况下,UI 自动化应该能够发挥作用。
44

55
我们在这里推出 Midscene.js,助你重拾编码的乐趣。
66

packages/midscene/src/ai-model/common.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import assert from 'node:assert';
2-
import { MIDSCENE_MODEL_TEXT_ONLY, getAIConfig } from '@/env';
32
import type { AIUsageInfo } from '@/types';
43

54
import type {
6-
ChatCompletionContentPart,
75
ChatCompletionSystemMessageParam,
86
ChatCompletionUserMessageParam,
97
} from 'openai/resources';
10-
import { callToGetJSONObject, checkAIConfig } from './openai';
8+
import { callToGetJSONObject, checkAIConfig } from './service-caller';
119

1210
export type AIArgs = [
1311
ChatCompletionSystemMessageParam,
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export { callToGetJSONObject } from './openai';
2-
export { systemPromptToFindElement } from './prompt/element-inspector';
1+
export { callToGetJSONObject } from './service-caller';
2+
export { systemPromptToLocateElement } from './prompt/llm-locator';
33
export { describeUserPage } from './prompt/util';
44

55
export type { ChatCompletionMessageParam } from 'openai/resources';
@@ -11,7 +11,6 @@ export {
1111
transformElementPositionToId,
1212
} from './inspect';
1313

14-
export { plan } from './automation';
14+
export { plan } from './llm-planning';
1515
export { callAiFn } from './common';
16-
17-
export { vlmPlanning } from './vlm-planning';
16+
export { vlmPlanning } from './ui-tars-planning';

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import assert from 'node:assert';
2-
import path from 'node:path';
32
import type {
43
AIAssertionResponse,
54
AIElementResponse,
@@ -9,29 +8,26 @@ import type {
98
AIUsageInfo,
109
BaseElement,
1110
ElementById,
12-
Point,
1311
Size,
1412
UIContext,
1513
} from '@/types';
16-
import { savePositionImg } from '@midscene/shared/img';
1714
import type {
1815
ChatCompletionSystemMessageParam,
1916
ChatCompletionUserMessageParam,
2017
} from 'openai/resources';
2118
import { AIActionType, callAiFn } from './common';
22-
import { call, callToGetJSONObject } from './openai';
2319
import {
2420
findElementPrompt,
25-
multiDescription,
26-
systemPromptToFindElement,
27-
} from './prompt/element-inspector';
21+
systemPromptToLocateElement,
22+
} from './prompt/llm-locator';
2823
import {
2924
describeUserPage,
3025
elementByPositionWithElementInfo,
3126
extractDataPrompt,
3227
systemPromptToAssert,
3328
systemPromptToExtract,
3429
} from './prompt/util';
30+
import { callToGetJSONObject } from './service-caller';
3531

3632
export type AIArgs = [
3733
ChatCompletionSystemMessageParam,
@@ -69,11 +65,7 @@ export async function transformElementPositionToId(
6965
},
7066
size,
7167
);
72-
// await savePositionImg({
73-
// inputImgBase64: screenshotBase64,
74-
// rect: absolutePosition,
75-
// outputPath: path.join(__dirname, 'test-data', `output-${index++}.png`),
76-
// });
68+
7769
const element = elementByPositionWithElementInfo(
7870
elementsInfo,
7971
absolutePosition,
@@ -182,7 +174,7 @@ export async function AiInspectElement<
182174
targetElementDescription,
183175
multi,
184176
});
185-
const systemPrompt = systemPromptToFindElement();
177+
const systemPrompt = systemPromptToLocateElement();
186178
const msgs: AIArgs = [
187179
{ role: 'system', content: systemPrompt },
188180
{

packages/midscene/src/ai-model/automation.ts renamed to packages/midscene/src/ai-model/llm-planning.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
automationUserPrompt,
77
generateTaskBackgroundContext,
88
systemPromptToTaskPlanning,
9-
} from './prompt/planning';
9+
} from './prompt/llm-planning';
1010
import { describeUserPage } from './prompt/util';
1111

1212
export async function plan(

packages/midscene/src/ai-model/prompt/element-inspector.ts renamed to packages/midscene/src/ai-model/prompt/llm-locator.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { MATCH_BY_POSITION, getAIConfig } from '@/env';
22
import { PromptTemplate } from '@langchain/core/prompts';
33
import type { ResponseFormatJSONSchema } from 'openai/resources';
4-
import { systemPromptToFindElementPosition } from './element-point';
4+
import { systemPromptToLocateElementPosition } from './ui-tars-locator';
55

6-
export function systemPromptToFindElement() {
6+
export function systemPromptToLocateElement() {
77
if (getAIConfig(MATCH_BY_POSITION)) {
8-
return systemPromptToFindElementPosition();
8+
return systemPromptToLocateElementPosition();
99
}
1010
return `
1111
## Role:
@@ -144,12 +144,6 @@ Output Example:
144144
`;
145145
}
146146

147-
export function multiDescription(multi: boolean) {
148-
return multi
149-
? 'multiple elements matching the description (two or more)'
150-
: 'The element closest to the description (only one)';
151-
}
152-
153147
export const findElementSchema: ResponseFormatJSONSchema = {
154148
type: 'json_schema',
155149
json_schema: {

packages/midscene/src/ai-model/prompt/element-point.ts renamed to packages/midscene/src/ai-model/prompt/ui-tars-locator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// claude 3.5 sonnet computer The ability to understand the content of the image is better, Does not provide element snapshot effect
2-
export function systemPromptToFindElementPosition() {
2+
export function systemPromptToLocateElementPosition() {
33
return `
44
You are a GUI agent. You are given a task and your action history, with screenshots. You need to perform the next action to complete the task.
55

packages/midscene/src/ai-model/prompt/ui-tars-planning.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Action } from '../vlm-planning';
1+
import type { Action } from '../ui-tars-planning';
22

33
export const uiTarsPlanningPrompt = `
44
You are a GUI agent. You are given a task and your action history, with screenshots. You need to perform the next action to complete the task.

0 commit comments

Comments
 (0)