@midscene/core 0.16.9-beta-20250507095704.0 → 0.16.9

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.
Files changed (40) hide show
  1. package/dist/es/ai-model.d.ts +3 -3
  2. package/dist/es/ai-model.js +1 -1
  3. package/dist/es/{chunk-NWSBT5YP.js → chunk-FYD4T7QD.js} +67 -51
  4. package/dist/es/chunk-FYD4T7QD.js.map +1 -0
  5. package/dist/es/{chunk-MVRTMYEM.js → chunk-KINAY5TJ.js} +4 -26
  6. package/dist/es/chunk-KINAY5TJ.js.map +1 -0
  7. package/dist/es/index.d.ts +5 -8
  8. package/dist/es/index.js +2 -85
  9. package/dist/es/index.js.map +1 -1
  10. package/dist/es/{llm-planning-28e999f3.d.ts → llm-planning-e16d1814.d.ts} +2 -3
  11. package/dist/es/tree.d.ts +1 -1
  12. package/dist/es/{types-88f46e9e.d.ts → types-8c83481c.d.ts} +2 -20
  13. package/dist/es/utils.d.ts +2 -3
  14. package/dist/es/utils.js +1 -3
  15. package/dist/lib/ai-model.d.ts +3 -3
  16. package/dist/lib/ai-model.js +2 -2
  17. package/dist/lib/{chunk-NWSBT5YP.js → chunk-FYD4T7QD.js} +68 -52
  18. package/dist/lib/chunk-FYD4T7QD.js.map +1 -0
  19. package/dist/lib/{chunk-MVRTMYEM.js → chunk-KINAY5TJ.js} +4 -26
  20. package/dist/lib/chunk-KINAY5TJ.js.map +1 -0
  21. package/dist/lib/index.d.ts +5 -8
  22. package/dist/lib/index.js +10 -93
  23. package/dist/lib/index.js.map +1 -1
  24. package/dist/lib/{llm-planning-28e999f3.d.ts → llm-planning-e16d1814.d.ts} +2 -3
  25. package/dist/lib/tree.d.ts +1 -1
  26. package/dist/{types/types-88f46e9e.d.ts → lib/types-8c83481c.d.ts} +2 -20
  27. package/dist/lib/utils.d.ts +2 -3
  28. package/dist/lib/utils.js +2 -4
  29. package/dist/types/ai-model.d.ts +3 -3
  30. package/dist/types/index.d.ts +5 -8
  31. package/dist/types/{llm-planning-28e999f3.d.ts → llm-planning-e16d1814.d.ts} +2 -3
  32. package/dist/types/tree.d.ts +1 -1
  33. package/dist/{lib/types-88f46e9e.d.ts → types/types-8c83481c.d.ts} +2 -20
  34. package/dist/types/utils.d.ts +2 -3
  35. package/package.json +5 -5
  36. package/dist/es/chunk-MVRTMYEM.js.map +0 -1
  37. package/dist/es/chunk-NWSBT5YP.js.map +0 -1
  38. package/dist/lib/chunk-MVRTMYEM.js.map +0 -1
  39. package/dist/lib/chunk-NWSBT5YP.js.map +0 -1
  40. package/report/index.html +0 -1839
@@ -1,7 +1,7 @@
1
- import { E as ExecutionTask, a as ExecutionTaskProgressOptions, b as ExecutionTaskApply, c as ExecutionDump, B as BaseElement, U as UIContext, I as InsightAction, D as DumpSubscriber, d as InsightTaskInfo, e as InsightOptions, f as DetailedLocateParam, L as LocateResult, g as InsightAssertionResponse, R as Rect, A as AIDescribeElementResponse, h as AISingleElementResponse } from './types-88f46e9e.js';
2
- export { u as AIAssertionResponse, s as AIDataExtractionResponse, q as AIElementCoordinatesResponse, p as AIElementLocatorResponse, r as AIElementResponse, m as AIResponseFormat, t as AISectionLocatorResponse, n as AISingleElementResponseById, o as AISingleElementResponseByPosition, l as AIUsageInfo, V as AgentAssertOpt, x as AgentDescribeElementAtPointResult, T as AgentWaitForOpt, a6 as BaseAgentParserOpt, C as CallAIFn, a5 as Color, G as DumpMeta, O as ElementById, k as ElementTreeNode, y as EnsureObject, a9 as ExecutionRecorderItem, ar as ExecutionTaskAction, aq as ExecutionTaskActionApply, ap as ExecutionTaskInsightAssertion, ao as ExecutionTaskInsightAssertionApply, an as ExecutionTaskInsightAssertionParam, ag as ExecutionTaskInsightDumpLog, ai as ExecutionTaskInsightLocate, ah as ExecutionTaskInsightLocateApply, af as ExecutionTaskInsightLocateOutput, ae as ExecutionTaskInsightLocateParam, am as ExecutionTaskInsightQuery, al as ExecutionTaskInsightQueryApply, ak as ExecutionTaskInsightQueryOutput, aj as ExecutionTaskInsightQueryParam, at as ExecutionTaskPlanning, as as ExecutionTaskPlanningApply, ad as ExecutionTaskReturn, aa as ExecutionTaskType, ab as ExecutorContext, aR as FreeFn, au as GroupedActionDump, J as InsightDump, z as InsightExtractParam, N as LiteUISection, aw as LocateOption, F as LocateResultElement, w as LocateValidatorResult, v as LocatorValidatorOption, j as MidsceneYamlFlowItem, aC as MidsceneYamlFlowItemAIAction, aD as MidsceneYamlFlowItemAIAssert, aH as MidsceneYamlFlowItemAIBoolean, aL as MidsceneYamlFlowItemAIHover, aM as MidsceneYamlFlowItemAIInput, aN as MidsceneYamlFlowItemAIKeyboardPress, aI as MidsceneYamlFlowItemAILocate, aG as MidsceneYamlFlowItemAINString, aF as MidsceneYamlFlowItemAINumber, aE as MidsceneYamlFlowItemAIQuery, aO as MidsceneYamlFlowItemAIScroll, aK as MidsceneYamlFlowItemAITap, aJ as MidsceneYamlFlowItemAIWaitFor, aP as MidsceneYamlFlowItemEvaluateJavaScript, aQ as MidsceneYamlFlowItemSleep, M as MidsceneYamlScript, aA as MidsceneYamlScriptAndroidEnv, aB as MidsceneYamlScriptEnv, ay as MidsceneYamlScriptEnvBase, az as MidsceneYamlScriptWebEnv, i as MidsceneYamlTask, Q as OnTaskStartTip, av as PageType, K as PartialInsightDumpFromSDK, Y as PlanningAIResponse, X as PlanningAction, a1 as PlanningActionParamAssert, a3 as PlanningActionParamError, _ as PlanningActionParamHover, $ as PlanningActionParamInputOrKeyPress, a0 as PlanningActionParamScroll, a2 as PlanningActionParamSleep, Z as PlanningActionParamTap, a4 as PlanningActionParamWaitFor, W as PlanningLocateParam, a8 as PlaywrightParserOpt, P as Point, a7 as PuppeteerParserOpt, H as ReportDumpWithAttributes, aT as ScriptPlayerStatusValue, aS as ScriptPlayerTaskStatus, S as Size, ac as TaskCacheInfo, ax as scrollParam } from './types-88f46e9e.js';
3
- import { c as callAiFn } from './llm-planning-28e999f3.js';
4
- export { a as AiAssert, A as AiLocateElement, d as describeUserPage, p as plan } from './llm-planning-28e999f3.js';
1
+ import { E as ExecutionTask, a as ExecutionTaskProgressOptions, b as ExecutionTaskApply, c as ExecutionDump, B as BaseElement, U as UIContext, I as InsightAction, D as DumpSubscriber, d as InsightTaskInfo, e as InsightOptions, f as DetailedLocateParam, L as LocateResult, g as InsightAssertionResponse, A as AISingleElementResponse } from './types-8c83481c.js';
2
+ export { t as AIAssertionResponse, r as AIDataExtractionResponse, p as AIElementCoordinatesResponse, o as AIElementLocatorResponse, q as AIElementResponse, l as AIResponseFormat, s as AISectionLocatorResponse, m as AISingleElementResponseById, n as AISingleElementResponseByPosition, k as AIUsageInfo, K as AgentAssertOpt, J as AgentWaitForOpt, a2 as BaseAgentParserOpt, C as CallAIFn, a1 as Color, x as DumpMeta, H as ElementById, j as ElementTreeNode, u as EnsureObject, a5 as ExecutionRecorderItem, an as ExecutionTaskAction, am as ExecutionTaskActionApply, al as ExecutionTaskInsightAssertion, ak as ExecutionTaskInsightAssertionApply, aj as ExecutionTaskInsightAssertionParam, ac as ExecutionTaskInsightDumpLog, ae as ExecutionTaskInsightLocate, ad as ExecutionTaskInsightLocateApply, ab as ExecutionTaskInsightLocateOutput, aa as ExecutionTaskInsightLocateParam, ai as ExecutionTaskInsightQuery, ah as ExecutionTaskInsightQueryApply, ag as ExecutionTaskInsightQueryOutput, af as ExecutionTaskInsightQueryParam, ap as ExecutionTaskPlanning, ao as ExecutionTaskPlanningApply, a9 as ExecutionTaskReturn, a6 as ExecutionTaskType, a7 as ExecutorContext, aN as FreeFn, aq as GroupedActionDump, z as InsightDump, v as InsightExtractParam, G as LiteUISection, as as LocateOption, w as LocateResultElement, i as MidsceneYamlFlowItem, ay as MidsceneYamlFlowItemAIAction, az as MidsceneYamlFlowItemAIAssert, aD as MidsceneYamlFlowItemAIBoolean, aH as MidsceneYamlFlowItemAIHover, aI as MidsceneYamlFlowItemAIInput, aJ as MidsceneYamlFlowItemAIKeyboardPress, aE as MidsceneYamlFlowItemAILocate, aC as MidsceneYamlFlowItemAINString, aB as MidsceneYamlFlowItemAINumber, aA as MidsceneYamlFlowItemAIQuery, aK as MidsceneYamlFlowItemAIScroll, aG as MidsceneYamlFlowItemAITap, aF as MidsceneYamlFlowItemAIWaitFor, aL as MidsceneYamlFlowItemEvaluateJavaScript, aM as MidsceneYamlFlowItemSleep, M as MidsceneYamlScript, aw as MidsceneYamlScriptAndroidEnv, ax as MidsceneYamlScriptEnv, au as MidsceneYamlScriptEnvBase, av as MidsceneYamlScriptWebEnv, h as MidsceneYamlTask, O as OnTaskStartTip, ar as PageType, F as PartialInsightDumpFromSDK, T as PlanningAIResponse, Q as PlanningAction, Z as PlanningActionParamAssert, $ as PlanningActionParamError, W as PlanningActionParamHover, X as PlanningActionParamInputOrKeyPress, Y as PlanningActionParamScroll, _ as PlanningActionParamSleep, V as PlanningActionParamTap, a0 as PlanningActionParamWaitFor, N as PlanningLocateParam, a4 as PlaywrightParserOpt, P as Point, a3 as PuppeteerParserOpt, R as Rect, y as ReportDumpWithAttributes, aP as ScriptPlayerStatusValue, aO as ScriptPlayerTaskStatus, S as Size, a8 as TaskCacheInfo, at as scrollParam } from './types-8c83481c.js';
3
+ import { c as callAiFn } from './llm-planning-e16d1814.js';
4
+ export { a as AiAssert, A as AiLocateElement, d as describeUserPage, p as plan } from './llm-planning-e16d1814.js';
5
5
  export { getVersion } from './utils.js';
6
6
  export { MIDSCENE_MODEL_NAME, getAIConfig } from '@midscene/shared/env';
7
7
  import '@midscene/shared/constants';
@@ -38,9 +38,6 @@ declare class Insight<ElementType extends BaseElement = BaseElement, ContextType
38
38
  extract<T extends Record<string, string>>(input: T): Promise<Record<keyof T, any>>;
39
39
  extract<T extends object>(input: Record<keyof T, string>): Promise<T>;
40
40
  assert(assertion: string): Promise<InsightAssertionResponse>;
