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.
Files changed (41) hide show
  1. package/README.md +349 -5
  2. package/dist/es/agent.js +158 -56
  3. package/dist/es/agent.js.map +1 -1
  4. package/dist/es/bridge-mode-browser.js +3 -3
  5. package/dist/es/bridge-mode.js +160 -58
  6. package/dist/es/bridge-mode.js.map +1 -1
  7. package/dist/es/chrome-extension.js +159 -57
  8. package/dist/es/chrome-extension.js.map +1 -1
  9. package/dist/es/index.js +158 -56
  10. package/dist/es/index.js.map +1 -1
  11. package/dist/es/midscene-playground.js +158 -56
  12. package/dist/es/midscene-playground.js.map +1 -1
  13. package/dist/es/playground.js +158 -56
  14. package/dist/es/playground.js.map +1 -1
  15. package/dist/es/playwright.js +158 -56
  16. package/dist/es/playwright.js.map +1 -1
  17. package/dist/es/puppeteer-agent-launcher.js +158 -56
  18. package/dist/es/puppeteer-agent-launcher.js.map +1 -1
  19. package/dist/es/puppeteer.js +158 -56
  20. package/dist/es/puppeteer.js.map +1 -1
  21. package/dist/lib/agent.js +158 -56
  22. package/dist/lib/agent.js.map +1 -1
  23. package/dist/lib/bridge-mode-browser.js +3 -3
  24. package/dist/lib/bridge-mode.js +160 -58
  25. package/dist/lib/bridge-mode.js.map +1 -1
  26. package/dist/lib/chrome-extension.js +159 -57
  27. package/dist/lib/chrome-extension.js.map +1 -1
  28. package/dist/lib/index.js +158 -56
  29. package/dist/lib/index.js.map +1 -1
  30. package/dist/lib/midscene-playground.js +158 -56
  31. package/dist/lib/midscene-playground.js.map +1 -1
  32. package/dist/lib/playground.js +158 -56
  33. package/dist/lib/playground.js.map +1 -1
  34. package/dist/lib/playwright.js +158 -56
  35. package/dist/lib/playwright.js.map +1 -1
  36. package/dist/lib/puppeteer-agent-launcher.js +158 -56
  37. package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
  38. package/dist/lib/puppeteer.js +158 -56
  39. package/dist/lib/puppeteer.js.map +1 -1
  40. package/dist/types/agent.d.ts +26 -0
  41. package/package.json +1 -1
@@ -1707,7 +1707,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1707
1707
  var import_semver = __toESM(require("semver"));
1708
1708
 
1709
1709
  // package.json
1710
- var version = "1.0.4";
1710
+ var version = "1.0.5";
1711
1711
 
1712
1712
  // src/common/task-cache.ts
1713
1713
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -1889,10 +1889,13 @@ var PageAgent = class {
1889
1889
  generateReport: true,
1890
1890
  autoPrintReportMsg: true,
1891
1891
  groupName: "Midscene Report",
1892
- groupDescription: ""
1892
+ groupDescription: "",
1893
+ enableCumulativeContext: true,
1894
+ autoClearContext: false
1893
1895
  },
1894
1896
  opts || {}
1895
1897
  );
1898
+ this.initializeContextStore();
1896
1899
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1897
1900
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || import_constants2.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1898
1901
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || import_constants2.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1919,6 +1922,69 @@ var PageAgent = class {
1919
1922
  opts?.testId || this.page.pageType || "web"
1920
1923
  );
1921
1924
  }
