misoai-web 1.0.6 → 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 (47) hide show
  1. package/README.md +5 -349
  2. package/dist/es/agent.js +43 -409
  3. package/dist/es/agent.js.map +1 -1
  4. package/dist/es/bridge-mode-browser.js +3 -3
  5. package/dist/es/bridge-mode.js +45 -411
  6. package/dist/es/bridge-mode.js.map +1 -1
  7. package/dist/es/chrome-extension.js +44 -410
  8. package/dist/es/chrome-extension.js.map +1 -1
  9. package/dist/es/index.js +47 -413
  10. package/dist/es/index.js.map +1 -1
  11. package/dist/es/midscene-playground.js +43 -409
  12. package/dist/es/midscene-playground.js.map +1 -1
  13. package/dist/es/playground.js +43 -409
  14. package/dist/es/playground.js.map +1 -1
  15. package/dist/es/playwright.js +44 -410
  16. package/dist/es/playwright.js.map +1 -1
  17. package/dist/es/puppeteer-agent-launcher.js +47 -413
  18. package/dist/es/puppeteer-agent-launcher.js.map +1 -1
  19. package/dist/es/puppeteer.js +47 -413
  20. package/dist/es/puppeteer.js.map +1 -1
  21. package/dist/es/yaml.js +5 -3
  22. package/dist/es/yaml.js.map +1 -1
  23. package/dist/lib/agent.js +43 -409
  24. package/dist/lib/agent.js.map +1 -1
  25. package/dist/lib/bridge-mode-browser.js +3 -3
  26. package/dist/lib/bridge-mode.js +45 -411
  27. package/dist/lib/bridge-mode.js.map +1 -1
  28. package/dist/lib/chrome-extension.js +44 -410
  29. package/dist/lib/chrome-extension.js.map +1 -1
  30. package/dist/lib/index.js +47 -413
  31. package/dist/lib/index.js.map +1 -1
  32. package/dist/lib/midscene-playground.js +43 -409
  33. package/dist/lib/midscene-playground.js.map +1 -1
  34. package/dist/lib/playground.js +43 -409
  35. package/dist/lib/playground.js.map +1 -1
  36. package/dist/lib/playwright.js +44 -410
  37. package/dist/lib/playwright.js.map +1 -1
  38. package/dist/lib/puppeteer-agent-launcher.js +47 -413
  39. package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
  40. package/dist/lib/puppeteer.js +47 -413
  41. package/dist/lib/puppeteer.js.map +1 -1
  42. package/dist/lib/yaml.js +5 -3
  43. package/dist/lib/yaml.js.map +1 -1
  44. package/dist/types/agent.d.ts +3 -44
  45. package/iife-script/htmlElement.js +2 -2
  46. package/iife-script/htmlElementDebug.js +2 -2
  47. package/package.json +4 -4
@@ -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");
@@ -1741,70 +1743,44 @@ var TaskCache = class {
1741
1743
  this.cache = cacheContent;
1742
1744
  this.cacheOriginalLength = this.cache.caches.length;
1743
1745
  }
