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
@@ -156,10 +156,11 @@ var ScriptPlayer = class {
156
156
  this.unnamedResultIndex = 0;
157
157
  this.pageAgent = null;
158
158
  this.result = {};
159
+ const target = script.target || script.web || script.android;
159
160
  if (import_utils3.ifInBrowser) {
160
161
  this.output = void 0;
161
- } else if (script.target?.output) {
162
- this.output = (0, import_node_path.resolve)(process.cwd(), script.target.output);
162
+ } else if (target?.output) {
163
+ this.output = (0, import_node_path.resolve)(process.cwd(), target.output);
163
164
  } else {
164
165
  this.output = (0, import_node_path.join)((0, import_common.getMidsceneRunSubDir)("output"), `${process.pid}.json`);
165
166
  }
@@ -233,12 +234,13 @@ var ScriptPlayer = class {
233
234
  } else if ("aiAssert" in flowItem) {
234
235
  const assertTask = flowItem;
235
236
  const prompt = assertTask.aiAssert;
237
+ const msg = assertTask.errorMessage;
236
238
  (0, import_utils3.assert)(prompt, "missing prompt for aiAssert");
237
239
  (0, import_utils3.assert)(
238
240
  typeof prompt === "string",
239
241
  "prompt for aiAssert must be a string"
240
242
  );
241
- await agent.aiAssert(prompt);
243
+ await agent.aiAssert(prompt, msg);
242
244
  } else if ("aiQuery" in flowItem) {
243
245
  const queryTask = flowItem;
244
246
  const prompt = queryTask.aiQuery;
@@ -1665,7 +1667,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1665
1667
  var import_semver = __toESM(require("semver"));
1666
1668
 
1667
1669
  // package.json
1668
- var version = "1.0.5";
1670
+ var version = "1.5.6";
1669
1671
 
1670
1672
  // src/common/task-cache.ts
1671
1673
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -1847,13 +1849,10 @@ var PageAgent = class {
1847
1849
  generateReport: true,
1848
1850
  autoPrintReportMsg: true,
1849
1851
  groupName: "Midscene Report",
1850
- groupDescription: "",
1851
- enableCumulativeContext: true,
1852
- autoClearContext: false
1852
+ groupDescription: ""
1853
1853
  },
1854
1854
  opts || {}
1855
1855
  );
1856
- this.initializeContextStore();
1857
1856
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1858
1857
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || import_constants2.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1859
1858
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || import_constants2.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1880,69 +1879,6 @@ var PageAgent = class {
1880
1879
  opts?.testId || this.page.pageType || "web"
1881
1880
  );
1882
1881
  }
