@midscene/core 1.0.1-beta-20251021060907.0 → 1.0.1-beta-20251022061922.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 (44) hide show
  1. package/dist/es/agent/agent.mjs.map +1 -1
  2. package/dist/es/agent/execution-session.mjs.map +1 -1
  3. package/dist/es/agent/task-builder.mjs +258 -246
  4. package/dist/es/agent/task-builder.mjs.map +1 -1
  5. package/dist/es/agent/tasks.mjs +17 -19
  6. package/dist/es/agent/tasks.mjs.map +1 -1
  7. package/dist/es/agent/utils.mjs +1 -1
  8. package/dist/es/ai-model/llm-planning.mjs +5 -6
  9. package/dist/es/ai-model/llm-planning.mjs.map +1 -1
  10. package/dist/es/ai-model/prompt/llm-planning.mjs +15 -0
  11. package/dist/es/ai-model/prompt/llm-planning.mjs.map +1 -1
  12. package/dist/es/index.mjs +1 -1
  13. package/dist/es/index.mjs.map +1 -1
  14. package/dist/es/task-runner.mjs +13 -1
  15. package/dist/es/task-runner.mjs.map +1 -1
  16. package/dist/es/types.mjs.map +1 -1
  17. package/dist/es/utils.mjs +2 -2
  18. package/dist/es/yaml/player.mjs.map +1 -1
  19. package/dist/lib/agent/agent.js.map +1 -1
  20. package/dist/lib/agent/execution-session.js.map +1 -1
  21. package/dist/lib/agent/task-builder.js +258 -246
  22. package/dist/lib/agent/task-builder.js.map +1 -1
  23. package/dist/lib/agent/tasks.js +17 -19
  24. package/dist/lib/agent/tasks.js.map +1 -1
  25. package/dist/lib/agent/utils.js +1 -1
  26. package/dist/lib/ai-model/llm-planning.js +5 -6
  27. package/dist/lib/ai-model/llm-planning.js.map +1 -1
  28. package/dist/lib/ai-model/prompt/llm-planning.js +15 -0
  29. package/dist/lib/ai-model/prompt/llm-planning.js.map +1 -1
  30. package/dist/lib/index.js +1 -1
  31. package/dist/lib/index.js.map +1 -1
  32. package/dist/lib/task-runner.js +13 -1
  33. package/dist/lib/task-runner.js.map +1 -1
  34. package/dist/lib/types.js.map +1 -1
  35. package/dist/lib/utils.js +2 -2
  36. package/dist/lib/yaml/player.js.map +1 -1
  37. package/dist/types/agent/task-builder.d.ts +11 -1
  38. package/dist/types/agent/tasks.d.ts +8 -4
  39. package/dist/types/agent/utils.d.ts +1 -0
  40. package/dist/types/device/index.d.ts +20 -20
  41. package/dist/types/index.d.ts +1 -1
  42. package/dist/types/task-runner.d.ts +1 -0
  43. package/dist/types/types.d.ts +6 -10
  44. package/package.json +3 -3
@@ -1,8 +1,8 @@
1
+ import { findAllMidsceneLocatorField, parseActionParam } from "../ai-model/index.mjs";
1
2
  import { InsightError } from "../types.mjs";
2
3
  import { sleep } from "../utils.mjs";
3
4
  import { getDebug } from "@midscene/shared/logger";
4
5
  import { assert } from "@midscene/shared/utils";
5
- import { findAllMidsceneLocatorField, parseActionParam } from "../ai-model/index.mjs";
6
6
  import { matchElementFromCache, matchElementFromPlan } from "./utils.mjs";
