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
@@ -1665,7 +1665,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1665
1665
  var import_semver = __toESM(require("semver"));
1666
1666
 
1667
1667
  // package.json
1668
- var version = "1.0.4";
1668
+ var version = "1.0.5";
1669
1669
 
1670
1670
  // src/common/task-cache.ts
1671
1671
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -1847,10 +1847,13 @@ var PageAgent = class {
1847
1847
  generateReport: true,
1848
1848
  autoPrintReportMsg: true,
1849
1849
  groupName: "Midscene Report",
1850
- groupDescription: ""
1850
+ groupDescription: "",
1851
+ enableCumulativeContext: true,
1852
+ autoClearContext: false
1851
1853
  },
1852
1854
  opts || {}
1853
1855
  );
1856
+ this.initializeContextStore();
1854
1857
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1855
1858
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || import_constants2.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1856
1859
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || import_constants2.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1877,6 +1880,69 @@ var PageAgent = class {
1877
1880
  opts?.testId || this.page.pageType || "web"
1878
1881
  );
1879
1882
  }
1883
+ /**
1884
+ * Initialize context store for cumulative context functionality
1885
+ */
1886
+ async initializeContextStore() {
1887
+ if (!this.opts.enableCumulativeContext) {
1888
+ debug4("Cumulative context disabled via options");
1889
+ return;
1890
+ }
1891
+ try {
1892
+ const aiModel = await import("misoai-core/ai-model");
1893
+ this.contextStore = aiModel.getContextStore();
1894
+ debug4("Context store initialized successfully", {
1895
+ autoClearContext: this.opts.autoClearContext,
1896
+ testId: this.opts.testId
1897
+ });
1898
+ if (this.opts.autoClearContext) {
1899
+ this.contextStore.clear();
1900
+ debug4("Context store cleared due to autoClearContext option");
1901
+ } else {
1902
+ const existingData = this.contextStore.getAllData();
1903
+ const existingSteps = this.contextStore.getRecentSteps(100).length;
1904
+ debug4("Context store preserving existing data", {
1905
+ existingDataKeys: Object.keys(existingData),
1906
+ existingStepsCount: existingSteps
1907
+ });
1908
+ }
1909
+ } catch (error) {
1910
+ debug4("Failed to initialize context store:", error);
1911
+ console.warn("⚠️ Could not initialize context store:", error);
1912
+ }
1913
+ }
1914
+ /**
1915
+ * Get the context store instance
1916
+ */
1917
+ getContextStore() {
1918
+ return this.contextStore;
1919
+ }
1920
+ /**
1921
+ * Clear the context store
1922
+ */
1923
+ clearContext() {
1924
+ if (this.contextStore) {
1925
+ this.contextStore.clear();
1926
+ }
1927
+ }
1928
+ /**
1929
+ * Get all stored data from context store
1930
+ */
1931
+ getStoredData() {
1932
+ if (this.contextStore) {
1933
+ return this.contextStore.getAllData();
1934
+ }
1935
+ return {};
1936
+ }
1937
+ /**
1938
+ * Get step summary from context store
1939
+ */
1940
+ getStepSummary() {
1941
+ if (this.contextStore) {
1942
+ return this.contextStore.getStepSummary();
1943
+ }
1944
+ return "";
1945
+ }
1880
1946
  async getUIContext(action) {
1881
1947
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
1882
1948
  return await parseContextFromWebPage(this.page, {
@@ -2112,18 +2178,30 @@ var PageAgent = class {
2112
2178
  };
2113
2179
  }
2114
2180
  async aiAction(taskPrompt, opt) {
2115
- try {
2116
- const aiModel = await import("misoai-core/ai-model");
2117
- const contextStore = aiModel.getContextStore();
2118
- const processedPrompt = contextStore.replaceAllReferences(taskPrompt, "action");
2119
- contextStore.addStep({
2120
- type: "action",
2121
- summary: `Action: ${processedPrompt}`,
2122
- prompt: processedPrompt
2123
- });
2124
- taskPrompt = processedPrompt;
2125
- } catch (error) {
2126
- debug4("Context store not available:", error);
2181
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2182
+ try {
2183
+ const originalPrompt = taskPrompt;
2184
+ const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
2185
+ if (originalPrompt !== processedPrompt) {
2186
+ debug4("Context replacement in aiAction:", {
2187
+ original: originalPrompt,
2188
+ processed: processedPrompt,
2189
+ storedData: this.contextStore.getAllData()
2190
+ });
2191
+ }
2192
+ this.contextStore.addStep({
2193
+ type: "action",
2194
+ summary: `Action: ${processedPrompt}`,
2195
+ prompt: processedPrompt
2196
+ });
2197
+ debug4("Added action step to context store:", {
2198
+ stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2199
+ totalSteps: this.contextStore.getRecentSteps(100).length
2200
+ });
2201
+ taskPrompt = processedPrompt;
2202
+ } catch (error) {
2203
+ debug4("Context store operation failed:", error);
2204
+ }
2127
2205
  }
2128
2206
  const cacheable = opt?.cacheable;
2129
2207
  const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
@@ -2194,38 +2272,50 @@ var PageAgent = class {
2194
2272
  debug4("Context store not available:", error);
2195
2273
  }
2196
2274
  const { output, executor } = await this.taskExecutor.query(processedDemand);
2197
- if (storageKey && output) {
2198
- try {
2199
- const aiModel = await import("misoai-core/ai-model");
2200
- const contextStore = aiModel.getContextStore();
2201
- const pendingAliases = contextStore._pendingAliases;
2202
- if (pendingAliases) {
2203
- contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2204
- delete contextStore._pendingAliases;
2205
- } else {
2206
- contextStore.storeData(storageKey, output);
2275
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2276
+ if (storageKey && output) {
2277
+ try {
2278
+ const pendingAliases = this.contextStore._pendingAliases;
2279
+ if (pendingAliases) {
2280
+ this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2281
+ delete this.contextStore._pendingAliases;
2282
+ debug4("Stored query result with aliases:", {
2283
+ key: storageKey,
2284
+ value: output,
2285
+ aliases: pendingAliases
2286
+ });
2287
+ } else {
2288
+ this.contextStore.storeData(storageKey, output);
2289
+ debug4("Stored query result:", {
2290
+ key: storageKey,
2291
+ value: output
2292
+ });
2293
+ }
2294
+ this.contextStore.addStep({
2295
+ type: "query",
2296
+ summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2297
+ data: output,
2298
+ prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2299
+ });
2300
+ debug4("Added query step to context store:", {
2301
+ storageKey,
2302
+ totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
2303
+ totalSteps: this.contextStore.getRecentSteps(100).length
2304
+ });
2305
+ } catch (error) {
2306
+ debug4("Failed to store query result:", error);
2307
+ }
2308
+ } else {
2309
+ try {
2310
+ this.contextStore.addStep({
2311
+ type: "query",
2312
+ summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2313
+ data: output,
2314
+ prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2315
+ });
2316
+ } catch (error) {
2317
+ debug4("Failed to add query step:", error);
2207
2318
  }
2208
- contextStore.addStep({
2209
- type: "query",
2210
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2211
- data: output,
2212
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2213
- });
2214
- } catch (error) {
2215
- debug4("Failed to store query result:", error);
2216
- }
2217
- } else {
2218
- try {
2219
- const aiModel = await import("misoai-core/ai-model");
2220
- const contextStore = aiModel.getContextStore();
2221
- contextStore.addStep({
2222
- type: "query",
2223
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2224
- data: output,
2225
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2226
- });
2227
- } catch (error) {
2228
- debug4("Failed to add query step:", error);
2229
2319
  }
2230
2320
  }
2231
2321
  const metadata = this.afterTaskRunning(executor);
@@ -2338,17 +2428,29 @@ var PageAgent = class {
2338
2428
  }
2339
2429
  async aiAssert(assertion, msg, opt) {
2340
2430
  let processedAssertion = assertion;
2341
- try {
2342
- const aiModel = await import("misoai-core/ai-model");
2343
- const contextStore = aiModel.getContextStore();
2344
- processedAssertion = contextStore.replaceAllReferences(assertion, "assertion");
2345
- contextStore.addStep({
2346
- type: "assertion",
2347
- summary: `Assertion: ${processedAssertion}`,
2348
- prompt: processedAssertion
2349
- });
2350
- } catch (error) {
2351
- debug4("Context store not available:", error);
2431
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2432
+ try {
2433
+ const originalAssertion = assertion;
2434
+ processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
2435
+ if (originalAssertion !== processedAssertion) {
2436
+ debug4("Context replacement in aiAssert:", {
2437
+ original: originalAssertion,
2438
+ processed: processedAssertion,
2439
+ context: "assertion",
2440
+ storedData: this.contextStore.getAllData()
2441
+ });
2442
+ }
2443
+ this.contextStore.addStep({
2444
+ type: "assertion",
2445
+ summary: `Assertion: ${processedAssertion}`,
2446
+ prompt: processedAssertion
2447
+ });
2448
+ debug4("Added assertion step to context store:", {
2449
+ totalSteps: this.contextStore.getRecentSteps(100).length
2450
+ });
2451
+ } catch (error) {
2452
+ debug4("Context store operation failed:", error);
2453
+ }
2352
2454
  }
2353
2455
  let currentUrl = "";
2354
2456
  if (this.page.url) {