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
@@ -55,10 +55,11 @@ var ScriptPlayer = class {
55
55
  this.unnamedResultIndex = 0;
56
56
  this.pageAgent = null;
57
57
  this.result = {};
58
+ const target = script.target || script.web || script.android;
58
59
  if (import_utils.ifInBrowser) {
59
60
  this.output = void 0;
60
- } else if (script.target?.output) {
61
- this.output = (0, import_node_path.resolve)(process.cwd(), script.target.output);
61
+ } else if (target?.output) {
62
+ this.output = (0, import_node_path.resolve)(process.cwd(), target.output);
62
63
  } else {
63
64
  this.output = (0, import_node_path.join)((0, import_common.getMidsceneRunSubDir)("output"), `${process.pid}.json`);
64
65
  }
@@ -132,12 +133,13 @@ var ScriptPlayer = class {
132
133
  } else if ("aiAssert" in flowItem) {
133
134
  const assertTask = flowItem;
134
135
  const prompt = assertTask.aiAssert;
136
+ const msg = assertTask.errorMessage;
135
137
  (0, import_utils.assert)(prompt, "missing prompt for aiAssert");
136
138
  (0, import_utils.assert)(
137
139
  typeof prompt === "string",
138
140
  "prompt for aiAssert must be a string"
139
141
  );
140
- await agent.aiAssert(prompt);
142
+ await agent.aiAssert(prompt, msg);
141
143
  } else if ("aiQuery" in flowItem) {
142
144
  const queryTask = flowItem;
143
145
  const prompt = queryTask.aiQuery;
@@ -1706,7 +1708,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1706
1708
  var import_semver = __toESM(require("semver"));
1707
1709
 
1708
1710
  // package.json
1709
- var version = "1.0.5";
1711
+ var version = "1.5.6";
1710
1712
 
1711
1713
  // src/common/task-cache.ts
1712
1714
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -1888,13 +1890,10 @@ var PageAgent = class {
1888
1890
  generateReport: true,
1889
1891
  autoPrintReportMsg: true,
1890
1892
  groupName: "Midscene Report",
1891
- groupDescription: "",
1892
- enableCumulativeContext: true,
1893
- autoClearContext: false
1893
+ groupDescription: ""
1894
1894
  },
1895
1895
  opts || {}
1896
1896
  );
1897
- this.initializeContextStore();
1898
1897
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1899
1898
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || import_constants2.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1900
1899
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || import_constants2.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1921,69 +1920,6 @@ var PageAgent = class {
1921
1920
  opts?.testId || this.page.pageType || "web"
1922
1921
  );
1923
1922
  }
