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
@@ -193,10 +193,11 @@ var ScriptPlayer = class {
193
193
  this.unnamedResultIndex = 0;
194
194
  this.pageAgent = null;
195
195
  this.result = {};
196
+ const target = script.target || script.web || script.android;
196
197
  if (import_utils3.ifInBrowser) {
197
198
  this.output = void 0;
198
- } else if (script.target?.output) {
199
- this.output = (0, import_node_path.resolve)(process.cwd(), script.target.output);
199
+ } else if (target?.output) {
200
+ this.output = (0, import_node_path.resolve)(process.cwd(), target.output);
200
201
  } else {
201
202
  this.output = (0, import_node_path.join)((0, import_common.getMidsceneRunSubDir)("output"), `${process.pid}.json`);
202
203
  }
@@ -270,12 +271,13 @@ var ScriptPlayer = class {
270
271
  } else if ("aiAssert" in flowItem) {
271
272
  const assertTask = flowItem;
272
273
  const prompt = assertTask.aiAssert;
274
+ const msg = assertTask.errorMessage;
273
275
  (0, import_utils3.assert)(prompt, "missing prompt for aiAssert");
274
276
  (0, import_utils3.assert)(
275
277
  typeof prompt === "string",
276
278
  "prompt for aiAssert must be a string"
277
279
  );
278
- await agent.aiAssert(prompt);
280
+ await agent.aiAssert(prompt, msg);
279
281
  } else if ("aiQuery" in flowItem) {
280
282
  const queryTask = flowItem;
281
283
  const prompt = queryTask.aiQuery;
@@ -1725,7 +1727,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1725
1727
  var import_semver = __toESM(require("semver"));
1726
1728
 
1727
1729
  // package.json
1728
- var version = "1.0.5";
1730
+ var version = "1.5.6";
1729
1731
 
1730
1732
  // src/common/task-cache.ts
1731
1733
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -1753,70 +1755,44 @@ var TaskCache = class {
1753
1755
  this.cache = cacheContent;
1754
1756
  this.cacheOriginalLength = this.cache.caches.length;
1755
1757
  }
1756
- matchCache(prompt, type, contextData) {
1757
- const contextHash = contextData ? this.generateContextHash(contextData) : void 0;
1758
+ matchCache(prompt, type) {
1758
1759
  for (let i = 0; i < this.cacheOriginalLength; i++) {
1759
1760
  const item = this.cache.caches[i];
1760
1761
  const key = `${type}:${prompt}:${i}`;
1761
- if (item.type !== type || item.prompt !== prompt || this.matchedCacheIndices.has(key)) {
1762
- continue;
1763
- }
1764
- if (type === "plan" && item.type === "plan") {
1765
- const planItem = item;
1766
- if (contextHash && planItem.contextHash) {
1767
- if (contextHash !== planItem.contextHash) {
1768
- debug3("cache context mismatch, type: %s, prompt: %s, index: %d", type, prompt, i);
1769
- continue;
1762
+ if (item.type === type && item.prompt === prompt && !this.matchedCacheIndices.has(key)) {
1763
+ this.matchedCacheIndices.add(key);
1764
+ debug3(
1765
+ "cache found and marked as used, type: %s, prompt: %s, index: %d",
1766
+ type,
1767
+ prompt,
1768
+ i
1769
+ );
1770
+ return {
1771
+ cacheContent: item,
1772
+ updateFn: (cb) => {
1773
+ debug3(
1774
+ "will call updateFn to update cache, type: %s, prompt: %s, index: %d",
1775
+ type,
1776
+ prompt,
1777
+ i
1778
+ );
1779
+ cb(item);
1780
+ debug3(
1781
+ "cache updated, will flush to file, type: %s, prompt: %s, index: %d",
1782
+ type,
1783
+ prompt,
1784
+ i
1785
+ );
1786
+ this.flushCacheToFile();
1770
1787
  }
1771
- } else if (contextHash || planItem.contextHash) {
1772
- debug3("cache context availability mismatch, type: %s, prompt: %s, index: %d", type, prompt, i);
1773
- continue;
1774
- }
1788
+ };
1775
1789
  }
1776
- this.matchedCacheIndices.add(key);
1777
- debug3(
1778
- "cache found and marked as used, type: %s, prompt: %s, index: %d, contextMatch: %s",
1779
- type,
1780
- prompt,
1781
- i,
1782
- contextHash ? "yes" : "no-context"
1783
- );
1784
- return {
1785
- cacheContent: item,
1786
- updateFn: (cb) => {
1787
- debug3(
1788
- "will call updateFn to update cache, type: %s, prompt: %s, index: %d",
1789
- type,
1790
- prompt,
1791
- i
1792
- );
1793
- cb(item);
1794
- debug3(
1795
- "cache updated, will flush to file, type: %s, prompt: %s, index: %d",
1796
- type,
1797
- prompt,
1798
- i
1799
- );
1800
- this.flushCacheToFile();
1801
- }
1802
- };
1803
1790
  }
1804
- debug3("no unused cache found, type: %s, prompt: %s, contextHash: %s", type, prompt, contextHash);
1791
+ debug3("no unused cache found, type: %s, prompt: %s", type, prompt);
1805
1792
  return void 0;
1806
1793
  }
1807
- generateContextHash(contextData) {
1808
- const sortedKeys = Object.keys(contextData).sort();
1809
- const stableString = sortedKeys.map((key) => `${key}:${JSON.stringify(contextData[key])}`).join("|");
1810
- let hash = 0;
1811
- for (let i = 0; i < stableString.length; i++) {
1812
- const char = stableString.charCodeAt(i);
1813
- hash = (hash << 5) - hash + char;
1814
- hash = hash & hash;
1815
- }
1816
- return hash.toString(36);
1817
- }
1818
- matchPlanCache(prompt, contextData) {
1819
- return this.matchCache(prompt, "plan", contextData);
1794
+ matchPlanCache(prompt) {
1795
+ return this.matchCache(prompt, "plan");
1820
1796
  }
1821
1797
  matchLocateCache(prompt) {
1822
1798
  return this.matchCache(prompt, "locate");
@@ -1892,16 +1868,11 @@ cache file: ${cacheFile}`
1892
1868
  );
1893
1869
  }
1894
1870
  }
1895
- updateOrAppendCacheRecord(newRecord, cachedRecord, contextData) {
1871
+ updateOrAppendCacheRecord(newRecord, cachedRecord) {
1896
1872
  if (cachedRecord) {
1897
1873
  if (newRecord.type === "plan") {
1898
1874
  cachedRecord.updateFn((cache) => {
1899
- const planCache = cache;
1900
- planCache.yamlWorkflow = newRecord.yamlWorkflow;
1901
- if (contextData) {
1902
- planCache.contextHash = this.generateContextHash(contextData);
1903
- planCache.contextData = { ...contextData };
1904
- }
1875
+ cache.yamlWorkflow = newRecord.yamlWorkflow;
1905
1876
  });
1906
1877
  } else {
1907
1878
  cachedRecord.updateFn((cache) => {
@@ -1909,11 +1880,6 @@ cache file: ${cacheFile}`
1909
1880
  });
1910
1881
  }
1911
1882
  } else {
1912
- if (newRecord.type === "plan" && contextData) {
1913
- const planRecord = newRecord;
1914
- planRecord.contextHash = this.generateContextHash(contextData);
1915
- planRecord.contextData = { ...contextData };
1916
- }
1917
1883
  this.appendCache(newRecord);
1918
1884
  }
1919
1885
  }
@@ -1943,13 +1909,10 @@ var PageAgent = class {
1943
1909
  generateReport: true,
1944
1910
  autoPrintReportMsg: true,
1945
1911
  groupName: "Midscene Report",
1946
- groupDescription: "",
1947
- enableCumulativeContext: true,
1948
- autoClearContext: false
1912
+ groupDescription: ""
1949
1913
  },
1950
1914
  opts || {}
1951
1915
  );
1952
- this.initializeContextStore();
1953
1916
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1954
1917
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || import_constants2.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1955
1918
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || import_constants2.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1976,69 +1939,6 @@ var PageAgent = class {
1976
1939
  opts?.testId || this.page.pageType || "web"
1977
1940
  );
1978
1941
  }
