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
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");
@@ -1716,70 +1718,44 @@ var TaskCache = class {
1716
1718
  this.cache = cacheContent;
1717
1719
  this.cacheOriginalLength = this.cache.caches.length;
1718
1720
  }
1719
- matchCache(prompt, type, contextData) {
1720
- const contextHash = contextData ? this.generateContextHash(contextData) : void 0;
1721
+ matchCache(prompt, type) {
1721
1722
  for (let i = 0; i < this.cacheOriginalLength; i++) {
1722
1723
  const item = this.cache.caches[i];
1723
1724
  const key = `${type}:${prompt}:${i}`;
1724
- if (item.type !== type || item.prompt !== prompt || this.matchedCacheIndices.has(key)) {
1725
- continue;
1726
- }
1727
- if (type === "plan" && item.type === "plan") {
1728
- const planItem = item;
1729
- if (contextHash && planItem.contextHash) {
1730
- if (contextHash !== planItem.contextHash) {
1731
- debug3("cache context mismatch, type: %s, prompt: %s, index: %d", type, prompt, i);
1732
- continue;
1725
+ if (item.type === type && item.prompt === prompt && !this.matchedCacheIndices.has(key)) {
1726
+ this.matchedCacheIndices.add(key);
1727
+ debug3(
1728
+ "cache found and marked as used, type: %s, prompt: %s, index: %d",
1729
+ type,
1730
+ prompt,
1731
+ i
1732
+ );
1733
+ return {
1734
+ cacheContent: item,
1735
+ updateFn: (cb) => {
1736
+ debug3(
1737
+ "will call updateFn to update cache, type: %s, prompt: %s, index: %d",
1738
+ type,
1739
+ prompt,
1740
+ i
1741
+ );
1742
+ cb(item);
1743
+ debug3(
1744
+ "cache updated, will flush to file, type: %s, prompt: %s, index: %d",
1745
+ type,
1746
+ prompt,
1747
+ i
1748
+ );
1749
+ this.flushCacheToFile();
1733
1750
  }
1734
- } else if (contextHash || planItem.contextHash) {
1735
- debug3("cache context availability mismatch, type: %s, prompt: %s, index: %d", type, prompt, i);
1736
- continue;
1737
- }
1751
+ };
1738
1752
  }
1739
- this.matchedCacheIndices.add(key);
1740
- debug3(
1741
- "cache found and marked as used, type: %s, prompt: %s, index: %d, contextMatch: %s",
1742
- type,
1743
- prompt,
1744
- i,
1745
- contextHash ? "yes" : "no-context"
1746
- );
1747
- return {
1748
- cacheContent: item,
1749
- updateFn: (cb) => {
1750
- debug3(
1751
- "will call updateFn to update cache, type: %s, prompt: %s, index: %d",
1752
- type,
1753
- prompt,
1754
- i
1755
- );
1756
- cb(item);
1757
- debug3(
1758
- "cache updated, will flush to file, type: %s, prompt: %s, index: %d",
1759
- type,
1760
- prompt,
1761
- i
1762
- );
1763
- this.flushCacheToFile();
1764
- }
1765
- };
1766
1753
  }
1767
- debug3("no unused cache found, type: %s, prompt: %s, contextHash: %s", type, prompt, contextHash);
1754
+ debug3("no unused cache found, type: %s, prompt: %s", type, prompt);
1768
1755
  return void 0;
1769
1756
  }
1770
- generateContextHash(contextData) {
1771
- const sortedKeys = Object.keys(contextData).sort();
1772
- const stableString = sortedKeys.map((key) => `${key}:${JSON.stringify(contextData[key])}`).join("|");
1773
- let hash = 0;
1774
- for (let i = 0; i < stableString.length; i++) {
1775
- const char = stableString.charCodeAt(i);
1776
- hash = (hash << 5) - hash + char;
1777
- hash = hash & hash;
1778
- }
1779
- return hash.toString(36);
1780
- }
1781
- matchPlanCache(prompt, contextData) {
1782
- return this.matchCache(prompt, "plan", contextData);
1757
+ matchPlanCache(prompt) {
1758
+ return this.matchCache(prompt, "plan");
1783
1759
  }
1784
1760
  matchLocateCache(prompt) {
1785
1761
  return this.matchCache(prompt, "locate");
@@ -1855,16 +1831,11 @@ cache file: ${cacheFile}`
1855
1831
  );
1856
1832
  }
1857
1833
  }
1858
- updateOrAppendCacheRecord(newRecord, cachedRecord, contextData) {
1834
+ updateOrAppendCacheRecord(newRecord, cachedRecord) {
1859
1835
  if (cachedRecord) {
1860
1836
  if (newRecord.type === "plan") {
1861
1837
  cachedRecord.updateFn((cache) => {
1862
- const planCache = cache;
1863
- planCache.yamlWorkflow = newRecord.yamlWorkflow;
1864
- if (contextData) {
1865
- planCache.contextHash = this.generateContextHash(contextData);
1866
- planCache.contextData = { ...contextData };
1867
- }
1838
+ cache.yamlWorkflow = newRecord.yamlWorkflow;
1868
1839
  });
1869
1840
  } else {
1870
1841
  cachedRecord.updateFn((cache) => {
@@ -1872,11 +1843,6 @@ cache file: ${cacheFile}`
1872
1843
  });
1873
1844
  }
1874
1845
  } else {
1875
- if (newRecord.type === "plan" && contextData) {
1876
- const planRecord = newRecord;
1877
- planRecord.contextHash = this.generateContextHash(contextData);
1878
- planRecord.contextData = { ...contextData };
1879
- }
1880
1846
  this.appendCache(newRecord);
1881
1847
  }
1882
1848
  }