1744
- matchCache(prompt, type, contextData) {
1745
- const contextHash = contextData ? this.generateContextHash(contextData) : void 0;
1746
+ matchCache(prompt, type) {
1746
1747
  for (let i = 0; i < this.cacheOriginalLength; i++) {
1747
1748
  const item = this.cache.caches[i];
1748
1749
  const key = `${type}:${prompt}:${i}`;
1749
- if (item.type !== type || item.prompt !== prompt || this.matchedCacheIndices.has(key)) {
1750
- continue;
1751
- }
1752
- if (type === "plan" && item.type === "plan") {
1753
- const planItem = item;
1754
- if (contextHash && planItem.contextHash) {
1755
- if (contextHash !== planItem.contextHash) {
1756
- debug3("cache context mismatch, type: %s, prompt: %s, index: %d", type, prompt, i);
1757
- continue;
1750
+ if (item.type === type && item.prompt === prompt && !this.matchedCacheIndices.has(key)) {
1751
+ this.matchedCacheIndices.add(key);
1752
+ debug3(
1753
+ "cache found and marked as used, type: %s, prompt: %s, index: %d",
1754
+ type,
1755
+ prompt,
1756
+ i
1757
+ );
1758
+ return {
1759
+ cacheContent: item,
1760
+ updateFn: (cb) => {
1761
+ debug3(
1762
+ "will call updateFn to update cache, type: %s, prompt: %s, index: %d",
1763
+ type,
1764
+ prompt,
1765
+ i
1766
+ );
1767
+ cb(item);
1768
+ debug3(
1769
+ "cache updated, will flush to file, type: %s, prompt: %s, index: %d",
1770
+ type,
1771
+ prompt,
1772
+ i
1773
+ );
1774
+ this.flushCacheToFile();
1758
1775
  }
1759
- } else if (contextHash || planItem.contextHash) {
1760
- debug3("cache context availability mismatch, type: %s, prompt: %s, index: %d", type, prompt, i);
1761
- continue;
1762
- }
1776
+ };
1763
1777
  }
1764
- this.matchedCacheIndices.add(key);
1765
- debug3(
1766
- "cache found and marked as used, type: %s, prompt: %s, index: %d, contextMatch: %s",
1767
- type,
1768
- prompt,
1769
- i,
1770
- contextHash ? "yes" : "no-context"
1771
- );
1772
- return {
1773
- cacheContent: item,
1774
- updateFn: (cb) => {
1775
- debug3(
1776
- "will call updateFn to update cache, type: %s, prompt: %s, index: %d",
1777
- type,
1778
- prompt,
1779
- i
1780
- );
1781
- cb(item);
1782
- debug3(
1783
- "cache updated, will flush to file, type: %s, prompt: %s, index: %d",
1784
- type,
1785
- prompt,
1786
- i
1787
- );
1788
- this.flushCacheToFile();
1789
- }
1790
- };
1791
1778
  }
1792
- debug3("no unused cache found, type: %s, prompt: %s, contextHash: %s", type, prompt, contextHash);
1779
+ debug3("no unused cache found, type: %s, prompt: %s", type, prompt);
1793
1780
  return void 0;
1794
1781
  }
1795
- generateContextHash(contextData) {
1796
- const sortedKeys = Object.keys(contextData).sort();
1797
- const stableString = sortedKeys.map((key) => `${key}:${JSON.stringify(contextData[key])}`).join("|");
1798
- let hash = 0;
1799
- for (let i = 0; i < stableString.length; i++) {
1800
- const char = stableString.charCodeAt(i);
1801
- hash = (hash << 5) - hash + char;
1802
- hash = hash & hash;
1803
- }
1804
- return hash.toString(36);
1805
- }
1806
- matchPlanCache(prompt, contextData) {
1807
- return this.matchCache(prompt, "plan", contextData);
1782
+ matchPlanCache(prompt) {
1783
+ return this.matchCache(prompt, "plan");
1808
1784
  }
1809
1785
  matchLocateCache(prompt) {
1810
1786
  return this.matchCache(prompt, "locate");
@@ -1880,16 +1856,11 @@ cache file: ${cacheFile}`
1880
1856
  );
1881
1857
  }
1882
1858
  }
1883
- updateOrAppendCacheRecord(newRecord, cachedRecord, contextData) {
1859
+ updateOrAppendCacheRecord(newRecord, cachedRecord) {
1884
1860
  if (cachedRecord) {
1885
1861
  if (newRecord.type === "plan") {
1886
1862
  cachedRecord.updateFn((cache) => {
1887
- const planCache = cache;
1888
- planCache.yamlWorkflow = newRecord.yamlWorkflow;
1889
- if (contextData) {
1890
- planCache.contextHash = this.generateContextHash(contextData);
1891
- planCache.contextData = { ...contextData };
1892
- }
1863
+ cache.yamlWorkflow = newRecord.yamlWorkflow;
1893
1864
  });
1894
1865
  } else {
1895
1866
  cachedRecord.updateFn((cache) => {
@@ -1897,11 +1868,6 @@ cache file: ${cacheFile}`
1897
1868
  });
1898
1869
  }
1899
1870
  } else {
1900
- if (newRecord.type === "plan" && contextData) {
1901
- const planRecord = newRecord;
1902
- planRecord.contextHash = this.generateContextHash(contextData);
1903
- planRecord.contextData = { ...contextData };
1904
- }
1905
1871
  this.appendCache(newRecord);
1906
1872
  }
1907
1873
  }
