misoai-web 1.0.4 → 1.0.5
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 +349 -5
- package/dist/es/agent.js +158 -56
- package/dist/es/agent.js.map +1 -1
- package/dist/es/bridge-mode-browser.js +3 -3
- package/dist/es/bridge-mode.js +160 -58
- package/dist/es/bridge-mode.js.map +1 -1
- package/dist/es/chrome-extension.js +159 -57
- package/dist/es/chrome-extension.js.map +1 -1
- package/dist/es/index.js +158 -56
- package/dist/es/index.js.map +1 -1
- package/dist/es/midscene-playground.js +158 -56
- package/dist/es/midscene-playground.js.map +1 -1
- package/dist/es/playground.js +158 -56
- package/dist/es/playground.js.map +1 -1
- package/dist/es/playwright.js +158 -56
- package/dist/es/playwright.js.map +1 -1
- package/dist/es/puppeteer-agent-launcher.js +158 -56
- package/dist/es/puppeteer-agent-launcher.js.map +1 -1
- package/dist/es/puppeteer.js +158 -56
- package/dist/es/puppeteer.js.map +1 -1
- package/dist/lib/agent.js +158 -56
- package/dist/lib/agent.js.map +1 -1
- package/dist/lib/bridge-mode-browser.js +3 -3
- package/dist/lib/bridge-mode.js +160 -58
- package/dist/lib/bridge-mode.js.map +1 -1
- package/dist/lib/chrome-extension.js +159 -57
- package/dist/lib/chrome-extension.js.map +1 -1
- package/dist/lib/index.js +158 -56
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/midscene-playground.js +158 -56
- package/dist/lib/midscene-playground.js.map +1 -1
- package/dist/lib/playground.js +158 -56
- package/dist/lib/playground.js.map +1 -1
- package/dist/lib/playwright.js +158 -56
- package/dist/lib/playwright.js.map +1 -1
- package/dist/lib/puppeteer-agent-launcher.js +158 -56
- package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
- package/dist/lib/puppeteer.js +158 -56
- package/dist/lib/puppeteer.js.map +1 -1
- package/dist/types/agent.d.ts +26 -0
- package/package.json +1 -1
@@ -1713,7 +1713,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
|
|
1713
1713
|
var import_semver = __toESM(require("semver"));
|
1714
1714
|
|
1715
1715
|
// package.json
|
1716
|
-
var version = "1.0.
|
1716
|
+
var version = "1.0.5";
|
1717
1717
|
|
1718
1718
|
// src/common/task-cache.ts
|
1719
1719
|
var debug3 = (0, import_logger3.getDebug)("cache");
|
@@ -1895,10 +1895,13 @@ var PageAgent = class {
|
|
1895
1895
|
generateReport: true,
|
1896
1896
|
autoPrintReportMsg: true,
|
1897
1897
|
groupName: "Midscene Report",
|
1898
|
-
groupDescription: ""
|
1898
|
+
groupDescription: "",
|
1899
|
+
enableCumulativeContext: true,
|
1900
|
+
autoClearContext: false
|
1899
1901
|
},
|
1900
1902
|
opts || {}
|
1901
1903
|
);
|
1904
|
+
this.initializeContextStore();
|
1902
1905
|
if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
|
1903
1906
|
this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || import_constants2.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
|
1904
1907
|
this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || import_constants2.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
|
@@ -1925,6 +1928,69 @@ var PageAgent = class {
|
|
1925
1928
|
opts?.testId || this.page.pageType || "web"
|
1926
1929
|
);
|
1927
1930
|
}
|
1931
|
+
/**
|
1932
|
+
* Initialize context store for cumulative context functionality
|
1933
|
+
*/
|
1934
|
+
async initializeContextStore() {
|
1935
|
+
if (!this.opts.enableCumulativeContext) {
|
1936
|
+
debug4("Cumulative context disabled via options");
|
1937
|
+
return;
|
1938
|
+
}
|
1939
|
+
try {
|
1940
|
+
const aiModel = await import("misoai-core/ai-model");
|
1941
|
+
this.contextStore = aiModel.getContextStore();
|
1942
|
+
debug4("Context store initialized successfully", {
|
1943
|
+
autoClearContext: this.opts.autoClearContext,
|
1944
|
+
testId: this.opts.testId
|
1945
|
+
});
|
1946
|
+
if (this.opts.autoClearContext) {
|
1947
|
+
this.contextStore.clear();
|
1948
|
+
debug4("Context store cleared due to autoClearContext option");
|
1949
|
+
} else {
|
1950
|
+
const existingData = this.contextStore.getAllData();
|
1951
|
+
const existingSteps = this.contextStore.getRecentSteps(100).length;
|
1952
|
+
debug4("Context store preserving existing data", {
|
1953
|
+
existingDataKeys: Object.keys(existingData),
|
1954
|
+
existingStepsCount: existingSteps
|
1955
|
+
});
|
1956
|
+
}
|
1957
|
+
} catch (error) {
|
1958
|
+
debug4("Failed to initialize context store:", error);
|
1959
|
+
console.warn("⚠️ Could not initialize context store:", error);
|
1960
|
+
}
|
1961
|
+
}
|
1962
|
+
/**
|
1963
|
+
* Get the context store instance
|
1964
|
+
*/
|
1965
|
+
getContextStore() {
|
1966
|
+
return this.contextStore;
|
1967
|
+
}
|
1968
|
+
/**
|
1969
|
+
* Clear the context store
|
1970
|
+
*/
|
1971
|
+
clearContext() {
|
1972
|
+
if (this.contextStore) {
|
1973
|
+
this.contextStore.clear();
|
1974
|
+
}
|
1975
|
+
}
|
1976
|
+
/**
|
1977
|
+
* Get all stored data from context store
|
1978
|
+
*/
|
1979
|
+
getStoredData() {
|
1980
|
+
if (this.contextStore) {
|
1981
|
+
return this.contextStore.getAllData();
|
1982
|
+
}
|
1983
|
+
return {};
|
1984
|
+
}
|
1985
|
+
/**
|
1986
|
+
* Get step summary from context store
|
1987
|
+
*/
|
1988
|
+
getStepSummary() {
|
1989
|
+
if (this.contextStore) {
|
1990
|
+
return this.contextStore.getStepSummary();
|
1991
|
+
}
|
1992
|
+
return "";
|
1993
|
+
}
|
1928
1994
|
async getUIContext(action) {
|
1929
1995
|
if (action && (action === "extract" || action === "assert" || action === "captcha")) {
|
1930
1996
|
return await parseContextFromWebPage(this.page, {
|
@@ -2160,18 +2226,30 @@ var PageAgent = class {
|
|
2160
2226
|
};
|
2161
2227
|
}
|
2162
2228
|
async aiAction(taskPrompt, opt) {
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2229
|
+
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2230
|
+
try {
|
2231
|
+
const originalPrompt = taskPrompt;
|
2232
|
+
const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
|
2233
|
+
if (originalPrompt !== processedPrompt) {
|
2234
|
+
debug4("Context replacement in aiAction:", {
|
2235
|
+
original: originalPrompt,
|
2236
|
+
processed: processedPrompt,
|
2237
|
+
storedData: this.contextStore.getAllData()
|
2238
|
+
});
|
2239
|
+
}
|
2240
|
+
this.contextStore.addStep({
|
2241
|
+
type: "action",
|
2242
|
+
summary: `Action: ${processedPrompt}`,
|
2243
|
+
prompt: processedPrompt
|
2244
|
+
});
|
2245
|
+
debug4("Added action step to context store:", {
|
2246
|
+
stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
|
2247
|
+
totalSteps: this.contextStore.getRecentSteps(100).length
|
2248
|
+
});
|
2249
|
+
taskPrompt = processedPrompt;
|
2250
|
+
} catch (error) {
|
2251
|
+
debug4("Context store operation failed:", error);
|
2252
|
+
}
|
2175
2253
|
}
|
2176
2254
|
const cacheable = opt?.cacheable;
|
2177
2255
|
const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
|
@@ -2242,38 +2320,50 @@ var PageAgent = class {
|
|
2242
2320
|
debug4("Context store not available:", error);
|
2243
2321
|
}
|
2244
2322
|
const { output, executor } = await this.taskExecutor.query(processedDemand);
|
2245
|
-
if (
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2251
|
-
|
2252
|
-
|
2253
|
-
|
2254
|
-
|
2323
|
+
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2324
|
+
if (storageKey && output) {
|
2325
|
+
try {
|
2326
|
+
const pendingAliases = this.contextStore._pendingAliases;
|
2327
|
+
if (pendingAliases) {
|
2328
|
+
this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
|
2329
|
+
delete this.contextStore._pendingAliases;
|
2330
|
+
debug4("Stored query result with aliases:", {
|
2331
|
+
key: storageKey,
|
2332
|
+
value: output,
|
2333
|
+
aliases: pendingAliases
|
2334
|
+
});
|
2335
|
+
} else {
|
2336
|
+
this.contextStore.storeData(storageKey, output);
|
2337
|
+
debug4("Stored query result:", {
|
2338
|
+
key: storageKey,
|
2339
|
+
value: output
|
2340
|
+
});
|
2341
|
+
}
|
2342
|
+
this.contextStore.addStep({
|
2343
|
+
type: "query",
|
2344
|
+
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
|
2345
|
+
data: output,
|
2346
|
+
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2347
|
+
});
|
2348
|
+
debug4("Added query step to context store:", {
|
2349
|
+
storageKey,
|
2350
|
+
totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
|
2351
|
+
totalSteps: this.contextStore.getRecentSteps(100).length
|
2352
|
+
});
|
2353
|
+
} catch (error) {
|
2354
|
+
debug4("Failed to store query result:", error);
|
2355
|
+
}
|
2356
|
+
} else {
|
2357
|
+
try {
|
2358
|
+
this.contextStore.addStep({
|
2359
|
+
type: "query",
|
2360
|
+
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
|
2361
|
+
data: output,
|
2362
|
+
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2363
|
+
});
|
2364
|
+
} catch (error) {
|
2365
|
+
debug4("Failed to add query step:", error);
|
2255
2366
|
}
|
2256
|
-
contextStore.addStep({
|
2257
|
-
type: "query",
|
2258
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
|
2259
|
-
data: output,
|
2260
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2261
|
-
});
|
2262
|
-
} catch (error) {
|
2263
|
-
debug4("Failed to store query result:", error);
|
2264
|
-
}
|
2265
|
-
} else {
|
2266
|
-
try {
|
2267
|
-
const aiModel = await import("misoai-core/ai-model");
|
2268
|
-
const contextStore = aiModel.getContextStore();
|
2269
|
-
contextStore.addStep({
|
2270
|
-
type: "query",
|
2271
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
|
2272
|
-
data: output,
|
2273
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2274
|
-
});
|
2275
|
-
} catch (error) {
|
2276
|
-
debug4("Failed to add query step:", error);
|
2277
2367
|
}
|
2278
2368
|
}
|
2279
2369
|
const metadata = this.afterTaskRunning(executor);
|
@@ -2386,17 +2476,29 @@ var PageAgent = class {
|
|
2386
2476
|
}
|
2387
2477
|
async aiAssert(assertion, msg, opt) {
|
2388
2478
|
let processedAssertion = assertion;
|
2389
|
-
|
2390
|
-
|
2391
|
-
|
2392
|
-
|
2393
|
-
|
2394
|
-
|
2395
|
-
|
2396
|
-
|
2397
|
-
|
2398
|
-
|
2399
|
-
|
2479
|
+
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2480
|
+
try {
|
2481
|
+
const originalAssertion = assertion;
|
2482
|
+
processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
|
2483
|
+
if (originalAssertion !== processedAssertion) {
|
2484
|
+
debug4("Context replacement in aiAssert:", {
|
2485
|
+
original: originalAssertion,
|
2486
|
+
processed: processedAssertion,
|
2487
|
+
context: "assertion",
|
2488
|
+
storedData: this.contextStore.getAllData()
|
2489
|
+
});
|
2490
|
+
}
|
2491
|
+
this.contextStore.addStep({
|
2492
|
+
type: "assertion",
|
2493
|
+
summary: `Assertion: ${processedAssertion}`,
|
2494
|
+
prompt: processedAssertion
|
2495
|
+
});
|
2496
|
+
debug4("Added assertion step to context store:", {
|
2497
|
+
totalSteps: this.contextStore.getRecentSteps(100).length
|
2498
|
+
});
|
2499
|
+
} catch (error) {
|
2500
|
+
debug4("Context store operation failed:", error);
|
2501
|
+
}
|
2400
2502
|
}
|
2401
2503
|
let currentUrl = "";
|
2402
2504
|
if (this.page.url) {
|