@midscene/core 0.24.1 → 0.24.2-beta-20250730123854.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.d.ts +3 -3
- package/dist/es/ai-model.js +1 -1
- package/dist/es/{chunk-TV47VKQ7.js → chunk-3LFZDNMQ.js} +80 -12
- package/dist/es/chunk-3LFZDNMQ.js.map +1 -0
- package/dist/es/{chunk-HUEQURIG.js → chunk-M4OYNEBY.js} +3 -3
- package/dist/es/index.d.ts +4 -4
- package/dist/es/index.js +12 -4
- package/dist/es/index.js.map +1 -1
- package/dist/es/{llm-planning-3407bd42.d.ts → llm-planning-ae19dc49.d.ts} +2 -1
- package/dist/es/{types-4d9c9a85.d.ts → types-d187efec.d.ts} +19 -2
- package/dist/es/utils.d.ts +1 -1
- package/dist/es/utils.js +1 -1
- package/dist/lib/ai-model.d.ts +3 -3
- package/dist/lib/ai-model.js +2 -2
- package/dist/lib/{chunk-TV47VKQ7.js → chunk-3LFZDNMQ.js} +80 -12
- package/dist/lib/chunk-3LFZDNMQ.js.map +1 -0
- package/dist/lib/{chunk-HUEQURIG.js → chunk-M4OYNEBY.js} +3 -3
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +21 -13
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/{llm-planning-3407bd42.d.ts → llm-planning-ae19dc49.d.ts} +2 -1
- package/dist/{types/types-4d9c9a85.d.ts → lib/types-d187efec.d.ts} +19 -2
- package/dist/lib/utils.d.ts +1 -1
- package/dist/lib/utils.js +2 -2
- package/dist/types/ai-model.d.ts +3 -3
- package/dist/types/index.d.ts +4 -4
- package/dist/types/{llm-planning-3407bd42.d.ts → llm-planning-ae19dc49.d.ts} +2 -1
- package/dist/{lib/types-4d9c9a85.d.ts → types/types-d187efec.d.ts} +19 -2
- package/dist/types/utils.d.ts +1 -1
- package/package.json +3 -3
- package/dist/es/chunk-TV47VKQ7.js.map +0 -1
- package/dist/lib/chunk-TV47VKQ7.js.map +0 -1
- /package/dist/es/{chunk-HUEQURIG.js.map → chunk-M4OYNEBY.js.map} +0 -0
- /package/dist/lib/{chunk-HUEQURIG.js.map → chunk-M4OYNEBY.js.map} +0 -0
package/dist/es/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { E as ExecutionTask, a as ExecutionTaskProgressOptions, b as ExecutionTaskApply, c as ExecutionDump, U as UIContext, I as InsightAction, D as DumpSubscriber, d as InsightTaskInfo, e as InsightOptions, f as DetailedLocateParam, L as LocateResult, g as InsightExtractOption, h as InsightAssertionResponse, A as AIDescribeElementResponse } from './types-
|
|
2
|
-
export { w as AIAssertionResponse, u as AIDataExtractionResponse, s as AIElementCoordinatesResponse, r as AIElementLocatorResponse, t as AIElementResponse, n as AIResponseFormat, v as AISectionLocatorResponse, q as AISingleElementResponse, o as AISingleElementResponseById, p as AISingleElementResponseByPosition, m as AIUsageInfo, S as AgentAssertOpt, z as AgentDescribeElementAtPointResult, Q as AgentWaitForOpt,
|
|
3
|
-
import { c as callAiFn } from './llm-planning-
|
|
4
|
-
export { a as AiAssert, A as AiLocateElement, d as describeUserPage, p as plan } from './llm-planning-
|
|
1
|
+
import { E as ExecutionTask, a as ExecutionTaskProgressOptions, b as ExecutionTaskApply, c as ExecutionDump, U as UIContext, I as InsightAction, D as DumpSubscriber, d as InsightTaskInfo, e as InsightOptions, f as DetailedLocateParam, L as LocateResult, g as InsightExtractOption, h as InsightAssertionResponse, A as AIDescribeElementResponse } from './types-d187efec.js';
|
|
2
|
+
export { w as AIAssertionResponse, u as AIDataExtractionResponse, s as AIElementCoordinatesResponse, r as AIElementLocatorResponse, t as AIElementResponse, n as AIResponseFormat, v as AISectionLocatorResponse, q as AISingleElementResponse, o as AISingleElementResponseById, p as AISingleElementResponseByPosition, m as AIUsageInfo, S as AgentAssertOpt, z as AgentDescribeElementAtPointResult, Q as AgentWaitForOpt, a7 as BaseAgentParserOpt, C as CallAIFn, aB as CodeGenerationChunk, a6 as Color, H as DumpMeta, N as ElementById, B as EnsureObject, aa as ExecutionRecorderItem, as as ExecutionTaskAction, ar as ExecutionTaskActionApply, ad as ExecutionTaskHitBy, aq as ExecutionTaskInsightAssertion, ap as ExecutionTaskInsightAssertionApply, ao as ExecutionTaskInsightAssertionParam, ah as ExecutionTaskInsightDumpLog, aj as ExecutionTaskInsightLocate, ai as ExecutionTaskInsightLocateApply, ag as ExecutionTaskInsightLocateOutput, af as ExecutionTaskInsightLocateParam, an as ExecutionTaskInsightQuery, am as ExecutionTaskInsightQueryApply, al as ExecutionTaskInsightQueryOutput, ak as ExecutionTaskInsightQueryParam, au as ExecutionTaskLog, at as ExecutionTaskLogApply, aw as ExecutionTaskPlanning, av as ExecutionTaskPlanningApply, ae as ExecutionTaskReturn, ab as ExecutionTaskType, ac as ExecutorContext, a$ as FreeFn, ax as GroupedActionDump, J as InsightDump, F as InsightExtractParam, K as LiteUISection, aD as LocateOption, G as LocateResultElement, y as LocateValidatorResult, x as LocatorValidatorOption, b2 as MidsceneYamlConfig, b3 as MidsceneYamlConfigOutput, l as MidsceneYamlConfigResult, j as MidsceneYamlFlowItem, aK as MidsceneYamlFlowItemAIAction, aP as MidsceneYamlFlowItemAIAsk, aL as MidsceneYamlFlowItemAIAssert, aQ as MidsceneYamlFlowItemAIBoolean, aU as MidsceneYamlFlowItemAIHover, aV as MidsceneYamlFlowItemAIInput, aW as MidsceneYamlFlowItemAIKeyboardPress, aR as MidsceneYamlFlowItemAILocate, aN as MidsceneYamlFlowItemAINumber, aM as MidsceneYamlFlowItemAIQuery, k as MidsceneYamlFlowItemAIRightClick, aX as MidsceneYamlFlowItemAIScroll, aO as MidsceneYamlFlowItemAIString, aT as MidsceneYamlFlowItemAITap, aS as MidsceneYamlFlowItemAIWaitFor, aY as MidsceneYamlFlowItemEvaluateJavaScript, a_ as MidsceneYamlFlowItemLogScreenshot, aZ as MidsceneYamlFlowItemSleep, M as MidsceneYamlScript, aI as MidsceneYamlScriptAndroidEnv, aJ as MidsceneYamlScriptEnv, aG as MidsceneYamlScriptEnvBase, aH as MidsceneYamlScriptWebEnv, i as MidsceneYamlTask, O as OnTaskStartTip, ay as PageType, P as PartialInsightDumpFromSDK, W as PlanningAIResponse, V as PlanningAction, a4 as PlanningActionParamAndroidLongPress, a5 as PlanningActionParamAndroidPull, a0 as PlanningActionParamAssert, a2 as PlanningActionParamError, Y as PlanningActionParamHover, _ as PlanningActionParamInputOrKeyPress, Z as PlanningActionParamRightClick, $ as PlanningActionParamScroll, a1 as PlanningActionParamSleep, X as PlanningActionParamTap, a3 as PlanningActionParamWaitFor, T as PlanningLocateParam, a9 as PlaywrightParserOpt, a8 as PuppeteerParserOpt, aE as ReferenceImage, R as ReportDumpWithAttributes, b1 as ScriptPlayerStatusValue, b0 as ScriptPlayerTaskStatus, aC as StreamingAIResponse, aA as StreamingCallback, az as StreamingCodeGenerationOptions, aF as scrollParam } from './types-d187efec.js';
|
|
3
|
+
import { c as callAiFn } from './llm-planning-ae19dc49.js';
|
|
4
|
+
export { a as AiAssert, A as AiLocateElement, d as describeUserPage, p as plan } from './llm-planning-ae19dc49.js';
|
|
5
5
|
import { BaseElement, Rect } from '@midscene/shared/types';
|
|
6
6
|
export { BaseElement, ElementTreeNode, Point, Rect, Size } from '@midscene/shared/types';
|
|
7
7
|
export { getVersion } from './utils.js';
|
package/dist/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getVersion
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-M4OYNEBY.js";
|
|
4
4
|
import {
|
|
5
5
|
AiAssert,
|
|
6
6
|
AiExtractElementInfo,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
describeUserPage,
|
|
12
12
|
expandSearchArea,
|
|
13
13
|
plan
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-3LFZDNMQ.js";
|
|
15
15
|
|
|
16
16
|
// src/ai-model/action-executor.ts
|
|
17
17
|
import {
|
|
@@ -291,7 +291,14 @@ var Insight = class {
|
|
|
291
291
|
searchArea = searchAreaResponse.rect;
|
|
292
292
|
}
|
|
293
293
|
const startTime = Date.now();
|
|
294
|
-
const {
|
|
294
|
+
const {
|
|
295
|
+
parseResult,
|
|
296
|
+
rect,
|
|
297
|
+
elementById,
|
|
298
|
+
rawResponse,
|
|
299
|
+
usage,
|
|
300
|
+
isOrderSensitive
|
|
301
|
+
} = await AiLocateElement({
|
|
295
302
|
callAI: callAI || this.aiVendorFn,
|
|
296
303
|
context,
|
|
297
304
|
targetElementDescription: queryPrompt,
|
|
@@ -360,7 +367,8 @@ ${parseResult.errors.join("\n")}`;
|
|
|
360
367
|
center: elements[0].center,
|
|
361
368
|
rect: elements[0].rect,
|
|
362
369
|
xpaths: elements[0].xpaths || [],
|
|
363
|
-
attributes: elements[0].attributes
|
|
370
|
+
attributes: elements[0].attributes,
|
|
371
|
+
isOrderSensitive
|
|
364
372
|
},
|
|
365
373
|
rect
|
|
366
374
|
};
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"mappings":";;;;;;;;;;;;;;;;AAUA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc;AAEhB,IAAM,WAAN,MAAe;AAAA,EAUpB,YACE,MACA,SAGA;AACA,SAAK,SACH,SAAS,SAAS,QAAQ,MAAM,SAAS,IAAI,YAAY;AAC3D,SAAK,OAAO;AACZ,SAAK,SAAS,SAAS,SAAS,CAAC,GAAG;AAAA,MAAI,CAAC,SACvC,KAAK,kBAAkB,IAAI;AAAA,IAC7B;AACA,SAAK,cAAc,SAAS;AAAA,EAC9B;AAAA,EAEQ,kBAAkB,MAAyC;AACjE,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,GAAG;AAAA,IACL;AAAA,EACF;AAAA,EAEA,MAAM,OAAO,MAAgE;AAC3E;AAAA,MACE,KAAK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AQ,IAAI;AAC5D,YAAM,4BAA4B,UAAU;AAC5C,qBAAe,MAAM;AAAA,QACnB;AAAA,QACA;AAAA,QACA,qBAAqB,oBAAoB;AAAA,MAC3C;AAAA,IACF;AAEA,UAAM,OAAe;AAAA,MACnB,EAAE,MAAM,UAAU,SAAS,aAAa;AAAA,MACxC;AAAA,QACE,MAAM;AAAA,QACN,SAAS;AAAA,UACP;AAAA,YACE,MAAM;AAAA,YACN,WAAW;AAAA,cACT,KAAK;AAAA,cACL,QAAQ;AAAA,YACV;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,WACJ,KAAK,cAAc;AAErB,UAAM,MAAM,MAAM,SAAS,8BAAmC;AAE9D,UAAM,EAAE,QAAQ,IAAI;AACpB,IAAAA,QAAO,CAAC,QAAQ,OAAO,oBAAoB,QAAQ,KAAK,EAAE;AAC1D,IAAAA,QAAO,QAAQ,aAAa,gCAAgC;AAC5D,WAAO;AAAA,EACT;AACF;;;AE1ZA,SAAS,eAAAE,cAAa,uBAAAD,4BAA2B;AAGjD,IAAO,cAAQ","names":["vlLocateMode","assert","MIDSCENE_MODEL_NAME","getAIConfig"],"ignoreList":[],"sources":["../../src/ai-model/action-executor.ts","../../src/ai-model/prompt/describe.ts","../../src/insight/index.ts","../../src/insight/utils.ts","../../src/index.ts"],"sourcesContent":["import type {\n ExecutionDump,\n ExecutionTask,\n ExecutionTaskApply,\n ExecutionTaskInsightLocateOutput,\n ExecutionTaskProgressOptions,\n ExecutionTaskReturn,\n ExecutorContext,\n} from '@/types';\nimport { getVersion } from '@/utils';\nimport {\n MIDSCENE_MODEL_NAME,\n getAIConfig,\n uiTarsModelVersion,\n vlLocateMode,\n} from '@midscene/shared/env';\nimport { assert } from '@midscene/shared/utils';\n\nexport class Executor {\n name: string;\n\n tasks: ExecutionTask[];\n\n // status of executor\n status: 'init' | 'pending' | 'running' | 'completed' | 'error';\n\n onTaskStart?: ExecutionTaskProgressOptions['onTaskStart'];\n\n constructor(\n name: string,\n options?: ExecutionTaskProgressOptions & {\n tasks?: ExecutionTaskApply[];\n },\n ) {\n this.status =\n options?.tasks && options.tasks.length > 0 ? 'pending' : 'init';\n this.name = name;\n this.tasks = (options?.tasks || []).map((item) =>\n this.markTaskAsPending(item),\n );\n this.onTaskStart = options?.onTaskStart;\n }\n\n private markTaskAsPending(task: ExecutionTaskApply): ExecutionTask {\n return {\n status: 'pending',\n ...task,\n };\n }\n\n async append(task: ExecutionTaskApply[] | ExecutionTaskApply): Promise<void> {\n assert(\n this.status !== 'error',\n `executor is in error state, cannot append task\\nerror=${this.latestErrorTask()?.error}\\n${this.latestErrorTask()?.errorStack}`,\n );\n if (Array.isArray(task)) {\n this.tasks.push(...task.map((item) => this.markTaskAsPending(item)));\n } else {\n this.tasks.push(this.markTaskAsPending(task));\n }\n if (this.status !== 'running') {\n this.status = 'pending';\n }\n }\n\n async flush(): Promise<any> {\n if (this.status === 'init' && this.tasks.length > 0) {\n console.warn(\n 'illegal state for executor, status is init but tasks are not empty',\n );\n }\n\n assert(this.status !== 'running', 'executor is already running');\n assert(this.status !== 'completed', 'executor is already completed');\n assert(this.status !== 'error', 'executor is in error state');\n\n const nextPendingIndex = this.tasks.findIndex(\n (task) => task.status === 'pending',\n );\n if (nextPendingIndex < 0) {\n // all tasks are completed\n return;\n }\n\n this.status = 'running';\n let taskIndex = nextPendingIndex;\n let successfullyCompleted = true;\n\n let previousFindOutput: ExecutionTaskInsightLocateOutput | undefined;\n\n while (taskIndex < this.tasks.length) {\n const task = this.tasks[taskIndex];\n assert(\n task.status === 'pending',\n `task status should be pending, but got: ${task.status}`,\n );\n task.timing = {\n start: Date.now(),\n };\n try {\n task.status = 'running';\n try {\n if (this.onTaskStart) {\n await this.onTaskStart(task);\n }\n } catch (e) {\n console.error('error in onTaskStart', e);\n }\n assert(\n ['Insight', 'Action', 'Planning'].indexOf(task.type) >= 0,\n `unsupported task type: ${task.type}`,\n );\n\n const { executor, param } = task;\n assert(executor, `executor is required for task type: ${task.type}`);\n\n let returnValue;\n const executorContext: ExecutorContext = {\n task,\n element: previousFindOutput?.element,\n };\n\n if (task.type === 'Insight') {\n assert(\n task.subType === 'Locate' ||\n task.subType === 'Query' ||\n task.subType === 'Assert' ||\n task.subType === 'Boolean' ||\n task.subType === 'Number' ||\n task.subType === 'String',\n `unsupported insight subType: ${task.subType}`,\n );\n returnValue = await task.executor(param, executorContext);\n if (task.subType === 'Locate') {\n previousFindOutput = (\n returnValue as ExecutionTaskReturn<ExecutionTaskInsightLocateOutput>\n )?.output;\n }\n } else if (task.type === 'Action' || task.type === 'Planning') {\n returnValue = await task.executor(param, executorContext);\n } else {\n console.warn(\n `unsupported task type: ${task.type}, will try to execute it directly`,\n );\n returnValue = await task.executor(param, executorContext);\n }\n\n Object.assign(task, returnValue);\n task.status = 'finished';\n task.timing.end = Date.now();\n task.timing.cost = task.timing.end - task.timing.start;\n taskIndex++;\n } catch (e: any) {\n successfullyCompleted = false;\n task.error =\n e?.message || (typeof e === 'string' ? e : 'error-without-message');\n task.errorStack = e.stack;\n\n task.status = 'failed';\n task.timing.end = Date.now();\n task.timing.cost = task.timing.end - task.timing.start;\n break;\n }\n }\n\n // set all remaining tasks as cancelled\n for (let i = taskIndex + 1; i < this.tasks.length; i++) {\n this.tasks[i].status = 'cancelled';\n }\n\n if (successfullyCompleted) {\n this.status = 'completed';\n } else {\n this.status = 'error';\n }\n\n if (this.tasks.length) {\n // return the last output\n const outputIndex = Math.min(taskIndex, this.tasks.length - 1);\n return this.tasks[outputIndex].output;\n }\n }\n\n isInErrorState(): boolean {\n return this.status === 'error';\n }\n\n latestErrorTask(): ExecutionTask | null {\n if (this.status !== 'error') {\n return null;\n }\n const errorTaskIndex = this.tasks.findIndex(\n (task) => task.status === 'failed',\n );\n if (errorTaskIndex >= 0) {\n return this.tasks[errorTaskIndex];\n }\n return null;\n }\n\n dump(): ExecutionDump {\n let modelDescription = '';\n\n if (vlLocateMode()) {\n const uiTarsModelVer = uiTarsModelVersion();\n if (uiTarsModelVer) {\n modelDescription = `UI-TARS=${uiTarsModelVer}`;\n } else {\n modelDescription = `${vlLocateMode()} mode`;\n }\n }\n const dumpData: ExecutionDump = {\n sdkVersion: getVersion(),\n model_name: getAIConfig(MIDSCENE_MODEL_NAME) || '',\n model_description: modelDescription,\n logTime: Date.now(),\n name: this.name,\n tasks: this.tasks,\n };\n return dumpData;\n }\n}\n","import { getPreferredLanguage } from '@midscene/shared/env';\n\nexport const elementDescriberInstruction = () => {\n return `Describe the element in the red rectangle for precise identification. Use ${getPreferredLanguage()}.\n\nRules:\n1. Start with element type (button, input, link, etc.) \n2. Include key identifiers:\n - Text content: \"with text 'Submit'\"\n - Visual features: \"blue background\", \"icon only\"\n - Position: \"top-right\", \"below search bar\"\n3. Keep description under 20 words\n4. Don't mention the red rectangle\n\nReturn JSON:\n{\n \"description\": \"brief element type with key identifiers\",\n \"error\"?: \"error message if any\"\n}`;\n};\n","import {\n AIActionType,\n type AIArgs,\n callAiFn,\n expandSearchArea,\n} from '@/ai-model/common';\nimport {\n AiExtractElementInfo,\n AiLocateElement,\n callToGetJSONObject,\n} from '@/ai-model/index';\nimport { AiAssert, AiLocateSection } from '@/ai-model/inspect';\nimport { elementDescriberInstruction } from '@/ai-model/prompt/describe';\nimport type {\n AIDescribeElementResponse,\n AIElementResponse,\n AIUsageInfo,\n BaseElement,\n DetailedLocateParam,\n DumpSubscriber,\n InsightAction,\n InsightAssertionResponse,\n InsightExtractOption,\n InsightExtractParam,\n InsightOptions,\n InsightTaskInfo,\n LocateResult,\n PartialInsightDumpFromSDK,\n Rect,\n UIContext,\n} from '@/types';\nimport {\n MIDSCENE_FORCE_DEEP_THINK,\n MIDSCENE_USE_QWEN_VL,\n getAIConfigInBoolean,\n vlLocateMode,\n} from '@midscene/shared/env';\nimport { compositeElementInfoImg, cropByRect } from '@midscene/shared/img';\nimport { getDebug } from '@midscene/shared/logger';\nimport { assert } from '@midscene/shared/utils';\nimport { emitInsightDump } from './utils';\n\nexport interface LocateOpts {\n context?: UIContext<BaseElement>;\n callAI?: typeof callAiFn<AIElementResponse>;\n}\n\nexport type AnyValue<T> = {\n [K in keyof T]: unknown extends T[K] ? any : T[K];\n};\n\nconst debug = getDebug('ai:insight');\nexport default class Insight<\n ElementType extends BaseElement = BaseElement,\n ContextType extends UIContext<ElementType> = UIContext<ElementType>,\n> {\n contextRetrieverFn: (\n action: InsightAction,\n ) => Promise<ContextType> | ContextType;\n\n aiVendorFn: (...args: Array<any>) => Promise<any> = callAiFn;\n\n onceDumpUpdatedFn?: DumpSubscriber;\n\n taskInfo?: Omit<InsightTaskInfo, 'durationMs'>;\n\n constructor(\n context:\n | ContextType\n | ((action: InsightAction) => Promise<ContextType> | ContextType),\n opt?: InsightOptions,\n ) {\n assert(context, 'context is required for Insight');\n if (typeof context === 'function') {\n this.contextRetrieverFn = context;\n } else {\n this.contextRetrieverFn = () => Promise.resolve(context);\n }\n\n if (typeof opt?.aiVendorFn !== 'undefined') {\n this.aiVendorFn = opt.aiVendorFn;\n }\n if (typeof opt?.taskInfo !== 'undefined') {\n this.taskInfo = opt.taskInfo;\n }\n }\n\n async locate(\n query: DetailedLocateParam,\n opt?: LocateOpts,\n ): Promise<LocateResult> {\n const { callAI } = opt || {};\n const queryPrompt = typeof query === 'string' ? query : query.prompt;\n assert(queryPrompt, 'query is required for locate');\n const dumpSubscriber = this.onceDumpUpdatedFn;\n this.onceDumpUpdatedFn = undefined;\n\n assert(typeof query === 'object', 'query should be an object for locate');\n\n const globalDeepThinkSwitch = getAIConfigInBoolean(\n MIDSCENE_FORCE_DEEP_THINK,\n );\n if (globalDeepThinkSwitch) {\n debug('globalDeepThinkSwitch', globalDeepThinkSwitch);\n }\n let searchAreaPrompt;\n if (query.deepThink || globalDeepThinkSwitch) {\n searchAreaPrompt = query.prompt;\n }\n\n if (searchAreaPrompt && !vlLocateMode()) {\n console.warn(\n 'The \"deepThink\" feature is not supported with multimodal LLM. Please config VL model for Midscene. https://midscenejs.com/choose-a-model',\n );\n searchAreaPrompt = undefined;\n }\n\n const context = opt?.context || (await this.contextRetrieverFn('locate'));\n\n let searchArea: Rect | undefined = undefined;\n let searchAreaRawResponse: string | undefined = undefined;\n let searchAreaUsage: AIUsageInfo | undefined = undefined;\n let searchAreaResponse:\n | Awaited<ReturnType<typeof AiLocateSection>>\n | undefined = undefined;\n if (searchAreaPrompt) {\n searchAreaResponse = await AiLocateSection({\n context,\n sectionDescription: searchAreaPrompt,\n });\n assert(\n searchAreaResponse.rect,\n `cannot find search area for \"${searchAreaPrompt}\"${\n searchAreaResponse.error ? `: ${searchAreaResponse.error}` : ''\n }`,\n );\n searchAreaRawResponse = searchAreaResponse.rawResponse;\n searchAreaUsage = searchAreaResponse.usage;\n searchArea = searchAreaResponse.rect;\n }\n\n const startTime = Date.now();\n const { parseResult, rect, elementById, rawResponse, usage } =\n await AiLocateElement({\n callAI: callAI || this.aiVendorFn,\n context,\n targetElementDescription: queryPrompt,\n searchConfig: searchAreaResponse,\n });\n\n const timeCost = Date.now() - startTime;\n const taskInfo: InsightTaskInfo = {\n ...(this.taskInfo ? this.taskInfo : {}),\n durationMs: timeCost,\n rawResponse: JSON.stringify(rawResponse),\n formatResponse: JSON.stringify(parseResult),\n usage,\n searchArea,\n searchAreaRawResponse,\n searchAreaUsage,\n };\n\n let errorLog: string | undefined;\n if (parseResult.errors?.length) {\n errorLog = `AI model failed to locate: \\n${parseResult.errors.join('\\n')}`;\n }\n\n const dumpData: PartialInsightDumpFromSDK = {\n type: 'locate',\n userQuery: {\n element: queryPrompt,\n },\n matchedElement: [],\n matchedRect: rect,\n data: null,\n taskInfo,\n deepThink: !!searchArea,\n error: errorLog,\n };\n\n const elements: BaseElement[] = [];\n (parseResult.elements || []).forEach((item) => {\n if ('id' in item) {\n const element = elementById(item?.id);\n\n if (!element) {\n console.warn(\n `locate: cannot find element id=${item.id}. Maybe an unstable response from AI model`,\n );\n return;\n }\n elements.push(element);\n }\n });\n\n emitInsightDump(\n {\n ...dumpData,\n matchedElement: elements,\n },\n dumpSubscriber,\n );\n\n if (errorLog) {\n throw new Error(errorLog);\n }\n\n assert(\n elements.length <= 1,\n `locate: multiple elements found, length = ${elements.length}`,\n );\n\n if (elements.length === 1) {\n return {\n element: {\n id: elements[0]!.id,\n indexId: elements[0]!.indexId,\n center: elements[0]!.center,\n rect: elements[0]!.rect,\n xpaths: elements[0]!.xpaths || [],\n attributes: elements[0]!.attributes,\n },\n rect,\n };\n }\n return {\n element: null,\n rect,\n };\n }\n\n async extract<T = any>(input: string, opt?: InsightExtractOption): Promise<T>;\n async extract<T extends Record<string, string>>(\n input: T,\n opt?: InsightExtractOption,\n ): Promise<Record<keyof T, any>>;\n async extract<T extends object>(\n input: Record<keyof T, string>,\n opt?: InsightExtractOption,\n ): Promise<T>;\n\n async extract<T>(\n dataDemand: InsightExtractParam,\n opt?: InsightExtractOption,\n ): Promise<any> {\n assert(\n typeof dataDemand === 'object' || typeof dataDemand === 'string',\n `dataDemand should be object or string, but get ${typeof dataDemand}`,\n );\n const dumpSubscriber = this.onceDumpUpdatedFn;\n this.onceDumpUpdatedFn = undefined;\n\n const context = await this.contextRetrieverFn('extract');\n\n const startTime = Date.now();\n const { parseResult, usage } = await AiExtractElementInfo<T>({\n context,\n dataQuery: dataDemand,\n extractOption: opt,\n });\n\n const timeCost = Date.now() - startTime;\n const taskInfo: InsightTaskInfo = {\n ...(this.taskInfo ? this.taskInfo : {}),\n durationMs: timeCost,\n rawResponse: JSON.stringify(parseResult),\n };\n\n let errorLog: string | undefined;\n if (parseResult.errors?.length) {\n errorLog = `AI response error: \\n${parseResult.errors.join('\\n')}`;\n }\n\n const dumpData: PartialInsightDumpFromSDK = {\n type: 'extract',\n userQuery: {\n dataDemand,\n },\n matchedElement: [],\n data: null,\n taskInfo,\n error: errorLog,\n };\n\n const { data } = parseResult || {};\n\n // 4\n emitInsightDump(\n {\n ...dumpData,\n data,\n },\n dumpSubscriber,\n );\n\n if (errorLog && !data) {\n throw new Error(errorLog);\n }\n\n return {\n data,\n usage,\n };\n }\n\n async assert(assertion: string): Promise<InsightAssertionResponse> {\n if (typeof assertion !== 'string') {\n throw new Error(\n 'This is the assert method for Midscene, the first argument should be a string. If you want to use the assert method from Node.js, please import it from the Node.js assert module.',\n );\n }\n\n const dumpSubscriber = this.onceDumpUpdatedFn;\n this.onceDumpUpdatedFn = undefined;\n\n const context = await this.contextRetrieverFn('assert');\n const startTime = Date.now();\n const assertResult = await AiAssert({\n assertion,\n context,\n });\n\n const timeCost = Date.now() - startTime;\n const taskInfo: InsightTaskInfo = {\n ...(this.taskInfo ? this.taskInfo : {}),\n durationMs: timeCost,\n rawResponse: JSON.stringify(assertResult.content),\n };\n\n const { thought, pass } = assertResult.content;\n const dumpData: PartialInsightDumpFromSDK = {\n type: 'assert',\n userQuery: {\n assertion,\n },\n matchedElement: [],\n data: null,\n taskInfo,\n assertionPass: pass,\n assertionThought: thought,\n error: pass ? undefined : thought,\n };\n emitInsightDump(dumpData, dumpSubscriber);\n\n return {\n pass,\n thought,\n usage: assertResult.usage,\n };\n }\n async describe(\n target: Rect | [number, number],\n opt?: {\n deepThink?: boolean;\n },\n ): Promise<Pick<AIDescribeElementResponse, 'description'>> {\n assert(target, 'target is required for insight.describe');\n const context = await this.contextRetrieverFn('describe');\n const { screenshotBase64, size } = context;\n assert(screenshotBase64, 'screenshot is required for insight.describe');\n\n const systemPrompt = elementDescriberInstruction();\n\n // Convert [x,y] center point to Rect if needed\n const defaultRectSize = 30;\n const targetRect: Rect = Array.isArray(target)\n ? {\n left: Math.floor(target[0] - defaultRectSize / 2),\n top: Math.floor(target[1] - defaultRectSize / 2),\n width: defaultRectSize,\n height: defaultRectSize,\n }\n : target;\n\n let imagePayload = await compositeElementInfoImg({\n inputImgBase64: screenshotBase64,\n size,\n elementsPositionInfo: [\n {\n rect: targetRect,\n },\n ],\n borderThickness: 3,\n });\n\n if (opt?.deepThink) {\n const searchArea = expandSearchArea(targetRect, context.size);\n debug('describe: set searchArea', searchArea);\n imagePayload = await cropByRect(\n imagePayload,\n searchArea,\n getAIConfigInBoolean(MIDSCENE_USE_QWEN_VL),\n );\n }\n\n const msgs: AIArgs = [\n { role: 'system', content: systemPrompt },\n {\n role: 'user',\n content: [\n {\n type: 'image_url',\n image_url: {\n url: imagePayload,\n detail: 'high',\n },\n },\n ],\n },\n ];\n\n const callAIFn =\n this.aiVendorFn || callToGetJSONObject<AIDescribeElementResponse>;\n\n const res = await callAIFn(msgs, AIActionType.DESCRIBE_ELEMENT);\n\n const { content } = res;\n assert(!content.error, `describe failed: ${content.error}`);\n assert(content.description, 'failed to describe the element');\n return content;\n }\n}\n","import type {\n DumpMeta,\n DumpSubscriber,\n InsightDump,\n PartialInsightDumpFromSDK,\n} from '@/types';\nimport { getVersion } from '@/utils';\nimport { MIDSCENE_MODEL_NAME, getAIConfig } from '@midscene/shared/env';\nimport { uuid } from '@midscene/shared/utils';\n\nexport function emitInsightDump(\n data: PartialInsightDumpFromSDK,\n dumpSubscriber?: DumpSubscriber,\n) {\n const baseData: DumpMeta = {\n sdkVersion: getVersion(),\n logTime: Date.now(),\n model_name: getAIConfig(MIDSCENE_MODEL_NAME) || '',\n };\n const finalData: InsightDump = {\n logId: uuid(),\n ...baseData,\n ...data,\n };\n\n dumpSubscriber?.(finalData);\n}\n","import { Executor } from './ai-model/action-executor';\nimport Insight from './insight/index';\nimport { getVersion } from './utils';\n\nexport {\n plan,\n describeUserPage,\n AiLocateElement,\n AiAssert,\n} from './ai-model/index';\n\nexport { getAIConfig, MIDSCENE_MODEL_NAME } from '@midscene/shared/env';\n\nexport type * from './types';\nexport default Insight;\nexport { Executor, Insight, getVersion };\n\nexport type {\n MidsceneYamlScript,\n MidsceneYamlTask,\n MidsceneYamlFlowItem,\n MidsceneYamlFlowItemAIRightClick,\n MidsceneYamlConfigResult,\n} from './yaml';\n"]}
|
|
1
|
+
{"version":3,"mappings":";;;;;;;;;;;;;;;;AAUA;AAAA,EACE;AAAA,EACA;AAAA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Config"],"ignoreList":[],"sources":["../../src/ai-model/action-executor.ts","../../src/ai-model/prompt/describe.ts","../../src/insight/index.ts","../../src/insight/utils.ts","../../src/index.ts"],"sourcesContent":["import type {\n ExecutionDump,\n ExecutionTask,\n ExecutionTaskApply,\n ExecutionTaskInsightLocateOutput,\n ExecutionTaskProgressOptions,\n ExecutionTaskReturn,\n ExecutorContext,\n} from '@/types';\nimport { getVersion } from '@/utils';\nimport {\n MIDSCENE_MODEL_NAME,\n getAIConfig,\n uiTarsModelVersion,\n vlLocateMode,\n} from '@midscene/shared/env';\nimport { assert } from '@midscene/shared/utils';\n\nexport class Executor {\n name: string;\n\n tasks: ExecutionTask[];\n\n // status of executor\n status: 'init' | 'pending' | 'running' | 'completed' | 'error';\n\n onTaskStart?: ExecutionTaskProgressOptions['onTaskStart'];\n\n constructor(\n name: string,\n options?: ExecutionTaskProgressOptions & {\n tasks?: ExecutionTaskApply[];\n },\n ) {\n this.status =\n options?.tasks && options.tasks.length > 0 ? 'pending' : 'init';\n this.name = name;\n this.tasks = (options?.tasks || []).map((item) =>\n this.markTaskAsPending(item),\n );\n this.onTaskStart = options?.onTaskStart;\n }\n\n private markTaskAsPending(task: ExecutionTaskApply): ExecutionTask {\n return {\n status: 'pending',\n ...task,\n };\n }\n\n async append(task: ExecutionTaskApply[] | ExecutionTaskApply): Promise<void> {\n assert(\n this.status !== 'error',\n `executor is in error state, cannot append task\\nerror=${this.latestErrorTask()?.error}\\n${this.latestErrorTask()?.errorStack}`,\n );\n if (Array.isArray(task)) {\n this.tasks.push(...task.map((item) => this.markTaskAsPending(item)));\n } else {\n this.tasks.push(this.markTaskAsPending(task));\n }\n if (this.status !== 'running') {\n this.status = 'pending';\n }\n }\n\n async flush(): Promise<any> {\n if (this.status === 'init' && this.tasks.length > 0) {\n console.warn(\n 'illegal state for executor, status is init but tasks are not empty',\n );\n }\n\n assert(this.status !== 'running', 'executor is already running');\n assert(this.status !== 'completed', 'executor is already completed');\n assert(this.status !== 'error', 'executor is in error state');\n\n const nextPendingIndex = this.tasks.findIndex(\n (task) => task.status === 'pending',\n );\n if (nextPendingIndex < 0) {\n // all tasks are completed\n return;\n }\n\n this.status = 'running';\n let taskIndex = nextPendingIndex;\n let successfullyCompleted = true;\n\n let previousFindOutput: ExecutionTaskInsightLocateOutput | undefined;\n\n while (taskIndex < this.tasks.length) {\n const task = this.tasks[taskIndex];\n assert(\n task.status === 'pending',\n `task status should be pending, but got: ${task.status}`,\n );\n task.timing = {\n start: Date.now(),\n };\n try {\n task.status = 'running';\n try {\n if (this.onTaskStart) {\n await this.onTaskStart(task);\n }\n } catch (e) {\n console.error('error in onTaskStart', e);\n }\n assert(\n ['Insight', 'Action', 'Planning'].indexOf(task.type) >= 0,\n `unsupported task type: ${task.type}`,\n );\n\n const { executor, param } = task;\n assert(executor, `executor is required for task type: ${task.type}`);\n\n let returnValue;\n const executorContext: ExecutorContext = {\n task,\n element: previousFindOutput?.element,\n };\n\n if (task.type === 'Insight') {\n assert(\n task.subType === 'Locate' ||\n task.subType === 'Query' ||\n task.subType === 'Assert' ||\n task.subType === 'Boolean' ||\n task.subType === 'Number' ||\n task.subType === 'String',\n `unsupported insight subType: ${task.subType}`,\n );\n returnValue = await task.executor(param, executorContext);\n if (task.subType === 'Locate') {\n previousFindOutput = (\n returnValue as ExecutionTaskReturn<ExecutionTaskInsightLocateOutput>\n )?.output;\n }\n } else if (task.type === 'Action' || task.type === 'Planning') {\n returnValue = await task.executor(param, executorContext);\n } else {\n console.warn(\n `unsupported task type: ${task.type}, will try to execute it directly`,\n );\n returnValue = await task.executor(param, executorContext);\n }\n\n Object.assign(task, returnValue);\n task.status = 'finished';\n task.timing.end = Date.now();\n task.timing.cost = task.timing.end - task.timing.start;\n taskIndex++;\n } catch (e: any) {\n successfullyCompleted = false;\n task.error =\n e?.message || (typeof e === 'string' ? e : 'error-without-message');\n task.errorStack = e.stack;\n\n task.status = 'failed';\n task.timing.end = Date.now();\n task.timing.cost = task.timing.end - task.timing.start;\n break;\n }\n }\n\n // set all remaining tasks as cancelled\n for (let i = taskIndex + 1; i < this.tasks.length; i++) {\n this.tasks[i].status = 'cancelled';\n }\n\n if (successfullyCompleted) {\n this.status = 'completed';\n } else {\n this.status = 'error';\n }\n\n if (this.tasks.length) {\n // return the last output\n const outputIndex = Math.min(taskIndex, this.tasks.length - 1);\n return this.tasks[outputIndex].output;\n }\n }\n\n isInErrorState(): boolean {\n return this.status === 'error';\n }\n\n latestErrorTask(): ExecutionTask | null {\n if (this.status !== 'error') {\n return null;\n }\n const errorTaskIndex = this.tasks.findIndex(\n (task) => task.status === 'failed',\n );\n if (errorTaskIndex >= 0) {\n return this.tasks[errorTaskIndex];\n }\n return null;\n }\n\n dump(): ExecutionDump {\n let modelDescription = '';\n\n if (vlLocateMode()) {\n const uiTarsModelVer = uiTarsModelVersion();\n if (uiTarsModelVer) {\n modelDescription = `UI-TARS=${uiTarsModelVer}`;\n } else {\n modelDescription = `${vlLocateMode()} mode`;\n }\n }\n const dumpData: ExecutionDump = {\n sdkVersion: getVersion(),\n model_name: getAIConfig(MIDSCENE_MODEL_NAME) || '',\n model_description: modelDescription,\n logTime: Date.now(),\n name: this.name,\n tasks: this.tasks,\n };\n return dumpData;\n }\n}\n","import { getPreferredLanguage } from '@midscene/shared/env';\n\nexport const elementDescriberInstruction = () => {\n return `Describe the element in the red rectangle for precise identification. Use ${getPreferredLanguage()}.\n\nRules:\n1. Start with element type (button, input, link, etc.) \n2. Include key identifiers:\n - Text content: \"with text 'Submit'\"\n - Visual features: \"blue background\", \"icon only\"\n - Position: \"top-right\", \"below search bar\"\n3. Keep description under 20 words\n4. Don't mention the red rectangle\n\nReturn JSON:\n{\n \"description\": \"brief element type with key identifiers\",\n \"error\"?: \"error message if any\"\n}`;\n};\n","import {\n AIActionType,\n type AIArgs,\n callAiFn,\n expandSearchArea,\n} from '@/ai-model/common';\nimport {\n AiExtractElementInfo,\n AiLocateElement,\n callToGetJSONObject,\n} from '@/ai-model/index';\nimport { AiAssert, AiLocateSection } from '@/ai-model/inspect';\nimport { elementDescriberInstruction } from '@/ai-model/prompt/describe';\nimport type {\n AIDescribeElementResponse,\n AIElementResponse,\n AIUsageInfo,\n BaseElement,\n DetailedLocateParam,\n DumpSubscriber,\n InsightAction,\n InsightAssertionResponse,\n InsightExtractOption,\n InsightExtractParam,\n InsightOptions,\n InsightTaskInfo,\n LocateResult,\n PartialInsightDumpFromSDK,\n Rect,\n UIContext,\n} from '@/types';\nimport {\n MIDSCENE_FORCE_DEEP_THINK,\n MIDSCENE_USE_QWEN_VL,\n getAIConfigInBoolean,\n vlLocateMode,\n} from '@midscene/shared/env';\nimport { compositeElementInfoImg, cropByRect } from '@midscene/shared/img';\nimport { getDebug } from '@midscene/shared/logger';\nimport { assert } from '@midscene/shared/utils';\nimport { emitInsightDump } from './utils';\n\nexport interface LocateOpts {\n context?: UIContext<BaseElement>;\n callAI?: typeof callAiFn<AIElementResponse>;\n}\n\nexport type AnyValue<T> = {\n [K in keyof T]: unknown extends T[K] ? any : T[K];\n};\n\nconst debug = getDebug('ai:insight');\nexport default class Insight<\n ElementType extends BaseElement = BaseElement,\n ContextType extends UIContext<ElementType> = UIContext<ElementType>,\n> {\n contextRetrieverFn: (\n action: InsightAction,\n ) => Promise<ContextType> | ContextType;\n\n aiVendorFn: (...args: Array<any>) => Promise<any> = callAiFn;\n\n onceDumpUpdatedFn?: DumpSubscriber;\n\n taskInfo?: Omit<InsightTaskInfo, 'durationMs'>;\n\n constructor(\n context:\n | ContextType\n | ((action: InsightAction) => Promise<ContextType> | ContextType),\n opt?: InsightOptions,\n ) {\n assert(context, 'context is required for Insight');\n if (typeof context === 'function') {\n this.contextRetrieverFn = context;\n } else {\n this.contextRetrieverFn = () => Promise.resolve(context);\n }\n\n if (typeof opt?.aiVendorFn !== 'undefined') {\n this.aiVendorFn = opt.aiVendorFn;\n }\n if (typeof opt?.taskInfo !== 'undefined') {\n this.taskInfo = opt.taskInfo;\n }\n }\n\n async locate(\n query: DetailedLocateParam,\n opt?: LocateOpts,\n ): Promise<LocateResult> {\n const { callAI } = opt || {};\n const queryPrompt = typeof query === 'string' ? query : query.prompt;\n assert(queryPrompt, 'query is required for locate');\n const dumpSubscriber = this.onceDumpUpdatedFn;\n this.onceDumpUpdatedFn = undefined;\n\n assert(typeof query === 'object', 'query should be an object for locate');\n\n const globalDeepThinkSwitch = getAIConfigInBoolean(\n MIDSCENE_FORCE_DEEP_THINK,\n );\n if (globalDeepThinkSwitch) {\n debug('globalDeepThinkSwitch', globalDeepThinkSwitch);\n }\n let searchAreaPrompt;\n if (query.deepThink || globalDeepThinkSwitch) {\n searchAreaPrompt = query.prompt;\n }\n\n if (searchAreaPrompt && !vlLocateMode()) {\n console.warn(\n 'The \"deepThink\" feature is not supported with multimodal LLM. Please config VL model for Midscene. https://midscenejs.com/choose-a-model',\n );\n searchAreaPrompt = undefined;\n }\n\n const context = opt?.context || (await this.contextRetrieverFn('locate'));\n\n let searchArea: Rect | undefined = undefined;\n let searchAreaRawResponse: string | undefined = undefined;\n let searchAreaUsage: AIUsageInfo | undefined = undefined;\n let searchAreaResponse:\n | Awaited<ReturnType<typeof AiLocateSection>>\n | undefined = undefined;\n if (searchAreaPrompt) {\n searchAreaResponse = await AiLocateSection({\n context,\n sectionDescription: searchAreaPrompt,\n });\n assert(\n searchAreaResponse.rect,\n `cannot find search area for \"${searchAreaPrompt}\"${\n searchAreaResponse.error ? `: ${searchAreaResponse.error}` : ''\n }`,\n );\n searchAreaRawResponse = searchAreaResponse.rawResponse;\n searchAreaUsage = searchAreaResponse.usage;\n searchArea = searchAreaResponse.rect;\n }\n\n const startTime = Date.now();\n const {\n parseResult,\n rect,\n elementById,\n rawResponse,\n usage,\n isOrderSensitive,\n } = await AiLocateElement({\n callAI: callAI || this.aiVendorFn,\n context,\n targetElementDescription: queryPrompt,\n searchConfig: searchAreaResponse,\n });\n\n const timeCost = Date.now() - startTime;\n const taskInfo: InsightTaskInfo = {\n ...(this.taskInfo ? this.taskInfo : {}),\n durationMs: timeCost,\n rawResponse: JSON.stringify(rawResponse),\n formatResponse: JSON.stringify(parseResult),\n usage,\n searchArea,\n searchAreaRawResponse,\n searchAreaUsage,\n };\n\n let errorLog: string | undefined;\n if (parseResult.errors?.length) {\n errorLog = `AI model failed to locate: \\n${parseResult.errors.join('\\n')}`;\n }\n\n const dumpData: PartialInsightDumpFromSDK = {\n type: 'locate',\n userQuery: {\n element: queryPrompt,\n },\n matchedElement: [],\n matchedRect: rect,\n data: null,\n taskInfo,\n deepThink: !!searchArea,\n error: errorLog,\n };\n\n const elements: BaseElement[] = [];\n (parseResult.elements || []).forEach((item) => {\n if ('id' in item) {\n const element = elementById(item?.id);\n\n if (!element) {\n console.warn(\n `locate: cannot find element id=${item.id}. Maybe an unstable response from AI model`,\n );\n return;\n }\n elements.push(element);\n }\n });\n\n emitInsightDump(\n {\n ...dumpData,\n matchedElement: elements,\n },\n dumpSubscriber,\n );\n\n if (errorLog) {\n throw new Error(errorLog);\n }\n\n assert(\n elements.length <= 1,\n `locate: multiple elements found, length = ${elements.length}`,\n );\n\n if (elements.length === 1) {\n return {\n element: {\n id: elements[0]!.id,\n indexId: elements[0]!.indexId,\n center: elements[0]!.center,\n rect: elements[0]!.rect,\n xpaths: elements[0]!.xpaths || [],\n attributes: elements[0]!.attributes,\n isOrderSensitive,\n },\n rect,\n };\n }\n return {\n element: null,\n rect,\n };\n }\n\n async extract<T = any>(input: string, opt?: InsightExtractOption): Promise<T>;\n async extract<T extends Record<string, string>>(\n input: T,\n opt?: InsightExtractOption,\n ): Promise<Record<keyof T, any>>;\n async extract<T extends object>(\n input: Record<keyof T, string>,\n opt?: InsightExtractOption,\n ): Promise<T>;\n\n async extract<T>(\n dataDemand: InsightExtractParam,\n opt?: InsightExtractOption,\n ): Promise<any> {\n assert(\n typeof dataDemand === 'object' || typeof dataDemand === 'string',\n `dataDemand should be object or string, but get ${typeof dataDemand}`,\n );\n const dumpSubscriber = this.onceDumpUpdatedFn;\n this.onceDumpUpdatedFn = undefined;\n\n const context = await this.contextRetrieverFn('extract');\n\n const startTime = Date.now();\n const { parseResult, usage } = await AiExtractElementInfo<T>({\n context,\n dataQuery: dataDemand,\n extractOption: opt,\n });\n\n const timeCost = Date.now() - startTime;\n const taskInfo: InsightTaskInfo = {\n ...(this.taskInfo ? this.taskInfo : {}),\n durationMs: timeCost,\n rawResponse: JSON.stringify(parseResult),\n };\n\n let errorLog: string | undefined;\n if (parseResult.errors?.length) {\n errorLog = `AI response error: \\n${parseResult.errors.join('\\n')}`;\n }\n\n const dumpData: PartialInsightDumpFromSDK = {\n type: 'extract',\n userQuery: {\n dataDemand,\n },\n matchedElement: [],\n data: null,\n taskInfo,\n error: errorLog,\n };\n\n const { data } = parseResult || {};\n\n // 4\n emitInsightDump(\n {\n ...dumpData,\n data,\n },\n dumpSubscriber,\n );\n\n if (errorLog && !data) {\n throw new Error(errorLog);\n }\n\n return {\n data,\n usage,\n };\n }\n\n async assert(assertion: string): Promise<InsightAssertionResponse> {\n if (typeof assertion !== 'string') {\n throw new Error(\n 'This is the assert method for Midscene, the first argument should be a string. If you want to use the assert method from Node.js, please import it from the Node.js assert module.',\n );\n }\n\n const dumpSubscriber = this.onceDumpUpdatedFn;\n this.onceDumpUpdatedFn = undefined;\n\n const context = await this.contextRetrieverFn('assert');\n const startTime = Date.now();\n const assertResult = await AiAssert({\n assertion,\n context,\n });\n\n const timeCost = Date.now() - startTime;\n const taskInfo: InsightTaskInfo = {\n ...(this.taskInfo ? this.taskInfo : {}),\n durationMs: timeCost,\n rawResponse: JSON.stringify(assertResult.content),\n };\n\n const { thought, pass } = assertResult.content;\n const dumpData: PartialInsightDumpFromSDK = {\n type: 'assert',\n userQuery: {\n assertion,\n },\n matchedElement: [],\n data: null,\n taskInfo,\n assertionPass: pass,\n assertionThought: thought,\n error: pass ? undefined : thought,\n };\n emitInsightDump(dumpData, dumpSubscriber);\n\n return {\n pass,\n thought,\n usage: assertResult.usage,\n };\n }\n async describe(\n target: Rect | [number, number],\n opt?: {\n deepThink?: boolean;\n },\n ): Promise<Pick<AIDescribeElementResponse, 'description'>> {\n assert(target, 'target is required for insight.describe');\n const context = await this.contextRetrieverFn('describe');\n const { screenshotBase64, size } = context;\n assert(screenshotBase64, 'screenshot is required for insight.describe');\n\n const systemPrompt = elementDescriberInstruction();\n\n // Convert [x,y] center point to Rect if needed\n const defaultRectSize = 30;\n const targetRect: Rect = Array.isArray(target)\n ? {\n left: Math.floor(target[0] - defaultRectSize / 2),\n top: Math.floor(target[1] - defaultRectSize / 2),\n width: defaultRectSize,\n height: defaultRectSize,\n }\n : target;\n\n let imagePayload = await compositeElementInfoImg({\n inputImgBase64: screenshotBase64,\n size,\n elementsPositionInfo: [\n {\n rect: targetRect,\n },\n ],\n borderThickness: 3,\n });\n\n if (opt?.deepThink) {\n const searchArea = expandSearchArea(targetRect, context.size);\n debug('describe: set searchArea', searchArea);\n imagePayload = await cropByRect(\n imagePayload,\n searchArea,\n getAIConfigInBoolean(MIDSCENE_USE_QWEN_VL),\n );\n }\n\n const msgs: AIArgs = [\n { role: 'system', content: systemPrompt },\n {\n role: 'user',\n content: [\n {\n type: 'image_url',\n image_url: {\n url: imagePayload,\n detail: 'high',\n },\n },\n ],\n },\n ];\n\n const callAIFn =\n this.aiVendorFn || callToGetJSONObject<AIDescribeElementResponse>;\n\n const res = await callAIFn(msgs, AIActionType.DESCRIBE_ELEMENT);\n\n const { content } = res;\n assert(!content.error, `describe failed: ${content.error}`);\n assert(content.description, 'failed to describe the element');\n return content;\n }\n}\n","import type {\n DumpMeta,\n DumpSubscriber,\n InsightDump,\n PartialInsightDumpFromSDK,\n} from '@/types';\nimport { getVersion } from '@/utils';\nimport { MIDSCENE_MODEL_NAME, getAIConfig } from '@midscene/shared/env';\nimport { uuid } from '@midscene/shared/utils';\n\nexport function emitInsightDump(\n data: PartialInsightDumpFromSDK,\n dumpSubscriber?: DumpSubscriber,\n) {\n const baseData: DumpMeta = {\n sdkVersion: getVersion(),\n logTime: Date.now(),\n model_name: getAIConfig(MIDSCENE_MODEL_NAME) || '',\n };\n const finalData: InsightDump = {\n logId: uuid(),\n ...baseData,\n ...data,\n };\n\n dumpSubscriber?.(finalData);\n}\n","import { Executor } from './ai-model/action-executor';\nimport Insight from './insight/index';\nimport { getVersion } from './utils';\n\nexport {\n plan,\n describeUserPage,\n AiLocateElement,\n AiAssert,\n} from './ai-model/index';\n\nexport { getAIConfig, MIDSCENE_MODEL_NAME } from '@midscene/shared/env';\n\nexport type * from './types';\nexport default Insight;\nexport { Executor, Insight, getVersion };\n\nexport type {\n MidsceneYamlScript,\n MidsceneYamlTask,\n MidsceneYamlFlowItem,\n MidsceneYamlFlowItemAIRightClick,\n MidsceneYamlConfigResult,\n} from './yaml';\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as AIUsageInfo, U as UIContext,
|
|
1
|
+
import { m as AIUsageInfo, U as UIContext, aE as ReferenceImage, r as AIElementLocatorResponse, N as ElementById, g as InsightExtractOption, u as AIDataExtractionResponse, w as AIAssertionResponse, ay as PageType, W as PlanningAIResponse } from './types-d187efec.js';
|
|
2
2
|
import { Rect, ElementTreeNode, BaseElement } from '@midscene/shared/types';
|
|
3
3
|
import { ChatCompletionSystemMessageParam, ChatCompletionUserMessageParam } from 'openai/resources';
|
|
4
4
|
|
|
@@ -63,6 +63,7 @@ declare function AiLocateElement<ElementType extends BaseElement = BaseElement>(
|
|
|
63
63
|
rawResponse: string;
|
|
64
64
|
elementById: ElementById;
|
|
65
65
|
usage?: AIUsageInfo;
|
|
66
|
+
isOrderSensitive?: boolean;
|
|
66
67
|
}>;
|
|
67
68
|
declare function AiLocateSection(options: {
|
|
68
69
|
context: UIContext<BaseElement>;
|
|
@@ -210,10 +210,12 @@ interface AIElementLocatorResponse {
|
|
|
210
210
|
xpaths?: string[];
|
|
211
211
|
}[];
|
|
212
212
|
bbox?: [number, number, number, number];
|
|
213
|
+
isOrderSensitive?: boolean;
|
|
213
214
|
errors?: string[];
|
|
214
215
|
}
|
|
215
216
|
interface AIElementCoordinatesResponse {
|
|
216
217
|
bbox: [number, number, number, number];
|
|
218
|
+
isOrderSensitive?: boolean;
|
|
217
219
|
errors?: string[];
|
|
218
220
|
}
|
|
219
221
|
type AIElementResponse = AIElementLocatorResponse | AIElementCoordinatesResponse;
|
|
@@ -279,6 +281,7 @@ type LocateResultElement = {
|
|
|
279
281
|
nodeType: NodeType;
|
|
280
282
|
[key: string]: string;
|
|
281
283
|
};
|
|
284
|
+
isOrderSensitive?: boolean;
|
|
282
285
|
};
|
|
283
286
|
interface LocateResult {
|
|
284
287
|
element: LocateResultElement | null;
|
|
@@ -354,7 +357,7 @@ interface PlanningLocateParam extends DetailedLocateParam {
|
|
|
354
357
|
}
|
|
355
358
|
interface PlanningAction<ParamType = any> {
|
|
356
359
|
thought?: string;
|
|
357
|
-
type: 'Locate' | 'Tap' | 'RightClick' | 'Hover' | 'Drag' | 'Input' | 'KeyboardPress' | 'Scroll' | 'Error' | 'ExpectedFalsyCondition' | 'Assert' | 'AssertWithoutThrow' | 'Sleep' | 'Finished' | 'AndroidBackButton' | 'AndroidHomeButton' | 'AndroidRecentAppsButton';
|
|
360
|
+
type: 'Locate' | 'Tap' | 'RightClick' | 'Hover' | 'Drag' | 'Input' | 'KeyboardPress' | 'Scroll' | 'Error' | 'ExpectedFalsyCondition' | 'Assert' | 'AssertWithoutThrow' | 'Sleep' | 'Finished' | 'AndroidBackButton' | 'AndroidHomeButton' | 'AndroidRecentAppsButton' | 'AndroidLongPress' | 'AndroidPull';
|
|
358
361
|
param: ParamType;
|
|
359
362
|
locate?: PlanningLocateParam | null;
|
|
360
363
|
}
|
|
@@ -390,6 +393,20 @@ interface PlanningActionParamError {
|
|
|
390
393
|
type PlanningActionParamWaitFor = AgentWaitForOpt & {
|
|
391
394
|
assertion: string;
|
|
392
395
|
};
|
|
396
|
+
interface PlanningActionParamAndroidLongPress {
|
|
397
|
+
x: number;
|
|
398
|
+
y: number;
|
|
399
|
+
duration?: number;
|
|
400
|
+
}
|
|
401
|
+
interface PlanningActionParamAndroidPull {
|
|
402
|
+
direction: 'up' | 'down';
|
|
403
|
+
startPoint?: {
|
|
404
|
+
x: number;
|
|
405
|
+
y: number;
|
|
406
|
+
};
|
|
407
|
+
distance?: number;
|
|
408
|
+
duration?: number;
|
|
409
|
+
}
|
|
393
410
|
/**
|
|
394
411
|
* misc
|
|
395
412
|
*/
|
|
@@ -525,4 +542,4 @@ interface StreamingAIResponse {
|
|
|
525
542
|
isStreamed: boolean;
|
|
526
543
|
}
|
|
527
544
|
|
|
528
|
-
export { type PlanningActionParamScroll as $, type AIDescribeElementResponse as A, type EnsureObject as B, type CallAIFn as C, type DumpSubscriber as D, type ExecutionTask as E, type InsightExtractParam as F, type LocateResultElement as G, type DumpMeta as H, type InsightAction as I, type InsightDump as J, type LiteUISection as K, type LocateResult as L, type MidsceneYamlScript as M, type ElementById as N, type OnTaskStartTip as O, type PartialInsightDumpFromSDK as P, type AgentWaitForOpt as Q, type ReportDumpWithAttributes as R, type AgentAssertOpt as S, type PlanningLocateParam as T, UIContext as U, type PlanningAction as V, type PlanningAIResponse as W, type PlanningActionParamTap as X, type PlanningActionParamHover as Y, type PlanningActionParamRightClick as Z, type PlanningActionParamInputOrKeyPress as _, type ExecutionTaskProgressOptions as a, type
|
|
545
|
+
export { type PlanningActionParamScroll as $, type AIDescribeElementResponse as A, type EnsureObject as B, type CallAIFn as C, type DumpSubscriber as D, type ExecutionTask as E, type InsightExtractParam as F, type LocateResultElement as G, type DumpMeta as H, type InsightAction as I, type InsightDump as J, type LiteUISection as K, type LocateResult as L, type MidsceneYamlScript as M, type ElementById as N, type OnTaskStartTip as O, type PartialInsightDumpFromSDK as P, type AgentWaitForOpt as Q, type ReportDumpWithAttributes as R, type AgentAssertOpt as S, type PlanningLocateParam as T, UIContext as U, type PlanningAction as V, type PlanningAIResponse as W, type PlanningActionParamTap as X, type PlanningActionParamHover as Y, type PlanningActionParamRightClick as Z, type PlanningActionParamInputOrKeyPress as _, type ExecutionTaskProgressOptions as a, type FreeFn as a$, type PlanningActionParamAssert as a0, type PlanningActionParamSleep as a1, type PlanningActionParamError as a2, type PlanningActionParamWaitFor as a3, type PlanningActionParamAndroidLongPress as a4, type PlanningActionParamAndroidPull as a5, type Color as a6, type BaseAgentParserOpt as a7, type PuppeteerParserOpt as a8, type PlaywrightParserOpt as a9, type StreamingCallback as aA, type CodeGenerationChunk as aB, type StreamingAIResponse as aC, type LocateOption as aD, type ReferenceImage as aE, type scrollParam as aF, type MidsceneYamlScriptEnvBase as aG, type MidsceneYamlScriptWebEnv as aH, type MidsceneYamlScriptAndroidEnv as aI, type MidsceneYamlScriptEnv as aJ, type MidsceneYamlFlowItemAIAction as aK, type MidsceneYamlFlowItemAIAssert as aL, type MidsceneYamlFlowItemAIQuery as aM, type MidsceneYamlFlowItemAINumber as aN, type MidsceneYamlFlowItemAIString as aO, type MidsceneYamlFlowItemAIAsk as aP, type MidsceneYamlFlowItemAIBoolean as aQ, type MidsceneYamlFlowItemAILocate as aR, type MidsceneYamlFlowItemAIWaitFor as aS, type MidsceneYamlFlowItemAITap as aT, type MidsceneYamlFlowItemAIHover as aU, type MidsceneYamlFlowItemAIInput as aV, type MidsceneYamlFlowItemAIKeyboardPress as aW, type MidsceneYamlFlowItemAIScroll as aX, type MidsceneYamlFlowItemEvaluateJavaScript as aY, type MidsceneYamlFlowItemSleep as aZ, type MidsceneYamlFlowItemLogScreenshot as a_, type ExecutionRecorderItem as aa, type ExecutionTaskType as ab, type ExecutorContext as ac, type ExecutionTaskHitBy as ad, type ExecutionTaskReturn as ae, type ExecutionTaskInsightLocateParam as af, type ExecutionTaskInsightLocateOutput as ag, type ExecutionTaskInsightDumpLog as ah, type ExecutionTaskInsightLocateApply as ai, type ExecutionTaskInsightLocate as aj, type ExecutionTaskInsightQueryParam as ak, type ExecutionTaskInsightQueryOutput as al, type ExecutionTaskInsightQueryApply as am, type ExecutionTaskInsightQuery as an, type ExecutionTaskInsightAssertionParam as ao, type ExecutionTaskInsightAssertionApply as ap, type ExecutionTaskInsightAssertion as aq, type ExecutionTaskActionApply as ar, type ExecutionTaskAction as as, type ExecutionTaskLogApply as at, type ExecutionTaskLog as au, type ExecutionTaskPlanningApply as av, type ExecutionTaskPlanning as aw, type GroupedActionDump as ax, type PageType as ay, type StreamingCodeGenerationOptions as az, type ExecutionTaskApply as b, type ScriptPlayerTaskStatus as b0, type ScriptPlayerStatusValue as b1, type MidsceneYamlConfig as b2, type MidsceneYamlConfigOutput as b3, type ExecutionDump as c, type InsightTaskInfo as d, type InsightOptions as e, type DetailedLocateParam as f, type InsightExtractOption as g, type InsightAssertionResponse as h, type MidsceneYamlTask as i, type MidsceneYamlFlowItem as j, type MidsceneYamlFlowItemAIRightClick as k, type MidsceneYamlConfigResult as l, type AIUsageInfo as m, AIResponseFormat as n, type AISingleElementResponseById as o, type AISingleElementResponseByPosition as p, type AISingleElementResponse as q, type AIElementLocatorResponse as r, type AIElementCoordinatesResponse as s, type AIElementResponse as t, type AIDataExtractionResponse as u, type AISectionLocatorResponse as v, type AIAssertionResponse as w, type LocatorValidatorOption as x, type LocateValidatorResult as y, type AgentDescribeElementAtPointResult as z };
|
package/dist/es/utils.d.ts
CHANGED
package/dist/es/utils.js
CHANGED
package/dist/lib/ai-model.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { aA as StreamingCallback, m as AIUsageInfo, az as StreamingCodeGenerationOptions, aC as StreamingAIResponse, V as PlanningAction, j as MidsceneYamlFlowItem } from './types-d187efec.js';
|
|
2
2
|
import OpenAI from 'openai';
|
|
3
3
|
import { ChatCompletionMessageParam } from 'openai/resources';
|
|
4
4
|
export { ChatCompletionMessageParam } from 'openai/resources';
|
|
5
|
-
import { b as AIActionType } from './llm-planning-
|
|
6
|
-
export { a as AiAssert, f as AiExtractElementInfo, A as AiLocateElement, g as AiLocateSection, h as adaptBboxToRect, c as callAiFn, d as describeUserPage, e as elementByPositionWithElementInfo, p as plan } from './llm-planning-
|
|
5
|
+
import { b as AIActionType } from './llm-planning-ae19dc49.js';
|
|
6
|
+
export { a as AiAssert, f as AiExtractElementInfo, A as AiLocateElement, g as AiLocateSection, h as adaptBboxToRect, c as callAiFn, d as describeUserPage, e as elementByPositionWithElementInfo, p as plan } from './llm-planning-ae19dc49.js';
|
|
7
7
|
import { vlLocateMode } from '@midscene/shared/env';
|
|
8
8
|
import { actionParser } from '@ui-tars/action-parser';
|
|
9
9
|
import { Size } from '@midscene/shared/types';
|
package/dist/lib/ai-model.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _chunk3LFZDNMQjs = require('./chunk-3LFZDNMQ.js');
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
@@ -39,4 +39,4 @@ var _chunkTV47VKQ7js = require('./chunk-TV47VKQ7.js');
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
exports.AIActionType =
|
|
42
|
+
exports.AIActionType = _chunk3LFZDNMQjs.AIActionType; exports.AiAssert = _chunk3LFZDNMQjs.AiAssert; exports.AiExtractElementInfo = _chunk3LFZDNMQjs.AiExtractElementInfo; exports.AiLocateElement = _chunk3LFZDNMQjs.AiLocateElement; exports.AiLocateSection = _chunk3LFZDNMQjs.AiLocateSection; exports.adaptBboxToRect = _chunk3LFZDNMQjs.adaptBboxToRect; exports.callAi = _chunk3LFZDNMQjs.call; exports.callAiFn = _chunk3LFZDNMQjs.callAiFn; exports.callToGetJSONObject = _chunk3LFZDNMQjs.callToGetJSONObject; exports.describeUserPage = _chunk3LFZDNMQjs.describeUserPage; exports.elementByPositionWithElementInfo = _chunk3LFZDNMQjs.elementByPositionWithElementInfo; exports.generatePlaywrightTest = _chunk3LFZDNMQjs.generatePlaywrightTest; exports.generatePlaywrightTestStream = _chunk3LFZDNMQjs.generatePlaywrightTestStream; exports.generateYamlTest = _chunk3LFZDNMQjs.generateYamlTest; exports.generateYamlTestStream = _chunk3LFZDNMQjs.generateYamlTestStream; exports.plan = _chunk3LFZDNMQjs.plan; exports.resizeImageForUiTars = _chunk3LFZDNMQjs.resizeImageForUiTars; exports.systemPromptToLocateElement = _chunk3LFZDNMQjs.systemPromptToLocateElement; exports.vlmPlanning = _chunk3LFZDNMQjs.vlmPlanning;
|
|
@@ -300,7 +300,7 @@ function buildYamlFlowFromPlans(plans, sleep) {
|
|
|
300
300
|
flow.push({
|
|
301
301
|
sleep: param.timeMs
|
|
302
302
|
});
|
|
303
|
-
} else if (type === "AndroidBackButton" || type === "AndroidHomeButton" || type === "AndroidRecentAppsButton") {
|
|
303
|
+
} else if (type === "AndroidBackButton" || type === "AndroidHomeButton" || type === "AndroidRecentAppsButton" || type === "AndroidLongPress" || type === "AndroidPull") {
|
|
304
304
|
} else if (type === "Error" || type === "ExpectedFalsyCondition" || type === "Assert" || type === "AssertWithoutThrow" || type === "Finished") {
|
|
305
305
|
} else {
|
|
306
306
|
console.warn(
|
|
@@ -386,31 +386,47 @@ You are an expert in software testing.
|
|
|
386
386
|
## Objective:
|
|
387
387
|
- Identify elements in screenshots and text that match the user's description.
|
|
388
388
|
- Give the coordinates of the element that matches the user's description best in the screenshot.
|
|
389
|
+
- Determine whether the user's description is order-sensitive (e.g., contains phrases like 'the third item in the list', 'the last button', etc.).
|
|
389
390
|
|
|
390
391
|
## Output Format:
|
|
391
392
|
\`\`\`json
|
|
392
393
|
{
|
|
393
394
|
"bbox": [number, number, number, number], // ${bboxComment}
|
|
394
|
-
"errors"?: string[]
|
|
395
|
+
"errors"?: string[],
|
|
396
|
+
"isOrderSensitive": boolean // Whether the targetElementDescription is order-sensitive (true/false)
|
|
395
397
|
}
|
|
396
398
|
\`\`\`
|
|
397
399
|
|
|
398
400
|
Fields:
|
|
399
401
|
* \`bbox\` is the bounding box of the element that matches the user's description best in the screenshot
|
|
402
|
+
* \`isOrderSensitive\` is a boolean indicating whether the user's description is order-sensitive (true/false)
|
|
400
403
|
* \`errors\` is an optional array of error messages (if any)
|
|
401
404
|
|
|
402
|
-
|
|
405
|
+
Order-sensitive means the description contains phrases like:
|
|
406
|
+
- "the third item in the list"
|
|
407
|
+
- "the last button"
|
|
408
|
+
- "the first input box"
|
|
409
|
+
- "the second row"
|
|
410
|
+
|
|
411
|
+
Not order-sensitive means the description is like:
|
|
412
|
+
- "confirm button"
|
|
413
|
+
- "search box"
|
|
414
|
+
- "password input"
|
|
415
|
+
|
|
416
|
+
For example, when an element is found and the description is order-sensitive:
|
|
403
417
|
\`\`\`json
|
|
404
418
|
{
|
|
405
419
|
"bbox": [100, 100, 200, 200],
|
|
420
|
+
"isOrderSensitive": true,
|
|
406
421
|
"errors": []
|
|
407
422
|
}
|
|
408
423
|
\`\`\`
|
|
409
424
|
|
|
410
|
-
When no element is found:
|
|
425
|
+
When no element is found and the description is not order-sensitive:
|
|
411
426
|
\`\`\`json
|
|
412
427
|
{
|
|
413
428
|
"bbox": [],
|
|
429
|
+
"isOrderSensitive": false,
|
|
414
430
|
"errors": ["I can see ..., but {some element} is not found"]
|
|
415
431
|
}
|
|
416
432
|
\`\`\`
|
|
@@ -423,6 +439,7 @@ You are an expert in software page image (2D) and page element text analysis.
|
|
|
423
439
|
## Objective:
|
|
424
440
|
- Identify elements in screenshots and text that match the user's description.
|
|
425
441
|
- Return JSON data containing the selection reason and element ID.
|
|
442
|
+
- Determine whether the user's description is order-sensitive (e.g., contains phrases like 'the third item in the list', 'the last button', etc.).
|
|
426
443
|
|
|
427
444
|
## Skills:
|
|
428
445
|
- Image analysis and recognition
|
|
@@ -434,6 +451,7 @@ You are an expert in software page image (2D) and page element text analysis.
|
|
|
434
451
|
2. Based on the user's description, locate the target element ID in the list of element descriptions and the screenshot.
|
|
435
452
|
3. Found the required number of elements
|
|
436
453
|
4. Return JSON data containing the selection reason and element ID.
|
|
454
|
+
5. Judge whether the user's description is order-sensitive (see below for definition and examples).
|
|
437
455
|
|
|
438
456
|
## Constraints:
|
|
439
457
|
- Strictly adhere to the specified location when describing the required element; do not select elements from other locations.
|
|
@@ -443,6 +461,10 @@ You are an expert in software page image (2D) and page element text analysis.
|
|
|
443
461
|
- The returned data must conform to the specified JSON format.
|
|
444
462
|
- The returned value id information must use the id from element info (important: **use id not indexId, id is hash content**)
|
|
445
463
|
|
|
464
|
+
## Order-Sensitive Definition:
|
|
465
|
+
- If the description contains phrases like "the third item in the list", "the last button", "the first input box", "the second row", etc., it is order-sensitive (isOrderSensitive = true).
|
|
466
|
+
- If the description is like "confirm button", "search box", "password input", etc., it is not order-sensitive (isOrderSensitive = false).
|
|
467
|
+
|
|
446
468
|
## Output Format:
|
|
447
469
|
|
|
448
470
|
Please return the result in JSON format as follows:
|
|
@@ -458,6 +480,7 @@ Please return the result in JSON format as follows:
|
|
|
458
480
|
}
|
|
459
481
|
// More elements...
|
|
460
482
|
],
|
|
483
|
+
"isOrderSensitive": true, // or false, depending on the user's description
|
|
461
484
|
"errors": [] // Array of strings containing any error messages
|
|
462
485
|
}
|
|
463
486
|
\`\`\`
|
|
@@ -546,6 +569,7 @@ Output Example:
|
|
|
546
569
|
"id": "1231"
|
|
547
570
|
}
|
|
548
571
|
],
|
|
572
|
+
"isOrderSensitive": true,
|
|
549
573
|
"errors": []
|
|
550
574
|
}
|
|
551
575
|
\`\`\`
|
|
@@ -583,6 +607,10 @@ var locatorSchema = {
|
|
|
583
607
|
},
|
|
584
608
|
description: "List of found elements"
|
|
585
609
|
},
|
|
610
|
+
isOrderSensitive: {
|
|
611
|
+
type: "boolean",
|
|
612
|
+
description: "Whether the targetElementDescription is order-sensitive (true/false)"
|
|
613
|
+
},
|
|
586
614
|
errors: {
|
|
587
615
|
type: "array",
|
|
588
616
|
items: {
|
|
@@ -591,7 +619,7 @@ var locatorSchema = {
|
|
|
591
619
|
description: "List of error messages, if any"
|
|
592
620
|
}
|
|
593
621
|
},
|
|
594
|
-
required: ["elements", "errors"],
|
|
622
|
+
required: ["elements", "isOrderSensitive", "errors"],
|
|
595
623
|
additionalProperties: false
|
|
596
624
|
}
|
|
597
625
|
}
|
|
@@ -766,7 +794,7 @@ Target: User will give you a screenshot, an instruction and some previous logs i
|
|
|
766
794
|
|
|
767
795
|
Restriction:
|
|
768
796
|
- Don't give extra actions or plans beyond the instruction. ONLY plan for what the instruction requires. For example, don't try to submit the form if the instruction is only to fill something.
|
|
769
|
-
- Always give ONLY ONE action in \`log\` field (or null if no action should be done), instead of multiple actions. Supported actions are Tap, Hover, Input, KeyboardPress, Scroll${pageType === "android" ? ", AndroidBackButton, AndroidHomeButton, AndroidRecentAppsButton." : "."}
|
|
797
|
+
- Always give ONLY ONE action in \`log\` field (or null if no action should be done), instead of multiple actions. Supported actions are Tap, Hover, Input, KeyboardPress, Scroll${pageType === "android" ? ", AndroidBackButton, AndroidHomeButton, AndroidRecentAppsButton, AndroidLongPress, AndroidPull." : "."}
|
|
770
798
|
- Don't repeat actions in the previous logs.
|
|
771
799
|
- Bbox is the bounding box of the element to be located. It's an array of 4 numbers, representing ${bboxDescription(vlMode)}.
|
|
772
800
|
|
|
@@ -779,7 +807,9 @@ Supporting actions:
|
|
|
779
807
|
- Scroll: { type: "Scroll", ${vlLocateParam} | null, param: { direction: 'down'(default) | 'up' | 'right' | 'left', scrollType: 'once' (default) | 'untilBottom' | 'untilTop' | 'untilRight' | 'untilLeft', distance: null | number }} // locate is the element to scroll. If it's a page scroll, put \`null\` in the \`locate\` field.
|
|
780
808
|
${pageType === "android" ? `- AndroidBackButton: { type: "AndroidBackButton", param: {} }
|
|
781
809
|
- AndroidHomeButton: { type: "AndroidHomeButton", param: {} }
|
|
782
|
-
- AndroidRecentAppsButton: { type: "AndroidRecentAppsButton", param: {} }
|
|
810
|
+
- AndroidRecentAppsButton: { type: "AndroidRecentAppsButton", param: {} }
|
|
811
|
+
- AndroidLongPress: { type: "AndroidLongPress", param: { x: number, y: number, duration?: number } }
|
|
812
|
+
- AndroidPull: { type: "AndroidPull", param: { direction: 'up' | 'down', startPoint?: { x: number, y: number }, distance?: number, duration?: number } } // Pull down to refresh (direction: 'down') or pull up to load more (direction: 'up')` : ""}
|
|
783
813
|
|
|
784
814
|
Field description:
|
|
785
815
|
* The \`prompt\` field inside the \`locate\` field is a short description that could be used to locate the element.
|
|
@@ -829,7 +859,7 @@ You are a versatile professional in software UI automation. Your outstanding con
|
|
|
829
859
|
## Workflow
|
|
830
860
|
|
|
831
861
|
1. Receive the screenshot, element description of screenshot(if any), user's instruction and previous logs.
|
|
832
|
-
2. Decompose the user's task into a sequence of actions, and place it in the \`actions\` field. There are different types of actions (Tap / Hover / Input / KeyboardPress / Scroll / FalsyConditionStatement / Sleep ${pageType === "android" ? "/ AndroidBackButton / AndroidHomeButton / AndroidRecentAppsButton" : ""}). The "About the action" section below will give you more details.
|
|
862
|
+
2. Decompose the user's task into a sequence of actions, and place it in the \`actions\` field. There are different types of actions (Tap / Hover / Input / KeyboardPress / Scroll / FalsyConditionStatement / Sleep ${pageType === "android" ? "/ AndroidBackButton / AndroidHomeButton / AndroidRecentAppsButton / AndroidLongPress / AndroidPull" : ""}). The "About the action" section below will give you more details.
|
|
833
863
|
3. Precisely locate the target element if it's already shown in the screenshot, put the location info in the \`locate\` field of the action.
|
|
834
864
|
4. If some target elements is not shown in the screenshot, consider the user's instruction is not feasible on this page. Follow the next steps.
|
|
835
865
|
5. Consider whether the user's instruction will be accomplished after all the actions
|
|
@@ -888,7 +918,11 @@ ${pageType === "android" ? `- type: 'AndroidBackButton', trigger the system "bac
|
|
|
888
918
|
- type: 'AndroidHomeButton', trigger the system "home" operation on Android devices
|
|
889
919
|
* {{ param: {{}} }}
|
|
890
920
|
- type: 'AndroidRecentAppsButton', trigger the system "recent apps" operation on Android devices
|
|
891
|
-
* {{ param: {{}} }}
|
|
921
|
+
* {{ param: {{}} }}
|
|
922
|
+
- type: 'AndroidLongPress', trigger a long press on the screen at specified coordinates on Android devices
|
|
923
|
+
* {{ param: {{ x: number, y: number, duration?: number }} }}
|
|
924
|
+
- type: 'AndroidPull', trigger pull down to refresh or pull up actions on Android devices
|
|
925
|
+
* {{ param: {{ direction: 'up' | 'down', startPoint?: {{ x: number, y: number }}, distance?: number, duration?: number }} }}` : ""}
|
|
892
926
|
`;
|
|
893
927
|
var outputTemplate = `
|
|
894
928
|
## Output JSON Format:
|
|
@@ -1002,7 +1036,7 @@ var planSchema = {
|
|
|
1002
1036
|
},
|
|
1003
1037
|
type: {
|
|
1004
1038
|
type: "string",
|
|
1005
|
-
description: 'Type of action, one of "Tap", "RightClick", "Hover" , "Input", "KeyboardPress", "Scroll", "ExpectedFalsyCondition", "Sleep", "AndroidBackButton", "AndroidHomeButton", "AndroidRecentAppsButton"'
|
|
1039
|
+
description: 'Type of action, one of "Tap", "RightClick", "Hover" , "Input", "KeyboardPress", "Scroll", "ExpectedFalsyCondition", "Sleep", "AndroidBackButton", "AndroidHomeButton", "AndroidRecentAppsButton", "AndroidLongPress"'
|
|
1006
1040
|
},
|
|
1007
1041
|
param: {
|
|
1008
1042
|
anyOf: [
|
|
@@ -2230,7 +2264,8 @@ async function AiLocateElement(options) {
|
|
|
2230
2264
|
},
|
|
2231
2265
|
rawResponse,
|
|
2232
2266
|
elementById,
|
|
2233
|
-
usage: res.usage
|
|
2267
|
+
usage: res.usage,
|
|
2268
|
+
isOrderSensitive: typeof res.content === "object" && res.content !== null && "isOrderSensitive" in res.content ? res.content.isOrderSensitive : void 0
|
|
2234
2269
|
};
|
|
2235
2270
|
}
|
|
2236
2271
|
async function AiLocateSection(options) {
|
|
@@ -2681,6 +2716,39 @@ async function vlmPlanning(options) {
|
|
|
2681
2716
|
type: "AndroidRecentAppsButton",
|
|
2682
2717
|
param: {}
|
|
2683
2718
|
});
|
|
2719
|
+
} else if (action.action_type === "androidLongPress") {
|
|
2720
|
+
_utils.assert.call(void 0,
|
|
2721
|
+
action.action_inputs.start_coords,
|
|
2722
|
+
"start_coords is required for androidLongPress"
|
|
2723
|
+
);
|
|
2724
|
+
const point = action.action_inputs.start_coords;
|
|
2725
|
+
transformActions.push({
|
|
2726
|
+
type: "AndroidLongPress",
|
|
2727
|
+
param: {
|
|
2728
|
+
x: point[0],
|
|
2729
|
+
y: point[1],
|
|
2730
|
+
duration: 1e3
|
|
2731
|
+
},
|
|
2732
|
+
locate: null,
|
|
2733
|
+
thought: action.thought || ""
|
|
2734
|
+
});
|
|
2735
|
+
} else if (action.action_type === "androidPull") {
|
|
2736
|
+
const pullDirection = action.action_inputs.direction || "down";
|
|
2737
|
+
const startPoint = action.action_inputs.start_coords ? {
|
|
2738
|
+
x: action.action_inputs.start_coords[0],
|
|
2739
|
+
y: action.action_inputs.start_coords[1]
|
|
2740
|
+
} : void 0;
|
|
2741
|
+
transformActions.push({
|
|
2742
|
+
type: "AndroidPull",
|
|
2743
|
+
param: {
|
|
2744
|
+
direction: pullDirection,
|
|
2745
|
+
startPoint,
|
|
2746
|
+
distance: action.action_inputs.distance,
|
|
2747
|
+
duration: action.action_inputs.duration || 500
|
|
2748
|
+
},
|
|
2749
|
+
locate: null,
|
|
2750
|
+
thought: action.thought || ""
|
|
2751
|
+
});
|
|
2684
2752
|
}
|
|
2685
2753
|
});
|
|
2686
2754
|
if (transformActions.length === 0) {
|
|
@@ -2764,4 +2832,4 @@ async function resizeImageForUiTars(imageBase64, size) {
|
|
|
2764
2832
|
|
|
2765
2833
|
exports.systemPromptToLocateElement = systemPromptToLocateElement; exports.elementByPositionWithElementInfo = elementByPositionWithElementInfo; exports.describeUserPage = describeUserPage; exports.call = call; exports.callToGetJSONObject = callToGetJSONObject; exports.AIActionType = AIActionType; exports.callAiFn = callAiFn; exports.adaptBboxToRect = adaptBboxToRect; exports.expandSearchArea = expandSearchArea; exports.generateYamlTest = generateYamlTest; exports.generateYamlTestStream = generateYamlTestStream; exports.generatePlaywrightTest = generatePlaywrightTest; exports.generatePlaywrightTestStream = generatePlaywrightTestStream; exports.AiLocateElement = AiLocateElement; exports.AiLocateSection = AiLocateSection; exports.AiExtractElementInfo = AiExtractElementInfo; exports.AiAssert = AiAssert; exports.plan = plan; exports.vlmPlanning = vlmPlanning; exports.resizeImageForUiTars = resizeImageForUiTars;
|
|
2766
2834
|
|
|
2767
|
-
//# sourceMappingURL=chunk-
|
|
2835
|
+
//# sourceMappingURL=chunk-3LFZDNMQ.js.map
|