41
- describe(target: Rect | [number, number], opt?: {
42
- deepThink?: boolean;
43
- }): Promise<Pick<AIDescribeElementResponse, 'description'>>;
44
41
  }
45
42
 
46
- export { AIDescribeElementResponse, AISingleElementResponse, BaseElement, DetailedLocateParam, DumpSubscriber, ExecutionDump, ExecutionTask, ExecutionTaskApply, ExecutionTaskProgressOptions, Executor, Insight, InsightAction, InsightAssertionResponse, InsightOptions, InsightTaskInfo, LocateResult, Rect, UIContext, Insight as default };
43
+ export { AISingleElementResponse, BaseElement, DetailedLocateParam, DumpSubscriber, ExecutionDump, ExecutionTask, ExecutionTaskApply, ExecutionTaskProgressOptions, Executor, Insight, InsightAction, InsightAssertionResponse, InsightOptions, InsightTaskInfo, LocateResult, UIContext, Insight as default };
package/dist/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkMVRTMYEMjs = require('./chunk-MVRTMYEM.js');
3
+ var _chunkKINAY5TJjs = require('./chunk-KINAY5TJ.js');
4
4
 
5
5
 
6
6
 
@@ -9,9 +9,7 @@ var _chunkMVRTMYEMjs = require('./chunk-MVRTMYEM.js');
9
9
 
10
10
 
11
11
 
12
-
13
-
14
- var _chunkNWSBT5YPjs = require('./chunk-NWSBT5YP.js');
12
+ var _chunkFYD4T7QDjs = require('./chunk-FYD4T7QD.js');
15
13
 
16
14
  // src/ai-model/action-executor.ts
17
15
  var _env = require('@midscene/shared/env');