7
7
  function _define_property(obj, key, value) {
8
8
  if (key in obj) Object.defineProperty(obj, key, {
@@ -31,263 +31,275 @@ class TaskBuilder {
31
31
  async build(plans, modelConfig, options) {
32
32
  const tasks = [];
33
33
  const cacheable = null == options ? void 0 : options.cacheable;
34
- const taskForLocatePlan = (plan, detailedLocateParam, onResult)=>{
35
- if ('string' == typeof detailedLocateParam) detailedLocateParam = {
36
- prompt: detailedLocateParam
37
- };
38
- if (void 0 !== cacheable) detailedLocateParam = {
39
- ...detailedLocateParam,
40
- cacheable
41
- };
42
- const taskFind = {
43
- type: 'Insight',
44
- subType: 'Locate',
45
- param: detailedLocateParam,
46
- thought: plan.thought,
47
- executor: async (param, taskContext)=>{
48
- var _this_taskCache, _locateCacheRecord_cacheContent;
49
- const { task } = taskContext;
50
- let { uiContext } = taskContext;
51
- assert((null == param ? void 0 : param.prompt) || (null == param ? void 0 : param.id) || (null == param ? void 0 : param.bbox), `No prompt or id or position or bbox to locate, param=${JSON.stringify(param)}`);
52
- if (!uiContext) uiContext = await this.insight.contextRetrieverFn();
53
- assert(uiContext, 'uiContext is required for Insight task');
54
- let locateDump;
55
- let locateResult;
56
- const applyDump = (dump)=>{
57
- var _dump_taskInfo, _dump_taskInfo1;
58
- if (!dump) return;
59
- locateDump = dump;
60
- task.log = {
61
- dump
62
- };
63
- task.usage = null == (_dump_taskInfo = dump.taskInfo) ? void 0 : _dump_taskInfo.usage;
64
- if (null == (_dump_taskInfo1 = dump.taskInfo) ? void 0 : _dump_taskInfo1.searchAreaUsage) task.searchAreaUsage = dump.taskInfo.searchAreaUsage;
65
- };
66
- const elementFromXpath = param.xpath && this.interface.getElementInfoByXpath ? await this.interface.getElementInfoByXpath(param.xpath) : void 0;
67
- const userExpectedPathHitFlag = !!elementFromXpath;
68
- const cachePrompt = param.prompt;
69
- const locateCacheRecord = null == (_this_taskCache = this.taskCache) ? void 0 : _this_taskCache.matchLocateCache(cachePrompt);
70
- const cacheEntry = null == locateCacheRecord ? void 0 : null == (_locateCacheRecord_cacheContent = locateCacheRecord.cacheContent) ? void 0 : _locateCacheRecord_cacheContent.cache;
71
- const elementFromCache = userExpectedPathHitFlag ? null : await matchElementFromCache({
72
- taskCache: this.taskCache,
73
- interfaceInstance: this.interface
74
- }, cacheEntry, cachePrompt, param.cacheable);
75
- const cacheHitFlag = !!elementFromCache;
76
- const elementFromPlan = userExpectedPathHitFlag || cacheHitFlag ? void 0 : matchElementFromPlan(param, uiContext.tree);
77
- const planHitFlag = !!elementFromPlan;
78
- let elementFromAiLocate;
79
- if (!userExpectedPathHitFlag && !cacheHitFlag && !planHitFlag) try {
80
- locateResult = await this.insight.locate(param, {
81
- context: uiContext
82
- }, modelConfig);
83
- applyDump(locateResult.dump);
84
- elementFromAiLocate = locateResult.element;
85
- } catch (error) {
86
- if (error instanceof InsightError) applyDump(error.dump);
87
- throw error;
88
- }
89
- const aiLocateHitFlag = !!elementFromAiLocate;
90
- const element = elementFromXpath || elementFromCache || elementFromPlan || elementFromAiLocate;
91
- let currentCacheEntry;
92
- if (element && this.taskCache && !cacheHitFlag && (null == param ? void 0 : param.cacheable) !== false) if (this.interface.cacheFeatureForRect) try {
93
- const feature = await this.interface.cacheFeatureForRect(element.rect, void 0 !== element.isOrderSensitive ? {
94
- _orderSensitive: element.isOrderSensitive
95
- } : void 0);
96
- if (feature && Object.keys(feature).length > 0) {
97
- debug('update cache, prompt: %s, cache: %o', cachePrompt, feature);
98
- currentCacheEntry = feature;
99
- this.taskCache.updateOrAppendCacheRecord({
100
- type: 'locate',
101
- prompt: cachePrompt,
102
- cache: feature
103
- }, locateCacheRecord);
104
- } else debug('no cache data returned, skip cache update, prompt: %s', cachePrompt);
105
- } catch (error) {
106
- debug('cacheFeatureForRect failed: %s', error);
107
- }
108
- else debug('cacheFeatureForRect is not supported, skip cache update');
109
- if (!element) {
110
- if (locateDump) throw new InsightError(`Element not found: ${param.prompt}`, locateDump);
111
- throw new Error(`Element not found: ${param.prompt}`);
112
- }
113
- let hitBy;
114
- if (userExpectedPathHitFlag) hitBy = {
115
- from: 'User expected path',
116
- context: {
117
- xpath: param.xpath
118
- }
119
- };
120
- else if (cacheHitFlag) hitBy = {
121
- from: 'Cache',
122
- context: {
123
- cacheEntry,
124
- cacheToSave: currentCacheEntry
125
- }
126
- };
127
- else if (planHitFlag) hitBy = {
128
- from: 'Planning',
129
- context: {
130
- id: null == elementFromPlan ? void 0 : elementFromPlan.id,
131
- bbox: null == elementFromPlan ? void 0 : elementFromPlan.bbox
132
- }
133
- };
134
- else if (aiLocateHitFlag) hitBy = {
135
- from: 'AI model',
136
- context: {
137
- prompt: param.prompt
138
- }
139
- };
140
- null == onResult || onResult(element);
141
- return {
142
- output: {
143
- element
144
- },
145
- uiContext,
146
- hitBy
147
- };
148
- }
149
- };
150
- return taskFind;
34
+ const context = {
35
+ tasks,
36
+ modelConfig,
37
+ cacheable,
38
+ subTask: !!(null == options ? void 0 : options.subTask)
151
39
  };
40
+ const planHandlers = new Map([
41
+ [
42
+ 'Locate',
43
+ (plan)=>this.handleLocatePlan(plan, context)
44
+ ],
45
+ [
46
+ 'Finished',
47
+ (plan)=>this.handleFinishedPlan(plan, context)
48
+ ],
49
+ [
50
+ 'Sleep',
51
+ (plan)=>this.handleSleepPlan(plan, context)
52
+ ]
53
+ ]);
54
+ const defaultHandler = (plan)=>this.handleActionPlan(plan, context);
152
55
  for (const plan of plans){
153
- if ('Locate' === plan.type) {
154
- if (!plan.locate || null === plan.locate) {
155
- debug('Locate action with id is null, will be ignored', plan);
156
- continue;
157
- }
158
- const taskLocate = taskForLocatePlan(plan, plan.locate);
159
- tasks.push(taskLocate);
160
- continue;
161
- }
162
- if ('Error' === plan.type) {
163
- var _plan_param;
164
- const taskActionError = {
165
- type: 'Action',
166
- subType: 'Error',
167
- param: plan.param,
168
- thought: plan.thought || (null == (_plan_param = plan.param) ? void 0 : _plan_param.thought),
169
- locate: plan.locate,
170
- executor: async ()=>{
171
- var _plan_param;
172
- throw new Error((null == plan ? void 0 : plan.thought) || (null == (_plan_param = plan.param) ? void 0 : _plan_param.thought) || 'error without thought');
173
- }
174
- };
175
- tasks.push(taskActionError);
176
- continue;
177
- }
178
- if ('Finished' === plan.type) {
179
- const taskActionFinished = {
180
- type: 'Action',
181
- subType: 'Finished',
182
- param: null,
183
- thought: plan.thought,
184
- locate: plan.locate,
185
- executor: async ()=>{}
186
- };
187
- tasks.push(taskActionFinished);
188
- continue;
56
+ const handler = planHandlers.get(plan.type) ?? defaultHandler;
57
+ await handler(plan);
58
+ }
59
+ return {
60
+ tasks
61
+ };
62
+ }
63
+ handleFinishedPlan(plan, context) {
64
+ const taskActionFinished = {
65
+ type: 'Action',
66
+ subType: 'Finished',
67
+ param: null,
68
+ thought: plan.thought,
69
+ locate: plan.locate,
70
+ subTask: context.subTask || void 0,
71
+ executor: async ()=>{}
72
+ };
73
+ context.tasks.push(taskActionFinished);
74
+ }
75
+ handleSleepPlan(plan, context) {
76
+ const sleepTask = this.createSleepTask(plan.param, {
77
+ thought: plan.thought,
78
+ locate: plan.locate
79
+ });
80
+ if (context.subTask) sleepTask.subTask = true;
81
+ context.tasks.push(sleepTask);
82
+ }
83
+ createSleepTask(param, meta) {
84
+ return {
85
+ type: 'Action',
86
+ subType: 'Sleep',
87
+ param,
88
+ thought: null == meta ? void 0 : meta.thought,
89
+ locate: (null == meta ? void 0 : meta.locate) ?? null,
90
+ executor: async (taskParam)=>{
91
+ await sleep((null == taskParam ? void 0 : taskParam.timeMs) || 3000);
189
92
  }
190
- if ('Sleep' === plan.type) {
191
- const taskActionSleep = {
192
- type: 'Action',
193
- subType: 'Sleep',
194
- param: plan.param,
195
- thought: plan.thought,
196
- locate: plan.locate,
197
- executor: async (taskParam)=>{
198
- await sleep((null == taskParam ? void 0 : taskParam.timeMs) || 3000);
199
- }
200
- };
201
- tasks.push(taskActionSleep);
202
- continue;
93
+ };
94
+ }
95
+ async handleLocatePlan(plan, context) {
96
+ if (!plan.locate || null === plan.locate) return void debug('Locate action with id is null, will be ignored', plan);
97
+ const taskLocate = this.createLocateTask(plan, plan.locate, context);
98
+ context.tasks.push(taskLocate);
99
+ }
100
+ async handleActionPlan(plan, context) {
101
+ const planType = plan.type;
102
+ const actionSpace = await this.interface.actionSpace();
103
+ const action = actionSpace.find((item)=>item.name === planType);
104
+ const param = plan.param;
105
+ if (!action) throw new Error(`Action type '${planType}' not found`);
106
+ const locateFields = action ? findAllMidsceneLocatorField(action.paramSchema) : [];
107
+ const requiredLocateFields = action ? findAllMidsceneLocatorField(action.paramSchema, true) : [];
108
+ locateFields.forEach((field)=>{
109
+ if (param[field]) {
110
+ const locatePlan = locatePlanForLocate(param[field]);
111
+ debug('will prepend locate param for field', `action.type=${planType}`, `param=${JSON.stringify(param[field])}`, `locatePlan=${JSON.stringify(locatePlan)}`);
112
+ const locateTask = this.createLocateTask(locatePlan, param[field], context, (result)=>{
113
+ param[field] = result;
114
+ });
115
+ context.tasks.push(locateTask);
116
+ } else {
117
+ assert(!requiredLocateFields.includes(field), `Required locate field '${field}' is not provided for action ${planType}`);
118
+ debug(`field '${field}' is not provided for action ${planType}`);
203
119
  }
204
- const planType = plan.type;
205
- const actionSpace = await this.interface.actionSpace();
206
- const action = actionSpace.find((item)=>item.name === planType);
207
- const param = plan.param;
208
- if (!action) throw new Error(`Action type '${planType}' not found`);
209
- const locateFields = action ? findAllMidsceneLocatorField(action.paramSchema) : [];
210
- const requiredLocateFields = action ? findAllMidsceneLocatorField(action.paramSchema, true) : [];
211
- locateFields.forEach((field)=>{
212
- if (param[field]) {
213
- const locatePlan = locatePlanForLocate(param[field]);
214
- debug('will prepend locate param for field', `action.type=${planType}`, `param=${JSON.stringify(param[field])}`, `locatePlan=${JSON.stringify(locatePlan)}`);
215
- const locateTask = taskForLocatePlan(locatePlan, param[field], (result)=>{
216
- param[field] = result;
120
+ });
121
+ const task = {
122
+ type: 'Action',
123
+ subType: planType,
124
+ thought: plan.thought,
125
+ param: plan.param,
126
+ subTask: context.subTask || void 0,
127
+ executor: async (param, taskContext)=>{
128
+ var _taskContext_element;
129
+ debug('executing action', planType, param, `taskContext.element.center: ${null == (_taskContext_element = taskContext.element) ? void 0 : _taskContext_element.center}`);
130
+ const uiContext = taskContext.uiContext;
131
+ assert(uiContext, 'uiContext is required for Action task');
132
+ requiredLocateFields.forEach((field)=>{
133
+ assert(param[field], `field '${field}' is required for action ${planType} but not provided. Cannot execute action ${planType}.`);
134
+ });
135
+ try {
136
+ await Promise.all([
137
+ (async ()=>{
138
+ if (this.interface.beforeInvokeAction) {
139
+ debug('will call "beforeInvokeAction" for interface');
140
+ await this.interface.beforeInvokeAction(action.name, param);
141
+ debug('called "beforeInvokeAction" for interface');
142
+ }
143
+ })(),
144
+ sleep(200)
145
+ ]);
146
+ } catch (originalError) {
147
+ const originalMessage = (null == originalError ? void 0 : originalError.message) || String(originalError);
148
+ throw new Error(`error in running beforeInvokeAction for ${action.name}: ${originalMessage}`, {
149
+ cause: originalError
217
150
  });
218
- tasks.push(locateTask);
219
- } else {
220
- assert(!requiredLocateFields.includes(field), `Required locate field '${field}' is not provided for action ${planType}`);
221
- debug(`field '${field}' is not provided for action ${planType}`);
222
151
  }
223
- });
224
- const task = {
225
- type: 'Action',
226
- subType: planType,
227
- thought: plan.thought,
228
- param: plan.param,
229
- executor: async (param, taskContext)=>{
230
- var _taskContext_element;
231
- debug('executing action', planType, param, `taskContext.element.center: ${null == (_taskContext_element = taskContext.element) ? void 0 : _taskContext_element.center}`);
232
- const uiContext = taskContext.uiContext;
233
- assert(uiContext, 'uiContext is required for Action task');
234
- requiredLocateFields.forEach((field)=>{
235
- assert(param[field], `field '${field}' is required for action ${planType} but not provided. Cannot execute action ${planType}.`);
152
+ if (action.paramSchema) try {
153
+ param = parseActionParam(param, action.paramSchema);
154
+ } catch (error) {
155
+ throw new Error(`Invalid parameters for action ${action.name}: ${error.message}\nParameters: ${JSON.stringify(param)}`, {
156
+ cause: error
236
157
  });
237
- try {
238
- await Promise.all([
239
- (async ()=>{
240
- if (this.interface.beforeInvokeAction) {
241
- debug('will call "beforeInvokeAction" for interface');
242
- await this.interface.beforeInvokeAction(action.name, param);
243
- debug('called "beforeInvokeAction" for interface');
244
- }
245
- })(),
246
- sleep(200)
247
- ]);
248
- } catch (originalError) {
249
- const originalMessage = (null == originalError ? void 0 : originalError.message) || String(originalError);
250
- throw new Error(`error in running beforeInvokeAction for ${action.name}: ${originalMessage}`, {
251
- cause: originalError
252
- });
253
- }
254
- if (action.paramSchema) try {
255
- param = parseActionParam(param, action.paramSchema);
256
- } catch (error) {
257
- throw new Error(`Invalid parameters for action ${action.name}: ${error.message}\nParameters: ${JSON.stringify(param)}`, {
258
- cause: error
259
- });
158
+ }
159
+ debug('calling action', action.name);
160
+ const actionFn = action.call.bind(this.interface);
161
+ await actionFn(param, taskContext);
162
+ debug('called action', action.name);
163
+ try {
164
+ if (this.interface.afterInvokeAction) {
165
+ debug('will call "afterInvokeAction" for interface');
166
+ await this.interface.afterInvokeAction(action.name, param);
167
+ debug('called "afterInvokeAction" for interface');
260
168
  }
261
- debug('calling action', action.name);
262
- const actionFn = action.call.bind(this.interface);
263
- await actionFn(param, taskContext);
264
- debug('called action', action.name);
265
- try {
266
- if (this.interface.afterInvokeAction) {
267
- debug('will call "afterInvokeAction" for interface');
268
- await this.interface.afterInvokeAction(action.name, param);
269
- debug('called "afterInvokeAction" for interface');
270
- }
271
- } catch (originalError) {
272
- const originalMessage = (null == originalError ? void 0 : originalError.message) || String(originalError);
273
- throw new Error(`error in running afterInvokeAction for ${action.name}: ${originalMessage}`, {
274
- cause: originalError
275
- });
169
+ } catch (originalError) {
170
+ const originalMessage = (null == originalError ? void 0 : originalError.message) || String(originalError);
171
+ throw new Error(`error in running afterInvokeAction for ${action.name}: ${originalMessage}`, {
172
+ cause: originalError
173
+ });
174
+ }
175
+ return {
176
+ output: {
177
+ success: true,
178
+ action: planType,
179
+ param: param
276
180
  }
277
- return {
278
- output: {
279
- success: true,
280
- action: planType,
281
- param: param
282
- }
181
+ };
182
+ }
183
+ };
184
+ context.tasks.push(task);
185
+ }
186
+ createLocateTask(plan, detailedLocateParam, context, onResult) {
187
+ const { cacheable, modelConfig } = context;
188
+ let locateParam = detailedLocateParam;
189
+ if ('string' == typeof locateParam) locateParam = {
190
+ prompt: locateParam
191
+ };
192
+ if (void 0 !== cacheable) locateParam = {
193
+ ...locateParam,
194
+ cacheable
195
+ };
196
+ const taskFind = {
197
+ type: 'Insight',
198
+ subType: 'Locate',
199
+ subTask: context.subTask || void 0,
200
+ param: locateParam,
201
+ thought: plan.thought,
202
+ executor: async (param, taskContext)=>{
203
+ var _this_taskCache, _locateCacheRecord_cacheContent;
204
+ const { task } = taskContext;
205
+ let { uiContext } = taskContext;
206
+ assert((null == param ? void 0 : param.prompt) || (null == param ? void 0 : param.id) || (null == param ? void 0 : param.bbox), `No prompt or id or position or bbox to locate, param=${JSON.stringify(param)}`);
207
+ if (!uiContext) uiContext = await this.insight.contextRetrieverFn();
208
+ assert(uiContext, 'uiContext is required for Insight task');
209
+ let locateDump;
210
+ let locateResult;
211
+ const applyDump = (dump)=>{
212
+ var _dump_taskInfo, _dump_taskInfo1;
213
+ if (!dump) return;
214
+ locateDump = dump;
215
+ task.log = {
216
+ dump
283
217
  };
218
+ task.usage = null == (_dump_taskInfo = dump.taskInfo) ? void 0 : _dump_taskInfo.usage;
219
+ if (null == (_dump_taskInfo1 = dump.taskInfo) ? void 0 : _dump_taskInfo1.searchAreaUsage) task.searchAreaUsage = dump.taskInfo.searchAreaUsage;
220
+ };
221
+ let elementFromXpath;
222
+ if (param.xpath && this.interface.rectMatchesCacheFeature) elementFromXpath = await this.interface.rectMatchesCacheFeature({
223
+ xpaths: [
224
+ param.xpath
225
+ ]
226
+ });
227
+ const userExpectedPathHitFlag = !!elementFromXpath;
228
+ const cachePrompt = param.prompt;
229
+ const locateCacheRecord = null == (_this_taskCache = this.taskCache) ? void 0 : _this_taskCache.matchLocateCache(cachePrompt);
230
+ const cacheEntry = null == locateCacheRecord ? void 0 : null == (_locateCacheRecord_cacheContent = locateCacheRecord.cacheContent) ? void 0 : _locateCacheRecord_cacheContent.cache;
231
+ const elementFromCache = userExpectedPathHitFlag ? null : await matchElementFromCache({
232
+ taskCache: this.taskCache,
233
+ interfaceInstance: this.interface
234
+ }, cacheEntry, cachePrompt, param.cacheable);
235
+ const cacheHitFlag = !!elementFromCache;
236
+ const elementFromPlan = userExpectedPathHitFlag || cacheHitFlag ? void 0 : matchElementFromPlan(param, uiContext.tree);
237
+ const planHitFlag = !!elementFromPlan;
238
+ let elementFromAiLocate;
239
+ if (!userExpectedPathHitFlag && !cacheHitFlag && !planHitFlag) try {
240
+ locateResult = await this.insight.locate(param, {
241
+ context: uiContext
242
+ }, modelConfig);
243
+ applyDump(locateResult.dump);
244
+ elementFromAiLocate = locateResult.element;
245
+ } catch (error) {
246
+ if (error instanceof InsightError) applyDump(error.dump);
247
+ throw error;
284
248
  }
285
- };
286
- tasks.push(task);
287
- }
288
- return {
289
- tasks
249
+ const element = elementFromXpath || elementFromCache || elementFromPlan || elementFromAiLocate;
250
+ let currentCacheEntry;
251
+ if (element && this.taskCache && !cacheHitFlag && (null == param ? void 0 : param.cacheable) !== false) if (this.interface.cacheFeatureForRect) try {
252
+ const feature = await this.interface.cacheFeatureForRect(element.rect, void 0 !== element.isOrderSensitive ? {
253
+ _orderSensitive: element.isOrderSensitive
254
+ } : void 0);
255
+ if (feature && Object.keys(feature).length > 0) {
256
+ debug('update cache, prompt: %s, cache: %o', cachePrompt, feature);
257
+ currentCacheEntry = feature;
258
+ this.taskCache.updateOrAppendCacheRecord({
259
+ type: 'locate',
260
+ prompt: cachePrompt,
261
+ cache: feature
262
+ }, locateCacheRecord);
263
+ } else debug('no cache data returned, skip cache update, prompt: %s', cachePrompt);
264
+ } catch (error) {
265
+ debug('cacheFeatureForRect failed: %s', error);
266
+ }
267
+ else debug('cacheFeatureForRect is not supported, skip cache update');
268
+ if (!element) {
269
+ if (locateDump) throw new InsightError(`Element not found: ${param.prompt}`, locateDump);
270
+ throw new Error(`Element not found: ${param.prompt}`);
271
+ }
272
+ let hitBy;
273
+ if (userExpectedPathHitFlag) hitBy = {
274
+ from: 'User expected path',
275
+ context: {
276
+ xpath: param.xpath
277
+ }
278
+ };
279
+ else if (cacheHitFlag) hitBy = {
280
+ from: 'Cache',
281
+ context: {
282
+ cacheEntry,
283
+ cacheToSave: currentCacheEntry
284
+ }
285
+ };
286
+ else if (planHitFlag) hitBy = {
287
+ from: 'Planning',
288
+ context: {
289
+ id: null == elementFromPlan ? void 0 : elementFromPlan.id,
290
+ bbox: null == elementFromPlan ? void 0 : elementFromPlan.bbox
291
+ }
292
+ };
293
+ null == onResult || onResult(element);
294
+ return {
295
+ output: {
296
+ element
297
+ },
298
+ hitBy
299
+ };
300
+ }
290
301
  };
302
+ return taskFind;
291
303
  }
292
304
  constructor({ interfaceInstance, insight, taskCache }){
293
305
  _define_property(this, "interface", void 0);