@midscene/playground 1.10.1 → 1.10.2
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/recorder-ui-describer.mjs +2 -15
- package/dist/es/recorder-ui-describer.mjs.map +1 -1
- package/dist/es/server.mjs +31 -1
- package/dist/es/server.mjs.map +1 -1
- package/dist/lib/recorder-ui-describer.js +2 -15
- package/dist/lib/recorder-ui-describer.js.map +1 -1
- package/dist/lib/server.js +31 -1
- package/dist/lib/server.js.map +1 -1
- package/dist/types/recorder-ui-describer.d.ts +3 -3
- package/package.json +3 -3
- package/static/index.html +1 -1
- package/static/static/js/{index.3146a384.js → index.f720647c.js} +138 -138
- package/static/static/js/index.f720647c.js.map +1 -0
- package/static/static/js/index.3146a384.js.map +0 -1
- /package/static/static/js/{index.3146a384.js.LICENSE.txt → index.f720647c.js.LICENSE.txt} +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ModelConfigManager } from "@midscene/shared/env";
|
|
2
1
|
import { buildMidsceneRecorderActionSummary, buildMidsceneRecorderReplayInstruction, getMidsceneRecorderSemantic } from "@midscene/shared/recorder";
|
|
3
2
|
import { callAIWithObjectResponse } from "./recorder-ai-service.mjs";
|
|
4
3
|
import { RECORDER_UI_DESCRIBER_SYSTEM_PROMPT } from "./recorder-ui-describer-prompt.mjs";
|
|
@@ -8,17 +7,6 @@ const RECORDER_UI_DESCRIBER_DEFAULT_CONCURRENCY = 2;
|
|
|
8
7
|
function delay(ms) {
|
|
9
8
|
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
10
9
|
}
|
|
11
|
-
function isResolvedModelConfig(modelConfig) {
|
|
12
|
-
return 'string' == typeof modelConfig.modelName && ('string' == typeof modelConfig.modelDescription || 'string' == typeof modelConfig.intent || 'string' == typeof modelConfig.slot || 'string' == typeof modelConfig.openaiApiKey);
|
|
13
|
-
}
|
|
14
|
-
function resolveRecorderModelConfig(modelConfig) {
|
|
15
|
-
if (isResolvedModelConfig(modelConfig)) return modelConfig;
|
|
16
|
-
const rawModelConfig = Object.entries(modelConfig).reduce((result, [key, value])=>{
|
|
17
|
-
if ('string' == typeof value || 'number' == typeof value) result[key] = value;
|
|
18
|
-
return result;
|
|
19
|
-
}, {});
|
|
20
|
-
return new ModelConfigManager(rawModelConfig).getModelConfig('default');
|
|
21
|
-
}
|
|
22
10
|
function clamp(value, min, max) {
|
|
23
11
|
return Math.min(Math.max(value, min), max);
|
|
24
12
|
}
|
|
@@ -305,7 +293,7 @@ async function createScreenshotWithBox(event, rect) {
|
|
|
305
293
|
if (event.screenshotWithBox) return event.screenshotWithBox;
|
|
306
294
|
const screenshot = getRecorderEventScreenshot(event);
|
|
307
295
|
if (!screenshot) return;
|
|
308
|
-
const { compositeElementInfoImg } = await import(
|
|
296
|
+
const { compositeElementInfoImg } = await import("@midscene/shared/img");
|
|
309
297
|
return compositeElementInfoImg({
|
|
310
298
|
inputImgBase64: screenshot,
|
|
311
299
|
size: event.pageInfo,
|
|
@@ -348,9 +336,8 @@ async function describeRecorderUIEvent(input, modelConfig, options = {}) {
|
|
|
348
336
|
}
|
|
349
337
|
let screenshotWithBox;
|
|
350
338
|
try {
|
|
351
|
-
const resolvedModelConfig = resolveRecorderModelConfig(modelConfig);
|
|
352
339
|
screenshotWithBox = await createScreenshotWithBox(event, rect);
|
|
353
|
-
const semanticFields = await describeWithRetry(event, input.target, screenshotWithBox || screenshot,
|
|
340
|
+
const semanticFields = await describeWithRetry(event, input.target, screenshotWithBox || screenshot, modelConfig, {
|
|
354
341
|
maxRetries: options.maxRetries ?? RECORDER_UI_DESCRIBER_DEFAULT_RETRIES,
|
|
355
342
|
retryDelayMs: options.retryDelayMs ?? RECORDER_UI_DESCRIBER_DEFAULT_RETRY_DELAY_MS
|
|
356
343
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recorder-ui-describer.mjs","sources":["../../src/recorder-ui-describer.ts"],"sourcesContent":["import type { Rect } from '@midscene/core';\nimport { type IModelConfig, ModelConfigManager } from '@midscene/shared/env';\nimport type {\n MidsceneRecorderEvent,\n MidsceneRecorderPageInfo,\n MidsceneRecorderSemanticAction,\n MidsceneRecorderTarget,\n} from '@midscene/shared/recorder';\nimport {\n buildMidsceneRecorderActionSummary,\n buildMidsceneRecorderReplayInstruction,\n getMidsceneRecorderSemantic,\n} from '@midscene/shared/recorder';\nimport { callAIWithObjectResponse } from './recorder-ai-service';\nimport { RECORDER_UI_DESCRIBER_SYSTEM_PROMPT } from './recorder-ui-describer-prompt';\n\nexport interface DescribeRecorderUIEventInput {\n event: MidsceneRecorderEvent;\n target?: MidsceneRecorderTarget;\n}\n\nexport interface DescribeRecorderUIEventOptions {\n maxRetries?: number;\n retryDelayMs?: number;\n concurrency?: number;\n}\n\nexport interface DescribeRecorderUIEventResult {\n event: MidsceneRecorderEvent;\n usedFallback: boolean;\n error?: string;\n}\n\ninterface RecorderUIEventAIResponse {\n elementDescription?: string;\n replayInstruction?: string;\n actionSummary?: string;\n scrollDestinationDescription?: string;\n confidence?: 'high' | 'medium' | 'low';\n error?: string;\n}\n\nconst RECORDER_UI_DESCRIBER_DEFAULT_RETRIES = 2;\nconst RECORDER_UI_DESCRIBER_DEFAULT_RETRY_DELAY_MS = 200;\nconst RECORDER_UI_DESCRIBER_DEFAULT_CONCURRENCY = 2;\n\nfunction delay(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nfunction isResolvedModelConfig(\n modelConfig: IModelConfig | Record<string, unknown>,\n): modelConfig is IModelConfig {\n return (\n typeof modelConfig.modelName === 'string' &&\n (typeof modelConfig.modelDescription === 'string' ||\n typeof modelConfig.intent === 'string' ||\n typeof modelConfig.slot === 'string' ||\n typeof modelConfig.openaiApiKey === 'string')\n );\n}\n\nfunction resolveRecorderModelConfig(\n modelConfig: IModelConfig | Record<string, unknown>,\n): IModelConfig {\n if (isResolvedModelConfig(modelConfig)) {\n return modelConfig;\n }\n const rawModelConfig = Object.entries(modelConfig).reduce<\n Record<string, string | number>\n >((result, [key, value]) => {\n if (typeof value === 'string' || typeof value === 'number') {\n result[key] = value;\n }\n return result;\n }, {});\n return new ModelConfigManager(rawModelConfig).getModelConfig('default');\n}\n\nfunction clamp(value: number, min: number, max: number) {\n return Math.min(Math.max(value, min), max);\n}\n\nfunction isFiniteNumber(value: unknown): value is number {\n return typeof value === 'number' && Number.isFinite(value);\n}\n\nfunction isPendingDescription(value?: string) {\n return value?.trim() === 'AI is analyzing element...';\n}\n\nfunction getRecorderEventScreenshot(event: MidsceneRecorderEvent) {\n return (\n event.screenshotWithBox || event.screenshotBefore || event.screenshotAfter\n );\n}\n\nfunction getRecorderEventAfterScreenshot(event: MidsceneRecorderEvent) {\n return event.screenshotAfter || event.screenshotWithBox;\n}\n\nfunction normalizeActionType(event: MidsceneRecorderEvent) {\n return event.actionType?.trim();\n}\n\nfunction getPlatformId(target?: MidsceneRecorderTarget) {\n return target?.platformId?.toLowerCase();\n}\n\nfunction getPlatformSurface(target?: MidsceneRecorderTarget) {\n switch (getPlatformId(target)) {\n case 'web':\n return 'current web page';\n case 'android':\n case 'ios':\n case 'harmony':\n return 'current mobile screen';\n case 'computer':\n return 'current desktop screen';\n default:\n return 'current UI';\n }\n}\n\nfunction getPlatformGuidance(target?: MidsceneRecorderTarget) {\n switch (getPlatformId(target)) {\n case 'web':\n return 'For web targets, use web UI terms such as button, input, link, menu item, tab, dialog, aria-label, placeholder, and form section when visible or inferable.';\n case 'android':\n case 'ios':\n case 'harmony':\n return 'For mobile targets, use mobile UI terms such as tab, list item, text field, icon button, navigation bar, bottom bar, sheet, card, and screen section.';\n case 'computer':\n return 'For desktop/computer targets, use desktop UI terms such as menu item, toolbar button, dialog field, sidebar item, window control, file row, and application region.';\n default:\n return 'Use platform-neutral UI terms such as control, field, item, icon button, list item, region, panel, and page section.';\n }\n}\n\nfunction getPointerActionVerb(event: MidsceneRecorderEvent) {\n switch (normalizeActionType(event)) {\n case 'Tap':\n return 'Tap';\n case 'DoubleClick':\n return 'Double click';\n case 'LongPress':\n return 'Long press';\n case 'RightClick':\n return 'Right click';\n default:\n return 'Click';\n }\n}\n\nfunction getDragActionVerb(event: MidsceneRecorderEvent) {\n switch (normalizeActionType(event)) {\n case 'Swipe':\n return 'Swipe';\n case 'DragAndDrop':\n return 'Drag';\n default:\n return 'Drag';\n }\n}\n\nfunction pointToRect(\n x: number,\n y: number,\n size: number,\n pageInfo: MidsceneRecorderPageInfo,\n): Rect {\n const width = pageInfo.width || size;\n const height = pageInfo.height || size;\n const left = clamp(Math.floor(x - size / 2), 0, Math.max(width - 1, 0));\n const top = clamp(Math.floor(y - size / 2), 0, Math.max(height - 1, 0));\n return {\n left,\n top,\n width: Math.min(size, Math.max(width - left, 1)),\n height: Math.min(size, Math.max(height - top, 1)),\n };\n}\n\nfunction getPointRectSize(event: MidsceneRecorderEvent) {\n switch (event.type) {\n case 'scroll':\n return 96;\n case 'drag':\n return 64;\n default:\n return 36;\n }\n}\n\nexport function getRecorderUIEventTargetRect(\n event: MidsceneRecorderEvent,\n): Rect | null {\n const rect = event.elementRect;\n if (!rect) {\n return null;\n }\n\n if (\n isFiniteNumber(rect.width) &&\n rect.width > 0 &&\n isFiniteNumber(rect.height) &&\n rect.height > 0 &&\n (isFiniteNumber(rect.left) || isFiniteNumber(rect.top))\n ) {\n return {\n left: rect.left || 0,\n top: rect.top || 0,\n width: rect.width,\n height: rect.height,\n };\n }\n\n if (isFiniteNumber(rect.x) && isFiniteNumber(rect.y)) {\n return pointToRect(rect.x, rect.y, getPointRectSize(event), event.pageInfo);\n }\n\n return null;\n}\n\nfunction getFallbackDescription(\n event: MidsceneRecorderEvent,\n target?: MidsceneRecorderTarget,\n) {\n const pageContext = getPageSemanticContext(event);\n const surface = getPlatformSurface(target);\n\n switch (event.type) {\n case 'navigation':\n return event.url || event.value || event.actionType || 'navigation';\n case 'scroll':\n return pageContext\n ? `${pageContext} scrollable content`\n : `scrollable content on the ${surface}`;\n case 'drag':\n return pageContext\n ? `gesture area in ${pageContext}`\n : `gesture area on the ${surface}`;\n case 'input':\n return `unresolved input field on the ${surface}`;\n case 'keydown':\n return pageContext\n ? `focused control in ${pageContext}`\n : `focused control on the ${surface}`;\n default:\n return pageContext\n ? `control in ${pageContext}`\n : `control on the ${surface}`;\n }\n}\n\nfunction buildSemanticAction(\n event: MidsceneRecorderEvent,\n scrollDestinationDescription?: string,\n): MidsceneRecorderSemanticAction {\n return {\n type: event.type,\n actionType: event.actionType,\n value: event.value,\n url: event.url,\n scrollDestinationDescription,\n };\n}\n\nfunction getFallbackReplayInstruction(\n event: MidsceneRecorderEvent,\n elementDescription: string,\n) {\n return buildMidsceneRecorderReplayInstruction(\n buildSemanticAction(event),\n elementDescription,\n );\n}\n\nfunction getFallbackActionSummary(\n event: MidsceneRecorderEvent,\n elementDescription: string,\n) {\n return buildMidsceneRecorderActionSummary(\n buildSemanticAction(event),\n elementDescription,\n );\n}\n\nfunction getActionGuidance(\n event: MidsceneRecorderEvent,\n target?: MidsceneRecorderTarget,\n) {\n const platformGuidance = getPlatformGuidance(target);\n\n switch (event.type) {\n case 'click':\n return `${platformGuidance} Identify the ${getPointerActionVerb(event).toLowerCase()} target by exact visible text first, then label/placeholder, then role plus stable surrounding context, then icon purpose, then visual position. Never describe it by coordinates, marker location, or as a nearby element.`;\n case 'input':\n return `${platformGuidance} Identify the exact input field at the marker before text entry. Use stable visible label, field role, field name, surrounding section, or sequence intent. Treat hint text that can change by user, time, data, or context as secondary evidence. Preserve the recorded input value only in replayInstruction; never describe the typed value or page title alone as the field.`;\n case 'scroll':\n return `${platformGuidance} Identify the scrollable page/region at the highlighted scroll point and concrete destination content revealed after scrolling. If multiple scrollable regions are visible, preserve the specific region where the scroll happened, such as left/right/top/bottom panel, navigation area, content pane, dialog body, table, list, or menu; do not generalize a panel/list scroll into the whole page. Use newly visible headings, section titles, list/table names, list items, or stable region labels; never say only \"more content\" or \"current page\".`;\n case 'drag':\n return `${platformGuidance} Identify the ${getDragActionVerb(event).toLowerCase()} start/end regions or the dragged UI control. Do not describe only the gesture path or coordinates.`;\n case 'keydown':\n return `${platformGuidance} Identify the focused element or keyboard target if visible, and preserve the recorded key in the replay instruction.`;\n default:\n return `${platformGuidance} Identify the UI target involved in this event using the most stable visible text or surrounding context.`;\n }\n}\n\nfunction getEventRawCoordinates(event: MidsceneRecorderEvent) {\n const x = event.elementRect?.x;\n const y = event.elementRect?.y;\n if (isFiniteNumber(x) && isFiniteNumber(y)) {\n return { x, y };\n }\n return undefined;\n}\n\nfunction getPageSemanticContext(event: MidsceneRecorderEvent) {\n const candidates = [event.title, event.url]\n .map((item) => item?.trim())\n .filter(Boolean) as string[];\n return candidates[0];\n}\n\nfunction isWeakDescription(value?: string) {\n if (!value) {\n return true;\n }\n if (isPendingDescription(value)) {\n return true;\n }\n const normalized = value.trim().toLowerCase();\n const compact = normalized.replace(/\\s+/g, '');\n return (\n normalized.length === 0 ||\n /^\\(?\\d+(?:\\.\\d+)?,\\s*\\d+(?:\\.\\d+)?\\)?$/.test(normalized) ||\n normalized === 'target' ||\n normalized === 'element' ||\n normalized === 'target element' ||\n normalized === 'the element' ||\n normalized === 'page element' ||\n normalized === 'input field' ||\n normalized === 'text input' ||\n normalized === 'text field' ||\n normalized === 'search box' ||\n normalized === 'more content' ||\n normalized === 'the page' ||\n normalized === 'current page' ||\n normalized === 'current screen' ||\n normalized === 'the screen' ||\n normalized === 'current ui' ||\n normalized === 'current visible ui' ||\n normalized === 'current visible page' ||\n normalized === 'current visible screen' ||\n normalized === 'main area' ||\n normalized === 'main scrollable area' ||\n normalized === 'scrollable area' ||\n normalized === 'highlighted element' ||\n normalized === 'highlighted item' ||\n normalized === 'marked element' ||\n normalized === 'marked item' ||\n normalized.includes('ai is analyzing element') ||\n compact.includes('坐标') ||\n compact.includes('附近') ||\n compact.includes('附近的元素') ||\n normalized.includes('coordinate') ||\n normalized.includes('near the coordinate') ||\n normalized.includes('near coordinates') ||\n normalized.includes('nearby element') ||\n normalized.includes('nearby item') ||\n normalized.includes('near the marker') ||\n normalized.includes('near marker') ||\n normalized.includes('near the point') ||\n normalized.includes('near point') ||\n normalized.includes('at the point') ||\n normalized.includes('button near point') ||\n normalized.includes('shown in the screenshot') ||\n normalized.includes('red rectangle') ||\n normalized.includes('red marker') ||\n normalized.includes('red box') ||\n normalized.includes('highlighted element') ||\n normalized.includes('highlighted item') ||\n normalized.includes('highlighted screenshot')\n );\n}\n\nfunction isWeakReplayInstruction(value?: string) {\n if (!value) {\n return true;\n }\n if (isPendingDescription(value)) {\n return true;\n }\n const normalized = value.trim().toLowerCase();\n const compact = normalized.replace(/\\s+/g, '');\n return (\n compact.includes('坐标') ||\n compact.includes('附近') ||\n normalized.includes('coordinate') ||\n normalized.includes('near the coordinate') ||\n normalized.includes('nearby element') ||\n normalized.includes('nearby item') ||\n normalized.includes('near the marker') ||\n normalized.includes('near marker') ||\n normalized.includes('near the point') ||\n normalized.includes('near point') ||\n normalized.includes('at the point') ||\n normalized.includes('ai is analyzing element') ||\n normalized.includes('more content') ||\n normalized.includes('current page') ||\n normalized.includes('current screen') ||\n normalized.includes('highlighted element') ||\n normalized.includes('highlighted item') ||\n normalized.includes('red marker') ||\n normalized.includes('red box') ||\n normalized.includes('shown in the screenshot') ||\n normalized.includes('highlighted screenshot')\n );\n}\n\nfunction normalizeForComparison(value: string) {\n return value.trim().toLowerCase().replace(/[\"'`]/g, '').replace(/\\s+/g, ' ');\n}\n\nfunction isInputValueUsedAsFieldDescription(\n event: MidsceneRecorderEvent,\n elementDescription?: string,\n) {\n if (event.type !== 'input' || !event.value || !elementDescription) {\n return false;\n }\n\n const typedValue = normalizeForComparison(event.value);\n if (!typedValue) {\n return false;\n }\n const description = normalizeForComparison(elementDescription);\n\n return (\n description === typedValue ||\n description === `${typedValue} input` ||\n description === `${typedValue} field` ||\n description === `${typedValue} text field` ||\n description === `input ${typedValue}` ||\n description === `field ${typedValue}` ||\n description.includes(`typed value ${typedValue}`) ||\n description.includes(`value ${typedValue}`)\n );\n}\n\nfunction hasScrollDestination(\n replayInstruction: string,\n scrollDestinationDescription?: string,\n) {\n if (\n scrollDestinationDescription &&\n !isWeakDescription(scrollDestinationDescription)\n ) {\n return true;\n }\n const normalized = replayInstruction.toLowerCase();\n return (\n normalized.includes(' until ') ||\n normalized.includes(' visible') ||\n normalized.includes(' reveal') ||\n normalized.includes(' to the ') ||\n normalized.includes(' toward ')\n );\n}\n\nasync function describeWithRetry(\n event: MidsceneRecorderEvent,\n target: MidsceneRecorderTarget | undefined,\n highlightedScreenshot: string,\n modelConfig: IModelConfig,\n options: Required<\n Pick<DescribeRecorderUIEventOptions, 'maxRetries' | 'retryDelayMs'>\n >,\n) {\n let lastError: unknown;\n for (let attempt = 1; attempt <= options.maxRetries; attempt += 1) {\n try {\n const afterScreenshot = getRecorderEventAfterScreenshot(event);\n const pageContext = getPageSemanticContext(event);\n const platformGuidance = getPlatformGuidance(target);\n const userContent: any[] = [\n {\n type: 'text',\n text: `Recorder event:\n${JSON.stringify(\n {\n type: event.type,\n actionType: event.actionType,\n value: event.value,\n rawCoordinates: getEventRawCoordinates(event),\n url: event.url,\n title: event.title,\n pageContext,\n pageInfo: event.pageInfo,\n target,\n platformGuidance,\n guidance: getActionGuidance(event, target),\n },\n null,\n 2,\n)}\n\nThe target or region is highlighted in the screenshot below. Convert this event into semantic replay fields.`,\n },\n {\n type: 'image_url',\n image_url: {\n url: highlightedScreenshot,\n detail: 'high',\n },\n },\n ];\n if (afterScreenshot) {\n userContent.push(\n {\n type: 'text',\n text: 'Screenshot after the recorded action, for context only:',\n },\n {\n type: 'image_url',\n image_url: {\n url: afterScreenshot,\n detail: 'high',\n },\n },\n );\n }\n const response =\n await callAIWithObjectResponse<RecorderUIEventAIResponse>(\n [\n {\n role: 'system',\n content: RECORDER_UI_DESCRIBER_SYSTEM_PROMPT,\n },\n {\n role: 'user',\n content: userContent,\n },\n ],\n modelConfig,\n );\n\n const content = response.content;\n if (content.error) {\n throw new Error(content.error);\n }\n if (isWeakDescription(content.elementDescription)) {\n throw new Error('AI returned a weak recorder event description.');\n }\n if (\n isInputValueUsedAsFieldDescription(event, content.elementDescription)\n ) {\n throw new Error(\n 'AI used the recorded input value as the field description.',\n );\n }\n const elementDescription = content.elementDescription!.trim();\n const scrollDestinationDescription =\n event.type === 'scroll'\n ? content.scrollDestinationDescription?.trim()\n : undefined;\n if (\n event.type === 'scroll' &&\n !hasScrollDestination('', scrollDestinationDescription)\n ) {\n throw new Error(\n 'AI returned a scroll description without a destination.',\n );\n }\n const aiReplayInstruction = content.replayInstruction?.trim();\n if (aiReplayInstruction && isWeakReplayInstruction(aiReplayInstruction)) {\n throw new Error('AI returned a weak recorder replay instruction.');\n }\n const semanticAction = buildSemanticAction(\n event,\n scrollDestinationDescription,\n );\n const replayInstruction = buildMidsceneRecorderReplayInstruction(\n semanticAction,\n elementDescription,\n );\n if (isWeakReplayInstruction(replayInstruction)) {\n throw new Error('AI returned a weak recorder replay instruction.');\n }\n const actionSummary = buildMidsceneRecorderActionSummary(\n semanticAction,\n elementDescription,\n );\n\n return {\n source: 'recorderAI' as const,\n status: 'ready' as const,\n elementDescription,\n replayInstruction,\n actionSummary,\n confidence: content.confidence || 'medium',\n };\n } catch (error) {\n lastError = error;\n if (attempt < options.maxRetries) {\n await delay(options.retryDelayMs);\n }\n }\n }\n throw lastError;\n}\n\nasync function createScreenshotWithBox(\n event: MidsceneRecorderEvent,\n rect: Rect,\n) {\n if (event.screenshotWithBox) {\n return event.screenshotWithBox;\n }\n const screenshot = getRecorderEventScreenshot(event);\n if (!screenshot) {\n return undefined;\n }\n const { compositeElementInfoImg } = await import(\n /* @vite-ignore */ '@midscene/shared/img'\n );\n return compositeElementInfoImg({\n inputImgBase64: screenshot,\n size: event.pageInfo,\n elementsPositionInfo: [{ rect }],\n borderThickness: 3,\n annotationPadding: 2,\n });\n}\n\nfunction createFallbackEvent(\n event: MidsceneRecorderEvent,\n error: string,\n screenshotWithBox?: string,\n target?: MidsceneRecorderTarget,\n): MidsceneRecorderEvent {\n const semantic = getMidsceneRecorderSemantic(event);\n const elementDescription =\n semantic?.elementDescription &&\n !isWeakDescription(semantic.elementDescription)\n ? semantic.elementDescription\n : getFallbackDescription(event, target);\n return {\n ...event,\n semantic: {\n source: 'heuristic',\n status: 'ready',\n elementDescription,\n replayInstruction: getFallbackReplayInstruction(\n event,\n elementDescription,\n ),\n actionSummary: getFallbackActionSummary(event, elementDescription),\n confidence: 'low',\n error,\n },\n screenshotWithBox: screenshotWithBox || event.screenshotWithBox,\n };\n}\n\nexport async function describeRecorderUIEvent(\n input: DescribeRecorderUIEventInput,\n modelConfig: IModelConfig | Record<string, unknown>,\n options: DescribeRecorderUIEventOptions = {},\n): Promise<DescribeRecorderUIEventResult> {\n const event = input.event;\n const rect = getRecorderUIEventTargetRect(event);\n const screenshot = getRecorderEventScreenshot(event);\n\n if (!rect || !screenshot) {\n const error = !rect\n ? 'Recorder event has no target rectangle.'\n : 'Recorder event has no screenshot.';\n return {\n usedFallback: true,\n event: createFallbackEvent(event, error, undefined, input.target),\n };\n }\n\n let screenshotWithBox: string | undefined;\n try {\n const resolvedModelConfig = resolveRecorderModelConfig(modelConfig);\n screenshotWithBox = await createScreenshotWithBox(event, rect);\n const semanticFields = await describeWithRetry(\n event,\n input.target,\n screenshotWithBox || screenshot,\n resolvedModelConfig,\n {\n maxRetries: options.maxRetries ?? RECORDER_UI_DESCRIBER_DEFAULT_RETRIES,\n retryDelayMs:\n options.retryDelayMs ?? RECORDER_UI_DESCRIBER_DEFAULT_RETRY_DELAY_MS,\n },\n );\n return {\n usedFallback: false,\n event: {\n ...event,\n semantic: semanticFields,\n screenshotWithBox: screenshotWithBox || event.screenshotWithBox,\n },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return {\n usedFallback: true,\n error: message,\n event: createFallbackEvent(\n event,\n message,\n screenshotWithBox,\n input.target,\n ),\n };\n }\n}\n\nexport async function describeRecorderUIEvents(\n inputs: DescribeRecorderUIEventInput[],\n modelConfig: IModelConfig | Record<string, unknown>,\n options: DescribeRecorderUIEventOptions = {},\n): Promise<DescribeRecorderUIEventResult[]> {\n const concurrency = Math.max(\n 1,\n options.concurrency ?? RECORDER_UI_DESCRIBER_DEFAULT_CONCURRENCY,\n );\n const results: DescribeRecorderUIEventResult[] = new Array(inputs.length);\n let cursor = 0;\n\n async function worker() {\n while (cursor < inputs.length) {\n const index = cursor;\n cursor += 1;\n results[index] = await describeRecorderUIEvent(\n inputs[index],\n modelConfig,\n options,\n );\n }\n }\n\n await Promise.all(\n Array.from({ length: Math.min(concurrency, inputs.length) }, () =>\n worker(),\n ),\n );\n return results;\n}\n"],"names":["RECORDER_UI_DESCRIBER_DEFAULT_RETRIES","RECORDER_UI_DESCRIBER_DEFAULT_RETRY_DELAY_MS","RECORDER_UI_DESCRIBER_DEFAULT_CONCURRENCY","delay","ms","Promise","resolve","setTimeout","isResolvedModelConfig","modelConfig","resolveRecorderModelConfig","rawModelConfig","Object","result","key","value","ModelConfigManager","clamp","min","max","Math","isFiniteNumber","Number","isPendingDescription","getRecorderEventScreenshot","event","getRecorderEventAfterScreenshot","normalizeActionType","getPlatformId","target","getPlatformSurface","getPlatformGuidance","getPointerActionVerb","getDragActionVerb","pointToRect","x","y","size","pageInfo","width","height","left","top","getPointRectSize","getRecorderUIEventTargetRect","rect","getFallbackDescription","pageContext","getPageSemanticContext","surface","buildSemanticAction","scrollDestinationDescription","getFallbackReplayInstruction","elementDescription","buildMidsceneRecorderReplayInstruction","getFallbackActionSummary","buildMidsceneRecorderActionSummary","getActionGuidance","platformGuidance","getEventRawCoordinates","candidates","item","Boolean","isWeakDescription","normalized","compact","isWeakReplayInstruction","normalizeForComparison","isInputValueUsedAsFieldDescription","typedValue","description","hasScrollDestination","replayInstruction","describeWithRetry","highlightedScreenshot","options","lastError","attempt","afterScreenshot","userContent","JSON","response","callAIWithObjectResponse","RECORDER_UI_DESCRIBER_SYSTEM_PROMPT","content","Error","undefined","aiReplayInstruction","semanticAction","actionSummary","error","createScreenshotWithBox","screenshot","compositeElementInfoImg","createFallbackEvent","screenshotWithBox","semantic","getMidsceneRecorderSemantic","describeRecorderUIEvent","input","resolvedModelConfig","semanticFields","message","String","describeRecorderUIEvents","inputs","concurrency","results","Array","cursor","worker","index"],"mappings":";;;;AA0CA,MAAMA,wCAAwC;AAC9C,MAAMC,+CAA+C;AACrD,MAAMC,4CAA4C;AAElD,SAASC,MAAMC,EAAU;IACvB,OAAO,IAAIC,QAAQ,CAACC,UAAYC,WAAWD,SAASF;AACtD;AAEA,SAASI,sBACPC,WAAmD;IAEnD,OACE,AAAiC,YAAjC,OAAOA,YAAY,SAAS,IAC3B,CAAwC,YAAxC,OAAOA,YAAY,gBAAgB,IAClC,AAA8B,YAA9B,OAAOA,YAAY,MAAM,IACzB,AAA4B,YAA5B,OAAOA,YAAY,IAAI,IACvB,AAAoC,YAApC,OAAOA,YAAY,YAAY,AAAY;AAEjD;AAEA,SAASC,2BACPD,WAAmD;IAEnD,IAAID,sBAAsBC,cACxB,OAAOA;IAET,MAAME,iBAAiBC,OAAO,OAAO,CAACH,aAAa,MAAM,CAEvD,CAACI,QAAQ,CAACC,KAAKC,MAAM;QACrB,IAAI,AAAiB,YAAjB,OAAOA,SAAsB,AAAiB,YAAjB,OAAOA,OACtCF,MAAM,CAACC,IAAI,GAAGC;QAEhB,OAAOF;IACT,GAAG,CAAC;IACJ,OAAO,IAAIG,mBAAmBL,gBAAgB,cAAc,CAAC;AAC/D;AAEA,SAASM,MAAMF,KAAa,EAAEG,GAAW,EAAEC,GAAW;IACpD,OAAOC,KAAK,GAAG,CAACA,KAAK,GAAG,CAACL,OAAOG,MAAMC;AACxC;AAEA,SAASE,eAAeN,KAAc;IACpC,OAAO,AAAiB,YAAjB,OAAOA,SAAsBO,OAAO,QAAQ,CAACP;AACtD;AAEA,SAASQ,qBAAqBR,KAAc;IAC1C,OAAOA,OAAO,WAAW;AAC3B;AAEA,SAASS,2BAA2BC,KA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,eAAeC;QACb,MAAOD,SAASJ,OAAO,MAAM,CAAE;YAC7B,MAAMM,QAAQF;YACdA,UAAU;YACVF,OAAO,CAACI,MAAM,GAAG,MAAMb,wBACrBO,MAAM,CAACM,MAAM,EACbtG,aACAkE;QAEJ;IACF;IAEA,MAAMtE,QAAQ,GAAG,CACfuG,MAAM,IAAI,CAAC;QAAE,QAAQxF,KAAK,GAAG,CAACsF,aAAaD,OAAO,MAAM;IAAE,GAAG,IAC3DK;IAGJ,OAAOH;AACT"}
|
|
1
|
+
{"version":3,"file":"recorder-ui-describer.mjs","sources":["../../src/recorder-ui-describer.ts"],"sourcesContent":["import type { Rect } from '@midscene/core';\nimport type { IModelConfig } from '@midscene/shared/env';\nimport type {\n MidsceneRecorderEvent,\n MidsceneRecorderPageInfo,\n MidsceneRecorderSemanticAction,\n MidsceneRecorderTarget,\n} from '@midscene/shared/recorder';\nimport {\n buildMidsceneRecorderActionSummary,\n buildMidsceneRecorderReplayInstruction,\n getMidsceneRecorderSemantic,\n} from '@midscene/shared/recorder';\nimport { callAIWithObjectResponse } from './recorder-ai-service';\nimport { RECORDER_UI_DESCRIBER_SYSTEM_PROMPT } from './recorder-ui-describer-prompt';\n\nexport interface DescribeRecorderUIEventInput {\n event: MidsceneRecorderEvent;\n target?: MidsceneRecorderTarget;\n}\n\nexport interface DescribeRecorderUIEventOptions {\n maxRetries?: number;\n retryDelayMs?: number;\n concurrency?: number;\n}\n\nexport interface DescribeRecorderUIEventResult {\n event: MidsceneRecorderEvent;\n usedFallback: boolean;\n error?: string;\n}\n\ninterface RecorderUIEventAIResponse {\n elementDescription?: string;\n replayInstruction?: string;\n actionSummary?: string;\n scrollDestinationDescription?: string;\n confidence?: 'high' | 'medium' | 'low';\n error?: string;\n}\n\nconst RECORDER_UI_DESCRIBER_DEFAULT_RETRIES = 2;\nconst RECORDER_UI_DESCRIBER_DEFAULT_RETRY_DELAY_MS = 200;\nconst RECORDER_UI_DESCRIBER_DEFAULT_CONCURRENCY = 2;\n\nfunction delay(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nfunction clamp(value: number, min: number, max: number) {\n return Math.min(Math.max(value, min), max);\n}\n\nfunction isFiniteNumber(value: unknown): value is number {\n return typeof value === 'number' && Number.isFinite(value);\n}\n\nfunction isPendingDescription(value?: string) {\n return value?.trim() === 'AI is analyzing element...';\n}\n\nfunction getRecorderEventScreenshot(event: MidsceneRecorderEvent) {\n return (\n event.screenshotWithBox || event.screenshotBefore || event.screenshotAfter\n );\n}\n\nfunction getRecorderEventAfterScreenshot(event: MidsceneRecorderEvent) {\n return event.screenshotAfter || event.screenshotWithBox;\n}\n\nfunction normalizeActionType(event: MidsceneRecorderEvent) {\n return event.actionType?.trim();\n}\n\nfunction getPlatformId(target?: MidsceneRecorderTarget) {\n return target?.platformId?.toLowerCase();\n}\n\nfunction getPlatformSurface(target?: MidsceneRecorderTarget) {\n switch (getPlatformId(target)) {\n case 'web':\n return 'current web page';\n case 'android':\n case 'ios':\n case 'harmony':\n return 'current mobile screen';\n case 'computer':\n return 'current desktop screen';\n default:\n return 'current UI';\n }\n}\n\nfunction getPlatformGuidance(target?: MidsceneRecorderTarget) {\n switch (getPlatformId(target)) {\n case 'web':\n return 'For web targets, use web UI terms such as button, input, link, menu item, tab, dialog, aria-label, placeholder, and form section when visible or inferable.';\n case 'android':\n case 'ios':\n case 'harmony':\n return 'For mobile targets, use mobile UI terms such as tab, list item, text field, icon button, navigation bar, bottom bar, sheet, card, and screen section.';\n case 'computer':\n return 'For desktop/computer targets, use desktop UI terms such as menu item, toolbar button, dialog field, sidebar item, window control, file row, and application region.';\n default:\n return 'Use platform-neutral UI terms such as control, field, item, icon button, list item, region, panel, and page section.';\n }\n}\n\nfunction getPointerActionVerb(event: MidsceneRecorderEvent) {\n switch (normalizeActionType(event)) {\n case 'Tap':\n return 'Tap';\n case 'DoubleClick':\n return 'Double click';\n case 'LongPress':\n return 'Long press';\n case 'RightClick':\n return 'Right click';\n default:\n return 'Click';\n }\n}\n\nfunction getDragActionVerb(event: MidsceneRecorderEvent) {\n switch (normalizeActionType(event)) {\n case 'Swipe':\n return 'Swipe';\n case 'DragAndDrop':\n return 'Drag';\n default:\n return 'Drag';\n }\n}\n\nfunction pointToRect(\n x: number,\n y: number,\n size: number,\n pageInfo: MidsceneRecorderPageInfo,\n): Rect {\n const width = pageInfo.width || size;\n const height = pageInfo.height || size;\n const left = clamp(Math.floor(x - size / 2), 0, Math.max(width - 1, 0));\n const top = clamp(Math.floor(y - size / 2), 0, Math.max(height - 1, 0));\n return {\n left,\n top,\n width: Math.min(size, Math.max(width - left, 1)),\n height: Math.min(size, Math.max(height - top, 1)),\n };\n}\n\nfunction getPointRectSize(event: MidsceneRecorderEvent) {\n switch (event.type) {\n case 'scroll':\n return 96;\n case 'drag':\n return 64;\n default:\n return 36;\n }\n}\n\nexport function getRecorderUIEventTargetRect(\n event: MidsceneRecorderEvent,\n): Rect | null {\n const rect = event.elementRect;\n if (!rect) {\n return null;\n }\n\n if (\n isFiniteNumber(rect.width) &&\n rect.width > 0 &&\n isFiniteNumber(rect.height) &&\n rect.height > 0 &&\n (isFiniteNumber(rect.left) || isFiniteNumber(rect.top))\n ) {\n return {\n left: rect.left || 0,\n top: rect.top || 0,\n width: rect.width,\n height: rect.height,\n };\n }\n\n if (isFiniteNumber(rect.x) && isFiniteNumber(rect.y)) {\n return pointToRect(rect.x, rect.y, getPointRectSize(event), event.pageInfo);\n }\n\n return null;\n}\n\nfunction getFallbackDescription(\n event: MidsceneRecorderEvent,\n target?: MidsceneRecorderTarget,\n) {\n const pageContext = getPageSemanticContext(event);\n const surface = getPlatformSurface(target);\n\n switch (event.type) {\n case 'navigation':\n return event.url || event.value || event.actionType || 'navigation';\n case 'scroll':\n return pageContext\n ? `${pageContext} scrollable content`\n : `scrollable content on the ${surface}`;\n case 'drag':\n return pageContext\n ? `gesture area in ${pageContext}`\n : `gesture area on the ${surface}`;\n case 'input':\n return `unresolved input field on the ${surface}`;\n case 'keydown':\n return pageContext\n ? `focused control in ${pageContext}`\n : `focused control on the ${surface}`;\n default:\n return pageContext\n ? `control in ${pageContext}`\n : `control on the ${surface}`;\n }\n}\n\nfunction buildSemanticAction(\n event: MidsceneRecorderEvent,\n scrollDestinationDescription?: string,\n): MidsceneRecorderSemanticAction {\n return {\n type: event.type,\n actionType: event.actionType,\n value: event.value,\n url: event.url,\n scrollDestinationDescription,\n };\n}\n\nfunction getFallbackReplayInstruction(\n event: MidsceneRecorderEvent,\n elementDescription: string,\n) {\n return buildMidsceneRecorderReplayInstruction(\n buildSemanticAction(event),\n elementDescription,\n );\n}\n\nfunction getFallbackActionSummary(\n event: MidsceneRecorderEvent,\n elementDescription: string,\n) {\n return buildMidsceneRecorderActionSummary(\n buildSemanticAction(event),\n elementDescription,\n );\n}\n\nfunction getActionGuidance(\n event: MidsceneRecorderEvent,\n target?: MidsceneRecorderTarget,\n) {\n const platformGuidance = getPlatformGuidance(target);\n\n switch (event.type) {\n case 'click':\n return `${platformGuidance} Identify the ${getPointerActionVerb(event).toLowerCase()} target by exact visible text first, then label/placeholder, then role plus stable surrounding context, then icon purpose, then visual position. Never describe it by coordinates, marker location, or as a nearby element.`;\n case 'input':\n return `${platformGuidance} Identify the exact input field at the marker before text entry. Use stable visible label, field role, field name, surrounding section, or sequence intent. Treat hint text that can change by user, time, data, or context as secondary evidence. Preserve the recorded input value only in replayInstruction; never describe the typed value or page title alone as the field.`;\n case 'scroll':\n return `${platformGuidance} Identify the scrollable page/region at the highlighted scroll point and concrete destination content revealed after scrolling. If multiple scrollable regions are visible, preserve the specific region where the scroll happened, such as left/right/top/bottom panel, navigation area, content pane, dialog body, table, list, or menu; do not generalize a panel/list scroll into the whole page. Use newly visible headings, section titles, list/table names, list items, or stable region labels; never say only \"more content\" or \"current page\".`;\n case 'drag':\n return `${platformGuidance} Identify the ${getDragActionVerb(event).toLowerCase()} start/end regions or the dragged UI control. Do not describe only the gesture path or coordinates.`;\n case 'keydown':\n return `${platformGuidance} Identify the focused element or keyboard target if visible, and preserve the recorded key in the replay instruction.`;\n default:\n return `${platformGuidance} Identify the UI target involved in this event using the most stable visible text or surrounding context.`;\n }\n}\n\nfunction getEventRawCoordinates(event: MidsceneRecorderEvent) {\n const x = event.elementRect?.x;\n const y = event.elementRect?.y;\n if (isFiniteNumber(x) && isFiniteNumber(y)) {\n return { x, y };\n }\n return undefined;\n}\n\nfunction getPageSemanticContext(event: MidsceneRecorderEvent) {\n const candidates = [event.title, event.url]\n .map((item) => item?.trim())\n .filter(Boolean) as string[];\n return candidates[0];\n}\n\nfunction isWeakDescription(value?: string) {\n if (!value) {\n return true;\n }\n if (isPendingDescription(value)) {\n return true;\n }\n const normalized = value.trim().toLowerCase();\n const compact = normalized.replace(/\\s+/g, '');\n return (\n normalized.length === 0 ||\n /^\\(?\\d+(?:\\.\\d+)?,\\s*\\d+(?:\\.\\d+)?\\)?$/.test(normalized) ||\n normalized === 'target' ||\n normalized === 'element' ||\n normalized === 'target element' ||\n normalized === 'the element' ||\n normalized === 'page element' ||\n normalized === 'input field' ||\n normalized === 'text input' ||\n normalized === 'text field' ||\n normalized === 'search box' ||\n normalized === 'more content' ||\n normalized === 'the page' ||\n normalized === 'current page' ||\n normalized === 'current screen' ||\n normalized === 'the screen' ||\n normalized === 'current ui' ||\n normalized === 'current visible ui' ||\n normalized === 'current visible page' ||\n normalized === 'current visible screen' ||\n normalized === 'main area' ||\n normalized === 'main scrollable area' ||\n normalized === 'scrollable area' ||\n normalized === 'highlighted element' ||\n normalized === 'highlighted item' ||\n normalized === 'marked element' ||\n normalized === 'marked item' ||\n normalized.includes('ai is analyzing element') ||\n compact.includes('坐标') ||\n compact.includes('附近') ||\n compact.includes('附近的元素') ||\n normalized.includes('coordinate') ||\n normalized.includes('near the coordinate') ||\n normalized.includes('near coordinates') ||\n normalized.includes('nearby element') ||\n normalized.includes('nearby item') ||\n normalized.includes('near the marker') ||\n normalized.includes('near marker') ||\n normalized.includes('near the point') ||\n normalized.includes('near point') ||\n normalized.includes('at the point') ||\n normalized.includes('button near point') ||\n normalized.includes('shown in the screenshot') ||\n normalized.includes('red rectangle') ||\n normalized.includes('red marker') ||\n normalized.includes('red box') ||\n normalized.includes('highlighted element') ||\n normalized.includes('highlighted item') ||\n normalized.includes('highlighted screenshot')\n );\n}\n\nfunction isWeakReplayInstruction(value?: string) {\n if (!value) {\n return true;\n }\n if (isPendingDescription(value)) {\n return true;\n }\n const normalized = value.trim().toLowerCase();\n const compact = normalized.replace(/\\s+/g, '');\n return (\n compact.includes('坐标') ||\n compact.includes('附近') ||\n normalized.includes('coordinate') ||\n normalized.includes('near the coordinate') ||\n normalized.includes('nearby element') ||\n normalized.includes('nearby item') ||\n normalized.includes('near the marker') ||\n normalized.includes('near marker') ||\n normalized.includes('near the point') ||\n normalized.includes('near point') ||\n normalized.includes('at the point') ||\n normalized.includes('ai is analyzing element') ||\n normalized.includes('more content') ||\n normalized.includes('current page') ||\n normalized.includes('current screen') ||\n normalized.includes('highlighted element') ||\n normalized.includes('highlighted item') ||\n normalized.includes('red marker') ||\n normalized.includes('red box') ||\n normalized.includes('shown in the screenshot') ||\n normalized.includes('highlighted screenshot')\n );\n}\n\nfunction normalizeForComparison(value: string) {\n return value.trim().toLowerCase().replace(/[\"'`]/g, '').replace(/\\s+/g, ' ');\n}\n\nfunction isInputValueUsedAsFieldDescription(\n event: MidsceneRecorderEvent,\n elementDescription?: string,\n) {\n if (event.type !== 'input' || !event.value || !elementDescription) {\n return false;\n }\n\n const typedValue = normalizeForComparison(event.value);\n if (!typedValue) {\n return false;\n }\n const description = normalizeForComparison(elementDescription);\n\n return (\n description === typedValue ||\n description === `${typedValue} input` ||\n description === `${typedValue} field` ||\n description === `${typedValue} text field` ||\n description === `input ${typedValue}` ||\n description === `field ${typedValue}` ||\n description.includes(`typed value ${typedValue}`) ||\n description.includes(`value ${typedValue}`)\n );\n}\n\nfunction hasScrollDestination(\n replayInstruction: string,\n scrollDestinationDescription?: string,\n) {\n if (\n scrollDestinationDescription &&\n !isWeakDescription(scrollDestinationDescription)\n ) {\n return true;\n }\n const normalized = replayInstruction.toLowerCase();\n return (\n normalized.includes(' until ') ||\n normalized.includes(' visible') ||\n normalized.includes(' reveal') ||\n normalized.includes(' to the ') ||\n normalized.includes(' toward ')\n );\n}\n\nasync function describeWithRetry(\n event: MidsceneRecorderEvent,\n target: MidsceneRecorderTarget | undefined,\n highlightedScreenshot: string,\n modelConfig: IModelConfig,\n options: Required<\n Pick<DescribeRecorderUIEventOptions, 'maxRetries' | 'retryDelayMs'>\n >,\n) {\n let lastError: unknown;\n for (let attempt = 1; attempt <= options.maxRetries; attempt += 1) {\n try {\n const afterScreenshot = getRecorderEventAfterScreenshot(event);\n const pageContext = getPageSemanticContext(event);\n const platformGuidance = getPlatformGuidance(target);\n const userContent: any[] = [\n {\n type: 'text',\n text: `Recorder event:\n${JSON.stringify(\n {\n type: event.type,\n actionType: event.actionType,\n value: event.value,\n rawCoordinates: getEventRawCoordinates(event),\n url: event.url,\n title: event.title,\n pageContext,\n pageInfo: event.pageInfo,\n target,\n platformGuidance,\n guidance: getActionGuidance(event, target),\n },\n null,\n 2,\n)}\n\nThe target or region is highlighted in the screenshot below. Convert this event into semantic replay fields.`,\n },\n {\n type: 'image_url',\n image_url: {\n url: highlightedScreenshot,\n detail: 'high',\n },\n },\n ];\n if (afterScreenshot) {\n userContent.push(\n {\n type: 'text',\n text: 'Screenshot after the recorded action, for context only:',\n },\n {\n type: 'image_url',\n image_url: {\n url: afterScreenshot,\n detail: 'high',\n },\n },\n );\n }\n const response =\n await callAIWithObjectResponse<RecorderUIEventAIResponse>(\n [\n {\n role: 'system',\n content: RECORDER_UI_DESCRIBER_SYSTEM_PROMPT,\n },\n {\n role: 'user',\n content: userContent,\n },\n ],\n modelConfig,\n );\n\n const content = response.content;\n if (content.error) {\n throw new Error(content.error);\n }\n if (isWeakDescription(content.elementDescription)) {\n throw new Error('AI returned a weak recorder event description.');\n }\n if (\n isInputValueUsedAsFieldDescription(event, content.elementDescription)\n ) {\n throw new Error(\n 'AI used the recorded input value as the field description.',\n );\n }\n const elementDescription = content.elementDescription!.trim();\n const scrollDestinationDescription =\n event.type === 'scroll'\n ? content.scrollDestinationDescription?.trim()\n : undefined;\n if (\n event.type === 'scroll' &&\n !hasScrollDestination('', scrollDestinationDescription)\n ) {\n throw new Error(\n 'AI returned a scroll description without a destination.',\n );\n }\n const aiReplayInstruction = content.replayInstruction?.trim();\n if (aiReplayInstruction && isWeakReplayInstruction(aiReplayInstruction)) {\n throw new Error('AI returned a weak recorder replay instruction.');\n }\n const semanticAction = buildSemanticAction(\n event,\n scrollDestinationDescription,\n );\n const replayInstruction = buildMidsceneRecorderReplayInstruction(\n semanticAction,\n elementDescription,\n );\n if (isWeakReplayInstruction(replayInstruction)) {\n throw new Error('AI returned a weak recorder replay instruction.');\n }\n const actionSummary = buildMidsceneRecorderActionSummary(\n semanticAction,\n elementDescription,\n );\n\n return {\n source: 'recorderAI' as const,\n status: 'ready' as const,\n elementDescription,\n replayInstruction,\n actionSummary,\n confidence: content.confidence || 'medium',\n };\n } catch (error) {\n lastError = error;\n if (attempt < options.maxRetries) {\n await delay(options.retryDelayMs);\n }\n }\n }\n throw lastError;\n}\n\nasync function createScreenshotWithBox(\n event: MidsceneRecorderEvent,\n rect: Rect,\n) {\n if (event.screenshotWithBox) {\n return event.screenshotWithBox;\n }\n const screenshot = getRecorderEventScreenshot(event);\n if (!screenshot) {\n return undefined;\n }\n const { compositeElementInfoImg } = await import('@midscene/shared/img');\n return compositeElementInfoImg({\n inputImgBase64: screenshot,\n size: event.pageInfo,\n elementsPositionInfo: [{ rect }],\n borderThickness: 3,\n annotationPadding: 2,\n });\n}\n\nfunction createFallbackEvent(\n event: MidsceneRecorderEvent,\n error: string,\n screenshotWithBox?: string,\n target?: MidsceneRecorderTarget,\n): MidsceneRecorderEvent {\n const semantic = getMidsceneRecorderSemantic(event);\n const elementDescription =\n semantic?.elementDescription &&\n !isWeakDescription(semantic.elementDescription)\n ? semantic.elementDescription\n : getFallbackDescription(event, target);\n return {\n ...event,\n semantic: {\n source: 'heuristic',\n status: 'ready',\n elementDescription,\n replayInstruction: getFallbackReplayInstruction(\n event,\n elementDescription,\n ),\n actionSummary: getFallbackActionSummary(event, elementDescription),\n confidence: 'low',\n error,\n },\n screenshotWithBox: screenshotWithBox || event.screenshotWithBox,\n };\n}\n\nexport async function describeRecorderUIEvent(\n input: DescribeRecorderUIEventInput,\n modelConfig: IModelConfig,\n options: DescribeRecorderUIEventOptions = {},\n): Promise<DescribeRecorderUIEventResult> {\n const event = input.event;\n const rect = getRecorderUIEventTargetRect(event);\n const screenshot = getRecorderEventScreenshot(event);\n\n if (!rect || !screenshot) {\n const error = !rect\n ? 'Recorder event has no target rectangle.'\n : 'Recorder event has no screenshot.';\n return {\n usedFallback: true,\n event: createFallbackEvent(event, error, undefined, input.target),\n };\n }\n\n let screenshotWithBox: string | undefined;\n try {\n screenshotWithBox = await createScreenshotWithBox(event, rect);\n const semanticFields = await describeWithRetry(\n event,\n input.target,\n screenshotWithBox || screenshot,\n modelConfig,\n {\n maxRetries: options.maxRetries ?? RECORDER_UI_DESCRIBER_DEFAULT_RETRIES,\n retryDelayMs:\n options.retryDelayMs ?? RECORDER_UI_DESCRIBER_DEFAULT_RETRY_DELAY_MS,\n },\n );\n return {\n usedFallback: false,\n event: {\n ...event,\n semantic: semanticFields,\n screenshotWithBox: screenshotWithBox || event.screenshotWithBox,\n },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return {\n usedFallback: true,\n error: message,\n event: createFallbackEvent(\n event,\n message,\n screenshotWithBox,\n input.target,\n ),\n };\n }\n}\n\nexport async function describeRecorderUIEvents(\n inputs: DescribeRecorderUIEventInput[],\n modelConfig: IModelConfig,\n options: DescribeRecorderUIEventOptions = {},\n): Promise<DescribeRecorderUIEventResult[]> {\n const concurrency = Math.max(\n 1,\n options.concurrency ?? RECORDER_UI_DESCRIBER_DEFAULT_CONCURRENCY,\n );\n const results: DescribeRecorderUIEventResult[] = new Array(inputs.length);\n let cursor = 0;\n\n async function worker() {\n while (cursor < inputs.length) {\n const index = cursor;\n cursor += 1;\n results[index] = await describeRecorderUIEvent(\n inputs[index],\n modelConfig,\n options,\n );\n }\n }\n\n await Promise.all(\n Array.from({ length: Math.min(concurrency, inputs.length) }, () =>\n worker(),\n ),\n );\n return results;\n}\n"],"names":["RECORDER_UI_DESCRIBER_DEFAULT_RETRIES","RECORDER_UI_DESCRIBER_DEFAULT_RETRY_DELAY_MS","RECORDER_UI_DESCRIBER_DEFAULT_CONCURRENCY","delay","ms","Promise","resolve","setTimeout","clamp","value","min","max","Math","isFiniteNumber","Number","isPendingDescription","getRecorderEventScreenshot","event","getRecorderEventAfterScreenshot","normalizeActionType","getPlatformId","target","getPlatformSurface","getPlatformGuidance","getPointerActionVerb","getDragActionVerb","pointToRect","x","y","size","pageInfo","width","height","left","top","getPointRectSize","getRecorderUIEventTargetRect","rect","getFallbackDescription","pageContext","getPageSemanticContext","surface","buildSemanticAction","scrollDestinationDescription","getFallbackReplayInstruction","elementDescription","buildMidsceneRecorderReplayInstruction","getFallbackActionSummary","buildMidsceneRecorderActionSummary","getActionGuidance","platformGuidance","getEventRawCoordinates","candidates","item","Boolean","isWeakDescription","normalized","compact","isWeakReplayInstruction","normalizeForComparison","isInputValueUsedAsFieldDescription","typedValue","description","hasScrollDestination","replayInstruction","describeWithRetry","highlightedScreenshot","modelConfig","options","lastError","attempt","afterScreenshot","userContent","JSON","response","callAIWithObjectResponse","RECORDER_UI_DESCRIBER_SYSTEM_PROMPT","content","Error","undefined","aiReplayInstruction","semanticAction","actionSummary","error","createScreenshotWithBox","screenshot","compositeElementInfoImg","createFallbackEvent","screenshotWithBox","semantic","getMidsceneRecorderSemantic","describeRecorderUIEvent","input","semanticFields","message","String","describeRecorderUIEvents","inputs","concurrency","results","Array","cursor","worker","index"],"mappings":";;;AA0CA,MAAMA,wCAAwC;AAC9C,MAAMC,+CAA+C;A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K,MAAM,OAAO,GAAGY,OAAOZ;QAChE,OAAO;YACL,cAAc;YACd,OAAOW;YACP,OAAOP,oBACLtE,OACA6E,SACAN,mBACAI,MAAM,MAAM;QAEhB;IACF;AACF;AAEO,eAAeI,yBACpBC,MAAsC,EACtC9B,WAAyB,EACzBC,UAA0C,CAAC,CAAC;IAE5C,MAAM8B,cAActF,KAAK,GAAG,CAC1B,GACAwD,QAAQ,WAAW,IAAIlE;IAEzB,MAAMiG,UAA2C,IAAIC,MAAMH,OAAO,MAAM;IACxE,IAAII,SAAS;IAEb,eAAeC;QACb,MAAOD,SAASJ,OAAO,MAAM,CAAE;YAC7B,MAAMM,QAAQF;YACdA,UAAU;YACVF,OAAO,CAACI,MAAM,GAAG,MAAMZ,wBACrBM,MAAM,CAACM,MAAM,EACbpC,aACAC;QAEJ;IACF;IAEA,MAAM/D,QAAQ,GAAG,CACf+F,MAAM,IAAI,CAAC;QAAE,QAAQxF,KAAK,GAAG,CAACsF,aAAaD,OAAO,MAAM;IAAE,GAAG,IAC3DK;IAGJ,OAAOH;AACT"}
|
package/dist/es/server.mjs
CHANGED
|
@@ -1058,8 +1058,38 @@ class PlaygroundServer {
|
|
|
1058
1058
|
deepLocate = describeResult.deepLocate;
|
|
1059
1059
|
verifyResult = verifyPrompt ? describeResult.verifyResult : void 0;
|
|
1060
1060
|
if (!elementDescription) throw new Error("aiDescribe returned an empty element description.");
|
|
1061
|
-
if (false === describeResult.success) throw new Error(describeResult.error || `aiDescribe ${describeResult.failureStage || 'unknown'} failed.`);
|
|
1062
1061
|
const semanticAction = buildRecorderSemanticAction(event.actionType || event.type, event.rawPayload || {}, event.url);
|
|
1062
|
+
if (false === describeResult.success && verifyResult?.pass === false) {
|
|
1063
|
+
const trace = await finishTrace('ready', {
|
|
1064
|
+
modelCallDurationMs,
|
|
1065
|
+
elementDescription,
|
|
1066
|
+
verifyPassed: false,
|
|
1067
|
+
centerDistance: verifyResult.centerDistance,
|
|
1068
|
+
verifyResult
|
|
1069
|
+
});
|
|
1070
|
+
debugInteract('recorder aiDescribe trace:', trace);
|
|
1071
|
+
return {
|
|
1072
|
+
event: {
|
|
1073
|
+
...event,
|
|
1074
|
+
semantic: buildReadyRecorderSemantic('aiDescribe', semanticAction, elementDescription, 'low', {
|
|
1075
|
+
aiDescribe: {
|
|
1076
|
+
verifyPrompt,
|
|
1077
|
+
verifyPassed: false,
|
|
1078
|
+
deepLocate,
|
|
1079
|
+
centerDistance: verifyResult.centerDistance,
|
|
1080
|
+
expectedCenter: [
|
|
1081
|
+
x,
|
|
1082
|
+
y
|
|
1083
|
+
],
|
|
1084
|
+
actualCenter: verifyResult.center,
|
|
1085
|
+
annotatedScreenshotPath: trace.annotatedScreenshotRef?.path
|
|
1086
|
+
}
|
|
1087
|
+
})
|
|
1088
|
+
},
|
|
1089
|
+
trace
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
if (false === describeResult.success) throw new Error(describeResult.error || `aiDescribe ${describeResult.failureStage || 'unknown'} failed.`);
|
|
1063
1093
|
const trace = await finishTrace('ready', {
|
|
1064
1094
|
modelCallDurationMs,
|
|
1065
1095
|
elementDescription,
|