@midscene/core 0.16.11-beta-20250513053735.0 → 0.16.11-beta-20250514094019.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.
Files changed (37) hide show
  1. package/dist/es/ai-model.d.ts +3 -3
  2. package/dist/es/ai-model.js +1 -3
  3. package/dist/es/{chunk-35CPO7N5.js → chunk-FYD4T7QD.js} +4 -8
  4. package/dist/es/chunk-FYD4T7QD.js.map +1 -0
  5. package/dist/es/{chunk-RB3UVNFX.js → chunk-XOXA3GER.js} +3 -3
  6. package/dist/es/index.d.ts +4 -4
  7. package/dist/es/index.js +4 -6
  8. package/dist/es/index.js.map +1 -1
  9. package/dist/es/{llm-planning-0867ed8d.d.ts → llm-planning-e16d1814.d.ts} +2 -6
  10. package/dist/es/tree.d.ts +1 -1
  11. package/dist/es/{types-81664b3b.d.ts → types-8c83481c.d.ts} +0 -8
  12. package/dist/es/utils.d.ts +1 -1
  13. package/dist/es/utils.js +1 -1
  14. package/dist/lib/ai-model.d.ts +3 -3
  15. package/dist/lib/ai-model.js +2 -4
  16. package/dist/lib/{chunk-35CPO7N5.js → chunk-FYD4T7QD.js} +5 -9
  17. package/dist/lib/chunk-FYD4T7QD.js.map +1 -0
  18. package/dist/lib/{chunk-RB3UVNFX.js → chunk-XOXA3GER.js} +3 -3
  19. package/dist/lib/index.d.ts +4 -4
  20. package/dist/lib/index.js +13 -15
  21. package/dist/lib/index.js.map +1 -1
  22. package/dist/lib/{llm-planning-0867ed8d.d.ts → llm-planning-e16d1814.d.ts} +2 -6
  23. package/dist/lib/tree.d.ts +1 -1
  24. package/dist/{types/types-81664b3b.d.ts → lib/types-8c83481c.d.ts} +0 -8
  25. package/dist/lib/utils.d.ts +1 -1
  26. package/dist/lib/utils.js +2 -2
  27. package/dist/types/ai-model.d.ts +3 -3
  28. package/dist/types/index.d.ts +4 -4
  29. package/dist/types/{llm-planning-0867ed8d.d.ts → llm-planning-e16d1814.d.ts} +2 -6
  30. package/dist/types/tree.d.ts +1 -1
  31. package/dist/{lib/types-81664b3b.d.ts → types/types-8c83481c.d.ts} +0 -8
  32. package/dist/types/utils.d.ts +1 -1
  33. package/package.json +2 -2
  34. package/dist/es/chunk-35CPO7N5.js.map +0 -1
  35. package/dist/lib/chunk-35CPO7N5.js.map +0 -1
  36. /package/dist/es/{chunk-RB3UVNFX.js.map → chunk-XOXA3GER.js.map} +0 -0
  37. /package/dist/lib/{chunk-RB3UVNFX.js.map → chunk-XOXA3GER.js.map} +0 -0
@@ -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, A as AISingleElementResponse } from './types-81664b3b.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-81664b3b.js';
3
- import { c as callAiFn } from './llm-planning-0867ed8d.js';
4
- export { a as AiAssert, A as AiLocateElement, d as describeUserPage, p as plan } from './llm-planning-0867ed8d.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';
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 _chunkRB3UVNFXjs = require('./chunk-RB3UVNFX.js');
3
+ var _chunkXOXA3GERjs = require('./chunk-XOXA3GER.js');
4
4
 
5
5
 
6
6
 
@@ -9,7 +9,7 @@ var _chunkRB3UVNFXjs = require('./chunk-RB3UVNFX.js');
9
9
 
10
10
 
11
11
 
12
- var _chunk35CPO7N5js = require('./chunk-35CPO7N5.js');
12
+ var _chunkFYD4T7QDjs = require('./chunk-FYD4T7QD.js');
13
13
 
14
14
  // src/ai-model/action-executor.ts
15
15
  var _env = require('@midscene/shared/env');
