@midscene/core 1.12.3 → 1.12.4-beta-20260902093735.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/agent/agent.mjs +88 -25
- package/dist/es/agent/agent.mjs.map +1 -1
- package/dist/es/agent/index.mjs +2 -1
- package/dist/es/agent/insight.mjs +40 -10
- package/dist/es/agent/insight.mjs.map +1 -1
- package/dist/es/agent/prompt-context.mjs +42 -6
- package/dist/es/agent/prompt-context.mjs.map +1 -1
- package/dist/es/agent/run-gherkin-scenario.mjs.map +1 -1
- package/dist/es/agent/utils.mjs +1 -1
- package/dist/es/ai-model/prompt/insight/user-prompt.mjs +1 -1
- package/dist/es/ai-model/prompt/insight/user-prompt.mjs.map +1 -1
- package/dist/es/ai-model/workflows/insight/extraction.mjs +4 -1
- package/dist/es/ai-model/workflows/insight/extraction.mjs.map +1 -1
- package/dist/es/ai-model/workflows/planning/custom-planning.mjs +3 -3
- package/dist/es/ai-model/workflows/planning/custom-planning.mjs.map +1 -1
- package/dist/es/ai-model/workflows/planning/standard-planning.mjs +1 -1
- package/dist/es/ai-model/workflows/planning/standard-planning.mjs.map +1 -1
- package/dist/es/index.mjs +2 -2
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/report-html-template.mjs +1 -1
- package/dist/es/types.mjs.map +1 -1
- package/dist/es/utils.mjs +1 -1
- package/dist/es/yaml/player.mjs +0 -5
- package/dist/es/yaml/player.mjs.map +1 -1
- package/dist/es/yaml/utils.mjs +4 -3
- package/dist/es/yaml/utils.mjs.map +1 -1
- package/dist/lib/agent/agent.js +87 -24
- package/dist/lib/agent/agent.js.map +1 -1
- package/dist/lib/agent/index.js +5 -1
- package/dist/lib/agent/insight.js +40 -10
- package/dist/lib/agent/insight.js.map +1 -1
- package/dist/lib/agent/prompt-context.js +55 -7
- package/dist/lib/agent/prompt-context.js.map +1 -1
- package/dist/lib/agent/run-gherkin-scenario.js.map +1 -1
- package/dist/lib/agent/utils.js +1 -1
- package/dist/lib/ai-model/prompt/insight/user-prompt.js +1 -1
- package/dist/lib/ai-model/prompt/insight/user-prompt.js.map +1 -1
- package/dist/lib/ai-model/workflows/insight/extraction.js +4 -1
- package/dist/lib/ai-model/workflows/insight/extraction.js.map +1 -1
- package/dist/lib/ai-model/workflows/planning/custom-planning.js +3 -3
- package/dist/lib/ai-model/workflows/planning/custom-planning.js.map +1 -1
- package/dist/lib/ai-model/workflows/planning/standard-planning.js +1 -1
- package/dist/lib/ai-model/workflows/planning/standard-planning.js.map +1 -1
- package/dist/lib/index.js +4 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/report-html-template.js +1 -1
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/utils.js +1 -1
- package/dist/lib/yaml/player.js +0 -5
- package/dist/lib/yaml/player.js.map +1 -1
- package/dist/lib/yaml/utils.js +3 -2
- package/dist/lib/yaml/utils.js.map +1 -1
- package/dist/types/agent/agent.d.ts +22 -3
- package/dist/types/agent/index.d.ts +2 -1
- package/dist/types/agent/insight.d.ts +6 -1
- package/dist/types/agent/prompt-context.d.ts +27 -1
- package/dist/types/agent/run-gherkin-scenario.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types.d.ts +26 -0
- package/dist/types/yaml.d.ts +12 -4
- package/package.json +2 -2
package/dist/lib/agent/agent.js
CHANGED
|
@@ -50,6 +50,7 @@ const external_utils_js_namespaceObject = require("../utils.js");
|
|
|
50
50
|
const external_yaml_index_js_namespaceObject = require("../yaml/index.js");
|
|
51
51
|
const promises_namespaceObject = require("node:fs/promises");
|
|
52
52
|
const external_node_path_namespaceObject = require("node:path");
|
|
53
|
+
const agent_context_namespaceObject = require("@midscene/shared/agent-tools/agent-context");
|
|
53
54
|
const error_formatter_namespaceObject = require("@midscene/shared/agent-tools/error-formatter");
|
|
54
55
|
const observation_artifact_namespaceObject = require("@midscene/shared/agent-tools/observation-artifact");
|
|
55
56
|
const env_namespaceObject = require("@midscene/shared/env");
|
|
@@ -92,8 +93,44 @@ class Agent {
|
|
|
92
93
|
this.dumpUpdateListeners = [];
|
|
93
94
|
if (callback) this.dumpUpdateListeners.push(callback);
|
|
94
95
|
}
|
|
95
|
-
get
|
|
96
|
-
|
|
96
|
+
get contexts() {
|
|
97
|
+
if (!this.opts.contexts) this.opts.contexts = {};
|
|
98
|
+
return this.opts.contexts;
|
|
99
|
+
}
|
|
100
|
+
resolveUserContext(apiName, callContext) {
|
|
101
|
+
if (void 0 !== callContext) return {
|
|
102
|
+
value: callContext,
|
|
103
|
+
metadata: {
|
|
104
|
+
source: 'call'
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const apiContext = this.opts.contexts?.[apiName];
|
|
108
|
+
if (void 0 !== apiContext) return {
|
|
109
|
+
value: apiContext,
|
|
110
|
+
metadata: {
|
|
111
|
+
source: 'api',
|
|
112
|
+
apiName
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const defaultContext = this.opts.contexts?.default;
|
|
116
|
+
if (void 0 !== defaultContext) return {
|
|
117
|
+
value: defaultContext,
|
|
118
|
+
metadata: {
|
|
119
|
+
source: 'default'
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
resolveContext(apiName, callContext, additionalContext) {
|
|
124
|
+
return (0, external_prompt_context_js_namespaceObject.renderAIContext)(this.resolveUserContext(apiName, callContext), additionalContext);
|
|
125
|
+
}
|
|
126
|
+
withContext(apiName, options) {
|
|
127
|
+
const resolvedContext = this.resolveUserContext(apiName, options?.context);
|
|
128
|
+
if (void 0 === resolvedContext) return options;
|
|
129
|
+
return {
|
|
130
|
+
...options ?? {},
|
|
131
|
+
context: resolvedContext.value,
|
|
132
|
+
[external_prompt_context_js_namespaceObject.INTERNAL_AI_CONTEXT_METADATA_KEY]: resolvedContext.metadata
|
|
133
|
+
};
|
|
97
134
|
}
|
|
98
135
|
get page() {
|
|
99
136
|
return this.interface;
|
|
@@ -119,7 +156,7 @@ class Agent {
|
|
|
119
156
|
};
|
|
120
157
|
}
|
|
121
158
|
createInsight(getUIContext) {
|
|
122
|
-
return new external_insight_js_namespaceObject.Insight(this.taskExecutor, ()=>this.resolveModelRuntime('insight'), getUIContext);
|
|
159
|
+
return new external_insight_js_namespaceObject.Insight(this.taskExecutor, ()=>this.resolveModelRuntime('insight'), getUIContext, (apiName, callContext)=>this.resolveUserContext(apiName, callContext));
|
|
123
160
|
}
|
|
124
161
|
async getActionSpace() {
|
|
125
162
|
return this.fullActionSpace;
|
|
@@ -180,12 +217,24 @@ class Agent {
|
|
|
180
217
|
return observer;
|
|
181
218
|
}
|
|
182
219
|
async setAIActionContext(prompt) {
|
|
183
|
-
|
|
220
|
+
warn('setAIActionContext() is deprecated; use setContext("aiAct", context) instead.');
|
|
221
|
+
this.setContext('aiAct', prompt);
|
|
184
222
|
}
|
|
185
223
|
async setAIActContext(prompt) {
|
|
186
|
-
|
|
187
|
-
this.
|
|
188
|
-
|
|
224
|
+
warn('setAIActContext() is deprecated; use setContext("aiAct", context) instead.');
|
|
225
|
+
this.setContext('aiAct', prompt);
|
|
226
|
+
}
|
|
227
|
+
setContext(target, context) {
|
|
228
|
+
if (!(0, agent_context_namespaceObject.isAgentContextKey)(target)) throw new TypeError(`Unknown Agent context key: ${String(target)}`);
|
|
229
|
+
if (void 0 !== context && 'string' != typeof context) throw new TypeError('Agent context must be a string or undefined');
|
|
230
|
+
this.contexts[target] = context;
|
|
231
|
+
if ('aiAct' === target) if (void 0 === context) {
|
|
232
|
+
this.opts.aiActContext = void 0;
|
|
233
|
+
this.opts.aiActionContext = void 0;
|
|
234
|
+
} else {
|
|
235
|
+
this.opts.aiActContext = context;
|
|
236
|
+
this.opts.aiActionContext = context;
|
|
237
|
+
}
|
|
189
238
|
}
|
|
190
239
|
resetDump() {
|
|
191
240
|
this.dump = new external_types_js_namespaceObject.ReportActionDump({
|
|
@@ -289,7 +338,7 @@ class Agent {
|
|
|
289
338
|
}
|
|
290
339
|
async aiTap(locatePrompt, opt) {
|
|
291
340
|
(0, utils_namespaceObject.assert)(locatePrompt, 'missing locate prompt for tap');
|
|
292
|
-
const detailedLocateParam = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParam)(locatePrompt, opt);
|
|
341
|
+
const detailedLocateParam = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParam)(locatePrompt, this.withContext('aiTap', opt));
|
|
293
342
|
const fileChooserAccept = opt?.fileChooserAccept ? this.normalizeFileInput(opt.fileChooserAccept) : void 0;
|
|
294
343
|
await (0, external_tasks_js_namespaceObject.withFileChooser)(this.interface, fileChooserAccept, async ()=>{
|
|
295
344
|
await this.callActionInActionSpace('Tap', {
|
|
@@ -299,21 +348,21 @@ class Agent {
|
|
|
299
348
|
}
|
|
300
349
|
async aiRightClick(locatePrompt, opt) {
|
|
301
350
|
(0, utils_namespaceObject.assert)(locatePrompt, 'missing locate prompt for right click');
|
|
302
|
-
const detailedLocateParam = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParam)(locatePrompt, opt);
|
|
351
|
+
const detailedLocateParam = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParam)(locatePrompt, this.withContext('aiRightClick', opt));
|
|
303
352
|
await this.callActionInActionSpace('RightClick', {
|
|
304
353
|
locate: detailedLocateParam
|
|
305
354
|
});
|
|
306
355
|
}
|
|
307
356
|
async aiDoubleClick(locatePrompt, opt) {
|
|
308
357
|
(0, utils_namespaceObject.assert)(locatePrompt, 'missing locate prompt for double click');
|
|
309
|
-
const detailedLocateParam = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParam)(locatePrompt, opt);
|
|
358
|
+
const detailedLocateParam = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParam)(locatePrompt, this.withContext('aiDoubleClick', opt));
|
|
310
359
|
await this.callActionInActionSpace('DoubleClick', {
|
|
311
360
|
locate: detailedLocateParam
|
|
312
361
|
});
|
|
313
362
|
}
|
|
314
363
|
async aiHover(locatePrompt, opt) {
|
|
315
364
|
(0, utils_namespaceObject.assert)(locatePrompt, 'missing locate prompt for hover');
|
|
316
|
-
const detailedLocateParam = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParam)(locatePrompt, opt);
|
|
365
|
+
const detailedLocateParam = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParam)(locatePrompt, this.withContext('aiHover', opt));
|
|
317
366
|
await this.callActionInActionSpace('Hover', {
|
|
318
367
|
locate: detailedLocateParam
|
|
319
368
|
});
|
|
@@ -337,7 +386,7 @@ class Agent {
|
|
|
337
386
|
}
|
|
338
387
|
(0, utils_namespaceObject.assert)('string' == typeof value || 'number' == typeof value, 'input value must be a string or number, use empty string if you want to clear the input');
|
|
339
388
|
(0, utils_namespaceObject.assert)(locatePrompt, 'missing locate prompt for input');
|
|
340
|
-
const { locateParam, restParams } = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParamAndRestParams)(locatePrompt, opt);
|
|
389
|
+
const { locateParam, restParams } = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParamAndRestParams)(locatePrompt, this.withContext('aiInput', opt));
|
|
341
390
|
const stringValue = 'number' == typeof value ? String(value) : value;
|
|
342
391
|
const mode = opt?.mode === 'append' ? 'typeOnly' : opt?.mode;
|
|
343
392
|
await this.callActionInActionSpace('Input', {
|
|
@@ -363,7 +412,7 @@ class Agent {
|
|
|
363
412
|
};
|
|
364
413
|
}
|
|
365
414
|
(0, utils_namespaceObject.assert)(opt?.keyName, 'missing keyName for keyboard press');
|
|
366
|
-
const { locateParam, restParams } = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParamAndRestParams)(locatePrompt || '', opt);
|
|
415
|
+
const { locateParam, restParams } = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParamAndRestParams)(locatePrompt || '', this.withContext('aiKeyboardPress', opt));
|
|
367
416
|
await this.callActionInActionSpace('KeyboardPress', {
|
|
368
417
|
...restParams,
|
|
369
418
|
locate: locateParam
|
|
@@ -395,14 +444,14 @@ class Agent {
|
|
|
395
444
|
scrollType: normalizedScrollType
|
|
396
445
|
};
|
|
397
446
|
}
|
|
398
|
-
const { locateParam, restParams } = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParamAndRestParams)(locatePrompt || '', opt);
|
|
447
|
+
const { locateParam, restParams } = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParamAndRestParams)(locatePrompt || '', this.withContext('aiScroll', opt));
|
|
399
448
|
await this.callActionInActionSpace('Scroll', {
|
|
400
449
|
...restParams,
|
|
401
450
|
locate: locateParam
|
|
402
451
|
});
|
|
403
452
|
}
|
|
404
453
|
async aiPinch(locatePrompt, opt) {
|
|
405
|
-
const { locateParam, restParams } = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParamAndRestParams)(locatePrompt || '', opt);
|
|
454
|
+
const { locateParam, restParams } = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParamAndRestParams)(locatePrompt || '', this.withContext('aiPinch', opt));
|
|
406
455
|
await this.callActionInActionSpace('Pinch', {
|
|
407
456
|
...restParams,
|
|
408
457
|
locate: locateParam
|
|
@@ -410,7 +459,7 @@ class Agent {
|
|
|
410
459
|
}
|
|
411
460
|
async aiLongPress(locatePrompt, opt) {
|
|
412
461
|
(0, utils_namespaceObject.assert)(locatePrompt, 'missing locate prompt for long press');
|
|
413
|
-
const { locateParam, restParams } = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParamAndRestParams)(locatePrompt, opt);
|
|
462
|
+
const { locateParam, restParams } = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParamAndRestParams)(locatePrompt, this.withContext('aiLongPress', opt));
|
|
414
463
|
await this.callActionInActionSpace('LongPress', {
|
|
415
464
|
...restParams,
|
|
416
465
|
locate: locateParam
|
|
@@ -418,13 +467,14 @@ class Agent {
|
|
|
418
467
|
}
|
|
419
468
|
async aiClearInput(locatePrompt, opt) {
|
|
420
469
|
(0, utils_namespaceObject.assert)(locatePrompt, 'missing locate prompt for clear input');
|
|
421
|
-
const detailedLocateParam = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParam)(locatePrompt, opt);
|
|
470
|
+
const detailedLocateParam = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParam)(locatePrompt, this.withContext('aiClearInput', opt));
|
|
422
471
|
await this.callActionInActionSpace('ClearInput', {
|
|
423
472
|
locate: detailedLocateParam
|
|
424
473
|
});
|
|
425
474
|
}
|
|
426
475
|
async aiAct(taskPrompt, opt) {
|
|
427
|
-
const
|
|
476
|
+
const internalOptions = opt;
|
|
477
|
+
const internalReportDisplay = internalOptions?._internalReportDisplay;
|
|
428
478
|
const taskPromptText = 'string' == typeof taskPrompt ? taskPrompt : taskPrompt.prompt;
|
|
429
479
|
const reportPrompt = internalReportDisplay?.prompt || taskPromptText;
|
|
430
480
|
const fileChooserAccept = opt?.fileChooserAccept ? this.normalizeFileInput(opt.fileChooserAccept) : void 0;
|
|
@@ -433,7 +483,7 @@ class Agent {
|
|
|
433
483
|
const runAiAct = async ()=>{
|
|
434
484
|
const planningModel = this.resolveModelRuntime('planning');
|
|
435
485
|
const defaultModel = this.resolveModelRuntime('default');
|
|
436
|
-
const aiActContext = opt?.context
|
|
486
|
+
const aiActContext = this.resolveContext('aiAct', opt?.context, internalOptions?._internalAdditionalContext);
|
|
437
487
|
const cachePrompt = (0, external_prompt_context_js_namespaceObject.buildPromptWithContext)(taskPrompt, aiActContext);
|
|
438
488
|
const effort = (()=>{
|
|
439
489
|
const resolvedEffort = opt?.effort ?? (opt?.deepThink === true ? 'deepThink' : 'balance');
|
|
@@ -551,7 +601,7 @@ class Agent {
|
|
|
551
601
|
return this.createInsight().aiAsk(prompt, opt);
|
|
552
602
|
}
|
|
553
603
|
async aiLocate(prompt, opt) {
|
|
554
|
-
const locateParam = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParam)(prompt, opt);
|
|
604
|
+
const locateParam = (0, external_yaml_index_js_namespaceObject.buildDetailedLocateParam)(prompt, this.withContext('aiLocate', opt));
|
|
555
605
|
(0, utils_namespaceObject.assert)(locateParam, 'cannot get locate param for aiLocate');
|
|
556
606
|
const locatePlan = (0, external_tasks_js_namespaceObject.locatePlanForLocate)(locateParam);
|
|
557
607
|
const plans = [
|
|
@@ -574,10 +624,11 @@ class Agent {
|
|
|
574
624
|
}
|
|
575
625
|
async aiWaitFor(assertion, opt) {
|
|
576
626
|
const modelRuntime = this.resolveModelRuntime('insight');
|
|
627
|
+
const options = this.withContext('aiWaitFor', opt);
|
|
577
628
|
await this.taskExecutor.waitFor(assertion, {
|
|
578
|
-
...
|
|
579
|
-
timeoutMs:
|
|
580
|
-
checkIntervalMs:
|
|
629
|
+
...options,
|
|
630
|
+
timeoutMs: options?.timeoutMs || 15000,
|
|
631
|
+
checkIntervalMs: options?.checkIntervalMs || 3000
|
|
581
632
|
}, modelRuntime);
|
|
582
633
|
}
|
|
583
634
|
async ai(...args) {
|
|
@@ -846,11 +897,23 @@ class Agent {
|
|
|
846
897
|
groupDescription: ''
|
|
847
898
|
}, opts || {});
|
|
848
899
|
(0, external_report_generator_js_namespaceObject.assertReportGenerationOptions)(this.opts);
|
|
849
|
-
|
|
900
|
+
if (void 0 !== this.opts.contexts && ('object' != typeof this.opts.contexts || null === this.opts.contexts || Array.isArray(this.opts.contexts))) throw new TypeError('opts.contexts must be a plain object');
|
|
901
|
+
for (const [key, value] of Object.entries(this.opts.contexts ?? {})){
|
|
902
|
+
if (!(0, agent_context_namespaceObject.isAgentContextKey)(key)) throw new TypeError(`Unknown Agent context key: ${key}`);
|
|
903
|
+
if (void 0 !== value && 'string' != typeof value) throw new TypeError(`Agent context "${key}" must be a string`);
|
|
904
|
+
}
|
|
905
|
+
const deprecatedAiActContextOption = void 0 !== this.opts.aiActContext ? 'aiActContext' : void 0 !== this.opts.aiActionContext ? 'aiActionContext' : void 0;
|
|
906
|
+
if (deprecatedAiActContextOption) warn(`Agent option "${deprecatedAiActContextOption}" is deprecated; use "contexts.aiAct" instead. When both are provided, "contexts.aiAct" takes precedence.`);
|
|
907
|
+
const normalizedContexts = {
|
|
908
|
+
...this.opts.contexts
|
|
909
|
+
};
|
|
910
|
+
const resolvedAiActContext = normalizedContexts.aiAct ?? this.opts.aiActContext ?? this.opts.aiActionContext;
|
|
850
911
|
if (void 0 !== resolvedAiActContext) {
|
|
912
|
+
normalizedContexts.aiAct = resolvedAiActContext;
|
|
851
913
|
this.opts.aiActContext = resolvedAiActContext;
|
|
852
914
|
this.opts.aiActionContext ??= resolvedAiActContext;
|
|
853
915
|
}
|
|
916
|
+
this.opts.contexts = normalizedContexts;
|
|
854
917
|
if (opts?.modelConfig && ('object' != typeof opts?.modelConfig || Array.isArray(opts.modelConfig))) throw new Error(`opts.modelConfig must be a plain object map of env keys to values, but got ${typeof opts?.modelConfig}`);
|
|
855
918
|
const hasCustomConfig = opts?.modelConfig || opts?.createOpenAIClient;
|
|
856
919
|
this.modelConfigManager = hasCustomConfig ? new env_namespaceObject.ModelConfigManager(opts?.modelConfig, opts?.createOpenAIClient) : env_namespaceObject.globalModelConfigManager;
|