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
@@ -22,10 +22,11 @@ var ScriptPlayer = class {
22
22
  this.unnamedResultIndex = 0;
23
23
  this.pageAgent = null;
24
24
  this.result = {};
25
+ const target = script.target || script.web || script.android;
25
26
  if (ifInBrowser) {
26
27
  this.output = void 0;
27
- } else if (script.target?.output) {
28
- this.output = resolve(process.cwd(), script.target.output);
28
+ } else if (target?.output) {
29
+ this.output = resolve(process.cwd(), target.output);
29
30
  } else {
30
31
  this.output = join(getMidsceneRunSubDir("output"), `${process.pid}.json`);
31
32
  }
@@ -99,12 +100,13 @@ var ScriptPlayer = class {
99
100
  } else if ("aiAssert" in flowItem) {
100
101
  const assertTask = flowItem;
101
102
  const prompt = assertTask.aiAssert;
103
+ const msg = assertTask.errorMessage;
102
104
  assert(prompt, "missing prompt for aiAssert");
103
105
  assert(
104
106
  typeof prompt === "string",
105
107
  "prompt for aiAssert must be a string"
106
108
  );
107
- await agent.aiAssert(prompt);
109
+ await agent.aiAssert(prompt, msg);
108
110
  } else if ("aiQuery" in flowItem) {
109
111
  const queryTask = flowItem;
110
112
  const prompt = queryTask.aiQuery;
@@ -1693,7 +1695,7 @@ import yaml3 from "js-yaml";
1693
1695
  import semver from "semver";
1694
1696
 
1695
1697
  // package.json
1696
- var version = "1.0.5";
1698
+ var version = "1.5.6";
1697
1699
 
1698
1700
  // src/common/task-cache.ts
1699
1701
  var debug3 = getDebug3("cache");
@@ -1875,13 +1877,10 @@ var PageAgent = class {
1875
1877
  generateReport: true,
1876
1878
  autoPrintReportMsg: true,
1877
1879
  groupName: "Midscene Report",
1878
- groupDescription: "",
1879
- enableCumulativeContext: true,
1880
- autoClearContext: false
1880
+ groupDescription: ""
1881
1881
  },
1882
1882
  opts || {}
1883
1883
  );
1884
- this.initializeContextStore();
1885
1884
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1886
1885
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1887
1886
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1908,69 +1907,6 @@ var PageAgent = class {
1908
1907
  opts?.testId || this.page.pageType || "web"
1909
1908
  );
1910
1909
  }
