@midscene/core 0.26.5-beta-20250814080504.0 → 0.26.5-beta-20250814125155.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/ai-model/action-executor.mjs +139 -0
- package/dist/es/ai-model/action-executor.mjs.map +1 -0
- package/dist/es/ai-model/common.mjs +219 -0
- package/dist/es/ai-model/common.mjs.map +1 -0
- package/dist/es/ai-model/index.mjs +10 -0
- package/dist/es/ai-model/inspect.mjs +317 -0
- package/dist/es/ai-model/inspect.mjs.map +1 -0
- package/dist/es/ai-model/llm-planning.mjs +85 -0
- package/dist/es/ai-model/llm-planning.mjs.map +1 -0
- package/dist/es/ai-model/prompt/assertion.mjs +55 -0
- package/dist/es/ai-model/prompt/assertion.mjs.map +1 -0
- package/dist/es/ai-model/prompt/common.mjs +7 -0
- package/dist/es/ai-model/prompt/common.mjs.map +1 -0
- package/dist/es/ai-model/prompt/describe.mjs +44 -0
- package/dist/es/ai-model/prompt/describe.mjs.map +1 -0
- package/dist/es/ai-model/prompt/extraction.mjs +137 -0
- package/dist/es/ai-model/prompt/extraction.mjs.map +1 -0
- package/dist/es/ai-model/prompt/llm-locator.mjs +275 -0
- package/dist/es/ai-model/prompt/llm-locator.mjs.map +1 -0
- package/dist/es/ai-model/prompt/llm-planning.mjs +359 -0
- package/dist/es/ai-model/prompt/llm-planning.mjs.map +1 -0
- package/dist/es/ai-model/prompt/llm-section-locator.mjs +47 -0
- package/dist/es/ai-model/prompt/llm-section-locator.mjs.map +1 -0
- package/dist/es/ai-model/prompt/playwright-generator.mjs +117 -0
- package/dist/es/ai-model/prompt/playwright-generator.mjs.map +1 -0
- package/dist/es/ai-model/prompt/ui-tars-locator.mjs +34 -0
- package/dist/es/ai-model/prompt/ui-tars-locator.mjs.map +1 -0
- package/dist/es/ai-model/prompt/ui-tars-planning.mjs +36 -0
- package/dist/es/ai-model/prompt/ui-tars-planning.mjs.map +1 -0
- package/dist/es/ai-model/prompt/util.mjs +123 -0
- package/dist/es/ai-model/prompt/util.mjs.map +1 -0
- package/dist/es/ai-model/prompt/yaml-generator.mjs +219 -0
- package/dist/es/ai-model/prompt/yaml-generator.mjs.map +1 -0
- package/dist/es/ai-model/service-caller/index.mjs +413 -0
- package/dist/es/ai-model/service-caller/index.mjs.map +1 -0
- package/dist/es/ai-model/ui-tars-planning.mjs +235 -0
- package/dist/es/ai-model/ui-tars-planning.mjs.map +1 -0
- package/dist/es/image/index.mjs +2 -0
- package/dist/es/index.mjs +7 -2360
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/insight/index.mjs +261 -0
- package/dist/es/insight/index.mjs.map +1 -0
- package/dist/es/insight/utils.mjs +19 -0
- package/dist/es/insight/utils.mjs.map +1 -0
- package/dist/es/types.mjs +11 -0
- package/dist/es/types.mjs.map +1 -0
- package/dist/es/utils.mjs +2 -2
- package/dist/es/yaml.mjs +0 -0
- package/dist/lib/ai-model/action-executor.js +173 -0
- package/dist/lib/ai-model/action-executor.js.map +1 -0
- package/dist/lib/ai-model/common.js +289 -0
- package/dist/lib/ai-model/common.js.map +1 -0
- package/dist/lib/ai-model/index.js +103 -0
- package/dist/lib/ai-model/index.js.map +1 -0
- package/dist/lib/ai-model/inspect.js +360 -0
- package/dist/lib/ai-model/inspect.js.map +1 -0
- package/dist/lib/ai-model/llm-planning.js +119 -0
- package/dist/lib/ai-model/llm-planning.js.map +1 -0
- package/dist/lib/ai-model/prompt/assertion.js +92 -0
- package/dist/lib/ai-model/prompt/assertion.js.map +1 -0
- package/dist/lib/ai-model/prompt/common.js +41 -0
- package/dist/lib/ai-model/prompt/common.js.map +1 -0
- package/dist/lib/ai-model/prompt/describe.js +78 -0
- package/dist/lib/ai-model/prompt/describe.js.map +1 -0
- package/dist/lib/ai-model/prompt/extraction.js +177 -0
- package/dist/lib/ai-model/prompt/extraction.js.map +1 -0
- package/dist/lib/ai-model/prompt/llm-locator.js +315 -0
- package/dist/lib/ai-model/prompt/llm-locator.js.map +1 -0
- package/dist/lib/ai-model/prompt/llm-planning.js +415 -0
- package/dist/lib/ai-model/prompt/llm-planning.js.map +1 -0
- package/dist/lib/ai-model/prompt/llm-section-locator.js +84 -0
- package/dist/lib/ai-model/prompt/llm-section-locator.js.map +1 -0
- package/dist/lib/ai-model/prompt/playwright-generator.js +178 -0
- package/dist/lib/ai-model/prompt/playwright-generator.js.map +1 -0
- package/dist/lib/ai-model/prompt/ui-tars-locator.js +68 -0
- package/dist/lib/ai-model/prompt/ui-tars-locator.js.map +1 -0
- package/dist/lib/ai-model/prompt/ui-tars-planning.js +73 -0
- package/dist/lib/ai-model/prompt/ui-tars-planning.js.map +1 -0
- package/dist/lib/ai-model/prompt/util.js +175 -0
- package/dist/lib/ai-model/prompt/util.js.map +1 -0
- package/dist/lib/ai-model/prompt/yaml-generator.js +280 -0
- package/dist/lib/ai-model/prompt/yaml-generator.js.map +1 -0
- package/dist/lib/ai-model/service-caller/index.js +496 -0
- package/dist/lib/ai-model/service-caller/index.js.map +1 -0
- package/dist/lib/ai-model/ui-tars-planning.js +272 -0
- package/dist/lib/ai-model/ui-tars-planning.js.map +1 -0
- package/dist/lib/image/index.js +56 -0
- package/dist/lib/image/index.js.map +1 -0
- package/dist/lib/index.js +21 -2393
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/insight/index.js +295 -0
- package/dist/lib/insight/index.js.map +1 -0
- package/dist/lib/insight/utils.js +53 -0
- package/dist/lib/insight/utils.js.map +1 -0
- package/dist/lib/types.js +82 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utils.js +2 -2
- package/dist/lib/yaml.js +20 -0
- package/dist/lib/yaml.js.map +1 -0
- package/dist/types/ai-model/action-executor.d.ts +19 -0
- package/dist/types/ai-model/common.d.ts +34 -0
- package/dist/types/ai-model/index.d.ts +11 -0
- package/dist/types/ai-model/inspect.d.ts +49 -0
- package/dist/types/ai-model/llm-planning.d.ts +10 -0
- package/dist/types/ai-model/prompt/assertion.d.ts +5 -0
- package/dist/types/ai-model/prompt/common.d.ts +2 -0
- package/dist/types/ai-model/prompt/describe.d.ts +1 -0
- package/dist/types/ai-model/prompt/extraction.d.ts +4 -0
- package/dist/types/ai-model/prompt/llm-locator.d.ts +9 -0
- package/dist/types/ai-model/prompt/llm-planning.d.ts +15 -0
- package/dist/types/ai-model/prompt/llm-section-locator.d.ts +6 -0
- package/dist/types/ai-model/prompt/playwright-generator.d.ts +25 -0
- package/dist/types/ai-model/prompt/ui-tars-locator.d.ts +1 -0
- package/dist/types/ai-model/prompt/ui-tars-planning.d.ts +2 -0
- package/dist/types/ai-model/prompt/util.d.ts +45 -0
- package/dist/types/ai-model/prompt/yaml-generator.d.ts +99 -0
- package/dist/types/ai-model/service-caller/index.d.ts +26 -0
- package/dist/types/ai-model/ui-tars-planning.d.ts +76 -0
- package/dist/types/image/index.d.ts +1 -0
- package/dist/types/index.d.ts +9 -1289
- package/dist/types/insight/index.d.ts +26 -0
- package/dist/types/insight/utils.d.ts +2 -0
- package/dist/types/tree.d.ts +1 -11
- package/dist/types/types.d.ts +399 -0
- package/dist/types/utils.d.ts +27 -47
- package/dist/types/yaml.d.ts +172 -0
- package/package.json +6 -6
- package/dist/es/ai-model.mjs +0 -2502
- package/dist/es/ai-model.mjs.map +0 -1
- package/dist/lib/ai-model.js +0 -2622
- package/dist/lib/ai-model.js.map +0 -1
- package/dist/types/ai-model.d.ts +0 -596
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { callAiFn } from '../ai-model/common';
|
|
2
|
+
import type { AIDescribeElementResponse, AIElementResponse, AIUsageInfo, BaseElement, DetailedLocateParam, DumpSubscriber, InsightAction, InsightAssertionResponse, InsightExtractOption, InsightExtractParam, InsightOptions, InsightTaskInfo, LocateResult, Rect, TMultimodalPrompt, TUserPrompt, UIContext } from '../types';
|
|
3
|
+
export interface LocateOpts {
|
|
4
|
+
context?: UIContext<BaseElement>;
|
|
5
|
+
callAI?: typeof callAiFn<AIElementResponse>;
|
|
6
|
+
}
|
|
7
|
+
export type AnyValue<T> = {
|
|
8
|
+
[K in keyof T]: unknown extends T[K] ? any : T[K];
|
|
9
|
+
};
|
|
10
|
+
export default class Insight<ElementType extends BaseElement = BaseElement, ContextType extends UIContext<ElementType> = UIContext<ElementType>> {
|
|
11
|
+
contextRetrieverFn: (action: InsightAction) => Promise<ContextType> | ContextType;
|
|
12
|
+
aiVendorFn: (...args: Array<any>) => Promise<any>;
|
|
13
|
+
onceDumpUpdatedFn?: DumpSubscriber;
|
|
14
|
+
taskInfo?: Omit<InsightTaskInfo, 'durationMs'>;
|
|
15
|
+
constructor(context: ContextType | ((action: InsightAction) => Promise<ContextType> | ContextType), opt?: InsightOptions);
|
|
16
|
+
locate(query: DetailedLocateParam, opt?: LocateOpts): Promise<LocateResult>;
|
|
17
|
+
extract<T>(dataDemand: InsightExtractParam, opt?: InsightExtractOption, multimodalPrompt?: TMultimodalPrompt): Promise<{
|
|
18
|
+
data: T;
|
|
19
|
+
thought?: string;
|
|
20
|
+
usage?: AIUsageInfo;
|
|
21
|
+
}>;
|
|
22
|
+
assert(assertion: TUserPrompt): Promise<InsightAssertionResponse>;
|
|
23
|
+
describe(target: Rect | [number, number], opt?: {
|
|
24
|
+
deepThink?: boolean;
|
|
25
|
+
}): Promise<Pick<AIDescribeElementResponse, 'description'>>;
|
|
26
|
+
}
|
package/dist/types/tree.d.ts
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { trimAttributes } from '@midscene/shared/extractor';
|
|
3
|
-
import { truncateText } from '@midscene/shared/extractor';
|
|
4
|
-
|
|
5
|
-
export { descriptionOfTree }
|
|
6
|
-
|
|
7
|
-
export { trimAttributes }
|
|
8
|
-
|
|
9
|
-
export { truncateText }
|
|
10
|
-
|
|
11
|
-
export { }
|
|
1
|
+
export { truncateText, trimAttributes, descriptionOfTree, } from '@midscene/shared/extractor';
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import type { NodeType } from '@midscene/shared/constants';
|
|
2
|
+
import type { BaseElement, ElementTreeNode, Rect, Size } from '@midscene/shared/types';
|
|
3
|
+
import type { ChatCompletionMessageParam } from 'openai/resources/index';
|
|
4
|
+
import type { DetailedLocateParam, MidsceneYamlFlowItem } from './yaml';
|
|
5
|
+
export type { ElementTreeNode, BaseElement, Rect, Size, Point, } from '@midscene/shared/types';
|
|
6
|
+
export * from './yaml';
|
|
7
|
+
export type AIUsageInfo = Record<string, any> & {
|
|
8
|
+
prompt_tokens: number | undefined;
|
|
9
|
+
completion_tokens: number | undefined;
|
|
10
|
+
total_tokens: number | undefined;
|
|
11
|
+
time_cost: number | undefined;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* openai
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export declare enum AIResponseFormat {
|
|
18
|
+
JSON = "json_object",
|
|
19
|
+
TEXT = "text"
|
|
20
|
+
}
|
|
21
|
+
export type AISingleElementResponseById = {
|
|
22
|
+
id: string;
|
|
23
|
+
reason?: string;
|
|
24
|
+
text?: string;
|
|
25
|
+
xpaths?: string[];
|
|
26
|
+
};
|
|
27
|
+
export type AISingleElementResponseByPosition = {
|
|
28
|
+
position?: {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
};
|
|
32
|
+
bbox?: [number, number, number, number];
|
|
33
|
+
reason: string;
|
|
34
|
+
text: string;
|
|
35
|
+
};
|
|
36
|
+
export type AISingleElementResponse = AISingleElementResponseById;
|
|
37
|
+
export interface AIElementLocatorResponse {
|
|
38
|
+
elements: {
|
|
39
|
+
id: string;
|
|
40
|
+
reason?: string;
|
|
41
|
+
text?: string;
|
|
42
|
+
xpaths?: string[];
|
|
43
|
+
}[];
|
|
44
|
+
bbox?: [number, number, number, number];
|
|
45
|
+
isOrderSensitive?: boolean;
|
|
46
|
+
errors?: string[];
|
|
47
|
+
}
|
|
48
|
+
export interface AIElementCoordinatesResponse {
|
|
49
|
+
bbox: [number, number, number, number];
|
|
50
|
+
isOrderSensitive?: boolean;
|
|
51
|
+
errors?: string[];
|
|
52
|
+
}
|
|
53
|
+
export type AIElementResponse = AIElementLocatorResponse | AIElementCoordinatesResponse;
|
|
54
|
+
export interface AIDataExtractionResponse<DataDemand> {
|
|
55
|
+
data: DataDemand;
|
|
56
|
+
errors?: string[];
|
|
57
|
+
thought?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface AISectionLocatorResponse {
|
|
60
|
+
bbox: [number, number, number, number];
|
|
61
|
+
references_bbox?: [number, number, number, number][];
|
|
62
|
+
error?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface AIAssertionResponse {
|
|
65
|
+
pass: boolean;
|
|
66
|
+
thought: string;
|
|
67
|
+
}
|
|
68
|
+
export interface AIDescribeElementResponse {
|
|
69
|
+
description: string;
|
|
70
|
+
error?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface LocatorValidatorOption {
|
|
73
|
+
centerDistanceThreshold?: number;
|
|
74
|
+
}
|
|
75
|
+
export interface LocateValidatorResult {
|
|
76
|
+
pass: boolean;
|
|
77
|
+
rect: Rect;
|
|
78
|
+
center: [number, number];
|
|
79
|
+
centerDistance?: number;
|
|
80
|
+
}
|
|
81
|
+
export interface AgentDescribeElementAtPointResult {
|
|
82
|
+
prompt: string;
|
|
83
|
+
deepThink: boolean;
|
|
84
|
+
verifyResult?: LocateValidatorResult;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* context
|
|
88
|
+
*/
|
|
89
|
+
export declare abstract class UIContext<ElementType extends BaseElement = BaseElement> {
|
|
90
|
+
abstract screenshotBase64: string;
|
|
91
|
+
abstract tree: ElementTreeNode<ElementType>;
|
|
92
|
+
abstract size: Size;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* insight
|
|
96
|
+
*/
|
|
97
|
+
export type CallAIFn = <T>(messages: ChatCompletionMessageParam[]) => Promise<T>;
|
|
98
|
+
export interface InsightOptions {
|
|
99
|
+
taskInfo?: Omit<InsightTaskInfo, 'durationMs'>;
|
|
100
|
+
aiVendorFn?: CallAIFn;
|
|
101
|
+
}
|
|
102
|
+
export type EnsureObject<T> = {
|
|
103
|
+
[K in keyof T]: any;
|
|
104
|
+
};
|
|
105
|
+
export type InsightAction = 'locate' | 'extract' | 'assert' | 'describe';
|
|
106
|
+
export type InsightExtractParam = string | Record<string, string>;
|
|
107
|
+
export type LocateResultElement = {
|
|
108
|
+
id: string;
|
|
109
|
+
indexId?: number;
|
|
110
|
+
center: [number, number];
|
|
111
|
+
rect: Rect;
|
|
112
|
+
xpaths: string[];
|
|
113
|
+
attributes: {
|
|
114
|
+
nodeType: NodeType;
|
|
115
|
+
[key: string]: string;
|
|
116
|
+
};
|
|
117
|
+
isOrderSensitive?: boolean;
|
|
118
|
+
};
|
|
119
|
+
export interface LocateResult {
|
|
120
|
+
element: LocateResultElement | null;
|
|
121
|
+
rect?: Rect;
|
|
122
|
+
}
|
|
123
|
+
export interface InsightTaskInfo {
|
|
124
|
+
durationMs: number;
|
|
125
|
+
formatResponse?: string;
|
|
126
|
+
rawResponse?: string;
|
|
127
|
+
usage?: AIUsageInfo;
|
|
128
|
+
searchArea?: Rect;
|
|
129
|
+
searchAreaRawResponse?: string;
|
|
130
|
+
searchAreaUsage?: AIUsageInfo;
|
|
131
|
+
}
|
|
132
|
+
export interface DumpMeta {
|
|
133
|
+
sdkVersion: string;
|
|
134
|
+
logTime: number;
|
|
135
|
+
model_name: string;
|
|
136
|
+
model_description?: string;
|
|
137
|
+
}
|
|
138
|
+
export interface ReportDumpWithAttributes {
|
|
139
|
+
dumpString: string;
|
|
140
|
+
attributes?: Record<string, any>;
|
|
141
|
+
}
|
|
142
|
+
export interface InsightDump extends DumpMeta {
|
|
143
|
+
type: 'locate' | 'extract' | 'assert';
|
|
144
|
+
logId: string;
|
|
145
|
+
userQuery: {
|
|
146
|
+
element?: TUserPrompt;
|
|
147
|
+
dataDemand?: InsightExtractParam;
|
|
148
|
+
assertion?: TUserPrompt;
|
|
149
|
+
};
|
|
150
|
+
matchedElement: BaseElement[];
|
|
151
|
+
matchedRect?: Rect;
|
|
152
|
+
deepThink?: boolean;
|
|
153
|
+
data: any;
|
|
154
|
+
assertionPass?: boolean;
|
|
155
|
+
assertionThought?: string;
|
|
156
|
+
taskInfo: InsightTaskInfo;
|
|
157
|
+
error?: string;
|
|
158
|
+
output?: any;
|
|
159
|
+
}
|
|
160
|
+
export type PartialInsightDumpFromSDK = Omit<InsightDump, 'sdkVersion' | 'logTime' | 'logId' | 'model_name'>;
|
|
161
|
+
export type DumpSubscriber = (dump: InsightDump) => Promise<void> | void;
|
|
162
|
+
export interface LiteUISection {
|
|
163
|
+
name: string;
|
|
164
|
+
description: string;
|
|
165
|
+
sectionCharacteristics: string;
|
|
166
|
+
textIds: string[];
|
|
167
|
+
}
|
|
168
|
+
export type ElementById = (id: string) => BaseElement | null;
|
|
169
|
+
export type InsightAssertionResponse = AIAssertionResponse & {
|
|
170
|
+
usage?: AIUsageInfo;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* agent
|
|
174
|
+
*/
|
|
175
|
+
export type OnTaskStartTip = (tip: string) => Promise<void> | void;
|
|
176
|
+
export interface AgentWaitForOpt {
|
|
177
|
+
checkIntervalMs?: number;
|
|
178
|
+
timeoutMs?: number;
|
|
179
|
+
}
|
|
180
|
+
export interface AgentAssertOpt {
|
|
181
|
+
keepRawResponse?: boolean;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* planning
|
|
185
|
+
*
|
|
186
|
+
*/
|
|
187
|
+
export interface PlanningLocateParam extends DetailedLocateParam {
|
|
188
|
+
id?: string;
|
|
189
|
+
bbox?: [number, number, number, number];
|
|
190
|
+
}
|
|
191
|
+
export interface PlanningAction<ParamType = any> {
|
|
192
|
+
thought?: string;
|
|
193
|
+
type: 'Locate' | 'Tap' | 'RightClick' | 'Hover' | 'Drag' | 'Input' | 'KeyboardPress' | 'Scroll' | 'Error' | 'Assert' | 'AssertWithoutThrow' | 'Sleep' | 'Finished' | 'AndroidBackButton' | 'AndroidHomeButton' | 'AndroidRecentAppsButton' | 'AndroidLongPress' | 'AndroidPull';
|
|
194
|
+
param: ParamType;
|
|
195
|
+
locate?: PlanningLocateParam | null;
|
|
196
|
+
}
|
|
197
|
+
export interface PlanningAIResponse {
|
|
198
|
+
action?: PlanningAction;
|
|
199
|
+
actions?: PlanningAction[];
|
|
200
|
+
more_actions_needed_by_instruction: boolean;
|
|
201
|
+
log: string;
|
|
202
|
+
sleep?: number;
|
|
203
|
+
error?: string;
|
|
204
|
+
usage?: AIUsageInfo;
|
|
205
|
+
rawResponse?: string;
|
|
206
|
+
yamlFlow?: MidsceneYamlFlowItem[];
|
|
207
|
+
yamlString?: string;
|
|
208
|
+
}
|
|
209
|
+
export type PlanningActionParamTap = null;
|
|
210
|
+
export type PlanningActionParamHover = null;
|
|
211
|
+
export type PlanningActionParamRightClick = null;
|
|
212
|
+
export interface PlanningActionParamInputOrKeyPress {
|
|
213
|
+
value: string;
|
|
214
|
+
autoDismissKeyboard?: boolean;
|
|
215
|
+
}
|
|
216
|
+
export interface PlanningActionParamAssert {
|
|
217
|
+
assertion: TUserPrompt;
|
|
218
|
+
}
|
|
219
|
+
export interface PlanningActionParamSleep {
|
|
220
|
+
timeMs: number;
|
|
221
|
+
}
|
|
222
|
+
export interface PlanningActionParamError {
|
|
223
|
+
thought: string;
|
|
224
|
+
}
|
|
225
|
+
export type PlanningActionParamWaitFor = AgentWaitForOpt & {
|
|
226
|
+
assertion: string;
|
|
227
|
+
};
|
|
228
|
+
export interface AndroidLongPressParam {
|
|
229
|
+
duration?: number;
|
|
230
|
+
}
|
|
231
|
+
export interface AndroidPullParam {
|
|
232
|
+
direction: 'up' | 'down';
|
|
233
|
+
distance?: number;
|
|
234
|
+
duration?: number;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* misc
|
|
238
|
+
*/
|
|
239
|
+
export interface Color {
|
|
240
|
+
name: string;
|
|
241
|
+
hex: string;
|
|
242
|
+
}
|
|
243
|
+
export interface BaseAgentParserOpt {
|
|
244
|
+
selector?: string;
|
|
245
|
+
ignoreMarker?: boolean;
|
|
246
|
+
}
|
|
247
|
+
export interface PuppeteerParserOpt extends BaseAgentParserOpt {
|
|
248
|
+
}
|
|
249
|
+
export interface PlaywrightParserOpt extends BaseAgentParserOpt {
|
|
250
|
+
}
|
|
251
|
+
export interface ExecutionTaskProgressOptions {
|
|
252
|
+
onTaskStart?: (task: ExecutionTask) => Promise<void> | void;
|
|
253
|
+
}
|
|
254
|
+
export interface ExecutionRecorderItem {
|
|
255
|
+
type: 'screenshot';
|
|
256
|
+
ts: number;
|
|
257
|
+
screenshot?: string;
|
|
258
|
+
timing?: string;
|
|
259
|
+
}
|
|
260
|
+
export type ExecutionTaskType = 'Planning' | 'Insight' | 'Action' | 'Assertion' | 'Log';
|
|
261
|
+
export interface ExecutorContext {
|
|
262
|
+
task: ExecutionTask;
|
|
263
|
+
element?: LocateResultElement | null;
|
|
264
|
+
}
|
|
265
|
+
export interface ExecutionTaskApply<Type extends ExecutionTaskType = any, TaskParam = any, TaskOutput = any, TaskLog = any> {
|
|
266
|
+
type: Type;
|
|
267
|
+
subType?: string;
|
|
268
|
+
param?: TaskParam;
|
|
269
|
+
thought?: string;
|
|
270
|
+
locate?: PlanningLocateParam | null;
|
|
271
|
+
pageContext?: UIContext;
|
|
272
|
+
executor: (param: TaskParam, context: ExecutorContext) => Promise<ExecutionTaskReturn<TaskOutput, TaskLog> | undefined | void> | undefined | void;
|
|
273
|
+
}
|
|
274
|
+
export interface ExecutionTaskHitBy {
|
|
275
|
+
from: string;
|
|
276
|
+
context: Record<string, any>;
|
|
277
|
+
}
|
|
278
|
+
export interface ExecutionTaskReturn<TaskOutput = unknown, TaskLog = unknown> {
|
|
279
|
+
output?: TaskOutput;
|
|
280
|
+
log?: TaskLog;
|
|
281
|
+
recorder?: ExecutionRecorderItem[];
|
|
282
|
+
hitBy?: ExecutionTaskHitBy;
|
|
283
|
+
}
|
|
284
|
+
export type ExecutionTask<E extends ExecutionTaskApply<any, any, any> = ExecutionTaskApply<any, any, any>> = E & ExecutionTaskReturn<E extends ExecutionTaskApply<any, any, infer TaskOutput, any> ? TaskOutput : unknown, E extends ExecutionTaskApply<any, any, any, infer TaskLog> ? TaskLog : unknown> & {
|
|
285
|
+
status: 'pending' | 'running' | 'finished' | 'failed' | 'cancelled';
|
|
286
|
+
error?: Error;
|
|
287
|
+
errorMessage?: string;
|
|
288
|
+
errorStack?: string;
|
|
289
|
+
timing?: {
|
|
290
|
+
start: number;
|
|
291
|
+
end?: number;
|
|
292
|
+
cost?: number;
|
|
293
|
+
};
|
|
294
|
+
usage?: AIUsageInfo;
|
|
295
|
+
};
|
|
296
|
+
export interface ExecutionDump extends DumpMeta {
|
|
297
|
+
name: string;
|
|
298
|
+
description?: string;
|
|
299
|
+
tasks: ExecutionTask[];
|
|
300
|
+
}
|
|
301
|
+
export type ExecutionTaskInsightLocateParam = PlanningLocateParam;
|
|
302
|
+
export interface ExecutionTaskInsightLocateOutput {
|
|
303
|
+
element: LocateResultElement | null;
|
|
304
|
+
}
|
|
305
|
+
export interface ExecutionTaskInsightDumpLog {
|
|
306
|
+
dump?: InsightDump;
|
|
307
|
+
}
|
|
308
|
+
export type ExecutionTaskInsightLocateApply = ExecutionTaskApply<'Insight', ExecutionTaskInsightLocateParam, ExecutionTaskInsightLocateOutput, ExecutionTaskInsightDumpLog>;
|
|
309
|
+
export type ExecutionTaskInsightLocate = ExecutionTask<ExecutionTaskInsightLocateApply>;
|
|
310
|
+
export interface ExecutionTaskInsightQueryParam {
|
|
311
|
+
dataDemand: InsightExtractParam;
|
|
312
|
+
}
|
|
313
|
+
export interface ExecutionTaskInsightQueryOutput {
|
|
314
|
+
data: any;
|
|
315
|
+
}
|
|
316
|
+
export type ExecutionTaskInsightQueryApply = ExecutionTaskApply<'Insight', ExecutionTaskInsightQueryParam, any, ExecutionTaskInsightDumpLog>;
|
|
317
|
+
export type ExecutionTaskInsightQuery = ExecutionTask<ExecutionTaskInsightQueryApply>;
|
|
318
|
+
export interface ExecutionTaskInsightAssertionParam {
|
|
319
|
+
assertion: string;
|
|
320
|
+
}
|
|
321
|
+
export type ExecutionTaskInsightAssertionApply = ExecutionTaskApply<'Insight', ExecutionTaskInsightAssertionParam, InsightAssertionResponse, ExecutionTaskInsightDumpLog>;
|
|
322
|
+
export type ExecutionTaskInsightAssertion = ExecutionTask<ExecutionTaskInsightAssertionApply>;
|
|
323
|
+
export type ExecutionTaskActionApply<ActionParam = any> = ExecutionTaskApply<'Action', ActionParam, void, void>;
|
|
324
|
+
export type ExecutionTaskAction = ExecutionTask<ExecutionTaskActionApply>;
|
|
325
|
+
export type ExecutionTaskLogApply<LogParam = {
|
|
326
|
+
content: string;
|
|
327
|
+
}> = ExecutionTaskApply<'Log', LogParam, void, void>;
|
|
328
|
+
export type ExecutionTaskLog = ExecutionTask<ExecutionTaskLogApply>;
|
|
329
|
+
export type ExecutionTaskPlanningApply = ExecutionTaskApply<'Planning', {
|
|
330
|
+
userInstruction: string;
|
|
331
|
+
log?: string;
|
|
332
|
+
}, PlanningAIResponse>;
|
|
333
|
+
export type ExecutionTaskPlanning = ExecutionTask<ExecutionTaskPlanningApply>;
|
|
334
|
+
export interface GroupedActionDump {
|
|
335
|
+
groupName: string;
|
|
336
|
+
groupDescription?: string;
|
|
337
|
+
executions: ExecutionDump[];
|
|
338
|
+
}
|
|
339
|
+
export type PageType = 'puppeteer' | 'playwright' | 'static' | 'chrome-extension-proxy' | 'android';
|
|
340
|
+
export interface StreamingCodeGenerationOptions {
|
|
341
|
+
/** Whether to enable streaming output */
|
|
342
|
+
stream?: boolean;
|
|
343
|
+
/** Callback function to handle streaming chunks */
|
|
344
|
+
onChunk?: StreamingCallback;
|
|
345
|
+
/** Callback function to handle streaming completion */
|
|
346
|
+
onComplete?: (finalCode: string) => void;
|
|
347
|
+
/** Callback function to handle streaming errors */
|
|
348
|
+
onError?: (error: Error) => void;
|
|
349
|
+
}
|
|
350
|
+
export type StreamingCallback = (chunk: CodeGenerationChunk) => void;
|
|
351
|
+
export interface CodeGenerationChunk {
|
|
352
|
+
/** The incremental content chunk */
|
|
353
|
+
content: string;
|
|
354
|
+
/** The reasoning content */
|
|
355
|
+
reasoning_content: string;
|
|
356
|
+
/** The accumulated content so far */
|
|
357
|
+
accumulated: string;
|
|
358
|
+
/** Whether this is the final chunk */
|
|
359
|
+
isComplete: boolean;
|
|
360
|
+
/** Token usage information if available */
|
|
361
|
+
usage?: AIUsageInfo;
|
|
362
|
+
}
|
|
363
|
+
export interface StreamingAIResponse {
|
|
364
|
+
/** The final accumulated content */
|
|
365
|
+
content: string;
|
|
366
|
+
/** Token usage information */
|
|
367
|
+
usage?: AIUsageInfo;
|
|
368
|
+
/** Whether the response was streamed */
|
|
369
|
+
isStreamed: boolean;
|
|
370
|
+
}
|
|
371
|
+
export type TMultimodalPrompt = {
|
|
372
|
+
/**
|
|
373
|
+
* Support use image to inspect elements.
|
|
374
|
+
* The "images" field is an object that uses image name as key and image url as value.
|
|
375
|
+
* The image url can be a local path, a http link , or a base64 string.
|
|
376
|
+
*/
|
|
377
|
+
images?: {
|
|
378
|
+
name: string;
|
|
379
|
+
url: string;
|
|
380
|
+
}[];
|
|
381
|
+
/**
|
|
382
|
+
* By default, the image url in the "images" filed starts with `https://` or `http://` will be directly sent to the LLM.
|
|
383
|
+
* In case the images are not accessible to the LLM (One common case is that image url is internal network only.), you can enable this option.
|
|
384
|
+
* Then image will be download and convert to base64 format.
|
|
385
|
+
*/
|
|
386
|
+
convertHttpImage2Base64?: boolean;
|
|
387
|
+
};
|
|
388
|
+
export type TUserPrompt = string | ({
|
|
389
|
+
prompt: string;
|
|
390
|
+
} & Partial<TMultimodalPrompt>);
|
|
391
|
+
export interface DeviceAction<ParamType = any> {
|
|
392
|
+
name: string;
|
|
393
|
+
description?: string;
|
|
394
|
+
paramSchema?: string;
|
|
395
|
+
paramDescription?: string;
|
|
396
|
+
location?: 'required' | 'optional' | false;
|
|
397
|
+
whatToLocate?: string;
|
|
398
|
+
call: (context: ExecutorContext, param: ParamType) => Promise<void> | void;
|
|
399
|
+
}
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,47 +1,27 @@
|
|
|
1
|
-
import { Rect } from '
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare function
|
|
8
|
-
|
|
9
|
-
export declare
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export declare function
|
|
20
|
-
|
|
21
|
-
declare
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
export declare function sleep(ms: number): Promise<unknown>;
|
|
29
|
-
|
|
30
|
-
export declare function stringifyDumpData(data: any, indents?: number): string;
|
|
31
|
-
|
|
32
|
-
export declare function uploadTestInfoToServer({ testUrl }: {
|
|
33
|
-
testUrl: string;
|
|
34
|
-
}): void;
|
|
35
|
-
|
|
36
|
-
export declare function writeDumpReport(fileName: string, dumpData: string | ReportDumpWithAttributes, appendReport?: boolean): string | null;
|
|
37
|
-
|
|
38
|
-
export declare function writeLogFile(opts: {
|
|
39
|
-
fileName: string;
|
|
40
|
-
fileExt: string;
|
|
41
|
-
fileContent: string;
|
|
42
|
-
type: 'dump' | 'cache' | 'report' | 'tmp';
|
|
43
|
-
generateReport?: boolean;
|
|
44
|
-
appendReport?: boolean;
|
|
45
|
-
}): string | null;
|
|
46
|
-
|
|
47
|
-
export { }
|
|
1
|
+
import type { Rect, ReportDumpWithAttributes } from './types';
|
|
2
|
+
export declare const groupedActionDumpFileExt = "web-dump.json";
|
|
3
|
+
/**
|
|
4
|
+
* high performance, insert script before </html> in HTML file
|
|
5
|
+
* only truncate and append, no temporary file
|
|
6
|
+
*/
|
|
7
|
+
export declare function insertScriptBeforeClosingHtml(filePath: string, scriptContent: string): void;
|
|
8
|
+
export declare function reportHTMLContent(dumpData: string | ReportDumpWithAttributes, reportPath?: string, appendReport?: boolean): string;
|
|
9
|
+
export declare function writeDumpReport(fileName: string, dumpData: string | ReportDumpWithAttributes, appendReport?: boolean): string | null;
|
|
10
|
+
export declare function writeLogFile(opts: {
|
|
11
|
+
fileName: string;
|
|
12
|
+
fileExt: string;
|
|
13
|
+
fileContent: string;
|
|
14
|
+
type: 'dump' | 'cache' | 'report' | 'tmp';
|
|
15
|
+
generateReport?: boolean;
|
|
16
|
+
appendReport?: boolean;
|
|
17
|
+
}): string | null;
|
|
18
|
+
export declare function getTmpDir(): string | null;
|
|
19
|
+
export declare function getTmpFile(fileExtWithoutDot: string): string | null;
|
|
20
|
+
export declare function overlapped(container: Rect, target: Rect): boolean;
|
|
21
|
+
export declare function sleep(ms: number): Promise<unknown>;
|
|
22
|
+
export declare function replacerForPageObject(key: string, value: any): any;
|
|
23
|
+
export declare function stringifyDumpData(data: any, indents?: number): string;
|
|
24
|
+
export declare function getVersion(): string;
|
|
25
|
+
export declare function uploadTestInfoToServer({ testUrl }: {
|
|
26
|
+
testUrl: string;
|
|
27
|
+
}): void;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type { Rect, TUserPrompt } from './types';
|
|
2
|
+
import type { BaseElement, UIContext } from './types';
|
|
3
|
+
export interface LocateOption {
|
|
4
|
+
deepThink?: boolean;
|
|
5
|
+
cacheable?: boolean;
|
|
6
|
+
xpath?: string;
|
|
7
|
+
pageContext?: UIContext<BaseElement>;
|
|
8
|
+
}
|
|
9
|
+
export interface InsightExtractOption {
|
|
10
|
+
domIncluded?: boolean | 'visible-only';
|
|
11
|
+
screenshotIncluded?: boolean;
|
|
12
|
+
returnThought?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface ReferenceImage {
|
|
15
|
+
base64: string;
|
|
16
|
+
rect?: Rect;
|
|
17
|
+
}
|
|
18
|
+
export interface DetailedLocateParam extends LocateOption {
|
|
19
|
+
prompt: TUserPrompt;
|
|
20
|
+
referenceImage?: ReferenceImage;
|
|
21
|
+
}
|
|
22
|
+
export interface ScrollParam {
|
|
23
|
+
direction: 'down' | 'up' | 'right' | 'left';
|
|
24
|
+
scrollType: 'once' | 'untilBottom' | 'untilTop' | 'untilRight' | 'untilLeft';
|
|
25
|
+
distance?: null | number;
|
|
26
|
+
}
|
|
27
|
+
export interface MidsceneYamlScript {
|
|
28
|
+
target?: MidsceneYamlScriptWebEnv;
|
|
29
|
+
web?: MidsceneYamlScriptWebEnv;
|
|
30
|
+
android?: MidsceneYamlScriptAndroidEnv;
|
|
31
|
+
tasks: MidsceneYamlTask[];
|
|
32
|
+
}
|
|
33
|
+
export interface MidsceneYamlTask {
|
|
34
|
+
name: string;
|
|
35
|
+
flow: MidsceneYamlFlowItem[];
|
|
36
|
+
continueOnError?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface MidsceneYamlScriptEnvBase {
|
|
39
|
+
output?: string;
|
|
40
|
+
unstableLogContent?: boolean | string;
|
|
41
|
+
aiActionContext?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface MidsceneYamlScriptWebEnv extends MidsceneYamlScriptEnvBase {
|
|
44
|
+
serve?: string;
|
|
45
|
+
url: string;
|
|
46
|
+
userAgent?: string;
|
|
47
|
+
acceptInsecureCerts?: boolean;
|
|
48
|
+
viewportWidth?: number;
|
|
49
|
+
viewportHeight?: number;
|
|
50
|
+
viewportScale?: number;
|
|
51
|
+
waitForNetworkIdle?: {
|
|
52
|
+
timeout?: number;
|
|
53
|
+
continueOnNetworkIdleError?: boolean;
|
|
54
|
+
};
|
|
55
|
+
cookie?: string;
|
|
56
|
+
forceSameTabNavigation?: boolean;
|
|
57
|
+
bridgeMode?: false | 'newTabWithUrl' | 'currentTab';
|
|
58
|
+
closeNewTabsAfterDisconnect?: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface MidsceneYamlScriptAndroidEnv extends MidsceneYamlScriptEnvBase {
|
|
61
|
+
deviceId?: string;
|
|
62
|
+
launch?: string;
|
|
63
|
+
}
|
|
64
|
+
export type MidsceneYamlScriptEnv = MidsceneYamlScriptWebEnv | MidsceneYamlScriptAndroidEnv;
|
|
65
|
+
export interface MidsceneYamlFlowItemAIAction {
|
|
66
|
+
ai?: string;
|
|
67
|
+
aiAction?: string;
|
|
68
|
+
aiActionProgressTips?: string[];
|
|
69
|
+
cacheable?: boolean;
|
|
70
|
+
}
|
|
71
|
+
export interface MidsceneYamlFlowItemAIAssert {
|
|
72
|
+
aiAssert: string;
|
|
73
|
+
errorMessage?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface MidsceneYamlFlowItemAIQuery extends InsightExtractOption {
|
|
76
|
+
aiQuery: string;
|
|
77
|
+
name?: string;
|
|
78
|
+
}
|
|
79
|
+
export interface MidsceneYamlFlowItemAINumber extends InsightExtractOption {
|
|
80
|
+
aiNumber: string;
|
|
81
|
+
name?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface MidsceneYamlFlowItemAIString extends InsightExtractOption {
|
|
84
|
+
aiString: string;
|
|
85
|
+
name?: string;
|
|
86
|
+
}
|
|
87
|
+
export interface MidsceneYamlFlowItemAIAsk extends InsightExtractOption {
|
|
88
|
+
aiAsk: string;
|
|
89
|
+
name?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface MidsceneYamlFlowItemAIBoolean extends InsightExtractOption {
|
|
92
|
+
aiBoolean: string;
|
|
93
|
+
name?: string;
|
|
94
|
+
}
|
|
95
|
+
export interface MidsceneYamlFlowItemAILocate extends LocateOption {
|
|
96
|
+
aiLocate: string;
|
|
97
|
+
name?: string;
|
|
98
|
+
}
|
|
99
|
+
export interface MidsceneYamlFlowItemAIWaitFor {
|
|
100
|
+
aiWaitFor: string;
|
|
101
|
+
timeout?: number;
|
|
102
|
+
}
|
|
103
|
+
export interface MidsceneYamlFlowItemAITap extends LocateOption {
|
|
104
|
+
aiTap: TUserPrompt;
|
|
105
|
+
}
|
|
106
|
+
export interface MidsceneYamlFlowItemAIRightClick extends LocateOption {
|
|
107
|
+
aiRightClick: TUserPrompt;
|
|
108
|
+
}
|
|
109
|
+
export interface MidsceneYamlFlowItemAIHover extends LocateOption {
|
|
110
|
+
aiHover: TUserPrompt;
|
|
111
|
+
}
|
|
112
|
+
export interface MidsceneYamlFlowItemAIInput extends LocateOption {
|
|
113
|
+
aiInput: string;
|
|
114
|
+
locate: TUserPrompt;
|
|
115
|
+
}
|
|
116
|
+
export interface MidsceneYamlFlowItemAIKeyboardPress extends LocateOption {
|
|
117
|
+
aiKeyboardPress: string;
|
|
118
|
+
locate?: TUserPrompt;
|
|
119
|
+
}
|
|
120
|
+
export interface MidsceneYamlFlowItemAIScroll extends LocateOption, ScrollParam {
|
|
121
|
+
aiScroll: null;
|
|
122
|
+
locate?: TUserPrompt;
|
|
123
|
+
}
|
|
124
|
+
export interface MidsceneYamlFlowItemEvaluateJavaScript {
|
|
125
|
+
javascript: string;
|
|
126
|
+
name?: string;
|
|
127
|
+
}
|
|
128
|
+
export interface MidsceneYamlFlowItemSleep {
|
|
129
|
+
sleep: number;
|
|
130
|
+
}
|
|
131
|
+
export interface MidsceneYamlFlowItemLogScreenshot {
|
|
132
|
+
logScreenshot?: string;
|
|
133
|
+
content?: string;
|
|
134
|
+
}
|
|
135
|
+
export type MidsceneYamlFlowItem = MidsceneYamlFlowItemAIAction | MidsceneYamlFlowItemAIAssert | MidsceneYamlFlowItemAIQuery | MidsceneYamlFlowItemAIWaitFor | MidsceneYamlFlowItemAITap | MidsceneYamlFlowItemAIRightClick | MidsceneYamlFlowItemAIHover | MidsceneYamlFlowItemAIInput | MidsceneYamlFlowItemAIKeyboardPress | MidsceneYamlFlowItemAIScroll | MidsceneYamlFlowItemSleep | MidsceneYamlFlowItemLogScreenshot;
|
|
136
|
+
export interface FreeFn {
|
|
137
|
+
name: string;
|
|
138
|
+
fn: () => void;
|
|
139
|
+
}
|
|
140
|
+
export interface ScriptPlayerTaskStatus extends MidsceneYamlTask {
|
|
141
|
+
status: ScriptPlayerStatusValue;
|
|
142
|
+
currentStep?: number;
|
|
143
|
+
totalSteps: number;
|
|
144
|
+
error?: Error;
|
|
145
|
+
}
|
|
146
|
+
export type ScriptPlayerStatusValue = 'init' | 'running' | 'done' | 'error';
|
|
147
|
+
export interface MidsceneYamlConfig {
|
|
148
|
+
concurrent?: number;
|
|
149
|
+
continueOnError?: boolean;
|
|
150
|
+
summary?: string;
|
|
151
|
+
shareBrowserContext?: boolean;
|
|
152
|
+
web?: MidsceneYamlScriptWebEnv;
|
|
153
|
+
android?: MidsceneYamlScriptAndroidEnv;
|
|
154
|
+
files: string[];
|
|
155
|
+
headed?: boolean;
|
|
156
|
+
keepWindow?: boolean;
|
|
157
|
+
dotenvOverride?: boolean;
|
|
158
|
+
dotenvDebug?: boolean;
|
|
159
|
+
}
|
|
160
|
+
export interface MidsceneYamlConfigOutput {
|
|
161
|
+
format?: 'json';
|
|
162
|
+
path?: string;
|
|
163
|
+
}
|
|
164
|
+
export interface MidsceneYamlConfigResult {
|
|
165
|
+
file: string;
|
|
166
|
+
success: boolean;
|
|
167
|
+
executed: boolean;
|
|
168
|
+
output?: string | null;
|
|
169
|
+
report?: string | null;
|
|
170
|
+
error?: string;
|
|
171
|
+
duration?: number;
|
|
172
|
+
}
|