@@ -158,7 +156,7 @@ ${_optionalChain([this, 'access', _7 => _7.latestErrorTask, 'call', _8 => _8(),
158
156
  }
159
157
  dump() {
160
158
  const dumpData = {
161
- sdkVersion: _chunkMVRTMYEMjs.getVersion.call(void 0, ),
159
+ sdkVersion: _chunkKINAY5TJjs.getVersion.call(void 0, ),
162
160
  model_name: _env.getAIConfig.call(void 0, _env.MIDSCENE_MODEL_NAME) || "",
163
161
  logTime: Date.now(),
164
162
  name: this.name,
@@ -168,40 +166,12 @@ ${_optionalChain([this, 'access', _7 => _7.latestErrorTask, 'call', _8 => _8(),
168
166
  }
169
167
  };
170
168
 
171
- // src/ai-model/prompt/describe.ts
172
-
173
- var preferredLanguage = _env.getPreferredLanguage.call(void 0, );
174
- var elementDescriberInstruction = () => {
175
- return `Tell what is the content of the element wrapped by the read rectangle in the screenshot. Your description is expected to be used to precisely locate the element from other similar elements on screenshot. Use ${preferredLanguage} in the description.
176
-
177
- Please follow the following rules:
178
- 1. The description should be start with a brief description, like "a button for confirming the action".
179
-
180
- 2. Include these information in the description to distinguish the element from its siblings and other similar elements, as much as possible:
181
- - The text of the element, like "with text 'Confirm'"
182
- - What the element looks like if it's an image, like "with image '...'"
183
- - The relative position of the element, like "on the left of ..., around ..."
184
- - How to distinguish the element from its siblings elements, like "it is the icon instead of the text"
185
-
186
- 3. Do NOT mention the red rectangle in the description.
187
-
188
- 4. Use the error field to describe the unexpected situations, if any. If not, put null.
189
-
190
- Return in JSON:
191
- {
192
- "description": "[{brief description}]: {text of the element} {image of the element} {relative position of the element} ... ",
193
- "error"?: "..."
194
- }`;
195
- };
196
-
197
169
  // src/insight/index.ts
198
170
 
199
171
 
200
172
 
201
173
 
202
174
 
203
-
204
- var _img = require('@midscene/shared/img');
205
175
  var _logger = require('@midscene/shared/logger');
206
176
 
207
177
 
@@ -224,7 +194,7 @@ function emitInsightDump(data, dumpSubscriber) {
224
194
  }
225
195
  }
226
196
  const baseData = {
227
- sdkVersion: _chunkMVRTMYEMjs.getVersion.call(void 0, ),
197
+ sdkVersion: _chunkKINAY5TJjs.getVersion.call(void 0, ),
228
198
  logTime: Date.now(),
229
199
  model_name: _env.getAIConfig.call(void 0, _env.MIDSCENE_MODEL_NAME) || "",
230
200
  model_description: modelDescription
@@ -241,7 +211,7 @@ function emitInsightDump(data, dumpSubscriber) {
241
211
  var debug = _logger.getDebug.call(void 0, "ai:insight");
242
212
  var Insight = class {
243
213
  constructor(context, opt) {
244
- this.aiVendorFn = _chunkNWSBT5YPjs.callAiFn;
214
+ this.aiVendorFn = _chunkFYD4T7QDjs.callAiFn;
245
215
  _utils.assert.call(void 0, context, "context is required for Insight");
246
216
  if (typeof context === "function") {
247
217
  this.contextRetrieverFn = context;
@@ -287,7 +257,7 @@ var Insight = class {
287
257
  let searchAreaUsage = void 0;
288
258
  let searchAreaResponse = void 0;
289
259
  if (searchAreaPrompt) {
290
- searchAreaResponse = await _chunkNWSBT5YPjs.AiLocateSection.call(void 0, {
260
+ searchAreaResponse = await _chunkFYD4T7QDjs.AiLocateSection.call(void 0, {
291
261
  context,
292
262
  sectionDescription: searchAreaPrompt
293
263
  });
@@ -300,7 +270,7 @@ var Insight = class {
300
270
  searchArea = searchAreaResponse.rect;
301
271
  }
302
272
  const startTime = Date.now();
303
- const { parseResult, rect, elementById, rawResponse, usage } = await _chunkNWSBT5YPjs.AiLocateElement.call(void 0, {
273
+ const { parseResult, rect, elementById, rawResponse, usage } = await _chunkFYD4T7QDjs.AiLocateElement.call(void 0, {
304
274
  callAI: callAI || this.aiVendorFn,
305
275
  context,
306
276
  targetElementDescription: queryPrompt,
@@ -388,7 +358,7 @@ ${parseResult.errors.join("\n")}`;
388
358
  this.onceDumpUpdatedFn = void 0;
389
359
  const context = await this.contextRetrieverFn("extract");
390
360
  const startTime = Date.now();
391
- const { parseResult, usage } = await _chunkNWSBT5YPjs.AiExtractElementInfo.call(void 0, {
361
+ const { parseResult, usage } = await _chunkFYD4T7QDjs.AiExtractElementInfo.call(void 0, {
392
362
  context,
393
363
  dataQuery: dataDemand
394
364
  });
@@ -439,7 +409,7 @@ ${parseResult.errors.join("\n")}`;
439
409
  this.onceDumpUpdatedFn = void 0;
440
410
  const context = await this.contextRetrieverFn("assert");
441
411
  const startTime = Date.now();
442
- const assertResult = await _chunkNWSBT5YPjs.AiAssert.call(void 0, {
412
+ const assertResult = await _chunkFYD4T7QDjs.AiAssert.call(void 0, {
443
413
  assertion,
444
414
  context
445
415
  });
@@ -469,59 +439,6 @@ ${parseResult.errors.join("\n")}`;
469
439
  usage: assertResult.usage
470
440
  };
471
441
  }
472
- async describe(target, opt) {
473
- _utils.assert.call(void 0, target, "target is required for insight.describe");
474
- const context = await this.contextRetrieverFn("describe");
475
- const { screenshotBase64 } = context;
476
- _utils.assert.call(void 0, screenshotBase64, "screenshot is required for insight.describe");
477
- const systemPrompt = elementDescriberInstruction();
478
- const defaultRectSize = 30;
479
- const targetRect = Array.isArray(target) ? {
480
- left: Math.floor(target[0] - defaultRectSize / 2),
481
- top: Math.floor(target[1] - defaultRectSize / 2),
482
- width: defaultRectSize,
483
- height: defaultRectSize
484
- } : target;
485
- let imagePayload = await _img.compositeElementInfoImg.call(void 0, {
486
- inputImgBase64: screenshotBase64,
487
- elementsPositionInfo: [
488
- {
489
- rect: targetRect
490
- }
491
- ],
492
- borderThickness: 3
493
- });
494
- if (_optionalChain([opt, 'optionalAccess', _24 => _24.deepThink])) {
495
- const searchArea = _chunkNWSBT5YPjs.expandSearchArea.call(void 0, targetRect, context.size);
496
- debug("describe: set searchArea", searchArea);
497
- imagePayload = await _img.cropByRect.call(void 0,
498
- imagePayload,
499
- searchArea,
500
- _env.getAIConfigInBoolean.call(void 0, _env.MIDSCENE_USE_QWEN_VL)
501
- );
502
- }
503
- const msgs = [
504
- { role: "system", content: systemPrompt },
505
- {
506
- role: "user",
507
- content: [
508
- {
509
- type: "image_url",
510
- image_url: {
511
- url: imagePayload,
512
- detail: "high"
513
- }
514
- }
515
- ]
516
- }
517
- ];
518
- const callAIFn = this.aiVendorFn || _chunkNWSBT5YPjs.callToGetJSONObject;
519
- const res = await callAIFn(msgs, 4 /* DESCRIBE_ELEMENT */);
520
- const { content } = res;
521
- _utils.assert.call(void 0, !content.error, `describe failed: ${content.error}`);
522
- _utils.assert.call(void 0, content.description, "failed to describe the element");
523
- return content;
524
- }
525
442
  };
526
443
 
527
444
  // src/index.ts
@@ -538,6 +455,6 @@ var src_default = Insight;
538
455
 
539
456
 
540
457
 
541
- exports.AiAssert = _chunkNWSBT5YPjs.AiAssert; exports.AiLocateElement = _chunkNWSBT5YPjs.AiLocateElement; exports.Executor = Executor; exports.Insight = Insight; exports.MIDSCENE_MODEL_NAME = _env.MIDSCENE_MODEL_NAME; exports.default = src_default; exports.describeUserPage = _chunkNWSBT5YPjs.describeUserPage; exports.getAIConfig = _env.getAIConfig; exports.getVersion = _chunkMVRTMYEMjs.getVersion; exports.plan = _chunkNWSBT5YPjs.plan;
458
+ exports.AiAssert = _chunkFYD4T7QDjs.AiAssert; exports.AiLocateElement = _chunkFYD4T7QDjs.AiLocateElement; exports.Executor = Executor; exports.Insight = Insight; exports.MIDSCENE_MODEL_NAME = _env.MIDSCENE_MODEL_NAME; exports.default = src_default; exports.describeUserPage = _chunkFYD4T7QDjs.describeUserPage; exports.getAIConfig = _env.getAIConfig; exports.getVersion = _chunkKINAY5TJjs.getVersion; exports.plan = _chunkFYD4T7QDjs.plan;
542
459
 
543
460
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"mappings":";;;;;;;;;;;;;;;;AAUA,SAAS,qBAAqB,mBAAmB;AACjD,SAAS,cAAc;AAEhB,IAAM,WAAN,MAAe;AAAA,EAUpB,YACE,MACA,SAGA;AACA,SAAK,SACH,SAAS,SAAS,QAAQ,MAAM,SAAS,IAAI,YAAY;AAC3D,SAAK,OAAO;AACZ,SAAK,SAAS,SAAS,SAAS,CAAC,GAAG;AAAA,MAAI,CAAC,SACvC,KAAK,kBAAkB,IAAI;AAAA,IAC7B;AACA,SAAK,cAAc,SAAS;AAAA,EAC9B;AAAA,EAEQ,kBAAkB,MAAyC;AACjE,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,GAAG;AAAA,IACL;AAAA,EACF;AAAA,EAEA,MAAM,OAAO,MAAgE;AAC3E;AAA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,CAAC;AAED,QAAI,KAAK,WAAW;AAClB,YAAM,aAAa,iBAAiB,YAAY,QAAQ,IAAI;AAC5D,YAAM,4BAA4B,UAAU;AAC5C,qBAAe,MAAM;AAAA,QACnB;AAAA,QACA;AAAA,QACA,qBAAqB,oBAAoB;AAAA,MAC3C;AAAA,IACF;AAEA,UAAM,OAAe;AAAA,MACnB,EAAE,MAAM,UAAU,SAAS,aAAa;AAAA,MACxC;AAAA,QACE,MAAM;AAAA,QACN,SAAS;AAAA,UACP;AAAA,YACE,MAAM;AAAA,YACN,WAAW;AAAA,cACT,KAAK;AAAA,cACL,QAAQ;AAAA,YACV;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,WACJ,KAAK,cAAc;AAErB,UAAM,MAAM,MAAM,SAAS,8BAAmC;AAE9D,UAAM,EAAE,QAAQ,IAAI;AACpB,IAAAA,QAAO,CAAC,QAAQ,OAAO,oBAAoB,QAAQ,KAAK,EAAE;AAC1D,IAAAA,QAAO,QAAQ,aAAa,gCAAgC;AAC5D,WAAO;AAAA,EACT;AACF;;;AEpZA,SAAS,eAAAE,cAAa,uBAAAD,4BAA2B;AAGjD,IAAO,cAAQ","names":["vlLocateMode","assert","MIDSCENE_MODEL_NAME","getAIConfig"],"ignoreList":[],"sources":["../../src/ai-model/action-executor.ts","../../src/ai-model/prompt/describe.ts","../../src/insight/index.ts","../../src/insight/utils.ts","../../src/index.ts"],"sourcesContent":["import type {\n ExecutionDump,\n ExecutionTask,\n ExecutionTaskApply,\n ExecutionTaskInsightLocateOutput,\n ExecutionTaskProgressOptions,\n ExecutionTaskReturn,\n ExecutorContext,\n} from '@/types';\nimport { getVersion } from '@/utils';\nimport { MIDSCENE_MODEL_NAME, getAIConfig } from '@midscene/shared/env';\nimport { assert } from '@midscene/shared/utils';\n\nexport class Executor {\n name: string;\n\n tasks: ExecutionTask[];\n\n // status of executor\n status: 'init' | 'pending' | 'running' | 'completed' | 'error';\n\n onTaskStart?: ExecutionTaskProgressOptions['onTaskStart'];\n\n constructor(\n name: string,\n options?: ExecutionTaskProgressOptions & {\n tasks?: ExecutionTaskApply[];\n },\n ) {\n this.status =\n options?.tasks && options.tasks.length > 0 ? 'pending' : 'init';\n this.name = name;\n this.tasks = (options?.tasks || []).map((item) =>\n this.markTaskAsPending(item),\n );\n this.onTaskStart = options?.onTaskStart;\n }\n\n private markTaskAsPending(task: ExecutionTaskApply): ExecutionTask {\n return {\n status: 'pending',\n ...task,\n };\n }\n\n async append(task: ExecutionTaskApply[] | ExecutionTaskApply): Promise<void> {\n assert(\n this.status !== 'error',\n `executor is in error state, cannot append task\\nerror=${this.latestErrorTask()?.error}\\n${this.latestErrorTask()?.errorStack}`,\n );\n if (Array.isArray(task)) {\n this.tasks.push(...task.map((item) => this.markTaskAsPending(item)));\n } else {\n this.tasks.push(this.markTaskAsPending(task));\n }\n if (this.status !== 'running') {\n this.status = 'pending';\n }\n }\n\n async flush(): Promise<any> {\n if (this.status === 'init' && this.tasks.length > 0) {\n console.warn(\n 'illegal state for executor, status is init but tasks are not empty',\n );\n }\n\n assert(this.status !== 'running', 'executor is already running');\n assert(this.status !== 'completed', 'executor is already completed');\n assert(this.status !== 'error', 'executor is in error state');\n\n const nextPendingIndex = this.tasks.findIndex(\n (task) => task.status === 'pending',\n );\n if (nextPendingIndex < 0) {\n // all tasks are completed\n return;\n }\n\n this.status = 'running';\n let taskIndex = nextPendingIndex;\n let successfullyCompleted = true;\n\n let previousFindOutput: ExecutionTaskInsightLocateOutput | undefined;\n\n while (taskIndex < this.tasks.length) {\n const task = this.tasks[taskIndex];\n assert(\n task.status === 'pending',\n `task status should be pending, but got: ${task.status}`,\n );\n task.timing = {\n start: Date.now(),\n };\n try {\n task.status = 'running';\n try {\n if (this.onTaskStart) {\n await this.onTaskStart(task);\n }\n } catch (e) {\n console.error('error in onTaskStart', e);\n }\n assert(\n ['Insight', 'Action', 'Planning'].indexOf(task.type) >= 0,\n `unsupported task type: ${task.type}`,\n );\n\n const { executor, param } = task;\n assert(executor, `executor is required for task type: ${task.type}`);\n\n let returnValue;\n const executorContext: ExecutorContext = {\n task,\n element: previousFindOutput?.element,\n };\n\n if (task.type === 'Insight') {\n assert(\n task.subType === 'Locate' ||\n task.subType === 'Query' ||\n task.subType === 'Assert' ||\n task.subType === 'Boolean' ||\n task.subType === 'Number' ||\n task.subType === 'String',\n `unsupported insight subType: ${task.subType}`,\n );\n returnValue = await task.executor(param, executorContext);\n if (task.subType === 'Locate') {\n previousFindOutput = (\n returnValue as ExecutionTaskReturn<ExecutionTaskInsightLocateOutput>\n )?.output;\n }\n } else if (task.type === 'Action' || task.type === 'Planning') {\n returnValue = await task.executor(param, executorContext);\n } else {\n console.warn(\n `unsupported task type: ${task.type}, will try to execute it directly`,\n );\n returnValue = await task.executor(param, executorContext);\n }\n\n Object.assign(task, returnValue);\n task.status = 'finished';\n task.timing.end = Date.now();\n task.timing.cost = task.timing.end - task.timing.start;\n task.timing.aiCost = (returnValue as any)?.aiCost || 0;\n taskIndex++;\n } catch (e: any) {\n successfullyCompleted = false;\n task.error =\n e?.message || (typeof e === 'string' ? e : 'error-without-message');\n task.errorStack = e.stack;\n\n task.status = 'failed';\n task.timing.end = Date.now();\n task.timing.cost = task.timing.end - task.timing.start;\n break;\n }\n }\n\n // set all remaining tasks as cancelled\n for (let i = taskIndex + 1; i < this.tasks.length; i++) {\n this.tasks[i].status = 'cancelled';\n }\n\n if (successfullyCompleted) {\n this.status = 'completed';\n } else {\n this.status = 'error';\n }\n\n if (this.tasks.length) {\n // return the last output\n const outputIndex = Math.min(taskIndex, this.tasks.length - 1);\n return this.tasks[outputIndex].output;\n }\n }\n\n isInErrorState(): boolean {\n return this.status === 'error';\n }\n\n latestErrorTask(): ExecutionTask | null {\n if (this.status !== 'error') {\n return null;\n }\n const errorTaskIndex = this.tasks.findIndex(\n (task) => task.status === 'failed',\n );\n if (errorTaskIndex >= 0) {\n return this.tasks[errorTaskIndex];\n }\n return null;\n }\n\n dump(): ExecutionDump {\n const dumpData: ExecutionDump = {\n sdkVersion: getVersion(),\n model_name: getAIConfig(MIDSCENE_MODEL_NAME) || '',\n logTime: Date.now(),\n name: this.name,\n tasks: this.tasks,\n };\n return dumpData;\n }\n}\n","import { getPreferredLanguage } from '@midscene/shared/env';\n\nconst preferredLanguage = getPreferredLanguage();\n\nexport const elementDescriberInstruction = () => {\n return `Tell what is the content of the element wrapped by the read rectangle in the screenshot. Your description is expected to be used to precisely locate the element from other similar elements on screenshot. Use ${preferredLanguage} in the description.\n\nPlease follow the following rules:\n1. The description should be start with a brief description, like \"a button for confirming the action\".\n\n2. Include these information in the description to distinguish the element from its siblings and other similar elements, as much as possible:\n- The text of the element, like \"with text 'Confirm'\"\n- What the element looks like if it's an image, like \"with image '...'\"\n- The relative position of the element, like \"on the left of ..., around ...\"\n- How to distinguish the element from its siblings elements, like \"it is the icon instead of the text\"\n\n3. Do NOT mention the red rectangle in the description.\n\n4. Use the error field to describe the unexpected situations, if any. If not, put null.\n\nReturn in JSON:\n{\n \"description\": \"[{brief description}]: {text of the element} {image of the element} {relative position of the element} ... \",\n \"error\"?: \"...\"\n}`;\n};\n","import {\n AIActionType,\n type AIArgs,\n callAiFn,\n expandSearchArea,\n} from '@/ai-model/common';\nimport {\n AiExtractElementInfo,\n AiLocateElement,\n callToGetJSONObject,\n} from '@/ai-model/index';\nimport { AiAssert, AiLocateSection } from '@/ai-model/inspect';\nimport { elementDescriberInstruction } from '@/ai-model/prompt/describe';\nimport type {\n AIDescribeElementResponse,\n AIElementResponse,\n AISingleElementResponse,\n AIUsageInfo,\n BaseElement,\n DetailedLocateParam,\n DumpSubscriber,\n InsightAction,\n InsightAssertionResponse,\n InsightExtractParam,\n InsightOptions,\n InsightTaskInfo,\n LocateResult,\n PartialInsightDumpFromSDK,\n Rect,\n UIContext,\n} from '@/types';\nimport {\n MIDSCENE_FORCE_DEEP_THINK,\n MIDSCENE_USE_QWEN_VL,\n getAIConfigInBoolean,\n vlLocateMode,\n} from '@midscene/shared/env';\nimport { compositeElementInfoImg, cropByRect } from '@midscene/shared/img';\nimport { getDebug } from '@midscene/shared/logger';\nimport { assert } from '@midscene/shared/utils';\nimport { emitInsightDump } from './utils';\n\nexport interface LocateOpts {\n callAI?: typeof callAiFn<AIElementResponse>;\n quickAnswer?: Partial<AISingleElementResponse>;\n}\n\nexport type AnyValue<T> = {\n [K in keyof T]: unknown extends T[K] ? any : T[K];\n};\n\nconst debug = getDebug('ai:insight');\nexport default class Insight<\n ElementType extends BaseElement = BaseElement,\n ContextType extends UIContext<ElementType> = UIContext<ElementType>,\n> {\n contextRetrieverFn: (\n action: InsightAction,\n ) => Promise<ContextType> | ContextType;\n\n aiVendorFn: (...args: Array<any>) => Promise<any> = callAiFn;\n\n onceDumpUpdatedFn?: DumpSubscriber;\n\n taskInfo?: Omit<InsightTaskInfo, 'durationMs'>;\n\n constructor(\n context:\n | ContextType\n | ((action: InsightAction) => Promise<ContextType> | ContextType),\n opt?: InsightOptions,\n ) {\n assert(context, 'context is required for Insight');\n if (typeof context === 'function') {\n this.contextRetrieverFn = context;\n } else {\n this.contextRetrieverFn = () => Promise.resolve(context);\n }\n\n if (typeof opt?.aiVendorFn !== 'undefined') {\n this.aiVendorFn = opt.aiVendorFn;\n }\n if (typeof opt?.taskInfo !== 'undefined') {\n this.taskInfo = opt.taskInfo;\n }\n }\n\n async locate(\n query: DetailedLocateParam,\n opt?: LocateOpts,\n ): Promise<LocateResult> {\n const { callAI } = opt || {};\n const queryPrompt = typeof query === 'string' ? query : query.prompt;\n assert(\n queryPrompt || opt?.quickAnswer,\n 'query or quickAnswer is required for locate',\n );\n const dumpSubscriber = this.onceDumpUpdatedFn;\n this.onceDumpUpdatedFn = undefined;\n\n assert(typeof query === 'object', 'query should be an object for locate');\n\n const globalDeepThinkSwitch = getAIConfigInBoolean(\n MIDSCENE_FORCE_DEEP_THINK,\n );\n if (globalDeepThinkSwitch) {\n debug('globalDeepThinkSwitch', globalDeepThinkSwitch);\n }\n let searchAreaPrompt;\n if (query.deepThink || globalDeepThinkSwitch) {\n searchAreaPrompt = query.prompt;\n }\n\n if (searchAreaPrompt && !vlLocateMode()) {\n console.warn(\n 'The \"deepThink\" feature is not supported with multimodal LLM. Please config VL model for Midscene. https://midscenejs.com/choose-a-model',\n );\n searchAreaPrompt = undefined;\n }\n\n const context = await this.contextRetrieverFn('locate');\n\n let searchArea: Rect | undefined = undefined;\n let searchAreaRawResponse: string | undefined = undefined;\n let searchAreaUsage: AIUsageInfo | undefined = undefined;\n let searchAreaResponse:\n | Awaited<ReturnType<typeof AiLocateSection>>\n | undefined = undefined;\n if (searchAreaPrompt) {\n searchAreaResponse = await AiLocateSection({\n context,\n sectionDescription: searchAreaPrompt,\n });\n assert(\n searchAreaResponse.rect,\n `cannot find search area for \"${searchAreaPrompt}\"${\n searchAreaResponse.error ? `: ${searchAreaResponse.error}` : ''\n }`,\n );\n searchAreaRawResponse = searchAreaResponse.rawResponse;\n searchAreaUsage = searchAreaResponse.usage;\n searchArea = searchAreaResponse.rect;\n }\n\n const startTime = Date.now();\n const { parseResult, rect, elementById, rawResponse, usage } =\n await AiLocateElement({\n callAI: callAI || this.aiVendorFn,\n context,\n targetElementDescription: queryPrompt,\n quickAnswer: opt?.quickAnswer,\n searchConfig: searchAreaResponse,\n });\n\n const timeCost = Date.now() - startTime;\n const taskInfo: InsightTaskInfo = {\n ...(this.taskInfo ? this.taskInfo : {}),\n durationMs: timeCost,\n rawResponse: JSON.stringify(rawResponse),\n formatResponse: JSON.stringify(parseResult),\n usage,\n searchArea,\n searchAreaRawResponse,\n searchAreaUsage,\n };\n\n let errorLog: string | undefined;\n if (parseResult.errors?.length) {\n errorLog = `AI model failed to locate: \\n${parseResult.errors.join('\\n')}`;\n }\n\n const dumpData: PartialInsightDumpFromSDK = {\n type: 'locate',\n userQuery: {\n element: queryPrompt,\n },\n quickAnswer: opt?.quickAnswer,\n matchedElement: [],\n matchedRect: rect,\n data: null,\n taskInfo,\n deepThink: !!searchArea,\n error: errorLog,\n };\n\n const elements: BaseElement[] = [];\n (parseResult.elements || []).forEach((item) => {\n if ('id' in item) {\n const element = elementById(item.id);\n\n if (!element) {\n console.warn(\n `locate: cannot find element id=${item.id}. Maybe an unstable response from AI model`,\n );\n return;\n }\n elements.push(element);\n }\n });\n\n emitInsightDump(\n {\n ...dumpData,\n matchedElement: elements,\n },\n dumpSubscriber,\n );\n\n if (errorLog) {\n throw new Error(errorLog);\n }\n\n assert(\n elements.length <= 1,\n `locate: multiple elements found, length = ${elements.length}`,\n );\n\n if (elements.length === 1) {\n return {\n element: {\n id: elements[0]!.id,\n indexId: elements[0]!.indexId,\n center: elements[0]!.center,\n rect: elements[0]!.rect,\n },\n rect,\n };\n }\n return {\n element: null,\n rect,\n };\n }\n\n async extract<T = any>(input: string): Promise<T>;\n async extract<T extends Record<string, string>>(\n input: T,\n ): Promise<Record<keyof T, any>>;\n async extract<T extends object>(input: Record<keyof T, string>): Promise<T>;\n\n async extract<T>(dataDemand: InsightExtractParam): Promise<any> {\n assert(\n typeof dataDemand === 'object' || typeof dataDemand === 'string',\n `dataDemand should be object or string, but get ${typeof dataDemand}`,\n );\n const dumpSubscriber = this.onceDumpUpdatedFn;\n this.onceDumpUpdatedFn = undefined;\n\n const context = await this.contextRetrieverFn('extract');\n\n const startTime = Date.now();\n const { parseResult, usage } = await AiExtractElementInfo<T>({\n context,\n dataQuery: dataDemand,\n });\n\n const timeCost = Date.now() - startTime;\n const taskInfo: InsightTaskInfo = {\n ...(this.taskInfo ? this.taskInfo : {}),\n durationMs: timeCost,\n rawResponse: JSON.stringify(parseResult),\n };\n\n let errorLog: string | undefined;\n if (parseResult.errors?.length) {\n errorLog = `AI response error: \\n${parseResult.errors.join('\\n')}`;\n }\n\n const dumpData: PartialInsightDumpFromSDK = {\n type: 'extract',\n userQuery: {\n dataDemand,\n },\n matchedElement: [],\n data: null,\n taskInfo,\n error: errorLog,\n };\n\n const { data } = parseResult || {};\n\n // 4\n emitInsightDump(\n {\n ...dumpData,\n data,\n },\n dumpSubscriber,\n );\n\n if (errorLog && !data) {\n throw new Error(errorLog);\n }\n\n return {\n data,\n usage,\n };\n }\n\n async assert(assertion: string): Promise<InsightAssertionResponse> {\n if (typeof assertion !== 'string') {\n throw new Error(\n 'This is the assert method for Midscene, the first argument should be a string. If you want to use the assert method from Node.js, please import it from the Node.js assert module.',\n );\n }\n\n const dumpSubscriber = this.onceDumpUpdatedFn;\n this.onceDumpUpdatedFn = undefined;\n\n const context = await this.contextRetrieverFn('assert');\n const startTime = Date.now();\n const assertResult = await AiAssert({\n assertion,\n context,\n });\n\n const timeCost = Date.now() - startTime;\n const taskInfo: InsightTaskInfo = {\n ...(this.taskInfo ? this.taskInfo : {}),\n durationMs: timeCost,\n rawResponse: JSON.stringify(assertResult.content),\n };\n\n const { thought, pass } = assertResult.content;\n const dumpData: PartialInsightDumpFromSDK = {\n type: 'assert',\n userQuery: {\n assertion,\n },\n matchedElement: [],\n data: null,\n taskInfo,\n assertionPass: pass,\n assertionThought: thought,\n error: pass ? undefined : thought,\n };\n emitInsightDump(dumpData, dumpSubscriber);\n\n return {\n pass,\n thought,\n usage: assertResult.usage,\n };\n }\n async describe(\n target: Rect | [number, number],\n opt?: {\n deepThink?: boolean;\n },\n ): Promise<Pick<AIDescribeElementResponse, 'description'>> {\n assert(target, 'target is required for insight.describe');\n const context = await this.contextRetrieverFn('describe');\n const { screenshotBase64 } = context;\n assert(screenshotBase64, 'screenshot is required for insight.describe');\n\n const systemPrompt = elementDescriberInstruction();\n\n // Convert [x,y] center point to Rect if needed\n const defaultRectSize = 30;\n const targetRect: Rect = Array.isArray(target)\n ? {\n left: Math.floor(target[0] - defaultRectSize / 2),\n top: Math.floor(target[1] - defaultRectSize / 2),\n width: defaultRectSize,\n height: defaultRectSize,\n }\n : target;\n\n let imagePayload = await compositeElementInfoImg({\n inputImgBase64: screenshotBase64,\n elementsPositionInfo: [\n {\n rect: targetRect,\n },\n ],\n borderThickness: 3,\n });\n\n if (opt?.deepThink) {\n const searchArea = expandSearchArea(targetRect, context.size);\n debug('describe: set searchArea', searchArea);\n imagePayload = await cropByRect(\n imagePayload,\n searchArea,\n getAIConfigInBoolean(MIDSCENE_USE_QWEN_VL),\n );\n }\n\n const msgs: AIArgs = [\n { role: 'system', content: systemPrompt },\n {\n role: 'user',\n content: [\n {\n type: 'image_url',\n image_url: {\n url: imagePayload,\n detail: 'high',\n },\n },\n ],\n },\n ];\n\n const callAIFn =\n this.aiVendorFn || callToGetJSONObject<AIDescribeElementResponse>;\n\n const res = await callAIFn(msgs, AIActionType.DESCRIBE_ELEMENT);\n\n const { content } = res;\n assert(!content.error, `describe failed: ${content.error}`);\n assert(content.description, 'failed to describe the element');\n return content;\n }\n}\n","import type {\n DumpMeta,\n DumpSubscriber,\n InsightDump,\n PartialInsightDumpFromSDK,\n} from '@/types';\nimport { getVersion } from '@/utils';\nimport {\n MIDSCENE_MODEL_NAME,\n getAIConfig,\n uiTarsModelVersion,\n vlLocateMode,\n} from '@midscene/shared/env';\nimport { uuid } from '@midscene/shared/utils';\n\nexport function emitInsightDump(\n data: PartialInsightDumpFromSDK,\n dumpSubscriber?: DumpSubscriber,\n) {\n let modelDescription = '';\n\n if (vlLocateMode()) {\n const uiTarsModelVer = uiTarsModelVersion();\n if (uiTarsModelVer) {\n modelDescription = `UI-TARS=${uiTarsModelVer}`;\n } else {\n modelDescription = `${vlLocateMode()} mode`;\n }\n }\n\n const baseData: DumpMeta = {\n sdkVersion: getVersion(),\n logTime: Date.now(),\n model_name: getAIConfig(MIDSCENE_MODEL_NAME) || '',\n model_description: modelDescription,\n };\n const finalData: InsightDump = {\n logId: uuid(),\n ...baseData,\n ...data,\n };\n\n dumpSubscriber?.(finalData);\n}\n","import { Executor } from './ai-model/action-executor';\nimport Insight from './insight/index';\nimport { getVersion } from './utils';\n\nexport {\n plan,\n describeUserPage,\n AiLocateElement,\n AiAssert,\n} from './ai-model/index';\n\nexport { getAIConfig, MIDSCENE_MODEL_NAME } from '@midscene/shared/env';\n\nexport type * from './types';\nexport default Insight;\nexport { Executor, Insight, getVersion };\n\nexport type {\n MidsceneYamlScript,\n MidsceneYamlTask,\n MidsceneYamlFlowItem,\n} from './yaml';\n"]}
1
+ {"version":3,"mappings":";;;;;;;;;;;;;;AAUA,SAAS,qBAAqB,mBAAmB;AACjD,SAAS,cAAc;AAEhB,IAAM,WAAN,MAAe;AAAA,EAUpB,YACE,MACA,SAGA;AACA,SAAK,SACH,SAAS,SAAS,QAAQ,MAAM,SAAS,IAAI,YAAY;AAC3D,SAAK,OAAO;AACZ,SAAK,SAAS,SAAS,SAAS,CAAC,GAAG;AAAA,MAAI,CAAC,SACvC,KAAK,kBAAkB,IAAI;AAAA,IAC7B;AACA,SAAK,cAAc,SAAS;AAAA,EAC9B;AAAA,EAEQ,kBAAkB,MAAyC;AACjE,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,GAAG;AAAA,IACL;AAAA,EACF;AAAA,EAEA,MAAM,OAAO,MAAgE;AAC3E;AAAA,MACE,KAAK,WAAW;AAAA,MAChB;AAAA,QAAyD,KAAK,gBAAgB,GAAG,KAAK;AAAA,EAAK,KAAK,gBAAgB,GAAG,UAAU;AAAA,IAC/H;AACA,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,WAAK,MAAM,KAAK,GAAG,KAAK,IAAI,CAAC,SAAS,KAAK,kBAAkB,IAAI,CAAC,CAAC;AAAA,IACrE,OAAO;AACL,WAAK,MAAM,KAAK,KAAK,kBAAkB,IAAI,CAAC;AAAA,IAC9C;AACA,QAAI,KAAK,WAAW,WAAW;AAC7B,WAAK,SAAS;AAAA,IAChB;AAAA,EACF;AAAA,EAEA,MAAM,QAAsB;AAC1B,QAAI,KAAK,WAAW,UAAU,KAAK,MAAM,SAAS,GAAG;AACnD,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAEA,WAAO,KAAK,WAAW,WAAW,6BAA6B;AAC/D,WAAO,KAAK,WAAW,aAAa,+BAA+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A;AAAA,IACF;AAEA,QAAI,YAAY,CAAC,MAAM;AACrB,YAAM,IAAI,MAAM,QAAQ;AAAA,IAC1B;AAEA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,OAAO,WAAsD;AACjE,QAAI,OAAO,cAAc,UAAU;AACjC,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,iBAAiB,KAAK;AAC5B,SAAK,oBAAoB;AAEzB,UAAM,UAAU,MAAM,KAAK,mBAAmB,QAAQ;AACtD,UAAM,YAAY,KAAK,IAAI;AAC3B,UAAM,eAAe,MAAM,SAAS;AAAA,MAClC;AAAA,MACA;AAAA,IACF,CAAC;AAED,UAAM,WAAW,KAAK,IAAI,IAAI;AAC9B,UAAM,WAA4B;AAAA,MAChC,GAAI,KAAK,WAAW,KAAK,WAAW,CAAC;AAAA,MACrC,YAAY;AAAA,MACZ,aAAa,KAAK,UAAU,aAAa,OAAO;AAAA,IAClD;AAEA,UAAM,EAAE,SAAS,KAAK,IAAI,aAAa;AACvC,UAAM,WAAsC;AAAA,MAC1C,MAAM;AAAA,MACN,WAAW;AAAA,QACT;AAAA,MACF;AAAA,MACA,gBAAgB,CAAC;AAAA,MACjB,MAAM;AAAA,MACN;AAAA,MACA,eAAe;AAAA,MACf,kBAAkB;AAAA,MAClB,OAAO,OAAO,SAAY;AAAA,IAC5B;AACA,oBAAgB,UAAU,cAAc;AAExC,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,OAAO,aAAa;AAAA,IACtB;AAAA,EACF;AACF;;;AEjUA,SAAS,eAAAE,cAAa,uBAAAD,4BAA2B;AAGjD,IAAO,cAAQ","names":["vlLocateMode","assert","MIDSCENE_MODEL_NAME","getAIConfig"],"ignoreList":[],"sources":["../../src/ai-model/action-executor.ts","../../src/insight/index.ts","../../src/insight/utils.ts","../../src/index.ts"],"sourcesContent":["import type {\n ExecutionDump,\n ExecutionTask,\n ExecutionTaskApply,\n ExecutionTaskInsightLocateOutput,\n ExecutionTaskProgressOptions,\n ExecutionTaskReturn,\n ExecutorContext,\n} from '@/types';\nimport { getVersion } from '@/utils';\nimport { MIDSCENE_MODEL_NAME, getAIConfig } from '@midscene/shared/env';\nimport { assert } from '@midscene/shared/utils';\n\nexport class Executor {\n name: string;\n\n tasks: ExecutionTask[];\n\n // status of executor\n status: 'init' | 'pending' | 'running' | 'completed' | 'error';\n\n onTaskStart?: ExecutionTaskProgressOptions['onTaskStart'];\n\n constructor(\n name: string,\n options?: ExecutionTaskProgressOptions & {\n tasks?: ExecutionTaskApply[];\n },\n ) {\n this.status =\n options?.tasks && options.tasks.length > 0 ? 'pending' : 'init';\n this.name = name;\n this.tasks = (options?.tasks || []).map((item) =>\n this.markTaskAsPending(item),\n );\n this.onTaskStart = options?.onTaskStart;\n }\n\n private markTaskAsPending(task: ExecutionTaskApply): ExecutionTask {\n return {\n status: 'pending',\n ...task,\n };\n }\n\n async append(task: ExecutionTaskApply[] | ExecutionTaskApply): Promise<void> {\n assert(\n this.status !== 'error',\n `executor is in error state, cannot append task\\nerror=${this.latestErrorTask()?.error}\\n${this.latestErrorTask()?.errorStack}`,\n );\n if (Array.isArray(task)) {\n this.tasks.push(...task.map((item) => this.markTaskAsPending(item)));\n } else {\n this.tasks.push(this.markTaskAsPending(task));\n }\n if (this.status !== 'running') {\n this.status = 'pending';\n }\n }\n\n async flush(): Promise<any> {\n if (this.status === 'init' && this.tasks.length > 0) {\n console.warn(\n 'illegal state for executor, status is init but tasks are not empty',\n );\n }\n\n assert(this.status !== 'running', 'executor is already running');\n assert(this.status !== 'completed', 'executor is already completed');\n assert(this.status !== 'error', 'executor is in error state');\n\n const nextPendingIndex = this.tasks.findIndex(\n (task) => task.status === 'pending',\n );\n if (nextPendingIndex < 0) {\n // all tasks are completed\n return;\n }\n\n this.status = 'running';\n let taskIndex = nextPendingIndex;\n let successfullyCompleted = true;\n\n let previousFindOutput: ExecutionTaskInsightLocateOutput | undefined;\n\n while (taskIndex < this.tasks.length) {\n const task = this.tasks[taskIndex];\n assert(\n task.status === 'pending',\n `task status should be pending, but got: ${task.status}`,\n );\n task.timing = {\n start: Date.now(),\n };\n try {\n task.status = 'running';\n try {\n if (this.onTaskStart) {\n await this.onTaskStart(task);\n }\n } catch (e) {\n console.error('error in onTaskStart', e);\n }\n assert(\n ['Insight', 'Action', 'Planning'].indexOf(task.type) >= 0,\n `unsupported task type: ${task.type}`,\n );\n\n const { executor, param } = task;\n assert(executor, `executor is required for task type: ${task.type}`);\n\n let returnValue;\n const executorContext: ExecutorContext = {\n task,\n element: previousFindOutput?.element,\n };\n\n if (task.type === 'Insight') {\n assert(\n task.subType === 'Locate' ||\n task.subType === 'Query' ||\n task.subType === 'Assert' ||\n task.subType === 'Boolean' ||\n task.subType === 'Number' ||\n task.subType === 'String',\n `unsupported insight subType: ${task.subType}`,\n );\n returnValue = await task.executor(param, executorContext);\n if (task.subType === 'Locate') {\n previousFindOutput = (\n returnValue as ExecutionTaskReturn<ExecutionTaskInsightLocateOutput>\n )?.output;\n }\n } else if (task.type === 'Action' || task.type === 'Planning') {\n returnValue = await task.executor(param, executorContext);\n } else {\n console.warn(\n `unsupported task type: ${task.type}, will try to execute it directly`,\n );\n returnValue = await task.executor(param, executorContext);\n }\n\n Object.assign(task, returnValue);\n task.status = 'finished';\n task.timing.end = Date.now();\n task.timing.cost = task.timing.end - task.timing.start;\n task.timing.aiCost = (returnValue as any)?.aiCost || 0;\n taskIndex++;\n } catch (e: any) {\n successfullyCompleted = false;\n task.error =\n e?.message || (typeof e === 'string' ? e : 'error-without-message');\n task.errorStack = e.stack;\n\n task.status = 'failed';\n task.timing.end = Date.now();\n task.timing.cost = task.timing.end - task.timing.start;\n break;\n }\n }\n\n // set all remaining tasks as cancelled\n for (let i = taskIndex + 1; i < this.tasks.length; i++) {\n this.tasks[i].status = 'cancelled';\n }\n\n if (successfullyCompleted) {\n this.status = 'completed';\n } else {\n this.status = 'error';\n }\n\n if (this.tasks.length) {\n // return the last output\n const outputIndex = Math.min(taskIndex, this.tasks.length - 1);\n return this.tasks[outputIndex].output;\n }\n }\n\n isInErrorState(): boolean {\n return this.status === 'error';\n }\n\n latestErrorTask(): ExecutionTask | null {\n if (this.status !== 'error') {\n return null;\n }\n const errorTaskIndex = this.tasks.findIndex(\n (task) => task.status === 'failed',\n );\n if (errorTaskIndex >= 0) {\n return this.tasks[errorTaskIndex];\n }\n return null;\n }\n\n dump(): ExecutionDump {\n const dumpData: ExecutionDump = {\n sdkVersion: getVersion(),\n model_name: getAIConfig(MIDSCENE_MODEL_NAME) || '',\n logTime: Date.now(),\n name: this.name,\n tasks: this.tasks,\n };\n return dumpData;\n }\n}\n","import { callAiFn } from '@/ai-model/common';\nimport { AiExtractElementInfo, AiLocateElement } from '@/ai-model/index';\nimport { AiAssert, AiLocateSection } from '@/ai-model/inspect';\nimport type {\n AIElementResponse,\n AISingleElementResponse,\n AIUsageInfo,\n BaseElement,\n DetailedLocateParam,\n DumpSubscriber,\n InsightAction,\n InsightAssertionResponse,\n InsightExtractParam,\n InsightOptions,\n InsightTaskInfo,\n LocateResult,\n PartialInsightDumpFromSDK,\n Rect,\n UIContext,\n} from '@/types';\nimport {\n MIDSCENE_FORCE_DEEP_THINK,\n getAIConfigInBoolean,\n vlLocateMode,\n} from '@midscene/shared/env';\nimport { getDebug } from '@midscene/shared/logger';\nimport { assert } from '@midscene/shared/utils';\nimport { emitInsightDump } from './utils';\n\nexport interface LocateOpts {\n callAI?: typeof callAiFn<AIElementResponse>;\n quickAnswer?: Partial<AISingleElementResponse>;\n}\n\nexport type AnyValue<T> = {\n [K in keyof T]: unknown extends T[K] ? any : T[K];\n};\n\nconst debug = getDebug('ai:insight');\nexport default class Insight<\n ElementType extends BaseElement = BaseElement,\n ContextType extends UIContext<ElementType> = UIContext<ElementType>,\n> {\n contextRetrieverFn: (\n action: InsightAction,\n ) => Promise<ContextType> | ContextType;\n\n aiVendorFn: (...args: Array<any>) => Promise<any> = callAiFn;\n\n onceDumpUpdatedFn?: DumpSubscriber;\n\n taskInfo?: Omit<InsightTaskInfo, 'durationMs'>;\n\n constructor(\n context:\n | ContextType\n | ((action: InsightAction) => Promise<ContextType> | ContextType),\n opt?: InsightOptions,\n ) {\n assert(context, 'context is required for Insight');\n if (typeof context === 'function') {\n this.contextRetrieverFn = context;\n } else {\n this.contextRetrieverFn = () => Promise.resolve(context);\n }\n\n if (typeof opt?.aiVendorFn !== 'undefined') {\n this.aiVendorFn = opt.aiVendorFn;\n }\n if (typeof opt?.taskInfo !== 'undefined') {\n this.taskInfo = opt.taskInfo;\n }\n }\n\n async locate(\n query: DetailedLocateParam,\n opt?: LocateOpts,\n ): Promise<LocateResult> {\n const { callAI } = opt || {};\n const queryPrompt = typeof query === 'string' ? query : query.prompt;\n assert(\n queryPrompt || opt?.quickAnswer,\n 'query or quickAnswer is required for locate',\n );\n const dumpSubscriber = this.onceDumpUpdatedFn;\n this.onceDumpUpdatedFn = undefined;\n\n assert(typeof query === 'object', 'query should be an object for locate');\n\n const globalDeepThinkSwitch = getAIConfigInBoolean(\n MIDSCENE_FORCE_DEEP_THINK,\n );\n if (globalDeepThinkSwitch) {\n debug('globalDeepThinkSwitch', globalDeepThinkSwitch);\n }\n let searchAreaPrompt;\n if (query.deepThink || globalDeepThinkSwitch) {\n searchAreaPrompt = query.prompt;\n }\n\n if (searchAreaPrompt && !vlLocateMode()) {\n console.warn(\n 'The \"deepThink\" feature is not supported with multimodal LLM. Please config VL model for Midscene. https://midscenejs.com/choose-a-model',\n );\n searchAreaPrompt = undefined;\n }\n\n const context = await this.contextRetrieverFn('locate');\n\n let searchArea: Rect | undefined = undefined;\n let searchAreaRawResponse: string | undefined = undefined;\n let searchAreaUsage: AIUsageInfo | undefined = undefined;\n let searchAreaResponse:\n | Awaited<ReturnType<typeof AiLocateSection>>\n | undefined = undefined;\n if (searchAreaPrompt) {\n searchAreaResponse = await AiLocateSection({\n context,\n sectionDescription: searchAreaPrompt,\n });\n assert(\n searchAreaResponse.rect,\n `cannot find search area for \"${searchAreaPrompt}\"${\n searchAreaResponse.error ? `: ${searchAreaResponse.error}` : ''\n }`,\n );\n searchAreaRawResponse = searchAreaResponse.rawResponse;\n searchAreaUsage = searchAreaResponse.usage;\n searchArea = searchAreaResponse.rect;\n }\n\n const startTime = Date.now();\n const { parseResult, rect, elementById, rawResponse, usage } =\n await AiLocateElement({\n callAI: callAI || this.aiVendorFn,\n context,\n targetElementDescription: queryPrompt,\n quickAnswer: opt?.quickAnswer,\n searchConfig: searchAreaResponse,\n });\n\n const timeCost = Date.now() - startTime;\n const taskInfo: InsightTaskInfo = {\n ...(this.taskInfo ? this.taskInfo : {}),\n durationMs: timeCost,\n rawResponse: JSON.stringify(rawResponse),\n formatResponse: JSON.stringify(parseResult),\n usage,\n searchArea,\n searchAreaRawResponse,\n searchAreaUsage,\n };\n\n let errorLog: string | undefined;\n if (parseResult.errors?.length) {\n errorLog = `AI model failed to locate: \\n${parseResult.errors.join('\\n')}`;\n }\n\n const dumpData: PartialInsightDumpFromSDK = {\n type: 'locate',\n userQuery: {\n element: queryPrompt,\n },\n quickAnswer: opt?.quickAnswer,\n matchedElement: [],\n matchedRect: rect,\n data: null,\n taskInfo,\n deepThink: !!searchArea,\n error: errorLog,\n };\n\n const elements: BaseElement[] = [];\n (parseResult.elements || []).forEach((item) => {\n if ('id' in item) {\n const element = elementById(item.id);\n\n if (!element) {\n console.warn(\n `locate: cannot find element id=${item.id}. Maybe an unstable response from AI model`,\n );\n return;\n }\n elements.push(element);\n }\n });\n\n emitInsightDump(\n {\n ...dumpData,\n matchedElement: elements,\n },\n dumpSubscriber,\n );\n\n if (errorLog) {\n throw new Error(errorLog);\n }\n\n assert(\n elements.length <= 1,\n `locate: multiple elements found, length = ${elements.length}`,\n );\n\n if (elements.length === 1) {\n return {\n element: {\n id: elements[0]!.id,\n indexId: elements[0]!.indexId,\n center: elements[0]!.center,\n rect: elements[0]!.rect,\n },\n rect,\n };\n }\n return {\n element: null,\n rect,\n };\n }\n\n async extract<T = any>(input: string): Promise<T>;\n async extract<T extends Record<string, string>>(\n input: T,\n ): Promise<Record<keyof T, any>>;\n async extract<T extends object>(input: Record<keyof T, string>): Promise<T>;\n\n async extract<T>(dataDemand: InsightExtractParam): Promise<any> {\n assert(\n typeof dataDemand === 'object' || typeof dataDemand === 'string',\n `dataDemand should be object or string, but get ${typeof dataDemand}`,\n );\n const dumpSubscriber = this.onceDumpUpdatedFn;\n this.onceDumpUpdatedFn = undefined;\n\n const context = await this.contextRetrieverFn('extract');\n\n const startTime = Date.now();\n const { parseResult, usage } = await AiExtractElementInfo<T>({\n context,\n dataQuery: dataDemand,\n });\n\n const timeCost = Date.now() - startTime;\n const taskInfo: InsightTaskInfo = {\n ...(this.taskInfo ? this.taskInfo : {}),\n durationMs: timeCost,\n rawResponse: JSON.stringify(parseResult),\n };\n\n let errorLog: string | undefined;\n if (parseResult.errors?.length) {\n errorLog = `AI response error: \\n${parseResult.errors.join('\\n')}`;\n }\n\n const dumpData: PartialInsightDumpFromSDK = {\n type: 'extract',\n userQuery: {\n dataDemand,\n },\n matchedElement: [],\n data: null,\n taskInfo,\n error: errorLog,\n };\n\n const { data } = parseResult || {};\n\n // 4\n emitInsightDump(\n {\n ...dumpData,\n data,\n },\n dumpSubscriber,\n );\n\n if (errorLog && !data) {\n throw new Error(errorLog);\n }\n\n return {\n data,\n usage,\n };\n }\n\n async assert(assertion: string): Promise<InsightAssertionResponse> {\n if (typeof assertion !== 'string') {\n throw new Error(\n 'This is the assert method for Midscene, the first argument should be a string. If you want to use the assert method from Node.js, please import it from the Node.js assert module.',\n );\n }\n\n const dumpSubscriber = this.onceDumpUpdatedFn;\n this.onceDumpUpdatedFn = undefined;\n\n const context = await this.contextRetrieverFn('assert');\n const startTime = Date.now();\n const assertResult = await AiAssert({\n assertion,\n context,\n });\n\n const timeCost = Date.now() - startTime;\n const taskInfo: InsightTaskInfo = {\n ...(this.taskInfo ? this.taskInfo : {}),\n durationMs: timeCost,\n rawResponse: JSON.stringify(assertResult.content),\n };\n\n const { thought, pass } = assertResult.content;\n const dumpData: PartialInsightDumpFromSDK = {\n type: 'assert',\n userQuery: {\n assertion,\n },\n matchedElement: [],\n data: null,\n taskInfo,\n assertionPass: pass,\n assertionThought: thought,\n error: pass ? undefined : thought,\n };\n emitInsightDump(dumpData, dumpSubscriber);\n\n return {\n pass,\n thought,\n usage: assertResult.usage,\n };\n }\n}\n","import type {\n DumpMeta,\n DumpSubscriber,\n InsightDump,\n PartialInsightDumpFromSDK,\n} from '@/types';\nimport { getVersion } from '@/utils';\nimport {\n MIDSCENE_MODEL_NAME,\n getAIConfig,\n uiTarsModelVersion,\n vlLocateMode,\n} from '@midscene/shared/env';\nimport { uuid } from '@midscene/shared/utils';\n\nexport function emitInsightDump(\n data: PartialInsightDumpFromSDK,\n dumpSubscriber?: DumpSubscriber,\n) {\n let modelDescription = '';\n\n if (vlLocateMode()) {\n const uiTarsModelVer = uiTarsModelVersion();\n if (uiTarsModelVer) {\n modelDescription = `UI-TARS=${uiTarsModelVer}`;\n } else {\n modelDescription = `${vlLocateMode()} mode`;\n }\n }\n\n const baseData: DumpMeta = {\n sdkVersion: getVersion(),\n logTime: Date.now(),\n model_name: getAIConfig(MIDSCENE_MODEL_NAME) || '',\n model_description: modelDescription,\n };\n const finalData: InsightDump = {\n logId: uuid(),\n ...baseData,\n ...data,\n };\n\n dumpSubscriber?.(finalData);\n}\n","import { Executor } from './ai-model/action-executor';\nimport Insight from './insight/index';\nimport { getVersion } from './utils';\n\nexport {\n plan,\n describeUserPage,\n AiLocateElement,\n AiAssert,\n} from './ai-model/index';\n\nexport { getAIConfig, MIDSCENE_MODEL_NAME } from '@midscene/shared/env';\n\nexport type * from './types';\nexport default Insight;\nexport { Executor, Insight, getVersion };\n\nexport type {\n MidsceneYamlScript,\n MidsceneYamlTask,\n MidsceneYamlFlowItem,\n} from './yaml';\n"]}
@@ -1,4 +1,4 @@
1
- import { l as AIUsageInfo, R as Rect, B as BaseElement, U as UIContext, h as AISingleElementResponse, o as AISingleElementResponseByPosition, p as AIElementLocatorResponse, O as ElementById, s as AIDataExtractionResponse, u as AIAssertionResponse, av as PageType, Y as PlanningAIResponse } from './types-88f46e9e.js';
1
+ import { k as AIUsageInfo, R as Rect, B as BaseElement, U as UIContext, A as AISingleElementResponse, n as AISingleElementResponseByPosition, o as AIElementLocatorResponse, H as ElementById, r as AIDataExtractionResponse, t as AIAssertionResponse, ar as PageType, T as PlanningAIResponse } from './types-8c83481c.js';
2
2
  import { ChatCompletionSystemMessageParam, ChatCompletionUserMessageParam } from 'openai/resources';
3
3
 
4
4
  type AIArgs = [
@@ -9,8 +9,7 @@ declare enum AIActionType {
9
9
  ASSERT = 0,
10
10
  INSPECT_ELEMENT = 1,
11
11
  EXTRACT_DATA = 2,
12
- PLAN = 3,
13
- DESCRIBE_ELEMENT = 4
12
+ PLAN = 3
14
13
  }
15
14
  declare function callAiFn<T>(msgs: AIArgs, AIActionTypeValue: AIActionType): Promise<{
16
15
  content: T;
@@ -1,5 +1,5 @@
1
1
  import * as _midscene_shared_constants from '@midscene/shared/constants';
2
- import { B as BaseElement, k as ElementTreeNode } from './types-88f46e9e.js';
2
+ import { B as BaseElement, j as ElementTreeNode } from './types-8c83481c.js';
3
3
  import 'openai/resources';
4
4
 
5
5
  declare function truncateText(text: string | number | object | undefined, maxLength?: number): string;
@@ -203,24 +203,6 @@ interface AIAssertionResponse {
203
203
  pass: boolean;
204
204
  thought: string;
205
205
  }
206
- interface AIDescribeElementResponse {
207
- description: string;
208
- error?: string;
209
- }
210
- interface LocatorValidatorOption {
211
- centerDistanceThreshold?: number;
212
- }
213
- interface LocateValidatorResult {
214
- pass: boolean;
215
- rect: Rect;
216
- center: [number, number];
217
- centerDistance?: number;
218
- }
219
- interface AgentDescribeElementAtPointResult {
220
- prompt: string;
221
- deepThink: boolean;
222
- verifyResult?: LocateValidatorResult;
223
- }
224
206
  /**
225
207
  * context
226
208
  */
@@ -241,7 +223,7 @@ interface InsightOptions {
241
223
  type EnsureObject<T> = {
242
224
  [K in keyof T]: any;
243
225
  };
244
- type InsightAction = 'locate' | 'extract' | 'assert' | 'describe';
226
+ type InsightAction = 'locate' | 'extract' | 'assert';
245
227
  type InsightExtractParam = string | Record<string, string>;
246
228
  type LocateResultElement = {
247
229
  id: string;
@@ -457,4 +439,4 @@ interface GroupedActionDump {
457
439
  }
458
440
  type PageType = 'puppeteer' | 'playwright' | 'static' | 'chrome-extension-proxy' | 'android';
459
441
 
460
- export { type PlanningActionParamInputOrKeyPress as $, type AIDescribeElementResponse as A, BaseElement as B, type CallAIFn as C, type DumpSubscriber as D, type ExecutionTask as E, type LocateResultElement as F, type DumpMeta as G, type ReportDumpWithAttributes as H, type InsightAction as I, type InsightDump as J, type PartialInsightDumpFromSDK as K, type LocateResult as L, type MidsceneYamlScript as M, type LiteUISection as N, type ElementById as O, type Point as P, type OnTaskStartTip as Q, type Rect as R, type Size as S, type AgentWaitForOpt as T, UIContext as U, type AgentAssertOpt as V, type PlanningLocateParam as W, type PlanningAction as X, type PlanningAIResponse as Y, type PlanningActionParamTap as Z, type PlanningActionParamHover as _, type ExecutionTaskProgressOptions as a, type PlanningActionParamScroll as a0, type PlanningActionParamAssert as a1, type PlanningActionParamSleep as a2, type PlanningActionParamError as a3, type PlanningActionParamWaitFor as a4, type Color as a5, type BaseAgentParserOpt as a6, type PuppeteerParserOpt as a7, type PlaywrightParserOpt as a8, type ExecutionRecorderItem as a9, type MidsceneYamlScriptAndroidEnv as aA, type MidsceneYamlScriptEnv as aB, type MidsceneYamlFlowItemAIAction as aC, type MidsceneYamlFlowItemAIAssert as aD, type MidsceneYamlFlowItemAIQuery as aE, type MidsceneYamlFlowItemAINumber as aF, type MidsceneYamlFlowItemAINString as aG, type MidsceneYamlFlowItemAIBoolean as aH, type MidsceneYamlFlowItemAILocate as aI, type MidsceneYamlFlowItemAIWaitFor as aJ, type MidsceneYamlFlowItemAITap as aK, type MidsceneYamlFlowItemAIHover as aL, type MidsceneYamlFlowItemAIInput as aM, type MidsceneYamlFlowItemAIKeyboardPress as aN, type MidsceneYamlFlowItemAIScroll as aO, type MidsceneYamlFlowItemEvaluateJavaScript as aP, type MidsceneYamlFlowItemSleep as aQ, type FreeFn as aR, type ScriptPlayerTaskStatus as aS, type ScriptPlayerStatusValue as aT, type ExecutionTaskType as aa, type ExecutorContext as ab, type TaskCacheInfo as ac, type ExecutionTaskReturn as ad, type ExecutionTaskInsightLocateParam as ae, type ExecutionTaskInsightLocateOutput as af, type ExecutionTaskInsightDumpLog as ag, type ExecutionTaskInsightLocateApply as ah, type ExecutionTaskInsightLocate as ai, type ExecutionTaskInsightQueryParam as aj, type ExecutionTaskInsightQueryOutput as ak, type ExecutionTaskInsightQueryApply as al, type ExecutionTaskInsightQuery as am, type ExecutionTaskInsightAssertionParam as an, type ExecutionTaskInsightAssertionApply as ao, type ExecutionTaskInsightAssertion as ap, type ExecutionTaskActionApply as aq, type ExecutionTaskAction as ar, type ExecutionTaskPlanningApply as as, type ExecutionTaskPlanning as at, type GroupedActionDump as au, type PageType as av, type LocateOption as aw, type scrollParam as ax, type MidsceneYamlScriptEnvBase as ay, type MidsceneYamlScriptWebEnv as az, type ExecutionTaskApply as b, type ExecutionDump as c, type InsightTaskInfo as d, type InsightOptions as e, type DetailedLocateParam as f, type InsightAssertionResponse as g, type AISingleElementResponse as h, type MidsceneYamlTask as i, type MidsceneYamlFlowItem as j, type ElementTreeNode as k, type AIUsageInfo as l, AIResponseFormat as m, type AISingleElementResponseById as n, type AISingleElementResponseByPosition as o, type AIElementLocatorResponse as p, type AIElementCoordinatesResponse as q, type AIElementResponse as r, type AIDataExtractionResponse as s, type AISectionLocatorResponse as t, type AIAssertionResponse as u, type LocatorValidatorOption as v, type LocateValidatorResult as w, type AgentDescribeElementAtPointResult as x, type EnsureObject as y, type InsightExtractParam as z };
442
+ export { type PlanningActionParamError as $, type AISingleElementResponse as A, BaseElement as B, type CallAIFn as C, type DumpSubscriber as D, type ExecutionTask as E, type PartialInsightDumpFromSDK as F, type LiteUISection as G, type ElementById as H, type InsightAction as I, type AgentWaitForOpt as J, type AgentAssertOpt as K, type LocateResult as L, type MidsceneYamlScript as M, type PlanningLocateParam as N, type OnTaskStartTip as O, type Point as P, type PlanningAction as Q, type Rect as R, type Size as S, type PlanningAIResponse as T, UIContext as U, type PlanningActionParamTap as V, type PlanningActionParamHover as W, type PlanningActionParamInputOrKeyPress as X, type PlanningActionParamScroll as Y, type PlanningActionParamAssert as Z, type PlanningActionParamSleep as _, type ExecutionTaskProgressOptions as a, type PlanningActionParamWaitFor as a0, type Color as a1, type BaseAgentParserOpt as a2, type PuppeteerParserOpt as a3, type PlaywrightParserOpt as a4, type ExecutionRecorderItem as a5, type ExecutionTaskType as a6, type ExecutorContext as a7, type TaskCacheInfo as a8, type ExecutionTaskReturn as a9, type MidsceneYamlFlowItemAIQuery as aA, type MidsceneYamlFlowItemAINumber as aB, type MidsceneYamlFlowItemAINString as aC, type MidsceneYamlFlowItemAIBoolean as aD, type MidsceneYamlFlowItemAILocate as aE, type MidsceneYamlFlowItemAIWaitFor as aF, type MidsceneYamlFlowItemAITap as aG, type MidsceneYamlFlowItemAIHover as aH, type MidsceneYamlFlowItemAIInput as aI, type MidsceneYamlFlowItemAIKeyboardPress as aJ, type MidsceneYamlFlowItemAIScroll as aK, type MidsceneYamlFlowItemEvaluateJavaScript as aL, type MidsceneYamlFlowItemSleep as aM, type FreeFn as aN, type ScriptPlayerTaskStatus as aO, type ScriptPlayerStatusValue as aP, type ExecutionTaskInsightLocateParam as aa, type ExecutionTaskInsightLocateOutput as ab, type ExecutionTaskInsightDumpLog as ac, type ExecutionTaskInsightLocateApply as ad, type ExecutionTaskInsightLocate as ae, type ExecutionTaskInsightQueryParam as af, type ExecutionTaskInsightQueryOutput as ag, type ExecutionTaskInsightQueryApply as ah, type ExecutionTaskInsightQuery as ai, type ExecutionTaskInsightAssertionParam as aj, type ExecutionTaskInsightAssertionApply as ak, type ExecutionTaskInsightAssertion as al, type ExecutionTaskActionApply as am, type ExecutionTaskAction as an, type ExecutionTaskPlanningApply as ao, type ExecutionTaskPlanning as ap, type GroupedActionDump as aq, type PageType as ar, type LocateOption as as, type scrollParam as at, type MidsceneYamlScriptEnvBase as au, type MidsceneYamlScriptWebEnv as av, type MidsceneYamlScriptAndroidEnv as aw, type MidsceneYamlScriptEnv as ax, type MidsceneYamlFlowItemAIAction as ay, type MidsceneYamlFlowItemAIAssert as az, type ExecutionTaskApply as b, type ExecutionDump as c, type InsightTaskInfo as d, type InsightOptions as e, type DetailedLocateParam as f, type InsightAssertionResponse as g, type MidsceneYamlTask as h, type MidsceneYamlFlowItem as i, type ElementTreeNode as j, type AIUsageInfo as k, AIResponseFormat as l, type AISingleElementResponseById as m, type AISingleElementResponseByPosition as n, type AIElementLocatorResponse as o, type AIElementCoordinatesResponse as p, type AIElementResponse as q, type AIDataExtractionResponse as r, type AISectionLocatorResponse as s, type AIAssertionResponse as t, type EnsureObject as u, type InsightExtractParam as v, type LocateResultElement as w, type DumpMeta as x, type ReportDumpWithAttributes as y, type InsightDump as z };
@@ -1,10 +1,9 @@
1
- import { H as ReportDumpWithAttributes, R as Rect } from './types-88f46e9e.js';
1
+ import { y as ReportDumpWithAttributes, R as Rect } from './types-8c83481c.js';
2
2
  import '@midscene/shared/constants';
3
3
  import 'openai/resources';
4
4
 
5
5
  declare const groupedActionDumpFileExt = "web-dump.json";
6
6
  declare function getLogDir(): string;
7
- declare function setReportTpl(tpl: string): void;
8
7
  declare function replaceStringWithFirstAppearance(str: string, target: string, replacement: string): string;
9
8
  declare function reportHTMLContent(dumpData: string | ReportDumpWithAttributes[], reportPath?: string): string;
10
9
  declare function writeDumpReport(fileName: string, dumpData: string | ReportDumpWithAttributes[]): string | null;
@@ -26,4 +25,4 @@ declare function uploadTestInfoToServer({ testUrl }: {
26
25
  testUrl: string;
27
26
  }): void;
28
27
 
29
- export { getLogDir, getTmpDir, getTmpFile, getVersion, groupedActionDumpFileExt, overlapped, replaceStringWithFirstAppearance, replacerForPageObject, reportHTMLContent, setReportTpl, sleep, stringifyDumpData, uploadTestInfoToServer, writeDumpReport, writeLogFile };
28
+ export { getLogDir, getTmpDir, getTmpFile, getVersion, groupedActionDumpFileExt, overlapped, replaceStringWithFirstAppearance, replacerForPageObject, reportHTMLContent, sleep, stringifyDumpData, uploadTestInfoToServer, writeDumpReport, writeLogFile };
package/dist/lib/utils.js CHANGED
@@ -13,8 +13,8 @@
13
13
 
14
14
 
15
15
 
16
+ var _chunkKINAY5TJjs = require('./chunk-KINAY5TJ.js');
16
17
 
17
- var _chunkMVRTMYEMjs = require('./chunk-MVRTMYEM.js');
18
18
 
19
19
 
20
20
 
@@ -29,6 +29,4 @@ var _chunkMVRTMYEMjs = require('./chunk-MVRTMYEM.js');
29
29
 
30
30
 
31
31
 
32
-
33
-
34
- exports.getLogDir = _chunkMVRTMYEMjs.getLogDir; exports.getTmpDir = _chunkMVRTMYEMjs.getTmpDir; exports.getTmpFile = _chunkMVRTMYEMjs.getTmpFile; exports.getVersion = _chunkMVRTMYEMjs.getVersion; exports.groupedActionDumpFileExt = _chunkMVRTMYEMjs.groupedActionDumpFileExt; exports.overlapped = _chunkMVRTMYEMjs.overlapped; exports.replaceStringWithFirstAppearance = _chunkMVRTMYEMjs.replaceStringWithFirstAppearance; exports.replacerForPageObject = _chunkMVRTMYEMjs.replacerForPageObject; exports.reportHTMLContent = _chunkMVRTMYEMjs.reportHTMLContent; exports.setReportTpl = _chunkMVRTMYEMjs.setReportTpl; exports.sleep = _chunkMVRTMYEMjs.sleep; exports.stringifyDumpData = _chunkMVRTMYEMjs.stringifyDumpData; exports.uploadTestInfoToServer = _chunkMVRTMYEMjs.uploadTestInfoToServer; exports.writeDumpReport = _chunkMVRTMYEMjs.writeDumpReport; exports.writeLogFile = _chunkMVRTMYEMjs.writeLogFile;
32
+ exports.getLogDir = _chunkKINAY5TJjs.getLogDir; exports.getTmpDir = _chunkKINAY5TJjs.getTmpDir; exports.getTmpFile = _chunkKINAY5TJjs.getTmpFile; exports.getVersion = _chunkKINAY5TJjs.getVersion; exports.groupedActionDumpFileExt = _chunkKINAY5TJjs.groupedActionDumpFileExt; exports.overlapped = _chunkKINAY5TJjs.overlapped; exports.replaceStringWithFirstAppearance = _chunkKINAY5TJjs.replaceStringWithFirstAppearance; exports.replacerForPageObject = _chunkKINAY5TJjs.replacerForPageObject; exports.reportHTMLContent = _chunkKINAY5TJjs.reportHTMLContent; exports.sleep = _chunkKINAY5TJjs.sleep; exports.stringifyDumpData = _chunkKINAY5TJjs.stringifyDumpData; exports.uploadTestInfoToServer = _chunkKINAY5TJjs.uploadTestInfoToServer; exports.writeDumpReport = _chunkKINAY5TJjs.writeDumpReport; exports.writeLogFile = _chunkKINAY5TJjs.writeLogFile;
@@ -1,8 +1,8 @@
1
- import { l as AIUsageInfo, X as PlanningAction } from './types-88f46e9e.js';
1
+ import { k as AIUsageInfo, Q as PlanningAction } from './types-8c83481c.js';
2
2
  import { ChatCompletionMessageParam } from 'openai/resources';
3
3
  export { ChatCompletionMessageParam } from 'openai/resources';
4
- import { b as AIActionType } from './llm-planning-28e999f3.js';
5
- export { a as AiAssert, e as AiExtractElementInfo, A as AiLocateElement, f as AiLocateSection, g as adaptBboxToRect, c as callAiFn, d as describeUserPage, p as plan } from './llm-planning-28e999f3.js';
4
+ import { b as AIActionType } from './llm-planning-e16d1814.js';
5
+ export { a as AiAssert, e as AiExtractElementInfo, A as AiLocateElement, f as AiLocateSection, g as adaptBboxToRect, c as callAiFn, d as describeUserPage, p as plan } from './llm-planning-e16d1814.js';
6
6
  import { vlLocateMode } from '@midscene/shared/env';
7
7
  import { actionParser } from '@ui-tars/action-parser';
8
8
  import '@midscene/shared/constants';
@@ -1,7 +1,7 @@
1
- import { E as ExecutionTask, a as ExecutionTaskProgressOptions, b as ExecutionTaskApply, c as ExecutionDump, B as BaseElement, U as UIContext, I as InsightAction, D as DumpSubscriber, d as InsightTaskInfo, e as InsightOptions, f as DetailedLocateParam, L as LocateResult, g as InsightAssertionResponse, R as Rect, A as AIDescribeElementResponse, h as AISingleElementResponse } from './types-88f46e9e.js';
2
- export { u as AIAssertionResponse, s as AIDataExtractionResponse, q as AIElementCoordinatesResponse, p as AIElementLocatorResponse, r as AIElementResponse, m as AIResponseFormat, t as AISectionLocatorResponse, n as AISingleElementResponseById, o as AISingleElementResponseByPosition, l as AIUsageInfo, V as AgentAssertOpt, x as AgentDescribeElementAtPointResult, T as AgentWaitForOpt, a6 as BaseAgentParserOpt, C as CallAIFn, a5 as Color, G as DumpMeta, O as ElementById, k as ElementTreeNode, y as EnsureObject, a9 as ExecutionRecorderItem, ar as ExecutionTaskAction, aq as ExecutionTaskActionApply, ap as ExecutionTaskInsightAssertion, ao as ExecutionTaskInsightAssertionApply, an as ExecutionTaskInsightAssertionParam, ag as ExecutionTaskInsightDumpLog, ai as ExecutionTaskInsightLocate, ah as ExecutionTaskInsightLocateApply, af as ExecutionTaskInsightLocateOutput, ae as ExecutionTaskInsightLocateParam, am as ExecutionTaskInsightQuery, al as ExecutionTaskInsightQueryApply, ak as ExecutionTaskInsightQueryOutput, aj as ExecutionTaskInsightQueryParam, at as ExecutionTaskPlanning, as as ExecutionTaskPlanningApply, ad as ExecutionTaskReturn, aa as ExecutionTaskType, ab as ExecutorContext, aR as FreeFn, au as GroupedActionDump, J as InsightDump, z as InsightExtractParam, N as LiteUISection, aw as LocateOption, F as LocateResultElement, w as LocateValidatorResult, v as LocatorValidatorOption, j as MidsceneYamlFlowItem, aC as MidsceneYamlFlowItemAIAction, aD as MidsceneYamlFlowItemAIAssert, aH as MidsceneYamlFlowItemAIBoolean, aL as MidsceneYamlFlowItemAIHover, aM as MidsceneYamlFlowItemAIInput, aN as MidsceneYamlFlowItemAIKeyboardPress, aI as MidsceneYamlFlowItemAILocate, aG as MidsceneYamlFlowItemAINString, aF as MidsceneYamlFlowItemAINumber, aE as MidsceneYamlFlowItemAIQuery, aO as MidsceneYamlFlowItemAIScroll, aK as MidsceneYamlFlowItemAITap, aJ as MidsceneYamlFlowItemAIWaitFor, aP as MidsceneYamlFlowItemEvaluateJavaScript, aQ as MidsceneYamlFlowItemSleep, M as MidsceneYamlScript, aA as MidsceneYamlScriptAndroidEnv, aB as MidsceneYamlScriptEnv, ay as MidsceneYamlScriptEnvBase, az as MidsceneYamlScriptWebEnv, i as MidsceneYamlTask, Q as OnTaskStartTip, av as PageType, K as PartialInsightDumpFromSDK, Y as PlanningAIResponse, X as PlanningAction, a1 as PlanningActionParamAssert, a3 as PlanningActionParamError, _ as PlanningActionParamHover, $ as PlanningActionParamInputOrKeyPress, a0 as PlanningActionParamScroll, a2 as PlanningActionParamSleep, Z as PlanningActionParamTap, a4 as PlanningActionParamWaitFor, W as PlanningLocateParam, a8 as PlaywrightParserOpt, P as Point, a7 as PuppeteerParserOpt, H as ReportDumpWithAttributes, aT as ScriptPlayerStatusValue, aS as ScriptPlayerTaskStatus, S as Size, ac as TaskCacheInfo, ax as scrollParam } from './types-88f46e9e.js';
3
- import { c as callAiFn } from './llm-planning-28e999f3.js';
4
- export { a as AiAssert, A as AiLocateElement, d as describeUserPage, p as plan } from './llm-planning-28e999f3.js';
1
+ import { E as ExecutionTask, a as ExecutionTaskProgressOptions, b as ExecutionTaskApply, c as ExecutionDump, B as BaseElement, U as UIContext, I as InsightAction, D as DumpSubscriber, d as InsightTaskInfo, e as InsightOptions, f as DetailedLocateParam, L as LocateResult, g as InsightAssertionResponse, A as AISingleElementResponse } from './types-8c83481c.js';
2
+ export { t as AIAssertionResponse, r as AIDataExtractionResponse, p as AIElementCoordinatesResponse, o as AIElementLocatorResponse, q as AIElementResponse, l as AIResponseFormat, s as AISectionLocatorResponse, m as AISingleElementResponseById, n as AISingleElementResponseByPosition, k as AIUsageInfo, K as AgentAssertOpt, J as AgentWaitForOpt, a2 as BaseAgentParserOpt, C as CallAIFn, a1 as Color, x as DumpMeta, H as ElementById, j as ElementTreeNode, u as EnsureObject, a5 as ExecutionRecorderItem, an as ExecutionTaskAction, am as ExecutionTaskActionApply, al as ExecutionTaskInsightAssertion, ak as ExecutionTaskInsightAssertionApply, aj as ExecutionTaskInsightAssertionParam, ac as ExecutionTaskInsightDumpLog, ae as ExecutionTaskInsightLocate, ad as ExecutionTaskInsightLocateApply, ab as ExecutionTaskInsightLocateOutput, aa as ExecutionTaskInsightLocateParam, ai as ExecutionTaskInsightQuery, ah as ExecutionTaskInsightQueryApply, ag as ExecutionTaskInsightQueryOutput, af as ExecutionTaskInsightQueryParam, ap as ExecutionTaskPlanning, ao as ExecutionTaskPlanningApply, a9 as ExecutionTaskReturn, a6 as ExecutionTaskType, a7 as ExecutorContext, aN as FreeFn, aq as GroupedActionDump, z as InsightDump, v as InsightExtractParam, G as LiteUISection, as as LocateOption, w as LocateResultElement, i as MidsceneYamlFlowItem, ay as MidsceneYamlFlowItemAIAction, az as MidsceneYamlFlowItemAIAssert, aD as MidsceneYamlFlowItemAIBoolean, aH as MidsceneYamlFlowItemAIHover, aI as MidsceneYamlFlowItemAIInput, aJ as MidsceneYamlFlowItemAIKeyboardPress, aE as MidsceneYamlFlowItemAILocate, aC as MidsceneYamlFlowItemAINString, aB as MidsceneYamlFlowItemAINumber, aA as MidsceneYamlFlowItemAIQuery, aK as MidsceneYamlFlowItemAIScroll, aG as MidsceneYamlFlowItemAITap, aF as MidsceneYamlFlowItemAIWaitFor, aL as MidsceneYamlFlowItemEvaluateJavaScript, aM as MidsceneYamlFlowItemSleep, M as MidsceneYamlScript, aw as MidsceneYamlScriptAndroidEnv, ax as MidsceneYamlScriptEnv, au as MidsceneYamlScriptEnvBase, av as MidsceneYamlScriptWebEnv, h as MidsceneYamlTask, O as OnTaskStartTip, ar as PageType, F as PartialInsightDumpFromSDK, T as PlanningAIResponse, Q as PlanningAction, Z as PlanningActionParamAssert, $ as PlanningActionParamError, W as PlanningActionParamHover, X as PlanningActionParamInputOrKeyPress, Y as PlanningActionParamScroll, _ as PlanningActionParamSleep, V as PlanningActionParamTap, a0 as PlanningActionParamWaitFor, N as PlanningLocateParam, a4 as PlaywrightParserOpt, P as Point, a3 as PuppeteerParserOpt, R as Rect, y as ReportDumpWithAttributes, aP as ScriptPlayerStatusValue, aO as ScriptPlayerTaskStatus, S as Size, a8 as TaskCacheInfo, at as scrollParam } from './types-8c83481c.js';
3
+ import { c as callAiFn } from './llm-planning-e16d1814.js';
4
+ export { a as AiAssert, A as AiLocateElement, d as describeUserPage, p as plan } from './llm-planning-e16d1814.js';
5
5
  export { getVersion } from './utils.js';
6
6
  export { MIDSCENE_MODEL_NAME, getAIConfig } from '@midscene/shared/env';
7
7
  import '@midscene/shared/constants';
@@ -38,9 +38,6 @@ declare class Insight<ElementType extends BaseElement = BaseElement, ContextType
38
38
  extract<T extends Record<string, string>>(input: T): Promise<Record<keyof T, any>>;
39
39
  extract<T extends object>(input: Record<keyof T, string>): Promise<T>;
40
40
  assert(assertion: string): Promise<InsightAssertionResponse>;
41
- describe(target: Rect | [number, number], opt?: {
42
- deepThink?: boolean;
43
- }): Promise<Pick<AIDescribeElementResponse, 'description'>>;
44
41
  }
45
42
 
46
- export { AIDescribeElementResponse, AISingleElementResponse, BaseElement, DetailedLocateParam, DumpSubscriber, ExecutionDump, ExecutionTask, ExecutionTaskApply, ExecutionTaskProgressOptions, Executor, Insight, InsightAction, InsightAssertionResponse, InsightOptions, InsightTaskInfo, LocateResult, Rect, UIContext, Insight as default };
43
+ export { AISingleElementResponse, BaseElement, DetailedLocateParam, DumpSubscriber, ExecutionDump, ExecutionTask, ExecutionTaskApply, ExecutionTaskProgressOptions, Executor, Insight, InsightAction, InsightAssertionResponse, InsightOptions, InsightTaskInfo, LocateResult, UIContext, Insight as default };
@@ -1,4 +1,4 @@
1
- import { l as AIUsageInfo, R as Rect, B as BaseElement, U as UIContext, h as AISingleElementResponse, o as AISingleElementResponseByPosition, p as AIElementLocatorResponse, O as ElementById, s as AIDataExtractionResponse, u as AIAssertionResponse, av as PageType, Y as PlanningAIResponse } from './types-88f46e9e.js';
1
+ import { k as AIUsageInfo, R as Rect, B as BaseElement, U as UIContext, A as AISingleElementResponse, n as AISingleElementResponseByPosition, o as AIElementLocatorResponse, H as ElementById, r as AIDataExtractionResponse, t as AIAssertionResponse, ar as PageType, T as PlanningAIResponse } from './types-8c83481c.js';
2
2
  import { ChatCompletionSystemMessageParam, ChatCompletionUserMessageParam } from 'openai/resources';
3
3
 
4
4
  type AIArgs = [
@@ -9,8 +9,7 @@ declare enum AIActionType {
9
9
  ASSERT = 0,
10
10
  INSPECT_ELEMENT = 1,
11
11
  EXTRACT_DATA = 2,
12
- PLAN = 3,
13
- DESCRIBE_ELEMENT = 4
12
+ PLAN = 3
14
13
  }
15
14
  declare function callAiFn<T>(msgs: AIArgs, AIActionTypeValue: AIActionType): Promise<{
16
15
  content: T;
@@ -1,5 +1,5 @@
1
1
  import * as _midscene_shared_constants from '@midscene/shared/constants';
2
- import { B as BaseElement, k as ElementTreeNode } from './types-88f46e9e.js';
2
+ import { B as BaseElement, j as ElementTreeNode } from './types-8c83481c.js';
3
3
  import 'openai/resources';
4
4
 
5
5
  declare function truncateText(text: string | number | object | undefined, maxLength?: number): string;