misoai-web 1.0.2 → 1.0.4
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/LICENSE +21 -0
- package/README.md +8 -8
- package/bin/midscene-playground +2 -2
- package/dist/es/agent.js +167 -44
- package/dist/es/agent.js.map +1 -1
- package/dist/es/bridge-mode-browser.js +64 -17
- package/dist/es/bridge-mode-browser.js.map +1 -1
- package/dist/es/bridge-mode.js +169 -46
- package/dist/es/bridge-mode.js.map +1 -1
- package/dist/es/chrome-extension.js +229 -59
- package/dist/es/chrome-extension.js.map +1 -1
- package/dist/es/index.js +183 -45
- package/dist/es/index.js.map +1 -1
- package/dist/es/midscene-playground.js +173 -44
- package/dist/es/midscene-playground.js.map +1 -1
- package/dist/es/midscene-server.js.map +1 -1
- package/dist/es/playground.js +173 -44
- package/dist/es/playground.js.map +1 -1
- package/dist/es/playwright-report.js.map +1 -1
- package/dist/es/playwright.js +183 -45
- package/dist/es/playwright.js.map +1 -1
- package/dist/es/puppeteer-agent-launcher.js +183 -45
- package/dist/es/puppeteer-agent-launcher.js.map +1 -1
- package/dist/es/puppeteer.js +183 -45
- package/dist/es/puppeteer.js.map +1 -1
- package/dist/es/ui-utils.js.map +1 -1
- package/dist/es/utils.js.map +1 -1
- package/dist/es/yaml.js +21 -3
- package/dist/es/yaml.js.map +1 -1
- package/dist/lib/agent.js +167 -44
- package/dist/lib/agent.js.map +1 -1
- package/dist/lib/bridge-mode-browser.js +64 -17
- package/dist/lib/bridge-mode-browser.js.map +1 -1
- package/dist/lib/bridge-mode.js +169 -46
- package/dist/lib/bridge-mode.js.map +1 -1
- package/dist/lib/chrome-extension.js +229 -59
- package/dist/lib/chrome-extension.js.map +1 -1
- package/dist/lib/index.js +181 -46
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/midscene-playground.js +173 -44
- package/dist/lib/midscene-playground.js.map +1 -1
- package/dist/lib/midscene-server.js.map +1 -1
- package/dist/lib/playground.js +173 -44
- package/dist/lib/playground.js.map +1 -1
- package/dist/lib/playwright-report.js.map +1 -1
- package/dist/lib/playwright.js +181 -46
- package/dist/lib/playwright.js.map +1 -1
- package/dist/lib/puppeteer-agent-launcher.js +181 -46
- package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
- package/dist/lib/puppeteer.js +181 -46
- package/dist/lib/puppeteer.js.map +1 -1
- package/dist/lib/ui-utils.js.map +1 -1
- package/dist/lib/utils.js.map +1 -1
- package/dist/lib/yaml.js +21 -3
- package/dist/lib/yaml.js.map +1 -1
- package/dist/types/agent.d.ts +16 -6
- package/dist/types/bridge-mode-browser.d.ts +2 -2
- package/dist/types/bridge-mode.d.ts +2 -2
- package/dist/types/{browser-d447695b.d.ts → browser-a1877d18.d.ts} +1 -1
- package/dist/types/chrome-extension.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/midscene-server.d.ts +1 -1
- package/dist/types/{page-b8ada1f3.d.ts → page-663ece08.d.ts} +41 -30
- package/dist/types/playground.d.ts +2 -2
- package/dist/types/playwright.d.ts +1 -1
- package/dist/types/puppeteer-agent-launcher.d.ts +1 -1
- package/dist/types/puppeteer.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/yaml.d.ts +1 -1
- package/iife-script/htmlElement.js +99 -37
- package/iife-script/htmlElementDebug.js +92 -9
- package/package.json +23 -24
@@ -227,7 +227,9 @@ var ScriptPlayer = class {
|
|
227
227
|
typeof prompt === "string",
|
228
228
|
"prompt for aiAction must be a string"
|
229
229
|
);
|
230
|
-
await agent.aiAction(prompt
|
230
|
+
await agent.aiAction(prompt, {
|
231
|
+
cacheable: actionTask.cacheable
|
232
|
+
});
|
231
233
|
} else if ("aiAssert" in flowItem) {
|
232
234
|
const assertTask = flowItem;
|
233
235
|
const prompt = assertTask.aiAssert;
|
@@ -429,8 +431,24 @@ function interpolateEnvVars(content) {
|
|
429
431
|
});
|
430
432
|
}
|
431
433
|
function parseYamlScript(content, filePath, ignoreCheckingTarget) {
|
432
|
-
|
433
|
-
|
434
|
+
let processedContent = content;
|
435
|
+
if (content.indexOf("android") !== -1 && content.match(/deviceId:\s*(\d+)/)) {
|
436
|
+
let matchedDeviceId;
|
437
|
+
processedContent = content.replace(
|
438
|
+
/deviceId:\s*(\d+)/g,
|
439
|
+
(match, deviceId) => {
|
440
|
+
matchedDeviceId = deviceId;
|
441
|
+
return `deviceId: '${deviceId}'`;
|
442
|
+
}
|
443
|
+
);
|
444
|
+
console.warn(
|
445
|
+
`please use string-style deviceId in yaml script, for example: deviceId: "${matchedDeviceId}"`
|
446
|
+
);
|
447
|
+
}
|
448
|
+
const interpolatedContent = interpolateEnvVars(processedContent);
|
449
|
+
const obj = import_js_yaml2.default.load(interpolatedContent, {
|
450
|
+
schema: import_js_yaml2.default.JSON_SCHEMA
|
451
|
+
});
|
434
452
|
const pathTip = filePath ? `, failed to load ${filePath}` : "";
|
435
453
|
const android = typeof obj.android !== "undefined" ? Object.assign({}, obj.android || {}) : void 0;
|
436
454
|
const webConfig = obj.web || obj.target;
|
@@ -471,7 +489,6 @@ var import_misoai_core = require("misoai-core");
|
|
471
489
|
var import_ai_model2 = require("misoai-core/ai-model");
|
472
490
|
var import_utils5 = require("misoai-core/utils");
|
473
491
|
var import_constants = require("misoai-shared/constants");
|
474
|
-
var import_fs = require("misoai-shared/fs");
|
475
492
|
var import_logger = require("misoai-shared/logger");
|
476
493
|
var import_utils6 = require("misoai-shared/utils");
|
477
494
|
|
@@ -589,16 +606,18 @@ var PageTaskExecutor = class {
|
|
589
606
|
);
|
590
607
|
if (info?.id) {
|
591
608
|
elementId = info.id;
|
609
|
+
} else {
|
610
|
+
debug(
|
611
|
+
"no element id found for position node, will not update cache",
|
612
|
+
element
|
613
|
+
);
|
592
614
|
}
|
593
615
|
}
|
594
616
|
if (!elementId) {
|
595
617
|
return void 0;
|
596
618
|
}
|
597
619
|
try {
|
598
|
-
const
|
599
|
-
const result = await this.page.evaluateJavaScript?.(
|
600
|
-
`${elementInfosScriptContent}midscene_element_inspector.getXpathsById('${elementId}')`
|
601
|
-
);
|
620
|
+
const result = await this.page.getXpathsById(elementId);
|
602
621
|
return result;
|
603
622
|
} catch (error) {
|
604
623
|
debug("getXpathsById error: ", error);
|
@@ -637,7 +656,7 @@ var PageTaskExecutor = class {
|
|
637
656
|
};
|
638
657
|
return taskWithScreenshot;
|
639
658
|
}
|
640
|
-
async convertPlanToExecutable(plans) {
|
659
|
+
async convertPlanToExecutable(plans, opts) {
|
641
660
|
const tasks = [];
|
642
661
|
plans.forEach((plan2) => {
|
643
662
|
if (plan2.type === "Locate") {
|
@@ -647,7 +666,10 @@ var PageTaskExecutor = class {
|
|
647
666
|
const taskFind = {
|
648
667
|
type: "Insight",
|
649
668
|
subType: "Locate",
|
650
|
-
param: plan2.locate
|
669
|
+
param: plan2.locate ? {
|
670
|
+
...plan2.locate,
|
671
|
+
cacheable: opts?.cacheable
|
672
|
+
} : void 0,
|
651
673
|
thought: plan2.thought,
|
652
674
|
locate: plan2.locate,
|
653
675
|
executor: async (param, taskContext) => {
|
@@ -684,19 +706,21 @@ var PageTaskExecutor = class {
|
|
684
706
|
let elementFromCache = null;
|
685
707
|
try {
|
686
708
|
if (xpaths?.length && this.taskCache?.isCacheResultUsed && param?.cacheable !== false) {
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
);
|
691
|
-
if (element2?.id) {
|
692
|
-
elementFromCache = element2;
|
693
|
-
debug("cache hit, prompt: %s", cachePrompt);
|
694
|
-
cacheHitFlag = true;
|
695
|
-
debug(
|
696
|
-
"found a new new element with same xpath, xpath: %s, id: %s",
|
697
|
-
xpaths[0],
|
698
|
-
element2?.id
|
709
|
+
for (let i = 0; i < xpaths.length; i++) {
|
710
|
+
const element2 = await this.page.getElementInfoByXpath(
|
711
|
+
xpaths[i]
|
699
712
|
);
|
713
|
+
if (element2?.id) {
|
714
|
+
elementFromCache = element2;
|
715
|
+
debug("cache hit, prompt: %s", cachePrompt);
|
716
|
+
cacheHitFlag = true;
|
717
|
+
debug(
|
718
|
+
"found a new new element with same xpath, xpath: %s, id: %s",
|
719
|
+
xpaths[i],
|
720
|
+
element2?.id
|
721
|
+
);
|
722
|
+
break;
|
723
|
+
}
|
700
724
|
}
|
701
725
|
}
|
702
726
|
} catch (error) {
|
@@ -709,12 +733,14 @@ var PageTaskExecutor = class {
|
|
709
733
|
context: pageContext
|
710
734
|
})).element;
|
711
735
|
const aiCost = Date.now() - startTime;
|
736
|
+
let currentXpaths;
|
712
737
|
if (element && this.taskCache && !cacheHitFlag && param?.cacheable !== false) {
|
713
738
|
const elementXpaths = await this.getElementXpath(
|
714
739
|
pageContext,
|
715
740
|
element
|
716
741
|
);
|
717
|
-
if (elementXpaths) {
|
742
|
+
if (elementXpaths?.length) {
|
743
|
+
currentXpaths = elementXpaths;
|
718
744
|
this.taskCache.updateOrAppendCacheRecord(
|
719
745
|
{
|
720
746
|
type: "locate",
|
@@ -724,7 +750,11 @@ var PageTaskExecutor = class {
|
|
724
750
|
locateCacheRecord
|
725
751
|
);
|
726
752
|
} else {
|
727
|
-
debug(
|
753
|
+
debug(
|
754
|
+
"no xpaths found, will not update cache",
|
755
|
+
cachePrompt,
|
756
|
+
elementXpaths
|
757
|
+
);
|
728
758
|
}
|
729
759
|
}
|
730
760
|
if (!element) {
|
@@ -736,7 +766,9 @@ var PageTaskExecutor = class {
|
|
736
766
|
},
|
737
767
|
pageContext,
|
738
768
|
cache: {
|
739
|
-
hit: cacheHitFlag
|
769
|
+
hit: cacheHitFlag,
|
770
|
+
originalXpaths: xpaths,
|
771
|
+
currentXpaths
|
740
772
|
},
|
741
773
|
aiCost
|
742
774
|
};
|
@@ -1104,6 +1136,7 @@ var PageTaskExecutor = class {
|
|
1104
1136
|
sleep: sleep2
|
1105
1137
|
} = planResult;
|
1106
1138
|
executorContext.task.log = {
|
1139
|
+
...executorContext.task.log || {},
|
1107
1140
|
rawResponse
|
1108
1141
|
};
|
1109
1142
|
executorContext.task.usage = usage;
|
@@ -1228,11 +1261,11 @@ var PageTaskExecutor = class {
|
|
1228
1261
|
};
|
1229
1262
|
return task;
|
1230
1263
|
}
|
1231
|
-
async runPlans(title, plans) {
|
1264
|
+
async runPlans(title, plans, opts) {
|
1232
1265
|
const taskExecutor = new import_misoai_core.Executor(title, {
|
1233
1266
|
onTaskStart: this.onTaskStartCallback
|
1234
1267
|
});
|
1235
|
-
const { tasks } = await this.convertPlanToExecutable(plans);
|
1268
|
+
const { tasks } = await this.convertPlanToExecutable(plans, opts);
|
1236
1269
|
await taskExecutor.append(tasks);
|
1237
1270
|
const result = await taskExecutor.flush();
|
1238
1271
|
return {
|
@@ -1240,7 +1273,7 @@ var PageTaskExecutor = class {
|
|
1240
1273
|
executor: taskExecutor
|
1241
1274
|
};
|
1242
1275
|
}
|
1243
|
-
async action(userPrompt, actionContext) {
|
1276
|
+
async action(userPrompt, actionContext, opts) {
|
1244
1277
|
const taskExecutor = new import_misoai_core.Executor(taskTitleStr("Action", userPrompt), {
|
1245
1278
|
onTaskStart: this.onTaskStartCallback
|
1246
1279
|
});
|
@@ -1265,7 +1298,7 @@ var PageTaskExecutor = class {
|
|
1265
1298
|
yamlFlow.push(...planResult.yamlFlow || []);
|
1266
1299
|
let executables;
|
1267
1300
|
try {
|
1268
|
-
executables = await this.convertPlanToExecutable(plans);
|
1301
|
+
executables = await this.convertPlanToExecutable(plans, opts);
|
1269
1302
|
taskExecutor.append(executables.tasks);
|
1270
1303
|
} catch (error) {
|
1271
1304
|
return this.appendErrorPlan(
|
@@ -1303,7 +1336,7 @@ var PageTaskExecutor = class {
|
|
1303
1336
|
executor: taskExecutor
|
1304
1337
|
};
|
1305
1338
|
}
|
1306
|
-
async actionToGoal(userPrompt) {
|
1339
|
+
async actionToGoal(userPrompt, opts) {
|
1307
1340
|
const taskExecutor = new import_misoai_core.Executor(taskTitleStr("Action", userPrompt), {
|
1308
1341
|
onTaskStart: this.onTaskStartCallback
|
1309
1342
|
});
|
@@ -1327,7 +1360,7 @@ var PageTaskExecutor = class {
|
|
1327
1360
|
yamlFlow.push(...output.yamlFlow || []);
|
1328
1361
|
let executables;
|
1329
1362
|
try {
|
1330
|
-
executables = await this.convertPlanToExecutable(plans);
|
1363
|
+
executables = await this.convertPlanToExecutable(plans, opts);
|
1331
1364
|
taskExecutor.append(executables.tasks);
|
1332
1365
|
} catch (error) {
|
1333
1366
|
return this.appendErrorPlan(
|
@@ -1632,7 +1665,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
|
|
1632
1665
|
var import_semver = __toESM(require("semver"));
|
1633
1666
|
|
1634
1667
|
// package.json
|
1635
|
-
var version = "1.0.
|
1668
|
+
var version = "1.0.4";
|
1636
1669
|
|
1637
1670
|
// src/common/task-cache.ts
|
1638
1671
|
var debug3 = (0, import_logger3.getDebug)("cache");
|
@@ -1975,9 +2008,9 @@ var PageAgent = class {
|
|
1975
2008
|
buildDetailedLocateParam(locatePrompt, opt) {
|
1976
2009
|
(0, import_utils12.assert)(locatePrompt, "missing locate prompt");
|
1977
2010
|
if (typeof opt === "object") {
|
1978
|
-
const prompt = opt.prompt
|
1979
|
-
const deepThink = opt.deepThink
|
1980
|
-
const cacheable = opt.cacheable
|
2011
|
+
const prompt = opt.prompt ?? locatePrompt;
|
2012
|
+
const deepThink = opt.deepThink ?? false;
|
2013
|
+
const cacheable = opt.cacheable ?? true;
|
1981
2014
|
return {
|
1982
2015
|
prompt,
|
1983
2016
|
deepThink,
|
@@ -1996,7 +2029,8 @@ var PageAgent = class {
|
|
1996
2029
|
const plans = buildPlans("Tap", detailedLocateParam);
|
1997
2030
|
const { executor, output } = await this.taskExecutor.runPlans(
|
1998
2031
|
taskTitleStr("Tap", locateParamStr(detailedLocateParam)),
|
1999
|
-
plans
|
2032
|
+
plans,
|
2033
|
+
{ cacheable: opt?.cacheable }
|
2000
2034
|
);
|
2001
2035
|
const metadata = this.afterTaskRunning(executor);
|
2002
2036
|
return {
|
@@ -2012,7 +2046,8 @@ var PageAgent = class {
|
|
2012
2046
|
const plans = buildPlans("Hover", detailedLocateParam);
|
2013
2047
|
const { executor, output } = await this.taskExecutor.runPlans(
|
2014
2048
|
taskTitleStr("Hover", locateParamStr(detailedLocateParam)),
|
2015
|
-
plans
|
2049
|
+
plans,
|
2050
|
+
{ cacheable: opt?.cacheable }
|
2016
2051
|
);
|
2017
2052
|
const metadata = this.afterTaskRunning(executor);
|
2018
2053
|
return {
|
@@ -2035,7 +2070,8 @@ var PageAgent = class {
|
|
2035
2070
|
});
|
2036
2071
|
const { executor, output } = await this.taskExecutor.runPlans(
|
2037
2072
|
taskTitleStr("Input", locateParamStr(detailedLocateParam)),
|
2038
|
-
plans
|
2073
|
+
plans,
|
2074
|
+
{ cacheable: opt?.cacheable }
|
2039
2075
|
);
|
2040
2076
|
const metadata = this.afterTaskRunning(executor);
|
2041
2077
|
return {
|
@@ -2051,7 +2087,8 @@ var PageAgent = class {
|
|
2051
2087
|
});
|
2052
2088
|
const { executor, output } = await this.taskExecutor.runPlans(
|
2053
2089
|
taskTitleStr("KeyboardPress", locateParamStr(detailedLocateParam)),
|
2054
|
-
plans
|
2090
|
+
plans,
|
2091
|
+
{ cacheable: opt?.cacheable }
|
2055
2092
|
);
|
2056
2093
|
const metadata = this.afterTaskRunning(executor);
|
2057
2094
|
return {
|
@@ -2065,7 +2102,8 @@ var PageAgent = class {
|
|
2065
2102
|
const paramInTitle = locatePrompt ? `${locateParamStr(detailedLocateParam)} - ${scrollParamStr(scrollParam)}` : scrollParamStr(scrollParam);
|
2066
2103
|
const { executor, output } = await this.taskExecutor.runPlans(
|
2067
2104
|
taskTitleStr("Scroll", paramInTitle),
|
2068
|
-
plans
|
2105
|
+
plans,
|
2106
|
+
{ cacheable: opt?.cacheable }
|
2069
2107
|
);
|
2070
2108
|
const metadata = this.afterTaskRunning(executor);
|
2071
2109
|
return {
|
@@ -2074,6 +2112,19 @@ var PageAgent = class {
|
|
2074
2112
|
};
|
2075
2113
|
}
|
2076
2114
|
async aiAction(taskPrompt, opt) {
|
2115
|
+
try {
|
2116
|
+
const aiModel = await import("misoai-core/ai-model");
|
2117
|
+
const contextStore = aiModel.getContextStore();
|
2118
|
+
const processedPrompt = contextStore.replaceAllReferences(taskPrompt, "action");
|
2119
|
+
contextStore.addStep({
|
2120
|
+
type: "action",
|
2121
|
+
summary: `Action: ${processedPrompt}`,
|
2122
|
+
prompt: processedPrompt
|
2123
|
+
});
|
2124
|
+
taskPrompt = processedPrompt;
|
2125
|
+
} catch (error) {
|
2126
|
+
debug4("Context store not available:", error);
|
2127
|
+
}
|
2077
2128
|
const cacheable = opt?.cacheable;
|
2078
2129
|
const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
|
2079
2130
|
const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
|
@@ -2091,7 +2142,9 @@ var PageAgent = class {
|
|
2091
2142
|
metadata: metadata2
|
2092
2143
|
};
|
2093
2144
|
}
|
2094
|
-
const { output, executor } = await (isVlmUiTars ? this.taskExecutor.actionToGoal(taskPrompt) : this.taskExecutor.action(taskPrompt, this.opts.aiActionContext
|
2145
|
+
const { output, executor } = await (isVlmUiTars ? this.taskExecutor.actionToGoal(taskPrompt, { cacheable }) : this.taskExecutor.action(taskPrompt, this.opts.aiActionContext, {
|
2146
|
+
cacheable
|
2147
|
+
}));
|
2095
2148
|
if (this.taskCache && output?.yamlFlow && cacheable !== false) {
|
2096
2149
|
const yamlContent = {
|
2097
2150
|
tasks: [
|
@@ -2118,7 +2171,63 @@ var PageAgent = class {
|
|
2118
2171
|
};
|
2119
2172
|
}
|
2120
2173
|
async aiQuery(demand) {
|
2121
|
-
|
2174
|
+
let processedDemand = demand;
|
2175
|
+
let storageKey;
|
2176
|
+
try {
|
2177
|
+
const aiModel = await import("misoai-core/ai-model");
|
2178
|
+
const contextStore = aiModel.getContextStore();
|
2179
|
+
if (typeof demand === "string") {
|
2180
|
+
const storageInstruction = contextStore.parseStorageInstruction(demand);
|
2181
|
+
if (storageInstruction) {
|
2182
|
+
storageKey = storageInstruction.key;
|
2183
|
+
processedDemand = storageInstruction.cleanText;
|
2184
|
+
contextStore._pendingAliases = storageInstruction.aliases;
|
2185
|
+
} else {
|
2186
|
+
const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
|
2187
|
+
if (storageMatch) {
|
2188
|
+
storageKey = storageMatch[1];
|
2189
|
+
processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
|
2190
|
+
}
|
2191
|
+
}
|
2192
|
+
}
|
2193
|
+
} catch (error) {
|
2194
|
+
debug4("Context store not available:", error);
|
2195
|
+
}
|
2196
|
+
const { output, executor } = await this.taskExecutor.query(processedDemand);
|
2197
|
+
if (storageKey && output) {
|
2198
|
+
try {
|
2199
|
+
const aiModel = await import("misoai-core/ai-model");
|
2200
|
+
const contextStore = aiModel.getContextStore();
|
2201
|
+
const pendingAliases = contextStore._pendingAliases;
|
2202
|
+
if (pendingAliases) {
|
2203
|
+
contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
|
2204
|
+
delete contextStore._pendingAliases;
|
2205
|
+
} else {
|
2206
|
+
contextStore.storeData(storageKey, output);
|
2207
|
+
}
|
2208
|
+
contextStore.addStep({
|
2209
|
+
type: "query",
|
2210
|
+
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
|
2211
|
+
data: output,
|
2212
|
+
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2213
|
+
});
|
2214
|
+
} catch (error) {
|
2215
|
+
debug4("Failed to store query result:", error);
|
2216
|
+
}
|
2217
|
+
} else {
|
2218
|
+
try {
|
2219
|
+
const aiModel = await import("misoai-core/ai-model");
|
2220
|
+
const contextStore = aiModel.getContextStore();
|
2221
|
+
contextStore.addStep({
|
2222
|
+
type: "query",
|
2223
|
+
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
|
2224
|
+
data: output,
|
2225
|
+
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2226
|
+
});
|
2227
|
+
} catch (error) {
|
2228
|
+
debug4("Failed to add query step:", error);
|
2229
|
+
}
|
2230
|
+
}
|
2122
2231
|
const metadata = this.afterTaskRunning(executor);
|
2123
2232
|
return {
|
2124
2233
|
result: output,
|
@@ -2213,7 +2322,8 @@ var PageAgent = class {
|
|
2213
2322
|
const plans = buildPlans("Locate", detailedLocateParam);
|
2214
2323
|
const { executor, output } = await this.taskExecutor.runPlans(
|
2215
2324
|
taskTitleStr("Locate", locateParamStr(detailedLocateParam)),
|
2216
|
-
plans
|
2325
|
+
plans,
|
2326
|
+
{ cacheable: opt?.cacheable }
|
2217
2327
|
);
|
2218
2328
|
const metadata = this.afterTaskRunning(executor);
|
2219
2329
|
const { element } = output;
|
@@ -2227,6 +2337,19 @@ var PageAgent = class {
|
|
2227
2337
|
};
|
2228
2338
|
}
|
2229
2339
|
async aiAssert(assertion, msg, opt) {
|
2340
|
+
let processedAssertion = assertion;
|
2341
|
+
try {
|
2342
|
+
const aiModel = await import("misoai-core/ai-model");
|
2343
|
+
const contextStore = aiModel.getContextStore();
|
2344
|
+
processedAssertion = contextStore.replaceAllReferences(assertion, "assertion");
|
2345
|
+
contextStore.addStep({
|
2346
|
+
type: "assertion",
|
2347
|
+
summary: `Assertion: ${processedAssertion}`,
|
2348
|
+
prompt: processedAssertion
|
2349
|
+
});
|
2350
|
+
} catch (error) {
|
2351
|
+
debug4("Context store not available:", error);
|
2352
|
+
}
|
2230
2353
|
let currentUrl = "";
|
2231
2354
|
if (this.page.url) {
|
2232
2355
|
try {
|
@@ -2234,7 +2357,7 @@ var PageAgent = class {
|
|
2234
2357
|
} catch (e) {
|
2235
2358
|
}
|
2236
2359
|
}
|
2237
|
-
const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${
|
2360
|
+
const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${processedAssertion}` : processedAssertion;
|
2238
2361
|
const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
|
2239
2362
|
const metadata = this.afterTaskRunning(executor, true);
|
2240
2363
|
if (output && opt?.keepRawResponse) {
|
@@ -2501,6 +2624,12 @@ var StaticPage = class {
|
|
2501
2624
|
async getElementsNodeTree() {
|
2502
2625
|
return ThrowNotImplemented("getElementsNodeTree");
|
2503
2626
|
}
|
2627
|
+
async getXpathsById(id) {
|
2628
|
+
return ThrowNotImplemented("getXpathsById");
|
2629
|
+
}
|
2630
|
+
async getElementInfoByXpath(xpath) {
|
2631
|
+
return ThrowNotImplemented("getElementInfoByXpath");
|
2632
|
+
}
|
2504
2633
|
async size() {
|
2505
2634
|
return this.uiContext.size;
|
2506
2635
|
}
|