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
package/dist/es/index.js CHANGED
@@ -17,10 +17,11 @@ var ScriptPlayer = class {
17
17
  this.unnamedResultIndex = 0;
18
18
  this.pageAgent = null;
19
19
  this.result = {};
20
+ const target = script.target || script.web || script.android;
20
21
  if (ifInBrowser) {
21
22
  this.output = void 0;
22
- } else if (script.target?.output) {
23
- this.output = resolve(process.cwd(), script.target.output);
23
+ } else if (target?.output) {
24
+ this.output = resolve(process.cwd(), target.output);
24
25
  } else {
25
26
  this.output = join(getMidsceneRunSubDir("output"), `${process.pid}.json`);
26
27
  }
@@ -94,12 +95,13 @@ var ScriptPlayer = class {
94
95
  } else if ("aiAssert" in flowItem) {
95
96
  const assertTask = flowItem;
96
97
  const prompt = assertTask.aiAssert;
98
+ const msg = assertTask.errorMessage;
97
99
  assert(prompt, "missing prompt for aiAssert");
98
100
  assert(
99
101
  typeof prompt === "string",
100
102
  "prompt for aiAssert must be a string"
101
103
  );
102
- await agent.aiAssert(prompt);
104
+ await agent.aiAssert(prompt, msg);
103
105
  } else if ("aiQuery" in flowItem) {
104
106
  const queryTask = flowItem;
105
107
  const prompt = queryTask.aiQuery;
@@ -1688,7 +1690,7 @@ import yaml3 from "js-yaml";
1688
1690
  import semver from "semver";
1689
1691
 
1690
1692
  // package.json
1691
- var version = "1.0.5";
1693
+ var version = "1.5.6";
1692
1694
 
1693
1695
  // src/common/task-cache.ts
1694
1696
  var debug3 = getDebug3("cache");
@@ -1870,13 +1872,10 @@ var PageAgent = class {
1870
1872
  generateReport: true,
1871
1873
  autoPrintReportMsg: true,
1872
1874
  groupName: "Midscene Report",
1873
- groupDescription: "",
1874
- enableCumulativeContext: true,
1875
- autoClearContext: false
1875
+ groupDescription: ""
1876
1876
  },
1877
1877
  opts || {}
1878
1878
  );
1879
- this.initializeContextStore();
1880
1879
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1881
1880
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1882
1881
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1903,69 +1902,6 @@ var PageAgent = class {
1903
1902
  opts?.testId || this.page.pageType || "web"
1904
1903
  );
1905
1904
  }
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
- }
1969
1905
  async getUIContext(action) {
1970
1906
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
1971
1907
  return await parseContextFromWebPage(this.page, {
@@ -2201,31 +2137,6 @@ var PageAgent = class {
2201
2137
  };
2202
2138
  }
2203
2139
  async aiAction(taskPrompt, opt) {
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
- }
2228
- }
2229
2140
  const cacheable = opt?.cacheable;
2230
2141
  const isVlmUiTars = vlLocateMode() === "vlm-ui-tars";
2231
2142
  const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
@@ -2272,75 +2183,7 @@ var PageAgent = class {
2272
2183
  };
2273
2184
  }
2274
2185
  async aiQuery(demand) {
2275
- let processedDemand = demand;
2276
- let storageKey;
2277
- try {
2278
- const aiModel = await import("misoai-core/ai-model");
2279
- const contextStore = aiModel.getContextStore();
2280
- if (typeof demand === "string") {
2281
- const storageInstruction = contextStore.parseStorageInstruction(demand);
2282
- if (storageInstruction) {
2283
- storageKey = storageInstruction.key;
2284
- processedDemand = storageInstruction.cleanText;
2285
- contextStore._pendingAliases = storageInstruction.aliases;
2286
- } else {
2287
- const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
2288
- if (storageMatch) {
2289
- storageKey = storageMatch[1];
2290
- processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
2291
- }
2292
- }
2293
- }
2294
- } catch (error) {
2295
- debug4("Context store not available:", error);
2296
- }
2297
- const { output, executor } = await this.taskExecutor.query(processedDemand);
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);
2341
- }
2342
- }
2343
- }
2186
+ const { output, executor } = await this.taskExecutor.query(demand);
2344
2187
  const metadata = this.afterTaskRunning(executor);
2345
2188
  return {
2346
2189
  result: output,
@@ -2450,31 +2293,6 @@ var PageAgent = class {
2450
2293
  };
2451
2294
  }
2452
2295
  async aiAssert(assertion, msg, opt) {
2453
- let processedAssertion = assertion;
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
- }
2477
- }
2478
2296
  let currentUrl = "";
2479
2297
  if (this.page.url) {
2480
2298
  try {
@@ -2482,7 +2300,7 @@ var PageAgent = class {
2482
2300
  } catch (e) {
2483
2301
  }
2484
2302
  }
2485
- const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${processedAssertion}` : processedAssertion;
2303
+ const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
2486
2304
  const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
2487
2305
  const metadata = this.afterTaskRunning(executor, true);
2488
2306
  if (output && opt?.keepRawResponse) {
@@ -2714,7 +2532,7 @@ var Page = class {
2714
2532
  this.everMoved = false;
2715
2533
  this.underlyingPage = underlyingPage;
2716
2534
  this.pageType = pageType;
2717
- this.waitForNavigationTimeout = opts?.waitForNavigationTimeout || DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT2;
2535
+ this.waitForNavigationTimeout = opts?.waitForNavigationTimeout ?? DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT2;
2718
2536
  }
2719
2537
  async evaluate(pageFunction, arg) {
2720
2538
  let result;
@@ -3250,9 +3068,9 @@ var WebPage2 = class extends Page {
3250
3068
  }
3251
3069
  async waitUntilNetworkIdle(options) {
3252
3070
  await this.underlyingPage.waitForNetworkIdle({
3253
- idleTime: options?.idleTime || DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME,
3254
- concurrency: options?.concurrency || DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
3255
- timeout: options?.timeout || this.waitForNetworkIdleTimeout
3071
+ idleTime: options?.idleTime ?? DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME,
3072
+ concurrency: options?.concurrency ?? DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
3073
+ timeout: options?.timeout ?? this.waitForNetworkIdleTimeout
3256
3074
  });
3257
3075
  }
3258
3076
  };