@midscene/core 0.26.2-beta-20250812091127.0 → 0.26.3-beta-20250813021342.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.
Files changed (47) hide show
  1. package/dist/es/ai-model.mjs +2502 -0
  2. package/dist/es/ai-model.mjs.map +1 -0
  3. package/dist/es/index.mjs +2362 -0
  4. package/dist/es/index.mjs.map +1 -0
  5. package/dist/es/tree.mjs +2 -0
  6. package/dist/es/utils.mjs +188 -0
  7. package/dist/es/{chunk-WXNDYUNG.js.map → utils.mjs.map} +1 -1
  8. package/dist/lib/ai-model.js +2581 -3
  9. package/dist/lib/ai-model.js.map +1 -0
  10. package/dist/lib/index.js +2375 -493
  11. package/dist/lib/index.js.map +1 -1
  12. package/dist/lib/tree.js +42 -11
  13. package/dist/lib/tree.js.map +1 -1
  14. package/dist/lib/utils.js +257 -29
  15. package/dist/lib/utils.js.map +1 -0
  16. package/dist/types/ai-model.d.ts +505 -99
  17. package/dist/types/index.d.ts +1299 -53
  18. package/dist/types/tree.d.ts +11 -1
  19. package/dist/types/utils.d.ts +47 -33
  20. package/package.json +28 -12
  21. package/dist/es/ai-model.d.ts +0 -99
  22. package/dist/es/ai-model.js +0 -44
  23. package/dist/es/chunk-DDYIQHOA.js +0 -2883
  24. package/dist/es/chunk-DDYIQHOA.js.map +0 -1
  25. package/dist/es/chunk-WXNDYUNG.js +0 -265
  26. package/dist/es/index.d.ts +0 -53
  27. package/dist/es/index.js +0 -570
  28. package/dist/es/index.js.map +0 -1
  29. package/dist/es/llm-planning-4e0c16fe.d.ts +0 -106
  30. package/dist/es/tree.d.ts +0 -1
  31. package/dist/es/tree.js +0 -13
  32. package/dist/es/tree.js.map +0 -1
  33. package/dist/es/types-8a6be57c.d.ts +0 -577
  34. package/dist/es/utils.d.ts +0 -33
  35. package/dist/es/utils.js +0 -30
  36. package/dist/lib/ai-model.d.ts +0 -99
  37. package/dist/lib/chunk-DDYIQHOA.js +0 -2883
  38. package/dist/lib/chunk-DDYIQHOA.js.map +0 -1
  39. package/dist/lib/chunk-WXNDYUNG.js +0 -265
  40. package/dist/lib/chunk-WXNDYUNG.js.map +0 -1
  41. package/dist/lib/index.d.ts +0 -53
  42. package/dist/lib/llm-planning-4e0c16fe.d.ts +0 -106
  43. package/dist/lib/tree.d.ts +0 -1
  44. package/dist/lib/types-8a6be57c.d.ts +0 -577
  45. package/dist/lib/utils.d.ts +0 -33
  46. package/dist/types/llm-planning-4e0c16fe.d.ts +0 -106
  47. package/dist/types/types-8a6be57c.d.ts +0 -577
