misoai-web 1.0.5 → 1.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +9 -353
  3. package/bin/midscene-playground +2 -2
  4. package/dist/es/agent.js +9 -191
  5. package/dist/es/agent.js.map +1 -1
  6. package/dist/es/bridge-mode-browser.js +3 -3
  7. package/dist/es/bridge-mode-browser.js.map +1 -1
  8. package/dist/es/bridge-mode.js +11 -193
  9. package/dist/es/bridge-mode.js.map +1 -1
  10. package/dist/es/chrome-extension.js +10 -192
  11. package/dist/es/chrome-extension.js.map +1 -1
  12. package/dist/es/index.js +13 -195
  13. package/dist/es/index.js.map +1 -1
  14. package/dist/es/midscene-playground.js +9 -191
  15. package/dist/es/midscene-playground.js.map +1 -1
  16. package/dist/es/midscene-server.js.map +1 -1
  17. package/dist/es/playground.js +9 -191
  18. package/dist/es/playground.js.map +1 -1
  19. package/dist/es/playwright-report.js.map +1 -1
  20. package/dist/es/playwright.js +10 -192
  21. package/dist/es/playwright.js.map +1 -1
  22. package/dist/es/puppeteer-agent-launcher.js +13 -195
  23. package/dist/es/puppeteer-agent-launcher.js.map +1 -1
  24. package/dist/es/puppeteer.js +13 -195
  25. package/dist/es/puppeteer.js.map +1 -1
  26. package/dist/es/ui-utils.js.map +1 -1
  27. package/dist/es/utils.js.map +1 -1
  28. package/dist/es/yaml.js +5 -3
  29. package/dist/es/yaml.js.map +1 -1
  30. package/dist/lib/agent.js +9 -191
  31. package/dist/lib/agent.js.map +1 -1
  32. package/dist/lib/bridge-mode-browser.js +3 -3
  33. package/dist/lib/bridge-mode-browser.js.map +1 -1
  34. package/dist/lib/bridge-mode.js +11 -193
  35. package/dist/lib/bridge-mode.js.map +1 -1
  36. package/dist/lib/chrome-extension.js +10 -192
  37. package/dist/lib/chrome-extension.js.map +1 -1
  38. package/dist/lib/index.js +13 -195
  39. package/dist/lib/index.js.map +1 -1
  40. package/dist/lib/midscene-playground.js +9 -191
  41. package/dist/lib/midscene-playground.js.map +1 -1
  42. package/dist/lib/midscene-server.js.map +1 -1
  43. package/dist/lib/playground.js +9 -191
  44. package/dist/lib/playground.js.map +1 -1
  45. package/dist/lib/playwright-report.js.map +1 -1
  46. package/dist/lib/playwright.js +10 -192
  47. package/dist/lib/playwright.js.map +1 -1
  48. package/dist/lib/puppeteer-agent-launcher.js +13 -195
  49. package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
  50. package/dist/lib/puppeteer.js +13 -195
  51. package/dist/lib/puppeteer.js.map +1 -1
  52. package/dist/lib/ui-utils.js.map +1 -1
  53. package/dist/lib/utils.js.map +1 -1
  54. package/dist/lib/yaml.js +5 -3
  55. package/dist/lib/yaml.js.map +1 -1
  56. package/dist/types/agent.d.ts +1 -27
  57. package/dist/types/bridge-mode-browser.d.ts +2 -2
  58. package/dist/types/bridge-mode.d.ts +2 -2
  59. package/dist/types/{browser-a1877d18.d.ts → browser-aec1055d.d.ts} +1 -1
  60. package/dist/types/chrome-extension.d.ts +2 -2
  61. package/dist/types/index.d.ts +1 -1
  62. package/dist/types/midscene-server.d.ts +1 -1
  63. package/dist/types/{page-663ece08.d.ts → page-86ab0fe1.d.ts} +34 -34
  64. package/dist/types/playground.d.ts +2 -2
  65. package/dist/types/playwright.d.ts +1 -1
  66. package/dist/types/puppeteer-agent-launcher.d.ts +1 -1
  67. package/dist/types/puppeteer.d.ts +1 -1
  68. package/dist/types/utils.d.ts +1 -1
  69. package/dist/types/yaml.d.ts +1 -1
  70. package/iife-script/htmlElement.js +2 -2
  71. package/iife-script/htmlElementDebug.js +2 -2
  72. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQA,sBAAiD;AACjD,mBAAuC;AACvC,iBAAsD;AAEtD,uBAKO;AACP,iBAAgC;AAEhC,IAAAA,gBAAqC;A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,MAAM,QAAoB;AACxB,iBAAa,KAAK,IAAK;AAEvB,WAAO,qBAAqB,OAAO,MAAM,EAAE;AAAA,EAC7C;AACF;AAEA,IAAO,mBAAQ","names":["import_utils","dayjs"],"ignoreList":[],"sources":["../../src/playwright/reporter/index.ts","../../src/common/utils.ts"],"sourcesContent":["import {\r\n printReportMsg,\r\n replaceIllegalPathCharsAndSpace,\r\n reportFileName,\r\n} from '@/common/utils';\r\nimport type { ReportDumpWithAttributes } from 'misoai-core';\r\nimport { writeDumpReport } from 'misoai-core/utils';\r\nimport type {\r\n FullConfig,\r\n FullResult,\r\n Reporter,\r\n Suite,\r\n TestCase,\r\n TestResult,\r\n} from '@playwright/test/reporter';\r\n\r\nfunction logger(...message: any[]) {\r\n if (process.env.DEBUG === 'true') {\r\n console.log('Midscene e2e report:', ...message);\r\n }\r\n}\r\n\r\nconst testDataList: Array<ReportDumpWithAttributes> = [];\r\nlet mergedFilename: string;\r\nconst testTitleToFilename: Map<string, string> = new Map();\r\n\r\nfunction getStableFilename(testTitle: string): string {\r\n if (!testTitleToFilename.has(testTitle)) {\r\n // use reportFileName to generate the base filename\r\n // only replace the illegal characters in the file system: /, \\, :, *, ?, \", <, >, |\r\n const baseTag = `playwright-${replaceIllegalPathCharsAndSpace(testTitle)}`;\r\n const generatedFilename = reportFileName(baseTag);\r\n testTitleToFilename.set(testTitle, generatedFilename);\r\n }\r\n return testTitleToFilename.get(testTitle)!;\r\n}\r\n\r\nfunction updateReport(mode: 'merged' | 'separate', testId?: string) {\r\n if (mode === 'separate') {\r\n // in separate mode, find the data for the corresponding testID and generate a separate report\r\n const testData = testDataList.find(\r\n (data) => data.attributes?.playwright_test_id === testId,\r\n );\r\n\r\n if (testData) {\r\n // use the stable filename\r\n const stableFilename = getStableFilename(\r\n testData.attributes?.playwright_test_title,\r\n );\r\n\r\n const reportPath = writeDumpReport(stableFilename, [testData]);\r\n reportPath && printReportMsg(reportPath);\r\n }\r\n } else if (mode === 'merged') {\r\n // in merged mode, write all test data into one file\r\n if (!mergedFilename) {\r\n mergedFilename = reportFileName('playwright-merged');\r\n }\r\n\r\n const reportPath = writeDumpReport(mergedFilename, testDataList);\r\n reportPath && printReportMsg(reportPath);\r\n } else {\r\n throw new Error(\r\n `Unknown reporter type in playwright config: ${mode}, only support 'merged' or 'separate'`,\r\n );\r\n }\r\n}\r\n\r\nfunction getMode(reporterType: string) {\r\n if (!reporterType) {\r\n return 'merged';\r\n }\r\n\r\n if (reporterType !== 'merged' && reporterType !== 'separate') {\r\n throw new Error(\r\n `Unknown reporter type in playwright config: ${reporterType}, only support 'merged' or 'separate'`,\r\n );\r\n }\r\n\r\n return reporterType;\r\n}\r\n\r\nclass MidsceneReporter implements Reporter {\r\n mode?: 'merged' | 'separate';\r\n\r\n async onBegin(config: FullConfig, suite: Suite) {\r\n const reporterType = config.reporter?.[1]?.[1]?.type;\r\n\r\n this.mode = getMode(reporterType);\r\n\r\n // const suites = suite.allTests();\r\n // logger(`Starting the run with ${suites.length} tests`);\r\n }\r\n\r\n onTestBegin(test: TestCase, _result: TestResult) {\r\n // logger(`Starting test ${test.title}`);\r\n }\r\n\r\n onTestEnd(test: TestCase, result: TestResult) {\r\n const dumpAnnotation = test.annotations.find((annotation) => {\r\n return annotation.type === 'MIDSCENE_DUMP_ANNOTATION';\r\n });\r\n if (!dumpAnnotation?.description) return;\r\n const retry = result.retry ? `(retry #${result.retry})` : '';\r\n const testId = `${test.id}${retry}`;\r\n const testData: ReportDumpWithAttributes = {\r\n dumpString: dumpAnnotation.description,\r\n attributes: {\r\n playwright_test_id: testId,\r\n playwright_test_title: `${test.title}${retry}`,\r\n playwright_test_status: result.status,\r\n playwright_test_duration: result.duration,\r\n },\r\n };\r\n\r\n testDataList.push(testData);\r\n\r\n updateReport(this.mode!, testId);\r\n\r\n test.annotations = test.annotations.filter(\r\n (annotation) => annotation.type !== 'MIDSCENE_DUMP_ANNOTATION',\r\n );\r\n }\r\n\r\n onEnd(result: FullResult) {\r\n updateReport(this.mode!);\r\n\r\n logger(`Finished the run: ${result.status}`);\r\n }\r\n}\r\n\r\nexport default MidsceneReporter;\r\n","import type { StaticPage } from '@/playground';\r\nimport type {\r\n BaseElement,\r\n ElementTreeNode,\r\n PlanningLocateParam,\r\n PlaywrightParserOpt,\r\n UIContext,\r\n} from 'misoai-core';\r\nimport { elementByPositionWithElementInfo } from 'misoai-core/ai-model';\r\nimport { uploadTestInfoToServer } from 'misoai-core/utils';\r\nimport { MIDSCENE_REPORT_TAG_NAME, getAIConfig } from 'misoai-shared/env';\r\nimport type { ElementInfo } from 'misoai-shared/extractor';\r\nimport {\r\n generateElementByPosition,\r\n getNodeFromCacheList,\r\n traverseTree,\r\n treeToList,\r\n} from 'misoai-shared/extractor';\r\nimport { resizeImgBase64 } from 'misoai-shared/img';\r\nimport type { DebugFunction } from 'misoai-shared/logger';\r\nimport { assert, logMsg, uuid } from 'misoai-shared/utils';\r\nimport dayjs from 'dayjs';\r\nimport type { Page as PlaywrightPage } from 'playwright';\r\nimport type { Page as PuppeteerPage } from 'puppeteer';\r\nimport { WebElementInfo } from '../web-element';\r\nimport type { WebPage } from './page';\r\n\r\nexport type WebUIContext = UIContext<WebElementInfo> & {\r\n url: string;\r\n};\r\n\r\nexport async function parseContextFromWebPage(\r\n page: WebPage,\r\n _opt?: PlaywrightParserOpt,\r\n): Promise<WebUIContext> {\r\n assert(page, 'page is required');\r\n if ((page as StaticPage)._forceUsePageContext) {\r\n return await (page as any)._forceUsePageContext();\r\n }\r\n const url = await page.url();\r\n uploadTestInfoToServer({ testUrl: url });\r\n\r\n let screenshotBase64: string;\r\n let tree: ElementTreeNode<ElementInfo>;\r\n\r\n await Promise.all([\r\n page.screenshotBase64().then((base64) => {\r\n screenshotBase64 = base64;\r\n }),\r\n page.getElementsNodeTree().then(async (treeRoot) => {\r\n tree = treeRoot;\r\n }),\r\n ]);\r\n\r\n const webTree = traverseTree(tree!, (elementInfo) => {\r\n const { rect, id, content, attributes, locator, indexId } = elementInfo;\r\n return new WebElementInfo({\r\n rect,\r\n locator,\r\n id,\r\n content,\r\n attributes,\r\n indexId,\r\n });\r\n });\r\n\r\n assert(screenshotBase64!, 'screenshotBase64 is required');\r\n\r\n const elementsInfo = treeToList(webTree);\r\n const size = await page.size();\r\n\r\n if (size.dpr && size.dpr > 1) {\r\n // console.time('resizeImgBase64');\r\n screenshotBase64 = await resizeImgBase64(screenshotBase64, {\r\n width: size.width,\r\n height: size.height,\r\n });\r\n // console.timeEnd('resizeImgBase64');\r\n }\r\n\r\n return {\r\n content: elementsInfo!,\r\n tree: webTree,\r\n size,\r\n screenshotBase64: screenshotBase64!,\r\n url,\r\n };\r\n}\r\n\r\nexport function reportFileName(tag = 'web') {\r\n const reportTagName = getAIConfig(MIDSCENE_REPORT_TAG_NAME);\r\n const dateTimeInFileName = dayjs().format('YYYY-MM-DD_HH-mm-ss');\r\n // ensure uniqueness at the same time\r\n const uniqueId = uuid().substring(0, 8);\r\n return `${reportTagName || tag}-${dateTimeInFileName}-${uniqueId}`;\r\n}\r\n\r\nexport function printReportMsg(filepath: string) {\r\n logMsg(`Midscene - report file updated: ${filepath}`);\r\n}\r\n\r\n/**\r\n * Get the current execution file name\r\n * @returns The name of the current execution file\r\n */\r\nexport function getCurrentExecutionFile(trace?: string): string | false {\r\n const error = new Error();\r\n const stackTrace = trace || error.stack;\r\n const pkgDir = process.cwd() || '';\r\n if (stackTrace) {\r\n const stackLines = stackTrace.split('\\n');\r\n for (const line of stackLines) {\r\n if (\r\n line.includes('.spec.') ||\r\n line.includes('.test.') ||\r\n line.includes('.ts') ||\r\n line.includes('.js')\r\n ) {\r\n const match = line.match(/(?:at\\s+)?(.*?\\.(?:spec|test)\\.[jt]s)/);\r\n if (match?.[1]) {\r\n const targetFileName = match[1]\r\n .replace(pkgDir, '')\r\n .trim()\r\n .replace('at ', '');\r\n return targetFileName;\r\n }\r\n }\r\n }\r\n }\r\n return false;\r\n}\r\n\r\nconst testFileIndex = new Map<string, number>();\r\n\r\nexport function generateCacheId(fileName?: string): string {\r\n let taskFile = fileName || getCurrentExecutionFile();\r\n if (!taskFile) {\r\n taskFile = uuid();\r\n console.warn(\r\n 'Midscene - using random UUID for cache id. Cache may be invalid.',\r\n );\r\n }\r\n\r\n if (testFileIndex.has(taskFile)) {\r\n const currentIndex = testFileIndex.get(taskFile);\r\n if (currentIndex !== undefined) {\r\n testFileIndex.set(taskFile, currentIndex + 1);\r\n }\r\n } else {\r\n testFileIndex.set(taskFile, 1);\r\n }\r\n return `${taskFile}-${testFileIndex.get(taskFile)}`;\r\n}\r\n\r\nexport const ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED =\r\n 'NOT_IMPLEMENTED_AS_DESIGNED';\r\n\r\nexport function replaceIllegalPathCharsAndSpace(str: string) {\r\n return str.replace(/[/\\\\:*?\"<>| ]/g, '-');\r\n}\r\n\r\nexport function forceClosePopup(\r\n page: PuppeteerPage | PlaywrightPage,\r\n debug: DebugFunction,\r\n) {\r\n page.on('popup', async (popup) => {\r\n if (!popup) {\r\n console.warn('got a popup event, but the popup is not ready yet, skip');\r\n return;\r\n }\r\n const url = await (popup as PuppeteerPage).url();\r\n console.log(`Popup opened: ${url}`);\r\n if (!(popup as PuppeteerPage).isClosed()) {\r\n try {\r\n await (popup as PuppeteerPage).close(); // Close the newly opened TAB\r\n } catch (error) {\r\n debug(`failed to close popup ${url}, error: ${error}`);\r\n }\r\n } else {\r\n debug(`popup is already closed, skip close ${url}`);\r\n }\r\n\r\n if (!page.isClosed()) {\r\n try {\r\n await page.goto(url);\r\n } catch (error) {\r\n debug(`failed to goto ${url}, error: ${error}`);\r\n }\r\n } else {\r\n debug(`page is already closed, skip goto ${url}`);\r\n }\r\n });\r\n}\r\n\r\nexport function matchElementFromPlan(\r\n planLocateParam: PlanningLocateParam,\r\n tree: ElementTreeNode<BaseElement>,\r\n) {\r\n if (!planLocateParam) {\r\n return undefined;\r\n }\r\n if (planLocateParam.id) {\r\n return getNodeFromCacheList(planLocateParam.id);\r\n }\r\n\r\n if (planLocateParam.bbox) {\r\n const centerPosition = {\r\n x: Math.floor((planLocateParam.bbox[0] + planLocateParam.bbox[2]) / 2),\r\n y: Math.floor((planLocateParam.bbox[1] + planLocateParam.bbox[3]) / 2),\r\n };\r\n let element = elementByPositionWithElementInfo(tree, centerPosition);\r\n\r\n if (!element) {\r\n element = generateElementByPosition(centerPosition) as BaseElement;\r\n }\r\n\r\n return element;\r\n }\r\n\r\n return undefined;\r\n}\r\n"]}
1
+ {"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQA,sBAAiD;AACjD,mBAAuC;AACvC,iBAAsD;AAEtD,uBAKO;AACP,iBAAgC;AAEhC,IAAAA,gBAAqC;AACrC,mBAAkB;AAoEX,SAAS,eAAe,MAAM,OAAO;AAC1C,QAAM,oBAAgB,wBAAY,mCAAwB;AAC1D,QAAM,yBAAqB,aAAAC,SAAM,EAAE,OAAO,qBAAqB;AAE/D,QAAM,eAAW,oBAAK,EAAE,UAAU,GAAG,CAAC;AACtC,SAAO,GAAG,iBAAiB,GAAG,IAAI,kBAAkB,IAAI,QAAQ;AAClE;AAEO,SAAS,eAAe,UAAkB;AAC/C,4BAAO,mCAAmC,QAAQ,EAAE;AACtD;AA0DO,SAAS,gCAAgC,KAAa;AAC3D,SAAO,IAAI,QAAQ,kBAAkB,GAAG;AAC1C;;;ADzJA,IAAAD,gBAAgC;AAUhC,SAAS,UAAU,SAAgB;AACjC,MAAI,QAAQ,IAAI,UAAU,QAAQ;AAChC,YAAQ,IAAI,wBAAwB,GAAG,OAAO;AAAA,EAChD;AACF;AAEA,IAAM,eAAgD,CAAC;AACvD,IAAI;AACJ,IAAM,sBAA2C,oBAAI,IAAI;AAEzD,SAAS,kBAAkB,WAA2B;AACpD,MAAI,CAAC,oBAAoB,IAAI,SAAS,GAAG;AAGvC,UAAM,UAAU,cAAc,gCAAgC,SAAS,CAAC;AACxE,UAAM,oB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;AAAa;AAClC,UAAM,QAAQ,OAAO,QAAQ,WAAW,OAAO,KAAK,MAAM;AAC1D,UAAM,SAAS,GAAG,KAAK,EAAE,GAAG,KAAK;AACjC,UAAM,WAAqC;AAAA,MACzC,YAAY,eAAe;AAAA,MAC3B,YAAY;AAAA,QACV,oBAAoB;AAAA,QACpB,uBAAuB,GAAG,KAAK,KAAK,GAAG,KAAK;AAAA,QAC5C,wBAAwB,OAAO;AAAA,QAC/B,0BAA0B,OAAO;AAAA,MACnC;AAAA,IACF;AAEA,iBAAa,KAAK,QAAQ;AAE1B,iBAAa,KAAK,MAAO,MAAM;AAE/B,SAAK,cAAc,KAAK,YAAY;AAAA,MAClC,CAAC,eAAe,WAAW,SAAS;AAAA,IACtC;AAAA,EACF;AAAA,EAEA,MAAM,QAAoB;AACxB,iBAAa,KAAK,IAAK;AAEvB,WAAO,qBAAqB,OAAO,MAAM,EAAE;AAAA,EAC7C;AACF;AAEA,IAAO,mBAAQ","names":["import_utils","dayjs"],"ignoreList":[],"sources":["../../src/playwright/reporter/index.ts","../../src/common/utils.ts"],"sourcesContent":["import {\n printReportMsg,\n replaceIllegalPathCharsAndSpace,\n reportFileName,\n} from '@/common/utils';\nimport type { ReportDumpWithAttributes } from 'misoai-core';\nimport { writeDumpReport } from 'misoai-core/utils';\nimport type {\n FullConfig,\n FullResult,\n Reporter,\n Suite,\n TestCase,\n TestResult,\n} from '@playwright/test/reporter';\n\nfunction logger(...message: any[]) {\n if (process.env.DEBUG === 'true') {\n console.log('Midscene e2e report:', ...message);\n }\n}\n\nconst testDataList: Array<ReportDumpWithAttributes> = [];\nlet mergedFilename: string;\nconst testTitleToFilename: Map<string, string> = new Map();\n\nfunction getStableFilename(testTitle: string): string {\n if (!testTitleToFilename.has(testTitle)) {\n // use reportFileName to generate the base filename\n // only replace the illegal characters in the file system: /, \\, :, *, ?, \", <, >, |\n const baseTag = `playwright-${replaceIllegalPathCharsAndSpace(testTitle)}`;\n const generatedFilename = reportFileName(baseTag);\n testTitleToFilename.set(testTitle, generatedFilename);\n }\n return testTitleToFilename.get(testTitle)!;\n}\n\nfunction updateReport(mode: 'merged' | 'separate', testId?: string) {\n if (mode === 'separate') {\n // in separate mode, find the data for the corresponding testID and generate a separate report\n const testData = testDataList.find(\n (data) => data.attributes?.playwright_test_id === testId,\n );\n\n if (testData) {\n // use the stable filename\n const stableFilename = getStableFilename(\n testData.attributes?.playwright_test_title,\n );\n\n const reportPath = writeDumpReport(stableFilename, [testData]);\n reportPath && printReportMsg(reportPath);\n }\n } else if (mode === 'merged') {\n // in merged mode, write all test data into one file\n if (!mergedFilename) {\n mergedFilename = reportFileName('playwright-merged');\n }\n\n const reportPath = writeDumpReport(mergedFilename, testDataList);\n reportPath && printReportMsg(reportPath);\n } else {\n throw new Error(\n `Unknown reporter type in playwright config: ${mode}, only support 'merged' or 'separate'`,\n );\n }\n}\n\nfunction getMode(reporterType: string) {\n if (!reporterType) {\n return 'merged';\n }\n\n if (reporterType !== 'merged' && reporterType !== 'separate') {\n throw new Error(\n `Unknown reporter type in playwright config: ${reporterType}, only support 'merged' or 'separate'`,\n );\n }\n\n return reporterType;\n}\n\nclass MidsceneReporter implements Reporter {\n mode?: 'merged' | 'separate';\n\n async onBegin(config: FullConfig, suite: Suite) {\n const reporterType = config.reporter?.[1]?.[1]?.type;\n\n this.mode = getMode(reporterType);\n\n // const suites = suite.allTests();\n // logger(`Starting the run with ${suites.length} tests`);\n }\n\n onTestBegin(test: TestCase, _result: TestResult) {\n // logger(`Starting test ${test.title}`);\n }\n\n onTestEnd(test: TestCase, result: TestResult) {\n const dumpAnnotation = test.annotations.find((annotation) => {\n return annotation.type === 'MIDSCENE_DUMP_ANNOTATION';\n });\n if (!dumpAnnotation?.description) return;\n const retry = result.retry ? `(retry #${result.retry})` : '';\n const testId = `${test.id}${retry}`;\n const testData: ReportDumpWithAttributes = {\n dumpString: dumpAnnotation.description,\n attributes: {\n playwright_test_id: testId,\n playwright_test_title: `${test.title}${retry}`,\n playwright_test_status: result.status,\n playwright_test_duration: result.duration,\n },\n };\n\n testDataList.push(testData);\n\n updateReport(this.mode!, testId);\n\n test.annotations = test.annotations.filter(\n (annotation) => annotation.type !== 'MIDSCENE_DUMP_ANNOTATION',\n );\n }\n\n onEnd(result: FullResult) {\n updateReport(this.mode!);\n\n logger(`Finished the run: ${result.status}`);\n }\n}\n\nexport default MidsceneReporter;\n","import type { StaticPage } from '@/playground';\nimport type {\n BaseElement,\n ElementTreeNode,\n PlanningLocateParam,\n PlaywrightParserOpt,\n UIContext,\n} from 'misoai-core';\nimport { elementByPositionWithElementInfo } from 'misoai-core/ai-model';\nimport { uploadTestInfoToServer } from 'misoai-core/utils';\nimport { MIDSCENE_REPORT_TAG_NAME, getAIConfig } from 'misoai-shared/env';\nimport type { ElementInfo } from 'misoai-shared/extractor';\nimport {\n generateElementByPosition,\n getNodeFromCacheList,\n traverseTree,\n treeToList,\n} from 'misoai-shared/extractor';\nimport { resizeImgBase64 } from 'misoai-shared/img';\nimport type { DebugFunction } from 'misoai-shared/logger';\nimport { assert, logMsg, uuid } from 'misoai-shared/utils';\nimport dayjs from 'dayjs';\nimport type { Page as PlaywrightPage } from 'playwright';\nimport type { Page as PuppeteerPage } from 'puppeteer';\nimport { WebElementInfo } from '../web-element';\nimport type { WebPage } from './page';\n\nexport type WebUIContext = UIContext<WebElementInfo> & {\n url: string;\n};\n\nexport async function parseContextFromWebPage(\n page: WebPage,\n _opt?: PlaywrightParserOpt,\n): Promise<WebUIContext> {\n assert(page, 'page is required');\n if ((page as StaticPage)._forceUsePageContext) {\n return await (page as any)._forceUsePageContext();\n }\n const url = await page.url();\n uploadTestInfoToServer({ testUrl: url });\n\n let screenshotBase64: string;\n let tree: ElementTreeNode<ElementInfo>;\n\n await Promise.all([\n page.screenshotBase64().then((base64) => {\n screenshotBase64 = base64;\n }),\n page.getElementsNodeTree().then(async (treeRoot) => {\n tree = treeRoot;\n }),\n ]);\n\n const webTree = traverseTree(tree!, (elementInfo) => {\n const { rect, id, content, attributes, locator, indexId } = elementInfo;\n return new WebElementInfo({\n rect,\n locator,\n id,\n content,\n attributes,\n indexId,\n });\n });\n\n assert(screenshotBase64!, 'screenshotBase64 is required');\n\n const elementsInfo = treeToList(webTree);\n const size = await page.size();\n\n if (size.dpr && size.dpr > 1) {\n // console.time('resizeImgBase64');\n screenshotBase64 = await resizeImgBase64(screenshotBase64, {\n width: size.width,\n height: size.height,\n });\n // console.timeEnd('resizeImgBase64');\n }\n\n return {\n content: elementsInfo!,\n tree: webTree,\n size,\n screenshotBase64: screenshotBase64!,\n url,\n };\n}\n\nexport function reportFileName(tag = 'web') {\n const reportTagName = getAIConfig(MIDSCENE_REPORT_TAG_NAME);\n const dateTimeInFileName = dayjs().format('YYYY-MM-DD_HH-mm-ss');\n // ensure uniqueness at the same time\n const uniqueId = uuid().substring(0, 8);\n return `${reportTagName || tag}-${dateTimeInFileName}-${uniqueId}`;\n}\n\nexport function printReportMsg(filepath: string) {\n logMsg(`Midscene - report file updated: ${filepath}`);\n}\n\n/**\n * Get the current execution file name\n * @returns The name of the current execution file\n */\nexport function getCurrentExecutionFile(trace?: string): string | false {\n const error = new Error();\n const stackTrace = trace || error.stack;\n const pkgDir = process.cwd() || '';\n if (stackTrace) {\n const stackLines = stackTrace.split('\\n');\n for (const line of stackLines) {\n if (\n line.includes('.spec.') ||\n line.includes('.test.') ||\n line.includes('.ts') ||\n line.includes('.js')\n ) {\n const match = line.match(/(?:at\\s+)?(.*?\\.(?:spec|test)\\.[jt]s)/);\n if (match?.[1]) {\n const targetFileName = match[1]\n .replace(pkgDir, '')\n .trim()\n .replace('at ', '');\n return targetFileName;\n }\n }\n }\n }\n return false;\n}\n\nconst testFileIndex = new Map<string, number>();\n\nexport function generateCacheId(fileName?: string): string {\n let taskFile = fileName || getCurrentExecutionFile();\n if (!taskFile) {\n taskFile = uuid();\n console.warn(\n 'Midscene - using random UUID for cache id. Cache may be invalid.',\n );\n }\n\n if (testFileIndex.has(taskFile)) {\n const currentIndex = testFileIndex.get(taskFile);\n if (currentIndex !== undefined) {\n testFileIndex.set(taskFile, currentIndex + 1);\n }\n } else {\n testFileIndex.set(taskFile, 1);\n }\n return `${taskFile}-${testFileIndex.get(taskFile)}`;\n}\n\nexport const ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED =\n 'NOT_IMPLEMENTED_AS_DESIGNED';\n\nexport function replaceIllegalPathCharsAndSpace(str: string) {\n return str.replace(/[/\\\\:*?\"<>| ]/g, '-');\n}\n\nexport function forceClosePopup(\n page: PuppeteerPage | PlaywrightPage,\n debug: DebugFunction,\n) {\n page.on('popup', async (popup) => {\n if (!popup) {\n console.warn('got a popup event, but the popup is not ready yet, skip');\n return;\n }\n const url = await (popup as PuppeteerPage).url();\n console.log(`Popup opened: ${url}`);\n if (!(popup as PuppeteerPage).isClosed()) {\n try {\n await (popup as PuppeteerPage).close(); // Close the newly opened TAB\n } catch (error) {\n debug(`failed to close popup ${url}, error: ${error}`);\n }\n } else {\n debug(`popup is already closed, skip close ${url}`);\n }\n\n if (!page.isClosed()) {\n try {\n await page.goto(url);\n } catch (error) {\n debug(`failed to goto ${url}, error: ${error}`);\n }\n } else {\n debug(`page is already closed, skip goto ${url}`);\n }\n });\n}\n\nexport function matchElementFromPlan(\n planLocateParam: PlanningLocateParam,\n tree: ElementTreeNode<BaseElement>,\n) {\n if (!planLocateParam) {\n return undefined;\n }\n if (planLocateParam.id) {\n return getNodeFromCacheList(planLocateParam.id);\n }\n\n if (planLocateParam.bbox) {\n const centerPosition = {\n x: Math.floor((planLocateParam.bbox[0] + planLocateParam.bbox[2]) / 2),\n y: Math.floor((planLocateParam.bbox[1] + planLocateParam.bbox[3]) / 2),\n };\n let element = elementByPositionWithElementInfo(tree, centerPosition);\n\n if (!element) {\n element = generateElementByPosition(centerPosition) as BaseElement;\n }\n\n return element;\n }\n\n return undefined;\n}\n"]}
@@ -56,10 +56,11 @@ var ScriptPlayer = class {
56
56
  this.unnamedResultIndex = 0;
57
57
  this.pageAgent = null;
58
58
  this.result = {};
59
+ const target = script.target || script.web || script.android;
59
60
  if (import_utils.ifInBrowser) {
60
61
  this.output = void 0;
61
- } else if (script.target?.output) {
62
- this.output = (0, import_node_path.resolve)(process.cwd(), script.target.output);
62
+ } else if (target?.output) {
63
+ this.output = (0, import_node_path.resolve)(process.cwd(), target.output);
63
64
  } else {
64
65
  this.output = (0, import_node_path.join)((0, import_common.getMidsceneRunSubDir)("output"), `${process.pid}.json`);
65
66
  }
@@ -133,12 +134,13 @@ var ScriptPlayer = class {
133
134
  } else if ("aiAssert" in flowItem) {
134
135
  const assertTask = flowItem;
135
136
  const prompt = assertTask.aiAssert;
137
+ const msg = assertTask.errorMessage;
136
138
  (0, import_utils.assert)(prompt, "missing prompt for aiAssert");
137
139
  (0, import_utils.assert)(
138
140
  typeof prompt === "string",
139
141
  "prompt for aiAssert must be a string"
140
142
  );
141
- await agent.aiAssert(prompt);
143
+ await agent.aiAssert(prompt, msg);
142
144
  } else if ("aiQuery" in flowItem) {
143
145
  const queryTask = flowItem;
144
146
  const prompt = queryTask.aiQuery;
@@ -1707,7 +1709,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1707
1709
  var import_semver = __toESM(require("semver"));
1708
1710
 
1709
1711
  // package.json
1710
- var version = "1.0.5";
1712
+ var version = "1.5.6";
1711
1713
 
1712
1714
  // src/common/task-cache.ts
1713
1715
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -1889,13 +1891,10 @@ var PageAgent = class {
1889
1891
  generateReport: true,
1890
1892
  autoPrintReportMsg: true,
1891
1893
  groupName: "Midscene Report",
1892
- groupDescription: "",
1893
- enableCumulativeContext: true,
1894
- autoClearContext: false
1894
+ groupDescription: ""
1895
1895
  },
1896
1896
  opts || {}
1897
1897
  );
1898
- this.initializeContextStore();
1899
1898
  if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1900
1899
  this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || import_constants2.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
1901
1900
  this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || import_constants2.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
@@ -1922,69 +1921,6 @@ var PageAgent = class {
1922
1921
  opts?.testId || this.page.pageType || "web"
1923
1922
  );
1924
1923
  }
1925
- /**
1926
- * Initialize context store for cumulative context functionality
1927
- */
1928
- async initializeContextStore() {
1929
- if (!this.opts.enableCumulativeContext) {
1930
- debug4("Cumulative context disabled via options");
1931
- return;
1932
- }
1933
- try {
1934
- const aiModel = await import("misoai-core/ai-model");
1935
- this.contextStore = aiModel.getContextStore();
1936
- debug4("Context store initialized successfully", {
1937
- autoClearContext: this.opts.autoClearContext,
1938
- testId: this.opts.testId
1939
- });
1940
- if (this.opts.autoClearContext) {
1941
- this.contextStore.clear();
1942
- debug4("Context store cleared due to autoClearContext option");
1943
- } else {
1944
- const existingData = this.contextStore.getAllData();
1945
- const existingSteps = this.contextStore.getRecentSteps(100).length;
1946
- debug4("Context store preserving existing data", {
1947
- existingDataKeys: Object.keys(existingData),
1948
- existingStepsCount: existingSteps
1949
- });
1950
- }
1951
- } catch (error) {
1952
- debug4("Failed to initialize context store:", error);
1953
- console.warn("⚠️ Could not initialize context store:", error);
1954
- }
1955
- }
1956
- /**
1957
- * Get the context store instance
1958
- */
1959
- getContextStore() {
1960
- return this.contextStore;
1961
- }
1962
- /**
1963
- * Clear the context store
1964
- */
1965
- clearContext() {
1966
- if (this.contextStore) {
1967
- this.contextStore.clear();
1968
- }
1969
- }
1970
- /**
1971
- * Get all stored data from context store
1972
- */
1973
- getStoredData() {
1974
- if (this.contextStore) {
1975
- return this.contextStore.getAllData();
1976
- }
1977
- return {};
1978
- }
1979
- /**
1980
- * Get step summary from context store
1981
- */
1982
- getStepSummary() {
1983
- if (this.contextStore) {
1984
- return this.contextStore.getStepSummary();
1985
- }
1986
- return "";
1987
- }
1988
1924
  async getUIContext(action) {
1989
1925
  if (action && (action === "extract" || action === "assert" || action === "captcha")) {
1990
1926
  return await parseContextFromWebPage(this.page, {
@@ -2220,31 +2156,6 @@ var PageAgent = class {
2220
2156
  };
2221
2157
  }
2222
2158
  async aiAction(taskPrompt, opt) {
2223
- if (this.opts.enableCumulativeContext && this.contextStore) {
2224
- try {
2225
- const originalPrompt = taskPrompt;
2226
- const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
2227
- if (originalPrompt !== processedPrompt) {
2228
- debug4("Context replacement in aiAction:", {
2229
- original: originalPrompt,
2230
- processed: processedPrompt,
2231
- storedData: this.contextStore.getAllData()
2232
- });
2233
- }
2234
- this.contextStore.addStep({
2235
- type: "action",
2236
- summary: `Action: ${processedPrompt}`,
2237
- prompt: processedPrompt
2238
- });
2239
- debug4("Added action step to context store:", {
2240
- stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
2241
- totalSteps: this.contextStore.getRecentSteps(100).length
2242
- });
2243
- taskPrompt = processedPrompt;
2244
- } catch (error) {
2245
- debug4("Context store operation failed:", error);
2246
- }
2247
- }
2248
2159
  const cacheable = opt?.cacheable;
2249
2160
  const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
2250
2161
  const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
@@ -2291,75 +2202,7 @@ var PageAgent = class {
2291
2202
  };
2292
2203
  }
2293
2204
  async aiQuery(demand) {
2294
- let processedDemand = demand;
2295
- let storageKey;
2296
- try {
2297
- const aiModel = await import("misoai-core/ai-model");
2298
- const contextStore = aiModel.getContextStore();
2299
- if (typeof demand === "string") {
2300
- const storageInstruction = contextStore.parseStorageInstruction(demand);
2301
- if (storageInstruction) {
2302
- storageKey = storageInstruction.key;
2303
- processedDemand = storageInstruction.cleanText;
2304
- contextStore._pendingAliases = storageInstruction.aliases;
2305
- } else {
2306
- const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
2307
- if (storageMatch) {
2308
- storageKey = storageMatch[1];
2309
- processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
2310
- }
2311
- }
2312
- }
2313
- } catch (error) {
2314
- debug4("Context store not available:", error);
2315
- }
2316
- const { output, executor } = await this.taskExecutor.query(processedDemand);
2317
- if (this.opts.enableCumulativeContext && this.contextStore) {
2318
- if (storageKey && output) {
2319
- try {
2320
- const pendingAliases = this.contextStore._pendingAliases;
2321
- if (pendingAliases) {
2322
- this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
2323
- delete this.contextStore._pendingAliases;
2324
- debug4("Stored query result with aliases:", {
2325
- key: storageKey,
2326
- value: output,
2327
- aliases: pendingAliases
2328
- });
2329
- } else {
2330
- this.contextStore.storeData(storageKey, output);
2331
- debug4("Stored query result:", {
2332
- key: storageKey,
2333
- value: output
2334
- });
2335
- }
2336
- this.contextStore.addStep({
2337
- type: "query",
2338
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
2339
- data: output,
2340
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2341
- });
2342
- debug4("Added query step to context store:", {
2343
- storageKey,
2344
- totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
2345
- totalSteps: this.contextStore.getRecentSteps(100).length
2346
- });
2347
- } catch (error) {
2348
- debug4("Failed to store query result:", error);
2349
- }
2350
- } else {
2351
- try {
2352
- this.contextStore.addStep({
2353
- type: "query",
2354
- summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
2355
- data: output,
2356
- prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
2357
- });
2358
- } catch (error) {
2359
- debug4("Failed to add query step:", error);
2360
- }
2361
- }
2362
- }
2205
+ const { output, executor } = await this.taskExecutor.query(demand);
2363
2206
  const metadata = this.afterTaskRunning(executor);
2364
2207
  return {
2365
2208
  result: output,
@@ -2469,31 +2312,6 @@ var PageAgent = class {
2469
2312
  };
2470
2313
  }
2471
2314
  async aiAssert(assertion, msg, opt) {
2472
- let processedAssertion = assertion;
2473
- if (this.opts.enableCumulativeContext && this.contextStore) {
2474
- try {
2475
- const originalAssertion = assertion;
2476
- processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
2477
- if (originalAssertion !== processedAssertion) {
2478
- debug4("Context replacement in aiAssert:", {
2479
- original: originalAssertion,
2480
- processed: processedAssertion,
2481
- context: "assertion",
2482
- storedData: this.contextStore.getAllData()
2483
- });
2484
- }
2485
- this.contextStore.addStep({
2486
- type: "assertion",
2487
- summary: `Assertion: ${processedAssertion}`,
2488
- prompt: processedAssertion
2489
- });
2490
- debug4("Added assertion step to context store:", {
2491
- totalSteps: this.contextStore.getRecentSteps(100).length
2492
- });
2493
- } catch (error) {
2494
- debug4("Context store operation failed:", error);
2495
- }
2496
- }
2497
2315
  let currentUrl = "";
2498
2316
  if (this.page.url) {
2499
2317
  try {
@@ -2501,7 +2319,7 @@ var PageAgent = class {
2501
2319
  } catch (e) {
2502
2320
  }
2503
2321
  }
2504
- const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${processedAssertion}` : processedAssertion;
2322
+ const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
2505
2323
  const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
2506
2324
  const metadata = this.afterTaskRunning(executor, true);
2507
2325
  if (output && opt?.keepRawResponse) {
@@ -2730,7 +2548,7 @@ var Page = class {
2730
2548
  this.everMoved = false;
2731
2549
  this.underlyingPage = underlyingPage;
2732
2550
  this.pageType = pageType;
2733
- this.waitForNavigationTimeout = opts?.waitForNavigationTimeout || import_constants3.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
2551
+ this.waitForNavigationTimeout = opts?.waitForNavigationTimeout ?? import_constants3.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
2734
2552
  }
2735
2553
  async evaluate(pageFunction, arg) {
2736
2554
  let result;