@@ -156,7 +156,7 @@ ${_optionalChain([this, 'access', _7 => _7.latestErrorTask, 'call', _8 => _8(),
156
156
  }
157
157
  dump() {
158
158
  const dumpData = {
159
- sdkVersion: _chunkRB3UVNFXjs.getVersion.call(void 0, ),
159
+ sdkVersion: _chunkXOXA3GERjs.getVersion.call(void 0, ),
160
160
  model_name: _env.getAIConfig.call(void 0, _env.MIDSCENE_MODEL_NAME) || "",
161
161
  logTime: Date.now(),
162
162
  name: this.name,
@@ -194,7 +194,7 @@ function emitInsightDump(data, dumpSubscriber) {
194
194
  }
195
195
  }
196
196
  const baseData = {
197
- sdkVersion: _chunkRB3UVNFXjs.getVersion.call(void 0, ),
197
+ sdkVersion: _chunkXOXA3GERjs.getVersion.call(void 0, ),
198
198
  logTime: Date.now(),
199
199
  model_name: _env.getAIConfig.call(void 0, _env.MIDSCENE_MODEL_NAME) || "",
200
200
  model_description: modelDescription
@@ -211,7 +211,7 @@ function emitInsightDump(data, dumpSubscriber) {
211
211
  var debug = _logger.getDebug.call(void 0, "ai:insight");
212
212
  var Insight = class {
213
213
  constructor(context, opt) {
214
- this.aiVendorFn = _chunk35CPO7N5js.callAiFn;
214
+ this.aiVendorFn = _chunkFYD4T7QDjs.callAiFn;
215
215
  _utils.assert.call(void 0, context, "context is required for Insight");
216
216
  if (typeof context === "function") {
217
217
  this.contextRetrieverFn = context;
@@ -257,7 +257,7 @@ var Insight = class {
257
257
  let searchAreaUsage = void 0;
258
258
  let searchAreaResponse = void 0;
259
259
  if (searchAreaPrompt) {
260
- searchAreaResponse = await _chunk35CPO7N5js.AiLocateSection.call(void 0, {
260
+ searchAreaResponse = await _chunkFYD4T7QDjs.AiLocateSection.call(void 0, {
261
261
  context,
262
262
  sectionDescription: searchAreaPrompt
263
263
  });
@@ -270,7 +270,7 @@ var Insight = class {
270
270
  searchArea = searchAreaResponse.rect;
271
271
  }
272
272
  const startTime = Date.now();
273
- const { parseResult, rect, elementById, rawResponse, usage } = await _chunk35CPO7N5js.AiLocateElement.call(void 0, {
273
+ const { parseResult, rect, elementById, rawResponse, usage } = await _chunkFYD4T7QDjs.AiLocateElement.call(void 0, {
274
274
  callAI: callAI || this.aiVendorFn,
275
275
  context,
276
276
  targetElementDescription: queryPrompt,
@@ -309,7 +309,7 @@ ${parseResult.errors.join("\n")}`;
309
309
  const elements = [];
310
310
  (parseResult.elements || []).forEach((item) => {
311
311
  if ("id" in item) {
312
- const element = elementById(_optionalChain([item, 'optionalAccess', _22 => _22.id]));
312
+ const element = elementById(item.id);
313
313
  if (!element) {
314
314
  console.warn(
315
315
  `locate: cannot find element id=${item.id}. Maybe an unstable response from AI model`
@@ -339,9 +339,7 @@ ${parseResult.errors.join("\n")}`;
339
339
  id: elements[0].id,
340
340
  indexId: elements[0].indexId,
341
341
  center: elements[0].center,
342
- rect: elements[0].rect,
343
- xpaths: elements[0].xpaths || [],
344
- attributes: elements[0].attributes
342
+ rect: elements[0].rect
345
343
  },
346
344
  rect
347
345
  };
@@ -360,7 +358,7 @@ ${parseResult.errors.join("\n")}`;
360
358
  this.onceDumpUpdatedFn = void 0;
361
359
  const context = await this.contextRetrieverFn("extract");
362
360
  const startTime = Date.now();
363
- const { parseResult, usage } = await _chunk35CPO7N5js.AiExtractElementInfo.call(void 0, {
361
+ const { parseResult, usage } = await _chunkFYD4T7QDjs.AiExtractElementInfo.call(void 0, {
364
362
  context,
365
363
  dataQuery: dataDemand
366
364
  });
@@ -371,7 +369,7 @@ ${parseResult.errors.join("\n")}`;
371
369
  rawResponse: JSON.stringify(parseResult)
372
370
  };
373
371
  let errorLog;
374
- if (_optionalChain([parseResult, 'access', _23 => _23.errors, 'optionalAccess', _24 => _24.length])) {
372
+ if (_optionalChain([parseResult, 'access', _22 => _22.errors, 'optionalAccess', _23 => _23.length])) {
375
373
  errorLog = `AI response error:
376
374
  ${parseResult.errors.join("\n")}`;
377
375
  }
@@ -411,7 +409,7 @@ ${parseResult.errors.join("\n")}`;
411
409
  this.onceDumpUpdatedFn = void 0;
412
410
  const context = await this.contextRetrieverFn("assert");
413
411
  const startTime = Date.now();
414
- const assertResult = await _chunk35CPO7N5js.AiAssert.call(void 0, {
412
+ const assertResult = await _chunkFYD4T7QDjs.AiAssert.call(void 0, {
415
413
  assertion,
416
414
  context
417
415
  });
@@ -457,6 +455,6 @@ var src_default = Insight;
457
455
 
458
456
 
459
457
 
460
- exports.AiAssert = _chunk35CPO7N5js.AiAssert; exports.AiLocateElement = _chunk35CPO7N5js.AiLocateElement; exports.Executor = Executor; exports.Insight = Insight; exports.MIDSCENE_MODEL_NAME = _env.MIDSCENE_MODEL_NAME; exports.default = src_default; exports.describeUserPage = _chunk35CPO7N5js.describeUserPage; exports.getAIConfig = _env.getAIConfig; exports.getVersion = _chunkRB3UVNFXjs.getVersion; exports.plan = _chunk35CPO7N5js.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 = _chunkXOXA3GERjs.getVersion; exports.plan = _chunkFYD4T7QDjs.plan;
461
459
 
462
460
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"mappings":";;;;;;;;;;;;;;AAUA,SAAS,qBAAqB,mBAAmB;AACjD,SAAS,cAAc;AAEhB,IAAM,WAAN,MAAe;AAAA,EAUpB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ACjE,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;;;AEnUA,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 xpaths: elements[0]!.xpaths || [],\n attributes: elements[0]!.attributes,\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
+ {"version":3,"mappings":";;;;;;;;;;;;;;AAUA,SAAS,qBAAqB,mBAAmB;AACjD,SAAS,cAAc;AAEhB,IAAM,WAAN,MAAe;AAAA,EAUpB,YACE,MACA,SAGA;AACA,SAAK,SACH,SAAS,SAAS,QAA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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 { k as AIUsageInfo, R as Rect, j as ElementTreeNode, 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-81664b3b.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 = [
@@ -17,10 +17,6 @@ declare function callAiFn<T>(msgs: AIArgs, AIActionTypeValue: AIActionType): Pro
17
17
  }>;
18
18
  declare function adaptBboxToRect(bbox: number[], width: number, height: number, offsetX?: number, offsetY?: number): Rect;
19
19
 
20
- declare function elementByPositionWithElementInfo(treeRoot: ElementTreeNode<BaseElement>, position: {
21
- x: number;
22
- y: number;
23
- }, strict?: boolean): BaseElement | undefined;
24
20
  declare function describeUserPage<ElementType extends BaseElement = BaseElement>(context: Omit<UIContext<ElementType>, 'describer'>, opt?: {
25
21
  truncateTextLength?: number;
26
22
  filterNonTextContent?: boolean;
@@ -92,4 +88,4 @@ declare function plan(userInstruction: string, opts: {
92
88
  actionContext?: string;
93
89
  }): Promise<PlanningAIResponse>;
94
90
 
95
- export { AiLocateElement as A, AiAssert as a, AIActionType as b, callAiFn as c, describeUserPage as d, elementByPositionWithElementInfo as e, AiExtractElementInfo as f, AiLocateSection as g, adaptBboxToRect as h, plan as p };
91
+ export { AiLocateElement as A, AiAssert as a, AIActionType as b, callAiFn as c, describeUserPage as d, AiExtractElementInfo as e, AiLocateSection as f, adaptBboxToRect as g, plan as p };
@@ -1,5 +1,5 @@
1
1
  import * as _midscene_shared_constants from '@midscene/shared/constants';
2
- import { B as BaseElement, j as ElementTreeNode } from './types-81664b3b.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;
@@ -143,7 +143,6 @@ declare abstract class BaseElement {
143
143
  abstract rect: Rect;
144
144
  abstract center: [number, number];
145
145
  abstract locator?: string;
146
- abstract xpaths?: string[];
147
146
  }
148
147
  interface ElementTreeNode<ElementType extends BaseElement = BaseElement> {
149
148
  node: ElementType | null;
@@ -166,7 +165,6 @@ type AISingleElementResponseById = {
166
165
  id: string;
167
166
  reason?: string;
168
167
  text?: string;
169
- xpaths?: string[];
170
168
  };
171
169
  type AISingleElementResponseByPosition = {
172
170
  position?: {
@@ -183,7 +181,6 @@ interface AIElementLocatorResponse {
183
181
  id: string;
184
182
  reason?: string;
185
183
  text?: string;
186
- xpaths?: string[];
187
184
  }[];
188
185
  bbox?: [number, number, number, number];
189
186
  errors?: string[];
@@ -233,11 +230,6 @@ type LocateResultElement = {
233
230
  indexId?: number;
234
231
  center: [number, number];
235
232
  rect: Rect;
236
- xpaths: string[];
237
- attributes: {
238
- nodeType: NodeType;
239
- [key: string]: string;
240
- };
241
233
  };
242
234
  interface LocateResult {
243
235
  element: LocateResultElement | null;
@@ -1,4 +1,4 @@
1
- import { y as ReportDumpWithAttributes, R as Rect } from './types-81664b3b.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
 
package/dist/lib/utils.js CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
 
15
15
 
16
- var _chunkRB3UVNFXjs = require('./chunk-RB3UVNFX.js');
16
+ var _chunkXOXA3GERjs = require('./chunk-XOXA3GER.js');
17
17
 
18
18
 
19
19
 
@@ -29,4 +29,4 @@ var _chunkRB3UVNFXjs = require('./chunk-RB3UVNFX.js');
29
29
 
30
30
 
31
31
 
32
- exports.getLogDir = _chunkRB3UVNFXjs.getLogDir; exports.getTmpDir = _chunkRB3UVNFXjs.getTmpDir; exports.getTmpFile = _chunkRB3UVNFXjs.getTmpFile; exports.getVersion = _chunkRB3UVNFXjs.getVersion; exports.groupedActionDumpFileExt = _chunkRB3UVNFXjs.groupedActionDumpFileExt; exports.overlapped = _chunkRB3UVNFXjs.overlapped; exports.replaceStringWithFirstAppearance = _chunkRB3UVNFXjs.replaceStringWithFirstAppearance; exports.replacerForPageObject = _chunkRB3UVNFXjs.replacerForPageObject; exports.reportHTMLContent = _chunkRB3UVNFXjs.reportHTMLContent; exports.sleep = _chunkRB3UVNFXjs.sleep; exports.stringifyDumpData = _chunkRB3UVNFXjs.stringifyDumpData; exports.uploadTestInfoToServer = _chunkRB3UVNFXjs.uploadTestInfoToServer; exports.writeDumpReport = _chunkRB3UVNFXjs.writeDumpReport; exports.writeLogFile = _chunkRB3UVNFXjs.writeLogFile;
32
+ exports.getLogDir = _chunkXOXA3GERjs.getLogDir; exports.getTmpDir = _chunkXOXA3GERjs.getTmpDir; exports.getTmpFile = _chunkXOXA3GERjs.getTmpFile; exports.getVersion = _chunkXOXA3GERjs.getVersion; exports.groupedActionDumpFileExt = _chunkXOXA3GERjs.groupedActionDumpFileExt; exports.overlapped = _chunkXOXA3GERjs.overlapped; exports.replaceStringWithFirstAppearance = _chunkXOXA3GERjs.replaceStringWithFirstAppearance; exports.replacerForPageObject = _chunkXOXA3GERjs.replacerForPageObject; exports.reportHTMLContent = _chunkXOXA3GERjs.reportHTMLContent; exports.sleep = _chunkXOXA3GERjs.sleep; exports.stringifyDumpData = _chunkXOXA3GERjs.stringifyDumpData; exports.uploadTestInfoToServer = _chunkXOXA3GERjs.uploadTestInfoToServer; exports.writeDumpReport = _chunkXOXA3GERjs.writeDumpReport; exports.writeLogFile = _chunkXOXA3GERjs.writeLogFile;
@@ -1,8 +1,8 @@
1
- import { k as AIUsageInfo, Q as PlanningAction } from './types-81664b3b.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-0867ed8d.js';
5
- export { a as AiAssert, f as AiExtractElementInfo, A as AiLocateElement, g as AiLocateSection, h as adaptBboxToRect, c as callAiFn, d as describeUserPage, e as elementByPositionWithElementInfo, p as plan } from './llm-planning-0867ed8d.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, A as AISingleElementResponse } from './types-81664b3b.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-81664b3b.js';
3
- import { c as callAiFn } from './llm-planning-0867ed8d.js';
4
- export { a as AiAssert, A as AiLocateElement, d as describeUserPage, p as plan } from './llm-planning-0867ed8d.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';
@@ -1,4 +1,4 @@
1
- import { k as AIUsageInfo, R as Rect, j as ElementTreeNode, 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-81664b3b.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 = [
@@ -17,10 +17,6 @@ declare function callAiFn<T>(msgs: AIArgs, AIActionTypeValue: AIActionType): Pro
17
17
  }>;
18
18
  declare function adaptBboxToRect(bbox: number[], width: number, height: number, offsetX?: number, offsetY?: number): Rect;
19
19
 
20
- declare function elementByPositionWithElementInfo(treeRoot: ElementTreeNode<BaseElement>, position: {
21
- x: number;
22
- y: number;
23
- }, strict?: boolean): BaseElement | undefined;
24
20
  declare function describeUserPage<ElementType extends BaseElement = BaseElement>(context: Omit<UIContext<ElementType>, 'describer'>, opt?: {
25
21
  truncateTextLength?: number;
26
22
  filterNonTextContent?: boolean;
@@ -92,4 +88,4 @@ declare function plan(userInstruction: string, opts: {
92
88
  actionContext?: string;
93
89
  }): Promise<PlanningAIResponse>;
94
90
 
95
- export { AiLocateElement as A, AiAssert as a, AIActionType as b, callAiFn as c, describeUserPage as d, elementByPositionWithElementInfo as e, AiExtractElementInfo as f, AiLocateSection as g, adaptBboxToRect as h, plan as p };
91
+ export { AiLocateElement as A, AiAssert as a, AIActionType as b, callAiFn as c, describeUserPage as d, AiExtractElementInfo as e, AiLocateSection as f, adaptBboxToRect as g, plan as p };
@@ -1,5 +1,5 @@
1
1
  import * as _midscene_shared_constants from '@midscene/shared/constants';
2
- import { B as BaseElement, j as ElementTreeNode } from './types-81664b3b.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;
@@ -143,7 +143,6 @@ declare abstract class BaseElement {
143
143
  abstract rect: Rect;
144
144
  abstract center: [number, number];
145
145
  abstract locator?: string;
146
- abstract xpaths?: string[];
147
146
  }
148
147
  interface ElementTreeNode<ElementType extends BaseElement = BaseElement> {
149
148
  node: ElementType | null;
@@ -166,7 +165,6 @@ type AISingleElementResponseById = {
166
165
  id: string;
167
166
  reason?: string;
168
167
  text?: string;
169
- xpaths?: string[];
170
168
  };
171
169
  type AISingleElementResponseByPosition = {
172
170
  position?: {
@@ -183,7 +181,6 @@ interface AIElementLocatorResponse {
183
181
  id: string;
184
182
  reason?: string;
185
183
  text?: string;
186
- xpaths?: string[];
187
184
  }[];
188
185
  bbox?: [number, number, number, number];
189
186
  errors?: string[];
@@ -233,11 +230,6 @@ type LocateResultElement = {
233
230
  indexId?: number;
234
231
  center: [number, number];
235
232
  rect: Rect;
236
- xpaths: string[];
237
- attributes: {
238
- nodeType: NodeType;
239
- [key: string]: string;
240
- };
241
233
  };
242
234
  interface LocateResult {
243
235
  element: LocateResultElement | null;
@@ -1,4 +1,4 @@
1
- import { y as ReportDumpWithAttributes, R as Rect } from './types-81664b3b.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
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@midscene/core",
3
3
  "description": "Automate browser actions, extract data, and perform assertions using AI. It offers JavaScript SDK, Chrome extension, and support for scripting in YAML. See https://midscenejs.com/ for details.",
4
- "version": "0.16.11-beta-20250513053735.0",
4
+ "version": "0.16.11-beta-20250514094019.0",
5
5
  "repository": "https://github.com/web-infra-dev/midscene",
6
6
  "homepage": "https://midscenejs.com/",
7
7
  "jsnext:source": "./src/index.ts",
@@ -44,7 +44,7 @@
44
44
  "langsmith": "0.3.7",
45
45
  "openai": "4.81.0",
46
46
  "socks-proxy-agent": "8.0.4",
47
- "@midscene/shared": "0.16.11-beta-20250513053735.0"
47
+ "@midscene/shared": "0.16.11-beta-20250514094019.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@modern-js/module-tools": "2.60.6",