@midscene/core 0.26.3-beta-20250813091321.0 → 0.26.3-beta-20250813105922.0
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.
- package/dist/es/ai-model.mjs.map +1 -1
- package/dist/es/index.mjs +1 -1
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/utils.mjs +2 -7
- package/dist/es/utils.mjs.map +1 -1
- package/dist/lib/ai-model.js.map +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/utils.js +2 -7
- package/dist/lib/utils.js.map +1 -1
- package/dist/types/ai-model.d.ts +5 -96
- package/dist/types/index.d.ts +26 -16
- package/package.json +3 -4
package/dist/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["webpack://@midscene/core/webpack/runtime/define_property_getters","webpack://@midscene/core/webpack/runtime/has_own_property","webpack://@midscene/core/webpack/runtime/make_namespace_object","webpack://@midscene/core/./src/utils.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { execSync } from 'node:child_process';\nimport * as fs from 'node:fs';\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport * as path from 'node:path';\nimport { dirname } from 'node:path';\nimport {\n defaultRunDirName,\n getMidsceneRunSubDir,\n} from '@midscene/shared/common';\nimport {\n MIDSCENE_DEBUG_MODE,\n MIDSCENE_OPENAI_INIT_CONFIG_JSON,\n getAIConfig,\n getAIConfigInJson,\n} from '@midscene/shared/env';\nimport { getRunningPkgInfo } from '@midscene/shared/node';\nimport { assert, logMsg } from '@midscene/shared/utils';\nimport {\n escapeScriptTag,\n ifInBrowser,\n ifInWorker,\n uuid,\n} from '@midscene/shared/utils';\nimport type { Rect, ReportDumpWithAttributes } from './types';\n\nlet logEnvReady = false;\n\nexport const groupedActionDumpFileExt = 'web-dump.json';\n\nconst reportInitializedMap = new Map<string, boolean>();\n\ndeclare const __DEV_REPORT_PATH__: string;\n\nfunction getReportTpl() {\n if (__DEV_REPORT_PATH__) {\n return fs.readFileSync(__DEV_REPORT_PATH__, 'utf-8');\n }\n const reportTpl = 'REPLACE_ME_WITH_REPORT_HTML';\n\n return reportTpl;\n}\n\n/**\n * high performance, insert script before </html> in HTML file\n * only truncate and append, no temporary file\n */\nexport function insertScriptBeforeClosingHtml(\n filePath: string,\n scriptContent: string,\n): void {\n const htmlEndTag = '</html>';\n const stat = fs.statSync(filePath);\n\n const readSize = Math.min(stat.size, 4096);\n const start = Math.max(0, stat.size - readSize);\n const buffer = Buffer.alloc(stat.size - start);\n const fd = fs.openSync(filePath, 'r');\n fs.readSync(fd, buffer, 0, buffer.length, start);\n fs.closeSync(fd);\n\n const tailStr = buffer.toString('utf8');\n const htmlEndIdx = tailStr.lastIndexOf(htmlEndTag);\n if (htmlEndIdx === -1) {\n throw new Error(`No </html> found in file:${filePath}`);\n }\n\n // calculate the correct byte position: char position to byte position\n const beforeHtmlInTail = tailStr.slice(0, htmlEndIdx);\n const htmlEndPos = start + Buffer.byteLength(beforeHtmlInTail, 'utf8');\n\n // truncate to </html> before\n fs.truncateSync(filePath, htmlEndPos);\n // append script and </html>\n fs.appendFileSync(filePath, `${scriptContent}\\n${htmlEndTag}\\n`);\n}\n\nexport function reportHTMLContent(\n dumpData: string | ReportDumpWithAttributes,\n reportPath?: string,\n appendReport?: boolean,\n): string {\n const tpl = getReportTpl();\n\n if (!tpl) {\n console.warn('reportTpl is not set, will not write report');\n return '';\n }\n\n // if reportPath is set, it means we are in write to file mode\n const writeToFile = reportPath && !ifInBrowser;\n let dumpContent = '';\n\n if (typeof dumpData === 'string') {\n // do not use template string here, will cause bundle error\n dumpContent =\n // biome-ignore lint/style/useTemplate: <explanation>\n '<script type=\"midscene_web_dump\" type=\"application/json\">\\n' +\n escapeScriptTag(dumpData) +\n '\\n</script>';\n } else {\n const { dumpString, attributes } = dumpData;\n const attributesArr = Object.keys(attributes || {}).map((key) => {\n return `${key}=\"${encodeURIComponent(attributes![key])}\"`;\n });\n\n dumpContent =\n // do not use template string here, will cause bundle error\n // biome-ignore lint/style/useTemplate: <explanation>\n '<script type=\"midscene_web_dump\" type=\"application/json\" ' +\n attributesArr.join(' ') +\n '>\\n' +\n escapeScriptTag(dumpString) +\n '\\n</script>';\n }\n\n if (writeToFile) {\n if (!appendReport) {\n writeFileSync(reportPath!, tpl + dumpContent, { flag: 'w' });\n return reportPath!;\n }\n\n if (!reportInitializedMap.get(reportPath!)) {\n writeFileSync(reportPath!, tpl, { flag: 'w' });\n reportInitializedMap.set(reportPath!, true);\n }\n\n insertScriptBeforeClosingHtml(reportPath!, dumpContent);\n return reportPath!;\n }\n\n return tpl + dumpContent;\n}\n\nexport function writeDumpReport(\n fileName: string,\n dumpData: string | ReportDumpWithAttributes,\n appendReport?: boolean,\n): string | null {\n if (ifInBrowser || ifInWorker) {\n console.log('will not write report in browser');\n return null;\n }\n\n // Try to find package info from current working directory\n // In bundled environments, __filename and import.meta.url may not work correctly\n // Using process.cwd() or undefined to let getRunningPkgInfo use its default behavior\n const midscenePkgInfo = getRunningPkgInfo();\n if (!midscenePkgInfo) {\n console.warn('midscenePkgInfo not found, will not write report');\n return null;\n }\n\n const reportPath = path.join(\n getMidsceneRunSubDir('report'),\n `${fileName}.html`,\n );\n\n reportHTMLContent(dumpData, reportPath, appendReport);\n\n if (process.env.MIDSCENE_DEBUG_LOG_JSON) {\n const jsonPath = `${reportPath}.json`;\n let data;\n\n if (typeof dumpData === 'string') {\n data = JSON.parse(dumpData) as ReportDumpWithAttributes;\n } else {\n data = dumpData;\n }\n\n writeFileSync(jsonPath, JSON.stringify(data, null, 2), {\n flag: appendReport ? 'a' : 'w',\n });\n\n logMsg(`Midscene - dump file written: ${jsonPath}`);\n }\n\n return reportPath;\n}\n\nexport function writeLogFile(opts: {\n fileName: string;\n fileExt: string;\n fileContent: string;\n type: 'dump' | 'cache' | 'report' | 'tmp';\n generateReport?: boolean;\n appendReport?: boolean;\n}) {\n if (ifInBrowser || ifInWorker) {\n return '/mock/report.html';\n }\n const { fileName, fileExt, fileContent, type = 'dump' } = opts;\n const targetDir = getMidsceneRunSubDir(type);\n // Ensure directory exists\n if (!logEnvReady) {\n assert(targetDir, 'logDir should be set before writing dump file');\n\n // gitIgnore in the parent directory\n const gitIgnorePath = path.join(targetDir, '../../.gitignore');\n const gitPath = path.join(targetDir, '../../.git');\n let gitIgnoreContent = '';\n\n if (existsSync(gitPath)) {\n // if the git path exists, we need to add the log folder to the git ignore file\n if (existsSync(gitIgnorePath)) {\n gitIgnoreContent = readFileSync(gitIgnorePath, 'utf-8');\n }\n\n // ignore the log folder\n if (!gitIgnoreContent.includes(`${defaultRunDirName}/`)) {\n writeFileSync(\n gitIgnorePath,\n `${gitIgnoreContent}\\n# Midscene.js dump files\\n${defaultRunDirName}/dump\\n${defaultRunDirName}/report\\n${defaultRunDirName}/tmp\\n${defaultRunDirName}/log\\n`,\n 'utf-8',\n );\n }\n }\n\n logEnvReady = true;\n }\n\n const filePath = path.join(targetDir, `${fileName}.${fileExt}`);\n\n if (type !== 'dump') {\n // do not write dump file any more\n writeFileSync(filePath, fileContent);\n }\n\n if (opts?.generateReport) {\n return writeDumpReport(fileName, fileContent, opts.appendReport);\n }\n\n return filePath;\n}\n\nexport function getTmpDir(): string | null {\n try {\n const runningPkgInfo = getRunningPkgInfo();\n if (!runningPkgInfo) {\n return null;\n }\n const { name } = runningPkgInfo;\n const tmpPath = path.join(tmpdir(), name);\n mkdirSync(tmpPath, { recursive: true });\n return tmpPath;\n } catch (e) {\n return null;\n }\n}\n\nexport function getTmpFile(fileExtWithoutDot: string): string | null {\n if (ifInBrowser || ifInWorker) {\n return null;\n }\n const tmpDir = getTmpDir();\n const filename = `${uuid()}.${fileExtWithoutDot}`;\n return path.join(tmpDir!, filename);\n}\n\nexport function overlapped(container: Rect, target: Rect) {\n // container and the target have some part overlapped\n return (\n container.left < target.left + target.width &&\n container.left + container.width > target.left &&\n container.top < target.top + target.height &&\n container.top + container.height > target.top\n );\n}\n\nexport async function sleep(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport function replacerForPageObject(key: string, value: any) {\n if (value && value.constructor?.name === 'Page') {\n return '[Page object]';\n }\n if (value && value.constructor?.name === 'Browser') {\n return '[Browser object]';\n }\n return value;\n}\n\nexport function stringifyDumpData(data: any, indents?: number) {\n return JSON.stringify(data, replacerForPageObject, indents);\n}\n\ndeclare const __VERSION__: string;\n\nexport function getVersion() {\n return __VERSION__;\n}\n\nfunction debugLog(...message: any[]) {\n const debugMode = getAIConfig(MIDSCENE_DEBUG_MODE);\n if (debugMode) {\n console.log('[Midscene]', ...message);\n }\n}\n\nlet lastReportedRepoUrl = '';\nexport function uploadTestInfoToServer({ testUrl }: { testUrl: string }) {\n let repoUrl = '';\n let userEmail = '';\n\n const extraConfig = getAIConfigInJson(MIDSCENE_OPENAI_INIT_CONFIG_JSON);\n const serverUrl = extraConfig?.REPORT_SERVER_URL;\n\n try {\n repoUrl = execSync('git config --get remote.origin.url').toString().trim();\n userEmail = execSync('git config --get user.email').toString().trim();\n } catch (error) {\n debugLog('Failed to get git info:', error);\n }\n\n // Only upload test info if:\n // 1. Server URL is configured AND\n // 2. Either:\n // - We have a repo URL that's different from last reported one (to avoid duplicate reports)\n // - OR we don't have a repo URL but have a test URL (for non-git environments)\n if (\n serverUrl &&\n ((repoUrl && repoUrl !== lastReportedRepoUrl) || (!repoUrl && testUrl))\n ) {\n debugLog('Uploading test info to server', {\n serverUrl,\n repoUrl,\n testUrl,\n userEmail,\n });\n\n fetch(serverUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n repo_url: repoUrl,\n test_url: testUrl,\n user_email: userEmail,\n }),\n })\n .then((response) => response.json())\n .then((data) => {\n debugLog('Successfully uploaded test info to server:', data);\n })\n .catch((error) =>\n debugLog('Failed to upload test info to server:', error),\n );\n lastReportedRepoUrl = repoUrl;\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","logEnvReady","groupedActionDumpFileExt","reportInitializedMap","Map","getReportTpl","reportTpl","insertScriptBeforeClosingHtml","filePath","scriptContent","htmlEndTag","stat","fs","readSize","Math","start","buffer","Buffer","fd","tailStr","htmlEndIdx","Error","beforeHtmlInTail","htmlEndPos","reportHTMLContent","dumpData","reportPath","appendReport","tpl","console","writeToFile","ifInBrowser","dumpContent","escapeScriptTag","dumpString","attributes","attributesArr","encodeURIComponent","writeFileSync","writeDumpReport","fileName","ifInWorker","midscenePkgInfo","getRunningPkgInfo","path","getMidsceneRunSubDir","process","jsonPath","data","JSON","logMsg","writeLogFile","opts","fileExt","fileContent","type","targetDir","assert","gitIgnorePath","gitPath","gitIgnoreContent","existsSync","readFileSync","defaultRunDirName","getTmpDir","runningPkgInfo","name","tmpPath","tmpdir","mkdirSync","e","getTmpFile","fileExtWithoutDot","tmpDir","filename","uuid","overlapped","container","target","sleep","ms","Promise","resolve","setTimeout","replacerForPageObject","value","_value_constructor","_value_constructor1","stringifyDumpData","indents","getVersion","__VERSION__","debugLog","message","debugMode","getAIConfig","MIDSCENE_DEBUG_MODE","lastReportedRepoUrl","uploadTestInfoToServer","testUrl","repoUrl","userEmail","extraConfig","getAIConfigInJson","MIDSCENE_OPENAI_INIT_CONFIG_JSON","serverUrl","execSync","error","fetch","response"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG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AAAAA,IAAAA,oBAAAA,WAAAA,AAAAA,EAAYC,oBAAAA,mBAAmBA;IACjD,IAAIF,WACFjE,QAAQ,GAAG,CAAC,iBAAiBgE;AAEjC;AAEA,IAAII,sBAAsB;AACnB,SAASC,uBAAuB,EAAEC,OAAO,EAAuB;IACrE,IAAIC,UAAU;IACd,IAAIC,YAAY;IAEhB,MAAMC,cAAcC,AAAAA,IAAAA,oBAAAA,iBAAAA,AAAAA,EAAkBC,oBAAAA,gCAAgCA;IACtE,MAAMC,YAAYH,QAAAA,cAAAA,KAAAA,IAAAA,YAAa,iBAAiB;IAEhD,IAAI;QACFF,UAAUM,AAAAA,IAAAA,4CAAAA,QAAAA,AAAAA,EAAS,sCAAsC,QAAQ,GAAG,IAAI;QACxEL,YAAYK,AAAAA,IAAAA,4CAAAA,QAAAA,AAAAA,EAAS,+BAA+B,QAAQ,GAAG,IAAI;IACrE,EAAE,OAAOC,OAAO;QACdf,SAAS,2BAA2Be;IACtC;IAOA,IACEF,aACEL,CAAAA,WAAWA,YAAYH,uBAAyB,CAACG,WAAWD,OAAM,GACpE;QACAP,SAAS,iCAAiC;YACxCa;YACAL;YACAD;YACAE;QACF;QAEAO,MAAMH,WAAW;YACf,QAAQ;YACR,SAAS;gBACP,gBAAgB;YAClB;YACA,MAAMxD,KAAK,SAAS,CAAC;gBACnB,UAAUmD;gBACV,UAAUD;gBACV,YAAYE;YACd;QACF,GACG,IAAI,CAAC,CAACQ,WAAaA,SAAS,IAAI,IAChC,IAAI,CAAC,CAAC7D;YACL4C,SAAS,8CAA8C5C;QACzD,GACC,KAAK,CAAC,CAAC2D,QACNf,SAAS,yCAAyCe;QAEtDV,sBAAsBG;IACxB;AACF"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["webpack://@midscene/core/webpack/runtime/define_property_getters","webpack://@midscene/core/webpack/runtime/has_own_property","webpack://@midscene/core/webpack/runtime/make_namespace_object","webpack://@midscene/core/./src/utils.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { execSync } from 'node:child_process';\nimport * as fs from 'node:fs';\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport * as path from 'node:path';\nimport {\n defaultRunDirName,\n getMidsceneRunSubDir,\n} from '@midscene/shared/common';\nimport {\n MIDSCENE_DEBUG_MODE,\n MIDSCENE_OPENAI_INIT_CONFIG_JSON,\n getAIConfig,\n getAIConfigInJson,\n} from '@midscene/shared/env';\nimport { getRunningPkgInfo } from '@midscene/shared/node';\nimport { assert, logMsg } from '@midscene/shared/utils';\nimport {\n escapeScriptTag,\n ifInBrowser,\n ifInWorker,\n uuid,\n} from '@midscene/shared/utils';\nimport type { Rect, ReportDumpWithAttributes } from './types';\n\nlet logEnvReady = false;\n\nexport const groupedActionDumpFileExt = 'web-dump.json';\n\nconst reportInitializedMap = new Map<string, boolean>();\n\ndeclare const __DEV_REPORT_PATH__: string;\n\nfunction getReportTpl() {\n if (__DEV_REPORT_PATH__) {\n return fs.readFileSync(__DEV_REPORT_PATH__, 'utf-8');\n }\n const reportTpl = 'REPLACE_ME_WITH_REPORT_HTML';\n\n return reportTpl;\n}\n\n/**\n * high performance, insert script before </html> in HTML file\n * only truncate and append, no temporary file\n */\nexport function insertScriptBeforeClosingHtml(\n filePath: string,\n scriptContent: string,\n): void {\n const htmlEndTag = '</html>';\n const stat = fs.statSync(filePath);\n\n const readSize = Math.min(stat.size, 4096);\n const start = Math.max(0, stat.size - readSize);\n const buffer = Buffer.alloc(stat.size - start);\n const fd = fs.openSync(filePath, 'r');\n fs.readSync(fd, buffer, 0, buffer.length, start);\n fs.closeSync(fd);\n\n const tailStr = buffer.toString('utf8');\n const htmlEndIdx = tailStr.lastIndexOf(htmlEndTag);\n if (htmlEndIdx === -1) {\n throw new Error(`No </html> found in file:${filePath}`);\n }\n\n // calculate the correct byte position: char position to byte position\n const beforeHtmlInTail = tailStr.slice(0, htmlEndIdx);\n const htmlEndPos = start + Buffer.byteLength(beforeHtmlInTail, 'utf8');\n\n // truncate to </html> before\n fs.truncateSync(filePath, htmlEndPos);\n // append script and </html>\n fs.appendFileSync(filePath, `${scriptContent}\\n${htmlEndTag}\\n`);\n}\n\nexport function reportHTMLContent(\n dumpData: string | ReportDumpWithAttributes,\n reportPath?: string,\n appendReport?: boolean,\n): string {\n const tpl = getReportTpl();\n\n if (!tpl) {\n console.warn('reportTpl is not set, will not write report');\n return '';\n }\n\n // if reportPath is set, it means we are in write to file mode\n const writeToFile = reportPath && !ifInBrowser;\n let dumpContent = '';\n\n if (typeof dumpData === 'string') {\n // do not use template string here, will cause bundle error\n dumpContent =\n // biome-ignore lint/style/useTemplate: <explanation>\n '<script type=\"midscene_web_dump\" type=\"application/json\">\\n' +\n escapeScriptTag(dumpData) +\n '\\n</script>';\n } else {\n const { dumpString, attributes } = dumpData;\n const attributesArr = Object.keys(attributes || {}).map((key) => {\n return `${key}=\"${encodeURIComponent(attributes![key])}\"`;\n });\n\n dumpContent =\n // do not use template string here, will cause bundle error\n // biome-ignore lint/style/useTemplate: <explanation>\n '<script type=\"midscene_web_dump\" type=\"application/json\" ' +\n attributesArr.join(' ') +\n '>\\n' +\n escapeScriptTag(dumpString) +\n '\\n</script>';\n }\n\n if (writeToFile) {\n if (!appendReport) {\n writeFileSync(reportPath!, tpl + dumpContent, { flag: 'w' });\n return reportPath!;\n }\n\n if (!reportInitializedMap.get(reportPath!)) {\n writeFileSync(reportPath!, tpl, { flag: 'w' });\n reportInitializedMap.set(reportPath!, true);\n }\n\n insertScriptBeforeClosingHtml(reportPath!, dumpContent);\n return reportPath!;\n }\n\n return tpl + dumpContent;\n}\n\nexport function writeDumpReport(\n fileName: string,\n dumpData: string | ReportDumpWithAttributes,\n appendReport?: boolean,\n): string | null {\n if (ifInBrowser || ifInWorker) {\n console.log('will not write report in browser');\n return null;\n }\n\n const reportPath = path.join(\n getMidsceneRunSubDir('report'),\n `${fileName}.html`,\n );\n\n reportHTMLContent(dumpData, reportPath, appendReport);\n\n if (process.env.MIDSCENE_DEBUG_LOG_JSON) {\n const jsonPath = `${reportPath}.json`;\n let data;\n\n if (typeof dumpData === 'string') {\n data = JSON.parse(dumpData) as ReportDumpWithAttributes;\n } else {\n data = dumpData;\n }\n\n writeFileSync(jsonPath, JSON.stringify(data, null, 2), {\n flag: appendReport ? 'a' : 'w',\n });\n\n logMsg(`Midscene - dump file written: ${jsonPath}`);\n }\n\n return reportPath;\n}\n\nexport function writeLogFile(opts: {\n fileName: string;\n fileExt: string;\n fileContent: string;\n type: 'dump' | 'cache' | 'report' | 'tmp';\n generateReport?: boolean;\n appendReport?: boolean;\n}) {\n if (ifInBrowser || ifInWorker) {\n return '/mock/report.html';\n }\n const { fileName, fileExt, fileContent, type = 'dump' } = opts;\n const targetDir = getMidsceneRunSubDir(type);\n // Ensure directory exists\n if (!logEnvReady) {\n assert(targetDir, 'logDir should be set before writing dump file');\n\n // gitIgnore in the parent directory\n const gitIgnorePath = path.join(targetDir, '../../.gitignore');\n const gitPath = path.join(targetDir, '../../.git');\n let gitIgnoreContent = '';\n\n if (existsSync(gitPath)) {\n // if the git path exists, we need to add the log folder to the git ignore file\n if (existsSync(gitIgnorePath)) {\n gitIgnoreContent = readFileSync(gitIgnorePath, 'utf-8');\n }\n\n // ignore the log folder\n if (!gitIgnoreContent.includes(`${defaultRunDirName}/`)) {\n writeFileSync(\n gitIgnorePath,\n `${gitIgnoreContent}\\n# Midscene.js dump files\\n${defaultRunDirName}/dump\\n${defaultRunDirName}/report\\n${defaultRunDirName}/tmp\\n${defaultRunDirName}/log\\n`,\n 'utf-8',\n );\n }\n }\n\n logEnvReady = true;\n }\n\n const filePath = path.join(targetDir, `${fileName}.${fileExt}`);\n\n if (type !== 'dump') {\n // do not write dump file any more\n writeFileSync(filePath, fileContent);\n }\n\n if (opts?.generateReport) {\n return writeDumpReport(fileName, fileContent, opts.appendReport);\n }\n\n return filePath;\n}\n\nexport function getTmpDir(): string | null {\n try {\n const runningPkgInfo = getRunningPkgInfo();\n if (!runningPkgInfo) {\n return null;\n }\n const { name } = runningPkgInfo;\n const tmpPath = path.join(tmpdir(), name);\n mkdirSync(tmpPath, { recursive: true });\n return tmpPath;\n } catch (e) {\n return null;\n }\n}\n\nexport function getTmpFile(fileExtWithoutDot: string): string | null {\n if (ifInBrowser || ifInWorker) {\n return null;\n }\n const tmpDir = getTmpDir();\n const filename = `${uuid()}.${fileExtWithoutDot}`;\n return path.join(tmpDir!, filename);\n}\n\nexport function overlapped(container: Rect, target: Rect) {\n // container and the target have some part overlapped\n return (\n container.left < target.left + target.width &&\n container.left + container.width > target.left &&\n container.top < target.top + target.height &&\n container.top + container.height > target.top\n );\n}\n\nexport async function sleep(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport function replacerForPageObject(key: string, value: any) {\n if (value && value.constructor?.name === 'Page') {\n return '[Page object]';\n }\n if (value && value.constructor?.name === 'Browser') {\n return '[Browser object]';\n }\n return value;\n}\n\nexport function stringifyDumpData(data: any, indents?: number) {\n return JSON.stringify(data, replacerForPageObject, indents);\n}\n\ndeclare const __VERSION__: string;\n\nexport function getVersion() {\n return __VERSION__;\n}\n\nfunction debugLog(...message: any[]) {\n const debugMode = getAIConfig(MIDSCENE_DEBUG_MODE);\n if (debugMode) {\n console.log('[Midscene]', ...message);\n }\n}\n\nlet lastReportedRepoUrl = '';\nexport function uploadTestInfoToServer({ testUrl }: { testUrl: string }) {\n let repoUrl = '';\n let userEmail = '';\n\n const extraConfig = getAIConfigInJson(MIDSCENE_OPENAI_INIT_CONFIG_JSON);\n const serverUrl = extraConfig?.REPORT_SERVER_URL;\n\n try {\n repoUrl = execSync('git config --get remote.origin.url').toString().trim();\n userEmail = execSync('git config --get user.email').toString().trim();\n } catch (error) {\n debugLog('Failed to get git info:', error);\n }\n\n // Only upload test info if:\n // 1. Server URL is configured AND\n // 2. Either:\n // - We have a repo URL that's different from last reported one (to avoid duplicate reports)\n // - OR we don't have a repo URL but have a test URL (for non-git environments)\n if (\n serverUrl &&\n ((repoUrl && repoUrl !== lastReportedRepoUrl) || (!repoUrl && testUrl))\n ) {\n debugLog('Uploading test info to server', {\n serverUrl,\n repoUrl,\n testUrl,\n userEmail,\n });\n\n fetch(serverUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n repo_url: repoUrl,\n test_url: testUrl,\n user_email: userEmail,\n }),\n })\n .then((response) => response.json())\n .then((data) => {\n debugLog('Successfully uploaded test info to server:', data);\n })\n .catch((error) =>\n debugLog('Failed to upload test info to server:', error),\n );\n lastReportedRepoUrl = repoUrl;\n }\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","logEnvReady","groupedActionDumpFileExt","reportInitializedMap","Map","getReportTpl","reportTpl","insertScriptBeforeClosingHtml","filePath","scriptContent","htmlEndTag","stat","fs","readSize","Math","start","buffer","Buffer","fd","tailStr","htmlEndIdx","Error","beforeHtmlInTail","htmlEndPos","reportHTMLContent","dumpData","reportPath","appendReport","tpl","console","writeToFile","ifInBrowser","dumpContent","escapeScriptTag","dumpString","attributes","attributesArr","encodeURIComponent","writeFileSync","writeDumpReport","fileName","ifInWorker","path","getMidsceneRunSubDir","process","jsonPath","data","JSON","logMsg","writeLogFile","opts","fileExt","fileContent","type","targetDir","assert","gitIgnorePath","gitPath","gitIgnoreContent","existsSync","readFileSync","defaultRunDirName","getTmpDir","runningPkgInfo","getRunningPkgInfo","name","tmpPath","tmpdir","mkdirSync","e","getTmpFile","fileExtWithoutDot","tmpDir","filename","uuid","overlapped","container","target","sleep","ms","Promise","resolve","setTimeout","replacerForPageObject","value","_value_constructor","_value_constructor1","stringifyDumpData","indents","getVersion","__VERSION__","debugLog","message","debugMode","getAIConfig","MIDSCENE_DEBUG_MODE","lastReportedRepoUrl","uploadTestInfoToServer","testUrl","repoUrl","userEmail","extraConfig","getAIConfigInJson","MIDSCENE_OPENAI_INIT_CONFIG_JSON","serverUrl","execSync","error","fetch","response"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;;;;;;;;;;;;;;;;ACmBA,IAAII,cAAc;AAEX,MAAMC,2BAA2B;AAExC,MAAMC,uBAAuB,IAAIC;AAIjC,SAASC;IAIP,MAAMC,YAAY;IAElB,OAAOA;AACT;AAMO,SAASC,8BACdC,QAAgB,EAChBC,aAAqB;IAErB,MAAMC,aAAa;IACnB,MAAMC,OAAOC,iCAAAA,QAAW,CAACJ;IAEzB,MAAMK,WAAWC,KAAK,GAAG,CAACH,KAAK,IAAI,EAAE;IACrC,MAAMI,QAAQD,KAAK,GAAG,CA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CAAyCe;QAEtDV,sBAAsBG;IACxB;AACF"}
|
package/dist/types/ai-model.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { ChatCompletionMessageParam } from 'openai/resources/index';
|
|
|
4
4
|
import type { ChatCompletionSystemMessageParam } from 'openai/resources/index';
|
|
5
5
|
import type { ChatCompletionUserMessageParam } from 'openai/resources/index';
|
|
6
6
|
import { ElementTreeNode } from '@midscene/shared/types';
|
|
7
|
-
import type { NodeType } from '@midscene/shared/constants';
|
|
8
7
|
import OpenAI from 'openai';
|
|
9
8
|
import { Rect } from '@midscene/shared/types';
|
|
10
9
|
import { Size } from '@midscene/shared/types';
|
|
@@ -207,7 +206,7 @@ declare interface DeviceAction<ParamType = any> {
|
|
|
207
206
|
paramDescription?: string;
|
|
208
207
|
location?: 'required' | 'optional' | false;
|
|
209
208
|
whatToLocate?: string; // what to locate if location is required or optional
|
|
210
|
-
call: (
|
|
209
|
+
call: (param: ParamType) => Promise<void> | void;
|
|
211
210
|
}
|
|
212
211
|
|
|
213
212
|
declare type ElementById = (id: string) => BaseElement | null;
|
|
@@ -220,85 +219,6 @@ export declare function elementByPositionWithElementInfo(treeRoot: ElementTreeNo
|
|
|
220
219
|
filterPositionElements?: boolean;
|
|
221
220
|
}): BaseElement | undefined;
|
|
222
221
|
|
|
223
|
-
declare interface ExecutionRecorderItem {
|
|
224
|
-
type: 'screenshot';
|
|
225
|
-
ts: number;
|
|
226
|
-
screenshot?: string;
|
|
227
|
-
timing?: string;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
declare type ExecutionTask<
|
|
231
|
-
E extends ExecutionTaskApply<any, any, any> = ExecutionTaskApply<
|
|
232
|
-
any,
|
|
233
|
-
any,
|
|
234
|
-
any
|
|
235
|
-
>,
|
|
236
|
-
> = E &
|
|
237
|
-
ExecutionTaskReturn<
|
|
238
|
-
E extends ExecutionTaskApply<any, any, infer TaskOutput, any>
|
|
239
|
-
? TaskOutput
|
|
240
|
-
: unknown,
|
|
241
|
-
E extends ExecutionTaskApply<any, any, any, infer TaskLog>
|
|
242
|
-
? TaskLog
|
|
243
|
-
: unknown
|
|
244
|
-
> & {
|
|
245
|
-
status: 'pending' | 'running' | 'finished' | 'failed' | 'cancelled';
|
|
246
|
-
error?: Error;
|
|
247
|
-
errorMessage?: string;
|
|
248
|
-
errorStack?: string;
|
|
249
|
-
timing?: {
|
|
250
|
-
start: number;
|
|
251
|
-
end?: number;
|
|
252
|
-
cost?: number;
|
|
253
|
-
};
|
|
254
|
-
usage?: AIUsageInfo;
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
declare interface ExecutionTaskApply<
|
|
258
|
-
Type extends ExecutionTaskType = any,
|
|
259
|
-
TaskParam = any,
|
|
260
|
-
TaskOutput = any,
|
|
261
|
-
TaskLog = any,
|
|
262
|
-
> {
|
|
263
|
-
type: Type;
|
|
264
|
-
subType?: string;
|
|
265
|
-
param?: TaskParam;
|
|
266
|
-
thought?: string;
|
|
267
|
-
locate?: PlanningLocateParam | null;
|
|
268
|
-
pageContext?: UIContext;
|
|
269
|
-
executor: (
|
|
270
|
-
param: TaskParam,
|
|
271
|
-
context: ExecutorContext,
|
|
272
|
-
) => // biome-ignore lint/suspicious/noConfusingVoidType: <explanation>
|
|
273
|
-
| Promise<ExecutionTaskReturn<TaskOutput, TaskLog> | undefined | void>
|
|
274
|
-
| undefined
|
|
275
|
-
| void;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
declare interface ExecutionTaskHitBy {
|
|
279
|
-
from: string;
|
|
280
|
-
context: Record<string, any>;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
declare interface ExecutionTaskReturn<TaskOutput = unknown, TaskLog = unknown> {
|
|
284
|
-
output?: TaskOutput;
|
|
285
|
-
log?: TaskLog;
|
|
286
|
-
recorder?: ExecutionRecorderItem[];
|
|
287
|
-
hitBy?: ExecutionTaskHitBy;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
declare type ExecutionTaskType =
|
|
291
|
-
| 'Planning'
|
|
292
|
-
| 'Insight'
|
|
293
|
-
| 'Action'
|
|
294
|
-
| 'Assertion'
|
|
295
|
-
| 'Log';
|
|
296
|
-
|
|
297
|
-
declare interface ExecutorContext {
|
|
298
|
-
task: ExecutionTask;
|
|
299
|
-
element?: LocateResultElement | null;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
222
|
/**
|
|
303
223
|
* Generates Playwright test code from recorded events
|
|
304
224
|
*/
|
|
@@ -332,19 +252,6 @@ declare interface LocateOption {
|
|
|
332
252
|
pageContext?: UIContext<BaseElement>;
|
|
333
253
|
}
|
|
334
254
|
|
|
335
|
-
declare type LocateResultElement = {
|
|
336
|
-
id: string;
|
|
337
|
-
indexId?: number;
|
|
338
|
-
center: [number, number];
|
|
339
|
-
rect: Rect;
|
|
340
|
-
xpaths: string[];
|
|
341
|
-
attributes: {
|
|
342
|
-
nodeType: NodeType;
|
|
343
|
-
[key: string]: string;
|
|
344
|
-
};
|
|
345
|
-
isOrderSensitive?: boolean;
|
|
346
|
-
};
|
|
347
|
-
|
|
348
255
|
declare type MidsceneYamlFlowItem =
|
|
349
256
|
| MidsceneYamlFlowItemAIAction
|
|
350
257
|
| MidsceneYamlFlowItemAIAssert
|
|
@@ -396,7 +303,7 @@ declare interface MidsceneYamlFlowItemAIRightClick extends LocateOption {
|
|
|
396
303
|
|
|
397
304
|
declare interface MidsceneYamlFlowItemAIScroll
|
|
398
305
|
extends LocateOption,
|
|
399
|
-
|
|
306
|
+
PlanningActionParamScroll {
|
|
400
307
|
aiScroll: null;
|
|
401
308
|
locate?: TUserPrompt; // which area to scroll, optional
|
|
402
309
|
}
|
|
@@ -460,6 +367,8 @@ declare interface PlanningAction<ParamType = any> {
|
|
|
460
367
|
locate?: PlanningLocateParam | null;
|
|
461
368
|
}
|
|
462
369
|
|
|
370
|
+
declare type PlanningActionParamScroll = scrollParam;
|
|
371
|
+
|
|
463
372
|
declare interface PlanningAIResponse {
|
|
464
373
|
action?: PlanningAction; // this is the qwen mode
|
|
465
374
|
actions?: PlanningAction[];
|
|
@@ -504,7 +413,7 @@ declare interface ReferenceImage {
|
|
|
504
413
|
|
|
505
414
|
export declare function resizeImageForUiTars(imageBase64: string, size: Size): Promise<string>;
|
|
506
415
|
|
|
507
|
-
declare interface
|
|
416
|
+
declare interface scrollParam {
|
|
508
417
|
direction: 'down' | 'up' | 'right' | 'left';
|
|
509
418
|
scrollType: 'once' | 'untilBottom' | 'untilTop' | 'untilRight' | 'untilLeft';
|
|
510
419
|
distance?: null | number; // distance in px
|
package/dist/types/index.d.ts
CHANGED
|
@@ -208,16 +208,6 @@ declare type AIUsageInfo_2 = Record<string, any> & {
|
|
|
208
208
|
time_cost: number | undefined;
|
|
209
209
|
};
|
|
210
210
|
|
|
211
|
-
export declare interface AndroidLongPressParam {
|
|
212
|
-
duration?: number;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
export declare interface AndroidPullParam {
|
|
216
|
-
direction: 'up' | 'down';
|
|
217
|
-
distance?: number;
|
|
218
|
-
duration?: number;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
211
|
export declare interface BaseAgentParserOpt {
|
|
222
212
|
selector?: string;
|
|
223
213
|
ignoreMarker?: boolean;
|
|
@@ -318,7 +308,7 @@ export declare interface DeviceAction<ParamType = any> {
|
|
|
318
308
|
paramDescription?: string;
|
|
319
309
|
location?: 'required' | 'optional' | false;
|
|
320
310
|
whatToLocate?: string;
|
|
321
|
-
call: (
|
|
311
|
+
call: (param: ParamType) => Promise<void> | void;
|
|
322
312
|
}
|
|
323
313
|
|
|
324
314
|
declare interface DeviceAction_2<ParamType = any> {
|
|
@@ -328,7 +318,7 @@ declare interface DeviceAction_2<ParamType = any> {
|
|
|
328
318
|
paramDescription?: string;
|
|
329
319
|
location?: 'required' | 'optional' | false;
|
|
330
320
|
whatToLocate?: string; // what to locate if location is required or optional
|
|
331
|
-
call: (
|
|
321
|
+
call: (param: ParamType) => Promise<void> | void;
|
|
332
322
|
}
|
|
333
323
|
|
|
334
324
|
export declare interface DumpMeta {
|
|
@@ -918,14 +908,14 @@ declare interface MidsceneYamlFlowItemAIRightClick_2 extends LocateOption_2 {
|
|
|
918
908
|
aiRightClick: TUserPrompt_2;
|
|
919
909
|
}
|
|
920
910
|
|
|
921
|
-
export declare interface MidsceneYamlFlowItemAIScroll extends LocateOption,
|
|
911
|
+
export declare interface MidsceneYamlFlowItemAIScroll extends LocateOption, PlanningActionParamScroll {
|
|
922
912
|
aiScroll: null;
|
|
923
913
|
locate?: TUserPrompt;
|
|
924
914
|
}
|
|
925
915
|
|
|
926
916
|
declare interface MidsceneYamlFlowItemAIScroll_2
|
|
927
917
|
extends LocateOption_2,
|
|
928
|
-
|
|
918
|
+
PlanningActionParamScroll_2 {
|
|
929
919
|
aiScroll: null;
|
|
930
920
|
locate?: TUserPrompt_2; // which area to scroll, optional
|
|
931
921
|
}
|
|
@@ -1077,6 +1067,22 @@ declare interface PlanningAction_2<ParamType = any> {
|
|
|
1077
1067
|
locate?: PlanningLocateParam_2 | null;
|
|
1078
1068
|
}
|
|
1079
1069
|
|
|
1070
|
+
export declare interface PlanningActionParamAndroidLongPress {
|
|
1071
|
+
x: number;
|
|
1072
|
+
y: number;
|
|
1073
|
+
duration?: number;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
export declare interface PlanningActionParamAndroidPull {
|
|
1077
|
+
direction: 'up' | 'down';
|
|
1078
|
+
startPoint?: {
|
|
1079
|
+
x: number;
|
|
1080
|
+
y: number;
|
|
1081
|
+
};
|
|
1082
|
+
distance?: number;
|
|
1083
|
+
duration?: number;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1080
1086
|
export declare interface PlanningActionParamAssert {
|
|
1081
1087
|
assertion: TUserPrompt;
|
|
1082
1088
|
}
|
|
@@ -1094,6 +1100,10 @@ export declare interface PlanningActionParamInputOrKeyPress {
|
|
|
1094
1100
|
|
|
1095
1101
|
export declare type PlanningActionParamRightClick = null;
|
|
1096
1102
|
|
|
1103
|
+
export declare type PlanningActionParamScroll = scrollParam;
|
|
1104
|
+
|
|
1105
|
+
declare type PlanningActionParamScroll_2 = scrollParam_2;
|
|
1106
|
+
|
|
1097
1107
|
export declare interface PlanningActionParamSleep {
|
|
1098
1108
|
timeMs: number;
|
|
1099
1109
|
}
|
|
@@ -1183,13 +1193,13 @@ export declare interface ScriptPlayerTaskStatus extends MidsceneYamlTask {
|
|
|
1183
1193
|
error?: Error;
|
|
1184
1194
|
}
|
|
1185
1195
|
|
|
1186
|
-
export declare interface
|
|
1196
|
+
export declare interface scrollParam {
|
|
1187
1197
|
direction: 'down' | 'up' | 'right' | 'left';
|
|
1188
1198
|
scrollType: 'once' | 'untilBottom' | 'untilTop' | 'untilRight' | 'untilLeft';
|
|
1189
1199
|
distance?: null | number;
|
|
1190
1200
|
}
|
|
1191
1201
|
|
|
1192
|
-
declare interface
|
|
1202
|
+
declare interface scrollParam_2 {
|
|
1193
1203
|
direction: 'down' | 'up' | 'right' | 'left';
|
|
1194
1204
|
scrollType: 'once' | 'untilBottom' | 'untilTop' | 'untilRight' | 'untilLeft';
|
|
1195
1205
|
distance?: null | number; // distance in px
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/core",
|
|
3
3
|
"description": "Automate browser actions, extract data, and perform assertions using AI. It offers JavaScript SDK, Chrome extension, and support for scripting in YAML. See https://midscenejs.com/ for details.",
|
|
4
|
-
"version": "0.26.3-beta-
|
|
4
|
+
"version": "0.26.3-beta-20250813105922.0",
|
|
5
5
|
"repository": "https://github.com/web-infra-dev/midscene",
|
|
6
6
|
"homepage": "https://midscenejs.com/",
|
|
7
|
-
"jsnext:source": "./src/index.ts",
|
|
8
7
|
"main": "./dist/lib/index.js",
|
|
9
8
|
"types": "./dist/types/index.d.ts",
|
|
10
9
|
"module": "./dist/es/index.mjs",
|
|
@@ -61,8 +60,8 @@
|
|
|
61
60
|
"langsmith": "0.3.7",
|
|
62
61
|
"openai": "4.81.0",
|
|
63
62
|
"socks-proxy-agent": "8.0.4",
|
|
64
|
-
"@midscene/recorder": "0.26.3-beta-
|
|
65
|
-
"@midscene/shared": "0.26.3-beta-
|
|
63
|
+
"@midscene/recorder": "0.26.3-beta-20250813105922.0",
|
|
64
|
+
"@midscene/shared": "0.26.3-beta-20250813105922.0"
|
|
66
65
|
},
|
|
67
66
|
"devDependencies": {
|
|
68
67
|
"@microsoft/api-extractor": "^7.52.10",
|