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
@@ -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");
@@ -1734,70 +1736,44 @@ var TaskCache = class {
1734
1736
  this.cache = cacheContent;
1735
1737
  this.cacheOriginalLength = this.cache.caches.length;
1736
1738
  }
1737
- matchCache(prompt, type, contextData) {
1738
- const contextHash = contextData ? this.generateContextHash(contextData) : void 0;
1739
+ matchCache(prompt, type) {
1739
1740
  for (let i = 0; i < this.cacheOriginalLength; i++) {
1740
1741
  const item = this.cache.caches[i];
1741
1742
  const key = `${type}:${prompt}:${i}`;
1742
- if (item.type !== type || item.prompt !== prompt || this.matchedCacheIndices.has(key)) {
1743
- continue;
1744
- }
1745
- if (type === "plan" && item.type === "plan") {
1746
- const planItem = item;
1747
- if (contextHash && planItem.contextHash) {
1748
- if (contextHash !== planItem.contextHash) {
1749
- debug3("cache context mismatch, type: %s, prompt: %s, index: %d", type, prompt, i);
1750
- continue;
1743
+ if (item.type === type && item.prompt === prompt && !this.matchedCacheIndices.has(key)) {
1744
+ this.matchedCacheIndices.add(key);
1745
+ debug3(
1746
+ "cache found and marked as used, type: %s, prompt: %s, index: %d",
1747
+ type,
1748
+ prompt,
1749
+ i
1750
+ );
1751
+ return {
1752
+ cacheContent: item,
1753
+ updateFn: (cb) => {
1754
+ debug3(
1755
+ "will call updateFn to update cache, type: %s, prompt: %s, index: %d",
1756
+ type,
1757
+ prompt,
1758
+ i
1759
+ );
1760
+ cb(item);
1761
+ debug3(
1762
+ "cache updated, will flush to file, type: %s, prompt: %s, index: %d",
1763
+ type,
1764
+ prompt,
1765
+ i
1766
+ );
1767
+ this.flushCacheToFile();
1751
1768
  }
1752
- } else if (contextHash || planItem.contextHash) {
1753
- debug3("cache context availability mismatch, type: %s, prompt: %s, index: %d", type, prompt, i);
1754
- continue;
1755
- }
1769
+ };
1756
1770
  }
1757
- this.matchedCacheIndices.add(key);
1758
- debug3(
1759
- "cache found and marked as used, type: %s, prompt: %s, index: %d, contextMatch: %s",
1760
- type,
1761
- prompt,
1762
- i,
1763
- contextHash ? "yes" : "no-context"
1764
- );
1765
- return {
1766
- cacheContent: item,
1767
- updateFn: (cb) => {
1768
- debug3(
1769
- "will call updateFn to update cache, type: %s, prompt: %s, index: %d",
1770
- type,
1771
- prompt,
1772
- i
1773
- );
1774
- cb(item);
1775
- debug3(
1776
- "cache updated, will flush to file, type: %s, prompt: %s, index: %d",
1777
- type,
1778
- prompt,
1779
- i
1780
- );
1781
- this.flushCacheToFile();
1782
- }
1783
- };
1784
1771
  }
1785
- debug3("no unused cache found, type: %s, prompt: %s, contextHash: %s", type, prompt, contextHash);
1772
+ debug3("no unused cache found, type: %s, prompt: %s", type, prompt);
1786
1773
  return void 0;
1787
1774
  }
1788
- generateContextHash(contextData) {
1789
- const sortedKeys = Object.keys(contextData).sort();
1790
- const stableString = sortedKeys.map((key) => `${key}:${JSON.stringify(contextData[key])}`).join("|");
1791
- let hash = 0;
1792
- for (let i = 0; i < stableString.length; i++) {
1793
- const char = stableString.charCodeAt(i);
1794
- hash = (hash << 5) - hash + char;
1795
- hash = hash & hash;
1796
- }
1797
- return hash.toString(36);
1798
- }
1799
- matchPlanCache(prompt, contextData) {
1800
- return this.matchCache(prompt, "plan", contextData);
1775
+ matchPlanCache(prompt) {
1776
+ return this.matchCache(prompt, "plan");
1801
1777
  }
1802
1778
  matchLocateCache(prompt) {
1803
1779
  return this.matchCache(prompt, "locate");
@@ -1873,16 +1849,11 @@ cache file: ${cacheFile}`
1873
1849
  );
1874
1850
  }
1875
1851
  }
1876
- updateOrAppendCacheRecord(newRecord, cachedRecord, contextData) {
1852
+ updateOrAppendCacheRecord(newRecord, cachedRecord) {
1877
1853
  if (cachedRecord) {
1878
1854
  if (newRecord.type === "plan") {
1879
1855
  cachedRecord.updateFn((cache) => {
1880
- const planCache = cache;
1881
- planCache.yamlWorkflow = newRecord.yamlWorkflow;
1882
- if (contextData) {
1883
- planCache.contextHash = this.generateContextHash(contextData);
1884
- planCache.contextData = { ...contextData };
1885
- }
1856
+ cache.yamlWorkflow = newRecord.yamlWorkflow;
1886
1857
  });
1887
1858
  } else {
1888
1859
  cachedRecord.updateFn((cache) => {
@@ -1890,11 +1861,6 @@ cache file: ${cacheFile}`
1890
1861
  });
1891
1862
  }
1892
1863
  } else {
1893
- if (newRecord.type === "plan" && contextData) {
1894
- const planRecord = newRecord;
1895
- planRecord.contextHash = this.generateContextHash(contextData);
1896
- planRecord.contextData = { ...contextData };
1897
- }
1898
1864
  this.appendCache(newRecord);
1899
1865
  }
1900
1866
  }
