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
@@ -291,7 +291,7 @@ function sleep(ms) {
291
291
  var ChromeExtensionProxyPage = class {
292
292
  constructor(forceSameTabNavigation) {
293
293
  this.pageType = "chrome-extension-proxy";
294
- this.version = "1.0.4";
294
+ this.version = "1.0.5";
295
295
  this.activeTabId = null;
296
296
  this.tabIdOfDebuggerAttached = null;
297
297
  this.attachingDebugger = null;
@@ -784,7 +784,7 @@ var BridgeClient = class {
784
784
  this.socket = (0, import_socket.io)(this.endpoint, {
785
785
  reconnection: false,
786
786
  query: {
787
- version: "1.0.4"
787
+ version: "1.0.5"
788
788
  }
789
789
  });
790
790
  const timeout = setTimeout(() => {
@@ -925,7 +925,7 @@ var ExtensionBridgePageBrowserSide = class extends ChromeExtensionProxyPage {
925
925
  );
926
926
  await this.bridgeClient.connect();
927
927
  this.onLogMessage(
928
- `Bridge connected, cli-side version v${this.bridgeClient.serverVersion}, browser-side version v${"1.0.4"}`,
928
+ `Bridge connected, cli-side version v${this.bridgeClient.serverVersion}, browser-side version v${"1.0.5"}`,
929
929
  "log"
930
930
  );
931
931
  }
@@ -1679,7 +1679,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1679
1679
  var import_semver = __toESM(require("semver"));
1680
1680
 
1681
1681
  // package.json
1682
- var version = "1.0.4";
1682
+ var version = "1.0.5";
1683
1683
 
1684
1684
  // src/common/task-cache.ts
1685
1685
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -1861,10 +1861,13 @@ var PageAgent = class {
1861
1861
  generateReport: true,
1862
1862
  autoPrintReportMsg: true,
1863
1863
  groupName: "Midscene Report",
1864
- groupDescription: ""
1864
+ groupDescription: "",
1865
+ enableCumulativeContext: true,
1866
+ autoClearContext: false
1865
1867
  },
1866
1868
  opts || {}
1867
1869
  );
1870
+ this.initializeContextStore();
1868
1871
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1869
1872
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || import_constants2.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1870
1873
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || import_constants2.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1891,6 +1894,69 @@ var PageAgent = class {
1891
1894
  opts?.testId || this.page.pageType || "web"
1892
1895
  );
1893
1896
  }
1897
+ /**
1898
+ * Initialize context store for cumulative context functionality
1899
+ */
1900
+ async initializeContextStore() {
1901
+ if (!this.opts.enableCumulativeContext) {
1902
+ debug4("Cumulative context disabled via options");
1903
+ return;
1904
+ }
1905
+ try {
1906
+ const aiModel = await import("misoai-core/ai-model");
1907
+ this.contextStore = aiModel.getContextStore();
1908
+ debug4("Context store initialized successfully", {
1909
+ autoClearContext: this.opts.autoClearContext,
1910
+ testId: this.opts.testId
1911
+ });
1912
+ if (this.opts.autoClearContext) {
1913
+ this.contextStore.clear();
1914
+ debug4("Context store cleared due to autoClearContext option");
1915
+ } else {
1916
+ const existingData = this.contextStore.getAllData();
1917
+ const existingSteps = this.contextStore.getRecentSteps(100).length;
1918
+ debug4("Context store preserving existing data", {
1919
+ existingDataKeys: Object.keys(existingData),
1920
+ existingStepsCount: existingSteps
1921
+ });
1922
+ }
1923
+ } catch (error) {
1924
+ debug4("Failed to initialize context store:", error);
1925
+ console.warn("⚠️ Could not initialize context store:", error);
1926
+ }
1927
+ }
1928
+ /**
1929
+ * Get the context store instance
1930
+ */
1931
+ getContextStore() {
1932
+ return this.contextStore;
1933
+ }
1934
+ /**
1935
+ * Clear the context store
1936
+ */
1937
+ clearContext() {
1938
+ if (this.contextStore) {
1939
+ this.contextStore.clear();
1940
+ }
1941
+ }
1942
+ /**
1943
+ * Get all stored data from context store
1944
+ */
1945
+ getStoredData() {
1946
+ if (this.contextStore) {
1947
+ return this.contextStore.getAllData();
1948
+ }
1949
+ return {};
1950
+ }
1951
+ /**
1952
+ * Get step summary from context store
1953
+ */
1954
+ getStepSummary() {
1955
+ if (this.contextStore) {
1956
+ return this.contextStore.getStepSummary();
1957
+ }
1958
+ return "";
1959
+ }
1894
1960
  async getUIContext(action) {
1895
1961
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
1896
1962
  return await parseContextFromWebPage(this.page, {
@@ -2126,18 +2192,30 @@ var PageAgent = class {
2126
2192
  };
2127
2193
  }
2128
2194
  async aiAction(taskPrompt, opt) {
2129
- try {
2130
- const aiModel = await import("misoai-core/ai-model");
2131
- const contextStore = aiModel.getContextStore();
2132
- const processedPrompt = contextStore.replaceAllReferences(taskPrompt, "action");
2133
- contextStore.addStep({
2134
- type: "action",
2135
- summary: `Action: ${processedPrompt}`,
2136
- prompt: processedPrompt
2137
- });
2138
- taskPrompt = processedPrompt;
2139
- } catch (error) {
2140
- debug4("Context store not available:", error);
2195
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2196
+ try {
2197
+ const originalPrompt = taskPrompt;
2198
+ const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
2199
+ if (originalPrompt !== processedPrompt) {
2200
+ debug4("Context replacement in aiAction:", {
2201
+ original: originalPrompt,
2202
+ processed: processedPrompt,
2203
+ storedData: this.contextStore.getAllData()
2204
+ });
2205
+ }
2206
+ this.contextStore.addStep({
2207
+ type: "action",
2208
+ summary: `Action: ${processedPrompt}`,
2209
+ prompt: processedPrompt
2210
+ });
2211
+ debug4("Added action step to context store:", {
2212
+ stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2213
+ totalSteps: this.contextStore.getRecentSteps(100).length
2214
+ });
2215
+ taskPrompt = processedPrompt;
2216
+ } catch (error) {
2217
+ debug4("Context store operation failed:", error);
2218
+ }
2141
2219
  }
2142
2220
  const cacheable = opt?.cacheable;
2143
2221
  const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
@@ -2208,38 +2286,50 @@ var PageAgent = class {
2208
2286
  debug4("Context store not available:", error);
2209
2287
  }
2210
2288
  const { output, executor } = await this.taskExecutor.query(processedDemand);
2211
- if (storageKey && output) {
2212
- try {
2213
- const aiModel = await import("misoai-core/ai-model");
2214
- const contextStore = aiModel.getContextStore();
2215
- const pendingAliases = contextStore._pendingAliases;
2216
- if (pendingAliases) {
2217
- contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2218
- delete contextStore._pendingAliases;
2219
- } else {
2220
- contextStore.storeData(storageKey, output);
2289
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2290
+ if (storageKey && output) {
2291
+ try {
2292
+ const pendingAliases = this.contextStore._pendingAliases;
2293
+ if (pendingAliases) {
2294
+ this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2295
+ delete this.contextStore._pendingAliases;
2296
+ debug4("Stored query result with aliases:", {
2297
+ key: storageKey,
2298
+ value: output,
2299
+ aliases: pendingAliases
2300
+ });
2301
+ } else {
2302
+ this.contextStore.storeData(storageKey, output);
2303
+ debug4("Stored query result:", {
2304
+ key: storageKey,
2305
+ value: output
2306
+ });
2307
+ }
2308
+ this.contextStore.addStep({
2309
+ type: "query",
2310
+ summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2311
+ data: output,
2312
+ prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2313
+ });
2314
+ debug4("Added query step to context store:", {
2315
+ storageKey,
2316
+ totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
2317
+ totalSteps: this.contextStore.getRecentSteps(100).length
2318
+ });
2319
+ } catch (error) {
2320
+ debug4("Failed to store query result:", error);
2321
+ }
2322
+ } else {
2323
+ try {
2324
+ this.contextStore.addStep({
2325
+ type: "query",
2326
+ summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2327
+ data: output,
2328
+ prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2329
+ });
2330
+ } catch (error) {
2331
+ debug4("Failed to add query step:", error);
2221
2332
  }
2222
- contextStore.addStep({
2223
- type: "query",
2224
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2225
- data: output,
2226
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2227
- });
2228
- } catch (error) {
2229
- debug4("Failed to store query result:", error);
2230
- }
2231
- } else {
2232
- try {
2233
- const aiModel = await import("misoai-core/ai-model");
2234
- const contextStore = aiModel.getContextStore();
2235
- contextStore.addStep({
2236
- type: "query",
2237
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2238
- data: output,
2239
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2240
- });
2241
- } catch (error) {
2242
- debug4("Failed to add query step:", error);
2243
2333
  }
2244
2334
  }
2245
2335
  const metadata = this.afterTaskRunning(executor);
@@ -2352,17 +2442,29 @@ var PageAgent = class {
2352
2442
  }
2353
2443
  async aiAssert(assertion, msg, opt) {
2354
2444
  let processedAssertion = assertion;
2355
- try {
2356
- const aiModel = await import("misoai-core/ai-model");
2357
- const contextStore = aiModel.getContextStore();
2358
- processedAssertion = contextStore.replaceAllReferences(assertion, "assertion");
2359
- contextStore.addStep({
2360
- type: "assertion",
2361
- summary: `Assertion: ${processedAssertion}`,
2362
- prompt: processedAssertion
2363
- });
2364
- } catch (error) {
2365
- debug4("Context store not available:", error);
2445
+ if (this.opts.enableCumulativeContext && this.contextStore) {
2446
+ try {
2447
+ const originalAssertion = assertion;
2448
+ processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
2449
+ if (originalAssertion !== processedAssertion) {
2450
+ debug4("Context replacement in aiAssert:", {
2451
+ original: originalAssertion,
2452
+ processed: processedAssertion,
2453
+ context: "assertion",
2454
+ storedData: this.contextStore.getAllData()
2455
+ });
2456
+ }
2457
+ this.contextStore.addStep({
2458
+ type: "assertion",
2459
+ summary: `Assertion: ${processedAssertion}`,
2460
+ prompt: processedAssertion
2461
+ });
2462
+ debug4("Added assertion step to context store:", {
2463
+ totalSteps: this.contextStore.getRecentSteps(100).length
2464
+ });
2465
+ } catch (error) {
2466
+ debug4("Context store operation failed:", error);
2467
+ }
2366
2468
  }
2367
2469
  let currentUrl = "";
2368
2470
  if (this.page.url) {
@@ -2697,7 +2799,7 @@ var BridgeServer = class {
2697
2799
  this.socket = socket;
2698
2800
  const clientVersion = socket.handshake.query.version;
2699
2801
  (0, import_utils16.logMsg)(
2700
- `Bridge connected, cli-side version v${"1.0.4"}, browser-side version v${clientVersion}`
2802
+ `Bridge connected, cli-side version v${"1.0.5"}, browser-side version v${clientVersion}`
2701
2803
  );
2702
2804
  socket.on("bridge-call-response" /* CallResponse */, (params) => {
2703
2805
  const id = params.id;
@@ -2728,7 +2830,7 @@ var BridgeServer = class {
2728
2830
  setTimeout(() => {
2729
2831
  this.onConnect?.();
2730
2832
  const payload = {
2731
- version: "1.0.4"
2833
+ version: "1.0.5"
2732
2834
  };
2733
2835
  socket.emit("bridge-connected" /* Connected */, payload);
2734
2836
  Promise.resolve().then(() => {