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
@@ -160,10 +160,11 @@ var ScriptPlayer = class {
|
|
160
160
|
this.unnamedResultIndex = 0;
|
161
161
|
this.pageAgent = null;
|
162
162
|
this.result = {};
|
163
|
+
const target = script.target || script.web || script.android;
|
163
164
|
if (ifInBrowser) {
|
164
165
|
this.output = void 0;
|
165
|
-
} else if (
|
166
|
-
this.output = resolve(process.cwd(),
|
166
|
+
} else if (target?.output) {
|
167
|
+
this.output = resolve(process.cwd(), target.output);
|
167
168
|
} else {
|
168
169
|
this.output = join(getMidsceneRunSubDir("output"), `${process.pid}.json`);
|
169
170
|
}
|
@@ -237,12 +238,13 @@ var ScriptPlayer = class {
|
|
237
238
|
} else if ("aiAssert" in flowItem) {
|
238
239
|
const assertTask = flowItem;
|
239
240
|
const prompt = assertTask.aiAssert;
|
241
|
+
const msg = assertTask.errorMessage;
|
240
242
|
assert2(prompt, "missing prompt for aiAssert");
|
241
243
|
assert2(
|
242
244
|
typeof prompt === "string",
|
243
245
|
"prompt for aiAssert must be a string"
|
244
246
|
);
|
245
|
-
await agent.aiAssert(prompt);
|
247
|
+
await agent.aiAssert(prompt, msg);
|
246
248
|
} else if ("aiQuery" in flowItem) {
|
247
249
|
const queryTask = flowItem;
|
248
250
|
const prompt = queryTask.aiQuery;
|
@@ -1707,7 +1709,7 @@ import yaml3 from "js-yaml";
|
|
1707
1709
|
import semver from "semver";
|
1708
1710
|
|
1709
1711
|
// package.json
|
1710
|
-
var version = "1.
|
1712
|
+
var version = "1.5.6";
|
1711
1713
|
|
1712
1714
|
// src/common/task-cache.ts
|
1713
1715
|
var debug3 = getDebug3("cache");
|
@@ -1735,70 +1737,44 @@ var TaskCache = class {
|
|
1735
1737
|
this.cache = cacheContent;
|
1736
1738
|
this.cacheOriginalLength = this.cache.caches.length;
|
1737
1739
|
}
|
1738
|
-
matchCache(prompt, type
|
1739
|
-
const contextHash = contextData ? this.generateContextHash(contextData) : void 0;
|
1740
|
+
matchCache(prompt, type) {
|
1740
1741
|
for (let i = 0; i < this.cacheOriginalLength; i++) {
|
1741
1742
|
const item = this.cache.caches[i];
|
1742
1743
|
const key = `${type}:${prompt}:${i}`;
|
1743
|
-
if (item.type
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1744
|
+
if (item.type === type && item.prompt === prompt && !this.matchedCacheIndices.has(key)) {
|
1745
|
+
this.matchedCacheIndices.add(key);
|
1746
|
+
debug3(
|
1747
|
+
"cache found and marked as used, type: %s, prompt: %s, index: %d",
|
1748
|
+
type,
|
1749
|
+
prompt,
|
1750
|
+
i
|
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();
|
1752
1769
|
}
|
1753
|
-
}
|
1754
|
-
debug3("cache context availability mismatch, type: %s, prompt: %s, index: %d", type, prompt, i);
|
1755
|
-
continue;
|
1756
|
-
}
|
1770
|
+
};
|
1757
1771
|
}
|
1758
|
-
this.matchedCacheIndices.add(key);
|
1759
|
-
debug3(
|
1760
|
-
"cache found and marked as used, type: %s, prompt: %s, index: %d, contextMatch: %s",
|
1761
|
-
type,
|
1762
|
-
prompt,
|
1763
|
-
i,
|
1764
|
-
contextHash ? "yes" : "no-context"
|
1765
|
-
);
|
1766
|
-
return {
|
1767
|
-
cacheContent: item,
|
1768
|
-
updateFn: (cb) => {
|
1769
|
-
debug3(
|
1770
|
-
"will call updateFn to update cache, type: %s, prompt: %s, index: %d",
|
1771
|
-
type,
|
1772
|
-
prompt,
|
1773
|
-
i
|
1774
|
-
);
|
1775
|
-
cb(item);
|
1776
|
-
debug3(
|
1777
|
-
"cache updated, will flush to file, type: %s, prompt: %s, index: %d",
|
1778
|
-
type,
|
1779
|
-
prompt,
|
1780
|
-
i
|
1781
|
-
);
|
1782
|
-
this.flushCacheToFile();
|
1783
|
-
}
|
1784
|
-
};
|
1785
1772
|
}
|
1786
|
-
debug3("no unused cache found, type: %s, prompt: %s
|
1773
|
+
debug3("no unused cache found, type: %s, prompt: %s", type, prompt);
|
1787
1774
|
return void 0;
|
1788
1775
|
}
|
1789
|
-
|
1790
|
-
|
1791
|
-
const stableString = sortedKeys.map((key) => `${key}:${JSON.stringify(contextData[key])}`).join("|");
|
1792
|
-
let hash = 0;
|
1793
|
-
for (let i = 0; i < stableString.length; i++) {
|
1794
|
-
const char = stableString.charCodeAt(i);
|
1795
|
-
hash = (hash << 5) - hash + char;
|
1796
|
-
hash = hash & hash;
|
1797
|
-
}
|
1798
|
-
return hash.toString(36);
|
1799
|
-
}
|
1800
|
-
matchPlanCache(prompt, contextData) {
|
1801
|
-
return this.matchCache(prompt, "plan", contextData);
|
1776
|
+
matchPlanCache(prompt) {
|
1777
|
+
return this.matchCache(prompt, "plan");
|
1802
1778
|
}
|
1803
1779
|
matchLocateCache(prompt) {
|
1804
1780
|
return this.matchCache(prompt, "locate");
|
@@ -1874,16 +1850,11 @@ cache file: ${cacheFile}`
|
|
1874
1850
|
);
|
1875
1851
|
}
|
1876
1852
|
}
|
1877
|
-
updateOrAppendCacheRecord(newRecord, cachedRecord
|
1853
|
+
updateOrAppendCacheRecord(newRecord, cachedRecord) {
|
1878
1854
|
if (cachedRecord) {
|
1879
1855
|
if (newRecord.type === "plan") {
|
1880
1856
|
cachedRecord.updateFn((cache) => {
|
1881
|
-
|
1882
|
-
planCache.yamlWorkflow = newRecord.yamlWorkflow;
|
1883
|
-
if (contextData) {
|
1884
|
-
planCache.contextHash = this.generateContextHash(contextData);
|
1885
|
-
planCache.contextData = { ...contextData };
|
1886
|
-
}
|
1857
|
+
cache.yamlWorkflow = newRecord.yamlWorkflow;
|
1887
1858
|
});
|
1888
1859
|
} else {
|
1889
1860
|
cachedRecord.updateFn((cache) => {
|
@@ -1891,11 +1862,6 @@ cache file: ${cacheFile}`
|
|
1891
1862
|
});
|
1892
1863
|
}
|
1893
1864
|
} else {
|
1894
|
-
if (newRecord.type === "plan" && contextData) {
|
1895
|
-
const planRecord = newRecord;
|
1896
|
-
planRecord.contextHash = this.generateContextHash(contextData);
|
1897
|
-
planRecord.contextData = { ...contextData };
|
1898
|
-
}
|
1899
1865
|
this.appendCache(newRecord);
|
1900
1866
|
}
|
1901
1867
|
}
|
@@ -1925,13 +1891,10 @@ var PageAgent = class {
|
|
1925
1891
|
generateReport: true,
|
1926
1892
|
autoPrintReportMsg: true,
|
1927
1893
|
groupName: "Midscene Report",
|
1928
|
-
groupDescription: ""
|
1929
|
-
enableCumulativeContext: true,
|
1930
|
-
autoClearContext: false
|
1894
|
+
groupDescription: ""
|
1931
1895
|
},
|
1932
1896
|
opts || {}
|
1933
1897
|
);
|
1934
|
-
this.initializeContextStore();
|
1935
1898
|
if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
|
1936
1899
|
this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
|
1937
1900
|
this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
|
@@ -1958,69 +1921,6 @@ var PageAgent = class {
|
|
1958
1921
|
opts?.testId || this.page.pageType || "web"
|
1959
1922
|
);
|
1960
1923
|
}
|
1961
|
-
/**
|
1962
|
-
* Initialize context store for cumulative context functionality
|
1963
|
-
*/
|
1964
|
-
async initializeContextStore() {
|
1965
|
-
if (!this.opts.enableCumulativeContext) {
|
1966
|
-
debug4("Cumulative context disabled via options");
|
1967
|
-
return;
|
1968
|
-
}
|
1969
|
-
try {
|
1970
|
-
const aiModel = await import("misoai-core/ai-model");
|
1971
|
-
this.contextStore = aiModel.getContextStore();
|
1972
|
-
debug4("Context store initialized successfully", {
|
1973
|
-
autoClearContext: this.opts.autoClearContext,
|
1974
|
-
testId: this.opts.testId
|
1975
|
-
});
|
1976
|
-
if (this.opts.autoClearContext) {
|
1977
|
-
this.contextStore.clear();
|
1978
|
-
debug4("Context store cleared due to autoClearContext option");
|
1979
|
-
} else {
|
1980
|
-
const existingData = this.contextStore.getAllData();
|
1981
|
-
const existingSteps = this.contextStore.getRecentSteps(100).length;
|
1982
|
-
debug4("Context store preserving existing data", {
|
1983
|
-
existingDataKeys: Object.keys(existingData),
|
1984
|
-
existingStepsCount: existingSteps
|
1985
|
-
});
|
1986
|
-
}
|
1987
|
-
} catch (error) {
|
1988
|
-
debug4("Failed to initialize context store:", error);
|
1989
|
-
console.warn("⚠️ Could not initialize context store:", error);
|
1990
|
-
}
|
1991
|
-
}
|
1992
|
-
/**
|
1993
|
-
* Get the context store instance
|
1994
|
-
*/
|
1995
|
-
getContextStore() {
|
1996
|
-
return this.contextStore;
|
1997
|
-
}
|
1998
|
-
/**
|
1999
|
-
* Clear the context store
|
2000
|
-
*/
|
2001
|
-
clearContext() {
|
2002
|
-
if (this.contextStore) {
|
2003
|
-
this.contextStore.clear();
|
2004
|
-
}
|
2005
|
-
}
|
2006
|
-
/**
|
2007
|
-
* Get all stored data from context store
|
2008
|
-
*/
|
2009
|
-
getStoredData() {
|
2010
|
-
if (this.contextStore) {
|
2011
|
-
return this.contextStore.getAllData();
|
2012
|
-
}
|
2013
|
-
return {};
|
2014
|
-
}
|
2015
|
-
/**
|
2016
|
-
* Get step summary from context store
|
2017
|
-
*/
|
2018
|
-
getStepSummary() {
|
2019
|
-
if (this.contextStore) {
|
2020
|
-
return this.contextStore.getStepSummary();
|
2021
|
-
}
|
2022
|
-
return "";
|
2023
|
-
}
|
2024
1924
|
async getUIContext(action) {
|
2025
1925
|
if (action && (action === "extract" || action === "assert" || action === "captcha")) {
|
2026
1926
|
return await parseContextFromWebPage(this.page, {
|
@@ -2256,35 +2156,9 @@ var PageAgent = class {
|
|
2256
2156
|
};
|
2257
2157
|
}
|
2258
2158
|
async aiAction(taskPrompt, opt) {
|
2259
|
-
const originalPrompt = taskPrompt;
|
2260
|
-
let processedPrompt = taskPrompt;
|
2261
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2262
|
-
try {
|
2263
|
-
const storedData = this.contextStore.getAllData();
|
2264
|
-
if (Object.keys(storedData).length > 0) {
|
2265
|
-
debug4("Available data for aiAction:", {
|
2266
|
-
prompt: taskPrompt,
|
2267
|
-
availableData: storedData
|
2268
|
-
});
|
2269
|
-
}
|
2270
|
-
} catch (error) {
|
2271
|
-
debug4("Context store operation failed:", error);
|
2272
|
-
}
|
2273
|
-
}
|
2274
2159
|
const cacheable = opt?.cacheable;
|
2275
2160
|
const isVlmUiTars = vlLocateMode() === "vlm-ui-tars";
|
2276
|
-
|
2277
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2278
|
-
try {
|
2279
|
-
contextData = this.contextStore.getAllData();
|
2280
|
-
if (contextData && Object.keys(contextData).length === 0) {
|
2281
|
-
contextData = void 0;
|
2282
|
-
}
|
2283
|
-
} catch (error) {
|
2284
|
-
debug4("Failed to get context data for cache:", error);
|
2285
|
-
}
|
2286
|
-
}
|
2287
|
-
const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt, contextData);
|
2161
|
+
const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
|
2288
2162
|
if (matchedCache && this.taskCache?.isCacheResultUsed) {
|
2289
2163
|
const { executor: executor2 } = await this.taskExecutor.loadYamlFlowAsPlanning(
|
2290
2164
|
taskPrompt,
|
@@ -2294,28 +2168,6 @@ var PageAgent = class {
|
|
2294
2168
|
debug4("matched cache, will call .runYaml to run the action");
|
2295
2169
|
const yaml5 = matchedCache.cacheContent?.yamlWorkflow;
|
2296
2170
|
const result = await this.runYaml(yaml5);
|
2297
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2298
|
-
try {
|
2299
|
-
const executionResult = {
|
2300
|
-
success: true,
|
2301
|
-
actionType: "cached",
|
2302
|
-
description: `Executed cached action: ${processedPrompt}`,
|
2303
|
-
timing: result.metadata?.totalTime
|
2304
|
-
};
|
2305
|
-
this.contextStore.addStep({
|
2306
|
-
type: "action",
|
2307
|
-
summary: `Action: ${processedPrompt} (cached)`,
|
2308
|
-
prompt: processedPrompt,
|
2309
|
-
executionResult
|
2310
|
-
});
|
2311
|
-
debug4("Added cached action step to context store:", {
|
2312
|
-
stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
|
2313
|
-
totalSteps: this.contextStore.getRecentSteps(100).length
|
2314
|
-
});
|
2315
|
-
} catch (error) {
|
2316
|
-
debug4("Failed to add cached action step:", error);
|
2317
|
-
}
|
2318
|
-
}
|
2319
2171
|
return {
|
2320
2172
|
result: result.result,
|
2321
2173
|
metadata: metadata2
|
@@ -2340,114 +2192,17 @@ var PageAgent = class {
|
|
2340
2192
|
prompt: taskPrompt,
|
2341
2193
|
yamlWorkflow: yamlFlowStr
|
2342
2194
|
},
|
2343
|
-
matchedCache
|
2344
|
-
contextData
|
2345
|
-
// Pass context data for cache creation
|
2195
|
+
matchedCache
|
2346
2196
|
);
|
2347
2197
|
}
|
2348
2198
|
const metadata = this.afterTaskRunning(executor);
|
2349
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2350
|
-
try {
|
2351
|
-
const executionResult = this.analyzeExecutionResults(executor, originalPrompt);
|
2352
|
-
this.contextStore.addStep({
|
2353
|
-
type: "action",
|
2354
|
-
summary: `Action: ${processedPrompt}`,
|
2355
|
-
prompt: processedPrompt,
|
2356
|
-
executionResult
|
2357
|
-
});
|
2358
|
-
debug4("Added action step with execution result to context store:", {
|
2359
|
-
stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
|
2360
|
-
totalSteps: this.contextStore.getRecentSteps(100).length,
|
2361
|
-
executionResult
|
2362
|
-
});
|
2363
|
-
} catch (error) {
|
2364
|
-
debug4("Failed to analyze execution results, adding step without execution result:", error);
|
2365
|
-
try {
|
2366
|
-
this.contextStore.addStep({
|
2367
|
-
type: "action",
|
2368
|
-
summary: `Action: ${processedPrompt}`,
|
2369
|
-
prompt: processedPrompt
|
2370
|
-
});
|
2371
|
-
} catch (stepError) {
|
2372
|
-
debug4("Failed to add action step:", stepError);
|
2373
|
-
}
|
2374
|
-
}
|
2375
|
-
}
|
2376
2199
|
return {
|
2377
2200
|
result: output,
|
2378
2201
|
metadata
|
2379
2202
|
};
|
2380
2203
|
}
|
2381
2204
|
async aiQuery(demand) {
|
2382
|
-
|
2383
|
-
let storageKey;
|
2384
|
-
try {
|
2385
|
-
const aiModel = await import("misoai-core/ai-model");
|
2386
|
-
const contextStore = aiModel.getContextStore();
|
2387
|
-
if (typeof demand === "string") {
|
2388
|
-
const storageInstruction = contextStore.parseStorageInstruction(demand);
|
2389
|
-
if (storageInstruction) {
|
2390
|
-
storageKey = storageInstruction.key;
|
2391
|
-
processedDemand = storageInstruction.cleanText;
|
2392
|
-
contextStore._pendingAliases = storageInstruction.aliases;
|
2393
|
-
} else {
|
2394
|
-
const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
|
2395
|
-
if (storageMatch) {
|
2396
|
-
storageKey = storageMatch[1];
|
2397
|
-
processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
|
2398
|
-
}
|
2399
|
-
}
|
2400
|
-
}
|
2401
|
-
} catch (error) {
|
2402
|
-
debug4("Context store not available:", error);
|
2403
|
-
}
|
2404
|
-
const { output, executor } = await this.taskExecutor.query(processedDemand);
|
2405
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2406
|
-
if (storageKey && output) {
|
2407
|
-
try {
|
2408
|
-
const pendingAliases = this.contextStore._pendingAliases;
|
2409
|
-
if (pendingAliases) {
|
2410
|
-
this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
|
2411
|
-
delete this.contextStore._pendingAliases;
|
2412
|
-
debug4("Stored query result with aliases:", {
|
2413
|
-
key: storageKey,
|
2414
|
-
value: output,
|
2415
|
-
aliases: pendingAliases
|
2416
|
-
});
|
2417
|
-
} else {
|
2418
|
-
this.contextStore.storeData(storageKey, output);
|
2419
|
-
debug4("Stored query result:", {
|
2420
|
-
key: storageKey,
|
2421
|
-
value: output
|
2422
|
-
});
|
2423
|
-
}
|
2424
|
-
this.contextStore.addStep({
|
2425
|
-
type: "query",
|
2426
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
|
2427
|
-
data: output,
|
2428
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2429
|
-
});
|
2430
|
-
debug4("Added query step to context store:", {
|
2431
|
-
storageKey,
|
2432
|
-
totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
|
2433
|
-
totalSteps: this.contextStore.getRecentSteps(100).length
|
2434
|
-
});
|
2435
|
-
} catch (error) {
|
2436
|
-
debug4("Failed to store query result:", error);
|
2437
|
-
}
|
2438
|
-
} else {
|
2439
|
-
try {
|
2440
|
-
this.contextStore.addStep({
|
2441
|
-
type: "query",
|
2442
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
|
2443
|
-
data: output,
|
2444
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2445
|
-
});
|
2446
|
-
} catch (error) {
|
2447
|
-
debug4("Failed to add query step:", error);
|
2448
|
-
}
|
2449
|
-
}
|
2450
|
-
}
|
2205
|
+
const { output, executor } = await this.taskExecutor.query(demand);
|
2451
2206
|
const metadata = this.afterTaskRunning(executor);
|
2452
2207
|
return {
|
2453
2208
|
result: output,
|
@@ -2557,48 +2312,6 @@ var PageAgent = class {
|
|
2557
2312
|
};
|
2558
2313
|
}
|
2559
2314
|
async aiAssert(assertion, msg, opt) {
|
2560
|
-
let executionContext = "";
|
2561
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2562
|
-
try {
|
2563
|
-
const recentSteps = this.contextStore.getRecentSteps(3);
|
2564
|
-
const stepsWithExecutionResults = recentSteps.filter((step) => step.executionResult);
|
2565
|
-
const storedData = this.contextStore.getAllData();
|
2566
|
-
if (stepsWithExecutionResults.length > 0) {
|
2567
|
-
const recentActions = stepsWithExecutionResults.map((step) => {
|
2568
|
-
const result = step.executionResult;
|
2569
|
-
return `- ${result.description}${result.success ? "" : " (FAILED)"}`;
|
2570
|
-
}).join("\n");
|
2571
|
-
executionContext = `
|
2572
|
-
|
2573
|
-
Recent actions performed:
|
2574
|
-
${recentActions}
|
2575
|
-
|
2576
|
-
This context may help verify the assertion.`;
|
2577
|
-
}
|
2578
|
-
if (storedData && Object.keys(storedData).length > 0) {
|
2579
|
-
executionContext += `
|
2580
|
-
|
2581
|
-
Available data for reference:
|
2582
|
-
${JSON.stringify(storedData, null, 2)}
|
2583
|
-
|
2584
|
-
Note: If the assertion references any data keys or natural language equivalents, consider the stored values when verifying.`;
|
2585
|
-
debug4("Available data for aiAssert:", {
|
2586
|
-
assertion,
|
2587
|
-
availableData: storedData
|
2588
|
-
});
|
2589
|
-
}
|
2590
|
-
this.contextStore.addStep({
|
2591
|
-
type: "assertion",
|
2592
|
-
summary: `Assertion: ${assertion}`,
|
2593
|
-
prompt: assertion
|
2594
|
-
});
|
2595
|
-
debug4("Added assertion step to context store:", {
|
2596
|
-
totalSteps: this.contextStore.getRecentSteps(100).length
|
2597
|
-
});
|
2598
|
-
} catch (error) {
|
2599
|
-
debug4("Context store operation failed:", error);
|
2600
|
-
}
|
2601
|
-
}
|
2602
2315
|
let currentUrl = "";
|
2603
2316
|
if (this.page.url) {
|
2604
2317
|
try {
|
@@ -2606,13 +2319,7 @@ Note: If the assertion references any data keys or natural language equivalents,
|
|
2606
2319
|
} catch (e) {
|
2607
2320
|
}
|
2608
2321
|
}
|
2609
|
-
|
2610
|
-
if (currentUrl) {
|
2611
|
-
assertionWithContext = `For the page at URL "${currentUrl}", ${assertion}`;
|
2612
|
-
}
|
2613
|
-
if (executionContext) {
|
2614
|
-
assertionWithContext += executionContext;
|
2615
|
-
}
|
2322
|
+
const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
|
2616
2323
|
const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
|
2617
2324
|
const metadata = this.afterTaskRunning(executor, true);
|
2618
2325
|
if (output && opt?.keepRawResponse) {
|
@@ -2826,79 +2533,6 @@ ${errors}`);
|
|
2826
2533
|
async destroy() {
|
2827
2534
|
await this.page.destroy();
|
2828
2535
|
}
|
2829
|
-
/**
|
2830
|
-
* Analyze execution results from executor to generate meaningful descriptions
|
2831
|
-
*/
|
2832
|
-
analyzeExecutionResults(executor, originalPrompt) {
|
2833
|
-
const tasks = executor.tasks;
|
2834
|
-
const success = !executor.isInErrorState();
|
2835
|
-
if (!success) {
|
2836
|
-
const errorTask = executor.latestErrorTask();
|
2837
|
-
return {
|
2838
|
-
success: false,
|
2839
|
-
actionType: "error",
|
2840
|
-
description: `Failed to execute: ${originalPrompt}`,
|
2841
|
-
error: errorTask?.error
|
2842
|
-
};
|
2843
|
-
}
|
2844
|
-
const actionTasks = tasks.filter((t) => t.type === "Action" && t.status === "finished");
|
2845
|
-
const locateTasks = tasks.filter((t) => t.type === "Insight" && t.subType === "Locate");
|
2846
|
-
const lastAction = actionTasks[actionTasks.length - 1];
|
2847
|
-
const lastLocate = locateTasks[locateTasks.length - 1];
|
2848
|
-
if (!lastAction) {
|
2849
|
-
return {
|
2850
|
-
success: true,
|
2851
|
-
actionType: "unknown",
|
2852
|
-
description: `Completed: ${originalPrompt}`
|
2853
|
-
};
|
2854
|
-
}
|
2855
|
-
const actionType = lastAction.subType || "unknown";
|
2856
|
-
const elementInfo = this.extractElementInfo(lastLocate, lastAction);
|
2857
|
-
const description = this.generateActionDescription(actionType, lastAction.param, elementInfo);
|
2858
|
-
return {
|
2859
|
-
success: true,
|
2860
|
-
actionType,
|
2861
|
-
description,
|
2862
|
-
elementInfo,
|
2863
|
-
timing: lastAction.timing?.cost
|
2864
|
-
};
|
2865
|
-
}
|
2866
|
-
/**
|
2867
|
-
* Extract element information from locate task
|
2868
|
-
*/
|
2869
|
-
extractElementInfo(locateTask, _actionTask) {
|
2870
|
-
if (!locateTask?.output?.element)
|
2871
|
-
return void 0;
|
2872
|
-
const element = locateTask.output.element;
|
2873
|
-
return {
|
2874
|
-
type: element.attributes?.nodeType || "unknown",
|
2875
|
-
text: element.content || element.attributes?.placeholder || element.attributes?.title || "",
|
2876
|
-
location: `(${element.center[0]}, ${element.center[1]})`
|
2877
|
-
};
|
2878
|
-
}
|
2879
|
-
/**
|
2880
|
-
* Generate natural language description for actions
|
2881
|
-
*/
|
2882
|
-
generateActionDescription(actionType, param, elementInfo) {
|
2883
|
-
const elementDesc = elementInfo ? `'${elementInfo.text || elementInfo.type}' element` : "element";
|
2884
|
-
switch (actionType) {
|
2885
|
-
case "Tap":
|
2886
|
-
return `Clicked on ${elementDesc}`;
|
2887
|
-
case "Input":
|
2888
|
-
const inputValue = param?.value || "";
|
2889
|
-
return `Entered "${inputValue}" into ${elementDesc}`;
|
2890
|
-
case "KeyboardPress":
|
2891
|
-
return `Pressed ${param?.value || "key"}`;
|
2892
|
-
case "Scroll":
|
2893
|
-
return `Scrolled ${param?.direction || "on page"}`;
|
2894
|
-
case "Hover":
|
2895
|
-
return `Hovered over ${elementDesc}`;
|
2896
|
-
case "Drag":
|
2897
|
-
return `Dragged ${elementDesc}`;
|
2898
|
-
default:
|
2899
|
-
return `Performed ${actionType} action on ${elementDesc}`;
|
2900
|
-
}
|
2901
|
-
}
|
2902
2536
|
};
|
2903
2537
|
|
2904
2538
|
// src/chrome-extension/agent.ts
|
@@ -3118,7 +2752,7 @@ function sleep2(ms) {
|
|
3118
2752
|
var ChromeExtensionProxyPage = class {
|
3119
2753
|
constructor(forceSameTabNavigation) {
|
3120
2754
|
this.pageType = "chrome-extension-proxy";
|
3121
|
-
this.version = "1.
|
2755
|
+
this.version = "1.5.6";
|
3122
2756
|
this.activeTabId = null;
|
3123
2757
|
this.tabIdOfDebuggerAttached = null;
|
3124
2758
|
this.attachingDebugger = null;
|