@@ -1924,13 +1890,10 @@ var PageAgent = class {
1924
1890
  generateReport: true,
1925
1891
  autoPrintReportMsg: true,
1926
1892
  groupName: "Midscene Report",
1927
- groupDescription: "",
1928
- enableCumulativeContext: true,
1929
- autoClearContext: false
1893
+ groupDescription: ""
1930
1894
  },
1931
1895
  opts || {}
1932
1896
  );
1933
- this.initializeContextStore();
1934
1897
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1935
1898
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || import_constants2.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1936
1899
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || import_constants2.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1957,69 +1920,6 @@ var PageAgent = class {
1957
1920
  opts?.testId || this.page.pageType || "web"
1958
1921
  );
1959
1922
  }
1960
- /**
1961
- * Initialize context store for cumulative context functionality
1962
- */
1963
- async initializeContextStore() {
1964
- if (!this.opts.enableCumulativeContext) {
1965
- debug4("Cumulative context disabled via options");
1966
- return;
1967
- }
1968
- try {
1969
- const aiModel = await import("misoai-core/ai-model");
1970
- this.contextStore = aiModel.getContextStore();
1971
- debug4("Context store initialized successfully", {
1972
- autoClearContext: this.opts.autoClearContext,
1973
- testId: this.opts.testId
1974
- });
1975
- if (this.opts.autoClearContext) {
1976
- this.contextStore.clear();
1977
- debug4("Context store cleared due to autoClearContext option");
1978
- } else {
1979
- const existingData = this.contextStore.getAllData();
1980
- const existingSteps = this.contextStore.getRecentSteps(100).length;
1981
- debug4("Context store preserving existing data", {
1982
- existingDataKeys: Object.keys(existingData),
1983
- existingStepsCount: existingSteps
1984
- });
1985
- }
1986
- } catch (error) {
1987
- debug4("Failed to initialize context store:", error);
1988
- console.warn("⚠️ Could not initialize context store:", error);
1989
- }
1990
- }
1991
- /**
1992
- * Get the context store instance
1993
- */
1994
- getContextStore() {
1995
- return this.contextStore;
1996
- }
1997
- /**
1998
- * Clear the context store
1999
- */
2000
- clearContext() {
2001
- if (this.contextStore) {
2002
- this.contextStore.clear();
2003
- }
2004
- }
2005
- /**
2006
- * Get all stored data from context store
2007
- */
2008
- getStoredData() {
2009
- if (this.contextStore) {
2010
- return this.contextStore.getAllData();
2011
- }
2012
- return {};
2013
- }
2014
- /**
2015
- * Get step summary from context store
2016
- */
2017
- getStepSummary() {
2018
- if (this.contextStore) {
2019
- return this.contextStore.getStepSummary();
2020
- }
2021
- return "";
2022
- }
2023
1923
  async getUIContext(action) {
2024
1924
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
2025
1925
  return await parseContextFromWebPage(this.page, {
@@ -2255,35 +2155,9 @@ var PageAgent = class {
2255
2155
  };
2256
2156
  }
2257
2157
  async aiAction(taskPrompt, opt) {
2258
- const originalPrompt = taskPrompt;
2259
- let processedPrompt = taskPrompt;
2260
- if (this.opts.enableCumulativeContext && this.contextStore) {
2261
- try {
2262
- const storedData = this.contextStore.getAllData();
2263
- if (Object.keys(storedData).length > 0) {
2264
- debug4("Available data for aiAction:", {
2265
- prompt: taskPrompt,
2266
- availableData: storedData
2267
- });
2268
- }
2269
- } catch (error) {
2270
- debug4("Context store operation failed:", error);
2271
- }
2272
- }
2273
2158
  const cacheable = opt?.cacheable;
2274
2159
  const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
2275
- let contextData;
2276
- if (this.opts.enableCumulativeContext && this.contextStore) {
2277
- try {
2278
- contextData = this.contextStore.getAllData();
2279
- if (contextData && Object.keys(contextData).length === 0) {
2280
- contextData = void 0;
2281
- }
2282
- } catch (error) {
2283
- debug4("Failed to get context data for cache:", error);
2284
- }
2285
- }
2286
- const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt, contextData);
2160
+ const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
2287
2161
  if (matchedCache && this.taskCache?.isCacheResultUsed) {
2288
2162
  const { executor: executor2 } = await this.taskExecutor.loadYamlFlowAsPlanning(
2289
2163
  taskPrompt,
@@ -2293,28 +2167,6 @@ var PageAgent = class {
2293
2167
  debug4("matched cache, will call .runYaml to run the action");
2294
2168
  const yaml5 = matchedCache.cacheContent?.yamlWorkflow;
2295
2169
  const result = await this.runYaml(yaml5);
2296
- if (this.opts.enableCumulativeContext && this.contextStore) {
2297
- try {
2298
- const executionResult = {
2299
- success: true,
2300
- actionType: "cached",
2301
- description: `Executed cached action: ${processedPrompt}`,
2302
- timing: result.metadata?.totalTime
2303
- };
2304
- this.contextStore.addStep({
2305
- type: "action",
2306
- summary: `Action: ${processedPrompt} (cached)`,
2307
- prompt: processedPrompt,
2308
- executionResult
2309
- });
2310
- debug4("Added cached action step to context store:", {
2311
- stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2312
- totalSteps: this.contextStore.getRecentSteps(100).length
2313
- });
2314
- } catch (error) {
2315
- debug4("Failed to add cached action step:", error);
2316
- }
2317
- }
2318
2170
  return {
2319
2171
  result: result.result,
2320
2172
  metadata: metadata2
@@ -2339,114 +2191,17 @@ var PageAgent = class {
2339
2191
  prompt: taskPrompt,
2340
2192
  yamlWorkflow: yamlFlowStr
2341
2193
  },
2342
- matchedCache,
2343
- contextData
2344
- // Pass context data for cache creation
2194
+ matchedCache
2345
2195
  );
2346
2196
  }
2347
2197
  const metadata = this.afterTaskRunning(executor);
2348
- if (this.opts.enableCumulativeContext && this.contextStore) {
2349
- try {
2350
- const executionResult = this.analyzeExecutionResults(executor, originalPrompt);
2351
- this.contextStore.addStep({
2352
- type: "action",
2353
- summary: `Action: ${processedPrompt}`,
2354
- prompt: processedPrompt,
2355
- executionResult
2356
- });
2357
- debug4("Added action step with execution result to context store:", {
2358
- stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2359
- totalSteps: this.contextStore.getRecentSteps(100).length,
2360
- executionResult
2361
- });
2362
- } catch (error) {
2363
- debug4("Failed to analyze execution results, adding step without execution result:", error);
2364
- try {
2365
- this.contextStore.addStep({
2366
- type: "action",
2367
- summary: `Action: ${processedPrompt}`,
2368
- prompt: processedPrompt
2369
- });
2370
- } catch (stepError) {
2371
- debug4("Failed to add action step:", stepError);
2372
- }
2373
- }
2374
- }
2375
2198
  return {
2376
2199
  result: output,
2377
2200
  metadata
2378
2201
  };
2379
2202
  }
2380
2203
  async aiQuery(demand) {
2381
- let processedDemand = demand;
2382
- let storageKey;
2383
- try {
2384
- const aiModel = await import("misoai-core/ai-model");
2385
- const contextStore = aiModel.getContextStore();
2386
- if (typeof demand === "string") {
2387
- const storageInstruction = contextStore.parseStorageInstruction(demand);
2388
- if (storageInstruction) {
2389
- storageKey = storageInstruction.key;
2390
- processedDemand = storageInstruction.cleanText;
2391
- contextStore._pendingAliases = storageInstruction.aliases;
2392
- } else {
2393
- const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
2394
- if (storageMatch) {
2395
- storageKey = storageMatch[1];
2396
- processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
2397
- }
2398
- }
2399
- }
2400
- } catch (error) {
2401
- debug4("Context store not available:", error);
2402
- }
2403
- const { output, executor } = await this.taskExecutor.query(processedDemand);
2404
- if (this.opts.enableCumulativeContext && this.contextStore) {
2405
- if (storageKey && output) {
2406
- try {
2407
- const pendingAliases = this.contextStore._pendingAliases;
2408
- if (pendingAliases) {
2409
- this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2410
- delete this.contextStore._pendingAliases;
2411
- debug4("Stored query result with aliases:", {
2412
- key: storageKey,
2413
- value: output,
2414
- aliases: pendingAliases
2415
- });
2416
- } else {
2417
- this.contextStore.storeData(storageKey, output);
2418
- debug4("Stored query result:", {
2419
- key: storageKey,
2420
- value: output
2421
- });
2422
- }
2423
- this.contextStore.addStep({
2424
- type: "query",
2425
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2426
- data: output,
2427
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2428
- });
2429
- debug4("Added query step to context store:", {
2430
- storageKey,
2431
- totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
2432
- totalSteps: this.contextStore.getRecentSteps(100).length
2433
- });
2434
- } catch (error) {
2435
- debug4("Failed to store query result:", error);
2436
- }
2437
- } else {
2438
- try {
2439
- this.contextStore.addStep({
2440
- type: "query",
2441
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2442
- data: output,
2443
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2444
- });
2445
- } catch (error) {
2446
- debug4("Failed to add query step:", error);
2447
- }
2448
- }
2449
- }
2204
+ const { output, executor } = await this.taskExecutor.query(demand);
2450
2205
  const metadata = this.afterTaskRunning(executor);
2451
2206
  return {
2452
2207
  result: output,
@@ -2556,48 +2311,6 @@ var PageAgent = class {
2556
2311
  };
2557
2312
  }
2558
2313
  async aiAssert(assertion, msg, opt) {
2559
- let executionContext = "";
2560
- if (this.opts.enableCumulativeContext && this.contextStore) {
2561
- try {
2562
- const recentSteps = this.contextStore.getRecentSteps(3);
2563
- const stepsWithExecutionResults = recentSteps.filter((step) => step.executionResult);
2564
- const storedData = this.contextStore.getAllData();
2565
- if (stepsWithExecutionResults.length > 0) {
2566
- const recentActions = stepsWithExecutionResults.map((step) => {
2567
- const result = step.executionResult;
2568
- return `- ${result.description}${result.success ? "" : " (FAILED)"}`;
2569
- }).join("\n");
2570
- executionContext = `
2571
-
2572
- Recent actions performed:
2573
- ${recentActions}
2574
-
2575
- This context may help verify the assertion.`;
2576
- }
2577
- if (storedData && Object.keys(storedData).length > 0) {
2578
- executionContext += `
2579
-
2580
- Available data for reference:
2581
- ${JSON.stringify(storedData, null, 2)}
2582
-
2583
- Note: If the assertion references any data keys or natural language equivalents, consider the stored values when verifying.`;
2584
- debug4("Available data for aiAssert:", {
2585
- assertion,
2586
- availableData: storedData
2587
- });
2588
- }
2589
- this.contextStore.addStep({
2590
- type: "assertion",
2591
- summary: `Assertion: ${assertion}`,
2592
- prompt: assertion
2593
- });
2594
- debug4("Added assertion step to context store:", {
2595
- totalSteps: this.contextStore.getRecentSteps(100).length
2596
- });
2597
- } catch (error) {
2598
- debug4("Context store operation failed:", error);
2599
- }
2600
- }
2601
2314
  let currentUrl = "";
2602
2315
  if (this.page.url) {
2603
2316
  try {
@@ -2605,13 +2318,7 @@ Note: If the assertion references any data keys or natural language equivalents,
2605
2318
  } catch (e) {
2606
2319
  }
2607
2320
  }
2608
- let assertionWithContext = assertion;
2609
- if (currentUrl) {
2610
- assertionWithContext = `For the page at URL "${currentUrl}", ${assertion}`;
2611
- }
2612
- if (executionContext) {
2613
- assertionWithContext += executionContext;
2614
- }
2321
+ const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
2615
2322
  const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
2616
2323
  const metadata = this.afterTaskRunning(executor, true);
2617
2324
  if (output && opt?.keepRawResponse) {
@@ -2825,79 +2532,6 @@ ${errors}`);
2825
2532
  async destroy() {
2826
2533
  await this.page.destroy();
2827
2534
  }
2828
- /**
2829
- * Analyze execution results from executor to generate meaningful descriptions
2830
- */
2831
- analyzeExecutionResults(executor, originalPrompt) {
2832
- const tasks = executor.tasks;
2833
- const success = !executor.isInErrorState();
2834
- if (!success) {
2835
- const errorTask = executor.latestErrorTask();
2836
- return {
2837
- success: false,
2838
- actionType: "error",
2839
- description: `Failed to execute: ${originalPrompt}`,
2840
- error: errorTask?.error
2841
- };
2842
- }
2843
- const actionTasks = tasks.filter((t) => t.type === "Action" && t.status === "finished");
2844
- const locateTasks = tasks.filter((t) => t.type === "Insight" && t.subType === "Locate");
2845
- const lastAction = actionTasks[actionTasks.length - 1];
2846
- const lastLocate = locateTasks[locateTasks.length - 1];
2847
- if (!lastAction) {
2848
- return {
2849
- success: true,
2850
- actionType: "unknown",
2851
- description: `Completed: ${originalPrompt}`
2852
- };
2853
- }
2854
- const actionType = lastAction.subType || "unknown";
2855
- const elementInfo = this.extractElementInfo(lastLocate, lastAction);
2856
- const description = this.generateActionDescription(actionType, lastAction.param, elementInfo);
2857
- return {
2858
- success: true,
2859
- actionType,
2860
- description,
2861
- elementInfo,
2862
- timing: lastAction.timing?.cost
2863
- };
2864
- }
2865
- /**
2866
- * Extract element information from locate task
2867
- */
2868
- extractElementInfo(locateTask, _actionTask) {
2869
- if (!locateTask?.output?.element)
2870
- return void 0;
2871
- const element = locateTask.output.element;
2872
- return {
2873
- type: element.attributes?.nodeType || "unknown",
2874
- text: element.content || element.attributes?.placeholder || element.attributes?.title || "",
2875
- location: `(${element.center[0]}, ${element.center[1]})`
2876
- };
2877
- }
2878
- /**
2879
- * Generate natural language description for actions
2880
- */
2881
- generateActionDescription(actionType, param, elementInfo) {
2882
- const elementDesc = elementInfo ? `'${elementInfo.text || elementInfo.type}' element` : "element";
2883
- switch (actionType) {
2884
- case "Tap":
2885
- return `Clicked on ${elementDesc}`;
2886
- case "Input":
2887
- const inputValue = param?.value || "";
2888
- return `Entered "${inputValue}" into ${elementDesc}`;
2889
- case "KeyboardPress":
2890
- return `Pressed ${param?.value || "key"}`;
2891
- case "Scroll":
2892
- return `Scrolled ${param?.direction || "on page"}`;
2893
- case "Hover":
2894
- return `Hovered over ${elementDesc}`;
2895
- case "Drag":
2896
- return `Dragged ${elementDesc}`;
2897
- default:
2898
- return `Performed ${actionType} action on ${elementDesc}`;
2899
- }
2900
- }
2901
2535
  };
2902
2536
 
2903
2537
  // src/puppeteer/index.ts
@@ -2919,7 +2553,7 @@ var Page = class {
2919
2553
  this.everMoved = false;
2920
2554
  this.underlyingPage = underlyingPage;
2921
2555
  this.pageType = pageType;
2922
- this.waitForNavigationTimeout = opts?.waitForNavigationTimeout || import_constants3.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
2556
+ this.waitForNavigationTimeout = opts?.waitForNavigationTimeout ?? import_constants3.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
2923
2557
  }
2924
2558
  async evaluate(pageFunction, arg) {
2925
2559
  let result;
@@ -3199,9 +2833,9 @@ var WebPage = class extends Page {
3199
2833
  }
3200
2834
  async waitUntilNetworkIdle(options) {
3201
2835
  await this.underlyingPage.waitForNetworkIdle({
3202
- idleTime: options?.idleTime || import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME,
3203
- concurrency: options?.concurrency || import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
3204
- 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
3205
2839
  });
3206
2840
  }
3207
2841
  };