@godscene/core 1.7.11
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/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/es/agent/agent.mjs +767 -0
- package/dist/es/agent/common.mjs +0 -0
- package/dist/es/agent/execution-session.mjs +39 -0
- package/dist/es/agent/index.mjs +6 -0
- package/dist/es/agent/task-builder.mjs +343 -0
- package/dist/es/agent/task-cache.mjs +212 -0
- package/dist/es/agent/tasks.mjs +428 -0
- package/dist/es/agent/ui-utils.mjs +101 -0
- package/dist/es/agent/utils.mjs +167 -0
- package/dist/es/ai-model/auto-glm/actions.mjs +237 -0
- package/dist/es/ai-model/auto-glm/index.mjs +6 -0
- package/dist/es/ai-model/auto-glm/parser.mjs +237 -0
- package/dist/es/ai-model/auto-glm/planning.mjs +69 -0
- package/dist/es/ai-model/auto-glm/prompt.mjs +220 -0
- package/dist/es/ai-model/auto-glm/util.mjs +7 -0
- package/dist/es/ai-model/connectivity.mjs +136 -0
- package/dist/es/ai-model/conversation-history.mjs +193 -0
- package/dist/es/ai-model/index.mjs +12 -0
- package/dist/es/ai-model/inspect.mjs +395 -0
- package/dist/es/ai-model/llm-planning.mjs +231 -0
- package/dist/es/ai-model/prompt/common.mjs +5 -0
- package/dist/es/ai-model/prompt/describe.mjs +64 -0
- package/dist/es/ai-model/prompt/extraction.mjs +129 -0
- package/dist/es/ai-model/prompt/llm-locator.mjs +49 -0
- package/dist/es/ai-model/prompt/llm-planning.mjs +584 -0
- package/dist/es/ai-model/prompt/llm-section-locator.mjs +42 -0
- package/dist/es/ai-model/prompt/order-sensitive-judge.mjs +33 -0
- package/dist/es/ai-model/prompt/playwright-generator.mjs +115 -0
- package/dist/es/ai-model/prompt/ui-tars-planning.mjs +34 -0
- package/dist/es/ai-model/prompt/util.mjs +57 -0
- package/dist/es/ai-model/prompt/yaml-generator.mjs +201 -0
- package/dist/es/ai-model/service-caller/codex-app-server.mjs +573 -0
- package/dist/es/ai-model/service-caller/image-detail.mjs +4 -0
- package/dist/es/ai-model/service-caller/index.mjs +648 -0
- package/dist/es/ai-model/service-caller/request-timeout.mjs +47 -0
- package/dist/es/ai-model/ui-tars-planning.mjs +247 -0
- package/dist/es/common.mjs +382 -0
- package/dist/es/device/device-options.mjs +0 -0
- package/dist/es/device/index.mjs +340 -0
- package/dist/es/dump/html-utils.mjs +290 -0
- package/dist/es/dump/index.mjs +3 -0
- package/dist/es/dump/screenshot-restoration.mjs +30 -0
- package/dist/es/dump/screenshot-store.mjs +125 -0
- package/dist/es/index.mjs +17 -0
- package/dist/es/report-cli.mjs +149 -0
- package/dist/es/report-generator.mjs +203 -0
- package/dist/es/report-markdown.mjs +216 -0
- package/dist/es/report.mjs +287 -0
- package/dist/es/screenshot-item.mjs +120 -0
- package/dist/es/service/index.mjs +272 -0
- package/dist/es/service/utils.mjs +13 -0
- package/dist/es/skill/index.mjs +35 -0
- package/dist/es/task-runner.mjs +261 -0
- package/dist/es/task-timing.mjs +10 -0
- package/dist/es/tree.mjs +11 -0
- package/dist/es/types.mjs +202 -0
- package/dist/es/utils.mjs +232 -0
- package/dist/es/yaml/builder.mjs +11 -0
- package/dist/es/yaml/index.mjs +4 -0
- package/dist/es/yaml/player.mjs +425 -0
- package/dist/es/yaml/utils.mjs +100 -0
- package/dist/es/yaml.mjs +0 -0
- package/dist/lib/agent/agent.js +815 -0
- package/dist/lib/agent/common.js +5 -0
- package/dist/lib/agent/execution-session.js +73 -0
- package/dist/lib/agent/index.js +76 -0
- package/dist/lib/agent/task-builder.js +380 -0
- package/dist/lib/agent/task-cache.js +264 -0
- package/dist/lib/agent/tasks.js +471 -0
- package/dist/lib/agent/ui-utils.js +153 -0
- package/dist/lib/agent/utils.js +238 -0
- package/dist/lib/ai-model/auto-glm/actions.js +271 -0
- package/dist/lib/ai-model/auto-glm/index.js +64 -0
- package/dist/lib/ai-model/auto-glm/parser.js +280 -0
- package/dist/lib/ai-model/auto-glm/planning.js +103 -0
- package/dist/lib/ai-model/auto-glm/prompt.js +257 -0
- package/dist/lib/ai-model/auto-glm/util.js +44 -0
- package/dist/lib/ai-model/connectivity.js +180 -0
- package/dist/lib/ai-model/conversation-history.js +227 -0
- package/dist/lib/ai-model/index.js +127 -0
- package/dist/lib/ai-model/inspect.js +441 -0
- package/dist/lib/ai-model/llm-planning.js +268 -0
- package/dist/lib/ai-model/prompt/common.js +39 -0
- package/dist/lib/ai-model/prompt/describe.js +98 -0
- package/dist/lib/ai-model/prompt/extraction.js +169 -0
- package/dist/lib/ai-model/prompt/llm-locator.js +86 -0
- package/dist/lib/ai-model/prompt/llm-planning.js +621 -0
- package/dist/lib/ai-model/prompt/llm-section-locator.js +79 -0
- package/dist/lib/ai-model/prompt/order-sensitive-judge.js +70 -0
- package/dist/lib/ai-model/prompt/playwright-generator.js +176 -0
- package/dist/lib/ai-model/prompt/ui-tars-planning.js +71 -0
- package/dist/lib/ai-model/prompt/util.js +103 -0
- package/dist/lib/ai-model/prompt/yaml-generator.js +262 -0
- package/dist/lib/ai-model/service-caller/codex-app-server.js +622 -0
- package/dist/lib/ai-model/service-caller/image-detail.js +38 -0
- package/dist/lib/ai-model/service-caller/index.js +716 -0
- package/dist/lib/ai-model/service-caller/request-timeout.js +93 -0
- package/dist/lib/ai-model/ui-tars-planning.js +281 -0
- package/dist/lib/common.js +491 -0
- package/dist/lib/device/device-options.js +18 -0
- package/dist/lib/device/index.js +467 -0
- package/dist/lib/dump/html-utils.js +366 -0
- package/dist/lib/dump/index.js +58 -0
- package/dist/lib/dump/screenshot-restoration.js +64 -0
- package/dist/lib/dump/screenshot-store.js +165 -0
- package/dist/lib/index.js +184 -0
- package/dist/lib/report-cli.js +189 -0
- package/dist/lib/report-generator.js +244 -0
- package/dist/lib/report-markdown.js +253 -0
- package/dist/lib/report.js +333 -0
- package/dist/lib/screenshot-item.js +154 -0
- package/dist/lib/service/index.js +306 -0
- package/dist/lib/service/utils.js +47 -0
- package/dist/lib/skill/index.js +69 -0
- package/dist/lib/task-runner.js +298 -0
- package/dist/lib/task-timing.js +44 -0
- package/dist/lib/tree.js +51 -0
- package/dist/lib/types.js +298 -0
- package/dist/lib/utils.js +314 -0
- package/dist/lib/yaml/builder.js +55 -0
- package/dist/lib/yaml/index.js +79 -0
- package/dist/lib/yaml/player.js +459 -0
- package/dist/lib/yaml/utils.js +153 -0
- package/dist/lib/yaml.js +18 -0
- package/dist/types/agent/agent.d.ts +220 -0
- package/dist/types/agent/common.d.ts +0 -0
- package/dist/types/agent/execution-session.d.ts +36 -0
- package/dist/types/agent/index.d.ts +9 -0
- package/dist/types/agent/task-builder.d.ts +34 -0
- package/dist/types/agent/task-cache.d.ts +49 -0
- package/dist/types/agent/tasks.d.ts +70 -0
- package/dist/types/agent/ui-utils.d.ts +14 -0
- package/dist/types/agent/utils.d.ts +25 -0
- package/dist/types/ai-model/auto-glm/actions.d.ts +78 -0
- package/dist/types/ai-model/auto-glm/index.d.ts +6 -0
- package/dist/types/ai-model/auto-glm/parser.d.ts +18 -0
- package/dist/types/ai-model/auto-glm/planning.d.ts +12 -0
- package/dist/types/ai-model/auto-glm/prompt.d.ts +27 -0
- package/dist/types/ai-model/auto-glm/util.d.ts +13 -0
- package/dist/types/ai-model/connectivity.d.ts +20 -0
- package/dist/types/ai-model/conversation-history.d.ts +105 -0
- package/dist/types/ai-model/index.d.ts +16 -0
- package/dist/types/ai-model/inspect.d.ts +67 -0
- package/dist/types/ai-model/llm-planning.d.ts +19 -0
- package/dist/types/ai-model/prompt/common.d.ts +2 -0
- package/dist/types/ai-model/prompt/describe.d.ts +1 -0
- package/dist/types/ai-model/prompt/extraction.d.ts +7 -0
- package/dist/types/ai-model/prompt/llm-locator.d.ts +3 -0
- package/dist/types/ai-model/prompt/llm-planning.d.ts +10 -0
- package/dist/types/ai-model/prompt/llm-section-locator.d.ts +3 -0
- package/dist/types/ai-model/prompt/order-sensitive-judge.d.ts +2 -0
- package/dist/types/ai-model/prompt/playwright-generator.d.ts +26 -0
- package/dist/types/ai-model/prompt/ui-tars-planning.d.ts +2 -0
- package/dist/types/ai-model/prompt/util.d.ts +33 -0
- package/dist/types/ai-model/prompt/yaml-generator.d.ts +102 -0
- package/dist/types/ai-model/service-caller/codex-app-server.d.ts +42 -0
- package/dist/types/ai-model/service-caller/image-detail.d.ts +2 -0
- package/dist/types/ai-model/service-caller/index.d.ts +60 -0
- package/dist/types/ai-model/service-caller/request-timeout.d.ts +32 -0
- package/dist/types/ai-model/ui-tars-planning.d.ts +72 -0
- package/dist/types/common.d.ts +288 -0
- package/dist/types/device/device-options.d.ts +155 -0
- package/dist/types/device/index.d.ts +2565 -0
- package/dist/types/dump/html-utils.d.ts +75 -0
- package/dist/types/dump/index.d.ts +5 -0
- package/dist/types/dump/screenshot-restoration.d.ts +8 -0
- package/dist/types/dump/screenshot-store.d.ts +49 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/report-cli.d.ts +36 -0
- package/dist/types/report-generator.d.ts +88 -0
- package/dist/types/report-markdown.d.ts +24 -0
- package/dist/types/report.d.ts +52 -0
- package/dist/types/screenshot-item.d.ts +67 -0
- package/dist/types/service/index.d.ts +24 -0
- package/dist/types/service/utils.d.ts +2 -0
- package/dist/types/skill/index.d.ts +25 -0
- package/dist/types/task-runner.d.ts +50 -0
- package/dist/types/task-timing.d.ts +8 -0
- package/dist/types/tree.d.ts +4 -0
- package/dist/types/types.d.ts +684 -0
- package/dist/types/utils.d.ts +45 -0
- package/dist/types/yaml/builder.d.ts +2 -0
- package/dist/types/yaml/index.d.ts +4 -0
- package/dist/types/yaml/player.d.ts +34 -0
- package/dist/types/yaml/utils.d.ts +9 -0
- package/dist/types/yaml.d.ts +215 -0
- package/package.json +130 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"node:fs" (module) {
|
|
4
|
+
module.exports = require("node:fs");
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
var __webpack_module_cache__ = {};
|
|
8
|
+
function __webpack_require__(moduleId) {
|
|
9
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
10
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
11
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
12
|
+
exports: {}
|
|
13
|
+
};
|
|
14
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
15
|
+
return module.exports;
|
|
16
|
+
}
|
|
17
|
+
(()=>{
|
|
18
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
19
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: definition[key]
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
})();
|
|
25
|
+
(()=>{
|
|
26
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
27
|
+
})();
|
|
28
|
+
(()=>{
|
|
29
|
+
__webpack_require__.r = (exports1)=>{
|
|
30
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
31
|
+
value: 'Module'
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
34
|
+
value: true
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
var __webpack_exports__ = {};
|
|
39
|
+
(()=>{
|
|
40
|
+
__webpack_require__.r(__webpack_exports__);
|
|
41
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
42
|
+
generateImageScriptTag: ()=>generateImageScriptTag,
|
|
43
|
+
getBaseUrlFixScript: ()=>getBaseUrlFixScript,
|
|
44
|
+
parseDumpScriptAttributes: ()=>parseDumpScriptAttributes,
|
|
45
|
+
extractImageByIdSync: ()=>extractImageByIdSync,
|
|
46
|
+
streamDumpScriptsSync: ()=>streamDumpScriptsSync,
|
|
47
|
+
escapeContent: ()=>escapeContent,
|
|
48
|
+
generateDumpScriptTag: ()=>generateDumpScriptTag,
|
|
49
|
+
STREAMING_CHUNK_SIZE: ()=>STREAMING_CHUNK_SIZE,
|
|
50
|
+
extractLastDumpScriptSync: ()=>extractLastDumpScriptSync,
|
|
51
|
+
parseDumpScript: ()=>parseDumpScript,
|
|
52
|
+
streamImageScriptsToFile: ()=>streamImageScriptsToFile,
|
|
53
|
+
streamScanTags: ()=>streamScanTags,
|
|
54
|
+
parseImageScripts: ()=>parseImageScripts,
|
|
55
|
+
extractAllDumpScriptsSync: ()=>extractAllDumpScriptsSync,
|
|
56
|
+
unescapeContent: ()=>unescapeContent
|
|
57
|
+
});
|
|
58
|
+
var external_node_fs_ = __webpack_require__("node:fs");
|
|
59
|
+
const utils_namespaceObject = require("@godscene/shared/utils");
|
|
60
|
+
const escapeContent = utils_namespaceObject.escapeScriptTag;
|
|
61
|
+
const unescapeContent = utils_namespaceObject.antiEscapeScriptTag;
|
|
62
|
+
const STREAMING_CHUNK_SIZE = 65536;
|
|
63
|
+
function streamScanTags(filePath, openTag, closeTag, onMatch) {
|
|
64
|
+
const fd = (0, external_node_fs_.openSync)(filePath, 'r');
|
|
65
|
+
const fileSize = (0, external_node_fs_.statSync)(filePath).size;
|
|
66
|
+
const buffer = Buffer.alloc(STREAMING_CHUNK_SIZE);
|
|
67
|
+
let position = 0;
|
|
68
|
+
let leftover = '';
|
|
69
|
+
let capturing = false;
|
|
70
|
+
let currentContent = '';
|
|
71
|
+
try {
|
|
72
|
+
while(position < fileSize){
|
|
73
|
+
const bytesRead = (0, external_node_fs_.readSync)(fd, buffer, 0, STREAMING_CHUNK_SIZE, position);
|
|
74
|
+
const chunk = leftover + buffer.toString('utf-8', 0, bytesRead);
|
|
75
|
+
position += bytesRead;
|
|
76
|
+
let searchStart = 0;
|
|
77
|
+
while(searchStart < chunk.length)if (capturing) {
|
|
78
|
+
const endIdx = chunk.indexOf(closeTag, searchStart);
|
|
79
|
+
if (-1 !== endIdx) {
|
|
80
|
+
currentContent += chunk.slice(searchStart, endIdx);
|
|
81
|
+
const shouldStop = onMatch(currentContent);
|
|
82
|
+
if (shouldStop) return;
|
|
83
|
+
capturing = false;
|
|
84
|
+
currentContent = '';
|
|
85
|
+
searchStart = endIdx + closeTag.length;
|
|
86
|
+
} else {
|
|
87
|
+
currentContent += chunk.slice(searchStart, -closeTag.length);
|
|
88
|
+
leftover = chunk.slice(-closeTag.length);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
const startIdx = chunk.indexOf(openTag, searchStart);
|
|
93
|
+
if (-1 !== startIdx) {
|
|
94
|
+
capturing = true;
|
|
95
|
+
currentContent = chunk.slice(startIdx + openTag.length);
|
|
96
|
+
const endIdx = currentContent.indexOf(closeTag);
|
|
97
|
+
if (-1 !== endIdx) {
|
|
98
|
+
const shouldStop = onMatch(currentContent.slice(0, endIdx));
|
|
99
|
+
if (shouldStop) return;
|
|
100
|
+
capturing = false;
|
|
101
|
+
currentContent = '';
|
|
102
|
+
searchStart = startIdx + openTag.length + endIdx + closeTag.length;
|
|
103
|
+
} else {
|
|
104
|
+
leftover = currentContent.slice(-closeTag.length);
|
|
105
|
+
currentContent = currentContent.slice(0, -closeTag.length);
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
leftover = chunk.slice(-openTag.length);
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
} finally{
|
|
115
|
+
(0, external_node_fs_.closeSync)(fd);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function extractImageByIdSync(htmlPath, imageId) {
|
|
119
|
+
const targetTag = `<script type="midscene-image" data-id="${imageId}">`;
|
|
120
|
+
const closeTag = "<\/script>";
|
|
121
|
+
let result = null;
|
|
122
|
+
streamScanTags(htmlPath, targetTag, closeTag, (content)=>{
|
|
123
|
+
result = unescapeContent(content);
|
|
124
|
+
return true;
|
|
125
|
+
});
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
function streamImageScriptsToFile(srcFilePath, destFilePath) {
|
|
129
|
+
const { appendFileSync } = __webpack_require__("node:fs");
|
|
130
|
+
const openTag = '<script type="midscene-image"';
|
|
131
|
+
const closeTag = "<\/script>";
|
|
132
|
+
streamScanTags(srcFilePath, openTag, closeTag, (content)=>{
|
|
133
|
+
appendFileSync(destFilePath, `${openTag}${content}${closeTag}\n`);
|
|
134
|
+
return false;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function extractLastDumpScriptSync(filePath) {
|
|
138
|
+
const openTagPrefix = '<script type="midscene_web_dump"';
|
|
139
|
+
const closeTag = "<\/script>";
|
|
140
|
+
let lastContent = '';
|
|
141
|
+
const fd = (0, external_node_fs_.openSync)(filePath, 'r');
|
|
142
|
+
const fileSize = (0, external_node_fs_.statSync)(filePath).size;
|
|
143
|
+
const buffer = Buffer.alloc(STREAMING_CHUNK_SIZE);
|
|
144
|
+
let position = 0;
|
|
145
|
+
let leftover = '';
|
|
146
|
+
let capturing = false;
|
|
147
|
+
let currentContent = '';
|
|
148
|
+
try {
|
|
149
|
+
while(position < fileSize){
|
|
150
|
+
const bytesRead = (0, external_node_fs_.readSync)(fd, buffer, 0, STREAMING_CHUNK_SIZE, position);
|
|
151
|
+
const chunk = leftover + buffer.toString('utf-8', 0, bytesRead);
|
|
152
|
+
position += bytesRead;
|
|
153
|
+
let searchStart = 0;
|
|
154
|
+
while(searchStart < chunk.length)if (capturing) {
|
|
155
|
+
const endIdx = chunk.indexOf(closeTag, searchStart);
|
|
156
|
+
if (-1 !== endIdx) {
|
|
157
|
+
currentContent += chunk.slice(searchStart, endIdx);
|
|
158
|
+
lastContent = currentContent.trim();
|
|
159
|
+
capturing = false;
|
|
160
|
+
currentContent = '';
|
|
161
|
+
searchStart = endIdx + closeTag.length;
|
|
162
|
+
} else {
|
|
163
|
+
currentContent += chunk.slice(searchStart, -closeTag.length);
|
|
164
|
+
leftover = chunk.slice(-closeTag.length);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
const startIdx = chunk.indexOf(openTagPrefix, searchStart);
|
|
169
|
+
if (-1 !== startIdx) {
|
|
170
|
+
const tagEndIdx = chunk.indexOf('>', startIdx);
|
|
171
|
+
if (-1 !== tagEndIdx) {
|
|
172
|
+
capturing = true;
|
|
173
|
+
currentContent = chunk.slice(tagEndIdx + 1);
|
|
174
|
+
const endIdx = currentContent.indexOf(closeTag);
|
|
175
|
+
if (-1 !== endIdx) {
|
|
176
|
+
lastContent = currentContent.slice(0, endIdx).trim();
|
|
177
|
+
capturing = false;
|
|
178
|
+
currentContent = '';
|
|
179
|
+
searchStart = tagEndIdx + 1 + endIdx + closeTag.length;
|
|
180
|
+
} else {
|
|
181
|
+
leftover = currentContent.slice(-closeTag.length);
|
|
182
|
+
currentContent = currentContent.slice(0, -closeTag.length);
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
leftover = chunk.slice(startIdx);
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
leftover = chunk.slice(-openTagPrefix.length);
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
} finally{
|
|
196
|
+
(0, external_node_fs_.closeSync)(fd);
|
|
197
|
+
}
|
|
198
|
+
return lastContent;
|
|
199
|
+
}
|
|
200
|
+
function extractAllDumpScriptsSync(filePath) {
|
|
201
|
+
const results = [];
|
|
202
|
+
streamDumpScriptsSync(filePath, (dumpScript)=>{
|
|
203
|
+
results.push(dumpScript);
|
|
204
|
+
return false;
|
|
205
|
+
});
|
|
206
|
+
return results;
|
|
207
|
+
}
|
|
208
|
+
function streamDumpScriptsSync(filePath, onMatch) {
|
|
209
|
+
const openTagPrefix = '<script type="midscene_web_dump"';
|
|
210
|
+
const closeTag = "<\/script>";
|
|
211
|
+
const fd = (0, external_node_fs_.openSync)(filePath, 'r');
|
|
212
|
+
const fileSize = (0, external_node_fs_.statSync)(filePath).size;
|
|
213
|
+
const buffer = Buffer.alloc(STREAMING_CHUNK_SIZE);
|
|
214
|
+
let position = 0;
|
|
215
|
+
let leftover = '';
|
|
216
|
+
let capturing = false;
|
|
217
|
+
let currentContent = '';
|
|
218
|
+
let currentOpenTag = '';
|
|
219
|
+
try {
|
|
220
|
+
while(position < fileSize){
|
|
221
|
+
const bytesRead = (0, external_node_fs_.readSync)(fd, buffer, 0, STREAMING_CHUNK_SIZE, position);
|
|
222
|
+
const chunk = leftover + buffer.toString('utf-8', 0, bytesRead);
|
|
223
|
+
position += bytesRead;
|
|
224
|
+
let searchStart = 0;
|
|
225
|
+
while(searchStart < chunk.length)if (capturing) {
|
|
226
|
+
const endIdx = chunk.indexOf(closeTag, searchStart);
|
|
227
|
+
if (-1 !== endIdx) {
|
|
228
|
+
currentContent += chunk.slice(searchStart, endIdx);
|
|
229
|
+
const shouldStop = onMatch({
|
|
230
|
+
openTag: currentOpenTag,
|
|
231
|
+
content: currentContent.trim()
|
|
232
|
+
});
|
|
233
|
+
if (shouldStop) return;
|
|
234
|
+
capturing = false;
|
|
235
|
+
currentContent = '';
|
|
236
|
+
currentOpenTag = '';
|
|
237
|
+
searchStart = endIdx + closeTag.length;
|
|
238
|
+
} else {
|
|
239
|
+
currentContent += chunk.slice(searchStart, -closeTag.length);
|
|
240
|
+
leftover = chunk.slice(-closeTag.length);
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
const startIdx = chunk.indexOf(openTagPrefix, searchStart);
|
|
245
|
+
if (-1 !== startIdx) {
|
|
246
|
+
const tagEndIdx = chunk.indexOf('>', startIdx);
|
|
247
|
+
if (-1 !== tagEndIdx) {
|
|
248
|
+
capturing = true;
|
|
249
|
+
currentOpenTag = chunk.slice(startIdx, tagEndIdx + 1);
|
|
250
|
+
currentContent = chunk.slice(tagEndIdx + 1);
|
|
251
|
+
const endIdx = currentContent.indexOf(closeTag);
|
|
252
|
+
if (-1 !== endIdx) {
|
|
253
|
+
const shouldStop = onMatch({
|
|
254
|
+
openTag: currentOpenTag,
|
|
255
|
+
content: currentContent.slice(0, endIdx).trim()
|
|
256
|
+
});
|
|
257
|
+
if (shouldStop) return;
|
|
258
|
+
capturing = false;
|
|
259
|
+
currentContent = '';
|
|
260
|
+
currentOpenTag = '';
|
|
261
|
+
searchStart = tagEndIdx + 1 + endIdx + closeTag.length;
|
|
262
|
+
} else {
|
|
263
|
+
leftover = currentContent.slice(-closeTag.length);
|
|
264
|
+
currentContent = currentContent.slice(0, -closeTag.length);
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
leftover = chunk.slice(startIdx);
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
} else {
|
|
272
|
+
leftover = chunk.slice(-openTagPrefix.length);
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
} finally{
|
|
278
|
+
(0, external_node_fs_.closeSync)(fd);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function parseImageScripts(html) {
|
|
282
|
+
const imageMap = {};
|
|
283
|
+
const regex = /<script type="midscene-image" data-id="([^"]+)">([\s\S]*?)<\/script>/g;
|
|
284
|
+
for (const match of html.matchAll(regex)){
|
|
285
|
+
const [, id, content] = match;
|
|
286
|
+
imageMap[id] = unescapeContent(content);
|
|
287
|
+
}
|
|
288
|
+
return imageMap;
|
|
289
|
+
}
|
|
290
|
+
function parseDumpScript(html) {
|
|
291
|
+
const scriptOpenTag = '<script type="midscene_web_dump"';
|
|
292
|
+
const scriptCloseTag = "<\/script>";
|
|
293
|
+
const lastOpenIndex = html.lastIndexOf(scriptOpenTag);
|
|
294
|
+
if (-1 === lastOpenIndex) throw new Error("No dump script found in HTML");
|
|
295
|
+
const tagEndIndex = html.indexOf('>', lastOpenIndex);
|
|
296
|
+
if (-1 === tagEndIndex) throw new Error("No dump script found in HTML");
|
|
297
|
+
const closeIndex = html.indexOf(scriptCloseTag, tagEndIndex);
|
|
298
|
+
if (-1 === closeIndex) throw new Error("No dump script found in HTML");
|
|
299
|
+
const content = html.substring(tagEndIndex + 1, closeIndex);
|
|
300
|
+
return unescapeContent(content);
|
|
301
|
+
}
|
|
302
|
+
function parseDumpScriptAttributes(html) {
|
|
303
|
+
const regex = /<script type="midscene_web_dump"([^>]*)>/;
|
|
304
|
+
const match = regex.exec(html);
|
|
305
|
+
if (!match) return {};
|
|
306
|
+
const attrString = match[1];
|
|
307
|
+
const attributes = {};
|
|
308
|
+
const attrRegex = /(\w+)="([^"]*)"/g;
|
|
309
|
+
for (const attrMatch of attrString.matchAll(attrRegex)){
|
|
310
|
+
const [, key, value] = attrMatch;
|
|
311
|
+
if ('type' !== key) attributes[key] = decodeURIComponent(value);
|
|
312
|
+
}
|
|
313
|
+
return attributes;
|
|
314
|
+
}
|
|
315
|
+
function generateImageScriptTag(id, data) {
|
|
316
|
+
return '<script type="midscene-image" data-id="' + id + '">' + escapeContent(data) + "<\/script>";
|
|
317
|
+
}
|
|
318
|
+
let _baseUrlFixScript;
|
|
319
|
+
function getBaseUrlFixScript() {
|
|
320
|
+
if (!_baseUrlFixScript) {
|
|
321
|
+
const close = "<\/script>";
|
|
322
|
+
_baseUrlFixScript = '\n<script>(function(){var p=window.location.pathname;if(p.endsWith("/")||/\\.\\w+$/.test(p))return;var b=document.createElement("base");b.href=p+"/";document.head.insertBefore(b,document.head.firstChild)})()' + close + '\n';
|
|
323
|
+
}
|
|
324
|
+
return _baseUrlFixScript;
|
|
325
|
+
}
|
|
326
|
+
function generateDumpScriptTag(json, attributes) {
|
|
327
|
+
let attrString = '';
|
|
328
|
+
if (attributes && Object.keys(attributes).length > 0) attrString = ' ' + Object.entries(attributes).map(([k, v])=>k + '="' + encodeURIComponent(v) + '"').join(' ');
|
|
329
|
+
return '<script type="midscene_web_dump"' + attrString + '>' + escapeContent(json) + "<\/script>";
|
|
330
|
+
}
|
|
331
|
+
})();
|
|
332
|
+
exports.STREAMING_CHUNK_SIZE = __webpack_exports__.STREAMING_CHUNK_SIZE;
|
|
333
|
+
exports.escapeContent = __webpack_exports__.escapeContent;
|
|
334
|
+
exports.extractAllDumpScriptsSync = __webpack_exports__.extractAllDumpScriptsSync;
|
|
335
|
+
exports.extractImageByIdSync = __webpack_exports__.extractImageByIdSync;
|
|
336
|
+
exports.extractLastDumpScriptSync = __webpack_exports__.extractLastDumpScriptSync;
|
|
337
|
+
exports.generateDumpScriptTag = __webpack_exports__.generateDumpScriptTag;
|
|
338
|
+
exports.generateImageScriptTag = __webpack_exports__.generateImageScriptTag;
|
|
339
|
+
exports.getBaseUrlFixScript = __webpack_exports__.getBaseUrlFixScript;
|
|
340
|
+
exports.parseDumpScript = __webpack_exports__.parseDumpScript;
|
|
341
|
+
exports.parseDumpScriptAttributes = __webpack_exports__.parseDumpScriptAttributes;
|
|
342
|
+
exports.parseImageScripts = __webpack_exports__.parseImageScripts;
|
|
343
|
+
exports.streamDumpScriptsSync = __webpack_exports__.streamDumpScriptsSync;
|
|
344
|
+
exports.streamImageScriptsToFile = __webpack_exports__.streamImageScriptsToFile;
|
|
345
|
+
exports.streamScanTags = __webpack_exports__.streamScanTags;
|
|
346
|
+
exports.unescapeContent = __webpack_exports__.unescapeContent;
|
|
347
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
348
|
+
"STREAMING_CHUNK_SIZE",
|
|
349
|
+
"escapeContent",
|
|
350
|
+
"extractAllDumpScriptsSync",
|
|
351
|
+
"extractImageByIdSync",
|
|
352
|
+
"extractLastDumpScriptSync",
|
|
353
|
+
"generateDumpScriptTag",
|
|
354
|
+
"generateImageScriptTag",
|
|
355
|
+
"getBaseUrlFixScript",
|
|
356
|
+
"parseDumpScript",
|
|
357
|
+
"parseDumpScriptAttributes",
|
|
358
|
+
"parseImageScripts",
|
|
359
|
+
"streamDumpScriptsSync",
|
|
360
|
+
"streamImageScriptsToFile",
|
|
361
|
+
"streamScanTags",
|
|
362
|
+
"unescapeContent"
|
|
363
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
364
|
+
Object.defineProperty(exports, '__esModule', {
|
|
365
|
+
value: true
|
|
366
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
parseDumpScript: ()=>external_html_utils_js_namespaceObject.parseDumpScript,
|
|
28
|
+
restoreImageReferences: ()=>external_screenshot_restoration_js_namespaceObject.restoreImageReferences,
|
|
29
|
+
generateImageScriptTag: ()=>external_html_utils_js_namespaceObject.generateImageScriptTag,
|
|
30
|
+
parseImageScripts: ()=>external_html_utils_js_namespaceObject.parseImageScripts,
|
|
31
|
+
parseDumpScriptAttributes: ()=>external_html_utils_js_namespaceObject.parseDumpScriptAttributes,
|
|
32
|
+
unescapeContent: ()=>external_html_utils_js_namespaceObject.unescapeContent,
|
|
33
|
+
escapeContent: ()=>external_html_utils_js_namespaceObject.escapeContent,
|
|
34
|
+
generateDumpScriptTag: ()=>external_html_utils_js_namespaceObject.generateDumpScriptTag
|
|
35
|
+
});
|
|
36
|
+
const external_screenshot_restoration_js_namespaceObject = require("./screenshot-restoration.js");
|
|
37
|
+
const external_html_utils_js_namespaceObject = require("./html-utils.js");
|
|
38
|
+
exports.escapeContent = __webpack_exports__.escapeContent;
|
|
39
|
+
exports.generateDumpScriptTag = __webpack_exports__.generateDumpScriptTag;
|
|
40
|
+
exports.generateImageScriptTag = __webpack_exports__.generateImageScriptTag;
|
|
41
|
+
exports.parseDumpScript = __webpack_exports__.parseDumpScript;
|
|
42
|
+
exports.parseDumpScriptAttributes = __webpack_exports__.parseDumpScriptAttributes;
|
|
43
|
+
exports.parseImageScripts = __webpack_exports__.parseImageScripts;
|
|
44
|
+
exports.restoreImageReferences = __webpack_exports__.restoreImageReferences;
|
|
45
|
+
exports.unescapeContent = __webpack_exports__.unescapeContent;
|
|
46
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
47
|
+
"escapeContent",
|
|
48
|
+
"generateDumpScriptTag",
|
|
49
|
+
"generateImageScriptTag",
|
|
50
|
+
"parseDumpScript",
|
|
51
|
+
"parseDumpScriptAttributes",
|
|
52
|
+
"parseImageScripts",
|
|
53
|
+
"restoreImageReferences",
|
|
54
|
+
"unescapeContent"
|
|
55
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
56
|
+
Object.defineProperty(exports, '__esModule', {
|
|
57
|
+
value: true
|
|
58
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
restoreImageReferences: ()=>restoreImageReferences
|
|
28
|
+
});
|
|
29
|
+
const external_screenshot_store_js_namespaceObject = require("./screenshot-store.js");
|
|
30
|
+
function restoreImageReferences(data, resolveImage) {
|
|
31
|
+
if ('string' == typeof data) return data;
|
|
32
|
+
if (Array.isArray(data)) return data.map((item)=>restoreImageReferences(item, resolveImage));
|
|
33
|
+
if ('object' == typeof data && null !== data) {
|
|
34
|
+
const refLike = (0, external_screenshot_store_js_namespaceObject.normalizeScreenshotRef)(data);
|
|
35
|
+
if (refLike) {
|
|
36
|
+
let resolved = null;
|
|
37
|
+
const lazy = Object.defineProperties({}, {
|
|
38
|
+
base64: {
|
|
39
|
+
get () {
|
|
40
|
+
if (null === resolved) resolved = resolveImage(refLike);
|
|
41
|
+
return resolved;
|
|
42
|
+
},
|
|
43
|
+
enumerable: true
|
|
44
|
+
},
|
|
45
|
+
capturedAt: {
|
|
46
|
+
value: refLike.capturedAt,
|
|
47
|
+
enumerable: true
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return lazy;
|
|
51
|
+
}
|
|
52
|
+
const result = {};
|
|
53
|
+
for (const [key, value] of Object.entries(data))result[key] = restoreImageReferences(value, resolveImage);
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
exports.restoreImageReferences = __webpack_exports__.restoreImageReferences;
|
|
59
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
60
|
+
"restoreImageReferences"
|
|
61
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
62
|
+
Object.defineProperty(exports, '__esModule', {
|
|
63
|
+
value: true
|
|
64
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
normalizeScreenshotRef: ()=>normalizeScreenshotRef,
|
|
28
|
+
ScreenshotStore: ()=>ScreenshotStore,
|
|
29
|
+
resolveScreenshotSource: ()=>resolveScreenshotSource
|
|
30
|
+
});
|
|
31
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
32
|
+
const promises_namespaceObject = require("node:fs/promises");
|
|
33
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
34
|
+
const external_html_utils_js_namespaceObject = require("./html-utils.js");
|
|
35
|
+
function _define_property(obj, key, value) {
|
|
36
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
37
|
+
value: value,
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true
|
|
41
|
+
});
|
|
42
|
+
else obj[key] = value;
|
|
43
|
+
return obj;
|
|
44
|
+
}
|
|
45
|
+
function normalizeScreenshotRef(value) {
|
|
46
|
+
if ('object' != typeof value || null === value) return null;
|
|
47
|
+
const record = value;
|
|
48
|
+
if ('midscene_screenshot_ref' === record.type && 'string' == typeof record.id && 'number' == typeof record.capturedAt && ('inline' === record.storage || 'file' === record.storage) && ('image/png' === record.mimeType || 'image/jpeg' === record.mimeType)) {
|
|
49
|
+
if ('file' === record.storage && 'string' != typeof record.path) return null;
|
|
50
|
+
return record;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function extensionByMimeType(mimeType) {
|
|
55
|
+
return 'image/jpeg' === mimeType ? 'jpeg' : 'png';
|
|
56
|
+
}
|
|
57
|
+
function resolveScreenshotSource(refInput, options) {
|
|
58
|
+
const ref = normalizeScreenshotRef(refInput);
|
|
59
|
+
const id = ref?.id ?? options.fallbackId;
|
|
60
|
+
const mimeType = ref?.mimeType ?? options.fallbackMimeType;
|
|
61
|
+
if (!id || !mimeType) throw new Error('ScreenshotStore: screenshot id and mimeType are required to resolve screenshot');
|
|
62
|
+
const resolveReportRelativePath = (filePath)=>(0, external_node_path_namespaceObject.isAbsolute)(filePath) ? filePath : (0, external_node_path_namespaceObject.join)((0, external_node_path_namespaceObject.dirname)(options.reportPath), filePath);
|
|
63
|
+
if (ref?.storage === 'file') {
|
|
64
|
+
if (!ref.path) throw new Error(`ScreenshotStore: screenshot ref "${ref.id}" missing file path`);
|
|
65
|
+
const explicitFilePath = resolveReportRelativePath(ref.path);
|
|
66
|
+
if ((0, external_node_fs_namespaceObject.existsSync)(explicitFilePath)) return {
|
|
67
|
+
type: 'file',
|
|
68
|
+
id,
|
|
69
|
+
mimeType,
|
|
70
|
+
filePath: explicitFilePath
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const inlineDataUri = (0, external_html_utils_js_namespaceObject.extractImageByIdSync)(options.reportPath, id);
|
|
74
|
+
if (inlineDataUri) return {
|
|
75
|
+
type: 'data-uri',
|
|
76
|
+
id,
|
|
77
|
+
mimeType,
|
|
78
|
+
dataUri: inlineDataUri
|
|
79
|
+
};
|
|
80
|
+
const siblingScreenshotPath = (0, external_node_path_namespaceObject.join)((0, external_node_path_namespaceObject.dirname)(options.reportPath), 'screenshots', `${id}.${extensionByMimeType(mimeType)}`);
|
|
81
|
+
if ((0, external_node_fs_namespaceObject.existsSync)(siblingScreenshotPath)) return {
|
|
82
|
+
type: 'file',
|
|
83
|
+
id,
|
|
84
|
+
mimeType,
|
|
85
|
+
filePath: siblingScreenshotPath
|
|
86
|
+
};
|
|
87
|
+
throw new Error(`ScreenshotStore: cannot resolve screenshot "${id}" from ${options.reportPath}`);
|
|
88
|
+
}
|
|
89
|
+
class ScreenshotStore {
|
|
90
|
+
async persist(screenshot) {
|
|
91
|
+
const shouldWriteFileCopy = 'directory' === this.mode || this.alsoWriteFileCopy;
|
|
92
|
+
const fileRef = shouldWriteFileCopy ? await this.persistToSharedFileIfNeeded(screenshot, {
|
|
93
|
+
markAsPersisted: 'directory' === this.mode
|
|
94
|
+
}) : null;
|
|
95
|
+
if ('inline' === this.mode) {
|
|
96
|
+
if (!this.writeInlineImage) throw new Error('ScreenshotStore: writeInlineImage is required in inline mode');
|
|
97
|
+
if (!this.writtenInlineIds.has(screenshot.id)) {
|
|
98
|
+
await this.writeInlineImage(screenshot.id, screenshot.base64);
|
|
99
|
+
this.writtenInlineIds.add(screenshot.id);
|
|
100
|
+
}
|
|
101
|
+
return screenshot.markPersistedInline(this.reportPath);
|
|
102
|
+
}
|
|
103
|
+
if (!fileRef) throw new Error('ScreenshotStore: file persistence is required in directory mode');
|
|
104
|
+
return fileRef;
|
|
105
|
+
}
|
|
106
|
+
async persistToSharedFileIfNeeded(screenshot, options) {
|
|
107
|
+
const screenshotsDir = this.screenshotsDir;
|
|
108
|
+
if (!screenshotsDir) throw new Error('ScreenshotStore: screenshotsDir is required when file persistence is enabled');
|
|
109
|
+
if (!(0, external_node_fs_namespaceObject.existsSync)(screenshotsDir)) (0, external_node_fs_namespaceObject.mkdirSync)(screenshotsDir, {
|
|
110
|
+
recursive: true
|
|
111
|
+
});
|
|
112
|
+
const relativePath = `./screenshots/${screenshot.id}.${screenshot.extension}`;
|
|
113
|
+
const absolutePath = (0, external_node_path_namespaceObject.join)(screenshotsDir, `${screenshot.id}.${screenshot.extension}`);
|
|
114
|
+
if (!this.writtenFileIds.has(screenshot.id)) {
|
|
115
|
+
const buffer = Buffer.from(screenshot.rawBase64, 'base64');
|
|
116
|
+
await (0, promises_namespaceObject.writeFile)(absolutePath, buffer);
|
|
117
|
+
this.writtenFileIds.add(screenshot.id);
|
|
118
|
+
}
|
|
119
|
+
if (options.markAsPersisted) return screenshot.markPersistedToPath(relativePath, absolutePath);
|
|
120
|
+
return screenshot.registerPersistedFileCopy(relativePath, absolutePath);
|
|
121
|
+
}
|
|
122
|
+
loadBase64(refInput) {
|
|
123
|
+
const ref = normalizeScreenshotRef(refInput);
|
|
124
|
+
if (!ref) throw new Error('ScreenshotStore: invalid screenshot reference');
|
|
125
|
+
const resolved = resolveScreenshotSource(ref, {
|
|
126
|
+
reportPath: this.reportPath
|
|
127
|
+
});
|
|
128
|
+
if ('data-uri' === resolved.type) return resolved.dataUri;
|
|
129
|
+
const data = (0, external_node_fs_namespaceObject.readFileSync)(resolved.filePath);
|
|
130
|
+
return `data:${resolved.mimeType};base64,${data.toString('base64')}`;
|
|
131
|
+
}
|
|
132
|
+
cleanup() {
|
|
133
|
+
if ('directory' === this.mode && this.screenshotsDir && (0, external_node_fs_namespaceObject.existsSync)(this.screenshotsDir)) (0, external_node_fs_namespaceObject.rmSync)(this.screenshotsDir, {
|
|
134
|
+
recursive: true,
|
|
135
|
+
force: true
|
|
136
|
+
});
|
|
137
|
+
this.writtenInlineIds.clear();
|
|
138
|
+
this.writtenFileIds.clear();
|
|
139
|
+
}
|
|
140
|
+
constructor(options){
|
|
141
|
+
_define_property(this, "mode", void 0);
|
|
142
|
+
_define_property(this, "reportPath", void 0);
|
|
143
|
+
_define_property(this, "screenshotsDir", void 0);
|
|
144
|
+
_define_property(this, "writeInlineImage", void 0);
|
|
145
|
+
_define_property(this, "alsoWriteFileCopy", void 0);
|
|
146
|
+
_define_property(this, "writtenInlineIds", new Set());
|
|
147
|
+
_define_property(this, "writtenFileIds", new Set());
|
|
148
|
+
this.mode = options.mode;
|
|
149
|
+
this.reportPath = options.reportPath;
|
|
150
|
+
this.screenshotsDir = options.screenshotsDir;
|
|
151
|
+
this.writeInlineImage = options.writeInlineImage;
|
|
152
|
+
this.alsoWriteFileCopy = options.alsoWriteFileCopy ?? options.ensureFileCopy ?? false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.ScreenshotStore = __webpack_exports__.ScreenshotStore;
|
|
156
|
+
exports.normalizeScreenshotRef = __webpack_exports__.normalizeScreenshotRef;
|
|
157
|
+
exports.resolveScreenshotSource = __webpack_exports__.resolveScreenshotSource;
|
|
158
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
159
|
+
"ScreenshotStore",
|
|
160
|
+
"normalizeScreenshotRef",
|
|
161
|
+
"resolveScreenshotSource"
|
|
162
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
163
|
+
Object.defineProperty(exports, '__esModule', {
|
|
164
|
+
value: true
|
|
165
|
+
});
|