misoai-web 1.0.5 → 1.5.6

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 (72) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +9 -353
  3. package/bin/midscene-playground +2 -2
  4. package/dist/es/agent.js +9 -191
  5. package/dist/es/agent.js.map +1 -1
  6. package/dist/es/bridge-mode-browser.js +3 -3
  7. package/dist/es/bridge-mode-browser.js.map +1 -1
  8. package/dist/es/bridge-mode.js +11 -193
  9. package/dist/es/bridge-mode.js.map +1 -1
  10. package/dist/es/chrome-extension.js +10 -192
  11. package/dist/es/chrome-extension.js.map +1 -1
  12. package/dist/es/index.js +13 -195
  13. package/dist/es/index.js.map +1 -1
  14. package/dist/es/midscene-playground.js +9 -191
  15. package/dist/es/midscene-playground.js.map +1 -1
  16. package/dist/es/midscene-server.js.map +1 -1
  17. package/dist/es/playground.js +9 -191
  18. package/dist/es/playground.js.map +1 -1
  19. package/dist/es/playwright-report.js.map +1 -1
  20. package/dist/es/playwright.js +10 -192
  21. package/dist/es/playwright.js.map +1 -1
  22. package/dist/es/puppeteer-agent-launcher.js +13 -195
  23. package/dist/es/puppeteer-agent-launcher.js.map +1 -1
  24. package/dist/es/puppeteer.js +13 -195
  25. package/dist/es/puppeteer.js.map +1 -1
  26. package/dist/es/ui-utils.js.map +1 -1
  27. package/dist/es/utils.js.map +1 -1
  28. package/dist/es/yaml.js +5 -3
  29. package/dist/es/yaml.js.map +1 -1
  30. package/dist/lib/agent.js +9 -191
  31. package/dist/lib/agent.js.map +1 -1
  32. package/dist/lib/bridge-mode-browser.js +3 -3
  33. package/dist/lib/bridge-mode-browser.js.map +1 -1
  34. package/dist/lib/bridge-mode.js +11 -193
  35. package/dist/lib/bridge-mode.js.map +1 -1
  36. package/dist/lib/chrome-extension.js +10 -192
  37. package/dist/lib/chrome-extension.js.map +1 -1
  38. package/dist/lib/index.js +13 -195
  39. package/dist/lib/index.js.map +1 -1
  40. package/dist/lib/midscene-playground.js +9 -191
  41. package/dist/lib/midscene-playground.js.map +1 -1
  42. package/dist/lib/midscene-server.js.map +1 -1
  43. package/dist/lib/playground.js +9 -191
  44. package/dist/lib/playground.js.map +1 -1
  45. package/dist/lib/playwright-report.js.map +1 -1
  46. package/dist/lib/playwright.js +10 -192
  47. package/dist/lib/playwright.js.map +1 -1
  48. package/dist/lib/puppeteer-agent-launcher.js +13 -195
  49. package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
  50. package/dist/lib/puppeteer.js +13 -195
  51. package/dist/lib/puppeteer.js.map +1 -1
  52. package/dist/lib/ui-utils.js.map +1 -1
  53. package/dist/lib/utils.js.map +1 -1
  54. package/dist/lib/yaml.js +5 -3
  55. package/dist/lib/yaml.js.map +1 -1
  56. package/dist/types/agent.d.ts +1 -27
  57. package/dist/types/bridge-mode-browser.d.ts +2 -2
  58. package/dist/types/bridge-mode.d.ts +2 -2
  59. package/dist/types/{browser-a1877d18.d.ts → browser-aec1055d.d.ts} +1 -1
  60. package/dist/types/chrome-extension.d.ts +2 -2
  61. package/dist/types/index.d.ts +1 -1
  62. package/dist/types/midscene-server.d.ts +1 -1
  63. package/dist/types/{page-663ece08.d.ts → page-86ab0fe1.d.ts} +34 -34
  64. package/dist/types/playground.d.ts +2 -2
  65. package/dist/types/playwright.d.ts +1 -1
  66. package/dist/types/puppeteer-agent-launcher.d.ts +1 -1
  67. package/dist/types/puppeteer.d.ts +1 -1
  68. package/dist/types/utils.d.ts +1 -1
  69. package/dist/types/yaml.d.ts +1 -1
  70. package/iife-script/htmlElement.js +2 -2
  71. package/iife-script/htmlElementDebug.js +2 -2
  72. package/package.json +3 -3