1979
- /**
1980
- * Initialize context store for cumulative context functionality
1981
- */
1982
- async initializeContextStore() {
1983
- if (!this.opts.enableCumulativeContext) {
1984
- debug4("Cumulative context disabled via options");
1985
- return;
1986
- }
1987
- try {
1988
- const aiModel = await import("misoai-core/ai-model");
1989
- this.contextStore = aiModel.getContextStore();
1990
- debug4("Context store initialized successfully", {
1991
- autoClearContext: this.opts.autoClearContext,
1992
- testId: this.opts.testId
1993
- });
1994
- if (this.opts.autoClearContext) {
1995
- this.contextStore.clear();
1996
- debug4("Context store cleared due to autoClearContext option");
1997
- } else {
1998
- const existingData = this.contextStore.getAllData();
1999
- const existingSteps = this.contextStore.getRecentSteps(100).length;
2000
- debug4("Context store preserving existing data", {
2001
- existingDataKeys: Object.keys(existingData),
2002
- existingStepsCount: existingSteps
2003
- });
2004
- }
2005
- } catch (error) {
2006
- debug4("Failed to initialize context store:", error);
2007
- console.warn("⚠️ Could not initialize context store:", error);
2008
- }
2009
- }
2010
- /**
2011
- * Get the context store instance
2012
- */
2013
- getContextStore() {
2014
- return this.contextStore;
2015
- }
2016
- /**
2017
- * Clear the context store
2018
- */
2019
- clearContext() {
2020
- if (this.contextStore) {
2021
- this.contextStore.clear();
2022
- }
2023
- }
2024
- /**
2025
- * Get all stored data from context store
2026
- */
2027
- getStoredData() {
2028
- if (this.contextStore) {
2029
- return this.contextStore.getAllData();
2030
- }
2031
- return {};
2032
- }
2033
- /**
2034
- * Get step summary from context store
2035
- */
2036
- getStepSummary() {
2037
- if (this.contextStore) {
2038
- return this.contextStore.getStepSummary();
2039
- }
2040
- return "";
2041
- }
2042
1942
  async getUIContext(action) {
2043
1943
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
2044
1944
  return await parseContextFromWebPage(this.page, {
@@ -2274,35 +2174,9 @@ var PageAgent = class {
2274
2174
  };
2275
2175
  }
2276
2176
  async aiAction(taskPrompt, opt) {
2277
- const originalPrompt = taskPrompt;
2278
- let processedPrompt = taskPrompt;
2279
- if (this.opts.enableCumulativeContext && this.contextStore) {
2280
- try {
2281
- const storedData = this.contextStore.getAllData();
2282
- if (Object.keys(storedData).length > 0) {
2283
- debug4("Available data for aiAction:", {
2284
- prompt: taskPrompt,
2285
- availableData: storedData
2286
- });
2287
- }
2288
- } catch (error) {
2289
- debug4("Context store operation failed:", error);
2290
- }
2291
- }
2292
2177
  const cacheable = opt?.cacheable;
2293
2178
  const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
2294
- let contextData;
2295
- if (this.opts.enableCumulativeContext && this.contextStore) {
2296
- try {
2297
- contextData = this.contextStore.getAllData();
2298
- if (contextData && Object.keys(contextData).length === 0) {
2299
- contextData = void 0;
2300
- }
2301
- } catch (error) {
2302
- debug4("Failed to get context data for cache:", error);
2303
- }
2304
- }
2305
- const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt, contextData);
2179
+ const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
2306
2180
  if (matchedCache && this.taskCache?.isCacheResultUsed) {
2307
2181
  const { executor: executor2 } = await this.taskExecutor.loadYamlFlowAsPlanning(
2308
2182
  taskPrompt,
@@ -2312,28 +2186,6 @@ var PageAgent = class {
2312
2186
  debug4("matched cache, will call .runYaml to run the action");
2313
2187
  const yaml5 = matchedCache.cacheContent?.yamlWorkflow;
2314
2188
  const result = await this.runYaml(yaml5);
2315
- if (this.opts.enableCumulativeContext && this.contextStore) {
2316
- try {
2317
- const executionResult = {
2318
- success: true,
2319
- actionType: "cached",
2320
- description: `Executed cached action: ${processedPrompt}`,
2321
- timing: result.metadata?.totalTime
2322
- };
2323
- this.contextStore.addStep({
2324
- type: "action",
2325
- summary: `Action: ${processedPrompt} (cached)`,
2326
- prompt: processedPrompt,
2327
- executionResult
2328
- });
2329
- debug4("Added cached action step to context store:", {
2330
- stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2331
- totalSteps: this.contextStore.getRecentSteps(100).length
2332
- });
2333
- } catch (error) {
2334
- debug4("Failed to add cached action step:", error);
2335
- }
2336
- }
2337
2189
  return {
2338
2190
  result: result.result,
2339
2191
  metadata: metadata2
@@ -2358,114 +2210,17 @@ var PageAgent = class {
2358
2210
  prompt: taskPrompt,
2359
2211
  yamlWorkflow: yamlFlowStr
2360
2212
  },
2361
- matchedCache,
2362
- contextData
2363
- // Pass context data for cache creation
2213
+ matchedCache
2364
2214
  );
2365
2215
  }
2366
2216
  const metadata = this.afterTaskRunning(executor);
2367
- if (this.opts.enableCumulativeContext && this.contextStore) {
2368
- try {
2369
- const executionResult = this.analyzeExecutionResults(executor, originalPrompt);
2370
- this.contextStore.addStep({
2371
- type: "action",
2372
- summary: `Action: ${processedPrompt}`,
2373
- prompt: processedPrompt,
2374
- executionResult
2375
- });
2376
- debug4("Added action step with execution result to context store:", {
2377
- stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2378
- totalSteps: this.contextStore.getRecentSteps(100).length,
2379
- executionResult
2380
- });
2381
- } catch (error) {
2382
- debug4("Failed to analyze execution results, adding step without execution result:", error);
2383
- try {
2384
- this.contextStore.addStep({
2385
- type: "action",
2386
- summary: `Action: ${processedPrompt}`,
2387
- prompt: processedPrompt
2388
- });
2389
- } catch (stepError) {
2390
- debug4("Failed to add action step:", stepError);
2391
- }
2392
- }
2393
- }
2394
2217
  return {
2395
2218
  result: output,
2396
2219
  metadata
2397
2220
  };
2398
2221
  }
2399
2222
  async aiQuery(demand) {
2400
- let processedDemand = demand;
2401
- let storageKey;
2402
- try {
2403
- const aiModel = await import("misoai-core/ai-model");
2404
- const contextStore = aiModel.getContextStore();
2405
- if (typeof demand === "string") {
2406
- const storageInstruction = contextStore.parseStorageInstruction(demand);
2407
- if (storageInstruction) {
2408
- storageKey = storageInstruction.key;
2409
- processedDemand = storageInstruction.cleanText;
2410
- contextStore._pendingAliases = storageInstruction.aliases;
2411
- } else {
2412
- const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
2413
- if (storageMatch) {
2414
- storageKey = storageMatch[1];
2415
- processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
2416
- }
2417
- }
2418
- }
2419
- } catch (error) {
2420
- debug4("Context store not available:", error);
2421
- }
2422
- const { output, executor } = await this.taskExecutor.query(processedDemand);
2423
- if (this.opts.enableCumulativeContext && this.contextStore) {
2424
- if (storageKey && output) {
2425
- try {
2426
- const pendingAliases = this.contextStore._pendingAliases;
2427
- if (pendingAliases) {
2428
- this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2429
- delete this.contextStore._pendingAliases;
2430
- debug4("Stored query result with aliases:", {
2431
- key: storageKey,
2432
- value: output,
2433
- aliases: pendingAliases
2434
- });
2435
- } else {
2436
- this.contextStore.storeData(storageKey, output);
2437
- debug4("Stored query result:", {
2438
- key: storageKey,
2439
- value: output
2440
- });
2441
- }
2442
- this.contextStore.addStep({
2443
- type: "query",
2444
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2445
- data: output,
2446
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2447
- });
2448
- debug4("Added query step to context store:", {
2449
- storageKey,
2450
- totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
2451
- totalSteps: this.contextStore.getRecentSteps(100).length
2452
- });
2453
- } catch (error) {
2454
- debug4("Failed to store query result:", error);
2455
- }
2456
- } else {
2457
- try {
2458
- this.contextStore.addStep({
2459
- type: "query",
2460
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2461
- data: output,
2462
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2463
- });
2464
- } catch (error) {
2465
- debug4("Failed to add query step:", error);
2466
- }
2467
- }
2468
- }
2223
+ const { output, executor } = await this.taskExecutor.query(demand);
2469
2224
  const metadata = this.afterTaskRunning(executor);
2470
2225
  return {
2471
2226
  result: output,
@@ -2575,48 +2330,6 @@ var PageAgent = class {
2575
2330
  };
2576
2331
  }
2577
2332
  async aiAssert(assertion, msg, opt) {
2578
- let executionContext = "";
2579
- if (this.opts.enableCumulativeContext && this.contextStore) {
2580
- try {
2581
- const recentSteps = this.contextStore.getRecentSteps(3);
2582
- const stepsWithExecutionResults = recentSteps.filter((step) => step.executionResult);
2583
- const storedData = this.contextStore.getAllData();
2584
- if (stepsWithExecutionResults.length > 0) {
2585
- const recentActions = stepsWithExecutionResults.map((step) => {
2586
- const result = step.executionResult;
2587
- return `- ${result.description}${result.success ? "" : " (FAILED)"}`;
2588
- }).join("\n");
2589
- executionContext = `
2590
-
2591
- Recent actions performed:
2592
- ${recentActions}
2593
-
2594
- This context may help verify the assertion.`;
2595
- }
2596
- if (storedData && Object.keys(storedData).length > 0) {
2597
- executionContext += `
2598
-
2599
- Available data for reference:
2600
- ${JSON.stringify(storedData, null, 2)}
2601
-
2602
- Note: If the assertion references any data keys or natural language equivalents, consider the stored values when verifying.`;
2603
- debug4("Available data for aiAssert:", {
2604
- assertion,
2605
- availableData: storedData
2606
- });
2607
- }
2608
- this.contextStore.addStep({
2609
- type: "assertion",
2610
- summary: `Assertion: ${assertion}`,
2611
- prompt: assertion
2612
- });
2613
- debug4("Added assertion step to context store:", {
2614
- totalSteps: this.contextStore.getRecentSteps(100).length
2615
- });
2616
- } catch (error) {
2617
- debug4("Context store operation failed:", error);
2618
- }
2619
- }
2620
2333
  let currentUrl = "";
2621
2334
  if (this.page.url) {
2622
2335
  try {
@@ -2624,13 +2337,7 @@ Note: If the assertion references any data keys or natural language equivalents,
2624
2337
  } catch (e) {
2625
2338
  }
2626
2339
  }
2627
- let assertionWithContext = assertion;
2628
- if (currentUrl) {
2629
- assertionWithContext = `For the page at URL "${currentUrl}", ${assertion}`;
2630
- }
2631
- if (executionContext) {
2632
- assertionWithContext += executionContext;
2633
- }
2340
+ const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
2634
2341
  const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
2635
2342
  const metadata = this.afterTaskRunning(executor, true);
2636
2343
  if (output && opt?.keepRawResponse) {
@@ -2844,79 +2551,6 @@ ${errors}`);
2844
2551
  async destroy() {
2845
2552
  await this.page.destroy();
2846
2553
  }
2847
- /**
2848
- * Analyze execution results from executor to generate meaningful descriptions
2849
- */
2850
- analyzeExecutionResults(executor, originalPrompt) {
2851
- const tasks = executor.tasks;
2852
- const success = !executor.isInErrorState();
2853
- if (!success) {
2854
- const errorTask = executor.latestErrorTask();
2855
- return {
2856
- success: false,
2857
- actionType: "error",
2858
- description: `Failed to execute: ${originalPrompt}`,
2859
- error: errorTask?.error
2860
- };
2861
- }
2862
- const actionTasks = tasks.filter((t) => t.type === "Action" && t.status === "finished");
2863
- const locateTasks = tasks.filter((t) => t.type === "Insight" && t.subType === "Locate");
2864
- const lastAction = actionTasks[actionTasks.length - 1];
2865
- const lastLocate = locateTasks[locateTasks.length - 1];
2866
- if (!lastAction) {
2867
- return {
2868
- success: true,
2869
- actionType: "unknown",
2870
- description: `Completed: ${originalPrompt}`
2871
- };
2872
- }
2873
- const actionType = lastAction.subType || "unknown";
2874
- const elementInfo = this.extractElementInfo(lastLocate, lastAction);
2875
- const description = this.generateActionDescription(actionType, lastAction.param, elementInfo);
2876
- return {
2877
- success: true,
2878
- actionType,
2879
- description,
2880
- elementInfo,
2881
- timing: lastAction.timing?.cost
2882
- };
2883
- }
2884
- /**
2885
- * Extract element information from locate task
2886
- */
2887
- extractElementInfo(locateTask, _actionTask) {
2888
- if (!locateTask?.output?.element)
2889
- return void 0;
2890
- const element = locateTask.output.element;
2891
- return {
2892
- type: element.attributes?.nodeType || "unknown",
2893
- text: element.content || element.attributes?.placeholder || element.attributes?.title || "",
2894
- location: `(${element.center[0]}, ${element.center[1]})`
2895
- };
2896
- }
2897
- /**
2898
- * Generate natural language description for actions
2899
- */
2900
- generateActionDescription(actionType, param, elementInfo) {
2901
- const elementDesc = elementInfo ? `'${elementInfo.text || elementInfo.type}' element` : "element";
2902
- switch (actionType) {
2903
- case "Tap":
2904
- return `Clicked on ${elementDesc}`;
2905
- case "Input":
2906
- const inputValue = param?.value || "";
2907
- return `Entered "${inputValue}" into ${elementDesc}`;
2908
- case "KeyboardPress":
2909
- return `Pressed ${param?.value || "key"}`;
2910
- case "Scroll":
2911
- return `Scrolled ${param?.direction || "on page"}`;
2912
- case "Hover":
2913
- return `Hovered over ${elementDesc}`;
2914
- case "Drag":
2915
- return `Dragged ${elementDesc}`;
2916
- default:
2917
- return `Performed ${actionType} action on ${elementDesc}`;
2918
- }
2919
- }
2920
2554
  };
2921
2555
 
2922
2556
  // src/chrome-extension/agent.ts
@@ -3134,7 +2768,7 @@ function sleep2(ms) {
3134
2768
  var ChromeExtensionProxyPage = class {
3135
2769
  constructor(forceSameTabNavigation) {
3136
2770
  this.pageType = "chrome-extension-proxy";
3137
- this.version = "1.0.5";
2771
+ this.version = "1.5.6";
3138
2772
  this.activeTabId = null;
3139
2773
  this.tabIdOfDebuggerAttached = null;
3140
2774
  this.attachingDebugger = null;