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
@@ -22,10 +22,11 @@ var ScriptPlayer = class {
|
|
22
22
|
this.unnamedResultIndex = 0;
|
23
23
|
this.pageAgent = null;
|
24
24
|
this.result = {};
|
25
|
+
const target = script.target || script.web || script.android;
|
25
26
|
if (ifInBrowser) {
|
26
27
|
this.output = void 0;
|
27
|
-
} else if (
|
28
|
-
this.output = resolve(process.cwd(),
|
28
|
+
} else if (target?.output) {
|
29
|
+
this.output = resolve(process.cwd(), target.output);
|
29
30
|
} else {
|
30
31
|
this.output = join(getMidsceneRunSubDir("output"), `${process.pid}.json`);
|
31
32
|
}
|
@@ -99,12 +100,13 @@ var ScriptPlayer = class {
|
|
99
100
|
} else if ("aiAssert" in flowItem) {
|
100
101
|
const assertTask = flowItem;
|
101
102
|
const prompt = assertTask.aiAssert;
|
103
|
+
const msg = assertTask.errorMessage;
|
102
104
|
assert(prompt, "missing prompt for aiAssert");
|
103
105
|
assert(
|
104
106
|
typeof prompt === "string",
|
105
107
|
"prompt for aiAssert must be a string"
|
106
108
|
);
|
107
|
-
await agent.aiAssert(prompt);
|
109
|
+
await agent.aiAssert(prompt, msg);
|
108
110
|
} else if ("aiQuery" in flowItem) {
|
109
111
|
const queryTask = flowItem;
|
110
112
|
const prompt = queryTask.aiQuery;
|
@@ -1693,7 +1695,7 @@ import yaml3 from "js-yaml";
|
|
1693
1695
|
import semver from "semver";
|
1694
1696
|
|
1695
1697
|
// package.json
|
1696
|
-
var version = "1.
|
1698
|
+
var version = "1.5.6";
|
1697
1699
|
|
1698
1700
|
// src/common/task-cache.ts
|
1699
1701
|
var debug3 = getDebug3("cache");
|
@@ -1721,70 +1723,44 @@ var TaskCache = class {
|
|
1721
1723
|
this.cache = cacheContent;
|
1722
1724
|
this.cacheOriginalLength = this.cache.caches.length;
|
1723
1725
|
}
|
1724
|
-
matchCache(prompt, type
|
1725
|
-
const contextHash = contextData ? this.generateContextHash(contextData) : void 0;
|
1726
|
+
matchCache(prompt, type) {
|
1726
1727
|
for (let i = 0; i < this.cacheOriginalLength; i++) {
|
1727
1728
|
const item = this.cache.caches[i];
|
1728
1729
|
const key = `${type}:${prompt}:${i}`;
|
1729
|
-
if (item.type
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1730
|
+
if (item.type === type && item.prompt === prompt && !this.matchedCacheIndices.has(key)) {
|
1731
|
+
this.matchedCacheIndices.add(key);
|
1732
|
+
debug3(
|
1733
|
+
"cache found and marked as used, type: %s, prompt: %s, index: %d",
|
1734
|
+
type,
|
1735
|
+
prompt,
|
1736
|
+
i
|
1737
|
+
);
|
1738
|
+
return {
|
1739
|
+
cacheContent: item,
|
1740
|
+
updateFn: (cb) => {
|
1741
|
+
debug3(
|
1742
|
+
"will call updateFn to update cache, type: %s, prompt: %s, index: %d",
|
1743
|
+
type,
|
1744
|
+
prompt,
|
1745
|
+
i
|
1746
|
+
);
|
1747
|
+
cb(item);
|
1748
|
+
debug3(
|
1749
|
+
"cache updated, will flush to file, type: %s, prompt: %s, index: %d",
|
1750
|
+
type,
|
1751
|
+
prompt,
|
1752
|
+
i
|
1753
|
+
);
|
1754
|
+
this.flushCacheToFile();
|
1738
1755
|
}
|
1739
|
-
}
|
1740
|
-
debug3("cache context availability mismatch, type: %s, prompt: %s, index: %d", type, prompt, i);
|
1741
|
-
continue;
|
1742
|
-
}
|
1756
|
+
};
|
1743
1757
|
}
|
1744
|
-
this.matchedCacheIndices.add(key);
|
1745
|
-
debug3(
|
1746
|
-
"cache found and marked as used, type: %s, prompt: %s, index: %d, contextMatch: %s",
|
1747
|
-
type,
|
1748
|
-
prompt,
|
1749
|
-
i,
|
1750
|
-
contextHash ? "yes" : "no-context"
|
1751
|
-
);
|
1752
|
-
return {
|
1753
|
-
cacheContent: item,
|
1754
|
-
updateFn: (cb) => {
|
1755
|
-
debug3(
|
1756
|
-
"will call updateFn to update cache, type: %s, prompt: %s, index: %d",
|
1757
|
-
type,
|
1758
|
-
prompt,
|
1759
|
-
i
|
1760
|
-
);
|
1761
|
-
cb(item);
|
1762
|
-
debug3(
|
1763
|
-
"cache updated, will flush to file, type: %s, prompt: %s, index: %d",
|
1764
|
-
type,
|
1765
|
-
prompt,
|
1766
|
-
i
|
1767
|
-
);
|
1768
|
-
this.flushCacheToFile();
|
1769
|
-
}
|
1770
|
-
};
|
1771
1758
|
}
|
1772
|
-
debug3("no unused cache found, type: %s, prompt: %s
|
1759
|
+
debug3("no unused cache found, type: %s, prompt: %s", type, prompt);
|
1773
1760
|
return void 0;
|
1774
1761
|
}
|
1775
|
-
|
1776
|
-
|
1777
|
-
const stableString = sortedKeys.map((key) => `${key}:${JSON.stringify(contextData[key])}`).join("|");
|
1778
|
-
let hash = 0;
|
1779
|
-
for (let i = 0; i < stableString.length; i++) {
|
1780
|
-
const char = stableString.charCodeAt(i);
|
1781
|
-
hash = (hash << 5) - hash + char;
|
1782
|
-
hash = hash & hash;
|
1783
|
-
}
|
1784
|
-
return hash.toString(36);
|
1785
|
-
}
|
1786
|
-
matchPlanCache(prompt, contextData) {
|
1787
|
-
return this.matchCache(prompt, "plan", contextData);
|
1762
|
+
matchPlanCache(prompt) {
|
1763
|
+
return this.matchCache(prompt, "plan");
|
1788
1764
|
}
|
1789
1765
|
matchLocateCache(prompt) {
|
1790
1766
|
return this.matchCache(prompt, "locate");
|
@@ -1860,16 +1836,11 @@ cache file: ${cacheFile}`
|
|
1860
1836
|
);
|
1861
1837
|
}
|
1862
1838
|
}
|
1863
|
-
updateOrAppendCacheRecord(newRecord, cachedRecord
|
1839
|
+
updateOrAppendCacheRecord(newRecord, cachedRecord) {
|
1864
1840
|
if (cachedRecord) {
|
1865
1841
|
if (newRecord.type === "plan") {
|
1866
1842
|
cachedRecord.updateFn((cache) => {
|
1867
|
-
|
1868
|
-
planCache.yamlWorkflow = newRecord.yamlWorkflow;
|
1869
|
-
if (contextData) {
|
1870
|
-
planCache.contextHash = this.generateContextHash(contextData);
|
1871
|
-
planCache.contextData = { ...contextData };
|
1872
|
-
}
|
1843
|
+
cache.yamlWorkflow = newRecord.yamlWorkflow;
|
1873
1844
|
});
|
1874
1845
|
} else {
|
1875
1846
|
cachedRecord.updateFn((cache) => {
|
@@ -1877,11 +1848,6 @@ cache file: ${cacheFile}`
|
|
1877
1848
|
});
|
1878
1849
|
}
|
1879
1850
|
} else {
|
1880
|
-
if (newRecord.type === "plan" && contextData) {
|
1881
|
-
const planRecord = newRecord;
|
1882
|
-
planRecord.contextHash = this.generateContextHash(contextData);
|
1883
|
-
planRecord.contextData = { ...contextData };
|
1884
|
-
}
|
1885
1851
|
this.appendCache(newRecord);
|
1886
1852
|
}
|
1887
1853
|
}
|
@@ -1911,13 +1877,10 @@ var PageAgent = class {
|
|
1911
1877
|
generateReport: true,
|
1912
1878
|
autoPrintReportMsg: true,
|
1913
1879
|
groupName: "Midscene Report",
|
1914
|
-
groupDescription: ""
|
1915
|
-
enableCumulativeContext: true,
|
1916
|
-
autoClearContext: false
|
1880
|
+
groupDescription: ""
|
1917
1881
|
},
|
1918
1882
|
opts || {}
|
1919
1883
|
);
|
1920
|
-
this.initializeContextStore();
|
1921
1884
|
if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
|
1922
1885
|
this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
|
1923
1886
|
this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
|
@@ -1944,69 +1907,6 @@ var PageAgent = class {
|
|
1944
1907
|
opts?.testId || this.page.pageType || "web"
|
1945
1908
|
);
|
1946
1909
|
}
|
1947
|
-
/**
|
1948
|
-
* Initialize context store for cumulative context functionality
|
1949
|
-
*/
|
1950
|
-
async initializeContextStore() {
|
1951
|
-
if (!this.opts.enableCumulativeContext) {
|
1952
|
-
debug4("Cumulative context disabled via options");
|
1953
|
-
return;
|
1954
|
-
}
|
1955
|
-
try {
|
1956
|
-
const aiModel = await import("misoai-core/ai-model");
|
1957
|
-
this.contextStore = aiModel.getContextStore();
|
1958
|
-
debug4("Context store initialized successfully", {
|
1959
|
-
autoClearContext: this.opts.autoClearContext,
|
1960
|
-
testId: this.opts.testId
|
1961
|
-
});
|
1962
|
-
if (this.opts.autoClearContext) {
|
1963
|
-
this.contextStore.clear();
|
1964
|
-
debug4("Context store cleared due to autoClearContext option");
|
1965
|
-
} else {
|
1966
|
-
const existingData = this.contextStore.getAllData();
|
1967
|
-
const existingSteps = this.contextStore.getRecentSteps(100).length;
|
1968
|
-
debug4("Context store preserving existing data", {
|
1969
|
-
existingDataKeys: Object.keys(existingData),
|
1970
|
-
existingStepsCount: existingSteps
|
1971
|
-
});
|
1972
|
-
}
|
1973
|
-
} catch (error) {
|
1974
|
-
debug4("Failed to initialize context store:", error);
|
1975
|
-
console.warn("⚠️ Could not initialize context store:", error);
|
1976
|
-
}
|
1977
|
-
}
|
1978
|
-
/**
|
1979
|
-
* Get the context store instance
|
1980
|
-
*/
|
1981
|
-
getContextStore() {
|
1982
|
-
return this.contextStore;
|
1983
|
-
}
|
1984
|
-
/**
|
1985
|
-
* Clear the context store
|
1986
|
-
*/
|
1987
|
-
clearContext() {
|
1988
|
-
if (this.contextStore) {
|
1989
|
-
this.contextStore.clear();
|
1990
|
-
}
|
1991
|
-
}
|
1992
|
-
/**
|
1993
|
-
* Get all stored data from context store
|
1994
|
-
*/
|
1995
|
-
getStoredData() {
|
1996
|
-
if (this.contextStore) {
|
1997
|
-
return this.contextStore.getAllData();
|
1998
|
-
}
|
1999
|
-
return {};
|
2000
|
-
}
|
2001
|
-
/**
|
2002
|
-
* Get step summary from context store
|
2003
|
-
*/
|
2004
|
-
getStepSummary() {
|
2005
|
-
if (this.contextStore) {
|
2006
|
-
return this.contextStore.getStepSummary();
|
2007
|
-
}
|
2008
|
-
return "";
|
2009
|
-
}
|
2010
1910
|
async getUIContext(action) {
|
2011
1911
|
if (action && (action === "extract" || action === "assert" || action === "captcha")) {
|
2012
1912
|
return await parseContextFromWebPage(this.page, {
|
@@ -2242,35 +2142,9 @@ var PageAgent = class {
|
|
2242
2142
|
};
|
2243
2143
|
}
|
2244
2144
|
async aiAction(taskPrompt, opt) {
|
2245
|
-
const originalPrompt = taskPrompt;
|
2246
|
-
let processedPrompt = taskPrompt;
|
2247
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2248
|
-
try {
|
2249
|
-
const storedData = this.contextStore.getAllData();
|
2250
|
-
if (Object.keys(storedData).length > 0) {
|
2251
|
-
debug4("Available data for aiAction:", {
|
2252
|
-
prompt: taskPrompt,
|
2253
|
-
availableData: storedData
|
2254
|
-
});
|
2255
|
-
}
|
2256
|
-
} catch (error) {
|
2257
|
-
debug4("Context store operation failed:", error);
|
2258
|
-
}
|
2259
|
-
}
|
2260
2145
|
const cacheable = opt?.cacheable;
|
2261
2146
|
const isVlmUiTars = vlLocateMode() === "vlm-ui-tars";
|
2262
|
-
|
2263
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2264
|
-
try {
|
2265
|
-
contextData = this.contextStore.getAllData();
|
2266
|
-
if (contextData && Object.keys(contextData).length === 0) {
|
2267
|
-
contextData = void 0;
|
2268
|
-
}
|
2269
|
-
} catch (error) {
|
2270
|
-
debug4("Failed to get context data for cache:", error);
|
2271
|
-
}
|
2272
|
-
}
|
2273
|
-
const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt, contextData);
|
2147
|
+
const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
|
2274
2148
|
if (matchedCache && this.taskCache?.isCacheResultUsed) {
|
2275
2149
|
const { executor: executor2 } = await this.taskExecutor.loadYamlFlowAsPlanning(
|
2276
2150
|
taskPrompt,
|
@@ -2280,28 +2154,6 @@ var PageAgent = class {
|
|
2280
2154
|
debug4("matched cache, will call .runYaml to run the action");
|
2281
2155
|
const yaml5 = matchedCache.cacheContent?.yamlWorkflow;
|
2282
2156
|
const result = await this.runYaml(yaml5);
|
2283
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2284
|
-
try {
|
2285
|
-
const executionResult = {
|
2286
|
-
success: true,
|
2287
|
-
actionType: "cached",
|
2288
|
-
description: `Executed cached action: ${processedPrompt}`,
|
2289
|
-
timing: result.metadata?.totalTime
|
2290
|
-
};
|
2291
|
-
this.contextStore.addStep({
|
2292
|
-
type: "action",
|
2293
|
-
summary: `Action: ${processedPrompt} (cached)`,
|
2294
|
-
prompt: processedPrompt,
|
2295
|
-
executionResult
|
2296
|
-
});
|
2297
|
-
debug4("Added cached action step to context store:", {
|
2298
|
-
stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
|
2299
|
-
totalSteps: this.contextStore.getRecentSteps(100).length
|
2300
|
-
});
|
2301
|
-
} catch (error) {
|
2302
|
-
debug4("Failed to add cached action step:", error);
|
2303
|
-
}
|
2304
|
-
}
|
2305
2157
|
return {
|
2306
2158
|
result: result.result,
|
2307
2159
|
metadata: metadata2
|
@@ -2326,114 +2178,17 @@ var PageAgent = class {
|
|
2326
2178
|
prompt: taskPrompt,
|
2327
2179
|
yamlWorkflow: yamlFlowStr
|
2328
2180
|
},
|
2329
|
-
matchedCache
|
2330
|
-
contextData
|
2331
|
-
// Pass context data for cache creation
|
2181
|
+
matchedCache
|
2332
2182
|
);
|
2333
2183
|
}
|
2334
2184
|
const metadata = this.afterTaskRunning(executor);
|
2335
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2336
|
-
try {
|
2337
|
-
const executionResult = this.analyzeExecutionResults(executor, originalPrompt);
|
2338
|
-
this.contextStore.addStep({
|
2339
|
-
type: "action",
|
2340
|
-
summary: `Action: ${processedPrompt}`,
|
2341
|
-
prompt: processedPrompt,
|
2342
|
-
executionResult
|
2343
|
-
});
|
2344
|
-
debug4("Added action step with execution result to context store:", {
|
2345
|
-
stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
|
2346
|
-
totalSteps: this.contextStore.getRecentSteps(100).length,
|
2347
|
-
executionResult
|
2348
|
-
});
|
2349
|
-
} catch (error) {
|
2350
|
-
debug4("Failed to analyze execution results, adding step without execution result:", error);
|
2351
|
-
try {
|
2352
|
-
this.contextStore.addStep({
|
2353
|
-
type: "action",
|
2354
|
-
summary: `Action: ${processedPrompt}`,
|
2355
|
-
prompt: processedPrompt
|
2356
|
-
});
|
2357
|
-
} catch (stepError) {
|
2358
|
-
debug4("Failed to add action step:", stepError);
|
2359
|
-
}
|
2360
|
-
}
|
2361
|
-
}
|
2362
2185
|
return {
|
2363
2186
|
result: output,
|
2364
2187
|
metadata
|
2365
2188
|
};
|
2366
2189
|
}
|
2367
2190
|
async aiQuery(demand) {
|
2368
|
-
|
2369
|
-
let storageKey;
|
2370
|
-
try {
|
2371
|
-
const aiModel = await import("misoai-core/ai-model");
|
2372
|
-
const contextStore = aiModel.getContextStore();
|
2373
|
-
if (typeof demand === "string") {
|
2374
|
-
const storageInstruction = contextStore.parseStorageInstruction(demand);
|
2375
|
-
if (storageInstruction) {
|
2376
|
-
storageKey = storageInstruction.key;
|
2377
|
-
processedDemand = storageInstruction.cleanText;
|
2378
|
-
contextStore._pendingAliases = storageInstruction.aliases;
|
2379
|
-
} else {
|
2380
|
-
const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
|
2381
|
-
if (storageMatch) {
|
2382
|
-
storageKey = storageMatch[1];
|
2383
|
-
processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
|
2384
|
-
}
|
2385
|
-
}
|
2386
|
-
}
|
2387
|
-
} catch (error) {
|
2388
|
-
debug4("Context store not available:", error);
|
2389
|
-
}
|
2390
|
-
const { output, executor } = await this.taskExecutor.query(processedDemand);
|
2391
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2392
|
-
if (storageKey && output) {
|
2393
|
-
try {
|
2394
|
-
const pendingAliases = this.contextStore._pendingAliases;
|
2395
|
-
if (pendingAliases) {
|
2396
|
-
this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
|
2397
|
-
delete this.contextStore._pendingAliases;
|
2398
|
-
debug4("Stored query result with aliases:", {
|
2399
|
-
key: storageKey,
|
2400
|
-
value: output,
|
2401
|
-
aliases: pendingAliases
|
2402
|
-
});
|
2403
|
-
} else {
|
2404
|
-
this.contextStore.storeData(storageKey, output);
|
2405
|
-
debug4("Stored query result:", {
|
2406
|
-
key: storageKey,
|
2407
|
-
value: output
|
2408
|
-
});
|
2409
|
-
}
|
2410
|
-
this.contextStore.addStep({
|
2411
|
-
type: "query",
|
2412
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
|
2413
|
-
data: output,
|
2414
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2415
|
-
});
|
2416
|
-
debug4("Added query step to context store:", {
|
2417
|
-
storageKey,
|
2418
|
-
totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
|
2419
|
-
totalSteps: this.contextStore.getRecentSteps(100).length
|
2420
|
-
});
|
2421
|
-
} catch (error) {
|
2422
|
-
debug4("Failed to store query result:", error);
|
2423
|
-
}
|
2424
|
-
} else {
|
2425
|
-
try {
|
2426
|
-
this.contextStore.addStep({
|
2427
|
-
type: "query",
|
2428
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
|
2429
|
-
data: output,
|
2430
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2431
|
-
});
|
2432
|
-
} catch (error) {
|
2433
|
-
debug4("Failed to add query step:", error);
|
2434
|
-
}
|
2435
|
-
}
|
2436
|
-
}
|
2191
|
+
const { output, executor } = await this.taskExecutor.query(demand);
|
2437
2192
|
const metadata = this.afterTaskRunning(executor);
|
2438
2193
|
return {
|
2439
2194
|
result: output,
|
@@ -2543,48 +2298,6 @@ var PageAgent = class {
|
|
2543
2298
|
};
|
2544
2299
|
}
|
2545
2300
|
async aiAssert(assertion, msg, opt) {
|
2546
|
-
let executionContext = "";
|
2547
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2548
|
-
try {
|
2549
|
-
const recentSteps = this.contextStore.getRecentSteps(3);
|
2550
|
-
const stepsWithExecutionResults = recentSteps.filter((step) => step.executionResult);
|
2551
|
-
const storedData = this.contextStore.getAllData();
|
2552
|
-
if (stepsWithExecutionResults.length > 0) {
|
2553
|
-
const recentActions = stepsWithExecutionResults.map((step) => {
|
2554
|
-
const result = step.executionResult;
|
2555
|
-
return `- ${result.description}${result.success ? "" : " (FAILED)"}`;
|
2556
|
-
}).join("\n");
|
2557
|
-
executionContext = `
|
2558
|
-
|
2559
|
-
Recent actions performed:
|
2560
|
-
${recentActions}
|
2561
|
-
|
2562
|
-
This context may help verify the assertion.`;
|
2563
|
-
}
|
2564
|
-
if (storedData && Object.keys(storedData).length > 0) {
|
2565
|
-
executionContext += `
|
2566
|
-
|
2567
|
-
Available data for reference:
|
2568
|
-
${JSON.stringify(storedData, null, 2)}
|
2569
|
-
|
2570
|
-
Note: If the assertion references any data keys or natural language equivalents, consider the stored values when verifying.`;
|
2571
|
-
debug4("Available data for aiAssert:", {
|
2572
|
-
assertion,
|
2573
|
-
availableData: storedData
|
2574
|
-
});
|
2575
|
-
}
|
2576
|
-
this.contextStore.addStep({
|
2577
|
-
type: "assertion",
|
2578
|
-
summary: `Assertion: ${assertion}`,
|
2579
|
-
prompt: assertion
|
2580
|
-
});
|
2581
|
-
debug4("Added assertion step to context store:", {
|
2582
|
-
totalSteps: this.contextStore.getRecentSteps(100).length
|
2583
|
-
});
|
2584
|
-
} catch (error) {
|
2585
|
-
debug4("Context store operation failed:", error);
|
2586
|
-
}
|
2587
|
-
}
|
2588
2301
|
let currentUrl = "";
|
2589
2302
|
if (this.page.url) {
|
2590
2303
|
try {
|
@@ -2592,13 +2305,7 @@ Note: If the assertion references any data keys or natural language equivalents,
|
|
2592
2305
|
} catch (e) {
|
2593
2306
|
}
|
2594
2307
|
}
|
2595
|
-
|
2596
|
-
if (currentUrl) {
|
2597
|
-
assertionWithContext = `For the page at URL "${currentUrl}", ${assertion}`;
|
2598
|
-
}
|
2599
|
-
if (executionContext) {
|
2600
|
-
assertionWithContext += executionContext;
|
2601
|
-
}
|
2308
|
+
const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
|
2602
2309
|
const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
|
2603
2310
|
const metadata = this.afterTaskRunning(executor, true);
|
2604
2311
|
if (output && opt?.keepRawResponse) {
|
@@ -2812,79 +2519,6 @@ ${errors}`);
|
|
2812
2519
|
async destroy() {
|
2813
2520
|
await this.page.destroy();
|
2814
2521
|
}
|
2815
|
-
/**
|
2816
|
-
* Analyze execution results from executor to generate meaningful descriptions
|
2817
|
-
*/
|
2818
|
-
analyzeExecutionResults(executor, originalPrompt) {
|
2819
|
-
const tasks = executor.tasks;
|
2820
|
-
const success = !executor.isInErrorState();
|
2821
|
-
if (!success) {
|
2822
|
-
const errorTask = executor.latestErrorTask();
|
2823
|
-
return {
|
2824
|
-
success: false,
|
2825
|
-
actionType: "error",
|
2826
|
-
description: `Failed to execute: ${originalPrompt}`,
|
2827
|
-
error: errorTask?.error
|
2828
|
-
};
|
2829
|
-
}
|
2830
|
-
const actionTasks = tasks.filter((t) => t.type === "Action" && t.status === "finished");
|
2831
|
-
const locateTasks = tasks.filter((t) => t.type === "Insight" && t.subType === "Locate");
|
2832
|
-
const lastAction = actionTasks[actionTasks.length - 1];
|
2833
|
-
const lastLocate = locateTasks[locateTasks.length - 1];
|
2834
|
-
if (!lastAction) {
|
2835
|
-
return {
|
2836
|
-
success: true,
|
2837
|
-
actionType: "unknown",
|
2838
|
-
description: `Completed: ${originalPrompt}`
|
2839
|
-
};
|
2840
|
-
}
|
2841
|
-
const actionType = lastAction.subType || "unknown";
|
2842
|
-
const elementInfo = this.extractElementInfo(lastLocate, lastAction);
|
2843
|
-
const description = this.generateActionDescription(actionType, lastAction.param, elementInfo);
|
2844
|
-
return {
|
2845
|
-
success: true,
|
2846
|
-
actionType,
|
2847
|
-
description,
|
2848
|
-
elementInfo,
|
2849
|
-
timing: lastAction.timing?.cost
|
2850
|
-
};
|
2851
|
-
}
|
2852
|
-
/**
|
2853
|
-
* Extract element information from locate task
|
2854
|
-
*/
|
2855
|
-
extractElementInfo(locateTask, _actionTask) {
|
2856
|
-
if (!locateTask?.output?.element)
|
2857
|
-
return void 0;
|
2858
|
-
const element = locateTask.output.element;
|
2859
|
-
return {
|
2860
|
-
type: element.attributes?.nodeType || "unknown",
|
2861
|
-
text: element.content || element.attributes?.placeholder || element.attributes?.title || "",
|
2862
|
-
location: `(${element.center[0]}, ${element.center[1]})`
|
2863
|
-
};
|
2864
|
-
}
|
2865
|
-
/**
|
2866
|
-
* Generate natural language description for actions
|
2867
|
-
*/
|
2868
|
-
generateActionDescription(actionType, param, elementInfo) {
|
2869
|
-
const elementDesc = elementInfo ? `'${elementInfo.text || elementInfo.type}' element` : "element";
|
2870
|
-
switch (actionType) {
|
2871
|
-
case "Tap":
|
2872
|
-
return `Clicked on ${elementDesc}`;
|
2873
|
-
case "Input":
|
2874
|
-
const inputValue = param?.value || "";
|
2875
|
-
return `Entered "${inputValue}" into ${elementDesc}`;
|
2876
|
-
case "KeyboardPress":
|
2877
|
-
return `Pressed ${param?.value || "key"}`;
|
2878
|
-
case "Scroll":
|
2879
|
-
return `Scrolled ${param?.direction || "on page"}`;
|
2880
|
-
case "Hover":
|
2881
|
-
return `Hovered over ${elementDesc}`;
|
2882
|
-
case "Drag":
|
2883
|
-
return `Dragged ${elementDesc}`;
|
2884
|
-
default:
|
2885
|
-
return `Performed ${actionType} action on ${elementDesc}`;
|
2886
|
-
}
|
2887
|
-
}
|
2888
2522
|
};
|
2889
2523
|
|
2890
2524
|
// src/puppeteer/index.ts
|
@@ -2914,7 +2548,7 @@ var Page = class {
|
|
2914
2548
|
this.everMoved = false;
|
2915
2549
|
this.underlyingPage = underlyingPage;
|
2916
2550
|
this.pageType = pageType;
|
2917
|
-
this.waitForNavigationTimeout = opts?.waitForNavigationTimeout
|
2551
|
+
this.waitForNavigationTimeout = opts?.waitForNavigationTimeout ?? DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT2;
|
2918
2552
|
}
|
2919
2553
|
async evaluate(pageFunction, arg) {
|
2920
2554
|
let result;
|
@@ -3194,9 +2828,9 @@ var WebPage = class extends Page {
|
|
3194
2828
|
}
|
3195
2829
|
async waitUntilNetworkIdle(options) {
|
3196
2830
|
await this.underlyingPage.waitForNetworkIdle({
|
3197
|
-
idleTime: options?.idleTime
|
3198
|
-
concurrency: options?.concurrency
|
3199
|
-
timeout: options?.timeout
|
2831
|
+
idleTime: options?.idleTime ?? DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME,
|
2832
|
+
concurrency: options?.concurrency ?? DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
|
2833
|
+
timeout: options?.timeout ?? this.waitForNetworkIdleTimeout
|
3200
2834
|
});
|
3201
2835
|
}
|
3202
2836
|
};
|