misoai-web 1.6.0 → 1.6.1
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/agent.js +105 -50
- package/dist/es/agent.js.map +1 -1
- package/dist/es/bridge-mode-browser.js +3 -3
- package/dist/es/bridge-mode-browser.js.map +1 -1
- package/dist/es/bridge-mode.js +107 -52
- package/dist/es/bridge-mode.js.map +1 -1
- package/dist/es/chrome-extension.js +106 -51
- package/dist/es/chrome-extension.js.map +1 -1
- package/dist/es/index.js +106 -51
- package/dist/es/index.js.map +1 -1
- package/dist/es/midscene-playground.js +108 -53
- package/dist/es/midscene-playground.js.map +1 -1
- package/dist/es/midscene-server.js +4 -4
- package/dist/es/midscene-server.js.map +1 -1
- package/dist/es/playground.js +105 -50
- package/dist/es/playground.js.map +1 -1
- package/dist/es/playwright-report.js +1 -1
- package/dist/es/playwright-report.js.map +1 -1
- package/dist/es/playwright.js +106 -51
- package/dist/es/playwright.js.map +1 -1
- package/dist/es/puppeteer-agent-launcher.js +105 -50
- package/dist/es/puppeteer-agent-launcher.js.map +1 -1
- package/dist/es/puppeteer.js +105 -50
- package/dist/es/puppeteer.js.map +1 -1
- package/dist/es/utils.js +1 -1
- package/dist/es/utils.js.map +1 -1
- package/dist/es/yaml.js +1 -1
- package/dist/es/yaml.js.map +1 -1
- package/dist/lib/agent.js +105 -50
- package/dist/lib/agent.js.map +1 -1
- package/dist/lib/bridge-mode-browser.js +3 -3
- package/dist/lib/bridge-mode-browser.js.map +1 -1
- package/dist/lib/bridge-mode.js +107 -52
- package/dist/lib/bridge-mode.js.map +1 -1
- package/dist/lib/chrome-extension.js +106 -51
- package/dist/lib/chrome-extension.js.map +1 -1
- package/dist/lib/index.js +106 -51
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/midscene-playground.js +108 -53
- package/dist/lib/midscene-playground.js.map +1 -1
- package/dist/lib/midscene-server.js +4 -4
- package/dist/lib/midscene-server.js.map +1 -1
- package/dist/lib/playground.js +105 -50
- package/dist/lib/playground.js.map +1 -1
- package/dist/lib/playwright-report.js +1 -1
- package/dist/lib/playwright-report.js.map +1 -1
- package/dist/lib/playwright.js +106 -51
- package/dist/lib/playwright.js.map +1 -1
- package/dist/lib/puppeteer-agent-launcher.js +105 -50
- package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
- package/dist/lib/puppeteer.js +105 -50
- package/dist/lib/puppeteer.js.map +1 -1
- package/dist/lib/utils.js +1 -1
- package/dist/lib/utils.js.map +1 -1
- package/dist/lib/yaml.js +1 -1
- package/dist/lib/yaml.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/playwright.d.ts +1 -1
- package/package.json +18 -54
@@ -38,23 +38,23 @@ var import_node_fs = require("fs");
|
|
38
38
|
var import_node_path = require("path");
|
39
39
|
|
40
40
|
// src/common/utils.ts
|
41
|
+
var import_dayjs = __toESM(require("dayjs"));
|
41
42
|
var import_ai_model = require("misoai-core/ai-model");
|
42
43
|
var import_utils = require("misoai-core/utils");
|
43
44
|
var import_env = require("misoai-shared/env");
|
44
45
|
var import_extractor = require("misoai-shared/extractor");
|
45
46
|
var import_img = require("misoai-shared/img");
|
46
47
|
var import_utils2 = require("misoai-shared/utils");
|
47
|
-
var import_dayjs = __toESM(require("dayjs"));
|
48
48
|
var ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED = "NOT_IMPLEMENTED_AS_DESIGNED";
|
49
49
|
|
50
50
|
// src/playground/server.ts
|
51
|
+
var import_cors = __toESM(require("cors"));
|
52
|
+
var import_dotenv = __toESM(require("dotenv"));
|
53
|
+
var import_express = __toESM(require("express"));
|
51
54
|
var import_utils4 = require("misoai-core/utils");
|
52
55
|
var import_constants = require("misoai-shared/constants");
|
53
56
|
var import_env2 = require("misoai-shared/env");
|
54
57
|
var import_utils5 = require("misoai-shared/utils");
|
55
|
-
var import_cors = __toESM(require("cors"));
|
56
|
-
var import_dotenv = __toESM(require("dotenv"));
|
57
|
-
var import_express = __toESM(require("express"));
|
58
58
|
var defaultPort = import_constants.PLAYGROUND_SERVER_PORT;
|
59
59
|
var errorHandler = (err, req, res, next) => {
|
60
60
|
console.error(err);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA2B;AAC3B,qBAAwD;AAExD,uBAAqB;;;ACKrB,sBAAiD;AACjD,mBAAuC;AACvC,iBAAsD;AAEtD,uBAKO;AACP,iBAAgC;AAEhC,IAAAA,gBAAqC;AACrC,mBAAkB;AAuIX,IAAM,yCACX;;;ADxJF,IAAAA,gBAA0B;AAC1B,uBAAuC;AACvC,IAAAC,cAAiC;AACjC,IAAAD,gBAA4B;AAC5B,kBAAiB;AACjB,oBAAmB;AACnB,qBAAoB;AAIpB,IAAM,cAAc;AAGpB,IAAM,eAAe,CAAC,KAAU,KAAU,KAAU,SAAc;AAChE,UAAQ,MAAM,GAAG;AACjB,MAAI,OAAO,GAAG,EAAE,KAAK;AAAA,IACnB,OAAO,IAAI;AAAA,EACb,CAAC;AACH;AAEA,IAAM,QAAQ,YAAY;AACxB,MAAI,CAAC,2BAAa;AAChB,UAAM,EAAE,OAAO,IAAI,cAAAE,QAAO,OAAO;AAEjC,QAAI,QAAQ;AACV,wCAAiB,MAAM;AAAA,IACzB;AAAA,EACF;AACF;AAEA,IAAqB,mBAArB,MAAsC;AAAA,EAcpC,YACE,WACA,YACA,YACA;AACA,SAAK,UAAM,eAAAC,SAAQ;AACnB,SAAK,aAAS,yBAAU;AACxB,SAAK,YAAY;AACjB,SAAK,aAAa;AAClB,SAAK,aAAa;AAClB,SAAK,mBAAmB,CAAC;AACzB,UAAM;AAAA,EACR;AAAA,EAEA,gBAAgBC,OAAc;AAC5B,eAAO,uBAAK,KAAK,QAAQ,GAAGA,KAAI,OAAO;AAAA,EACzC;AAAA,EAEA,gBAAgBA,OAAc,SAAiB;AAC7C,UAAM,UAAU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AAAA,QACH;AAEA,YAAI;AACF,4CAAiB,QAAQ;AAEzB,iBAAO,IAAI,KAAK;AAAA,YACd,QAAQ;AAAA,YACR,SAAS;AAAA,UACX,CAAC;AAAA,QACH,SAAS,OAAY;AACnB,kBAAQ,MAAM,+BAA+B,MAAM,OAAO,EAAE;AAC5D,iBAAO,IAAI,OAAO,GAAG,EAAE,KAAK;AAAA,YAC1B,OAAO,+BAA+B,MAAM,OAAO;AAAA,UACrD,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAGA,QAAI,KAAK,YAAY;AACnB,WAAK,IAAI,IAAI,KAAK,CAAC,KAAK,QAAQ;AAE9B,YAAI,SAAS,aAAa;AAAA,MAC5B,CAAC;AAED,WAAK,IAAI,IAAI,KAAK,CAAC,KAAK,QAAQ;AAC9B,cAAM,oBAAgB,uBAAK,KAAK,YAAa,IAAI,IAAI;AACrD,gBAAI,2BAAW,aAAa,GAAG;AAC7B,cAAI,SAAS,aAAa;AAAA,QAC5B,OAAO;AACL,cAAI,aAAS,uBAAK,KAAK,YAAa,YAAY,CAAC;AAAA,QACnD;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,YAAMG,QAAO,KAAK;AAClB,WAAK,SAAS,KAAK,IAAI,OAAOA,OAAM,MAAM;AACxC,gBAAQ,IAAI;AAAA,MACd,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA,EAEA,QAAQ;AAEN,QAAI,KAAK,QAAQ;AACf,aAAO,KAAK,OAAO,MAAM;AAAA,IAC3B;AAAA,EACF;AACF","names":["import_utils","import_env","dotenv","express","uuid","cors","port"],"ignoreList":[],"sources":["../../src/playground/server.ts","../../src/common/utils.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport type { Server } from 'node:http';\nimport { join } from 'node:path';\nimport { ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED } from '@/common/utils';\nimport { getTmpDir } from 'misoai-core/utils';\nimport { PLAYGROUND_SERVER_PORT } from 'misoai-shared/constants';\nimport { overrideAIConfig } from 'misoai-shared/env';\nimport { ifInBrowser } from 'misoai-shared/utils';\nimport cors from 'cors';\nimport dotenv from 'dotenv';\nimport express from 'express';\nimport type { PageAgent } from '../common/agent';\nimport type { AbstractPage } from '../page';\n\nconst defaultPort = PLAYGROUND_SERVER_PORT;\n// const staticPath = join(__dirname, '../../static');\n\nconst errorHandler = (err: any, req: any, res: any, next: any) => {\n console.error(err);\n res.status(500).json({\n error: err.message,\n });\n};\n\nconst setup = async () => {\n if (!ifInBrowser) {\n const { parsed } = dotenv.config();\n\n if (parsed) {\n overrideAIConfig(parsed);\n }\n }\n};\n\nexport default class PlaygroundServer {\n app: express.Application;\n tmpDir: string;\n server?: Server;\n port?: number | null;\n pageClass: new (\n ...args: any[]\n ) => AbstractPage;\n agentClass: new (\n ...args: any[]\n ) => PageAgent;\n staticPath?: string;\n taskProgressTips: Record<string, string>;\n\n constructor(\n pageClass: new (...args: any[]) => AbstractPage,\n agentClass: new (...args: any[]) => PageAgent,\n staticPath?: string,\n ) {\n this.app = express();\n this.tmpDir = getTmpDir()!;\n this.pageClass = pageClass;\n this.agentClass = agentClass;\n this.staticPath = staticPath;\n this.taskProgressTips = {};\n setup();\n }\n\n filePathForUuid(uuid: string) {\n return join(this.tmpDir, `${uuid}.json`);\n }\n\n saveContextFile(uuid: string, context: string) {\n const tmpFile = this.filePathForUuid(uuid);\n console.log(`save context file: ${tmpFile}`);\n writeFileSync(tmpFile, context);\n return tmpFile;\n }\n\n async launch(port?: number) {\n this.port = port || defaultPort;\n this.app.use(errorHandler);\n\n this.app.use(\n cors({\n origin: '*',\n credentials: true,\n }),\n );\n\n this.app.get('/status', cors(), async (req, res) => {\n // const modelName = g\n res.send({\n status: 'ok',\n });\n });\n\n // this.app.get('/playground/:uuid', async (req, res) => {\n // res.sendFile(join(staticPath, 'index.html'));\n // });\n\n this.app.get('/context/:uuid', async (req, res) => {\n const { uuid } = req.params;\n const contextFile = this.filePathForUuid(uuid);\n\n if (!existsSync(contextFile)) {\n return res.status(404).json({\n error: 'Context not found',\n });\n }\n\n const context = readFileSync(contextFile, 'utf8');\n res.json({\n context,\n });\n });\n\n this.app.get('/task-progress/:requestId', cors(), async (req, res) => {\n const { requestId } = req.params;\n res.json({\n tip: this.taskProgressTips[requestId] || '',\n });\n });\n\n // -------------------------\n // actions from report file\n this.app.post(\n '/playground-with-context',\n express.json({ limit: '50mb' }),\n async (req, res) => {\n const context = req.body.context;\n\n if (!context) {\n return res.status(400).json({\n error: 'context is required',\n });\n }\n\n const uuid = randomUUID();\n this.saveContextFile(uuid, context);\n return res.json({\n location: `/playground/${uuid}`,\n uuid,\n });\n },\n );\n\n this.app.post(\n '/execute',\n express.json({ limit: '30mb' }),\n async (req, res) => {\n const { context, type, prompt, requestId, deepThink } = req.body;\n\n if (!context) {\n return res.status(400).json({\n error: 'context is required',\n });\n }\n\n if (!type) {\n return res.status(400).json({\n error: 'type is required',\n });\n }\n\n if (!prompt) {\n return res.status(400).json({\n error: 'prompt is required',\n });\n }\n\n // build an agent with context\n const page = new this.pageClass(context);\n const agent = new this.agentClass(page);\n\n if (requestId) {\n this.taskProgressTips[requestId] = '';\n\n agent.onTaskStartTip = (tip: string) => {\n this.taskProgressTips[requestId] = tip;\n };\n }\n\n const response: {\n result: any;\n dump: string | null;\n error: string | null;\n reportHTML: string | null;\n requestId?: string;\n } = {\n result: null,\n dump: null,\n error: null,\n reportHTML: null,\n requestId,\n };\n\n const startTime = Date.now();\n try {\n if (type === 'aiQuery') {\n response.result = await agent.aiQuery(prompt);\n } else if (type === 'aiAction') {\n response.result = await agent.aiAction(prompt);\n } else if (type === 'aiAssert') {\n response.result = await agent.aiAssert(prompt, undefined, {\n keepRawResponse: true,\n });\n } else if (type === 'aiTap') {\n response.result = await agent.aiTap(prompt, {\n deepThink,\n });\n } else {\n response.error = `Unknown type: ${type}`;\n }\n } catch (error: any) {\n if (!error.message.includes(ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED)) {\n response.error = error.message;\n }\n }\n\n try {\n response.dump = JSON.parse(agent.dumpDataString());\n response.reportHTML = agent.reportHTMLString() || null;\n\n agent.writeOutActionDumps();\n } catch (error: any) {\n console.error(\n `write out dump failed: requestId: ${requestId}, ${error.message}`,\n );\n }\n\n res.send(response);\n const timeCost = Date.now() - startTime;\n\n if (response.error) {\n console.error(\n `handle request failed after ${timeCost}ms: requestId: ${requestId}, ${response.error}`,\n );\n } else {\n console.log(\n `handle request done after ${timeCost}ms: requestId: ${requestId}`,\n );\n }\n },\n );\n\n this.app.post(\n '/config',\n express.json({ limit: '1mb' }),\n async (req, res) => {\n const { aiConfig } = req.body;\n\n if (!aiConfig || typeof aiConfig !== 'object') {\n return res.status(400).json({\n error: 'aiConfig is required and must be an object',\n });\n }\n\n try {\n overrideAIConfig(aiConfig);\n\n return res.json({\n status: 'ok',\n message: 'AI config updated successfully',\n });\n } catch (error: any) {\n console.error(`Failed to update AI config: ${error.message}`);\n return res.status(500).json({\n error: `Failed to update AI config: ${error.message}`,\n });\n }\n },\n );\n\n // Set up static file serving after all API routes are defined\n if (this.staticPath) {\n this.app.get('/', (req, res) => {\n // compatible with windows\n res.redirect('/index.html');\n });\n\n this.app.get('*', (req, res) => {\n const requestedPath = join(this.staticPath!, req.path);\n if (existsSync(requestedPath)) {\n res.sendFile(requestedPath);\n } else {\n res.sendFile(join(this.staticPath!, 'index.html'));\n }\n });\n }\n\n return new Promise((resolve, reject) => {\n const port = this.port;\n this.server = this.app.listen(port, () => {\n resolve(this);\n });\n });\n }\n\n close() {\n // close the server\n if (this.server) {\n return this.server.close();\n }\n }\n}\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, isVisible } =\n elementInfo;\n return new WebElementInfo({\n rect,\n locator,\n id,\n content,\n attributes,\n indexId,\n isVisible,\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 // Only replace characters that are illegal in filenames, but preserve path separators\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"]}
|
1
|
+
{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA2B;AAC3B,qBAAwD;AAExD,uBAAqB;;;ACFrB,mBAAkB;AAQlB,sBAAiD;AACjD,mBAAuC;AACvC,iBAAsD;AAEtD,uBAKO;AACP,iBAAgC;AAEhC,IAAAA,gBAAqC;AAuI9B,IAAM,yCACX;;;ADxJF,kBAAiB;AACjB,oBAAmB;AACnB,qBAAoB;AACpB,IAAAA,gBAA0B;AAC1B,uBAAuC;AACvC,IAAAC,cAAiC;AACjC,IAAAD,gBAA4B;AAI5B,IAAM,cAAc;AAGpB,IAAM,eAA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BAAW,aAAa,GAAG;AAC7B,cAAI,SAAS,aAAa;AAAA,QAC5B,OAAO;AACL,cAAI,aAAS,uBAAK,KAAK,YAAa,YAAY,CAAC;AAAA,QACnD;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,YAAMG,QAAO,KAAK;AAClB,WAAK,SAAS,KAAK,IAAI,OAAOA,OAAM,MAAM;AACxC,gBAAQ,IAAI;AAAA,MACd,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA,EAEA,QAAQ;AAEN,QAAI,KAAK,QAAQ;AACf,aAAO,KAAK,OAAO,MAAM;AAAA,IAC3B;AAAA,EACF;AACF","names":["import_utils","import_env","dotenv","express","uuid","cors","port"],"ignoreList":[],"sources":["../../src/playground/server.ts","../../src/common/utils.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport type { Server } from 'node:http';\nimport { join } from 'node:path';\nimport { ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED } from '@/common/utils';\nimport cors from 'cors';\nimport dotenv from 'dotenv';\nimport express from 'express';\nimport { getTmpDir } from 'misoai-core/utils';\nimport { PLAYGROUND_SERVER_PORT } from 'misoai-shared/constants';\nimport { overrideAIConfig } from 'misoai-shared/env';\nimport { ifInBrowser } from 'misoai-shared/utils';\nimport type { PageAgent } from '../common/agent';\nimport type { AbstractPage } from '../page';\n\nconst defaultPort = PLAYGROUND_SERVER_PORT;\n// const staticPath = join(__dirname, '../../static');\n\nconst errorHandler = (err: any, req: any, res: any, next: any) => {\n console.error(err);\n res.status(500).json({\n error: err.message,\n });\n};\n\nconst setup = async () => {\n if (!ifInBrowser) {\n const { parsed } = dotenv.config();\n\n if (parsed) {\n overrideAIConfig(parsed);\n }\n }\n};\n\nexport default class PlaygroundServer {\n app: express.Application;\n tmpDir: string;\n server?: Server;\n port?: number | null;\n pageClass: new (\n ...args: any[]\n ) => AbstractPage;\n agentClass: new (\n ...args: any[]\n ) => PageAgent;\n staticPath?: string;\n taskProgressTips: Record<string, string>;\n\n constructor(\n pageClass: new (...args: any[]) => AbstractPage,\n agentClass: new (...args: any[]) => PageAgent,\n staticPath?: string,\n ) {\n this.app = express();\n this.tmpDir = getTmpDir()!;\n this.pageClass = pageClass;\n this.agentClass = agentClass;\n this.staticPath = staticPath;\n this.taskProgressTips = {};\n setup();\n }\n\n filePathForUuid(uuid: string) {\n return join(this.tmpDir, `${uuid}.json`);\n }\n\n saveContextFile(uuid: string, context: string) {\n const tmpFile = this.filePathForUuid(uuid);\n console.log(`save context file: ${tmpFile}`);\n writeFileSync(tmpFile, context);\n return tmpFile;\n }\n\n async launch(port?: number) {\n this.port = port || defaultPort;\n this.app.use(errorHandler);\n\n this.app.use(\n cors({\n origin: '*',\n credentials: true,\n }),\n );\n\n this.app.get('/status', cors(), async (req, res) => {\n // const modelName = g\n res.send({\n status: 'ok',\n });\n });\n\n // this.app.get('/playground/:uuid', async (req, res) => {\n // res.sendFile(join(staticPath, 'index.html'));\n // });\n\n this.app.get('/context/:uuid', async (req, res) => {\n const { uuid } = req.params;\n const contextFile = this.filePathForUuid(uuid);\n\n if (!existsSync(contextFile)) {\n return res.status(404).json({\n error: 'Context not found',\n });\n }\n\n const context = readFileSync(contextFile, 'utf8');\n res.json({\n context,\n });\n });\n\n this.app.get('/task-progress/:requestId', cors(), async (req, res) => {\n const { requestId } = req.params;\n res.json({\n tip: this.taskProgressTips[requestId] || '',\n });\n });\n\n // -------------------------\n // actions from report file\n this.app.post(\n '/playground-with-context',\n express.json({ limit: '50mb' }),\n async (req, res) => {\n const context = req.body.context;\n\n if (!context) {\n return res.status(400).json({\n error: 'context is required',\n });\n }\n\n const uuid = randomUUID();\n this.saveContextFile(uuid, context);\n return res.json({\n location: `/playground/${uuid}`,\n uuid,\n });\n },\n );\n\n this.app.post(\n '/execute',\n express.json({ limit: '30mb' }),\n async (req, res) => {\n const { context, type, prompt, requestId, deepThink } = req.body;\n\n if (!context) {\n return res.status(400).json({\n error: 'context is required',\n });\n }\n\n if (!type) {\n return res.status(400).json({\n error: 'type is required',\n });\n }\n\n if (!prompt) {\n return res.status(400).json({\n error: 'prompt is required',\n });\n }\n\n // build an agent with context\n const page = new this.pageClass(context);\n const agent = new this.agentClass(page);\n\n if (requestId) {\n this.taskProgressTips[requestId] = '';\n\n agent.onTaskStartTip = (tip: string) => {\n this.taskProgressTips[requestId] = tip;\n };\n }\n\n const response: {\n result: any;\n dump: string | null;\n error: string | null;\n reportHTML: string | null;\n requestId?: string;\n } = {\n result: null,\n dump: null,\n error: null,\n reportHTML: null,\n requestId,\n };\n\n const startTime = Date.now();\n try {\n if (type === 'aiQuery') {\n response.result = await agent.aiQuery(prompt);\n } else if (type === 'aiAction') {\n response.result = await agent.aiAction(prompt);\n } else if (type === 'aiAssert') {\n response.result = await agent.aiAssert(prompt, undefined, {\n keepRawResponse: true,\n });\n } else if (type === 'aiTap') {\n response.result = await agent.aiTap(prompt, {\n deepThink,\n });\n } else {\n response.error = `Unknown type: ${type}`;\n }\n } catch (error: any) {\n if (!error.message.includes(ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED)) {\n response.error = error.message;\n }\n }\n\n try {\n response.dump = JSON.parse(agent.dumpDataString());\n response.reportHTML = agent.reportHTMLString() || null;\n\n agent.writeOutActionDumps();\n } catch (error: any) {\n console.error(\n `write out dump failed: requestId: ${requestId}, ${error.message}`,\n );\n }\n\n res.send(response);\n const timeCost = Date.now() - startTime;\n\n if (response.error) {\n console.error(\n `handle request failed after ${timeCost}ms: requestId: ${requestId}, ${response.error}`,\n );\n } else {\n console.log(\n `handle request done after ${timeCost}ms: requestId: ${requestId}`,\n );\n }\n },\n );\n\n this.app.post(\n '/config',\n express.json({ limit: '1mb' }),\n async (req, res) => {\n const { aiConfig } = req.body;\n\n if (!aiConfig || typeof aiConfig !== 'object') {\n return res.status(400).json({\n error: 'aiConfig is required and must be an object',\n });\n }\n\n try {\n overrideAIConfig(aiConfig);\n\n return res.json({\n status: 'ok',\n message: 'AI config updated successfully',\n });\n } catch (error: any) {\n console.error(`Failed to update AI config: ${error.message}`);\n return res.status(500).json({\n error: `Failed to update AI config: ${error.message}`,\n });\n }\n },\n );\n\n // Set up static file serving after all API routes are defined\n if (this.staticPath) {\n this.app.get('/', (req, res) => {\n // compatible with windows\n res.redirect('/index.html');\n });\n\n this.app.get('*', (req, res) => {\n const requestedPath = join(this.staticPath!, req.path);\n if (existsSync(requestedPath)) {\n res.sendFile(requestedPath);\n } else {\n res.sendFile(join(this.staticPath!, 'index.html'));\n }\n });\n }\n\n return new Promise((resolve, reject) => {\n const port = this.port;\n this.server = this.app.listen(port, () => {\n resolve(this);\n });\n });\n }\n\n close() {\n // close the server\n if (this.server) {\n return this.server.close();\n }\n }\n}\n","import type { StaticPage } from '@/playground';\nimport dayjs from 'dayjs';\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 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, isVisible } =\n elementInfo;\n return new WebElementInfo({\n rect,\n locator,\n id,\n content,\n attributes,\n indexId,\n isVisible,\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 // Only replace characters that are illegal in filenames, but preserve path separators\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"]}
|
package/dist/lib/playground.js
CHANGED
@@ -37,13 +37,13 @@ __export(playground_exports, {
|
|
37
37
|
module.exports = __toCommonJS(playground_exports);
|
38
38
|
|
39
39
|
// src/common/utils.ts
|
40
|
+
var import_dayjs = __toESM(require("dayjs"));
|
40
41
|
var import_ai_model = require("misoai-core/ai-model");
|
41
42
|
var import_utils = require("misoai-core/utils");
|
42
43
|
var import_env = require("misoai-shared/env");
|
43
44
|
var import_extractor = require("misoai-shared/extractor");
|
44
45
|
var import_img = require("misoai-shared/img");
|
45
46
|
var import_utils2 = require("misoai-shared/utils");
|
46
|
-
var import_dayjs = __toESM(require("dayjs"));
|
47
47
|
|
48
48
|
// src/web-element.ts
|
49
49
|
var WebElementInfo = class {
|
@@ -462,8 +462,8 @@ var ScriptPlayer = class {
|
|
462
462
|
var import_js_yaml = __toESM(require("js-yaml"));
|
463
463
|
|
464
464
|
// src/yaml/utils.ts
|
465
|
-
var import_utils4 = require("misoai-shared/utils");
|
466
465
|
var import_js_yaml2 = __toESM(require("js-yaml"));
|
466
|
+
var import_utils4 = require("misoai-shared/utils");
|
467
467
|
function interpolateEnvVars(content) {
|
468
468
|
return content.replace(/\$\{([^}]+)\}/g, (_, envVar) => {
|
469
469
|
const value = process.env[envVar.trim()];
|
@@ -639,8 +639,12 @@ var WorkflowMemory = class {
|
|
639
639
|
const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
640
640
|
workflow.memory = [...memory];
|
641
641
|
workflow.metadata.totalSteps = workflow.steps.length;
|
642
|
-
workflow.metadata.completedSteps = workflow.steps.filter(
|
643
|
-
|
642
|
+
workflow.metadata.completedSteps = workflow.steps.filter(
|
643
|
+
(s) => s.status === "completed"
|
644
|
+
).length;
|
645
|
+
workflow.metadata.failedSteps = workflow.steps.filter(
|
646
|
+
(s) => s.status === "failed"
|
647
|
+
).length;
|
644
648
|
this.workflows.set(workflowId, workflow);
|
645
649
|
this.enforceRetentionPolicy();
|
646
650
|
}
|
@@ -651,7 +655,9 @@ var WorkflowMemory = class {
|
|
651
655
|
const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
652
656
|
workflow.context = { ...workflow.context, ...context };
|
653
657
|
if (context.currentStep) {
|
654
|
-
const existingStep = workflow.steps.find(
|
658
|
+
const existingStep = workflow.steps.find(
|
659
|
+
(s) => s.stepName === context.currentStep
|
660
|
+
);
|
655
661
|
if (!existingStep) {
|
656
662
|
workflow.steps.push({
|
657
663
|
stepId: `step_${workflow.steps.length + 1}`,
|
@@ -696,7 +702,9 @@ var WorkflowMemory = class {
|
|
696
702
|
enforceRetentionPolicy() {
|
697
703
|
const maxWorkflows = 10;
|
698
704
|
if (this.workflows.size > maxWorkflows) {
|
699
|
-
const sortedWorkflows = Array.from(this.workflows.entries()).sort(
|
705
|
+
const sortedWorkflows = Array.from(this.workflows.entries()).sort(
|
706
|
+
([, a], [, b]) => (b.metadata.endTime || b.metadata.startTime) - (a.metadata.endTime || a.metadata.startTime)
|
707
|
+
);
|
700
708
|
const toDelete = sortedWorkflows.slice(maxWorkflows);
|
701
709
|
toDelete.forEach(([workflowId]) => this.workflows.delete(workflowId));
|
702
710
|
}
|
@@ -1435,7 +1443,9 @@ var PageTaskExecutor = class {
|
|
1435
1443
|
*/
|
1436
1444
|
getPersistentExecutor() {
|
1437
1445
|
if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
|
1438
|
-
const previousMemory = this.workflowMemory.getWorkflowMemory(
|
1446
|
+
const previousMemory = this.workflowMemory.getWorkflowMemory(
|
1447
|
+
this.sessionContext.workflowId
|
1448
|
+
);
|
1439
1449
|
this.persistentExecutor = new import_misoai_core.Executor("Persistent Task Executor", {
|
1440
1450
|
onTaskStart: this.onTaskStartCallback,
|
1441
1451
|
initialMemory: previousMemory
|
@@ -1464,7 +1474,9 @@ var PageTaskExecutor = class {
|
|
1464
1474
|
if (this.persistentExecutor) {
|
1465
1475
|
this.persistentExecutor.clearMemory();
|
1466
1476
|
}
|
1467
|
-
this.workflowMemory.clearWorkflow(
|
1477
|
+
this.workflowMemory.clearWorkflow(
|
1478
|
+
this.sessionContext.workflowId || "default"
|
1479
|
+
);
|
1468
1480
|
}
|
1469
1481
|
/**
|
1470
1482
|
* Mevcut hafızayı döndürür
|
@@ -1476,7 +1488,9 @@ var PageTaskExecutor = class {
|
|
1476
1488
|
* İş akışı hafızasını döndürür
|
1477
1489
|
*/
|
1478
1490
|
getWorkflowMemory() {
|
1479
|
-
return this.workflowMemory.getWorkflowData(
|
1491
|
+
return this.workflowMemory.getWorkflowData(
|
1492
|
+
this.sessionContext.workflowId || "default"
|
1493
|
+
);
|
1480
1494
|
}
|
1481
1495
|
/**
|
1482
1496
|
* Hafıza istatistiklerini döndürür
|
@@ -1484,7 +1498,13 @@ var PageTaskExecutor = class {
|
|
1484
1498
|
getMemoryStats() {
|
1485
1499
|
return this.persistentExecutor?.getMemoryStats() || {
|
1486
1500
|
totalItems: 0,
|
1487
|
-
analytics: {
|
1501
|
+
analytics: {
|
1502
|
+
totalTasks: 0,
|
1503
|
+
memoryHits: 0,
|
1504
|
+
memoryMisses: 0,
|
1505
|
+
averageMemorySize: 0,
|
1506
|
+
memoryEffectiveness: 0
|
1507
|
+
},
|
1488
1508
|
config: this.memoryConfig
|
1489
1509
|
};
|
1490
1510
|
}
|
@@ -1520,11 +1540,14 @@ var PageTaskExecutor = class {
|
|
1520
1540
|
let taskExecutor;
|
1521
1541
|
if (useMemory) {
|
1522
1542
|
taskExecutor = this.getPersistentExecutor();
|
1523
|
-
this.workflowMemory.updateWorkflowContext(
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1543
|
+
this.workflowMemory.updateWorkflowContext(
|
1544
|
+
{
|
1545
|
+
currentStep: title,
|
1546
|
+
pageInfo: this.sessionContext.pageInfo,
|
1547
|
+
timestamp: Date.now()
|
1548
|
+
},
|
1549
|
+
this.sessionContext.workflowId || "default"
|
1550
|
+
);
|
1528
1551
|
} else {
|
1529
1552
|
taskExecutor = new import_misoai_core.Executor(title, {
|
1530
1553
|
onTaskStart: this.onTaskStartCallback
|
@@ -1890,14 +1913,19 @@ var PageTaskExecutor = class {
|
|
1890
1913
|
*/
|
1891
1914
|
addToMemory(memoryItem) {
|
1892
1915
|
if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
|
1893
|
-
const previousMemory = this.workflowMemory.getWorkflowMemory(
|
1916
|
+
const previousMemory = this.workflowMemory.getWorkflowMemory(
|
1917
|
+
this.sessionContext.workflowId
|
1918
|
+
);
|
1894
1919
|
this.persistentExecutor = new import_misoai_core.Executor("Persistent Task Executor", {
|
1895
1920
|
onTaskStart: this.onTaskStartCallback,
|
1896
1921
|
initialMemory: previousMemory
|
1897
1922
|
});
|
1898
1923
|
}
|
1899
1924
|
this.persistentExecutor.memoryStore?.add(memoryItem);
|
1900
|
-
this.persistentExecutor.memoryAnalytics?.recordMemoryOperation(
|
1925
|
+
this.persistentExecutor.memoryAnalytics?.recordMemoryOperation(
|
1926
|
+
"add",
|
1927
|
+
memoryItem
|
1928
|
+
);
|
1901
1929
|
}
|
1902
1930
|
};
|
1903
1931
|
|
@@ -1986,14 +2014,14 @@ function buildPlans(type, locateParam, param) {
|
|
1986
2014
|
var import_node_assert = __toESM(require("assert"));
|
1987
2015
|
var import_node_fs2 = require("fs");
|
1988
2016
|
var import_node_path2 = require("path");
|
2017
|
+
var import_js_yaml3 = __toESM(require("js-yaml"));
|
1989
2018
|
var import_common2 = require("misoai-shared/common");
|
1990
2019
|
var import_logger3 = require("misoai-shared/logger");
|
1991
2020
|
var import_utils9 = require("misoai-shared/utils");
|
1992
|
-
var import_js_yaml3 = __toESM(require("js-yaml"));
|
1993
2021
|
var import_semver = __toESM(require("semver"));
|
1994
2022
|
|
1995
2023
|
// package.json
|
1996
|
-
var version = "1.6.
|
2024
|
+
var version = "1.6.1";
|
1997
2025
|
|
1998
2026
|
// src/common/task-cache.ts
|
1999
2027
|
var debug3 = (0, import_logger3.getDebug)("cache");
|
@@ -2288,22 +2316,28 @@ var PageAgent = class {
|
|
2288
2316
|
const allThoughts = executor.tasks.filter((task) => task.thought).map((task) => task.thought);
|
2289
2317
|
const allLocates = executor.tasks.filter((task) => task.locate).map((task) => task.locate);
|
2290
2318
|
const allPlans = executor.tasks.filter((task) => task.param?.plans).map((task) => task.param?.plans);
|
2291
|
-
const planningTasks = executor.tasks.filter(
|
2292
|
-
|
2319
|
+
const planningTasks = executor.tasks.filter(
|
2320
|
+
(task) => task.type === "Planning"
|
2321
|
+
);
|
2322
|
+
const insightTasks = executor.tasks.filter(
|
2323
|
+
(task) => task.type === "Insight"
|
2324
|
+
);
|
2293
2325
|
const actionTasks = executor.tasks.filter((task) => task.type === "Action");
|
2294
2326
|
const planning = planningTasks.length > 0 ? {
|
2295
2327
|
type: "Planning",
|
2296
|
-
description:
|
2328
|
+
description: "Planning for task execution",
|
2297
2329
|
steps: planningTasks.map((task) => task.thought || "Planning step")
|
2298
2330
|
} : void 0;
|
2299
2331
|
const insight = insightTasks.length > 0 ? {
|
2300
2332
|
type: "Insight",
|
2301
|
-
description:
|
2302
|
-
elements: insightTasks.map(
|
2333
|
+
description: "Insight for task execution",
|
2334
|
+
elements: insightTasks.map(
|
2335
|
+
(task) => task.thought || "Insight element"
|
2336
|
+
)
|
2303
2337
|
} : void 0;
|
2304
2338
|
const action = actionTasks.length > 0 ? {
|
2305
2339
|
type: "Action",
|
2306
|
-
description:
|
2340
|
+
description: "Action for task execution",
|
2307
2341
|
result: lastTask?.output
|
2308
2342
|
} : void 0;
|
2309
2343
|
const actionDetails = executor.tasks.map((task) => ({
|
@@ -2637,7 +2671,10 @@ ${memoryContext}` : void 0;
|
|
2637
2671
|
}
|
2638
2672
|
const memoryContext = this.getMemoryAsContext();
|
2639
2673
|
const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
|
2640
|
-
const { output, executor } = await this.taskExecutor.assert(
|
2674
|
+
const { output, executor } = await this.taskExecutor.assert(
|
2675
|
+
assertionWithContext,
|
2676
|
+
memoryContext
|
2677
|
+
);
|
2641
2678
|
const metadata = this.afterTaskRunning(executor, true);
|
2642
2679
|
if (output && opt?.keepRawResponse) {
|
2643
2680
|
return {
|
@@ -2676,7 +2713,10 @@ A complex CAPTCHA typically has one or more of these characteristics:
|
|
2676
2713
|
Return only "complex" or "simple" based on your analysis.
|
2677
2714
|
`;
|
2678
2715
|
const complexityMsgs = [
|
2679
|
-
{
|
2716
|
+
{
|
2717
|
+
role: "system",
|
2718
|
+
content: "You are an AI assistant that analyzes screenshots to determine CAPTCHA complexity."
|
2719
|
+
},
|
2680
2720
|
{
|
2681
2721
|
role: "user",
|
2682
2722
|
content: [
|
@@ -2700,7 +2740,12 @@ Return only "complex" or "simple" based on your analysis.
|
|
2700
2740
|
);
|
2701
2741
|
const responseText = typeof complexityResult.content === "string" ? complexityResult.content.toLowerCase() : JSON.stringify(complexityResult.content).toLowerCase();
|
2702
2742
|
shouldUseDeepThink = responseText.includes("complex");
|
2703
|
-
debug4(
|
2743
|
+
debug4(
|
2744
|
+
"CAPTCHA complexity analysis:",
|
2745
|
+
responseText,
|
2746
|
+
"Using deep think:",
|
2747
|
+
shouldUseDeepThink
|
2748
|
+
);
|
2704
2749
|
} catch (error) {
|
2705
2750
|
debug4("Failed to analyze CAPTCHA complexity:", error);
|
2706
2751
|
}
|
@@ -2717,7 +2762,9 @@ Return only "complex" or "simple" based on your analysis.
|
|
2717
2762
|
await this.aiTap(action.target, { deepThink: shouldUseDeepThink });
|
2718
2763
|
} else if (action.type === "input" && action.value) {
|
2719
2764
|
if (action.target) {
|
2720
|
-
await this.aiInput(action.value, action.target, {
|
2765
|
+
await this.aiInput(action.value, action.target, {
|
2766
|
+
deepThink: shouldUseDeepThink
|
2767
|
+
});
|
2721
2768
|
}
|
2722
2769
|
} else if (action.type === "verify" && action.target) {
|
2723
2770
|
await this.aiTap(action.target, { deepThink: shouldUseDeepThink });
|
@@ -2729,7 +2776,9 @@ Return only "complex" or "simple" based on your analysis.
|
|
2729
2776
|
if (action.coordinates) {
|
2730
2777
|
const x = action.coordinates[0];
|
2731
2778
|
const y = action.coordinates[1];
|
2732
|
-
await this.aiTap(`element at coordinates (${x}, ${y})`, {
|
2779
|
+
await this.aiTap(`element at coordinates (${x}, ${y})`, {
|
2780
|
+
deepThink: shouldUseDeepThink
|
2781
|
+
});
|
2733
2782
|
} else if (action.target) {
|
2734
2783
|
await this.aiTap(action.target, { deepThink: shouldUseDeepThink });
|
2735
2784
|
}
|
@@ -2881,25 +2930,27 @@ ${errors}`);
|
|
2881
2930
|
const executionDump = {
|
2882
2931
|
name: screenshotTitle,
|
2883
2932
|
description: content,
|
2884
|
-
tasks: [
|
2885
|
-
|
2886
|
-
|
2887
|
-
|
2888
|
-
|
2889
|
-
|
2890
|
-
|
2891
|
-
|
2892
|
-
|
2893
|
-
|
2894
|
-
|
2895
|
-
|
2896
|
-
|
2897
|
-
|
2898
|
-
|
2899
|
-
|
2900
|
-
|
2933
|
+
tasks: [
|
2934
|
+
{
|
2935
|
+
type: "Screenshot",
|
2936
|
+
subType: "log",
|
2937
|
+
status: "finished",
|
2938
|
+
executor: null,
|
2939
|
+
param: {
|
2940
|
+
title: screenshotTitle,
|
2941
|
+
content
|
2942
|
+
},
|
2943
|
+
output: {
|
2944
|
+
screenshot
|
2945
|
+
},
|
2946
|
+
thought: `Logged screenshot: ${screenshotTitle}`,
|
2947
|
+
timing: {
|
2948
|
+
start: Date.now(),
|
2949
|
+
end: Date.now(),
|
2950
|
+
cost: 0
|
2951
|
+
}
|
2901
2952
|
}
|
2902
|
-
|
2953
|
+
],
|
2903
2954
|
sdkVersion: "1.0.0",
|
2904
2955
|
logTime: Date.now(),
|
2905
2956
|
model_name: "screenshot"
|
@@ -2951,7 +3002,9 @@ ${errors}`);
|
|
2951
3002
|
totalTasks: stats.analytics.totalTasks,
|
2952
3003
|
memoryHits: stats.analytics.memoryHits,
|
2953
3004
|
memoryMisses: stats.analytics.memoryMisses,
|
2954
|
-
memoryEffectiveness: Math.round(
|
3005
|
+
memoryEffectiveness: Math.round(
|
3006
|
+
stats.analytics.memoryEffectiveness * 100
|
3007
|
+
),
|
2955
3008
|
averageMemorySize: Math.round(stats.analytics.averageMemorySize * 100) / 100
|
2956
3009
|
},
|
2957
3010
|
config: stats.config,
|
@@ -3015,7 +3068,9 @@ ${errors}`);
|
|
3015
3068
|
calculateSuccessRate(memory) {
|
3016
3069
|
if (memory.length === 0)
|
3017
3070
|
return 0;
|
3018
|
-
const successCount = memory.filter(
|
3071
|
+
const successCount = memory.filter(
|
3072
|
+
(item) => item.metadata?.success !== false
|
3073
|
+
).length;
|
3019
3074
|
return Math.round(successCount / memory.length * 100);
|
3020
3075
|
}
|
3021
3076
|
calculateAverageExecutionTime(memory) {
|