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
package/dist/lib/agent.js CHANGED
@@ -1674,7 +1674,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1674
1674
  var import_semver = __toESM(require("semver"));
1675
1675
 
1676
1676
  // package.json
1677
- var version = "1.0.4";
1677
+ var version = "1.0.5";
1678
1678
 
1679
1679
  // src/common/task-cache.ts
1680
1680
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -1856,10 +1856,13 @@ var PageAgent = class {
1856
1856
  generateReport: true,
1857
1857
  autoPrintReportMsg: true,
1858
1858
  groupName: "Midscene Report",
1859
- groupDescription: ""
1859
+ groupDescription: "",
1860
+ enableCumulativeContext: true,
1861
+ autoClearContext: false
1860
1862
  },
1861
1863
  opts || {}
1862
1864
  );
1865
+ this.initializeContextStore();
1863
1866
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1864
1867
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || import_constants2.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1865
1868
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || import_constants2.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1886,6 +1889,69 @@ var PageAgent = class {
1886
1889
  opts?.testId || this.page.pageType || "web"
1887
1890
  );
1888
1891
  }
1892
+ /**
1893
+ * Initialize context store for cumulative context functionality
1894
+ */
1895
+ async initializeContextStore() {
1896
+ if (!this.opts.enableCumulativeContext) {
1897
+ debug4("Cumulative context disabled via options");
1898
+ return;
1899
+ }
1900
+ try {
1901
+ const aiModel = await import("misoai-core/ai-model");
1902
+ this.contextStore = aiModel.getContextStore();
1903
+ debug4("Context store initialized successfully", {
1904
+ autoClearContext: this.opts.autoClearContext,
1905
+ testId: this.opts.testId
1906
+ });
1907
+ if (this.opts.autoClearContext) {
1908
+ this.contextStore.clear();
1909
+ debug4("Context store cleared due to autoClearContext option");
1910
+ } else {
1911
+ const existingData = this.contextStore.getAllData();
1912
+ const existingSteps = this.contextStore.getRecentSteps(100).length;
1913
+ debug4("Context store preserving existing data", {
1914
+ existingDataKeys: Object.keys(existingData),
1915
+ existingStepsCount: existingSteps
1916
+ });
1917
+ }
1918
+ } catch (error) {
1919
+ debug4("Failed to initialize context store:", error);
1920
+ console.warn("⚠️ Could not initialize context store:", error);
1921
+ }
1922
+ }
1923
+ /**
1924
+ * Get the context store instance
1925
+ */
1926
+ getContextStore() {
1927
+ return this.contextStore;
1928
+ }
1929
+ /**
1930
+ * Clear the context store
1931
+ */
1932
+ clearContext() {
1933
+ if (this.contextStore) {
1934
+ this.contextStore.clear();
1935
+ }
1936
+ }
1937
+ /**
1938
+ * Get all stored data from context store
1939
+ */
1940
+ getStoredData() {
1941
+ if (this.contextStore) {
1942
+ return this.contextStore.getAllData();
1943
+ }
1944
+ return {};
1945
+ }
1946
+ /**
1947
+ * Get step summary from context store
1948
+ */
1949
+ getStepSummary() {
1950
+ if (this.contextStore) {
1951
+ return this.contextStore.getStepSummary();
1952
+ }
1953
+ return "";
1954
+ }
1889
1955
  async getUIContext(action) {
1890
1956
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
1891
1957
  return await parseContextFromWebPage(this.page, {
@@ -2121,18 +2187,30 @@ var PageAgent = class {
2121
2187
  };
2122
2188
  }
2123
2189
  async aiAction(taskPrompt, opt) {
2124
- try {
2125
- const aiModel = await import("misoai-core/ai-model");
2126
- const contextStore = aiModel.getContextStore();
2127
- const processedPrompt = contextStore.replaceAllReferences(taskPrompt, "action");
2128
- contextStore.addStep({
2129
- type: "action",
2130
- summary: `Action: ${processedPrompt}`,
2131
- prompt: processedPrompt
2132
- });
2133
- taskPrompt = processedPrompt;
2134
- } catch (error) {
2135
- debug4("Context store not available:", error);
2190
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2191
+ try {
2192
+ const originalPrompt = taskPrompt;
2193
+ const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
2194
+ if (originalPrompt !== processedPrompt) {
2195
+ debug4("Context replacement in aiAction:", {
2196
+ original: originalPrompt,
2197
+ processed: processedPrompt,
2198
+ storedData: this.contextStore.getAllData()
2199
+ });
2200
+ }
2201
+ this.contextStore.addStep({
2202
+ type: "action",
2203
+ summary: `Action: ${processedPrompt}`,
2204
+ prompt: processedPrompt
2205
+ });
2206
+ debug4("Added action step to context store:", {
2207
+ stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2208
+ totalSteps: this.contextStore.getRecentSteps(100).length
2209
+ });
2210
+ taskPrompt = processedPrompt;
2211
+ } catch (error) {
2212
+ debug4("Context store operation failed:", error);
2213
+ }
2136
2214
  }
2137
2215
  const cacheable = opt?.cacheable;
2138
2216
  const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
@@ -2203,38 +2281,50 @@ var PageAgent = class {
2203
2281
  debug4("Context store not available:", error);
2204
2282
  }
2205
2283
  const { output, executor } = await this.taskExecutor.query(processedDemand);
2206
- if (storageKey && output) {
2207
- try {
2208
- const aiModel = await import("misoai-core/ai-model");
2209
- const contextStore = aiModel.getContextStore();
2210
- const pendingAliases = contextStore._pendingAliases;
2211
- if (pendingAliases) {
2212
- contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2213
- delete contextStore._pendingAliases;
2214
- } else {
2215
- contextStore.storeData(storageKey, output);
2284
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2285
+ if (storageKey && output) {
2286
+ try {
2287
+ const pendingAliases = this.contextStore._pendingAliases;
2288
+ if (pendingAliases) {
2289
+ this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2290
+ delete this.contextStore._pendingAliases;
2291
+ debug4("Stored query result with aliases:", {
2292
+ key: storageKey,
2293
+ value: output,
2294
+ aliases: pendingAliases
2295
+ });
2296
+ } else {
2297
+ this.contextStore.storeData(storageKey, output);
2298
+ debug4("Stored query result:", {
2299
+ key: storageKey,
2300
+ value: output
2301
+ });
2302
+ }
2303
+ this.contextStore.addStep({
2304
+ type: "query",
2305
+ summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2306
+ data: output,
2307
+ prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2308
+ });
2309
+ debug4("Added query step to context store:", {
2310
+ storageKey,
2311
+ totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
2312
+ totalSteps: this.contextStore.getRecentSteps(100).length
2313
+ });
2314
+ } catch (error) {
2315
+ debug4("Failed to store query result:", error);
2316
+ }
2317
+ } else {
2318
+ try {
2319
+ this.contextStore.addStep({
2320
+ type: "query",
2321
+ summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2322
+ data: output,
2323
+ prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2324
+ });
2325
+ } catch (error) {
2326
+ debug4("Failed to add query step:", error);
2216
2327
  }
2217
- contextStore.addStep({
2218
- type: "query",
2219
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2220
- data: output,
2221
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2222
- });
2223
- } catch (error) {
2224
- debug4("Failed to store query result:", error);
2225
- }
2226
- } else {
2227
- try {
2228
- const aiModel = await import("misoai-core/ai-model");
2229
- const contextStore = aiModel.getContextStore();
2230
- contextStore.addStep({
2231
- type: "query",
2232
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2233
- data: output,
2234
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2235
- });
2236
- } catch (error) {
2237
- debug4("Failed to add query step:", error);
2238
2328
  }
2239
2329
  }
2240
2330
  const metadata = this.afterTaskRunning(executor);
@@ -2347,17 +2437,29 @@ var PageAgent = class {
2347
2437
  }
2348
2438
  async aiAssert(assertion, msg, opt) {
2349
2439
  let processedAssertion = assertion;
2350
- try {
2351
- const aiModel = await import("misoai-core/ai-model");
2352
- const contextStore = aiModel.getContextStore();
2353
- processedAssertion = contextStore.replaceAllReferences(assertion, "assertion");
2354
- contextStore.addStep({
2355
- type: "assertion",
2356
- summary: `Assertion: ${processedAssertion}`,
2357
- prompt: processedAssertion
2358
- });
2359
- } catch (error) {
2360
- debug4("Context store not available:", error);
2440
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2441
+ try {
2442
+ const originalAssertion = assertion;
2443
+ processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
2444
+ if (originalAssertion !== processedAssertion) {
2445
+ debug4("Context replacement in aiAssert:", {
2446
+ original: originalAssertion,
2447
+ processed: processedAssertion,
2448
+ context: "assertion",
2449
+ storedData: this.contextStore.getAllData()
2450
+ });
2451
+ }
2452
+ this.contextStore.addStep({
2453
+ type: "assertion",
2454
+ summary: `Assertion: ${processedAssertion}`,
2455
+ prompt: processedAssertion
2456
+ });
2457
+ debug4("Added assertion step to context store:", {
2458
+ totalSteps: this.contextStore.getRecentSteps(100).length
2459
+ });
2460
+ } catch (error) {
2461
+ debug4("Context store operation failed:", error);
2462
+ }
2361
2463
  }
2362
2464
  let currentUrl = "";
2363
2465
  if (this.page.url) {