@@ -0,0 +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 const __dirname = dirname(__filename);\n const midscenePkgInfo = getRunningPkgInfo(__dirname);\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","__dirname","dirname","__filename","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,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,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AQ,GAAG,CAAC,iBAAiBmE;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,99 +1,505 @@
1
- import { aD as StreamingCallback, A as AIUsageInfo, aC as StreamingCodeGenerationOptions, aF as StreamingAIResponse, Y as PlanningAction, m as MidsceneYamlFlowItem } from './types-8a6be57c.js';
2
- import OpenAI from 'openai';
3
- import { ChatCompletionMessageParam } from 'openai/resources';
4
- export { ChatCompletionMessageParam } from 'openai/resources';
5
- import { b as AIActionType, e as AIArgs } from './llm-planning-4e0c16fe.js';
6
- export { a as AiAssert, g as AiExtractElementInfo, A as AiLocateElement, h as AiLocateSection, i as adaptBboxToRect, c as callAiFn, d as describeUserPage, f as elementByPositionWithElementInfo, p as plan } from './llm-planning-4e0c16fe.js';
7
- import { vlLocateMode } from '@midscene/shared/env';
8
- import { actionParser } from '@ui-tars/action-parser';
9
- import { Size } from '@midscene/shared/types';
10
- import '@midscene/shared/constants';
11
-
12
- declare function call(messages: ChatCompletionMessageParam[], AIActionTypeValue: AIActionType, responseFormat?: OpenAI.ChatCompletionCreateParams['response_format'] | OpenAI.ResponseFormatJSONObject, options?: {
13
- stream?: boolean;
14
- onChunk?: StreamingCallback;
15
- }): Promise<{
16
- content: string;
17
- usage?: AIUsageInfo;
18
- isStreamed: boolean;
19
- }>;
20
- declare function callToGetJSONObject<T>(messages: ChatCompletionMessageParam[], AIActionTypeValue: AIActionType): Promise<{
21
- content: T;
22
- usage?: AIUsageInfo;
23
- }>;
24
- declare function callAiFnWithStringResponse<T>(msgs: AIArgs, AIActionTypeValue: AIActionType): Promise<{
25
- content: string;
26
- usage?: AIUsageInfo;
27
- }>;
28
-
29
- declare function systemPromptToLocateElement(vlMode: ReturnType<typeof vlLocateMode>): string;
30
-
31
- interface ChromeRecordedEvent {
32
- type: string;
33
- timestamp: number;
34
- url?: string;
35
- title?: string;
36
- elementDescription?: string;
37
- value?: string;
38
- pageInfo?: any;
39
- elementRect?: any;
40
- screenshotBefore?: string;
41
- screenshotAfter?: string;
42
- screenshotWithBox?: string;
43
- }
44
- interface YamlGenerationOptions {
45
- testName?: string;
46
- includeTimestamps?: boolean;
47
- maxScreenshots?: number;
48
- description?: string;
49
- }
50
- /**
51
- * Generates YAML test configuration from recorded events using AI
52
- */
53
- declare const generateYamlTest: (events: ChromeRecordedEvent[], options?: YamlGenerationOptions) => Promise<string>;
54
- /**
55
- * Generates YAML test configuration from recorded events using AI with streaming support
56
- */
57
- declare const generateYamlTestStream: (events: ChromeRecordedEvent[], options?: YamlGenerationOptions & StreamingCodeGenerationOptions) => Promise<StreamingAIResponse>;
58
-
59
- interface PlaywrightGenerationOptions {
60
- testName?: string;
61
- includeScreenshots?: boolean;
62
- includeTimestamps?: boolean;
63
- maxScreenshots?: number;
64
- description?: string;
65
- viewportSize?: {
66
- width: number;
67
- height: number;
68
- };
69
- waitForNetworkIdle?: boolean;
70
- waitForNetworkIdleTimeout?: number;
71
- }
72
-
73
- /**
74
- * Generates Playwright test code from recorded events
75
- */
76
- declare const generatePlaywrightTest: (events: ChromeRecordedEvent[], options?: PlaywrightGenerationOptions) => Promise<string>;
77
- /**
78
- * Generates Playwright test code from recorded events with streaming support
79
- */
80
- declare const generatePlaywrightTestStream: (events: ChromeRecordedEvent[], options?: PlaywrightGenerationOptions & StreamingCodeGenerationOptions) => Promise<StreamingAIResponse>;
81
-
82
- declare function vlmPlanning(options: {
83
- userInstruction: string;
84
- conversationHistory: ChatCompletionMessageParam[];
85
- size: {
86
- width: number;
87
- height: number;
88
- };
89
- }): Promise<{
90
- actions: PlanningAction<any>[];
91
- actionsFromModel: ReturnType<typeof actionParser>['parsed'];
92
- action_summary: string;
93
- yamlFlow?: MidsceneYamlFlowItem[];
94
- usage?: AIUsageInfo;
95
- rawResponse?: string;
96
- }>;
97
- declare function resizeImageForUiTars(imageBase64: string, size: Size): Promise<string>;
98
-
99
- export { AIActionType, AIArgs, call as callAi, callAiFnWithStringResponse, callToGetJSONObject, generatePlaywrightTest, generatePlaywrightTestStream, generateYamlTest, generateYamlTestStream, resizeImageForUiTars, systemPromptToLocateElement, vlmPlanning };
1
+ import { actionParser } from '@ui-tars/action-parser';
2
+ import { BaseElement } from '@midscene/shared/types';
3
+ import { ChatCompletionMessageParam } from 'openai/resources/index';
4
+ import type { ChatCompletionSystemMessageParam } from 'openai/resources/index';
5
+ import type { ChatCompletionUserMessageParam } from 'openai/resources/index';
6
+ import { ElementTreeNode } from '@midscene/shared/types';
7
+ import OpenAI from 'openai';
8
+ import { Rect } from '@midscene/shared/types';
9
+ import { Size } from '@midscene/shared/types';
10
+ import type { vlLocateMode } from '@midscene/shared/env';
11
+
12
+ export declare function adaptBboxToRect(bbox: number[], width: number, height: number, offsetX?: number, offsetY?: number): Rect;
13
+
14
+ export declare enum AIActionType {
15
+ ASSERT = 0,
16
+ INSPECT_ELEMENT = 1,
17
+ EXTRACT_DATA = 2,
18
+ PLAN = 3,
19
+ DESCRIBE_ELEMENT = 4
20
+ }
21
+
22
+ export declare type AIArgs = [
23
+ ChatCompletionSystemMessageParam,
24
+ ...ChatCompletionUserMessageParam[]
25
+ ];
26
+
27
+ export declare function AiAssert<ElementType extends BaseElement = BaseElement>(options: {
28
+ assertion: TUserPrompt;
29
+ context: UIContext<ElementType>;
30
+ }): Promise<{
31
+ content: AIAssertionResponse;
32
+ usage: AIUsageInfo | undefined;
33
+ }>;
34
+
35
+ declare interface AIAssertionResponse {
36
+ pass: boolean;
37
+ thought: string;
38
+ }
39
+
40
+ declare interface AIDataExtractionResponse<DataDemand> {
41
+ data: DataDemand;
42
+ errors?: string[];
43
+ thought?: string;
44
+ }
45
+
46
+ declare interface AIElementCoordinatesResponse {
47
+ bbox: [number, number, number, number];
48
+ isOrderSensitive?: boolean;
49
+ errors?: string[];
50
+ }
51
+
52
+ declare interface AIElementLocatorResponse {
53
+ elements: {
54
+ id: string;
55
+ reason?: string;
56
+ text?: string;
57
+ xpaths?: string[];
58
+ }[];
59
+ bbox?: [number, number, number, number];
60
+ isOrderSensitive?: boolean;
61
+ errors?: string[];
62
+ }
63
+
64
+ declare type AIElementResponse =
65
+ | AIElementLocatorResponse
66
+ | AIElementCoordinatesResponse;
67
+
68
+ export declare function AiExtractElementInfo<T, ElementType extends BaseElement = BaseElement>(options: {
69
+ dataQuery: string | Record<string, string>;
70
+ multimodalPrompt?: TMultimodalPrompt;
71
+ context: UIContext<ElementType>;
72
+ extractOption?: InsightExtractOption;
73
+ }): Promise<{
74
+ parseResult: AIDataExtractionResponse<T>;
75
+ elementById: (idOrIndexId: string) => ElementType;
76
+ usage: AIUsageInfo | undefined;
77
+ }>;
78
+
79
+ export declare function AiLocateElement<ElementType extends BaseElement = BaseElement>(options: {
80
+ context: UIContext<ElementType>;
81
+ targetElementDescription: TUserPrompt;
82
+ referenceImage?: ReferenceImage;
83
+ callAI?: typeof callAiFn<AIElementResponse | [number, number]>;
84
+ searchConfig?: Awaited<ReturnType<typeof AiLocateSection>>;
85
+ }): Promise<{
86
+ parseResult: AIElementLocatorResponse;
87
+ rect?: Rect;
88
+ rawResponse: string;
89
+ elementById: ElementById;
90
+ usage?: AIUsageInfo;
91
+ isOrderSensitive?: boolean;
92
+ }>;
93
+
94
+ export declare function AiLocateSection(options: {
95
+ context: UIContext<BaseElement>;
96
+ sectionDescription: TUserPrompt;
97
+ callAI?: typeof callAiFn<AISectionLocatorResponse>;
98
+ }): Promise<{
99
+ rect?: Rect;
100
+ imageBase64?: string;
101
+ error?: string;
102
+ rawResponse: string;
103
+ usage?: AIUsageInfo;
104
+ }>;
105
+
106
+ declare interface AISectionLocatorResponse {
107
+ bbox: [number, number, number, number];
108
+ references_bbox?: [number, number, number, number][];
109
+ error?: string;
110
+ }
111
+
112
+ declare type AIUsageInfo = Record<string, any> & {
113
+ prompt_tokens: number | undefined;
114
+ completion_tokens: number | undefined;
115
+ total_tokens: number | undefined;
116
+ time_cost: number | undefined;
117
+ };
118
+
119
+ export declare function callAi(messages: ChatCompletionMessageParam[], AIActionTypeValue: AIActionType, responseFormat?: OpenAI.ChatCompletionCreateParams['response_format'] | OpenAI.ResponseFormatJSONObject, options?: {
120
+ stream?: boolean;
121
+ onChunk?: StreamingCallback;
122
+ }): Promise<{
123
+ content: string;
124
+ usage?: AIUsageInfo;
125
+ isStreamed: boolean;
126
+ }>;
127
+
128
+ export declare function callAiFn<T>(msgs: AIArgs, AIActionTypeValue: AIActionType): Promise<{
129
+ content: T;
130
+ usage?: AIUsageInfo;
131
+ }>;
132
+
133
+ export declare function callAiFnWithStringResponse<T>(msgs: AIArgs, AIActionTypeValue: AIActionType): Promise<{
134
+ content: string;
135
+ usage?: AIUsageInfo;
136
+ }>;
137
+
138
+ export declare function callToGetJSONObject<T>(messages: ChatCompletionMessageParam[], AIActionTypeValue: AIActionType): Promise<{
139
+ content: T;
140
+ usage?: AIUsageInfo;
141
+ }>;
142
+
143
+ export { ChatCompletionMessageParam }
144
+
145
+ declare interface ChromeRecordedEvent {
146
+ type: string;
147
+ timestamp: number;
148
+ url?: string;
149
+ title?: string;
150
+ elementDescription?: string;
151
+ value?: string;
152
+ pageInfo?: any;
153
+ elementRect?: any;
154
+ screenshotBefore?: string;
155
+ screenshotAfter?: string;
156
+ screenshotWithBox?: string;
157
+ }
158
+
159
+ declare interface CodeGenerationChunk {
160
+ /** The incremental content chunk */
161
+ content: string;
162
+ /** The reasoning content */
163
+ reasoning_content: string;
164
+ /** The accumulated content so far */
165
+ accumulated: string;
166
+ /** Whether this is the final chunk */
167
+ isComplete: boolean;
168
+ /** Token usage information if available */
169
+ usage?: AIUsageInfo;
170
+ }
171
+
172
+ export declare function describeUserPage<ElementType extends BaseElement = BaseElement>(context: Omit<UIContext<ElementType>, 'describer'>, opt?: {
173
+ truncateTextLength?: number;
174
+ filterNonTextContent?: boolean;
175
+ domIncluded?: boolean | 'visible-only';
176
+ visibleOnly?: boolean;
177
+ }): Promise<{
178
+ description: string;
179
+ elementById(idOrIndexId: string): ElementType;
180
+ elementByPosition(position: {
181
+ x: number;
182
+ y: number;
183
+ }, size: {
184
+ width: number;
185
+ height: number;
186
+ }): BaseElement | undefined;
187
+ insertElementByPosition(position: {
188
+ x: number;
189
+ y: number;
190
+ }): ElementType;
191
+ size: {
192
+ width: number;
193
+ height: number;
194
+ };
195
+ }>;
196
+
197
+ declare interface DetailedLocateParam extends LocateOption {
198
+ prompt: TUserPrompt;
199
+ referenceImage?: ReferenceImage;
200
+ }
201
+
202
+ declare interface DeviceAction<ParamType = any> {
203
+ name: string;
204
+ description?: string;
205
+ paramSchema?: string;
206
+ paramDescription?: string;
207
+ location?: 'required' | 'optional' | false;
208
+ whatToLocate?: string; // what to locate if location is required or optional
209
+ call: (param: ParamType) => Promise<void> | void;
210
+ }
211
+
212
+ declare type ElementById = (id: string) => BaseElement | null;
213
+
214
+ export declare function elementByPositionWithElementInfo(treeRoot: ElementTreeNode<BaseElement>, position: {
215
+ x: number;
216
+ y: number;
217
+ }, options?: {
218
+ requireStrictDistance?: boolean;
219
+ filterPositionElements?: boolean;
220
+ }): BaseElement | undefined;
221
+
222
+ /**
223
+ * Generates Playwright test code from recorded events
224
+ */
225
+ export declare const generatePlaywrightTest: (events: ChromeRecordedEvent[], options?: PlaywrightGenerationOptions) => Promise<string>;
226
+
227
+ /**
228
+ * Generates Playwright test code from recorded events with streaming support
229
+ */
230
+ export declare const generatePlaywrightTestStream: (events: ChromeRecordedEvent[], options?: PlaywrightGenerationOptions & StreamingCodeGenerationOptions) => Promise<StreamingAIResponse>;
231
+
232
+ /**
233
+ * Generates YAML test configuration from recorded events using AI
234
+ */
235
+ export declare const generateYamlTest: (events: ChromeRecordedEvent[], options?: YamlGenerationOptions) => Promise<string>;
236
+
237
+ /**
238
+ * Generates YAML test configuration from recorded events using AI with streaming support
239
+ */
240
+ export declare const generateYamlTestStream: (events: ChromeRecordedEvent[], options?: YamlGenerationOptions & StreamingCodeGenerationOptions) => Promise<StreamingAIResponse>;
241
+
242
+ declare interface InsightExtractOption {
243
+ domIncluded?: boolean | 'visible-only';
244
+ screenshotIncluded?: boolean;
245
+ returnThought?: boolean;
246
+ }
247
+
248
+ declare interface LocateOption {
249
+ deepThink?: boolean; // only available in vl model
250
+ cacheable?: boolean; // user can set this param to false to disable the cache for a single agent api
251
+ xpath?: string; // only available in web
252
+ pageContext?: UIContext<BaseElement>;
253
+ }
254
+
255
+ declare type MidsceneYamlFlowItem =
256
+ | MidsceneYamlFlowItemAIAction
257
+ | MidsceneYamlFlowItemAIAssert
258
+ | MidsceneYamlFlowItemAIQuery
259
+ | MidsceneYamlFlowItemAIWaitFor
260
+ | MidsceneYamlFlowItemAITap
261
+ | MidsceneYamlFlowItemAIRightClick
262
+ | MidsceneYamlFlowItemAIHover
263
+ | MidsceneYamlFlowItemAIInput
264
+ | MidsceneYamlFlowItemAIKeyboardPress
265
+ | MidsceneYamlFlowItemAIScroll
266
+ | MidsceneYamlFlowItemSleep
267
+ | MidsceneYamlFlowItemLogScreenshot;
268
+
269
+ declare interface MidsceneYamlFlowItemAIAction {
270
+ ai?: string; // this is the shortcut for aiAction
271
+ aiAction?: string;
272
+ aiActionProgressTips?: string[];
273
+ cacheable?: boolean;
274
+ }
275
+
276
+ declare interface MidsceneYamlFlowItemAIAssert {
277
+ aiAssert: string;
278
+ errorMessage?: string;
279
+ }
280
+
281
+ declare interface MidsceneYamlFlowItemAIHover extends LocateOption {
282
+ aiHover: TUserPrompt;
283
+ }
284
+
285
+ declare interface MidsceneYamlFlowItemAIInput extends LocateOption {
286
+ aiInput: string; // value to input
287
+ locate: TUserPrompt; // where to input
288
+ }
289
+
290
+ declare interface MidsceneYamlFlowItemAIKeyboardPress extends LocateOption {
291
+ aiKeyboardPress: string;
292
+ locate?: TUserPrompt; // where to press, optional
293
+ }
294
+
295
+ declare interface MidsceneYamlFlowItemAIQuery extends InsightExtractOption {
296
+ aiQuery: string;
297
+ name?: string;
298
+ }
299
+
300
+ declare interface MidsceneYamlFlowItemAIRightClick extends LocateOption {
301
+ aiRightClick: TUserPrompt;
302
+ }
303
+
304
+ declare interface MidsceneYamlFlowItemAIScroll
305
+ extends LocateOption,
306
+ PlanningActionParamScroll {
307
+ aiScroll: null;
308
+ locate?: TUserPrompt; // which area to scroll, optional
309
+ }
310
+
311
+ declare interface MidsceneYamlFlowItemAITap extends LocateOption {
312
+ aiTap: TUserPrompt;
313
+ }
314
+
315
+ declare interface MidsceneYamlFlowItemAIWaitFor {
316
+ aiWaitFor: string;
317
+ timeout?: number;
318
+ }
319
+
320
+ declare interface MidsceneYamlFlowItemLogScreenshot {
321
+ logScreenshot?: string; // optional, the title of the screenshot
322
+ content?: string;
323
+ }
324
+
325
+ declare interface MidsceneYamlFlowItemSleep {
326
+ sleep: number;
327
+ }
328
+
329
+ declare type PageType =
330
+ | 'puppeteer'
331
+ | 'playwright'
332
+ | 'static'
333
+ | 'chrome-extension-proxy'
334
+ | 'android';
335
+
336
+ export declare function plan(userInstruction: string, opts: {
337
+ context: UIContext;
338
+ pageType: PageType;
339
+ actionSpace: DeviceAction[];
340
+ callAI?: typeof callAiFn<PlanningAIResponse>;
341
+ log?: string;
342
+ actionContext?: string;
343
+ }): Promise<PlanningAIResponse>;
344
+
345
+ declare interface PlanningAction<ParamType = any> {
346
+ thought?: string;
347
+ type:
348
+ | 'Locate'
349
+ | 'Tap'
350
+ | 'RightClick'
351
+ | 'Hover'
352
+ | 'Drag'
353
+ | 'Input'
354
+ | 'KeyboardPress'
355
+ | 'Scroll'
356
+ | 'Error'
357
+ | 'Assert'
358
+ | 'AssertWithoutThrow'
359
+ | 'Sleep'
360
+ | 'Finished'
361
+ | 'AndroidBackButton'
362
+ | 'AndroidHomeButton'
363
+ | 'AndroidRecentAppsButton'
364
+ | 'AndroidLongPress'
365
+ | 'AndroidPull';
366
+ param: ParamType;
367
+ locate?: PlanningLocateParam | null;
368
+ }
369
+
370
+ declare type PlanningActionParamScroll = scrollParam;
371
+
372
+ declare interface PlanningAIResponse {
373
+ action?: PlanningAction; // this is the qwen mode
374
+ actions?: PlanningAction[];
375
+ more_actions_needed_by_instruction: boolean;
376
+ log: string;
377
+ sleep?: number;
378
+ error?: string;
379
+ usage?: AIUsageInfo;
380
+ rawResponse?: string;
381
+ yamlFlow?: MidsceneYamlFlowItem[];
382
+ yamlString?: string;
383
+ }
384
+
385
+ /**
386
+ * planning
387
+ *
388
+ */
389
+
390
+ declare interface PlanningLocateParam extends DetailedLocateParam {
391
+ id?: string;
392
+ bbox?: [number, number, number, number];
393
+ }
394
+
395
+ declare interface PlaywrightGenerationOptions {
396
+ testName?: string;
397
+ includeScreenshots?: boolean;
398
+ includeTimestamps?: boolean;
399
+ maxScreenshots?: number;
400
+ description?: string;
401
+ viewportSize?: {
402
+ width: number;
403
+ height: number;
404
+ };
405
+ waitForNetworkIdle?: boolean;
406
+ waitForNetworkIdleTimeout?: number;
407
+ }
408
+
409
+ declare interface ReferenceImage {
410
+ base64: string;
411
+ rect?: Rect;
412
+ }
413
+
414
+ export declare function resizeImageForUiTars(imageBase64: string, size: Size): Promise<string>;
415
+
416
+ declare interface scrollParam {
417
+ direction: 'down' | 'up' | 'right' | 'left';
418
+ scrollType: 'once' | 'untilBottom' | 'untilTop' | 'untilRight' | 'untilLeft';
419
+ distance?: null | number; // distance in px
420
+ }
421
+
422
+ declare interface StreamingAIResponse {
423
+ /** The final accumulated content */
424
+ content: string;
425
+ /** Token usage information */
426
+ usage?: AIUsageInfo;
427
+ /** Whether the response was streamed */
428
+ isStreamed: boolean;
429
+ }
430
+
431
+ declare type StreamingCallback = (chunk: CodeGenerationChunk) => void;
432
+
433
+ declare interface StreamingCodeGenerationOptions {
434
+ /** Whether to enable streaming output */
435
+ stream?: boolean;
436
+ /** Callback function to handle streaming chunks */
437
+ onChunk?: StreamingCallback;
438
+ /** Callback function to handle streaming completion */
439
+ onComplete?: (finalCode: string) => void;
440
+ /** Callback function to handle streaming errors */
441
+ onError?: (error: Error) => void;
442
+ }
443
+
444
+ export declare function systemPromptToLocateElement(vlMode: ReturnType<typeof vlLocateMode>): string;
445
+
446
+ declare type TMultimodalPrompt = {
447
+ /**
448
+ * Support use image to inspect elements.
449
+ * The "images" field is an object that uses image name as key and image url as value.
450
+ * The image url can be a local path, a http link , or a base64 string.
451
+ */
452
+ images?: {
453
+ name: string;
454
+ url: string;
455
+ }[];
456
+ /**
457
+ * By default, the image url in the "images" filed starts with `https://` or `http://` will be directly sent to the LLM.
458
+ * In case the images are not accessible to the LLM (One common case is that image url is internal network only.), you can enable this option.
459
+ * Then image will be download and convert to base64 format.
460
+ */
461
+ convertHttpImage2Base64?: boolean;
462
+ };
463
+
464
+ declare type TUserPrompt =
465
+ | string
466
+ | ({
467
+ prompt: string;
468
+ } & Partial<TMultimodalPrompt>);
469
+
470
+ /**
471
+ * context
472
+ */
473
+
474
+ declare abstract class UIContext<ElementType extends BaseElement = BaseElement> {
475
+ abstract screenshotBase64: string;
476
+
477
+ abstract tree: ElementTreeNode<ElementType>;
478
+
479
+ abstract size: Size;
480
+ }
481
+
482
+ export declare function vlmPlanning(options: {
483
+ userInstruction: string;
484
+ conversationHistory: ChatCompletionMessageParam[];
485
+ size: {
486
+ width: number;
487
+ height: number;
488
+ };
489
+ }): Promise<{
490
+ actions: PlanningAction<any>[];
491
+ actionsFromModel: ReturnType<typeof actionParser>['parsed'];
492
+ action_summary: string;
493
+ yamlFlow?: MidsceneYamlFlowItem[];
494
+ usage?: AIUsageInfo;
495
+ rawResponse?: string;
496
+ }>;
497
+
498
+ declare interface YamlGenerationOptions {
499
+ testName?: string;
500
+ includeTimestamps?: boolean;
501
+ maxScreenshots?: number;
502
+ description?: string;
503
+ }
504
+
505
+ export { }