1925
+ /**
1926
+ * Initialize context store for cumulative context functionality
1927
+ */
1928
+ async initializeContextStore() {
1929
+ if (!this.opts.enableCumulativeContext) {
1930
+ debug4("Cumulative context disabled via options");
1931
+ return;
1932
+ }
1933
+ try {
1934
+ const aiModel = await import("misoai-core/ai-model");
1935
+ this.contextStore = aiModel.getContextStore();
1936
+ debug4("Context store initialized successfully", {
1937
+ autoClearContext: this.opts.autoClearContext,
1938
+ testId: this.opts.testId
1939
+ });
1940
+ if (this.opts.autoClearContext) {
1941
+ this.contextStore.clear();
1942
+ debug4("Context store cleared due to autoClearContext option");
1943
+ } else {
1944
+ const existingData = this.contextStore.getAllData();
1945
+ const existingSteps = this.contextStore.getRecentSteps(100).length;
1946
+ debug4("Context store preserving existing data", {
1947
+ existingDataKeys: Object.keys(existingData),
1948
+ existingStepsCount: existingSteps
1949
+ });
1950
+ }
1951
+ } catch (error) {
1952
+ debug4("Failed to initialize context store:", error);
1953
+ console.warn("⚠️ Could not initialize context store:", error);
1954
+ }
1955
+ }
1956
+ /**
1957
+ * Get the context store instance
1958
+ */
1959
+ getContextStore() {
1960
+ return this.contextStore;
1961
+ }
1962
+ /**
1963
+ * Clear the context store
1964
+ */
1965
+ clearContext() {
1966
+ if (this.contextStore) {
1967
+ this.contextStore.clear();
1968
+ }
1969
+ }
1970
+ /**
1971
+ * Get all stored data from context store
1972
+ */
1973
+ getStoredData() {
1974
+ if (this.contextStore) {
1975
+ return this.contextStore.getAllData();
1976
+ }
1977
+ return {};
1978
+ }
1979
+ /**
1980
+ * Get step summary from context store
1981
+ */
1982
+ getStepSummary() {
1983
+ if (this.contextStore) {
1984
+ return this.contextStore.getStepSummary();
1985
+ }
1986
+ return "";
1987
+ }
1922
1988
  async getUIContext(action) {
1923
1989
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
1924
1990
  return await parseContextFromWebPage(this.page, {
@@ -2154,18 +2220,30 @@ var PageAgent = class {
2154
2220
  };
2155
2221
  }
2156
2222
  async aiAction(taskPrompt, opt) {
2157
- try {
2158
- const aiModel = await import("misoai-core/ai-model");
2159
- const contextStore = aiModel.getContextStore();
2160
- const processedPrompt = contextStore.replaceAllReferences(taskPrompt, "action");
2161
- contextStore.addStep({
2162
- type: "action",
2163
- summary: `Action: ${processedPrompt}`,
2164
- prompt: processedPrompt
2165
- });
2166
- taskPrompt = processedPrompt;
2167
- } catch (error) {
2168
- debug4("Context store not available:", error);
2223
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2224
+ try {
2225
+ const originalPrompt = taskPrompt;
2226
+ const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
2227
+ if (originalPrompt !== processedPrompt) {
2228
+ debug4("Context replacement in aiAction:", {
2229
+ original: originalPrompt,
2230
+ processed: processedPrompt,
2231
+ storedData: this.contextStore.getAllData()
2232
+ });
2233
+ }
2234
+ this.contextStore.addStep({
2235
+ type: "action",
2236
+ summary: `Action: ${processedPrompt}`,
2237
+ prompt: processedPrompt
2238
+ });
2239
+ debug4("Added action step to context store:", {
2240
+ stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2241
+ totalSteps: this.contextStore.getRecentSteps(100).length
2242
+ });
2243
+ taskPrompt = processedPrompt;
2244
+ } catch (error) {
2245
+ debug4("Context store operation failed:", error);
2246
+ }
2169
2247
  }
2170
2248
  const cacheable = opt?.cacheable;
2171
2249
  const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
@@ -2236,38 +2314,50 @@ var PageAgent = class {
2236
2314
  debug4("Context store not available:", error);
2237
2315
  }
2238
2316
  const { output, executor } = await this.taskExecutor.query(processedDemand);
2239
- if (storageKey && output) {
2240
- try {
2241
- const aiModel = await import("misoai-core/ai-model");
2242
- const contextStore = aiModel.getContextStore();
2243
- const pendingAliases = contextStore._pendingAliases;
2244
- if (pendingAliases) {
2245
- contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2246
- delete contextStore._pendingAliases;
2247
- } else {
2248
- contextStore.storeData(storageKey, output);
2317
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2318
+ if (storageKey && output) {
2319
+ try {
2320
+ const pendingAliases = this.contextStore._pendingAliases;
2321
+ if (pendingAliases) {
2322
+ this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2323
+ delete this.contextStore._pendingAliases;
2324
+ debug4("Stored query result with aliases:", {
2325
+ key: storageKey,
2326
+ value: output,
2327
+ aliases: pendingAliases
2328
+ });
2329
+ } else {
2330
+ this.contextStore.storeData(storageKey, output);
2331
+ debug4("Stored query result:", {
2332
+ key: storageKey,
2333
+ value: output
2334
+ });
2335
+ }
2336
+ this.contextStore.addStep({
2337
+ type: "query",
2338
+ summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2339
+ data: output,
2340
+ prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2341
+ });
2342
+ debug4("Added query step to context store:", {
2343
+ storageKey,
2344
+ totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
2345
+ totalSteps: this.contextStore.getRecentSteps(100).length
2346
+ });
2347
+ } catch (error) {
2348
+ debug4("Failed to store query result:", error);
2349
+ }
2350
+ } else {
2351
+ try {
2352
+ this.contextStore.addStep({
2353
+ type: "query",
2354
+ summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2355
+ data: output,
2356
+ prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2357
+ });
2358
+ } catch (error) {
2359
+ debug4("Failed to add query step:", error);
2249
2360
  }
2250
- contextStore.addStep({
2251
- type: "query",
2252
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2253
- data: output,
2254
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2255
- });
2256
- } catch (error) {
2257
- debug4("Failed to store query result:", error);
2258
- }
2259
- } else {
2260
- try {
2261
- const aiModel = await import("misoai-core/ai-model");
2262
- const contextStore = aiModel.getContextStore();
2263
- contextStore.addStep({
2264
- type: "query",
2265
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2266
- data: output,
2267
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2268
- });
2269
- } catch (error) {
2270
- debug4("Failed to add query step:", error);
2271
2361
  }
2272
2362
  }
2273
2363
  const metadata = this.afterTaskRunning(executor);
@@ -2380,17 +2470,29 @@ var PageAgent = class {
2380
2470
  }
2381
2471
  async aiAssert(assertion, msg, opt) {
2382
2472
  let processedAssertion = assertion;
2383
- try {
2384
- const aiModel = await import("misoai-core/ai-model");
2385
- const contextStore = aiModel.getContextStore();
2386
- processedAssertion = contextStore.replaceAllReferences(assertion, "assertion");
2387
- contextStore.addStep({
2388
- type: "assertion",
2389
- summary: `Assertion: ${processedAssertion}`,
2390
- prompt: processedAssertion
2391
- });
2392
- } catch (error) {
2393
- debug4("Context store not available:", error);
2473
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2474
+ try {
2475
+ const originalAssertion = assertion;
2476
+ processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
2477
+ if (originalAssertion !== processedAssertion) {
2478
+ debug4("Context replacement in aiAssert:", {
2479
+ original: originalAssertion,
2480
+ processed: processedAssertion,
2481
+ context: "assertion",
2482
+ storedData: this.contextStore.getAllData()
2483
+ });
2484
+ }
2485
+ this.contextStore.addStep({
2486
+ type: "assertion",
2487
+ summary: `Assertion: ${processedAssertion}`,
2488
+ prompt: processedAssertion
2489
+ });
2490
+ debug4("Added assertion step to context store:", {
2491
+ totalSteps: this.contextStore.getRecentSteps(100).length
2492
+ });
2493
+ } catch (error) {
2494
+ debug4("Context store operation failed:", error);
2495
+ }
2394
2496
  }
2395
2497
  let currentUrl = "";
2396
2498
  if (this.page.url) {