@@ -62,10 +62,11 @@ var ScriptPlayer = class {
62
62
  this.unnamedResultIndex = 0;
63
63
  this.pageAgent = null;
64
64
  this.result = {};
65
+ const target = script.target || script.web || script.android;
65
66
  if (import_utils.ifInBrowser) {
66
67
  this.output = void 0;
67
- } else if (script.target?.output) {
68
- this.output = (0, import_node_path.resolve)(process.cwd(), script.target.output);
68
+ } else if (target?.output) {
69
+ this.output = (0, import_node_path.resolve)(process.cwd(), target.output);
69
70
  } else {
70
71
  this.output = (0, import_node_path.join)((0, import_common.getMidsceneRunSubDir)("output"), `${process.pid}.json`);
71
72
  }
@@ -139,12 +140,13 @@ var ScriptPlayer = class {
139
140
  } else if ("aiAssert" in flowItem) {
140
141
  const assertTask = flowItem;
141
142
  const prompt = assertTask.aiAssert;
143
+ const msg = assertTask.errorMessage;
142
144
  (0, import_utils.assert)(prompt, "missing prompt for aiAssert");
143
145
  (0, import_utils.assert)(
144
146
  typeof prompt === "string",
145
147
  "prompt for aiAssert must be a string"
146
148
  );
147
- await agent.aiAssert(prompt);
149
+ await agent.aiAssert(prompt, msg);
148
150
  } else if ("aiQuery" in flowItem) {
149
151
  const queryTask = flowItem;
150
152
  const prompt = queryTask.aiQuery;
@@ -1713,7 +1715,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1713
1715
  var import_semver = __toESM(require("semver"));
1714
1716
 
1715
1717
  // package.json
1716
- var version = "1.0.5";
1718
+ var version = "1.5.6";
1717
1719
 
1718
1720
  // src/common/task-cache.ts
1719
1721
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -1895,13 +1897,10 @@ var PageAgent = class {
1895
1897
  generateReport: true,
1896
1898
  autoPrintReportMsg: true,
1897
1899
  groupName: "Midscene Report",
1898
- groupDescription: "",
1899
- enableCumulativeContext: true,
1900
- autoClearContext: false
1900
+ groupDescription: ""
1901
1901
  },
1902
1902
  opts || {}
1903
1903
  );
1904
- this.initializeContextStore();
1905
1904
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1906
1905
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || import_constants2.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1907
1906
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || import_constants2.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1928,69 +1927,6 @@ var PageAgent = class {
1928
1927
  opts?.testId || this.page.pageType || "web"
1929
1928
  );
1930
1929
  }