1883
- /**
1884
- * Initialize context store for cumulative context functionality
1885
- */
1886
- async initializeContextStore() {
1887
- if (!this.opts.enableCumulativeContext) {
1888
- debug4("Cumulative context disabled via options");
1889
- return;
1890
- }
1891
- try {
1892
- const aiModel = await import("misoai-core/ai-model");
1893
- this.contextStore = aiModel.getContextStore();
1894
- debug4("Context store initialized successfully", {
1895
- autoClearContext: this.opts.autoClearContext,
1896
- testId: this.opts.testId
1897
- });
1898
- if (this.opts.autoClearContext) {
1899
- this.contextStore.clear();
1900
- debug4("Context store cleared due to autoClearContext option");
1901
- } else {
1902
- const existingData = this.contextStore.getAllData();
1903
- const existingSteps = this.contextStore.getRecentSteps(100).length;
1904
- debug4("Context store preserving existing data", {
1905
- existingDataKeys: Object.keys(existingData),
1906
- existingStepsCount: existingSteps
1907
- });
1908
- }
1909
- } catch (error) {
1910
- debug4("Failed to initialize context store:", error);
1911
- console.warn("⚠️ Could not initialize context store:", error);
1912
- }
1913
- }
1914
- /**
1915
- * Get the context store instance
1916
- */
1917
- getContextStore() {
1918
- return this.contextStore;
1919
- }
1920
- /**
1921
- * Clear the context store
1922
- */
1923
- clearContext() {
1924
- if (this.contextStore) {
1925
- this.contextStore.clear();
1926
- }
1927
- }
1928
- /**
1929
- * Get all stored data from context store
1930
- */
1931
- getStoredData() {
1932
- if (this.contextStore) {
1933
- return this.contextStore.getAllData();
1934
- }
1935
- return {};
1936
- }
1937
- /**
1938
- * Get step summary from context store
1939
- */
1940
- getStepSummary() {
1941
- if (this.contextStore) {
1942
- return this.contextStore.getStepSummary();
1943
- }
1944
- return "";
1945
- }
1946
1882
  async getUIContext(action) {
1947
1883
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
1948
1884
  return await parseContextFromWebPage(this.page, {
@@ -2178,31 +2114,6 @@ var PageAgent = class {
2178
2114
  };
2179
2115
  }
2180
2116
  async aiAction(taskPrompt, opt) {
2181
- if (this.opts.enableCumulativeContext && this.contextStore) {
2182
- try {
2183
- const originalPrompt = taskPrompt;
2184
- const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
2185
- if (originalPrompt !== processedPrompt) {
2186
- debug4("Context replacement in aiAction:", {
2187
- original: originalPrompt,
2188
- processed: processedPrompt,
2189
- storedData: this.contextStore.getAllData()
2190
- });
2191
- }
2192
- this.contextStore.addStep({
2193
- type: "action",
2194
- summary: `Action: ${processedPrompt}`,
2195
- prompt: processedPrompt
2196
- });
2197
- debug4("Added action step to context store:", {
2198
- stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2199
- totalSteps: this.contextStore.getRecentSteps(100).length
2200
- });
2201
- taskPrompt = processedPrompt;
2202
- } catch (error) {
2203
- debug4("Context store operation failed:", error);
2204
- }
2205
- }
2206
2117
  const cacheable = opt?.cacheable;
2207
2118
  const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
2208
2119
  const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
@@ -2249,75 +2160,7 @@ var PageAgent = class {
2249
2160
  };
2250
2161
  }
2251
2162
  async aiQuery(demand) {
2252
- let processedDemand = demand;
2253
- let storageKey;
2254
- try {
2255
- const aiModel = await import("misoai-core/ai-model");
2256
- const contextStore = aiModel.getContextStore();
2257
- if (typeof demand === "string") {
2258
- const storageInstruction = contextStore.parseStorageInstruction(demand);
2259
- if (storageInstruction) {
2260
- storageKey = storageInstruction.key;
2261
- processedDemand = storageInstruction.cleanText;
2262
- contextStore._pendingAliases = storageInstruction.aliases;
2263
- } else {
2264
- const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
2265
- if (storageMatch) {
2266
- storageKey = storageMatch[1];
2267
- processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
2268
- }
2269
- }
2270
- }
2271
- } catch (error) {
2272
- debug4("Context store not available:", error);
2273
- }
2274
- const { output, executor } = await this.taskExecutor.query(processedDemand);
2275
- if (this.opts.enableCumulativeContext && this.contextStore) {
2276
- if (storageKey && output) {
2277
- try {
2278
- const pendingAliases = this.contextStore._pendingAliases;
2279
- if (pendingAliases) {
2280
- this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2281
- delete this.contextStore._pendingAliases;
2282
- debug4("Stored query result with aliases:", {
2283
- key: storageKey,
2284
- value: output,
2285
- aliases: pendingAliases
2286
- });
2287
- } else {
2288
- this.contextStore.storeData(storageKey, output);
2289
- debug4("Stored query result:", {
2290
- key: storageKey,
2291
- value: output
2292
- });
2293
- }
2294
- this.contextStore.addStep({
2295
- type: "query",
2296
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2297
- data: output,
2298
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2299
- });
2300
- debug4("Added query step to context store:", {
2301
- storageKey,
2302
- totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
2303
- totalSteps: this.contextStore.getRecentSteps(100).length
2304
- });
2305
- } catch (error) {
2306
- debug4("Failed to store query result:", error);
2307
- }
2308
- } else {
2309
- try {
2310
- this.contextStore.addStep({
2311
- type: "query",
2312
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2313
- data: output,
2314
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2315
- });
2316
- } catch (error) {
2317
- debug4("Failed to add query step:", error);
2318
- }
2319
- }
2320
- }
2163
+ const { output, executor } = await this.taskExecutor.query(demand);
2321
2164
  const metadata = this.afterTaskRunning(executor);
2322
2165
  return {
2323
2166
  result: output,
@@ -2427,31 +2270,6 @@ var PageAgent = class {
2427
2270
  };
2428
2271
  }
2429
2272
  async aiAssert(assertion, msg, opt) {
2430
- let processedAssertion = assertion;
2431
- if (this.opts.enableCumulativeContext && this.contextStore) {
2432
- try {
2433
- const originalAssertion = assertion;
2434
- processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
2435
- if (originalAssertion !== processedAssertion) {
2436
- debug4("Context replacement in aiAssert:", {
2437
- original: originalAssertion,
2438
- processed: processedAssertion,
2439
- context: "assertion",
2440
- storedData: this.contextStore.getAllData()
2441
- });
2442
- }
2443
- this.contextStore.addStep({
2444
- type: "assertion",
2445
- summary: `Assertion: ${processedAssertion}`,
2446
- prompt: processedAssertion
2447
- });
2448
- debug4("Added assertion step to context store:", {
2449
- totalSteps: this.contextStore.getRecentSteps(100).length
2450
- });
2451
- } catch (error) {
2452
- debug4("Context store operation failed:", error);
2453
- }
2454
- }
2455
2273
  let currentUrl = "";
2456
2274
  if (this.page.url) {
2457
2275
  try {
@@ -2459,7 +2277,7 @@ var PageAgent = class {
2459
2277
  } catch (e) {
2460
2278
  }
2461
2279
  }
2462
- const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${processedAssertion}` : processedAssertion;
2280
+ const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
2463
2281
  const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
2464
2282
  const metadata = this.afterTaskRunning(executor, true);
2465
2283
  if (output && opt?.keepRawResponse) {