1911
- /**
1912
- * Initialize context store for cumulative context functionality
1913
- */
1914
- async initializeContextStore() {
1915
- if (!this.opts.enableCumulativeContext) {
1916
- debug4("Cumulative context disabled via options");
1917
- return;
1918
- }
1919
- try {
1920
- const aiModel = await import("misoai-core/ai-model");
1921
- this.contextStore = aiModel.getContextStore();
1922
- debug4("Context store initialized successfully", {
1923
- autoClearContext: this.opts.autoClearContext,
1924
- testId: this.opts.testId
1925
- });
1926
- if (this.opts.autoClearContext) {
1927
- this.contextStore.clear();
1928
- debug4("Context store cleared due to autoClearContext option");
1929
- } else {
1930
- const existingData = this.contextStore.getAllData();
1931
- const existingSteps = this.contextStore.getRecentSteps(100).length;
1932
- debug4("Context store preserving existing data", {
1933
- existingDataKeys: Object.keys(existingData),
1934
- existingStepsCount: existingSteps
1935
- });
1936
- }
1937
- } catch (error) {
1938
- debug4("Failed to initialize context store:", error);
1939
- console.warn("⚠️ Could not initialize context store:", error);
1940
- }
1941
- }
1942
- /**
1943
- * Get the context store instance
1944
- */
1945
- getContextStore() {
1946
- return this.contextStore;
1947
- }
1948
- /**
1949
- * Clear the context store
1950
- */
1951
- clearContext() {
1952
- if (this.contextStore) {
1953
- this.contextStore.clear();
1954
- }
1955
- }
1956
- /**
1957
- * Get all stored data from context store
1958
- */
1959
- getStoredData() {
1960
- if (this.contextStore) {
1961
- return this.contextStore.getAllData();
1962
- }
1963
- return {};
1964
- }
1965
- /**
1966
- * Get step summary from context store
1967
- */
1968
- getStepSummary() {
1969
- if (this.contextStore) {
1970
- return this.contextStore.getStepSummary();
1971
- }
1972
- return "";
1973
- }
1974
1910
  async getUIContext(action) {
1975
1911
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
1976
1912
  return await parseContextFromWebPage(this.page, {
@@ -2206,31 +2142,6 @@ var PageAgent = class {
2206
2142
  };
2207
2143
  }
2208
2144
  async aiAction(taskPrompt, opt) {
2209
- if (this.opts.enableCumulativeContext && this.contextStore) {
2210
- try {
2211
- const originalPrompt = taskPrompt;
2212
- const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
2213
- if (originalPrompt !== processedPrompt) {
2214
- debug4("Context replacement in aiAction:", {
2215
- original: originalPrompt,
2216
- processed: processedPrompt,
2217
- storedData: this.contextStore.getAllData()
2218
- });
2219
- }
2220
- this.contextStore.addStep({
2221
- type: "action",
2222
- summary: `Action: ${processedPrompt}`,
2223
- prompt: processedPrompt
2224
- });
2225
- debug4("Added action step to context store:", {
2226
- stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2227
- totalSteps: this.contextStore.getRecentSteps(100).length
2228
- });
2229
- taskPrompt = processedPrompt;
2230
- } catch (error) {
2231
- debug4("Context store operation failed:", error);
2232
- }
2233
- }
2234
2145
  const cacheable = opt?.cacheable;
2235
2146
  const isVlmUiTars = vlLocateMode() === "vlm-ui-tars";
2236
2147
  const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
@@ -2277,75 +2188,7 @@ var PageAgent = class {
2277
2188
  };
2278
2189
  }
2279
2190
  async aiQuery(demand) {
2280
- let processedDemand = demand;
2281
- let storageKey;
2282
- try {
2283
- const aiModel = await import("misoai-core/ai-model");
2284
- const contextStore = aiModel.getContextStore();
2285
- if (typeof demand === "string") {
2286
- const storageInstruction = contextStore.parseStorageInstruction(demand);
2287
- if (storageInstruction) {
2288
- storageKey = storageInstruction.key;
2289
- processedDemand = storageInstruction.cleanText;
2290
- contextStore._pendingAliases = storageInstruction.aliases;
2291
- } else {
2292
- const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
2293
- if (storageMatch) {
2294
- storageKey = storageMatch[1];
2295
- processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
2296
- }
2297
- }
2298
- }
2299
- } catch (error) {
2300
- debug4("Context store not available:", error);
2301
- }
2302
- const { output, executor } = await this.taskExecutor.query(processedDemand);
2303
- if (this.opts.enableCumulativeContext && this.contextStore) {
2304
- if (storageKey && output) {
2305
- try {
2306
- const pendingAliases = this.contextStore._pendingAliases;
2307
- if (pendingAliases) {
2308
- this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2309
- delete this.contextStore._pendingAliases;
2310
- debug4("Stored query result with aliases:", {
2311
- key: storageKey,
2312
- value: output,
2313
- aliases: pendingAliases
2314
- });
2315
- } else {
2316
- this.contextStore.storeData(storageKey, output);
2317
- debug4("Stored query result:", {
2318
- key: storageKey,
2319
- value: output
2320
- });
2321
- }
2322
- this.contextStore.addStep({
2323
- type: "query",
2324
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2325
- data: output,
2326
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2327
- });
2328
- debug4("Added query step to context store:", {
2329
- storageKey,
2330
- totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
2331
- totalSteps: this.contextStore.getRecentSteps(100).length
2332
- });
2333
- } catch (error) {
2334
- debug4("Failed to store query result:", error);
2335
- }
2336
- } else {
2337
- try {
2338
- this.contextStore.addStep({
2339
- type: "query",
2340
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2341
- data: output,
2342
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2343
- });
2344
- } catch (error) {
2345
- debug4("Failed to add query step:", error);
2346
- }
2347
- }
2348
- }
2191
+ const { output, executor } = await this.taskExecutor.query(demand);
2349
2192
  const metadata = this.afterTaskRunning(executor);
2350
2193
  return {
2351
2194
  result: output,
@@ -2455,31 +2298,6 @@ var PageAgent = class {
2455
2298
  };
2456
2299
  }
2457
2300
  async aiAssert(assertion, msg, opt) {
2458
- let processedAssertion = assertion;
2459
- if (this.opts.enableCumulativeContext && this.contextStore) {
2460
- try {
2461
- const originalAssertion = assertion;
2462
- processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
2463
- if (originalAssertion !== processedAssertion) {
2464
- debug4("Context replacement in aiAssert:", {
2465
- original: originalAssertion,
2466
- processed: processedAssertion,
2467
- context: "assertion",
2468
- storedData: this.contextStore.getAllData()
2469
- });
2470
- }
2471
- this.contextStore.addStep({
2472
- type: "assertion",
2473
- summary: `Assertion: ${processedAssertion}`,
2474
- prompt: processedAssertion
2475
- });
2476
- debug4("Added assertion step to context store:", {
2477
- totalSteps: this.contextStore.getRecentSteps(100).length
2478
- });
2479
- } catch (error) {
2480
- debug4("Context store operation failed:", error);
2481
- }
2482
- }
2483
2301
  let currentUrl = "";
2484
2302
  if (this.page.url) {
2485
2303
  try {
@@ -2487,7 +2305,7 @@ var PageAgent = class {
2487
2305
  } catch (e) {
2488
2306
  }
2489
2307
  }
2490
- const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${processedAssertion}` : processedAssertion;
2308
+ const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
2491
2309
  const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
2492
2310
  const metadata = this.afterTaskRunning(executor, true);
2493
2311
  if (output && opt?.keepRawResponse) {
@@ -2730,7 +2548,7 @@ var Page = class {
2730
2548
  this.everMoved = false;
2731
2549
  this.underlyingPage = underlyingPage;
2732
2550
  this.pageType = pageType;
2733
- this.waitForNavigationTimeout = opts?.waitForNavigationTimeout || DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT2;
2551
+ this.waitForNavigationTimeout = opts?.waitForNavigationTimeout ?? DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT2;
2734
2552
  }
2735
2553
  async evaluate(pageFunction, arg) {
2736
2554
  let result;
@@ -3010,9 +2828,9 @@ var WebPage = class extends Page {
3010
2828
  }
3011
2829
  async waitUntilNetworkIdle(options) {
3012
2830
  await this.underlyingPage.waitForNetworkIdle({
3013
- idleTime: options?.idleTime || DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME,
3014
- concurrency: options?.concurrency || DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
3015
- timeout: options?.timeout || this.waitForNetworkIdleTimeout
2831
+ idleTime: options?.idleTime ?? DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME,
2832
+ concurrency: options?.concurrency ?? DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
2833
+ timeout: options?.timeout ?? this.waitForNetworkIdleTimeout
3016
2834
  });
3017
2835
  }
3018
2836
  };