1931
- /**
1932
- * Initialize context store for cumulative context functionality
1933
- */
1934
- async initializeContextStore() {
1935
- if (!this.opts.enableCumulativeContext) {
1936
- debug4("Cumulative context disabled via options");
1937
- return;
1938
- }
1939
- try {
1940
- const aiModel = await import("misoai-core/ai-model");
1941
- this.contextStore = aiModel.getContextStore();
1942
- debug4("Context store initialized successfully", {
1943
- autoClearContext: this.opts.autoClearContext,
1944
- testId: this.opts.testId
1945
- });
1946
- if (this.opts.autoClearContext) {
1947
- this.contextStore.clear();
1948
- debug4("Context store cleared due to autoClearContext option");
1949
- } else {
1950
- const existingData = this.contextStore.getAllData();
1951
- const existingSteps = this.contextStore.getRecentSteps(100).length;
1952
- debug4("Context store preserving existing data", {
1953
- existingDataKeys: Object.keys(existingData),
1954
- existingStepsCount: existingSteps
1955
- });
1956
- }
1957
- } catch (error) {
1958
- debug4("Failed to initialize context store:", error);
1959
- console.warn("⚠️ Could not initialize context store:", error);
1960
- }
1961
- }
1962
- /**
1963
- * Get the context store instance
1964
- */
1965
- getContextStore() {
1966
- return this.contextStore;
1967
- }
1968
- /**
1969
- * Clear the context store
1970
- */
1971
- clearContext() {
1972
- if (this.contextStore) {
1973
- this.contextStore.clear();
1974
- }
1975
- }
1976
- /**
1977
- * Get all stored data from context store
1978
- */
1979
- getStoredData() {
1980
- if (this.contextStore) {
1981
- return this.contextStore.getAllData();
1982
- }
1983
- return {};
1984
- }
1985
- /**
1986
- * Get step summary from context store
1987
- */
1988
- getStepSummary() {
1989
- if (this.contextStore) {
1990
- return this.contextStore.getStepSummary();
1991
- }
1992
- return "";
1993
- }
1994
1930
  async getUIContext(action) {
1995
1931
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
1996
1932
  return await parseContextFromWebPage(this.page, {
@@ -2226,31 +2162,6 @@ var PageAgent = class {
2226
2162
  };
2227
2163
  }
2228
2164
  async aiAction(taskPrompt, opt) {
2229
- if (this.opts.enableCumulativeContext && this.contextStore) {
2230
- try {
2231
- const originalPrompt = taskPrompt;
2232
- const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
2233
- if (originalPrompt !== processedPrompt) {
2234
- debug4("Context replacement in aiAction:", {
2235
- original: originalPrompt,
2236
- processed: processedPrompt,
2237
- storedData: this.contextStore.getAllData()
2238
- });
2239
- }
2240
- this.contextStore.addStep({
2241
- type: "action",
2242
- summary: `Action: ${processedPrompt}`,
2243
- prompt: processedPrompt
2244
- });
2245
- debug4("Added action step to context store:", {
2246
- stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2247
- totalSteps: this.contextStore.getRecentSteps(100).length
2248
- });
2249
- taskPrompt = processedPrompt;
2250
- } catch (error) {
2251
- debug4("Context store operation failed:", error);
2252
- }
2253
- }
2254
2165
  const cacheable = opt?.cacheable;
2255
2166
  const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
2256
2167
  const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
@@ -2297,75 +2208,7 @@ var PageAgent = class {
2297
2208
  };
2298
2209
  }
2299
2210
  async aiQuery(demand) {
2300
- let processedDemand = demand;
2301
- let storageKey;
2302
- try {
2303
- const aiModel = await import("misoai-core/ai-model");
2304
- const contextStore = aiModel.getContextStore();
2305
- if (typeof demand === "string") {
2306
- const storageInstruction = contextStore.parseStorageInstruction(demand);
2307
- if (storageInstruction) {
2308
- storageKey = storageInstruction.key;
2309
- processedDemand = storageInstruction.cleanText;
2310
- contextStore._pendingAliases = storageInstruction.aliases;
2311
- } else {
2312
- const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
2313
- if (storageMatch) {
2314
- storageKey = storageMatch[1];
2315
- processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
2316
- }
2317
- }
2318
- }
2319
- } catch (error) {
2320
- debug4("Context store not available:", error);
2321
- }
2322
- const { output, executor } = await this.taskExecutor.query(processedDemand);
2323
- if (this.opts.enableCumulativeContext && this.contextStore) {
2324
- if (storageKey && output) {
2325
- try {
2326
- const pendingAliases = this.contextStore._pendingAliases;
2327
- if (pendingAliases) {
2328
- this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2329
- delete this.contextStore._pendingAliases;
2330
- debug4("Stored query result with aliases:", {
2331
- key: storageKey,
2332
- value: output,
2333
- aliases: pendingAliases
2334
- });
2335
- } else {
2336
- this.contextStore.storeData(storageKey, output);
2337
- debug4("Stored query result:", {
2338
- key: storageKey,
2339
- value: output
2340
- });
2341
- }
2342
- this.contextStore.addStep({
2343
- type: "query",
2344
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2345
- data: output,
2346
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2347
- });
2348
- debug4("Added query step to context store:", {
2349
- storageKey,
2350
- totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
2351
- totalSteps: this.contextStore.getRecentSteps(100).length
2352
- });
2353
- } catch (error) {
2354
- debug4("Failed to store query result:", error);
2355
- }
2356
- } else {
2357
- try {
2358
- this.contextStore.addStep({
2359
- type: "query",
2360
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2361
- data: output,
2362
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2363
- });
2364
- } catch (error) {
2365
- debug4("Failed to add query step:", error);
2366
- }
2367
- }
2368
- }
2211
+ const { output, executor } = await this.taskExecutor.query(demand);
2369
2212
  const metadata = this.afterTaskRunning(executor);
2370
2213
  return {
2371
2214
  result: output,
@@ -2475,31 +2318,6 @@ var PageAgent = class {
2475
2318
  };
2476
2319
  }
2477
2320
  async aiAssert(assertion, msg, opt) {
2478
- let processedAssertion = assertion;
2479
- if (this.opts.enableCumulativeContext && this.contextStore) {
2480
- try {
2481
- const originalAssertion = assertion;
2482
- processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
2483
- if (originalAssertion !== processedAssertion) {
2484
- debug4("Context replacement in aiAssert:", {
2485
- original: originalAssertion,
2486
- processed: processedAssertion,
2487
- context: "assertion",
2488
- storedData: this.contextStore.getAllData()
2489
- });
2490
- }
2491
- this.contextStore.addStep({
2492
- type: "assertion",
2493
- summary: `Assertion: ${processedAssertion}`,
2494
- prompt: processedAssertion
2495
- });
2496
- debug4("Added assertion step to context store:", {
2497
- totalSteps: this.contextStore.getRecentSteps(100).length
2498
- });
2499
- } catch (error) {
2500
- debug4("Context store operation failed:", error);
2501
- }
2502
- }
2503
2321
  let currentUrl = "";
2504
2322
  if (this.page.url) {
2505
2323
  try {
@@ -2507,7 +2325,7 @@ var PageAgent = class {
2507
2325
  } catch (e) {
2508
2326
  }
2509
2327
  }
2510
- const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${processedAssertion}` : processedAssertion;
2328
+ const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
2511
2329
  const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
2512
2330
  const metadata = this.afterTaskRunning(executor, true);
2513
2331
  if (output && opt?.keepRawResponse) {
@@ -2742,7 +2560,7 @@ var Page = class {
2742
2560
  this.everMoved = false;
2743
2561
  this.underlyingPage = underlyingPage;
2744
2562
  this.pageType = pageType;
2745
- this.waitForNavigationTimeout = opts?.waitForNavigationTimeout || import_constants3.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
2563
+ this.waitForNavigationTimeout = opts?.waitForNavigationTimeout ?? import_constants3.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
2746
2564
  }
2747
2565
  async evaluate(pageFunction, arg) {
2748
2566
  let result;
@@ -3022,9 +2840,9 @@ var WebPage = class extends Page {
3022
2840
  }
3023
2841
  async waitUntilNetworkIdle(options) {
3024
2842
  await this.underlyingPage.waitForNetworkIdle({
3025
- idleTime: options?.idleTime || import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME,
3026
- concurrency: options?.concurrency || import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
3027
- timeout: options?.timeout || this.waitForNetworkIdleTimeout
2843
+ idleTime: options?.idleTime ?? import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME,
2844
+ concurrency: options?.concurrency ?? import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
2845
+ timeout: options?.timeout ?? this.waitForNetworkIdleTimeout
3028
2846
  });
3029
2847
  }
3030
2848
  };