@midscene/core 1.9.6 → 1.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/agent/agent.mjs +40 -8
- package/dist/es/agent/agent.mjs.map +1 -1
- package/dist/es/agent/tasks.mjs +3 -3
- package/dist/es/agent/tasks.mjs.map +1 -1
- package/dist/es/agent/utils.mjs +18 -3
- package/dist/es/agent/utils.mjs.map +1 -1
- package/dist/es/ai-model/prompt/describe.mjs +10 -2
- package/dist/es/ai-model/prompt/describe.mjs.map +1 -1
- package/dist/es/ai-model/prompt/markdown-generator.mjs +150 -40
- package/dist/es/ai-model/prompt/markdown-generator.mjs.map +1 -1
- package/dist/es/ai-model/prompt/recorder-generation-common.mjs +74 -14
- package/dist/es/ai-model/prompt/recorder-generation-common.mjs.map +1 -1
- package/dist/es/ai-model/prompt/recorder-metadata-generator.mjs +3 -5
- package/dist/es/ai-model/prompt/recorder-metadata-generator.mjs.map +1 -1
- package/dist/es/ai-model/prompt/recorder-ui-describer.mjs +10 -6
- package/dist/es/ai-model/prompt/recorder-ui-describer.mjs.map +1 -1
- package/dist/es/ai-model/prompt/yaml-generator.mjs +2 -2
- package/dist/es/ai-model/prompt/yaml-generator.mjs.map +1 -1
- package/dist/es/ai-model/service-caller/index.mjs +33 -3
- package/dist/es/ai-model/service-caller/index.mjs.map +1 -1
- package/dist/es/device/index.mjs.map +1 -1
- package/dist/es/recorder-ui-describer.mjs +33 -84
- package/dist/es/recorder-ui-describer.mjs.map +1 -1
- package/dist/es/service/index.mjs +11 -3
- package/dist/es/service/index.mjs.map +1 -1
- package/dist/es/service/utils.mjs +50 -1
- package/dist/es/service/utils.mjs.map +1 -1
- package/dist/es/types.mjs.map +1 -1
- package/dist/es/utils.mjs +2 -2
- package/dist/lib/agent/agent.js +39 -7
- package/dist/lib/agent/agent.js.map +1 -1
- package/dist/lib/agent/tasks.js +3 -3
- package/dist/lib/agent/tasks.js.map +1 -1
- package/dist/lib/agent/utils.js +20 -2
- package/dist/lib/agent/utils.js.map +1 -1
- package/dist/lib/ai-model/prompt/describe.js +10 -2
- package/dist/lib/ai-model/prompt/describe.js.map +1 -1
- package/dist/lib/ai-model/prompt/markdown-generator.js +150 -40
- package/dist/lib/ai-model/prompt/markdown-generator.js.map +1 -1
- package/dist/lib/ai-model/prompt/recorder-generation-common.js +75 -12
- package/dist/lib/ai-model/prompt/recorder-generation-common.js.map +1 -1
- package/dist/lib/ai-model/prompt/recorder-metadata-generator.js +2 -4
- package/dist/lib/ai-model/prompt/recorder-metadata-generator.js.map +1 -1
- package/dist/lib/ai-model/prompt/recorder-ui-describer.js +10 -6
- package/dist/lib/ai-model/prompt/recorder-ui-describer.js.map +1 -1
- package/dist/lib/ai-model/prompt/yaml-generator.js +2 -2
- package/dist/lib/ai-model/prompt/yaml-generator.js.map +1 -1
- package/dist/lib/ai-model/service-caller/index.js +33 -3
- package/dist/lib/ai-model/service-caller/index.js.map +1 -1
- package/dist/lib/device/index.js.map +1 -1
- package/dist/lib/recorder-ui-describer.js +33 -84
- package/dist/lib/recorder-ui-describer.js.map +1 -1
- package/dist/lib/service/index.js +10 -2
- package/dist/lib/service/index.js.map +1 -1
- package/dist/lib/service/utils.js +53 -1
- package/dist/lib/service/utils.js.map +1 -1
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/utils.js +2 -2
- package/dist/types/agent/agent.d.ts +17 -6
- package/dist/types/agent/index.d.ts +1 -1
- package/dist/types/agent/tasks.d.ts +4 -2
- package/dist/types/agent/utils.d.ts +4 -1
- package/dist/types/ai-model/prompt/recorder-generation-common.d.ts +11 -7
- package/dist/types/ai-model/prompt/recorder-ui-describer.d.ts +1 -1
- package/dist/types/device/index.d.ts +6 -0
- package/dist/types/service/index.d.ts +1 -0
- package/dist/types/service/utils.d.ts +2 -0
- package/dist/types/types.d.ts +1 -0
- package/package.json +2 -2
|
@@ -28,10 +28,91 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
generateRecorderMarkdownReplay: ()=>generateRecorderMarkdownReplay,
|
|
29
29
|
convertRecordLogIntoMarkdown: ()=>convertRecordLogIntoMarkdown
|
|
30
30
|
});
|
|
31
|
+
const img_namespaceObject = require("@midscene/shared/img");
|
|
32
|
+
const logger_namespaceObject = require("@midscene/shared/logger");
|
|
31
33
|
const recorder_namespaceObject = require("@midscene/shared/recorder");
|
|
32
34
|
const external_index_js_namespaceObject = require("../index.js");
|
|
33
35
|
const index_js_namespaceObject = require("../models/index.js");
|
|
34
36
|
const external_recorder_generation_common_js_namespaceObject = require("./recorder-generation-common.js");
|
|
37
|
+
const MARKDOWN_REPLAY_SCREENSHOT_PAYLOAD_BUDGET = 600000;
|
|
38
|
+
const MARKDOWN_REPLAY_SCREENSHOT_MAX_EDGE = 768;
|
|
39
|
+
const debugMarkdownReplay = (0, logger_namespaceObject.getDebug)('ai:recorder-markdown', {
|
|
40
|
+
console: true
|
|
41
|
+
});
|
|
42
|
+
function limitScreenshotAssetsForMarkdownReplay(screenshotAssets) {
|
|
43
|
+
let usedPayload = 0;
|
|
44
|
+
return screenshotAssets.filter((asset)=>{
|
|
45
|
+
const payloadSize = asset.dataUrl.length;
|
|
46
|
+
if (payloadSize > MARKDOWN_REPLAY_SCREENSHOT_PAYLOAD_BUDGET || usedPayload + payloadSize > MARKDOWN_REPLAY_SCREENSHOT_PAYLOAD_BUDGET) return false;
|
|
47
|
+
usedPayload += payloadSize;
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async function compressScreenshotAssetForMarkdownReplay(asset) {
|
|
52
|
+
const { width, height } = await (0, img_namespaceObject.imageInfoOfBase64)(asset.dataUrl);
|
|
53
|
+
const longestEdge = Math.max(width, height);
|
|
54
|
+
if (longestEdge <= MARKDOWN_REPLAY_SCREENSHOT_MAX_EDGE) return asset;
|
|
55
|
+
const scale = MARKDOWN_REPLAY_SCREENSHOT_MAX_EDGE / longestEdge;
|
|
56
|
+
const dataUrl = await (0, img_namespaceObject.resizeImgBase64)(asset.dataUrl, {
|
|
57
|
+
width: Math.max(1, Math.round(width * scale)),
|
|
58
|
+
height: Math.max(1, Math.round(height * scale))
|
|
59
|
+
});
|
|
60
|
+
const { body, mimeType } = (0, img_namespaceObject.parseBase64)(dataUrl);
|
|
61
|
+
return {
|
|
62
|
+
...asset,
|
|
63
|
+
dataUrl,
|
|
64
|
+
base64Data: body,
|
|
65
|
+
mimeType
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async function prepareScreenshotAssetsForMarkdownReplay(screenshotAssets) {
|
|
69
|
+
const compressedAssets = [];
|
|
70
|
+
for (const asset of screenshotAssets)try {
|
|
71
|
+
compressedAssets.push(await compressScreenshotAssetForMarkdownReplay(asset));
|
|
72
|
+
} catch {
|
|
73
|
+
compressedAssets.push(asset);
|
|
74
|
+
}
|
|
75
|
+
return limitScreenshotAssetsForMarkdownReplay(compressedAssets);
|
|
76
|
+
}
|
|
77
|
+
function summarizeScreenshotAssets(screenshotAssets) {
|
|
78
|
+
const payloadSizes = screenshotAssets.map((asset)=>asset.dataUrl.length);
|
|
79
|
+
return {
|
|
80
|
+
count: screenshotAssets.length,
|
|
81
|
+
totalPayloadChars: payloadSizes.reduce((sum, size)=>sum + size, 0),
|
|
82
|
+
maxPayloadChars: payloadSizes.length ? Math.max(...payloadSizes) : 0
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function getPromptShape(prompt) {
|
|
86
|
+
let textChars = 0;
|
|
87
|
+
let imageCount = 0;
|
|
88
|
+
for (const message of prompt){
|
|
89
|
+
const content = message.content;
|
|
90
|
+
if ('string' == typeof content) {
|
|
91
|
+
textChars += content.length;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(content)) {
|
|
95
|
+
for (const part of content)if ('object' == typeof part && part && 'type' in part) {
|
|
96
|
+
if ('text' === part.type && 'text' in part) textChars += String(part.text).length;
|
|
97
|
+
if ('image_url' === part.type) imageCount += 1;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
textChars,
|
|
103
|
+
imageCount
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function removeOmittedScreenshotPaths(summary, screenshotAssets) {
|
|
107
|
+
const includedScreenshotPaths = new Set(screenshotAssets.map((asset)=>asset.relativePath));
|
|
108
|
+
return {
|
|
109
|
+
...summary,
|
|
110
|
+
events: summary.events.map((event)=>event.screenshotPath && !includedScreenshotPaths.has(event.screenshotPath) ? {
|
|
111
|
+
...event,
|
|
112
|
+
screenshotPath: void 0
|
|
113
|
+
} : event)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
35
116
|
function getMarkdownLanguageInstruction(language) {
|
|
36
117
|
const normalizedLanguage = language?.trim();
|
|
37
118
|
if (!normalizedLanguage) return '';
|
|
@@ -51,17 +132,62 @@ function resolveModelRuntime(model) {
|
|
|
51
132
|
}
|
|
52
133
|
function createRecorderMarkdownReplayPrompt(input) {
|
|
53
134
|
(0, external_recorder_generation_common_js_namespaceObject.validateEvents)(input.events);
|
|
54
|
-
const { summary, screenshotAssets } = (0, external_recorder_generation_common_js_namespaceObject.prepareRecorderGenerationContext)(input);
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
135
|
+
const { summary: rawSummary, screenshotAssets: rawScreenshotAssets } = (0, external_recorder_generation_common_js_namespaceObject.prepareRecorderGenerationContext)(input);
|
|
136
|
+
const screenshotAssets = limitScreenshotAssetsForMarkdownReplay(rawScreenshotAssets);
|
|
137
|
+
const summary = removeOmittedScreenshotPaths(rawSummary, screenshotAssets);
|
|
138
|
+
return createRecorderMarkdownReplayPromptFromContext(input, summary, screenshotAssets);
|
|
139
|
+
}
|
|
140
|
+
async function createRecorderMarkdownReplayPromptForGeneration(input) {
|
|
141
|
+
(0, external_recorder_generation_common_js_namespaceObject.validateEvents)(input.events);
|
|
142
|
+
const { summary: rawSummary, screenshotAssets: rawScreenshotAssets } = (0, external_recorder_generation_common_js_namespaceObject.prepareRecorderGenerationContext)(input);
|
|
143
|
+
const screenshotAssets = await prepareScreenshotAssetsForMarkdownReplay(rawScreenshotAssets);
|
|
144
|
+
const summary = removeOmittedScreenshotPaths(rawSummary, screenshotAssets);
|
|
145
|
+
const prompt = createRecorderMarkdownReplayPromptFromContext(input, summary, screenshotAssets);
|
|
146
|
+
debugMarkdownReplay('markdown replay prompt shape %o', {
|
|
147
|
+
eventCount: input.events.length,
|
|
148
|
+
maxScreenshots: input.maxScreenshots,
|
|
149
|
+
rawScreenshots: summarizeScreenshotAssets(rawScreenshotAssets),
|
|
150
|
+
includedScreenshots: summarizeScreenshotAssets(screenshotAssets),
|
|
151
|
+
prompt: getPromptShape(prompt)
|
|
152
|
+
});
|
|
153
|
+
return prompt;
|
|
154
|
+
}
|
|
155
|
+
function createRecorderMarkdownReplayPromptFromContext(input, summary, screenshotAssets) {
|
|
156
|
+
const screenshotIndexByEventHash = new Map(screenshotAssets.map((asset, index)=>[
|
|
157
|
+
asset.eventHashId,
|
|
158
|
+
`screenshot-${index + 1}`
|
|
159
|
+
]));
|
|
160
|
+
const events = summary.events.map((event)=>{
|
|
161
|
+
const screenshotRef = screenshotIndexByEventHash.get(event.hashId);
|
|
162
|
+
const { screenshotPath, ...eventWithoutScreenshotPath } = event;
|
|
163
|
+
return screenshotRef ? {
|
|
164
|
+
...eventWithoutScreenshotPath,
|
|
165
|
+
screenshotRef
|
|
166
|
+
} : eventWithoutScreenshotPath;
|
|
167
|
+
});
|
|
168
|
+
const promptPayload = {
|
|
169
|
+
testName: input.testName || summary.testName,
|
|
170
|
+
target: {
|
|
171
|
+
platformId: input.target.platformId,
|
|
172
|
+
label: input.target.label,
|
|
173
|
+
values: input.target.values
|
|
174
|
+
},
|
|
175
|
+
startUrl: summary.startUrl,
|
|
176
|
+
events,
|
|
177
|
+
screenshots: screenshotAssets.map((asset, index)=>({
|
|
178
|
+
screenshotRef: `screenshot-${index + 1}`,
|
|
179
|
+
eventIndex: asset.eventIndex,
|
|
180
|
+
eventHashId: asset.eventHashId,
|
|
181
|
+
eventType: asset.eventType,
|
|
182
|
+
description: (0, recorder_namespaceObject.getMidsceneRecorderEventDescription)(input.events[asset.eventIndex])
|
|
183
|
+
}))
|
|
184
|
+
};
|
|
185
|
+
const promptText = `Generate a Markdown replay script for Midscene Agent. It will be executed with:
|
|
186
|
+
await agent.aiAct(markdownReplayPrompt)
|
|
59
187
|
|
|
60
|
-
|
|
188
|
+
Use only the recorder data and screenshots below.
|
|
61
189
|
|
|
62
|
-
Target
|
|
63
|
-
- Preserve this exact platform: ${input.target.platformId}
|
|
64
|
-
- Target block:
|
|
190
|
+
Target block:
|
|
65
191
|
${(0, recorder_namespaceObject.stringifyMidsceneRecorderTargetBlock)(input.target)}
|
|
66
192
|
|
|
67
193
|
Replay goal:
|
|
@@ -71,13 +197,18 @@ Replay goal:
|
|
|
71
197
|
- Do not invent alternative navigation paths.
|
|
72
198
|
- Do not skip, merge, reorder, or add extra user actions.
|
|
73
199
|
- Prefer recorded UI text, element descriptions, URLs, input values, and scroll direction.
|
|
74
|
-
-
|
|
75
|
-
-
|
|
200
|
+
- For input events, enter event.typedText/event.value exactly; do not infer or correct the text from screenshots.
|
|
201
|
+
- Prefer event.semantic.replayInstruction and event.semantic.elementDescription when event.semantic.source is "aiDescribe" or "recorderAI" and event.semantic.status is "ready".
|
|
202
|
+
- For scroll events, preserve the recorded scroll region from event.semantic.elementDescription/replayInstruction. If the scroll happened in a specific panel, list, table, dialog body, menu, navigation area, or content pane, keep that region in the Markdown step instead of generalizing it to the whole page.
|
|
203
|
+
- If event.semantic.source is "heuristic" or event.semantic.status is "pending"/"failed", use the screenshot/context to write the best visual instruction.
|
|
76
204
|
- Coordinates are only fallback hints. Do not make coordinates the primary instruction when text or screenshots are available.
|
|
205
|
+
- For a click/tap that only focuses a field before an input event, describe the target as the field/control itself. Do not target a placeholder character, typed character, caret, or inner text fragment inside the field.
|
|
77
206
|
- If a target cannot be found, stop and report the missing step. Do not click similar-looking elements.
|
|
78
|
-
-
|
|
207
|
+
- Screenshots are only generation-time visual evidence for you. The generated Markdown will be passed directly to agent.aiAct(markdownReplayPrompt), which accepts text only and cannot receive attached images.
|
|
208
|
+
- Convert any useful screenshot evidence into textual replay instructions. Do not include screenshots, image syntax, image paths, or reference-image names in the generated Markdown.
|
|
209
|
+
- Never write Markdown image syntax such as , reference-style images, HTML <img> tags, ./screenshots/... paths, or screenshot-* names in the output.
|
|
79
210
|
|
|
80
|
-
Required
|
|
211
|
+
Required structure:
|
|
81
212
|
# ${input.testName || summary.testName}
|
|
82
213
|
|
|
83
214
|
## Goal
|
|
@@ -87,33 +218,11 @@ Reproduce the recorded user workflow exactly.
|
|
|
87
218
|
- Platform: ${input.target.platformId}
|
|
88
219
|
- Start target: ${summary.startUrl || input.target.label || input.target.deviceId || 'Recorded target'}
|
|
89
220
|
|
|
90
|
-
## Replay rules
|
|
91
|
-
- Follow the steps in order.
|
|
92
|
-
- Do not invent alternative navigation paths.
|
|
93
|
-
- If a referenced target cannot be found, stop and report the missing step.
|
|
94
|
-
|
|
95
221
|
## Steps
|
|
96
222
|
1. ...
|
|
97
223
|
|
|
98
|
-
|
|
99
|
-
${JSON.stringify({
|
|
100
|
-
...summary,
|
|
101
|
-
target: input.target,
|
|
102
|
-
events: summary.events,
|
|
103
|
-
screenshotAssets: screenshotAssets.map((asset)=>({
|
|
104
|
-
eventIndex: asset.eventIndex,
|
|
105
|
-
eventHashId: asset.eventHashId,
|
|
106
|
-
eventType: asset.eventType,
|
|
107
|
-
relativePath: asset.relativePath,
|
|
108
|
-
description: (0, recorder_namespaceObject.getMidsceneRecorderEventDescription)(input.events[asset.eventIndex])
|
|
109
|
-
}))
|
|
110
|
-
}, null, 2)}
|
|
111
|
-
|
|
112
|
-
Screenshot rules:
|
|
113
|
-
- Insert a screenshot directly under the step that needs visual grounding.
|
|
114
|
-
- Use Markdown image syntax exactly like: 
|
|
115
|
-
- Only reference paths listed in screenshotAssets.
|
|
116
|
-
- Do not reference images that are not listed.${getMarkdownLanguageInstruction(input.language)}
|
|
224
|
+
Recorder data:
|
|
225
|
+
${JSON.stringify(promptPayload, null, 2)}${getMarkdownLanguageInstruction(input.language)}
|
|
117
226
|
|
|
118
227
|
Important: Return ONLY raw Markdown. Do NOT wrap the response in markdown code blocks.`;
|
|
119
228
|
const content = [
|
|
@@ -123,9 +232,10 @@ Important: Return ONLY raw Markdown. Do NOT wrap the response in markdown code b
|
|
|
123
232
|
}
|
|
124
233
|
];
|
|
125
234
|
for (const asset of screenshotAssets){
|
|
235
|
+
const screenshotRef = screenshotIndexByEventHash.get(asset.eventHashId);
|
|
126
236
|
content.push({
|
|
127
237
|
type: 'text',
|
|
128
|
-
text:
|
|
238
|
+
text: `${screenshotRef} for event #${asset.eventIndex + 1}`
|
|
129
239
|
});
|
|
130
240
|
content.push({
|
|
131
241
|
type: 'image_url',
|
|
@@ -137,7 +247,7 @@ Important: Return ONLY raw Markdown. Do NOT wrap the response in markdown code b
|
|
|
137
247
|
return [
|
|
138
248
|
{
|
|
139
249
|
role: 'system',
|
|
140
|
-
content: "You generate precise Markdown replay scripts for Midscene agent.
|
|
250
|
+
content: "You generate precise Markdown replay scripts for Midscene agent.aiAct. The final output is plain text that will be passed directly to agent.aiAct, so it must be deterministic, ordered, safe for AI execution, and must not contain image references, screenshot paths, or screenshot labels."
|
|
141
251
|
},
|
|
142
252
|
{
|
|
143
253
|
role: 'user',
|
|
@@ -147,7 +257,7 @@ Important: Return ONLY raw Markdown. Do NOT wrap the response in markdown code b
|
|
|
147
257
|
}
|
|
148
258
|
async function generateRecorderMarkdownReplay(input, model) {
|
|
149
259
|
try {
|
|
150
|
-
const prompt =
|
|
260
|
+
const prompt = await createRecorderMarkdownReplayPromptForGeneration(input);
|
|
151
261
|
const response = await (0, external_index_js_namespaceObject.callAIWithStringResponse)(prompt, resolveModelRuntime(model));
|
|
152
262
|
if (response?.content && 'string' == typeof response.content) return normalizeGeneratedMarkdown(response.content);
|
|
153
263
|
throw new Error('Failed to generate recorder Markdown replay');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-model/prompt/markdown-generator.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/ai-model/prompt/markdown-generator.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { IModelConfig } from '@midscene/shared/env';\nimport {\n getMidsceneRecorderEventDescription,\n stringifyMidsceneRecorderTargetBlock,\n} from '@midscene/shared/recorder';\nimport type { ChatCompletionMessageParam } from 'openai/resources/index';\nimport { callAIWithStringResponse } from '../index';\nimport { type ModelRuntime, getModelRuntime } from '../models';\nimport {\n type RecorderGenerationInput,\n prepareRecorderGenerationContext,\n validateEvents,\n} from './recorder-generation-common';\n\nexport type RecorderMarkdownGenerationInput = RecorderGenerationInput;\n\nfunction getMarkdownLanguageInstruction(language?: string) {\n const normalizedLanguage = language?.trim();\n if (!normalizedLanguage) {\n return '';\n }\n\n return `\nLanguage requirement:\n- Write all human-readable Markdown instructions in ${normalizedLanguage}.\n- Keep file paths, URLs, platform ids, API names, and quoted UI text unchanged.`;\n}\n\nfunction normalizeGeneratedMarkdown(content: string) {\n const trimmed = content.trim();\n const fencedMatch = trimmed.match(\n /^```(?:md|markdown)?\\s*([\\s\\S]*?)\\s*```$/i,\n );\n return `${(fencedMatch?.[1] ?? trimmed).trim()}\\n`;\n}\n\nfunction resolveModelRuntime(model: IModelConfig | ModelRuntime): ModelRuntime {\n if ('config' in model && 'adapter' in model) {\n return model;\n }\n return getModelRuntime(model);\n}\n\nexport function createRecorderMarkdownReplayPrompt(\n input: RecorderMarkdownGenerationInput,\n): ChatCompletionMessageParam[] {\n validateEvents(input.events);\n\n const { summary, screenshotAssets } = prepareRecorderGenerationContext(input);\n const promptText = `Generate a Markdown replay script for Midscene Agent.\n\nThis Markdown will be executed with:\nawait agent.runMarkdown('./x.md')\n\nIt is an AI-executable replay script, not a human report.\n\nTarget platform:\n- Preserve this exact platform: ${input.target.platformId}\n- Target block:\n${stringifyMidsceneRecorderTargetBlock(input.target)}\n\nReplay goal:\n- Reproduce the recorded user workflow exactly.\n- Preserve event order.\n- Preserve the user's original intent.\n- Do not invent alternative navigation paths.\n- Do not skip, merge, reorder, or add extra user actions.\n- Prefer recorded UI text, element descriptions, URLs, input values, and scroll direction.\n- Prefer event.replayInstruction and event.elementDescription when descriptionSource is \"ai\".\n- If descriptionSource is \"fallback\", use the screenshot/context to write the best visual instruction.\n- Coordinates are only fallback hints. Do not make coordinates the primary instruction when text or screenshots are available.\n- If a target cannot be found, stop and report the missing step. Do not click similar-looking elements.\n- Use screenshots only when they are provided below. Reference them by their exact relative paths.\n\nRequired Markdown structure:\n# ${input.testName || summary.testName}\n\n## Goal\nReproduce the recorded user workflow exactly.\n\n## Target\n- Platform: ${input.target.platformId}\n- Start target: ${summary.startUrl || input.target.label || input.target.deviceId || 'Recorded target'}\n\n## Replay rules\n- Follow the steps in order.\n- Do not invent alternative navigation paths.\n- If a referenced target cannot be found, stop and report the missing step.\n\n## Steps\n1. ...\n\nEvent summary:\n${JSON.stringify(\n {\n ...summary,\n target: input.target,\n events: summary.events,\n screenshotAssets: screenshotAssets.map((asset) => ({\n eventIndex: asset.eventIndex,\n eventHashId: asset.eventHashId,\n eventType: asset.eventType,\n relativePath: asset.relativePath,\n description: getMidsceneRecorderEventDescription(\n input.events[asset.eventIndex],\n ),\n })),\n },\n null,\n 2,\n)}\n\nScreenshot rules:\n- Insert a screenshot directly under the step that needs visual grounding.\n- Use Markdown image syntax exactly like: \n- Only reference paths listed in screenshotAssets.\n- Do not reference images that are not listed.${getMarkdownLanguageInstruction(input.language)}\n\nImportant: Return ONLY raw Markdown. Do NOT wrap the response in markdown code blocks.`;\n\n const content: any[] = [\n {\n type: 'text',\n text: promptText,\n },\n ];\n\n for (const asset of screenshotAssets) {\n content.push({\n type: 'text',\n text: `Screenshot asset for event #${asset.eventIndex + 1}: ${asset.relativePath}`,\n });\n content.push({\n type: 'image_url',\n image_url: {\n url: asset.dataUrl,\n },\n });\n }\n\n return [\n {\n role: 'system',\n content:\n 'You generate precise Markdown replay scripts for Midscene agent.runMarkdown. The output must be deterministic, ordered, and safe for AI execution.',\n },\n {\n role: 'user',\n content,\n },\n ];\n}\n\nexport async function generateRecorderMarkdownReplay(\n input: RecorderMarkdownGenerationInput,\n model: IModelConfig | ModelRuntime,\n): Promise<string> {\n try {\n const prompt = createRecorderMarkdownReplayPrompt(input);\n const response = await callAIWithStringResponse(\n prompt,\n resolveModelRuntime(model),\n );\n\n if (response?.content && typeof response.content === 'string') {\n return normalizeGeneratedMarkdown(response.content);\n }\n\n throw new Error('Failed to generate recorder Markdown replay');\n } catch (error) {\n throw new Error(`Failed to generate recorder Markdown replay: ${error}`);\n }\n}\n\nexport async function convertRecordLogIntoMarkdown(\n log: RecorderMarkdownGenerationInput,\n modelConfig: IModelConfig,\n): Promise<string> {\n return generateRecorderMarkdownReplay(log, modelConfig);\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","getMarkdownLanguageInstruction","language","normalizedLanguage","normalizeGeneratedMarkdown","content","trimmed","fencedMatch","resolveModelRuntime","model","getModelRuntime","createRecorderMarkdownReplayPrompt","input","validateEvents","summary","screenshotAssets","prepareRecorderGenerationContext","promptText","stringifyMidsceneRecorderTargetBlock","JSON","asset","getMidsceneRecorderEventDescription","generateRecorderMarkdownReplay","prompt","response","callAIWithStringResponse","Error","error","convertRecordLogIntoMarkdown","log","modelConfig"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;;ACUA,SAASI,+BAA+BC,QAAiB;IACvD,MAAMC,qBAAqBD,UAAU;IACrC,IAAI,CAACC,oBACH,OAAO;IAGT,OAAO,CAAC;;oDAE0C,EAAEA,mBAAmB;+EACM,CAAC;AAChF;AAEA,SAASC,2BAA2BC,OAAe;IACjD,MAAMC,UAAUD,QAAQ,IAAI;IAC5B,MAAME,cAAcD,QAAQ,KAAK,CAC/B;IAEF,OAAO,GAAIC,AAAAA,CAAAA,aAAa,CAAC,EAAE,IAAID,OAAM,EAAG,IAAI,GAAG,EAAE,CAAC;AACpD;AAEA,SAASE,oBAAoBC,KAAkC;IAC7D,IAAI,YAAYA,SAAS,aAAaA,OACpC,OAAOA;IAET,OAAOC,AAAAA,IAAAA,yBAAAA,eAAAA,AAAAA,EAAgBD;AACzB;AAEO,SAASE,mCACdC,KAAsC;IAEtCC,IAAAA,uDAAAA,cAAAA,AAAAA,EAAeD,MAAM,MAAM;IAE3B,MAAM,EA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pB;QACF;IACF;IAEA,OAAO;QACL;YACE,MAAM;YACN,SACE;QACJ;QACA;YACE,MAAM;YACNf;QACF;KACD;AACH;AAEO,eAAeiB,+BACpBV,KAAsC,EACtCH,KAAkC;IAElC,IAAI;QACF,MAAMc,SAASZ,mCAAmCC;QAClD,MAAMY,WAAW,MAAMC,AAAAA,IAAAA,kCAAAA,wBAAAA,AAAAA,EACrBF,QACAf,oBAAoBC;QAGtB,IAAIe,UAAU,WAAW,AAA4B,YAA5B,OAAOA,SAAS,OAAO,EAC9C,OAAOpB,2BAA2BoB,SAAS,OAAO;QAGpD,MAAM,IAAIE,MAAM;IAClB,EAAE,OAAOC,OAAO;QACd,MAAM,IAAID,MAAM,CAAC,6CAA6C,EAAEC,OAAO;IACzE;AACF;AAEO,eAAeC,6BACpBC,GAAoC,EACpCC,WAAyB;IAEzB,OAAOR,+BAA+BO,KAAKC;AAC7C"}
|
|
1
|
+
{"version":3,"file":"ai-model/prompt/markdown-generator.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/ai-model/prompt/markdown-generator.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { IModelConfig } from '@midscene/shared/env';\nimport {\n imageInfoOfBase64,\n parseBase64,\n resizeImgBase64,\n} from '@midscene/shared/img';\nimport { getDebug } from '@midscene/shared/logger';\nimport {\n type MidsceneRecorderMarkdownScreenshotAsset,\n getMidsceneRecorderEventDescription,\n stringifyMidsceneRecorderTargetBlock,\n} from '@midscene/shared/recorder';\nimport type { ChatCompletionMessageParam } from 'openai/resources/index';\nimport { callAIWithStringResponse } from '../index';\nimport { type ModelRuntime, getModelRuntime } from '../models';\nimport {\n type RecorderGenerationInput,\n prepareRecorderGenerationContext,\n validateEvents,\n} from './recorder-generation-common';\n\nexport type RecorderMarkdownGenerationInput = RecorderGenerationInput;\n\nconst MARKDOWN_REPLAY_SCREENSHOT_PAYLOAD_BUDGET = 600_000;\nconst MARKDOWN_REPLAY_SCREENSHOT_MAX_EDGE = 768;\nconst debugMarkdownReplay = getDebug('ai:recorder-markdown', {\n console: true,\n});\n\nfunction limitScreenshotAssetsForMarkdownReplay(\n screenshotAssets: MidsceneRecorderMarkdownScreenshotAsset[],\n) {\n let usedPayload = 0;\n return screenshotAssets.filter((asset) => {\n const payloadSize = asset.dataUrl.length;\n if (\n payloadSize > MARKDOWN_REPLAY_SCREENSHOT_PAYLOAD_BUDGET ||\n usedPayload + payloadSize > MARKDOWN_REPLAY_SCREENSHOT_PAYLOAD_BUDGET\n ) {\n return false;\n }\n usedPayload += payloadSize;\n return true;\n });\n}\n\nasync function compressScreenshotAssetForMarkdownReplay(\n asset: MidsceneRecorderMarkdownScreenshotAsset,\n): Promise<MidsceneRecorderMarkdownScreenshotAsset> {\n const { width, height } = await imageInfoOfBase64(asset.dataUrl);\n const longestEdge = Math.max(width, height);\n if (longestEdge <= MARKDOWN_REPLAY_SCREENSHOT_MAX_EDGE) {\n return asset;\n }\n\n const scale = MARKDOWN_REPLAY_SCREENSHOT_MAX_EDGE / longestEdge;\n const dataUrl = await resizeImgBase64(asset.dataUrl, {\n width: Math.max(1, Math.round(width * scale)),\n height: Math.max(1, Math.round(height * scale)),\n });\n const { body, mimeType } = parseBase64(dataUrl);\n return {\n ...asset,\n dataUrl,\n base64Data: body,\n mimeType,\n };\n}\n\nasync function prepareScreenshotAssetsForMarkdownReplay(\n screenshotAssets: MidsceneRecorderMarkdownScreenshotAsset[],\n) {\n const compressedAssets: MidsceneRecorderMarkdownScreenshotAsset[] = [];\n for (const asset of screenshotAssets) {\n try {\n compressedAssets.push(\n await compressScreenshotAssetForMarkdownReplay(asset),\n );\n } catch {\n compressedAssets.push(asset);\n }\n }\n return limitScreenshotAssetsForMarkdownReplay(compressedAssets);\n}\n\nfunction summarizeScreenshotAssets(\n screenshotAssets: MidsceneRecorderMarkdownScreenshotAsset[],\n) {\n const payloadSizes = screenshotAssets.map((asset) => asset.dataUrl.length);\n return {\n count: screenshotAssets.length,\n totalPayloadChars: payloadSizes.reduce((sum, size) => sum + size, 0),\n maxPayloadChars: payloadSizes.length ? Math.max(...payloadSizes) : 0,\n };\n}\n\nfunction getPromptShape(prompt: ChatCompletionMessageParam[]) {\n let textChars = 0;\n let imageCount = 0;\n for (const message of prompt) {\n const content = message.content;\n if (typeof content === 'string') {\n textChars += content.length;\n continue;\n }\n if (!Array.isArray(content)) {\n continue;\n }\n for (const part of content) {\n if (typeof part === 'object' && part && 'type' in part) {\n if (part.type === 'text' && 'text' in part) {\n textChars += String(part.text).length;\n }\n if (part.type === 'image_url') {\n imageCount += 1;\n }\n }\n }\n }\n return { textChars, imageCount };\n}\n\nfunction removeOmittedScreenshotPaths(\n summary: ReturnType<typeof prepareRecorderGenerationContext>['summary'],\n screenshotAssets: MidsceneRecorderMarkdownScreenshotAsset[],\n) {\n const includedScreenshotPaths = new Set(\n screenshotAssets.map((asset) => asset.relativePath),\n );\n return {\n ...summary,\n events: summary.events.map((event) =>\n event.screenshotPath && !includedScreenshotPaths.has(event.screenshotPath)\n ? { ...event, screenshotPath: undefined }\n : event,\n ),\n };\n}\n\nfunction getMarkdownLanguageInstruction(language?: string) {\n const normalizedLanguage = language?.trim();\n if (!normalizedLanguage) {\n return '';\n }\n\n return `\nLanguage requirement:\n- Write all human-readable Markdown instructions in ${normalizedLanguage}.\n- Keep file paths, URLs, platform ids, API names, and quoted UI text unchanged.`;\n}\n\nfunction normalizeGeneratedMarkdown(content: string) {\n const trimmed = content.trim();\n const fencedMatch = trimmed.match(\n /^```(?:md|markdown)?\\s*([\\s\\S]*?)\\s*```$/i,\n );\n return `${(fencedMatch?.[1] ?? trimmed).trim()}\\n`;\n}\n\nfunction resolveModelRuntime(model: IModelConfig | ModelRuntime): ModelRuntime {\n if ('config' in model && 'adapter' in model) {\n return model;\n }\n return getModelRuntime(model);\n}\n\nexport function createRecorderMarkdownReplayPrompt(\n input: RecorderMarkdownGenerationInput,\n): ChatCompletionMessageParam[] {\n validateEvents(input.events);\n\n const { summary: rawSummary, screenshotAssets: rawScreenshotAssets } =\n prepareRecorderGenerationContext(input);\n const screenshotAssets =\n limitScreenshotAssetsForMarkdownReplay(rawScreenshotAssets);\n const summary = removeOmittedScreenshotPaths(rawSummary, screenshotAssets);\n return createRecorderMarkdownReplayPromptFromContext(\n input,\n summary,\n screenshotAssets,\n );\n}\n\nasync function createRecorderMarkdownReplayPromptForGeneration(\n input: RecorderMarkdownGenerationInput,\n): Promise<ChatCompletionMessageParam[]> {\n validateEvents(input.events);\n\n const { summary: rawSummary, screenshotAssets: rawScreenshotAssets } =\n prepareRecorderGenerationContext(input);\n const screenshotAssets =\n await prepareScreenshotAssetsForMarkdownReplay(rawScreenshotAssets);\n const summary = removeOmittedScreenshotPaths(rawSummary, screenshotAssets);\n const prompt = createRecorderMarkdownReplayPromptFromContext(\n input,\n summary,\n screenshotAssets,\n );\n debugMarkdownReplay('markdown replay prompt shape %o', {\n eventCount: input.events.length,\n maxScreenshots: input.maxScreenshots,\n rawScreenshots: summarizeScreenshotAssets(rawScreenshotAssets),\n includedScreenshots: summarizeScreenshotAssets(screenshotAssets),\n prompt: getPromptShape(prompt),\n });\n return prompt;\n}\n\nfunction createRecorderMarkdownReplayPromptFromContext(\n input: RecorderMarkdownGenerationInput,\n summary: ReturnType<typeof prepareRecorderGenerationContext>['summary'],\n screenshotAssets: MidsceneRecorderMarkdownScreenshotAsset[],\n): ChatCompletionMessageParam[] {\n const screenshotIndexByEventHash = new Map(\n screenshotAssets.map((asset, index) => [\n asset.eventHashId,\n `screenshot-${index + 1}`,\n ]),\n );\n const events = summary.events.map((event) => {\n const screenshotRef = screenshotIndexByEventHash.get(event.hashId);\n const { screenshotPath, ...eventWithoutScreenshotPath } = event;\n return screenshotRef\n ? { ...eventWithoutScreenshotPath, screenshotRef }\n : eventWithoutScreenshotPath;\n });\n const promptPayload = {\n testName: input.testName || summary.testName,\n target: {\n platformId: input.target.platformId,\n label: input.target.label,\n values: input.target.values,\n },\n startUrl: summary.startUrl,\n events,\n screenshots: screenshotAssets.map((asset, index) => ({\n screenshotRef: `screenshot-${index + 1}`,\n eventIndex: asset.eventIndex,\n eventHashId: asset.eventHashId,\n eventType: asset.eventType,\n description: getMidsceneRecorderEventDescription(\n input.events[asset.eventIndex],\n ),\n })),\n };\n const promptText = `Generate a Markdown replay script for Midscene Agent. It will be executed with:\nawait agent.aiAct(markdownReplayPrompt)\n\nUse only the recorder data and screenshots below.\n\nTarget block:\n${stringifyMidsceneRecorderTargetBlock(input.target)}\n\nReplay goal:\n- Reproduce the recorded user workflow exactly.\n- Preserve event order.\n- Preserve the user's original intent.\n- Do not invent alternative navigation paths.\n- Do not skip, merge, reorder, or add extra user actions.\n- Prefer recorded UI text, element descriptions, URLs, input values, and scroll direction.\n- For input events, enter event.typedText/event.value exactly; do not infer or correct the text from screenshots.\n- Prefer event.semantic.replayInstruction and event.semantic.elementDescription when event.semantic.source is \"aiDescribe\" or \"recorderAI\" and event.semantic.status is \"ready\".\n- For scroll events, preserve the recorded scroll region from event.semantic.elementDescription/replayInstruction. If the scroll happened in a specific panel, list, table, dialog body, menu, navigation area, or content pane, keep that region in the Markdown step instead of generalizing it to the whole page.\n- If event.semantic.source is \"heuristic\" or event.semantic.status is \"pending\"/\"failed\", use the screenshot/context to write the best visual instruction.\n- Coordinates are only fallback hints. Do not make coordinates the primary instruction when text or screenshots are available.\n- For a click/tap that only focuses a field before an input event, describe the target as the field/control itself. Do not target a placeholder character, typed character, caret, or inner text fragment inside the field.\n- If a target cannot be found, stop and report the missing step. Do not click similar-looking elements.\n- Screenshots are only generation-time visual evidence for you. The generated Markdown will be passed directly to agent.aiAct(markdownReplayPrompt), which accepts text only and cannot receive attached images.\n- Convert any useful screenshot evidence into textual replay instructions. Do not include screenshots, image syntax, image paths, or reference-image names in the generated Markdown.\n- Never write Markdown image syntax such as , reference-style images, HTML <img> tags, ./screenshots/... paths, or screenshot-* names in the output.\n\nRequired structure:\n# ${input.testName || summary.testName}\n\n## Goal\nReproduce the recorded user workflow exactly.\n\n## Target\n- Platform: ${input.target.platformId}\n- Start target: ${summary.startUrl || input.target.label || input.target.deviceId || 'Recorded target'}\n\n## Steps\n1. ...\n\nRecorder data:\n${JSON.stringify(promptPayload, null, 2)}${getMarkdownLanguageInstruction(input.language)}\n\nImportant: Return ONLY raw Markdown. Do NOT wrap the response in markdown code blocks.`;\n\n const content: any[] = [\n {\n type: 'text',\n text: promptText,\n },\n ];\n\n for (const asset of screenshotAssets) {\n const screenshotRef = screenshotIndexByEventHash.get(asset.eventHashId);\n content.push({\n type: 'text',\n text: `${screenshotRef} for event #${asset.eventIndex + 1}`,\n });\n content.push({\n type: 'image_url',\n image_url: {\n url: asset.dataUrl,\n },\n });\n }\n\n return [\n {\n role: 'system',\n content:\n 'You generate precise Markdown replay scripts for Midscene agent.aiAct. The final output is plain text that will be passed directly to agent.aiAct, so it must be deterministic, ordered, safe for AI execution, and must not contain image references, screenshot paths, or screenshot labels.',\n },\n {\n role: 'user',\n content,\n },\n ];\n}\n\nexport async function generateRecorderMarkdownReplay(\n input: RecorderMarkdownGenerationInput,\n model: IModelConfig | ModelRuntime,\n): Promise<string> {\n try {\n const prompt = await createRecorderMarkdownReplayPromptForGeneration(input);\n const response = await callAIWithStringResponse(\n prompt,\n resolveModelRuntime(model),\n );\n\n if (response?.content && typeof response.content === 'string') {\n return normalizeGeneratedMarkdown(response.content);\n }\n\n throw new Error('Failed to generate recorder Markdown replay');\n } catch (error) {\n throw new Error(`Failed to generate recorder Markdown replay: ${error}`);\n }\n}\n\nexport async function convertRecordLogIntoMarkdown(\n log: RecorderMarkdownGenerationInput,\n modelConfig: IModelConfig,\n): Promise<string> {\n return generateRecorderMarkdownReplay(log, modelConfig);\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","MARKDOWN_REPLAY_SCREENSHOT_PAYLOAD_BUDGET","MARKDOWN_REPLAY_SCREENSHOT_MAX_EDGE","debugMarkdownReplay","getDebug","limitScreenshotAssetsForMarkdownReplay","screenshotAssets","usedPayload","asset","payloadSize","compressScreenshotAssetForMarkdownReplay","width","height","imageInfoOfBase64","longestEdge","Math","scale","dataUrl","resizeImgBase64","body","mimeType","parseBase64","prepareScreenshotAssetsForMarkdownReplay","compressedAssets","summarizeScreenshotAssets","payloadSizes","sum","size","getPromptShape","prompt","textChars","imageCount","message","content","Array","part","String","removeOmittedScreenshotPaths","summary","includedScreenshotPaths","Set","event","undefined","getMarkdownLanguageInstruction","language","normalizedLanguage","normalizeGeneratedMarkdown","trimmed","fencedMatch","resolveModelRuntime","model","getModelRuntime","createRecorderMarkdownReplayPrompt","input","validateEvents","rawSummary","rawScreenshotAssets","prepareRecorderGenerationContext","createRecorderMarkdownReplayPromptFromContext","createRecorderMarkdownReplayPromptForGeneration","screenshotIndexByEventHash","Map","index","events","screenshotRef","screenshotPath","eventWithoutScreenshotPath","promptPayload","getMidsceneRecorderEventDescription","promptText","stringifyMidsceneRecorderTargetBlock","JSON","generateRecorderMarkdownReplay","response","callAIWithStringResponse","Error","error","convertRecordLogIntoMarkdown","log","modelConfig"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,I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tB,IAAIuB,UAAU,WAAW,AAA4B,YAA5B,OAAOA,SAAS,OAAO,EAC9C,OAAO3B,2BAA2B2B,SAAS,OAAO;QAGpD,MAAM,IAAIE,MAAM;IAClB,EAAE,OAAOC,OAAO;QACd,MAAM,IAAID,MAAM,CAAC,6CAA6C,EAAEC,OAAO;IACzE;AACF;AAEO,eAAeC,6BACpBC,GAAoC,EACpCC,WAAyB;IAEzB,OAAOP,+BAA+BM,KAAKC;AAC7C"}
|
|
@@ -32,12 +32,48 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
32
32
|
extractInputDescriptions: ()=>extractInputDescriptions,
|
|
33
33
|
prepareEventSummary: ()=>prepareEventSummary,
|
|
34
34
|
prepareRecorderGenerationContext: ()=>prepareRecorderGenerationContext,
|
|
35
|
+
compactRecorderSemanticForGeneration: ()=>compactRecorderSemanticForGeneration,
|
|
35
36
|
processEventsForLLM: ()=>processEventsForLLM
|
|
36
37
|
});
|
|
37
38
|
const recorder_namespaceObject = require("@midscene/shared/recorder");
|
|
39
|
+
const MAX_RECORDER_GENERATION_SEMANTIC_TEXT_LENGTH = 1200;
|
|
40
|
+
const MAX_RECORDER_GENERATION_SEMANTIC_ERROR_LENGTH = 400;
|
|
38
41
|
function cleanRecorderSemanticField(value) {
|
|
39
42
|
return value?.trim() === 'AI is analyzing element...' ? void 0 : value;
|
|
40
43
|
}
|
|
44
|
+
function truncateRecorderGenerationText(value, maxLength) {
|
|
45
|
+
if (value.length <= maxLength) return value;
|
|
46
|
+
return `${value.slice(0, maxLength)}... [truncated ${value.length - maxLength} chars]`;
|
|
47
|
+
}
|
|
48
|
+
function compactRecorderSemanticText(value) {
|
|
49
|
+
const cleaned = cleanRecorderSemanticField(value);
|
|
50
|
+
return cleaned ? truncateRecorderGenerationText(cleaned, MAX_RECORDER_GENERATION_SEMANTIC_TEXT_LENGTH) : void 0;
|
|
51
|
+
}
|
|
52
|
+
function compactRecorderSemanticError(value) {
|
|
53
|
+
return value ? truncateRecorderGenerationText(value, MAX_RECORDER_GENERATION_SEMANTIC_ERROR_LENGTH) : void 0;
|
|
54
|
+
}
|
|
55
|
+
function compactRecorderSemanticForGeneration(semantic) {
|
|
56
|
+
if (!semantic) return;
|
|
57
|
+
return {
|
|
58
|
+
source: semantic.source,
|
|
59
|
+
status: semantic.status,
|
|
60
|
+
confidence: semantic.confidence,
|
|
61
|
+
elementDescription: compactRecorderSemanticText(semantic.elementDescription),
|
|
62
|
+
replayInstruction: compactRecorderSemanticText(semantic.replayInstruction),
|
|
63
|
+
actionSummary: compactRecorderSemanticText(semantic.actionSummary),
|
|
64
|
+
error: compactRecorderSemanticError(semantic.error),
|
|
65
|
+
...semantic.aiDescribe ? {
|
|
66
|
+
aiDescribe: {
|
|
67
|
+
verifyPrompt: semantic.aiDescribe.verifyPrompt,
|
|
68
|
+
verifyPassed: semantic.aiDescribe.verifyPassed,
|
|
69
|
+
deepLocate: semantic.aiDescribe.deepLocate,
|
|
70
|
+
centerDistance: semantic.aiDescribe.centerDistance,
|
|
71
|
+
expectedCenter: semantic.aiDescribe.expectedCenter,
|
|
72
|
+
actualCenter: semantic.aiDescribe.actualCenter
|
|
73
|
+
}
|
|
74
|
+
} : {}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
41
77
|
const validateEvents = (events)=>{
|
|
42
78
|
if (!events.length) throw new Error('No events provided for test generation');
|
|
43
79
|
};
|
|
@@ -58,35 +94,60 @@ const createEventCounts = (filteredEvents, totalEvents)=>({
|
|
|
58
94
|
scroll: filteredEvents.scrollEvents.length,
|
|
59
95
|
total: totalEvents
|
|
60
96
|
});
|
|
61
|
-
const extractInputDescriptions = (inputEvents)=>inputEvents.map((event)=>
|
|
62
|
-
|
|
97
|
+
const extractInputDescriptions = (inputEvents)=>inputEvents.map((event)=>{
|
|
98
|
+
const semantic = (0, recorder_namespaceObject.getMidsceneRecorderSemantic)(event);
|
|
99
|
+
return {
|
|
100
|
+
description: cleanRecorderSemanticField(semantic?.elementDescription) || '',
|
|
63
101
|
value: event.value || ''
|
|
64
|
-
}
|
|
65
|
-
|
|
102
|
+
};
|
|
103
|
+
}).filter((item)=>item.description && item.value);
|
|
104
|
+
const processEventsForLLM = (events, screenshotPathByEventHash = new Map())=>{
|
|
105
|
+
let inputIndex = 0;
|
|
106
|
+
return events.map((event, index)=>{
|
|
107
|
+
const previousEvent = events[index - 1];
|
|
108
|
+
const nextEvent = events[index + 1];
|
|
109
|
+
const previousInput = events.slice(0, index).reverse().find((candidate)=>'input' === candidate.type);
|
|
110
|
+
const nextInput = events.slice(index + 1).find((candidate)=>'input' === candidate.type);
|
|
111
|
+
const isInput = 'input' === event.type;
|
|
112
|
+
const inputSequenceIndex = isInput ? ++inputIndex : void 0;
|
|
113
|
+
const hasNeighborInput = Boolean(previousInput || nextInput);
|
|
114
|
+
const neighborInputValues = isInput ? [
|
|
115
|
+
previousInput?.value,
|
|
116
|
+
nextInput?.value
|
|
117
|
+
].filter((value)=>Boolean(value)) : void 0;
|
|
118
|
+
const semantic = compactRecorderSemanticForGeneration((0, recorder_namespaceObject.getMidsceneRecorderSemantic)(event));
|
|
119
|
+
return {
|
|
66
120
|
hashId: event.hashId,
|
|
67
121
|
type: event.type,
|
|
68
122
|
timestamp: event.timestamp,
|
|
69
123
|
source: event.source,
|
|
70
124
|
actionType: event.actionType,
|
|
71
|
-
descriptionSource: event.descriptionSource,
|
|
72
|
-
descriptionError: event.descriptionError,
|
|
73
125
|
url: event.url,
|
|
74
126
|
title: event.title,
|
|
75
|
-
|
|
76
|
-
replayInstruction: cleanRecorderSemanticField(event.replayInstruction),
|
|
77
|
-
actionSummary: cleanRecorderSemanticField(event.actionSummary),
|
|
78
|
-
semanticConfidence: event.semanticConfidence,
|
|
127
|
+
semantic,
|
|
79
128
|
description: (0, recorder_namespaceObject.getMidsceneRecorderEventDescription)(event),
|
|
80
129
|
value: event.value,
|
|
130
|
+
previousActionDescription: previousEvent ? (0, recorder_namespaceObject.getMidsceneRecorderEventDescription)(previousEvent) : void 0,
|
|
131
|
+
nextActionDescription: nextEvent ? (0, recorder_namespaceObject.getMidsceneRecorderEventDescription)(nextEvent) : void 0,
|
|
132
|
+
...isInput ? {
|
|
133
|
+
typedText: event.value || '',
|
|
134
|
+
inputIndex: inputSequenceIndex,
|
|
135
|
+
isSequentialInput: previousEvent?.type === 'input' || nextEvent?.type === 'input',
|
|
136
|
+
hasNeighborInput,
|
|
137
|
+
previousInputDescription: previousInput ? (0, recorder_namespaceObject.getMidsceneRecorderEventDescription)(previousInput) : void 0,
|
|
138
|
+
neighborInputValues: neighborInputValues && neighborInputValues.length > 0 ? neighborInputValues : void 0
|
|
139
|
+
} : {},
|
|
81
140
|
pageInfo: event.pageInfo,
|
|
82
141
|
elementRect: event.elementRect,
|
|
83
142
|
screenshotPath: screenshotPathByEventHash.get(event.hashId)
|
|
84
|
-
}
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
};
|
|
85
146
|
const prepareEventSummary = (events, options = {})=>{
|
|
86
147
|
const filteredEvents = filterEventsByType(events);
|
|
87
148
|
const eventCounts = createEventCounts(filteredEvents, events.length);
|
|
88
149
|
const startUrl = filteredEvents.navigationEvents.length > 0 ? filteredEvents.navigationEvents[0].url || '' : '';
|
|
89
|
-
const clickDescriptions = filteredEvents.clickEvents.map((event)=>event
|
|
150
|
+
const clickDescriptions = filteredEvents.clickEvents.map((event)=>(0, recorder_namespaceObject.getMidsceneRecorderSemantic)(event)?.elementDescription).filter((desc)=>Boolean(desc)).slice(0, 10);
|
|
90
151
|
const inputDescriptions = extractInputDescriptions(filteredEvents.inputEvents).slice(0, 10);
|
|
91
152
|
const urls = filteredEvents.navigationEvents.map((e)=>e.url).filter((url)=>Boolean(url)).slice(0, 5);
|
|
92
153
|
const processedEvents = processEventsForLLM(events, options.screenshotPathByEventHash);
|
|
@@ -142,6 +203,7 @@ const createMessageContent = (promptText, screenshots = [], includeScreenshots =
|
|
|
142
203
|
}
|
|
143
204
|
return messageContent;
|
|
144
205
|
};
|
|
206
|
+
exports.compactRecorderSemanticForGeneration = __webpack_exports__.compactRecorderSemanticForGeneration;
|
|
145
207
|
exports.createEventCounts = __webpack_exports__.createEventCounts;
|
|
146
208
|
exports.createMessageContent = __webpack_exports__.createMessageContent;
|
|
147
209
|
exports.extractInputDescriptions = __webpack_exports__.extractInputDescriptions;
|
|
@@ -152,6 +214,7 @@ exports.prepareRecorderGenerationContext = __webpack_exports__.prepareRecorderGe
|
|
|
152
214
|
exports.processEventsForLLM = __webpack_exports__.processEventsForLLM;
|
|
153
215
|
exports.validateEvents = __webpack_exports__.validateEvents;
|
|
154
216
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
217
|
+
"compactRecorderSemanticForGeneration",
|
|
155
218
|
"createEventCounts",
|
|
156
219
|
"createMessageContent",
|
|
157
220
|
"extractInputDescriptions",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-model/prompt/recorder-generation-common.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/ai-model/prompt/recorder-generation-common.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import {\n DEFAULT_MIDSCENE_RECORDER_MARKDOWN_MAX_SCREENSHOTS,\n type MidsceneRecorderEvent,\n type MidsceneRecorderMarkdownScreenshotAsset,\n type MidsceneRecorderTarget,\n createMidsceneRecorderMarkdownScreenshotAssets,\n getMidsceneRecorderEventDescription,\n} from '@midscene/shared/recorder';\n\nexport interface EventCounts {\n navigation: number;\n click: number;\n input: number;\n scroll: number;\n total: number;\n}\n\nexport interface InputDescription {\n description: string;\n value: string;\n}\n\nexport interface ProcessedEvent {\n hashId: string;\n type: string;\n timestamp: number;\n source?: string;\n actionType?: string;\n descriptionSource?: string;\n descriptionError?: string;\n url?: string;\n title?: string;\n elementDescription?: string;\n replayInstruction?: string;\n actionSummary?: string;\n semanticConfidence?: string;\n description?: string;\n value?: string;\n pageInfo?: any;\n elementRect?: any;\n screenshotPath?: string;\n}\n\nexport interface EventSummary {\n testName: string;\n startUrl: string;\n eventCounts: EventCounts;\n urls: string[];\n clickDescriptions: string[];\n inputDescriptions: InputDescription[];\n events: ProcessedEvent[];\n}\n\nexport interface RecorderGenerationContext {\n summary: EventSummary;\n screenshotAssets: MidsceneRecorderMarkdownScreenshotAsset[];\n}\n\nexport type ChromeRecordedEvent = MidsceneRecorderEvent;\n\nexport interface RecorderGenerationOptions {\n testName?: string;\n includeTimestamps?: boolean;\n maxScreenshots?: number;\n description?: string;\n /** Language for human-readable generated content (e.g. 'English', 'Chinese'). Keys and API names are kept as-is. */\n language?: string;\n navigationInfo?: {\n urls?: string[];\n titles?: string[];\n initialViewport?: {\n width?: number;\n height?: number;\n };\n };\n}\n\nexport interface RecorderGenerationInput extends RecorderGenerationOptions {\n target: MidsceneRecorderTarget;\n events: MidsceneRecorderEvent[];\n}\n\nexport interface FilteredEvents {\n navigationEvents: ChromeRecordedEvent[];\n clickEvents: ChromeRecordedEvent[];\n inputEvents: ChromeRecordedEvent[];\n scrollEvents: ChromeRecordedEvent[];\n}\n\nfunction cleanRecorderSemanticField(value?: string) {\n return value?.trim() === 'AI is analyzing element...' ? undefined : value;\n}\n\nexport const validateEvents = (events: ChromeRecordedEvent[]): void => {\n if (!events.length) {\n throw new Error('No events provided for test generation');\n }\n};\n\nexport const getScreenshotsForLLM = (\n events: ChromeRecordedEvent[],\n maxScreenshots = 1,\n): string[] => {\n return createMidsceneRecorderMarkdownScreenshotAssets(events, {\n baseDir: './screenshots',\n maxScreenshots,\n }).map((asset) => asset.dataUrl);\n};\n\nexport const filterEventsByType = (\n events: ChromeRecordedEvent[],\n): FilteredEvents => {\n return {\n navigationEvents: events.filter((event) => event.type === 'navigation'),\n clickEvents: events.filter((event) => event.type === 'click'),\n inputEvents: events.filter((event) => event.type === 'input'),\n scrollEvents: events.filter((event) => event.type === 'scroll'),\n };\n};\n\nexport const createEventCounts = (\n filteredEvents: FilteredEvents,\n totalEvents: number,\n): EventCounts => {\n return {\n navigation: filteredEvents.navigationEvents.length,\n click: filteredEvents.clickEvents.length,\n input: filteredEvents.inputEvents.length,\n scroll: filteredEvents.scrollEvents.length,\n total: totalEvents,\n };\n};\n\nexport const extractInputDescriptions = (\n inputEvents: ChromeRecordedEvent[],\n): InputDescription[] => {\n return inputEvents\n .map((event) => ({\n description: cleanRecorderSemanticField(event.elementDescription) || '',\n value: event.value || '',\n }))\n .filter((item) => item.description && item.value);\n};\n\nexport const processEventsForLLM = (\n events: ChromeRecordedEvent[],\n screenshotPathByEventHash: Map<string, string> = new Map(),\n): ProcessedEvent[] => {\n return events.map((event) => ({\n hashId: event.hashId,\n type: event.type,\n timestamp: event.timestamp,\n source: event.source,\n actionType: event.actionType,\n descriptionSource: event.descriptionSource,\n descriptionError: event.descriptionError,\n url: event.url,\n title: event.title,\n elementDescription: cleanRecorderSemanticField(event.elementDescription),\n replayInstruction: cleanRecorderSemanticField(event.replayInstruction),\n actionSummary: cleanRecorderSemanticField(event.actionSummary),\n semanticConfidence: event.semanticConfidence,\n description: getMidsceneRecorderEventDescription(event),\n value: event.value,\n pageInfo: event.pageInfo,\n elementRect: event.elementRect,\n screenshotPath: screenshotPathByEventHash.get(event.hashId),\n }));\n};\n\nexport const prepareEventSummary = (\n events: ChromeRecordedEvent[],\n options: {\n testName?: string;\n maxScreenshots?: number;\n screenshotPathByEventHash?: Map<string, string>;\n } = {},\n): EventSummary => {\n const filteredEvents = filterEventsByType(events);\n const eventCounts = createEventCounts(filteredEvents, events.length);\n\n const startUrl =\n filteredEvents.navigationEvents.length > 0\n ? filteredEvents.navigationEvents[0].url || ''\n : '';\n\n const clickDescriptions = filteredEvents.clickEvents\n .map((event) => event.elementDescription)\n .filter((desc): desc is string => Boolean(desc))\n .slice(0, 10);\n\n const inputDescriptions = extractInputDescriptions(\n filteredEvents.inputEvents,\n ).slice(0, 10);\n\n const urls = filteredEvents.navigationEvents\n .map((e) => e.url)\n .filter((url): url is string => Boolean(url))\n .slice(0, 5);\n\n const processedEvents = processEventsForLLM(\n events,\n options.screenshotPathByEventHash,\n );\n\n return {\n testName: options.testName || 'Automated test from recorded events',\n startUrl,\n eventCounts,\n urls,\n clickDescriptions,\n inputDescriptions,\n events: processedEvents,\n };\n};\n\nexport function prepareRecorderGenerationContext(\n input: RecorderGenerationInput,\n): RecorderGenerationContext {\n validateEvents(input.events);\n\n const maxScreenshots =\n input.maxScreenshots ?? DEFAULT_MIDSCENE_RECORDER_MARKDOWN_MAX_SCREENSHOTS;\n const screenshotAssets = createMidsceneRecorderMarkdownScreenshotAssets(\n input.events,\n {\n baseDir: './screenshots',\n maxScreenshots,\n },\n );\n const screenshotPathByEventHash = new Map(\n screenshotAssets.map((asset) => [asset.eventHashId, asset.relativePath]),\n );\n\n return {\n summary: prepareEventSummary(input.events, {\n testName: input.testName,\n screenshotPathByEventHash,\n }),\n screenshotAssets,\n };\n}\n\nexport const createMessageContent = (\n promptText: string,\n screenshots: string[] = [],\n includeScreenshots = true,\n) => {\n const messageContent: any[] = [\n {\n type: 'text',\n text: promptText,\n },\n ];\n\n if (includeScreenshots && screenshots.length > 0) {\n messageContent.unshift({\n type: 'text',\n text: 'Here are screenshots from the recording session to help you understand the context:',\n });\n\n screenshots.forEach((screenshot) => {\n messageContent.push({\n type: 'image_url',\n image_url: {\n url: screenshot,\n },\n });\n });\n }\n\n return messageContent;\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","cleanRecorderSemanticField","value","undefined","validateEvents","events","Error","getScreenshotsForLLM","maxScreenshots","createMidsceneRecorderMarkdownScreenshotAssets","asset","filterEventsByType","event","createEventCounts","filteredEvents","totalEvents","extractInputDescriptions","inputEvents","item","processEventsForLLM","screenshotPathByEventHash","Map","getMidsceneRecorderEventDescription","prepareEventSummary","options","eventCounts","startUrl","clickDescriptions","desc","Boolean","inputDescriptions","urls","e","url","processedEvents","prepareRecorderGenerationContext","input","DEFAULT_MIDSCENE_RECORDER_MARKDOWN_MAX_SCREENSHOTS","screenshotAssets","createMessageContent","promptText","screenshots","includeScreenshots","messageContent","screenshot"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;;;;;ACmFA,SAASI,2BAA2BC,KAAc;IAChD,OAAOA,OAAO,WAAW,+BAA+BC,SAAYD;AACtE;AAEO,MAAME,iBAAiB,CAACC;IAC7B,IAAI,CAACA,OAAO,MAAM,EAChB,MAAM,IAAIC,MAAM;AAEpB;AAEO,MAAMC,uBAAuB,CAClCF,QACAG,iBAAiB,CAAC,GAEXC,AAAAA,IAAAA,yBAAAA,8CAAAA,AAAAA,EAA+CJ,QA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AAM,EACZ;QACE,SAAS;QACT5B;IACF;IAEF,MAAMY,4BAA4B,IAAIC,IACpCiB,iBAAiB,GAAG,CAAC,CAAC5B,QAAU;YAACA,MAAM,WAAW;YAAEA,MAAM,YAAY;SAAC;IAGzE,OAAO;QACL,SAASa,oBAAoBa,MAAM,MAAM,EAAE;YACzC,UAAUA,MAAM,QAAQ;YACxBhB;QACF;QACAkB;IACF;AACF;AAEO,MAAMC,uBAAuB,CAClCC,YACAC,cAAwB,EAAE,EAC1BC,qBAAqB,IAAI;IAEzB,MAAMC,iBAAwB;QAC5B;YACE,MAAM;YACN,MAAMH;QACR;KACD;IAED,IAAIE,sBAAsBD,YAAY,MAAM,GAAG,GAAG;QAChDE,eAAe,OAAO,CAAC;YACrB,MAAM;YACN,MAAM;QACR;QAEAF,YAAY,OAAO,CAAC,CAACG;YACnBD,eAAe,IAAI,CAAC;gBAClB,MAAM;gBACN,WAAW;oBACT,KAAKC;gBACP;YACF;QACF;IACF;IAEA,OAAOD;AACT"}
|
|
1
|
+
{"version":3,"file":"ai-model/prompt/recorder-generation-common.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/ai-model/prompt/recorder-generation-common.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import {\n DEFAULT_MIDSCENE_RECORDER_MARKDOWN_MAX_SCREENSHOTS,\n type MidsceneRecorderEvent,\n type MidsceneRecorderMarkdownScreenshotAsset,\n type MidsceneRecorderSemantic,\n type MidsceneRecorderTarget,\n createMidsceneRecorderMarkdownScreenshotAssets,\n getMidsceneRecorderEventDescription,\n getMidsceneRecorderSemantic,\n} from '@midscene/shared/recorder';\n\nexport interface EventCounts {\n navigation: number;\n click: number;\n input: number;\n scroll: number;\n total: number;\n}\n\nexport interface InputDescription {\n description: string;\n value: string;\n}\n\nexport interface ProcessedEvent {\n hashId: string;\n type: string;\n timestamp: number;\n source?: string;\n actionType?: string;\n url?: string;\n title?: string;\n semantic?: MidsceneRecorderSemantic;\n description?: string;\n value?: string;\n typedText?: string;\n inputIndex?: number;\n isSequentialInput?: boolean;\n hasNeighborInput?: boolean;\n previousInputDescription?: string;\n previousActionDescription?: string;\n nextActionDescription?: string;\n neighborInputValues?: string[];\n pageInfo?: any;\n elementRect?: any;\n screenshotPath?: string;\n}\n\nexport interface EventSummary {\n testName: string;\n startUrl: string;\n eventCounts: EventCounts;\n urls: string[];\n clickDescriptions: string[];\n inputDescriptions: InputDescription[];\n events: ProcessedEvent[];\n}\n\nexport interface RecorderGenerationContext {\n summary: EventSummary;\n screenshotAssets: MidsceneRecorderMarkdownScreenshotAsset[];\n}\n\nexport type ChromeRecordedEvent = MidsceneRecorderEvent;\n\nconst MAX_RECORDER_GENERATION_SEMANTIC_TEXT_LENGTH = 1200;\nconst MAX_RECORDER_GENERATION_SEMANTIC_ERROR_LENGTH = 400;\n\nexport interface RecorderGenerationOptions {\n testName?: string;\n includeTimestamps?: boolean;\n maxScreenshots?: number;\n description?: string;\n /** Language for human-readable generated content (e.g. 'English', 'Chinese'). Keys and API names are kept as-is. */\n language?: string;\n navigationInfo?: {\n urls?: string[];\n titles?: string[];\n initialViewport?: {\n width?: number;\n height?: number;\n };\n };\n}\n\nexport interface RecorderGenerationInput extends RecorderGenerationOptions {\n target: MidsceneRecorderTarget;\n events: MidsceneRecorderEvent[];\n}\n\nexport interface FilteredEvents {\n navigationEvents: ChromeRecordedEvent[];\n clickEvents: ChromeRecordedEvent[];\n inputEvents: ChromeRecordedEvent[];\n scrollEvents: ChromeRecordedEvent[];\n}\n\nfunction cleanRecorderSemanticField(value?: string) {\n return value?.trim() === 'AI is analyzing element...' ? undefined : value;\n}\n\nfunction truncateRecorderGenerationText(value: string, maxLength: number) {\n if (value.length <= maxLength) {\n return value;\n }\n return `${value.slice(0, maxLength)}... [truncated ${value.length - maxLength} chars]`;\n}\n\nfunction compactRecorderSemanticText(value?: string) {\n const cleaned = cleanRecorderSemanticField(value);\n return cleaned\n ? truncateRecorderGenerationText(\n cleaned,\n MAX_RECORDER_GENERATION_SEMANTIC_TEXT_LENGTH,\n )\n : undefined;\n}\n\nfunction compactRecorderSemanticError(value?: string) {\n return value\n ? truncateRecorderGenerationText(\n value,\n MAX_RECORDER_GENERATION_SEMANTIC_ERROR_LENGTH,\n )\n : undefined;\n}\n\nexport function compactRecorderSemanticForGeneration(\n semantic?: MidsceneRecorderSemantic,\n): MidsceneRecorderSemantic | undefined {\n if (!semantic) {\n return undefined;\n }\n\n return {\n source: semantic.source,\n status: semantic.status,\n confidence: semantic.confidence,\n elementDescription: compactRecorderSemanticText(\n semantic.elementDescription,\n ),\n replayInstruction: compactRecorderSemanticText(semantic.replayInstruction),\n actionSummary: compactRecorderSemanticText(semantic.actionSummary),\n error: compactRecorderSemanticError(semantic.error),\n ...(semantic.aiDescribe\n ? {\n aiDescribe: {\n verifyPrompt: semantic.aiDescribe.verifyPrompt,\n verifyPassed: semantic.aiDescribe.verifyPassed,\n deepLocate: semantic.aiDescribe.deepLocate,\n centerDistance: semantic.aiDescribe.centerDistance,\n expectedCenter: semantic.aiDescribe.expectedCenter,\n actualCenter: semantic.aiDescribe.actualCenter,\n },\n }\n : {}),\n };\n}\n\nexport const validateEvents = (events: ChromeRecordedEvent[]): void => {\n if (!events.length) {\n throw new Error('No events provided for test generation');\n }\n};\n\nexport const getScreenshotsForLLM = (\n events: ChromeRecordedEvent[],\n maxScreenshots = 1,\n): string[] => {\n return createMidsceneRecorderMarkdownScreenshotAssets(events, {\n baseDir: './screenshots',\n maxScreenshots,\n }).map((asset) => asset.dataUrl);\n};\n\nexport const filterEventsByType = (\n events: ChromeRecordedEvent[],\n): FilteredEvents => {\n return {\n navigationEvents: events.filter((event) => event.type === 'navigation'),\n clickEvents: events.filter((event) => event.type === 'click'),\n inputEvents: events.filter((event) => event.type === 'input'),\n scrollEvents: events.filter((event) => event.type === 'scroll'),\n };\n};\n\nexport const createEventCounts = (\n filteredEvents: FilteredEvents,\n totalEvents: number,\n): EventCounts => {\n return {\n navigation: filteredEvents.navigationEvents.length,\n click: filteredEvents.clickEvents.length,\n input: filteredEvents.inputEvents.length,\n scroll: filteredEvents.scrollEvents.length,\n total: totalEvents,\n };\n};\n\nexport const extractInputDescriptions = (\n inputEvents: ChromeRecordedEvent[],\n): InputDescription[] => {\n return inputEvents\n .map((event) => {\n const semantic = getMidsceneRecorderSemantic(event);\n return {\n description:\n cleanRecorderSemanticField(semantic?.elementDescription) || '',\n value: event.value || '',\n };\n })\n .filter((item) => item.description && item.value);\n};\n\nexport const processEventsForLLM = (\n events: ChromeRecordedEvent[],\n screenshotPathByEventHash: Map<string, string> = new Map(),\n): ProcessedEvent[] => {\n let inputIndex = 0;\n return events.map((event, index) => {\n const previousEvent = events[index - 1];\n const nextEvent = events[index + 1];\n const previousInput = events\n .slice(0, index)\n .reverse()\n .find((candidate) => candidate.type === 'input');\n const nextInput = events\n .slice(index + 1)\n .find((candidate) => candidate.type === 'input');\n const isInput = event.type === 'input';\n const inputSequenceIndex = isInput ? ++inputIndex : undefined;\n const hasNeighborInput = Boolean(previousInput || nextInput);\n const neighborInputValues = isInput\n ? [previousInput?.value, nextInput?.value].filter(\n (value): value is string => Boolean(value),\n )\n : undefined;\n const semantic = compactRecorderSemanticForGeneration(\n getMidsceneRecorderSemantic(event),\n );\n\n return {\n hashId: event.hashId,\n type: event.type,\n timestamp: event.timestamp,\n source: event.source,\n actionType: event.actionType,\n url: event.url,\n title: event.title,\n semantic,\n description: getMidsceneRecorderEventDescription(event),\n value: event.value,\n previousActionDescription: previousEvent\n ? getMidsceneRecorderEventDescription(previousEvent)\n : undefined,\n nextActionDescription: nextEvent\n ? getMidsceneRecorderEventDescription(nextEvent)\n : undefined,\n ...(isInput\n ? {\n typedText: event.value || '',\n inputIndex: inputSequenceIndex,\n isSequentialInput:\n previousEvent?.type === 'input' || nextEvent?.type === 'input',\n hasNeighborInput,\n previousInputDescription: previousInput\n ? getMidsceneRecorderEventDescription(previousInput)\n : undefined,\n neighborInputValues:\n neighborInputValues && neighborInputValues.length > 0\n ? neighborInputValues\n : undefined,\n }\n : {}),\n pageInfo: event.pageInfo,\n elementRect: event.elementRect,\n screenshotPath: screenshotPathByEventHash.get(event.hashId),\n };\n });\n};\n\nexport const prepareEventSummary = (\n events: ChromeRecordedEvent[],\n options: {\n testName?: string;\n maxScreenshots?: number;\n screenshotPathByEventHash?: Map<string, string>;\n } = {},\n): EventSummary => {\n const filteredEvents = filterEventsByType(events);\n const eventCounts = createEventCounts(filteredEvents, events.length);\n\n const startUrl =\n filteredEvents.navigationEvents.length > 0\n ? filteredEvents.navigationEvents[0].url || ''\n : '';\n\n const clickDescriptions = filteredEvents.clickEvents\n .map((event) => getMidsceneRecorderSemantic(event)?.elementDescription)\n .filter((desc): desc is string => Boolean(desc))\n .slice(0, 10);\n\n const inputDescriptions = extractInputDescriptions(\n filteredEvents.inputEvents,\n ).slice(0, 10);\n\n const urls = filteredEvents.navigationEvents\n .map((e) => e.url)\n .filter((url): url is string => Boolean(url))\n .slice(0, 5);\n\n const processedEvents = processEventsForLLM(\n events,\n options.screenshotPathByEventHash,\n );\n\n return {\n testName: options.testName || 'Automated test from recorded events',\n startUrl,\n eventCounts,\n urls,\n clickDescriptions,\n inputDescriptions,\n events: processedEvents,\n };\n};\n\nexport function prepareRecorderGenerationContext(\n input: RecorderGenerationInput,\n): RecorderGenerationContext {\n validateEvents(input.events);\n\n const maxScreenshots =\n input.maxScreenshots ?? DEFAULT_MIDSCENE_RECORDER_MARKDOWN_MAX_SCREENSHOTS;\n const screenshotAssets = createMidsceneRecorderMarkdownScreenshotAssets(\n input.events,\n {\n baseDir: './screenshots',\n maxScreenshots,\n },\n );\n const screenshotPathByEventHash = new Map(\n screenshotAssets.map((asset) => [asset.eventHashId, asset.relativePath]),\n );\n\n return {\n summary: prepareEventSummary(input.events, {\n testName: input.testName,\n screenshotPathByEventHash,\n }),\n screenshotAssets,\n };\n}\n\nexport const createMessageContent = (\n promptText: string,\n screenshots: string[] = [],\n includeScreenshots = true,\n) => {\n const messageContent: any[] = [\n {\n type: 'text',\n text: promptText,\n },\n ];\n\n if (includeScreenshots && screenshots.length > 0) {\n messageContent.unshift({\n type: 'text',\n text: 'Here are screenshots from the recording session to help you understand the context:',\n });\n\n screenshots.forEach((screenshot) => {\n messageContent.push({\n type: 'image_url',\n image_url: {\n url: screenshot,\n },\n });\n });\n }\n\n return messageContent;\n};\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","MAX_RECORDER_GENERATION_SEMANTIC_TEXT_LENGTH","MAX_RECORDER_GENERATION_SEMANTIC_ERROR_LENGTH","cleanRecorderSemanticField","value","undefined","truncateRecorderGenerationText","maxLength","compactRecorderSemanticText","cleaned","compactRecorderSemanticError","compactRecorderSemanticForGeneration","semantic","validateEvents","events","Error","getScreenshotsForLLM","maxScreenshots","createMidsceneRecorderMarkdownScreenshotAssets","asset","filterEventsByType","event","createEventCounts","filteredEvents","totalEvents","extractInputDescriptions","inputEvents","getMidsceneRecorderSemantic","item","processEventsForLLM","screenshotPathByEventHash","Map","inputIndex","index","previousEvent","nextEvent","previousInput","candidate","nextInput","isInput","inputSequenceIndex","hasNeighborInput","Boolean","neighborInputValues","getMidsceneRecorderEventDescription","prepareEventSummary","options","eventCounts","startUrl","clickDescriptions","desc","inputDescriptions","urls","e","url","processedEvents","prepareRecorderGenerationContext","input","DEFAULT_MIDSCENE_RECORDER_MARKDOWN_MAX_SCREENSHOTS","screenshotAssets","createMessageContent","promptText","screenshots","includeScreenshots","messageContent","screenshot"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;;;;;;;;AC2DA,MAAMI,+CAA+C;AACrD,MAAMC,gDAAgD;AA+BtD,SAASC,2BAA2BC,KAAc;IAChD,OAAOA,OAAO,WAAW,+BAA+BC,SAAYD;AACtE;AAEA,SAASE,+BAA+BF,KAAa,EAAEG,SAAiB;IACtE,IAAIH,MAAM,MAAM,IAAIG,WAClB,OAAOH;IAET,OAAO,GAAGA,MAAM,KAAK,CAAC,GAAGG,WAAW,eAAe,EAAEH,MAAM,MAAM,GAAGG,UAAU,OAAO,CAAC;AACxF;AAEA,SAASC,4BAA4BJ,KAAc;IACjD,MAAMK,UAAUN,2BAA2BC;IAC3C,OAAOK,UACHH,+BACEG,SACAR,gDAEFI;AACN;AAEA,SAASK,6BAA6BN,KAAc;IAClD,OAAOA,QACHE,+BACEF,OACAF,iDAEFG;AACN;AAEO,SAASM,qCACdC,QAAmC;IAEnC,IAAI,CAACA,UACH;IAGF,OAAO;QACL,QAAQA,SAAS,MAAM;QACvB,QAAQA,SAA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|
29
29
|
const recorder_namespaceObject = require("@midscene/shared/recorder");
|
|
30
30
|
const index_js_namespaceObject = require("../service-caller/index.js");
|
|
31
|
+
const external_recorder_generation_common_js_namespaceObject = require("./recorder-generation-common.js");
|
|
31
32
|
function summarizeRecorderEvents(input) {
|
|
32
33
|
const events = input.events;
|
|
33
34
|
const navigationEvents = events.filter((event)=>'navigation' === event.type);
|
|
@@ -56,10 +57,7 @@ function summarizeRecorderEvents(input) {
|
|
|
56
57
|
title: event.title,
|
|
57
58
|
value: event.value,
|
|
58
59
|
description: (0, recorder_namespaceObject.getMidsceneRecorderEventDescription)(event),
|
|
59
|
-
|
|
60
|
-
replayInstruction: event.replayInstruction,
|
|
61
|
-
actionSummary: event.actionSummary,
|
|
62
|
-
semanticConfidence: event.semanticConfidence
|
|
60
|
+
semantic: (0, external_recorder_generation_common_js_namespaceObject.compactRecorderSemanticForGeneration)((0, recorder_namespaceObject.getMidsceneRecorderSemantic)(event))
|
|
63
61
|
}))
|
|
64
62
|
};
|
|
65
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-model/prompt/recorder-metadata-generator.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/ai-model/prompt/recorder-metadata-generator.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { IModelConfig } from '@midscene/shared/env';\nimport {\n type MidsceneRecorderEvent,\n type MidsceneRecorderTarget,\n getMidsceneRecorderEventDescription,\n getMidsceneRecorderScreenshotsForLLM,\n} from '@midscene/shared/recorder';\nimport { callAIWithObjectResponse } from '../service-caller/index';\n\nexport interface RecorderMetadataGenerationInput {\n target: MidsceneRecorderTarget;\n events: MidsceneRecorderEvent[];\n fallbackName?: string;\n maxScreenshots?: number;\n}\n\nexport interface RecorderGeneratedMetadata {\n title?: string;\n description?: string;\n}\n\nfunction summarizeRecorderEvents(input: RecorderMetadataGenerationInput) {\n const events = input.events;\n const navigationEvents = events.filter(\n (event) => event.type === 'navigation',\n );\n const clickEvents = events.filter((event) => event.type === 'click');\n const inputEvents = events.filter((event) => event.type === 'input');\n const scrollEvents = events.filter((event) => event.type === 'scroll');\n const urls = navigationEvents\n .map((event) => event.url)\n .filter((url): url is string => Boolean(url));\n const titles = navigationEvents\n .map((event) => event.title)\n .filter((title): title is string => Boolean(title));\n\n return {\n platform: input.target.platformId,\n target: input.target,\n fallbackName: input.fallbackName,\n pageCount: navigationEvents.length,\n pageTitles: titles.slice(0, 5),\n urls: urls.slice(0, 5),\n clickCount: clickEvents.length,\n inputCount: inputEvents.length,\n scrollCount: scrollEvents.length,\n totalActions: events.length,\n firstUrl: urls[0] || input.target.values.url || '',\n lastUrl: urls[urls.length - 1] || '',\n events: events.slice(0, 20).map((event) => ({\n type: event.type,\n actionType: event.actionType,\n url: event.url,\n title: event.title,\n value: event.value,\n description: getMidsceneRecorderEventDescription(event),\n
|
|
1
|
+
{"version":3,"file":"ai-model/prompt/recorder-metadata-generator.js","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../../../src/ai-model/prompt/recorder-metadata-generator.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { IModelConfig } from '@midscene/shared/env';\nimport {\n type MidsceneRecorderEvent,\n type MidsceneRecorderTarget,\n getMidsceneRecorderEventDescription,\n getMidsceneRecorderScreenshotsForLLM,\n getMidsceneRecorderSemantic,\n} from '@midscene/shared/recorder';\nimport { callAIWithObjectResponse } from '../service-caller/index';\nimport { compactRecorderSemanticForGeneration } from './recorder-generation-common';\n\nexport interface RecorderMetadataGenerationInput {\n target: MidsceneRecorderTarget;\n events: MidsceneRecorderEvent[];\n fallbackName?: string;\n maxScreenshots?: number;\n}\n\nexport interface RecorderGeneratedMetadata {\n title?: string;\n description?: string;\n}\n\nfunction summarizeRecorderEvents(input: RecorderMetadataGenerationInput) {\n const events = input.events;\n const navigationEvents = events.filter(\n (event) => event.type === 'navigation',\n );\n const clickEvents = events.filter((event) => event.type === 'click');\n const inputEvents = events.filter((event) => event.type === 'input');\n const scrollEvents = events.filter((event) => event.type === 'scroll');\n const urls = navigationEvents\n .map((event) => event.url)\n .filter((url): url is string => Boolean(url));\n const titles = navigationEvents\n .map((event) => event.title)\n .filter((title): title is string => Boolean(title));\n\n return {\n platform: input.target.platformId,\n target: input.target,\n fallbackName: input.fallbackName,\n pageCount: navigationEvents.length,\n pageTitles: titles.slice(0, 5),\n urls: urls.slice(0, 5),\n clickCount: clickEvents.length,\n inputCount: inputEvents.length,\n scrollCount: scrollEvents.length,\n totalActions: events.length,\n firstUrl: urls[0] || input.target.values.url || '',\n lastUrl: urls[urls.length - 1] || '',\n events: events.slice(0, 20).map((event) => ({\n type: event.type,\n actionType: event.actionType,\n url: event.url,\n title: event.title,\n value: event.value,\n description: getMidsceneRecorderEventDescription(event),\n semantic: compactRecorderSemanticForGeneration(\n getMidsceneRecorderSemantic(event),\n ),\n })),\n };\n}\n\nfunction normalizeMetadataValue(value: unknown) {\n return typeof value === 'string' ? value.trim() : '';\n}\n\nexport async function generateRecorderSessionMetadata(\n input: RecorderMetadataGenerationInput,\n modelConfig: IModelConfig,\n): Promise<RecorderGeneratedMetadata> {\n if (!input?.events?.length) {\n throw new Error('generateRecorderSessionMetadata: events are required.');\n }\n if (!modelConfig?.modelName) {\n throw new Error(\n 'generateRecorderSessionMetadata: modelConfig.modelName is required.',\n );\n }\n\n const summary = summarizeRecorderEvents(input);\n const screenshots = getMidsceneRecorderScreenshotsForLLM(\n input.events,\n input.maxScreenshots ?? 1,\n );\n const messageContent: any[] = [\n {\n type: 'text',\n text: `Generate a concise title (5-7 words) and brief description (1-2 sentences) for a Studio recording of user actions.\n\nThe recording can target Web, Android, iOS, HarmonyOS, or Computer. Do not assume it is a browser session unless the platform is web.\nDescribe what the user did or accomplished. The description should use the user as the subject, preferably starting with \"The user ...\". Do not start the description with \"The session ...\".\nThe title should be action-oriented and highlight the main task accomplished.\n\nSummary:\n${JSON.stringify(summary, null, 2)}\n\nRespond with a JSON object containing exactly \"title\" and \"description\".`,\n },\n ];\n\n for (const screenshot of screenshots) {\n messageContent.push({\n type: 'image_url',\n image_url: { url: screenshot },\n });\n }\n\n const response = await callAIWithObjectResponse<{\n title?: string;\n description?: string;\n }>(\n [\n {\n role: 'system',\n content:\n 'You generate clear, task-oriented titles and descriptions for recorded automation sessions.',\n },\n {\n role: 'user',\n content: messageContent,\n },\n ],\n modelConfig,\n );\n\n return {\n title: normalizeMetadataValue(response.content.title),\n description: normalizeMetadataValue(response.content.description),\n };\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","summarizeRecorderEvents","input","events","navigationEvents","event","clickEvents","inputEvents","scrollEvents","urls","url","Boolean","titles","title","getMidsceneRecorderEventDescription","compactRecorderSemanticForGeneration","getMidsceneRecorderSemantic","normalizeMetadataValue","value","generateRecorderSessionMetadata","modelConfig","Error","summary","screenshots","getMidsceneRecorderScreenshotsForLLM","messageContent","JSON","screenshot","response","callAIWithObjectResponse"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;;ACiBA,SAASI,wBAAwBC,KAAsC;IACrE,MAAMC,SAASD,MAAM,MAAM;IAC3B,MAAME,mBAAmBD,OAAO,MAAM,CACpC,CAACE,QAAUA,AAAe,iBAAfA,MAAM,IAAI;IAEvB,MAAMC,cAAcH,OAAO,MAAM,CAAC,CAACE,QAAUA,AAAe,YAAfA,MAAM,IAAI;IACvD,MAAME,cAAcJ,OAAO,MAAM,CAAC,CAACE,QAAUA,AAAe,YAAfA,MAAM,IAAI;IACvD,MAAMG,eAAeL,OAAO,MAAM,CAAC,CAACE,QAAUA,AAAe,aAAfA,MAAM,IAAI;IACxD,MAAMI,OAAOL,iBACV,GAAG,CAAC,CAACC,QAAUA,MAAM,GAAG,EACxB,MAAM,CAAC,CAACK,MAAuBC,QAAQD;IAC1C,MAAME,SAASR,iBACZ,GAAG,CAAC,CAACC,QAAUA,MAAM,KAAK,EAC1B,MAAM,CAAC,CAACQ,QAA2BF,QAAQE;IAE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