@@ -1906,13 +1872,10 @@ var PageAgent = class {
1906
1872
  generateReport: true,
1907
1873
  autoPrintReportMsg: true,
1908
1874
  groupName: "Midscene Report",
1909
- groupDescription: "",
1910
- enableCumulativeContext: true,
1911
- autoClearContext: false
1875
+ groupDescription: ""
1912
1876
  },
1913
1877
  opts || {}
1914
1878
  );
1915
- this.initializeContextStore();
1916
1879
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1917
1880
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1918
1881
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1939,69 +1902,6 @@ var PageAgent = class {
1939
1902
  opts?.testId || this.page.pageType || "web"
1940
1903
  );
1941
1904
  }
1942
- /**
1943
- * Initialize context store for cumulative context functionality
1944
- */
1945
- async initializeContextStore() {
1946
- if (!this.opts.enableCumulativeContext) {
1947
- debug4("Cumulative context disabled via options");
1948
- return;
1949
- }
1950
- try {
1951
- const aiModel = await import("misoai-core/ai-model");
1952
- this.contextStore = aiModel.getContextStore();
1953
- debug4("Context store initialized successfully", {
1954
- autoClearContext: this.opts.autoClearContext,
1955
- testId: this.opts.testId
1956
- });
1957
- if (this.opts.autoClearContext) {
1958
- this.contextStore.clear();
1959
- debug4("Context store cleared due to autoClearContext option");
1960
- } else {
1961
- const existingData = this.contextStore.getAllData();
1962
- const existingSteps = this.contextStore.getRecentSteps(100).length;
1963
- debug4("Context store preserving existing data", {
1964
- existingDataKeys: Object.keys(existingData),
1965
- existingStepsCount: existingSteps
1966
- });
1967
- }
1968
- } catch (error) {
1969
- debug4("Failed to initialize context store:", error);
1970
- console.warn("⚠️ Could not initialize context store:", error);
1971
- }
1972
- }
1973
- /**
1974
- * Get the context store instance
1975
- */
1976
- getContextStore() {
1977
- return this.contextStore;
1978
- }
1979
- /**
1980
- * Clear the context store
1981
- */
1982
- clearContext() {
1983
- if (this.contextStore) {
1984
- this.contextStore.clear();
1985
- }
1986
- }
1987
- /**
1988
- * Get all stored data from context store
1989
- */
1990
- getStoredData() {
1991
- if (this.contextStore) {
1992
- return this.contextStore.getAllData();
1993
- }
1994
- return {};
1995
- }
1996
- /**
1997
- * Get step summary from context store
1998
- */
1999
- getStepSummary() {
2000
- if (this.contextStore) {
2001
- return this.contextStore.getStepSummary();
2002
- }
2003
- return "";
2004
- }
2005
1905
  async getUIContext(action) {
2006
1906
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
2007
1907
  return await parseContextFromWebPage(this.page, {
@@ -2237,35 +2137,9 @@ var PageAgent = class {
2237
2137
  };
2238
2138
  }
2239
2139
  async aiAction(taskPrompt, opt) {
2240
- const originalPrompt = taskPrompt;
2241
- let processedPrompt = taskPrompt;
2242
- if (this.opts.enableCumulativeContext && this.contextStore) {
2243
- try {
2244
- const storedData = this.contextStore.getAllData();
2245
- if (Object.keys(storedData).length > 0) {
2246
- debug4("Available data for aiAction:", {
2247
- prompt: taskPrompt,
2248
- availableData: storedData
2249
- });
2250
- }
2251
- } catch (error) {
2252
- debug4("Context store operation failed:", error);
2253
- }
2254
- }
2255
2140
  const cacheable = opt?.cacheable;
2256
2141
  const isVlmUiTars = vlLocateMode() === "vlm-ui-tars";
2257
- let contextData;
2258
- if (this.opts.enableCumulativeContext && this.contextStore) {
2259
- try {
2260
- contextData = this.contextStore.getAllData();
2261
- if (contextData && Object.keys(contextData).length === 0) {
2262
- contextData = void 0;
2263
- }
2264
- } catch (error) {
2265
- debug4("Failed to get context data for cache:", error);
2266
- }
2267
- }
2268
- const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt, contextData);
2142
+ const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
2269
2143
  if (matchedCache && this.taskCache?.isCacheResultUsed) {
2270
2144
  const { executor: executor2 } = await this.taskExecutor.loadYamlFlowAsPlanning(
2271
2145
  taskPrompt,
@@ -2275,28 +2149,6 @@ var PageAgent = class {
2275
2149
  debug4("matched cache, will call .runYaml to run the action");
2276
2150
  const yaml5 = matchedCache.cacheContent?.yamlWorkflow;
2277
2151
  const result = await this.runYaml(yaml5);
2278
- if (this.opts.enableCumulativeContext && this.contextStore) {
2279
- try {
2280
- const executionResult = {
2281
- success: true,
2282
- actionType: "cached",
2283
- description: `Executed cached action: ${processedPrompt}`,
2284
- timing: result.metadata?.totalTime
2285
- };
2286
- this.contextStore.addStep({
2287
- type: "action",
2288
- summary: `Action: ${processedPrompt} (cached)`,
2289
- prompt: processedPrompt,
2290
- executionResult
2291
- });
2292
- debug4("Added cached action step to context store:", {
2293
- stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2294
- totalSteps: this.contextStore.getRecentSteps(100).length
2295
- });
2296
- } catch (error) {
2297
- debug4("Failed to add cached action step:", error);
2298
- }
2299
- }
2300
2152
  return {
2301
2153
  result: result.result,
2302
2154
  metadata: metadata2
@@ -2321,114 +2173,17 @@ var PageAgent = class {
2321
2173
  prompt: taskPrompt,
2322
2174
  yamlWorkflow: yamlFlowStr
2323
2175
  },
2324
- matchedCache,
2325
- contextData
2326
- // Pass context data for cache creation
2176
+ matchedCache
2327
2177
  );
2328
2178
  }
2329
2179
  const metadata = this.afterTaskRunning(executor);
2330
- if (this.opts.enableCumulativeContext && this.contextStore) {
2331
- try {
2332
- const executionResult = this.analyzeExecutionResults(executor, originalPrompt);
2333
- this.contextStore.addStep({
2334
- type: "action",
2335
- summary: `Action: ${processedPrompt}`,
2336
- prompt: processedPrompt,
2337
- executionResult
2338
- });
2339
- debug4("Added action step with execution result to context store:", {
2340
- stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2341
- totalSteps: this.contextStore.getRecentSteps(100).length,
2342
- executionResult
2343
- });
2344
- } catch (error) {
2345
- debug4("Failed to analyze execution results, adding step without execution result:", error);
2346
- try {
2347
- this.contextStore.addStep({
2348
- type: "action",
2349
- summary: `Action: ${processedPrompt}`,
2350
- prompt: processedPrompt
2351
- });
2352
- } catch (stepError) {
2353
- debug4("Failed to add action step:", stepError);
2354
- }
2355
- }
2356
- }
2357
2180
  return {
2358
2181
  result: output,
2359
2182
  metadata
2360
2183
  };
2361
2184
  }
2362
2185
  async aiQuery(demand) {
2363
- let processedDemand = demand;
2364
- let storageKey;
2365
- try {
2366
- const aiModel = await import("misoai-core/ai-model");
2367
- const contextStore = aiModel.getContextStore();
2368
- if (typeof demand === "string") {
2369
- const storageInstruction = contextStore.parseStorageInstruction(demand);
2370
- if (storageInstruction) {
2371
- storageKey = storageInstruction.key;
2372
- processedDemand = storageInstruction.cleanText;
2373
- contextStore._pendingAliases = storageInstruction.aliases;
2374
- } else {
2375
- const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
2376
- if (storageMatch) {
2377
- storageKey = storageMatch[1];
2378
- processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
2379
- }
2380
- }
2381
- }
2382
- } catch (error) {
2383
- debug4("Context store not available:", error);
2384
- }
2385
- const { output, executor } = await this.taskExecutor.query(processedDemand);
2386
- if (this.opts.enableCumulativeContext && this.contextStore) {
2387
- if (storageKey && output) {
2388
- try {
2389
- const pendingAliases = this.contextStore._pendingAliases;
2390
- if (pendingAliases) {
2391
- this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2392
- delete this.contextStore._pendingAliases;
2393
- debug4("Stored query result with aliases:", {
2394
- key: storageKey,
2395
- value: output,
2396
- aliases: pendingAliases
2397
- });
2398
- } else {
2399
- this.contextStore.storeData(storageKey, output);
2400
- debug4("Stored query result:", {
2401
- key: storageKey,
2402
- value: output
2403
- });
2404
- }
2405
- this.contextStore.addStep({
2406
- type: "query",
2407
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2408
- data: output,
2409
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2410
- });
2411
- debug4("Added query step to context store:", {
2412
- storageKey,
2413
- totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
2414
- totalSteps: this.contextStore.getRecentSteps(100).length
2415
- });
2416
- } catch (error) {
2417
- debug4("Failed to store query result:", error);
2418
- }
2419
- } else {
2420
- try {
2421
- this.contextStore.addStep({
2422
- type: "query",
2423
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2424
- data: output,
2425
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2426
- });
2427
- } catch (error) {
2428
- debug4("Failed to add query step:", error);
2429
- }
2430
- }
2431
- }
2186
+ const { output, executor } = await this.taskExecutor.query(demand);
2432
2187
  const metadata = this.afterTaskRunning(executor);
2433
2188
  return {
2434
2189
  result: output,
@@ -2538,48 +2293,6 @@ var PageAgent = class {
2538
2293
  };
2539
2294
  }
2540
2295
  async aiAssert(assertion, msg, opt) {
2541
- let executionContext = "";
2542
- if (this.opts.enableCumulativeContext && this.contextStore) {
2543
- try {
2544
- const recentSteps = this.contextStore.getRecentSteps(3);
2545
- const stepsWithExecutionResults = recentSteps.filter((step) => step.executionResult);
2546
- const storedData = this.contextStore.getAllData();
2547
- if (stepsWithExecutionResults.length > 0) {
2548
- const recentActions = stepsWithExecutionResults.map((step) => {
2549
- const result = step.executionResult;
2550
- return `- ${result.description}${result.success ? "" : " (FAILED)"}`;
2551
- }).join("\n");
2552
- executionContext = `
2553
-
2554
- Recent actions performed:
2555
- ${recentActions}
2556
-
2557
- This context may help verify the assertion.`;
2558
- }
2559
- if (storedData && Object.keys(storedData).length > 0) {
2560
- executionContext += `
2561
-
2562
- Available data for reference:
2563
- ${JSON.stringify(storedData, null, 2)}
2564
-
2565
- Note: If the assertion references any data keys or natural language equivalents, consider the stored values when verifying.`;
2566
- debug4("Available data for aiAssert:", {
2567
- assertion,
2568
- availableData: storedData
2569
- });
2570
- }
2571
- this.contextStore.addStep({
2572
- type: "assertion",
2573
- summary: `Assertion: ${assertion}`,
2574
- prompt: assertion
2575
- });
2576
- debug4("Added assertion step to context store:", {
2577
- totalSteps: this.contextStore.getRecentSteps(100).length
2578
- });
2579
- } catch (error) {
2580
- debug4("Context store operation failed:", error);
2581
- }
2582
- }
2583
2296
  let currentUrl = "";
2584
2297
  if (this.page.url) {
2585
2298
  try {
@@ -2587,13 +2300,7 @@ Note: If the assertion references any data keys or natural language equivalents,
2587
2300
  } catch (e) {
2588
2301
  }
2589
2302
  }
2590
- let assertionWithContext = assertion;
2591
- if (currentUrl) {
2592
- assertionWithContext = `For the page at URL "${currentUrl}", ${assertion}`;
2593
- }
2594
- if (executionContext) {
2595
- assertionWithContext += executionContext;
2596
- }
2303
+ const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
2597
2304
  const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
2598
2305
  const metadata = this.afterTaskRunning(executor, true);
2599
2306
  if (output && opt?.keepRawResponse) {
@@ -2807,79 +2514,6 @@ ${errors}`);
2807
2514
  async destroy() {
2808
2515
  await this.page.destroy();
2809
2516
  }
2810
- /**
2811
- * Analyze execution results from executor to generate meaningful descriptions
2812
- */
2813
- analyzeExecutionResults(executor, originalPrompt) {
2814
- const tasks = executor.tasks;
2815
- const success = !executor.isInErrorState();
2816
- if (!success) {
2817
- const errorTask = executor.latestErrorTask();
2818
- return {
2819
- success: false,
2820
- actionType: "error",
2821
- description: `Failed to execute: ${originalPrompt}`,
2822
- error: errorTask?.error
2823
- };
2824
- }
2825
- const actionTasks = tasks.filter((t) => t.type === "Action" && t.status === "finished");
2826
- const locateTasks = tasks.filter((t) => t.type === "Insight" && t.subType === "Locate");
2827
- const lastAction = actionTasks[actionTasks.length - 1];
2828
- const lastLocate = locateTasks[locateTasks.length - 1];
2829
- if (!lastAction) {
2830
- return {
2831
- success: true,
2832
- actionType: "unknown",
2833
- description: `Completed: ${originalPrompt}`
2834
- };
2835
- }
2836
- const actionType = lastAction.subType || "unknown";
2837
- const elementInfo = this.extractElementInfo(lastLocate, lastAction);
2838
- const description = this.generateActionDescription(actionType, lastAction.param, elementInfo);
2839
- return {
2840
- success: true,
2841
- actionType,
2842
- description,
2843
- elementInfo,
2844
- timing: lastAction.timing?.cost
2845
- };
2846
- }
2847
- /**
2848
- * Extract element information from locate task
2849
- */
2850
- extractElementInfo(locateTask, _actionTask) {
2851
- if (!locateTask?.output?.element)
2852
- return void 0;
2853
- const element = locateTask.output.element;
2854
- return {
2855
- type: element.attributes?.nodeType || "unknown",
2856
- text: element.content || element.attributes?.placeholder || element.attributes?.title || "",
2857
- location: `(${element.center[0]}, ${element.center[1]})`
2858
- };
2859
- }
2860
- /**
2861
- * Generate natural language description for actions
2862
- */
2863
- generateActionDescription(actionType, param, elementInfo) {
2864
- const elementDesc = elementInfo ? `'${elementInfo.text || elementInfo.type}' element` : "element";
2865
- switch (actionType) {
2866
- case "Tap":
2867
- return `Clicked on ${elementDesc}`;
2868
- case "Input":
2869
- const inputValue = param?.value || "";
2870
- return `Entered "${inputValue}" into ${elementDesc}`;
2871
- case "KeyboardPress":
2872
- return `Pressed ${param?.value || "key"}`;
2873
- case "Scroll":
2874
- return `Scrolled ${param?.direction || "on page"}`;
2875
- case "Hover":
2876
- return `Hovered over ${elementDesc}`;
2877
- case "Drag":
2878
- return `Dragged ${elementDesc}`;
2879
- default:
2880
- return `Performed ${actionType} action on ${elementDesc}`;
2881
- }
2882
- }
2883
2517
  };
2884
2518
 
2885
2519
  // src/puppeteer/base-page.ts
@@ -2898,7 +2532,7 @@ var Page = class {
2898
2532
  this.everMoved = false;
2899
2533
  this.underlyingPage = underlyingPage;
2900
2534
  this.pageType = pageType;
2901
- this.waitForNavigationTimeout = opts?.waitForNavigationTimeout || DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT2;
2535
+ this.waitForNavigationTimeout = opts?.waitForNavigationTimeout ?? DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT2;
2902
2536
  }
2903
2537
  async evaluate(pageFunction, arg) {
2904
2538
  let result;
@@ -3434,9 +3068,9 @@ var WebPage2 = class extends Page {
3434
3068
  }
3435
3069
  async waitUntilNetworkIdle(options) {
3436
3070
  await this.underlyingPage.waitForNetworkIdle({
3437
- idleTime: options?.idleTime || DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME,
3438
- concurrency: options?.concurrency || DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
3439
- 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
3440
3074
  });
3441
3075
  }
3442
3076
  };