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