1924
- /**
1925
- * Initialize context store for cumulative context functionality
1926
- */
1927
- async initializeContextStore() {
1928
- if (!this.opts.enableCumulativeContext) {
1929
- debug4("Cumulative context disabled via options");
1930
- return;
1931
- }
1932
- try {
1933
- const aiModel = await import("misoai-core/ai-model");
1934
- this.contextStore = aiModel.getContextStore();
1935
- debug4("Context store initialized successfully", {
1936
- autoClearContext: this.opts.autoClearContext,
1937
- testId: this.opts.testId
1938
- });
1939
- if (this.opts.autoClearContext) {
1940
- this.contextStore.clear();
1941
- debug4("Context store cleared due to autoClearContext option");
1942
- } else {
1943
- const existingData = this.contextStore.getAllData();
1944
- const existingSteps = this.contextStore.getRecentSteps(100).length;
1945
- debug4("Context store preserving existing data", {
1946
- existingDataKeys: Object.keys(existingData),
1947
- existingStepsCount: existingSteps
1948
- });
1949
- }
1950
- } catch (error) {
1951
- debug4("Failed to initialize context store:", error);
1952
- console.warn("⚠️ Could not initialize context store:", error);
1953
- }
1954
- }
1955
- /**
1956
- * Get the context store instance
1957
- */
1958
- getContextStore() {
1959
- return this.contextStore;
1960
- }
1961
- /**
1962
- * Clear the context store
1963
- */
1964
- clearContext() {
1965
- if (this.contextStore) {
1966
- this.contextStore.clear();
1967
- }
1968
- }
1969
- /**
1970
- * Get all stored data from context store
1971
- */
1972
- getStoredData() {
1973
- if (this.contextStore) {
1974
- return this.contextStore.getAllData();
1975
- }
1976
- return {};
1977
- }
1978
- /**
1979
- * Get step summary from context store
1980
- */
1981
- getStepSummary() {
1982
- if (this.contextStore) {
1983
- return this.contextStore.getStepSummary();
1984
- }
1985
- return "";
1986
- }
1987
1923
  async getUIContext(action) {
1988
1924
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
1989
1925
  return await parseContextFromWebPage(this.page, {
@@ -2219,31 +2155,6 @@ var PageAgent = class {
2219
2155
  };
2220
2156
  }
2221
2157
  async aiAction(taskPrompt, opt) {
2222
- if (this.opts.enableCumulativeContext && this.contextStore) {
2223
- try {
2224
- const originalPrompt = taskPrompt;
2225
- const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
2226
- if (originalPrompt !== processedPrompt) {
2227
- debug4("Context replacement in aiAction:", {
2228
- original: originalPrompt,
2229
- processed: processedPrompt,
2230
- storedData: this.contextStore.getAllData()
2231
- });
2232
- }
2233
- this.contextStore.addStep({
2234
- type: "action",
2235
- summary: `Action: ${processedPrompt}`,
2236
- prompt: processedPrompt
2237
- });
2238
- debug4("Added action step to context store:", {
2239
- stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2240
- totalSteps: this.contextStore.getRecentSteps(100).length
2241
- });
2242
- taskPrompt = processedPrompt;
2243
- } catch (error) {
2244
- debug4("Context store operation failed:", error);
2245
- }
2246
- }
2247
2158
  const cacheable = opt?.cacheable;
2248
2159
  const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
2249
2160
  const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
@@ -2290,75 +2201,7 @@ var PageAgent = class {
2290
2201
  };
2291
2202
  }
2292
2203
  async aiQuery(demand) {
2293
- let processedDemand = demand;
2294
- let storageKey;
2295
- try {
2296
- const aiModel = await import("misoai-core/ai-model");
2297
- const contextStore = aiModel.getContextStore();
2298
- if (typeof demand === "string") {
2299
- const storageInstruction = contextStore.parseStorageInstruction(demand);
2300
- if (storageInstruction) {
2301
- storageKey = storageInstruction.key;
2302
- processedDemand = storageInstruction.cleanText;
2303
- contextStore._pendingAliases = storageInstruction.aliases;
2304
- } else {
2305
- const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
2306
- if (storageMatch) {
2307
- storageKey = storageMatch[1];
2308
- processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
2309
- }
2310
- }
2311
- }
2312
- } catch (error) {
2313
- debug4("Context store not available:", error);
2314
- }
2315
- const { output, executor } = await this.taskExecutor.query(processedDemand);
2316
- if (this.opts.enableCumulativeContext && this.contextStore) {
2317
- if (storageKey && output) {
2318
- try {
2319
- const pendingAliases = this.contextStore._pendingAliases;
2320
- if (pendingAliases) {
2321
- this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2322
- delete this.contextStore._pendingAliases;
2323
- debug4("Stored query result with aliases:", {
2324
- key: storageKey,
2325
- value: output,
2326
- aliases: pendingAliases
2327
- });
2328
- } else {
2329
- this.contextStore.storeData(storageKey, output);
2330
- debug4("Stored query result:", {
2331
- key: storageKey,
2332
- value: output
2333
- });
2334
- }
2335
- this.contextStore.addStep({
2336
- type: "query",
2337
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2338
- data: output,
2339
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2340
- });
2341
- debug4("Added query step to context store:", {
2342
- storageKey,
2343
- totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
2344
- totalSteps: this.contextStore.getRecentSteps(100).length
2345
- });
2346
- } catch (error) {
2347
- debug4("Failed to store query result:", error);
2348
- }
2349
- } else {
2350
- try {
2351
- this.contextStore.addStep({
2352
- type: "query",
2353
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2354
- data: output,
2355
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2356
- });
2357
- } catch (error) {
2358
- debug4("Failed to add query step:", error);
2359
- }
2360
- }
2361
- }
2204
+ const { output, executor } = await this.taskExecutor.query(demand);
2362
2205
  const metadata = this.afterTaskRunning(executor);
2363
2206
  return {
2364
2207
  result: output,
@@ -2468,31 +2311,6 @@ var PageAgent = class {
2468
2311
  };
2469
2312
  }
2470
2313
  async aiAssert(assertion, msg, opt) {
2471
- let processedAssertion = assertion;
2472
- if (this.opts.enableCumulativeContext && this.contextStore) {
2473
- try {
2474
- const originalAssertion = assertion;
2475
- processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
2476
- if (originalAssertion !== processedAssertion) {
2477
- debug4("Context replacement in aiAssert:", {
2478
- original: originalAssertion,
2479
- processed: processedAssertion,
2480
- context: "assertion",
2481
- storedData: this.contextStore.getAllData()
2482
- });
2483
- }
2484
- this.contextStore.addStep({
2485
- type: "assertion",
2486
- summary: `Assertion: ${processedAssertion}`,
2487
- prompt: processedAssertion
2488
- });
2489
- debug4("Added assertion step to context store:", {
2490
- totalSteps: this.contextStore.getRecentSteps(100).length
2491
- });
2492
- } catch (error) {
2493
- debug4("Context store operation failed:", error);
2494
- }
2495
- }
2496
2314
  let currentUrl = "";
2497
2315
  if (this.page.url) {
2498
2316
  try {
@@ -2500,7 +2318,7 @@ var PageAgent = class {
2500
2318
  } catch (e) {
2501
2319
  }
2502
2320
  }
2503
- const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${processedAssertion}` : processedAssertion;
2321
+ const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
2504
2322
  const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
2505
2323
  const metadata = this.afterTaskRunning(executor, true);
2506
2324
  if (output && opt?.keepRawResponse) {
@@ -2735,7 +2553,7 @@ var Page = class {
2735
2553
  this.everMoved = false;
2736
2554
  this.underlyingPage = underlyingPage;
2737
2555
  this.pageType = pageType;
2738
- this.waitForNavigationTimeout = opts?.waitForNavigationTimeout || import_constants3.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
2556
+ this.waitForNavigationTimeout = opts?.waitForNavigationTimeout ?? import_constants3.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
2739
2557
  }
2740
2558
  async evaluate(pageFunction, arg) {
2741
2559
  let result;
@@ -3015,9 +2833,9 @@ var WebPage = class extends Page {
3015
2833
  }
3016
2834
  async waitUntilNetworkIdle(options) {
3017
2835
  await this.underlyingPage.waitForNetworkIdle({
3018
- idleTime: options?.idleTime || import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME,
3019
- concurrency: options?.concurrency || import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
3020
- timeout: options?.timeout || this.waitForNetworkIdleTimeout
2836
+ idleTime: options?.idleTime ?? import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME,
2837
+ concurrency: options?.concurrency ?? import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
2838
+ timeout: options?.timeout ?? this.waitForNetworkIdleTimeout
3021
2839
  });
3022
2840
  }
3023
2841
  };