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