misoai-web 1.0.6 → 1.5.6
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/README.md +5 -349
- package/dist/es/agent.js +43 -409
- package/dist/es/agent.js.map +1 -1
- package/dist/es/bridge-mode-browser.js +3 -3
- package/dist/es/bridge-mode.js +45 -411
- package/dist/es/bridge-mode.js.map +1 -1
- package/dist/es/chrome-extension.js +44 -410
- package/dist/es/chrome-extension.js.map +1 -1
- package/dist/es/index.js +47 -413
- package/dist/es/index.js.map +1 -1
- package/dist/es/midscene-playground.js +43 -409
- package/dist/es/midscene-playground.js.map +1 -1
- package/dist/es/playground.js +43 -409
- package/dist/es/playground.js.map +1 -1
- package/dist/es/playwright.js +44 -410
- package/dist/es/playwright.js.map +1 -1
- package/dist/es/puppeteer-agent-launcher.js +47 -413
- package/dist/es/puppeteer-agent-launcher.js.map +1 -1
- package/dist/es/puppeteer.js +47 -413
- package/dist/es/puppeteer.js.map +1 -1
- package/dist/es/yaml.js +5 -3
- package/dist/es/yaml.js.map +1 -1
- package/dist/lib/agent.js +43 -409
- package/dist/lib/agent.js.map +1 -1
- package/dist/lib/bridge-mode-browser.js +3 -3
- package/dist/lib/bridge-mode.js +45 -411
- package/dist/lib/bridge-mode.js.map +1 -1
- package/dist/lib/chrome-extension.js +44 -410
- package/dist/lib/chrome-extension.js.map +1 -1
- package/dist/lib/index.js +47 -413
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/midscene-playground.js +43 -409
- package/dist/lib/midscene-playground.js.map +1 -1
- package/dist/lib/playground.js +43 -409
- package/dist/lib/playground.js.map +1 -1
- package/dist/lib/playwright.js +44 -410
- package/dist/lib/playwright.js.map +1 -1
- package/dist/lib/puppeteer-agent-launcher.js +47 -413
- package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
- package/dist/lib/puppeteer.js +47 -413
- package/dist/lib/puppeteer.js.map +1 -1
- package/dist/lib/yaml.js +5 -3
- package/dist/lib/yaml.js.map +1 -1
- package/dist/types/agent.d.ts +3 -44
- package/iife-script/htmlElement.js +2 -2
- package/iife-script/htmlElementDebug.js +2 -2
- package/package.json +4 -4
package/dist/lib/index.js
CHANGED
@@ -60,10 +60,11 @@ var ScriptPlayer = class {
|
|
60
60
|
this.unnamedResultIndex = 0;
|
61
61
|
this.pageAgent = null;
|
62
62
|
this.result = {};
|
63
|
+
const target = script.target || script.web || script.android;
|
63
64
|
if (import_utils.ifInBrowser) {
|
64
65
|
this.output = void 0;
|
65
|
-
} else if (
|
66
|
-
this.output = (0, import_node_path.resolve)(process.cwd(),
|
66
|
+
} else if (target?.output) {
|
67
|
+
this.output = (0, import_node_path.resolve)(process.cwd(), target.output);
|
67
68
|
} else {
|
68
69
|
this.output = (0, import_node_path.join)((0, import_common.getMidsceneRunSubDir)("output"), `${process.pid}.json`);
|
69
70
|
}
|
@@ -137,12 +138,13 @@ var ScriptPlayer = class {
|
|
137
138
|
} else if ("aiAssert" in flowItem) {
|
138
139
|
const assertTask = flowItem;
|
139
140
|
const prompt = assertTask.aiAssert;
|
141
|
+
const msg = assertTask.errorMessage;
|
140
142
|
(0, import_utils.assert)(prompt, "missing prompt for aiAssert");
|
141
143
|
(0, import_utils.assert)(
|
142
144
|
typeof prompt === "string",
|
143
145
|
"prompt for aiAssert must be a string"
|
144
146
|
);
|
145
|
-
await agent.aiAssert(prompt);
|
147
|
+
await agent.aiAssert(prompt, msg);
|
146
148
|
} else if ("aiQuery" in flowItem) {
|
147
149
|
const queryTask = flowItem;
|
148
150
|
const prompt = queryTask.aiQuery;
|
@@ -1711,7 +1713,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
|
|
1711
1713
|
var import_semver = __toESM(require("semver"));
|
1712
1714
|
|
1713
1715
|
// package.json
|
1714
|
-
var version = "1.
|
1716
|
+
var version = "1.5.6";
|
1715
1717
|
|
1716
1718
|
// src/common/task-cache.ts
|
1717
1719
|
var debug3 = (0, import_logger3.getDebug)("cache");
|
@@ -1739,70 +1741,44 @@ var TaskCache = class {
|
|
1739
1741
|
this.cache = cacheContent;
|
1740
1742
|
this.cacheOriginalLength = this.cache.caches.length;
|
1741
1743
|
}
|
1742
|
-
matchCache(prompt, type
|
1743
|
-
const contextHash = contextData ? this.generateContextHash(contextData) : void 0;
|
1744
|
+
matchCache(prompt, type) {
|
1744
1745
|
for (let i = 0; i < this.cacheOriginalLength; i++) {
|
1745
1746
|
const item = this.cache.caches[i];
|
1746
1747
|
const key = `${type}:${prompt}:${i}`;
|
1747
|
-
if (item.type
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1748
|
+
if (item.type === type && item.prompt === prompt && !this.matchedCacheIndices.has(key)) {
|
1749
|
+
this.matchedCacheIndices.add(key);
|
1750
|
+
debug3(
|
1751
|
+
"cache found and marked as used, type: %s, prompt: %s, index: %d",
|
1752
|
+
type,
|
1753
|
+
prompt,
|
1754
|
+
i
|
1755
|
+
);
|
1756
|
+
return {
|
1757
|
+
cacheContent: item,
|
1758
|
+
updateFn: (cb) => {
|
1759
|
+
debug3(
|
1760
|
+
"will call updateFn to update cache, type: %s, prompt: %s, index: %d",
|
1761
|
+
type,
|
1762
|
+
prompt,
|
1763
|
+
i
|
1764
|
+
);
|
1765
|
+
cb(item);
|
1766
|
+
debug3(
|
1767
|
+
"cache updated, will flush to file, type: %s, prompt: %s, index: %d",
|
1768
|
+
type,
|
1769
|
+
prompt,
|
1770
|
+
i
|
1771
|
+
);
|
1772
|
+
this.flushCacheToFile();
|
1756
1773
|
}
|
1757
|
-
}
|
1758
|
-
debug3("cache context availability mismatch, type: %s, prompt: %s, index: %d", type, prompt, i);
|
1759
|
-
continue;
|
1760
|
-
}
|
1774
|
+
};
|
1761
1775
|
}
|
1762
|
-
this.matchedCacheIndices.add(key);
|
1763
|
-
debug3(
|
1764
|
-
"cache found and marked as used, type: %s, prompt: %s, index: %d, contextMatch: %s",
|
1765
|
-
type,
|
1766
|
-
prompt,
|
1767
|
-
i,
|
1768
|
-
contextHash ? "yes" : "no-context"
|
1769
|
-
);
|
1770
|
-
return {
|
1771
|
-
cacheContent: item,
|
1772
|
-
updateFn: (cb) => {
|
1773
|
-
debug3(
|
1774
|
-
"will call updateFn to update cache, type: %s, prompt: %s, index: %d",
|
1775
|
-
type,
|
1776
|
-
prompt,
|
1777
|
-
i
|
1778
|
-
);
|
1779
|
-
cb(item);
|
1780
|
-
debug3(
|
1781
|
-
"cache updated, will flush to file, type: %s, prompt: %s, index: %d",
|
1782
|
-
type,
|
1783
|
-
prompt,
|
1784
|
-
i
|
1785
|
-
);
|
1786
|
-
this.flushCacheToFile();
|
1787
|
-
}
|
1788
|
-
};
|
1789
1776
|
}
|
1790
|
-
debug3("no unused cache found, type: %s, prompt: %s
|
1777
|
+
debug3("no unused cache found, type: %s, prompt: %s", type, prompt);
|
1791
1778
|
return void 0;
|
1792
1779
|
}
|
1793
|
-
|
1794
|
-
|
1795
|
-
const stableString = sortedKeys.map((key) => `${key}:${JSON.stringify(contextData[key])}`).join("|");
|
1796
|
-
let hash = 0;
|
1797
|
-
for (let i = 0; i < stableString.length; i++) {
|
1798
|
-
const char = stableString.charCodeAt(i);
|
1799
|
-
hash = (hash << 5) - hash + char;
|
1800
|
-
hash = hash & hash;
|
1801
|
-
}
|
1802
|
-
return hash.toString(36);
|
1803
|
-
}
|
1804
|
-
matchPlanCache(prompt, contextData) {
|
1805
|
-
return this.matchCache(prompt, "plan", contextData);
|
1780
|
+
matchPlanCache(prompt) {
|
1781
|
+
return this.matchCache(prompt, "plan");
|
1806
1782
|
}
|
1807
1783
|
matchLocateCache(prompt) {
|
1808
1784
|
return this.matchCache(prompt, "locate");
|
@@ -1878,16 +1854,11 @@ cache file: ${cacheFile}`
|
|
1878
1854
|
);
|
1879
1855
|
}
|
1880
1856
|
}
|
1881
|
-
updateOrAppendCacheRecord(newRecord, cachedRecord
|
1857
|
+
updateOrAppendCacheRecord(newRecord, cachedRecord) {
|
1882
1858
|
if (cachedRecord) {
|
1883
1859
|
if (newRecord.type === "plan") {
|
1884
1860
|
cachedRecord.updateFn((cache) => {
|
1885
|
-
|
1886
|
-
planCache.yamlWorkflow = newRecord.yamlWorkflow;
|
1887
|
-
if (contextData) {
|
1888
|
-
planCache.contextHash = this.generateContextHash(contextData);
|
1889
|
-
planCache.contextData = { ...contextData };
|
1890
|
-
}
|
1861
|
+
cache.yamlWorkflow = newRecord.yamlWorkflow;
|
1891
1862
|
});
|
1892
1863
|
} else {
|
1893
1864
|
cachedRecord.updateFn((cache) => {
|
@@ -1895,11 +1866,6 @@ cache file: ${cacheFile}`
|
|
1895
1866
|
});
|
1896
1867
|
}
|
1897
1868
|
} else {
|
1898
|
-
if (newRecord.type === "plan" && contextData) {
|
1899
|
-
const planRecord = newRecord;
|
1900
|
-
planRecord.contextHash = this.generateContextHash(contextData);
|
1901
|
-
planRecord.contextData = { ...contextData };
|
1902
|
-
}
|
1903
1869
|
this.appendCache(newRecord);
|
1904
1870
|
}
|
1905
1871
|
}
|
@@ -1929,13 +1895,10 @@ var PageAgent = class {
|
|
1929
1895
|
generateReport: true,
|
1930
1896
|
autoPrintReportMsg: true,
|
1931
1897
|
groupName: "Midscene Report",
|
1932
|
-
groupDescription: ""
|
1933
|
-
enableCumulativeContext: true,
|
1934
|
-
autoClearContext: false
|
1898
|
+
groupDescription: ""
|
1935
1899
|
},
|
1936
1900
|
opts || {}
|
1937
1901
|
);
|
1938
|
-
this.initializeContextStore();
|
1939
1902
|
if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
|
1940
1903
|
this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || import_constants2.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
|
1941
1904
|
this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || import_constants2.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
|
@@ -1962,69 +1925,6 @@ var PageAgent = class {
|
|
1962
1925
|
opts?.testId || this.page.pageType || "web"
|
1963
1926
|
);
|
1964
1927
|
}
|
1965
|
-
/**
|
1966
|
-
* Initialize context store for cumulative context functionality
|
1967
|
-
*/
|
1968
|
-
async initializeContextStore() {
|
1969
|
-
if (!this.opts.enableCumulativeContext) {
|
1970
|
-
debug4("Cumulative context disabled via options");
|
1971
|
-
return;
|
1972
|
-
}
|
1973
|
-
try {
|
1974
|
-
const aiModel = await import("misoai-core/ai-model");
|
1975
|
-
this.contextStore = aiModel.getContextStore();
|
1976
|
-
debug4("Context store initialized successfully", {
|
1977
|
-
autoClearContext: this.opts.autoClearContext,
|
1978
|
-
testId: this.opts.testId
|
1979
|
-
});
|
1980
|
-
if (this.opts.autoClearContext) {
|
1981
|
-
this.contextStore.clear();
|
1982
|
-
debug4("Context store cleared due to autoClearContext option");
|
1983
|
-
} else {
|
1984
|
-
const existingData = this.contextStore.getAllData();
|
1985
|
-
const existingSteps = this.contextStore.getRecentSteps(100).length;
|
1986
|
-
debug4("Context store preserving existing data", {
|
1987
|
-
existingDataKeys: Object.keys(existingData),
|
1988
|
-
existingStepsCount: existingSteps
|
1989
|
-
});
|
1990
|
-
}
|
1991
|
-
} catch (error) {
|
1992
|
-
debug4("Failed to initialize context store:", error);
|
1993
|
-
console.warn("⚠️ Could not initialize context store:", error);
|
1994
|
-
}
|
1995
|
-
}
|
1996
|
-
/**
|
1997
|
-
* Get the context store instance
|
1998
|
-
*/
|
1999
|
-
getContextStore() {
|
2000
|
-
return this.contextStore;
|
2001
|
-
}
|
2002
|
-
/**
|
2003
|
-
* Clear the context store
|
2004
|
-
*/
|
2005
|
-
clearContext() {
|
2006
|
-
if (this.contextStore) {
|
2007
|
-
this.contextStore.clear();
|
2008
|
-
}
|
2009
|
-
}
|
2010
|
-
/**
|
2011
|
-
* Get all stored data from context store
|
2012
|
-
*/
|
2013
|
-
getStoredData() {
|
2014
|
-
if (this.contextStore) {
|
2015
|
-
return this.contextStore.getAllData();
|
2016
|
-
}
|
2017
|
-
return {};
|
2018
|
-
}
|
2019
|
-
/**
|
2020
|
-
* Get step summary from context store
|
2021
|
-
*/
|
2022
|
-
getStepSummary() {
|
2023
|
-
if (this.contextStore) {
|
2024
|
-
return this.contextStore.getStepSummary();
|
2025
|
-
}
|
2026
|
-
return "";
|
2027
|
-
}
|
2028
1928
|
async getUIContext(action) {
|
2029
1929
|
if (action && (action === "extract" || action === "assert" || action === "captcha")) {
|
2030
1930
|
return await parseContextFromWebPage(this.page, {
|
@@ -2260,35 +2160,9 @@ var PageAgent = class {
|
|
2260
2160
|
};
|
2261
2161
|
}
|
2262
2162
|
async aiAction(taskPrompt, opt) {
|
2263
|
-
const originalPrompt = taskPrompt;
|
2264
|
-
let processedPrompt = taskPrompt;
|
2265
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2266
|
-
try {
|
2267
|
-
const storedData = this.contextStore.getAllData();
|
2268
|
-
if (Object.keys(storedData).length > 0) {
|
2269
|
-
debug4("Available data for aiAction:", {
|
2270
|
-
prompt: taskPrompt,
|
2271
|
-
availableData: storedData
|
2272
|
-
});
|
2273
|
-
}
|
2274
|
-
} catch (error) {
|
2275
|
-
debug4("Context store operation failed:", error);
|
2276
|
-
}
|
2277
|
-
}
|
2278
2163
|
const cacheable = opt?.cacheable;
|
2279
2164
|
const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
|
2280
|
-
|
2281
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2282
|
-
try {
|
2283
|
-
contextData = this.contextStore.getAllData();
|
2284
|
-
if (contextData && Object.keys(contextData).length === 0) {
|
2285
|
-
contextData = void 0;
|
2286
|
-
}
|
2287
|
-
} catch (error) {
|
2288
|
-
debug4("Failed to get context data for cache:", error);
|
2289
|
-
}
|
2290
|
-
}
|
2291
|
-
const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt, contextData);
|
2165
|
+
const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
|
2292
2166
|
if (matchedCache && this.taskCache?.isCacheResultUsed) {
|
2293
2167
|
const { executor: executor2 } = await this.taskExecutor.loadYamlFlowAsPlanning(
|
2294
2168
|
taskPrompt,
|
@@ -2298,28 +2172,6 @@ var PageAgent = class {
|
|
2298
2172
|
debug4("matched cache, will call .runYaml to run the action");
|
2299
2173
|
const yaml5 = matchedCache.cacheContent?.yamlWorkflow;
|
2300
2174
|
const result = await this.runYaml(yaml5);
|
2301
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2302
|
-
try {
|
2303
|
-
const executionResult = {
|
2304
|
-
success: true,
|
2305
|
-
actionType: "cached",
|
2306
|
-
description: `Executed cached action: ${processedPrompt}`,
|
2307
|
-
timing: result.metadata?.totalTime
|
2308
|
-
};
|
2309
|
-
this.contextStore.addStep({
|
2310
|
-
type: "action",
|
2311
|
-
summary: `Action: ${processedPrompt} (cached)`,
|
2312
|
-
prompt: processedPrompt,
|
2313
|
-
executionResult
|
2314
|
-
});
|
2315
|
-
debug4("Added cached action step to context store:", {
|
2316
|
-
stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
|
2317
|
-
totalSteps: this.contextStore.getRecentSteps(100).length
|
2318
|
-
});
|
2319
|
-
} catch (error) {
|
2320
|
-
debug4("Failed to add cached action step:", error);
|
2321
|
-
}
|
2322
|
-
}
|
2323
2175
|
return {
|
2324
2176
|
result: result.result,
|
2325
2177
|
metadata: metadata2
|
@@ -2344,114 +2196,17 @@ var PageAgent = class {
|
|
2344
2196
|
prompt: taskPrompt,
|
2345
2197
|
yamlWorkflow: yamlFlowStr
|
2346
2198
|
},
|
2347
|
-
matchedCache
|
2348
|
-
contextData
|
2349
|
-
// Pass context data for cache creation
|
2199
|
+
matchedCache
|
2350
2200
|
);
|
2351
2201
|
}
|
2352
2202
|
const metadata = this.afterTaskRunning(executor);
|
2353
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2354
|
-
try {
|
2355
|
-
const executionResult = this.analyzeExecutionResults(executor, originalPrompt);
|
2356
|
-
this.contextStore.addStep({
|
2357
|
-
type: "action",
|
2358
|
-
summary: `Action: ${processedPrompt}`,
|
2359
|
-
prompt: processedPrompt,
|
2360
|
-
executionResult
|
2361
|
-
});
|
2362
|
-
debug4("Added action step with execution result to context store:", {
|
2363
|
-
stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
|
2364
|
-
totalSteps: this.contextStore.getRecentSteps(100).length,
|
2365
|
-
executionResult
|
2366
|
-
});
|
2367
|
-
} catch (error) {
|
2368
|
-
debug4("Failed to analyze execution results, adding step without execution result:", error);
|
2369
|
-
try {
|
2370
|
-
this.contextStore.addStep({
|
2371
|
-
type: "action",
|
2372
|
-
summary: `Action: ${processedPrompt}`,
|
2373
|
-
prompt: processedPrompt
|
2374
|
-
});
|
2375
|
-
} catch (stepError) {
|
2376
|
-
debug4("Failed to add action step:", stepError);
|
2377
|
-
}
|
2378
|
-
}
|
2379
|
-
}
|
2380
2203
|
return {
|
2381
2204
|
result: output,
|
2382
2205
|
metadata
|
2383
2206
|
};
|
2384
2207
|
}
|
2385
2208
|
async aiQuery(demand) {
|
2386
|
-
|
2387
|
-
let storageKey;
|
2388
|
-
try {
|
2389
|
-
const aiModel = await import("misoai-core/ai-model");
|
2390
|
-
const contextStore = aiModel.getContextStore();
|
2391
|
-
if (typeof demand === "string") {
|
2392
|
-
const storageInstruction = contextStore.parseStorageInstruction(demand);
|
2393
|
-
if (storageInstruction) {
|
2394
|
-
storageKey = storageInstruction.key;
|
2395
|
-
processedDemand = storageInstruction.cleanText;
|
2396
|
-
contextStore._pendingAliases = storageInstruction.aliases;
|
2397
|
-
} else {
|
2398
|
-
const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
|
2399
|
-
if (storageMatch) {
|
2400
|
-
storageKey = storageMatch[1];
|
2401
|
-
processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
|
2402
|
-
}
|
2403
|
-
}
|
2404
|
-
}
|
2405
|
-
} catch (error) {
|
2406
|
-
debug4("Context store not available:", error);
|
2407
|
-
}
|
2408
|
-
const { output, executor } = await this.taskExecutor.query(processedDemand);
|
2409
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2410
|
-
if (storageKey && output) {
|
2411
|
-
try {
|
2412
|
-
const pendingAliases = this.contextStore._pendingAliases;
|
2413
|
-
if (pendingAliases) {
|
2414
|
-
this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
|
2415
|
-
delete this.contextStore._pendingAliases;
|
2416
|
-
debug4("Stored query result with aliases:", {
|
2417
|
-
key: storageKey,
|
2418
|
-
value: output,
|
2419
|
-
aliases: pendingAliases
|
2420
|
-
});
|
2421
|
-
} else {
|
2422
|
-
this.contextStore.storeData(storageKey, output);
|
2423
|
-
debug4("Stored query result:", {
|
2424
|
-
key: storageKey,
|
2425
|
-
value: output
|
2426
|
-
});
|
2427
|
-
}
|
2428
|
-
this.contextStore.addStep({
|
2429
|
-
type: "query",
|
2430
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
|
2431
|
-
data: output,
|
2432
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2433
|
-
});
|
2434
|
-
debug4("Added query step to context store:", {
|
2435
|
-
storageKey,
|
2436
|
-
totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
|
2437
|
-
totalSteps: this.contextStore.getRecentSteps(100).length
|
2438
|
-
});
|
2439
|
-
} catch (error) {
|
2440
|
-
debug4("Failed to store query result:", error);
|
2441
|
-
}
|
2442
|
-
} else {
|
2443
|
-
try {
|
2444
|
-
this.contextStore.addStep({
|
2445
|
-
type: "query",
|
2446
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
|
2447
|
-
data: output,
|
2448
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2449
|
-
});
|
2450
|
-
} catch (error) {
|
2451
|
-
debug4("Failed to add query step:", error);
|
2452
|
-
}
|
2453
|
-
}
|
2454
|
-
}
|
2209
|
+
const { output, executor } = await this.taskExecutor.query(demand);
|
2455
2210
|
const metadata = this.afterTaskRunning(executor);
|
2456
2211
|
return {
|
2457
2212
|
result: output,
|
@@ -2561,48 +2316,6 @@ var PageAgent = class {
|
|
2561
2316
|
};
|
2562
2317
|
}
|
2563
2318
|
async aiAssert(assertion, msg, opt) {
|
2564
|
-
let executionContext = "";
|
2565
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2566
|
-
try {
|
2567
|
-
const recentSteps = this.contextStore.getRecentSteps(3);
|
2568
|
-
const stepsWithExecutionResults = recentSteps.filter((step) => step.executionResult);
|
2569
|
-
const storedData = this.contextStore.getAllData();
|
2570
|
-
if (stepsWithExecutionResults.length > 0) {
|
2571
|
-
const recentActions = stepsWithExecutionResults.map((step) => {
|
2572
|
-
const result = step.executionResult;
|
2573
|
-
return `- ${result.description}${result.success ? "" : " (FAILED)"}`;
|
2574
|
-
}).join("\n");
|
2575
|
-
executionContext = `
|
2576
|
-
|
2577
|
-
Recent actions performed:
|
2578
|
-
${recentActions}
|
2579
|
-
|
2580
|
-
This context may help verify the assertion.`;
|
2581
|
-
}
|
2582
|
-
if (storedData && Object.keys(storedData).length > 0) {
|
2583
|
-
executionContext += `
|
2584
|
-
|
2585
|
-
Available data for reference:
|
2586
|
-
${JSON.stringify(storedData, null, 2)}
|
2587
|
-
|
2588
|
-
Note: If the assertion references any data keys or natural language equivalents, consider the stored values when verifying.`;
|
2589
|
-
debug4("Available data for aiAssert:", {
|
2590
|
-
assertion,
|
2591
|
-
availableData: storedData
|
2592
|
-
});
|
2593
|
-
}
|
2594
|
-
this.contextStore.addStep({
|
2595
|
-
type: "assertion",
|
2596
|
-
summary: `Assertion: ${assertion}`,
|
2597
|
-
prompt: assertion
|
2598
|
-
});
|
2599
|
-
debug4("Added assertion step to context store:", {
|
2600
|
-
totalSteps: this.contextStore.getRecentSteps(100).length
|
2601
|
-
});
|
2602
|
-
} catch (error) {
|
2603
|
-
debug4("Context store operation failed:", error);
|
2604
|
-
}
|
2605
|
-
}
|
2606
2319
|
let currentUrl = "";
|
2607
2320
|
if (this.page.url) {
|
2608
2321
|
try {
|
@@ -2610,13 +2323,7 @@ Note: If the assertion references any data keys or natural language equivalents,
|
|
2610
2323
|
} catch (e) {
|
2611
2324
|
}
|
2612
2325
|
}
|
2613
|
-
|
2614
|
-
if (currentUrl) {
|
2615
|
-
assertionWithContext = `For the page at URL "${currentUrl}", ${assertion}`;
|
2616
|
-
}
|
2617
|
-
if (executionContext) {
|
2618
|
-
assertionWithContext += executionContext;
|
2619
|
-
}
|
2326
|
+
const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
|
2620
2327
|
const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
|
2621
2328
|
const metadata = this.afterTaskRunning(executor, true);
|
2622
2329
|
if (output && opt?.keepRawResponse) {
|
@@ -2830,79 +2537,6 @@ ${errors}`);
|
|
2830
2537
|
async destroy() {
|
2831
2538
|
await this.page.destroy();
|
2832
2539
|
}
|
2833
|
-
/**
|
2834
|
-
* Analyze execution results from executor to generate meaningful descriptions
|
2835
|
-
*/
|
2836
|
-
analyzeExecutionResults(executor, originalPrompt) {
|
2837
|
-
const tasks = executor.tasks;
|
2838
|
-
const success = !executor.isInErrorState();
|
2839
|
-
if (!success) {
|
2840
|
-
const errorTask = executor.latestErrorTask();
|
2841
|
-
return {
|
2842
|
-
success: false,
|
2843
|
-
actionType: "error",
|
2844
|
-
description: `Failed to execute: ${originalPrompt}`,
|
2845
|
-
error: errorTask?.error
|
2846
|
-
};
|
2847
|
-
}
|
2848
|
-
const actionTasks = tasks.filter((t) => t.type === "Action" && t.status === "finished");
|
2849
|
-
const locateTasks = tasks.filter((t) => t.type === "Insight" && t.subType === "Locate");
|
2850
|
-
const lastAction = actionTasks[actionTasks.length - 1];
|
2851
|
-
const lastLocate = locateTasks[locateTasks.length - 1];
|
2852
|
-
if (!lastAction) {
|
2853
|
-
return {
|
2854
|
-
success: true,
|
2855
|
-
actionType: "unknown",
|
2856
|
-
description: `Completed: ${originalPrompt}`
|
2857
|
-
};
|
2858
|
-
}
|
2859
|
-
const actionType = lastAction.subType || "unknown";
|
2860
|
-
const elementInfo = this.extractElementInfo(lastLocate, lastAction);
|
2861
|
-
const description = this.generateActionDescription(actionType, lastAction.param, elementInfo);
|
2862
|
-
return {
|
2863
|
-
success: true,
|
2864
|
-
actionType,
|
2865
|
-
description,
|
2866
|
-
elementInfo,
|
2867
|
-
timing: lastAction.timing?.cost
|
2868
|
-
};
|
2869
|
-
}
|
2870
|
-
/**
|
2871
|
-
* Extract element information from locate task
|
2872
|
-
*/
|
2873
|
-
extractElementInfo(locateTask, _actionTask) {
|
2874
|
-
if (!locateTask?.output?.element)
|
2875
|
-
return void 0;
|
2876
|
-
const element = locateTask.output.element;
|
2877
|
-
return {
|
2878
|
-
type: element.attributes?.nodeType || "unknown",
|
2879
|
-
text: element.content || element.attributes?.placeholder || element.attributes?.title || "",
|
2880
|
-
location: `(${element.center[0]}, ${element.center[1]})`
|
2881
|
-
};
|
2882
|
-
}
|
2883
|
-
/**
|
2884
|
-
* Generate natural language description for actions
|
2885
|
-
*/
|
2886
|
-
generateActionDescription(actionType, param, elementInfo) {
|
2887
|
-
const elementDesc = elementInfo ? `'${elementInfo.text || elementInfo.type}' element` : "element";
|
2888
|
-
switch (actionType) {
|
2889
|
-
case "Tap":
|
2890
|
-
return `Clicked on ${elementDesc}`;
|
2891
|
-
case "Input":
|
2892
|
-
const inputValue = param?.value || "";
|
2893
|
-
return `Entered "${inputValue}" into ${elementDesc}`;
|
2894
|
-
case "KeyboardPress":
|
2895
|
-
return `Pressed ${param?.value || "key"}`;
|
2896
|
-
case "Scroll":
|
2897
|
-
return `Scrolled ${param?.direction || "on page"}`;
|
2898
|
-
case "Hover":
|
2899
|
-
return `Hovered over ${elementDesc}`;
|
2900
|
-
case "Drag":
|
2901
|
-
return `Dragged ${elementDesc}`;
|
2902
|
-
default:
|
2903
|
-
return `Performed ${actionType} action on ${elementDesc}`;
|
2904
|
-
}
|
2905
|
-
}
|
2906
2540
|
};
|
2907
2541
|
|
2908
2542
|
// src/puppeteer/base-page.ts
|
@@ -2918,7 +2552,7 @@ var Page = class {
|
|
2918
2552
|
this.everMoved = false;
|
2919
2553
|
this.underlyingPage = underlyingPage;
|
2920
2554
|
this.pageType = pageType;
|
2921
|
-
this.waitForNavigationTimeout = opts?.waitForNavigationTimeout
|
2555
|
+
this.waitForNavigationTimeout = opts?.waitForNavigationTimeout ?? import_constants3.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
|
2922
2556
|
}
|
2923
2557
|
async evaluate(pageFunction, arg) {
|
2924
2558
|
let result;
|
@@ -3449,9 +3083,9 @@ var WebPage2 = class extends Page {
|
|
3449
3083
|
}
|
3450
3084
|
async waitUntilNetworkIdle(options) {
|
3451
3085
|
await this.underlyingPage.waitForNetworkIdle({
|
3452
|
-
idleTime: options?.idleTime
|
3453
|
-
concurrency: options?.concurrency
|
3454
|
-
timeout: options?.timeout
|
3086
|
+
idleTime: options?.idleTime ?? import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME,
|
3087
|
+
concurrency: options?.concurrency ?? import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
|
3088
|
+
timeout: options?.timeout ?? this.waitForNetworkIdleTimeout
|
3455
3089
|
});
|
3456
3090
|
}
|
3457
3091
|
};
|