@@ -1931,13 +1897,10 @@ var PageAgent = class {
1931
1897
  generateReport: true,
1932
1898
  autoPrintReportMsg: true,
1933
1899
  groupName: "Midscene Report",
1934
- groupDescription: "",
1935
- enableCumulativeContext: true,
1936
- autoClearContext: false
1900
+ groupDescription: ""
1937
1901
  },
1938
1902
  opts || {}
1939
1903
  );
1940
- this.initializeContextStore();
1941
1904
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1942
1905
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || import_constants2.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1943
1906
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || import_constants2.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1964,69 +1927,6 @@ var PageAgent = class {
1964
1927
  opts?.testId || this.page.pageType || "web"
1965
1928
  );
1966
1929
  }
1967
- /**
1968
- * Initialize context store for cumulative context functionality
1969
- */
1970
- async initializeContextStore() {
1971
- if (!this.opts.enableCumulativeContext) {
1972
- debug4("Cumulative context disabled via options");
1973
- return;
1974
- }
1975
- try {
1976
- const aiModel = await import("misoai-core/ai-model");
1977
- this.contextStore = aiModel.getContextStore();
1978
- debug4("Context store initialized successfully", {
1979
- autoClearContext: this.opts.autoClearContext,
1980
- testId: this.opts.testId
1981
- });
1982
- if (this.opts.autoClearContext) {
1983
- this.contextStore.clear();
1984
- debug4("Context store cleared due to autoClearContext option");
1985
- } else {
1986
- const existingData = this.contextStore.getAllData();
1987
- const existingSteps = this.contextStore.getRecentSteps(100).length;
1988
- debug4("Context store preserving existing data", {
1989
- existingDataKeys: Object.keys(existingData),
1990
- existingStepsCount: existingSteps
1991
- });
1992
- }
1993
- } catch (error) {
1994
- debug4("Failed to initialize context store:", error);
1995
- console.warn("⚠️ Could not initialize context store:", error);
1996
- }
1997
- }
1998
- /**
1999
- * Get the context store instance
2000
- */
2001
- getContextStore() {
2002
- return this.contextStore;
2003
- }
2004
- /**
2005
- * Clear the context store
2006
- */
2007
- clearContext() {
2008
- if (this.contextStore) {
2009
- this.contextStore.clear();
2010
- }
2011
- }
2012
- /**
2013
- * Get all stored data from context store
2014
- */
2015
- getStoredData() {
2016
- if (this.contextStore) {
2017
- return this.contextStore.getAllData();
2018
- }
2019
- return {};
2020
- }
2021
- /**
2022
- * Get step summary from context store
2023
- */
2024
- getStepSummary() {
2025
- if (this.contextStore) {
2026
- return this.contextStore.getStepSummary();
2027
- }
2028
- return "";
2029
- }
2030
1930
  async getUIContext(action) {
2031
1931
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
2032
1932
  return await parseContextFromWebPage(this.page, {
@@ -2262,35 +2162,9 @@ var PageAgent = class {
2262
2162
  };
2263
2163
  }
2264
2164
  async aiAction(taskPrompt, opt) {
2265
- const originalPrompt = taskPrompt;
2266
- let processedPrompt = taskPrompt;
2267
- if (this.opts.enableCumulativeContext && this.contextStore) {
2268
- try {
2269
- const storedData = this.contextStore.getAllData();
2270
- if (Object.keys(storedData).length > 0) {
2271
- debug4("Available data for aiAction:", {
2272
- prompt: taskPrompt,
2273
- availableData: storedData
2274
- });
2275
- }
2276
- } catch (error) {
2277
- debug4("Context store operation failed:", error);
2278
- }
2279
- }
2280
2165
  const cacheable = opt?.cacheable;
2281
2166
  const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
2282
- let contextData;
2283
- if (this.opts.enableCumulativeContext && this.contextStore) {
2284
- try {
2285
- contextData = this.contextStore.getAllData();
2286
- if (contextData && Object.keys(contextData).length === 0) {
2287
- contextData = void 0;
2288
- }
2289
- } catch (error) {
2290
- debug4("Failed to get context data for cache:", error);
2291
- }
2292
- }
2293
- const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt, contextData);
2167
+ const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
2294
2168
  if (matchedCache && this.taskCache?.isCacheResultUsed) {
2295
2169
  const { executor: executor2 } = await this.taskExecutor.loadYamlFlowAsPlanning(
2296
2170
  taskPrompt,
@@ -2300,28 +2174,6 @@ var PageAgent = class {
2300
2174
  debug4("matched cache, will call .runYaml to run the action");
2301
2175
  const yaml5 = matchedCache.cacheContent?.yamlWorkflow;
2302
2176
  const result = await this.runYaml(yaml5);
2303
- if (this.opts.enableCumulativeContext && this.contextStore) {
2304
- try {
2305
- const executionResult = {
2306
- success: true,
2307
- actionType: "cached",
2308
- description: `Executed cached action: ${processedPrompt}`,
2309
- timing: result.metadata?.totalTime
2310
- };
2311
- this.contextStore.addStep({
2312
- type: "action",
2313
- summary: `Action: ${processedPrompt} (cached)`,
2314
- prompt: processedPrompt,
2315
- executionResult
2316
- });
2317
- debug4("Added cached action step to context store:", {
2318
- stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2319
- totalSteps: this.contextStore.getRecentSteps(100).length
2320
- });
2321
- } catch (error) {
2322
- debug4("Failed to add cached action step:", error);
2323
- }
2324
- }
2325
2177
  return {
2326
2178
  result: result.result,
2327
2179
  metadata: metadata2
@@ -2346,114 +2198,17 @@ var PageAgent = class {
2346
2198
  prompt: taskPrompt,
2347
2199
  yamlWorkflow: yamlFlowStr
2348
2200
  },
2349
- matchedCache,
2350
- contextData
2351
- // Pass context data for cache creation
2201
+ matchedCache
2352
2202
  );
2353
2203
  }
2354
2204
  const metadata = this.afterTaskRunning(executor);
2355
- if (this.opts.enableCumulativeContext && this.contextStore) {
2356
- try {
2357
- const executionResult = this.analyzeExecutionResults(executor, originalPrompt);
2358
- this.contextStore.addStep({
2359
- type: "action",
2360
- summary: `Action: ${processedPrompt}`,
2361
- prompt: processedPrompt,
2362
- executionResult
2363
- });
2364
- debug4("Added action step with execution result to context store:", {
2365
- stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2366
- totalSteps: this.contextStore.getRecentSteps(100).length,
2367
- executionResult
2368
- });
2369
- } catch (error) {
2370
- debug4("Failed to analyze execution results, adding step without execution result:", error);
2371
- try {
2372
- this.contextStore.addStep({
2373
- type: "action",
2374
- summary: `Action: ${processedPrompt}`,
2375
- prompt: processedPrompt
2376
- });
2377
- } catch (stepError) {
2378
- debug4("Failed to add action step:", stepError);
2379
- }
2380
- }
2381
- }
2382
2205
  return {
2383
2206
  result: output,
2384
2207
  metadata
2385
2208
  };
2386
2209
  }
2387
2210
  async aiQuery(demand) {
2388
- let processedDemand = demand;
2389
- let storageKey;
2390
- try {
2391
- const aiModel = await import("misoai-core/ai-model");
2392
- const contextStore = aiModel.getContextStore();
2393
- if (typeof demand === "string") {
2394
- const storageInstruction = contextStore.parseStorageInstruction(demand);
2395
- if (storageInstruction) {
2396
- storageKey = storageInstruction.key;
2397
- processedDemand = storageInstruction.cleanText;
2398
- contextStore._pendingAliases = storageInstruction.aliases;
2399
- } else {
2400
- const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
2401
- if (storageMatch) {
2402
- storageKey = storageMatch[1];
2403
- processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
2404
- }
2405
- }
2406
- }
2407
- } catch (error) {
2408
- debug4("Context store not available:", error);
2409
- }
2410
- const { output, executor } = await this.taskExecutor.query(processedDemand);
2411
- if (this.opts.enableCumulativeContext && this.contextStore) {
2412
- if (storageKey && output) {
2413
- try {
2414
- const pendingAliases = this.contextStore._pendingAliases;
2415
- if (pendingAliases) {
2416
- this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2417
- delete this.contextStore._pendingAliases;
2418
- debug4("Stored query result with aliases:", {
2419
- key: storageKey,
2420
- value: output,
2421
- aliases: pendingAliases
2422
- });
2423
- } else {
2424
- this.contextStore.storeData(storageKey, output);
2425
- debug4("Stored query result:", {
2426
- key: storageKey,
2427
- value: output
2428
- });
2429
- }
2430
- this.contextStore.addStep({
2431
- type: "query",
2432
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2433
- data: output,
2434
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2435
- });
2436
- debug4("Added query step to context store:", {
2437
- storageKey,
2438
- totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
2439
- totalSteps: this.contextStore.getRecentSteps(100).length
2440
- });
2441
- } catch (error) {
2442
- debug4("Failed to store query result:", error);
2443
- }
2444
- } else {
2445
- try {
2446
- this.contextStore.addStep({
2447
- type: "query",
2448
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2449
- data: output,
2450
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2451
- });
2452
- } catch (error) {
2453
- debug4("Failed to add query step:", error);
2454
- }
2455
- }
2456
- }
2211
+ const { output, executor } = await this.taskExecutor.query(demand);
2457
2212
  const metadata = this.afterTaskRunning(executor);
2458
2213
  return {
2459
2214
  result: output,
@@ -2563,48 +2318,6 @@ var PageAgent = class {
2563
2318
  };
2564
2319
  }
2565
2320
  async aiAssert(assertion, msg, opt) {
2566
- let executionContext = "";
2567
- if (this.opts.enableCumulativeContext && this.contextStore) {
2568
- try {
2569
- const recentSteps = this.contextStore.getRecentSteps(3);
2570
- const stepsWithExecutionResults = recentSteps.filter((step) => step.executionResult);
2571
- const storedData = this.contextStore.getAllData();
2572
- if (stepsWithExecutionResults.length > 0) {
2573
- const recentActions = stepsWithExecutionResults.map((step) => {
2574
- const result = step.executionResult;
2575
- return `- ${result.description}${result.success ? "" : " (FAILED)"}`;
2576
- }).join("\n");
2577
- executionContext = `
2578
-
2579
- Recent actions performed:
2580
- ${recentActions}
2581
-
2582
- This context may help verify the assertion.`;
2583
- }
2584
- if (storedData && Object.keys(storedData).length > 0) {
2585
- executionContext += `
2586
-
2587
- Available data for reference:
2588
- ${JSON.stringify(storedData, null, 2)}
2589
-
2590
- Note: If the assertion references any data keys or natural language equivalents, consider the stored values when verifying.`;
2591
- debug4("Available data for aiAssert:", {
2592
- assertion,
2593
- availableData: storedData
2594
- });
2595
- }
2596
- this.contextStore.addStep({
2597
- type: "assertion",
2598
- summary: `Assertion: ${assertion}`,
2599
- prompt: assertion
2600
- });
2601
- debug4("Added assertion step to context store:", {
2602
- totalSteps: this.contextStore.getRecentSteps(100).length
2603
- });
2604
- } catch (error) {
2605
- debug4("Context store operation failed:", error);
2606
- }
2607
- }
2608
2321
  let currentUrl = "";
2609
2322
  if (this.page.url) {
2610
2323
  try {
@@ -2612,13 +2325,7 @@ Note: If the assertion references any data keys or natural language equivalents,
2612
2325
  } catch (e) {
2613
2326
  }
2614
2327
  }
2615
- let assertionWithContext = assertion;
2616
- if (currentUrl) {
2617
- assertionWithContext = `For the page at URL "${currentUrl}", ${assertion}`;
2618
- }
2619
- if (executionContext) {
2620
- assertionWithContext += executionContext;
2621
- }
2328
+ const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
2622
2329
  const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
2623
2330
  const metadata = this.afterTaskRunning(executor, true);
2624
2331
  if (output && opt?.keepRawResponse) {
@@ -2832,79 +2539,6 @@ ${errors}`);
2832
2539
  async destroy() {
2833
2540
  await this.page.destroy();
2834
2541
  }
2835
- /**
2836
- * Analyze execution results from executor to generate meaningful descriptions
2837
- */
2838
- analyzeExecutionResults(executor, originalPrompt) {
2839
- const tasks = executor.tasks;
2840
- const success = !executor.isInErrorState();
2841
- if (!success) {
2842
- const errorTask = executor.latestErrorTask();
2843
- return {
2844
- success: false,
2845
- actionType: "error",
2846
- description: `Failed to execute: ${originalPrompt}`,
2847
- error: errorTask?.error
2848
- };
2849
- }
2850
- const actionTasks = tasks.filter((t) => t.type === "Action" && t.status === "finished");
2851
- const locateTasks = tasks.filter((t) => t.type === "Insight" && t.subType === "Locate");
2852
- const lastAction = actionTasks[actionTasks.length - 1];
2853
- const lastLocate = locateTasks[locateTasks.length - 1];
2854
- if (!lastAction) {
2855
- return {
2856
- success: true,
2857
- actionType: "unknown",
2858
- description: `Completed: ${originalPrompt}`
2859
- };
2860
- }
2861
- const actionType = lastAction.subType || "unknown";
2862
- const elementInfo = this.extractElementInfo(lastLocate, lastAction);
2863
- const description = this.generateActionDescription(actionType, lastAction.param, elementInfo);
2864
- return {
2865
- success: true,
2866
- actionType,
2867
- description,
2868
- elementInfo,
2869
- timing: lastAction.timing?.cost
2870
- };
2871
- }
2872
- /**
2873
- * Extract element information from locate task
2874
- */
2875
- extractElementInfo(locateTask, _actionTask) {
2876
- if (!locateTask?.output?.element)
2877
- return void 0;
2878
- const element = locateTask.output.element;
2879
- return {
2880
- type: element.attributes?.nodeType || "unknown",
2881
- text: element.content || element.attributes?.placeholder || element.attributes?.title || "",
2882
- location: `(${element.center[0]}, ${element.center[1]})`
2883
- };
2884
- }
2885
- /**
2886
- * Generate natural language description for actions
2887
- */
2888
- generateActionDescription(actionType, param, elementInfo) {
2889
- const elementDesc = elementInfo ? `'${elementInfo.text || elementInfo.type}' element` : "element";
2890
- switch (actionType) {
2891
- case "Tap":
2892
- return `Clicked on ${elementDesc}`;
2893
- case "Input":
2894
- const inputValue = param?.value || "";
2895
- return `Entered "${inputValue}" into ${elementDesc}`;
2896
- case "KeyboardPress":
2897
- return `Pressed ${param?.value || "key"}`;
2898
- case "Scroll":
2899
- return `Scrolled ${param?.direction || "on page"}`;
2900
- case "Hover":
2901
- return `Hovered over ${elementDesc}`;
2902
- case "Drag":
2903
- return `Dragged ${elementDesc}`;
2904
- default:
2905
- return `Performed ${actionType} action on ${elementDesc}`;
2906
- }
2907
- }
2908
2542
  };
2909
2543
 
2910
2544
  // src/puppeteer/index.ts
@@ -2926,7 +2560,7 @@ var Page = class {
2926
2560
  this.everMoved = false;
2927
2561
  this.underlyingPage = underlyingPage;
2928
2562
  this.pageType = pageType;
2929
- this.waitForNavigationTimeout = opts?.waitForNavigationTimeout || import_constants3.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
2563
+ this.waitForNavigationTimeout = opts?.waitForNavigationTimeout ?? import_constants3.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
2930
2564
  }
2931
2565
  async evaluate(pageFunction, arg) {
2932
2566
  let result;
@@ -3206,9 +2840,9 @@ var WebPage = class extends Page {
3206
2840
  }
3207
2841
  async waitUntilNetworkIdle(options) {
3208
2842
  await this.underlyingPage.waitForNetworkIdle({
3209
- idleTime: options?.idleTime || import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME,
3210
- concurrency: options?.concurrency || import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
3211
- 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
3212
2846
  });
3213
2847
  }
3214
2848
  };