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/es/index.js CHANGED
@@ -1688,7 +1688,7 @@ import yaml3 from "js-yaml";
1688
1688
  import semver from "semver";
1689
1689
 
1690
1690
  // package.json
1691
- var version = "1.0.4";
1691
+ var version = "1.0.5";
1692
1692
 
1693
1693
  // src/common/task-cache.ts
1694
1694
  var debug3 = getDebug3("cache");
@@ -1870,10 +1870,13 @@ var PageAgent = class {
1870
1870
  generateReport: true,
1871
1871
  autoPrintReportMsg: true,
1872
1872
  groupName: "Midscene Report",
1873
- groupDescription: ""
1873
+ groupDescription: "",
1874
+ enableCumulativeContext: true,
1875
+ autoClearContext: false
1874
1876
  },
1875
1877
  opts || {}
1876
1878
  );
1879
+ this.initializeContextStore();
1877
1880
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1878
1881
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1879
1882
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1900,6 +1903,69 @@ var PageAgent = class {
1900
1903
  opts?.testId || this.page.pageType || "web"
1901
1904
  );
1902
1905
  }
1906
+ /**
1907
+ * Initialize context store for cumulative context functionality
1908
+ */
1909
+ async initializeContextStore() {
1910
+ if (!this.opts.enableCumulativeContext) {
1911
+ debug4("Cumulative context disabled via options");
1912
+ return;
1913
+ }
1914
+ try {
1915
+ const aiModel = await import("misoai-core/ai-model");
1916
+ this.contextStore = aiModel.getContextStore();
1917
+ debug4("Context store initialized successfully", {
1918
+ autoClearContext: this.opts.autoClearContext,
1919
+ testId: this.opts.testId
1920
+ });
1921
+ if (this.opts.autoClearContext) {
1922
+ this.contextStore.clear();
1923
+ debug4("Context store cleared due to autoClearContext option");
1924
+ } else {
1925
+ const existingData = this.contextStore.getAllData();
1926
+ const existingSteps = this.contextStore.getRecentSteps(100).length;
1927
+ debug4("Context store preserving existing data", {
1928
+ existingDataKeys: Object.keys(existingData),
1929
+ existingStepsCount: existingSteps
1930
+ });
1931
+ }
1932
+ } catch (error) {
1933
+ debug4("Failed to initialize context store:", error);
1934
+ console.warn("⚠️ Could not initialize context store:", error);
1935
+ }
1936
+ }
1937
+ /**
1938
+ * Get the context store instance
1939
+ */
1940
+ getContextStore() {
1941
+ return this.contextStore;
1942
+ }
1943
+ /**
1944
+ * Clear the context store
1945
+ */
1946
+ clearContext() {
1947
+ if (this.contextStore) {
1948
+ this.contextStore.clear();
1949
+ }
1950
+ }
1951
+ /**
1952
+ * Get all stored data from context store
1953
+ */
1954
+ getStoredData() {
1955
+ if (this.contextStore) {
1956
+ return this.contextStore.getAllData();
1957
+ }
1958
+ return {};
1959
+ }
1960
+ /**
1961
+ * Get step summary from context store
1962
+ */
1963
+ getStepSummary() {
1964
+ if (this.contextStore) {
1965
+ return this.contextStore.getStepSummary();
1966
+ }
1967
+ return "";
1968
+ }
1903
1969
  async getUIContext(action) {
1904
1970
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
1905
1971
  return await parseContextFromWebPage(this.page, {
@@ -2135,18 +2201,30 @@ var PageAgent = class {
2135
2201
  };
2136
2202
  }
2137
2203
  async aiAction(taskPrompt, opt) {
2138
- try {
2139
- const aiModel = await import("misoai-core/ai-model");
2140
- const contextStore = aiModel.getContextStore();
2141
- const processedPrompt = contextStore.replaceAllReferences(taskPrompt, "action");
2142
- contextStore.addStep({
2143
- type: "action",
2144
- summary: `Action: ${processedPrompt}`,
2145
- prompt: processedPrompt
2146
- });
2147
- taskPrompt = processedPrompt;
2148
- } catch (error) {
2149
- debug4("Context store not available:", error);
2204
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2205
+ try {
2206
+ const originalPrompt = taskPrompt;
2207
+ const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
2208
+ if (originalPrompt !== processedPrompt) {
2209
+ debug4("Context replacement in aiAction:", {
2210
+ original: originalPrompt,
2211
+ processed: processedPrompt,
2212
+ storedData: this.contextStore.getAllData()
2213
+ });
2214
+ }
2215
+ this.contextStore.addStep({
2216
+ type: "action",
2217
+ summary: `Action: ${processedPrompt}`,
2218
+ prompt: processedPrompt
2219
+ });
2220
+ debug4("Added action step to context store:", {
2221
+ stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2222
+ totalSteps: this.contextStore.getRecentSteps(100).length
2223
+ });
2224
+ taskPrompt = processedPrompt;
2225
+ } catch (error) {
2226
+ debug4("Context store operation failed:", error);
2227
+ }
2150
2228
  }
2151
2229
  const cacheable = opt?.cacheable;
2152
2230
  const isVlmUiTars = vlLocateMode() === "vlm-ui-tars";
@@ -2217,38 +2295,50 @@ var PageAgent = class {
2217
2295
  debug4("Context store not available:", error);
2218
2296
  }
2219
2297
  const { output, executor } = await this.taskExecutor.query(processedDemand);
2220
- if (storageKey && output) {
2221
- try {
2222
- const aiModel = await import("misoai-core/ai-model");
2223
- const contextStore = aiModel.getContextStore();
2224
- const pendingAliases = contextStore._pendingAliases;
2225
- if (pendingAliases) {
2226
- contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2227
- delete contextStore._pendingAliases;
2228
- } else {
2229
- contextStore.storeData(storageKey, output);
2298
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2299
+ if (storageKey && output) {
2300
+ try {
2301
+ const pendingAliases = this.contextStore._pendingAliases;
2302
+ if (pendingAliases) {
2303
+ this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2304
+ delete this.contextStore._pendingAliases;
2305
+ debug4("Stored query result with aliases:", {
2306
+ key: storageKey,
2307
+ value: output,
2308
+ aliases: pendingAliases
2309
+ });
2310
+ } else {
2311
+ this.contextStore.storeData(storageKey, output);
2312
+ debug4("Stored query result:", {
2313
+ key: storageKey,
2314
+ value: output
2315
+ });
2316
+ }
2317
+ this.contextStore.addStep({
2318
+ type: "query",
2319
+ summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2320
+ data: output,
2321
+ prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2322
+ });
2323
+ debug4("Added query step to context store:", {
2324
+ storageKey,
2325
+ totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
2326
+ totalSteps: this.contextStore.getRecentSteps(100).length
2327
+ });
2328
+ } catch (error) {
2329
+ debug4("Failed to store query result:", error);
2330
+ }
2331
+ } else {
2332
+ try {
2333
+ this.contextStore.addStep({
2334
+ type: "query",
2335
+ summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2336
+ data: output,
2337
+ prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2338
+ });
2339
+ } catch (error) {
2340
+ debug4("Failed to add query step:", error);
2230
2341
  }
2231
- contextStore.addStep({
2232
- type: "query",
2233
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2234
- data: output,
2235
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2236
- });
2237
- } catch (error) {
2238
- debug4("Failed to store query result:", error);
2239
- }
2240
- } else {
2241
- try {
2242
- const aiModel = await import("misoai-core/ai-model");
2243
- const contextStore = aiModel.getContextStore();
2244
- contextStore.addStep({
2245
- type: "query",
2246
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2247
- data: output,
2248
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2249
- });
2250
- } catch (error) {
2251
- debug4("Failed to add query step:", error);
2252
2342
  }
2253
2343
  }
2254
2344
  const metadata = this.afterTaskRunning(executor);
@@ -2361,17 +2451,29 @@ var PageAgent = class {
2361
2451
  }
2362
2452
  async aiAssert(assertion, msg, opt) {
2363
2453
  let processedAssertion = assertion;
2364
- try {
2365
- const aiModel = await import("misoai-core/ai-model");
2366
- const contextStore = aiModel.getContextStore();
2367
- processedAssertion = contextStore.replaceAllReferences(assertion, "assertion");
2368
- contextStore.addStep({
2369
- type: "assertion",
2370
- summary: `Assertion: ${processedAssertion}`,
2371
- prompt: processedAssertion
2372
- });
2373
- } catch (error) {
2374
- debug4("Context store not available:", error);
2454
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2455
+ try {
2456
+ const originalAssertion = assertion;
2457
+ processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
2458
+ if (originalAssertion !== processedAssertion) {
2459
+ debug4("Context replacement in aiAssert:", {
2460
+ original: originalAssertion,
2461
+ processed: processedAssertion,
2462
+ context: "assertion",
2463
+ storedData: this.contextStore.getAllData()
2464
+ });
2465
+ }
2466
+ this.contextStore.addStep({
2467
+ type: "assertion",
2468
+ summary: `Assertion: ${processedAssertion}`,
2469
+ prompt: processedAssertion
2470
+ });
2471
+ debug4("Added assertion step to context store:", {
2472
+ totalSteps: this.contextStore.getRecentSteps(100).length
2473
+ });
2474
+ } catch (error) {
2475
+ debug4("Context store operation failed:", error);
2476
+ }
2375
2477
  }
2376
2478
  let currentUrl = "";
2377
2479
  if (this.page.url) {