gz-research-assistant 0.1.2 → 1.0.4
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/README.md +49 -32
- package/dist/App.d.ts +7 -3
- package/dist/api/automation.d.ts +1 -1
- package/dist/components/AssistantErrorBoundary/index.d.ts +16 -0
- package/dist/{recorder-ClSMnnGL.js → core-DWx1hG8M.js} +234 -233
- package/dist/core-DWx1hG8M.js.map +1 -0
- package/dist/core.js +2 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2676 -4
- package/dist/index.js.map +1 -0
- package/dist/inject.d.ts +21 -0
- package/dist/pages/assistant/components/TimelinePanel/index.d.ts +1 -1
- package/dist/pages/assistant/index.d.ts +3 -1
- package/dist/pages/assistant/useLauncherDrag.d.ts +5 -0
- package/dist/style.css +1 -1
- package/package.json +51 -55
- package/dist/App-B12hd4tM.js +0 -2524
- package/dist/App-B12hd4tM.js.map +0 -1
- package/dist/recorder-ClSMnnGL.js.map +0 -1
- package/dist/sdk.d.ts +0 -7
- package/dist/sdk.js +0 -33
- package/dist/sdk.js.map +0 -1
|
@@ -1,45 +1,46 @@
|
|
|
1
1
|
import { controls as e, describeControl as t, excluded as n, locate as r, privateInput as i } from "gz-laya-pilot/browser";
|
|
2
|
+
import { parseAssertion as a, parseCase as o } from "gz-laya-pilot/schema";
|
|
2
3
|
//#region src/utils/diagnostics/privacy.ts
|
|
3
|
-
var
|
|
4
|
-
function
|
|
4
|
+
var s = /password|passwd|pwd|token|authorization|cookie|secret|credential|session|api[-_]?key|身份证|手机号|银行卡|证件|phone|mobile|email|idcard|bankcard/i;
|
|
5
|
+
function c(e, t = 600) {
|
|
5
6
|
return e.slice(0, 12e3).replace(/Bearer\s+[^\s,;"']+/gi, "Bearer [已脱敏]").replace(/\beyJ[\w-]+\.[\w-]+\.[\w-]+\b/g, "[令牌已脱敏]").replace(/((?:password|passwd|pwd|token|secret|authorization|cookie|session(?:id)?|api[-_]?key)["']?\s*[=:]\s*["']?)[^"'\s,;&]+/gi, "$1[已脱敏]").replace(/\b1[3-9]\d{9}\b/g, "[手机号已脱敏]").replace(/\b\d{17}[\dXx]\b/g, "[证件号已脱敏]").replace(/[\w.+-]+@[\w.-]+\.[a-z]{2,}/gi, "[邮箱已脱敏]").slice(0, t);
|
|
6
7
|
}
|
|
7
|
-
function
|
|
8
|
+
function l(e) {
|
|
8
9
|
try {
|
|
9
10
|
let t = new URL(e, location.origin);
|
|
10
11
|
if (!["http:", "https:"].includes(t.protocol)) return "[" + t.protocol + "]";
|
|
11
12
|
let n = [...new Set(t.searchParams.keys())].slice(0, 20);
|
|
12
|
-
return
|
|
13
|
+
return c(t.origin + t.pathname, 300) + (n.length ? "?" + n.map((e) => encodeURIComponent(c(e, 40)) + "=[已脱敏]").join("&") : "") + (t.hash ? "#[已省略]" : "");
|
|
13
14
|
} catch {
|
|
14
15
|
return "[无效地址]";
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
-
return t > 5 ? "[层级已截断]" : typeof e == "string" ?
|
|
19
|
-
name:
|
|
20
|
-
message:
|
|
21
|
-
stack:
|
|
22
|
-
} : typeof e == "object" ? n.has(e) ? "[循环引用]" : (n.add(e), Array.isArray(e) ? e.slice(0, 30).map((e) =>
|
|
18
|
+
function u(e, t = 0, n = /* @__PURE__ */ new WeakSet()) {
|
|
19
|
+
return t > 5 ? "[层级已截断]" : typeof e == "string" ? c(e) : e === null || typeof e == "number" || typeof e == "boolean" ? e : e instanceof Error ? {
|
|
20
|
+
name: c(e.name),
|
|
21
|
+
message: c(e.message),
|
|
22
|
+
stack: c(e.stack ?? "", 1800)
|
|
23
|
+
} : typeof e == "object" ? n.has(e) ? "[循环引用]" : (n.add(e), Array.isArray(e) ? e.slice(0, 30).map((e) => u(e, t + 1, n)) : Object.fromEntries(Object.entries(e).slice(0, 50).map(([e, r]) => [c(e, 80), s.test(e) ? "[已脱敏]" : u(r, t + 1, n)]))) : String(e).slice(0, 80);
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
+
function d(e) {
|
|
25
26
|
if (typeof e != "string") return e == null ? null : "[非文本正文未采集]";
|
|
26
27
|
if (e.length > 16e3) return "[正文超过 16 KB,未采集]";
|
|
27
28
|
try {
|
|
28
|
-
return
|
|
29
|
+
return u(JSON.parse(e));
|
|
29
30
|
} catch {
|
|
30
31
|
return "[非 JSON 正文未采集]";
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
function
|
|
34
|
+
function f(e) {
|
|
34
35
|
return /\/(?:login|logininfo|logout|auth|oauth|token|password|session)(?:\/|\?|$)/i.test(e);
|
|
35
36
|
}
|
|
36
37
|
//#endregion
|
|
37
38
|
//#region src/utils/diagnostics/performance.ts
|
|
38
|
-
var
|
|
39
|
+
var p = () => ({
|
|
39
40
|
heapSamples: [],
|
|
40
41
|
longTasks: []
|
|
41
|
-
}),
|
|
42
|
-
function
|
|
42
|
+
}), m = (e) => `${(e / 1048576).toFixed(1)} MB`;
|
|
43
|
+
function h(e, t, n) {
|
|
43
44
|
let r = [];
|
|
44
45
|
e.LCP > 2500 && r.push({
|
|
45
46
|
id: "lcp",
|
|
@@ -77,7 +78,7 @@ function p(e, t, n) {
|
|
|
77
78
|
id: "heap-pressure",
|
|
78
79
|
severity: "error",
|
|
79
80
|
title: "JS 堆内存压力偏高",
|
|
80
|
-
evidence: `当前 ${
|
|
81
|
+
evidence: `当前 ${m(c.used)} / 堆上限 ${m(c.limit)}(${Math.round(c.used / c.limit * 100)}%)`,
|
|
81
82
|
rule: "本地告警规则:连续 3 次采样 ≥ 浏览器 JS 堆上限的 80%。",
|
|
82
83
|
suggestions: ["在 Chrome 任务管理器核对内存占用,并在 Memory 中比较堆快照。", "检查大数组、缓存和未释放的对象;按实际设备验证内存预算。"],
|
|
83
84
|
url: "https://developer.chrome.com/docs/devtools/memory-problems"
|
|
@@ -87,7 +88,7 @@ function p(e, t, n) {
|
|
|
87
88
|
id: "heap-growth",
|
|
88
89
|
severity: "warning",
|
|
89
90
|
title: "内存持续增长,建议排查泄漏",
|
|
90
|
-
evidence: `${Math.round((c.time - s[0].time) / 1e3)} 秒内,分段内存低点增加 ${
|
|
91
|
+
evidence: `${Math.round((c.time - s[0].time) / 1e3)} 秒内,分段内存低点增加 ${m(o)}(${Math.round(o / n * 100)}%)`,
|
|
91
92
|
rule: "本地风险规则:至少连续 60 秒、13 次采样,三段低点依次增长,增量 ≥ 20 MB 且 ≥ 30%。这不是泄漏结论。",
|
|
92
93
|
suggestions: [
|
|
93
94
|
"重复进入、退出同一业务页面,再静置观察内存是否回落。",
|
|
@@ -101,52 +102,52 @@ function p(e, t, n) {
|
|
|
101
102
|
}
|
|
102
103
|
//#endregion
|
|
103
104
|
//#region src/utils/diagnostics/runtime.ts
|
|
104
|
-
var
|
|
105
|
+
var g = 300, _ = 60, v = 900 * 1e3, y = {
|
|
105
106
|
events: [],
|
|
106
107
|
requests: [],
|
|
107
108
|
metrics: {},
|
|
108
|
-
performance:
|
|
109
|
+
performance: p(),
|
|
109
110
|
performanceUpdatedAt: Date.now(),
|
|
110
111
|
paused: !1,
|
|
111
112
|
frozen: null
|
|
112
|
-
},
|
|
113
|
-
function
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
}, b = /* @__PURE__ */ new Set(), x = 0, S, C = !1, w = 0, T, E = /* @__PURE__ */ new Set(), D;
|
|
114
|
+
function O() {
|
|
115
|
+
T ||= setTimeout(() => {
|
|
116
|
+
T = void 0, E.forEach((e) => e());
|
|
116
117
|
}, 150);
|
|
117
118
|
}
|
|
118
|
-
function
|
|
119
|
-
let e = Date.now() -
|
|
120
|
-
|
|
121
|
-
...
|
|
122
|
-
events:
|
|
123
|
-
requests:
|
|
119
|
+
function k() {
|
|
120
|
+
let e = Date.now() - v;
|
|
121
|
+
y = {
|
|
122
|
+
...y,
|
|
123
|
+
events: y.events.filter((t) => t.time >= e).slice(-g),
|
|
124
|
+
requests: y.requests.filter((t) => t.time >= e).slice(-_),
|
|
124
125
|
performanceUpdatedAt: Date.now()
|
|
125
126
|
};
|
|
126
127
|
}
|
|
127
|
-
function
|
|
128
|
-
if (!
|
|
128
|
+
function A(e, t, n, r = Date.now(), i = S) {
|
|
129
|
+
if (!C || y.paused) return;
|
|
129
130
|
let a = {
|
|
130
|
-
id: ++
|
|
131
|
+
id: ++x,
|
|
131
132
|
time: r,
|
|
132
133
|
kind: e,
|
|
133
|
-
title:
|
|
134
|
-
page:
|
|
134
|
+
title: c(t, 180),
|
|
135
|
+
page: l(location.href),
|
|
135
136
|
actionId: i,
|
|
136
|
-
detail:
|
|
137
|
+
detail: u(n)
|
|
137
138
|
};
|
|
138
|
-
(e === "click" || e === "change" || e === "route") && (
|
|
139
|
-
...
|
|
140
|
-
events: [...
|
|
141
|
-
},
|
|
139
|
+
(e === "click" || e === "change" || e === "route") && (S = a.id), y = {
|
|
140
|
+
...y,
|
|
141
|
+
events: [...y.events, a]
|
|
142
|
+
}, k(), O();
|
|
142
143
|
}
|
|
143
|
-
function
|
|
144
|
-
return e ? i(e) ? "[敏感控件]" :
|
|
144
|
+
function j(e) {
|
|
145
|
+
return e ? i(e) ? "[敏感控件]" : c(t(e).label, 70) : "";
|
|
145
146
|
}
|
|
146
|
-
function
|
|
147
|
+
function M() {
|
|
147
148
|
return {
|
|
148
|
-
url:
|
|
149
|
-
title:
|
|
149
|
+
url: l(location.href),
|
|
150
|
+
title: c(document.title, 100),
|
|
150
151
|
viewport: {
|
|
151
152
|
width: innerWidth,
|
|
152
153
|
height: innerHeight,
|
|
@@ -157,28 +158,28 @@ function A() {
|
|
|
157
158
|
y: scrollY
|
|
158
159
|
},
|
|
159
160
|
visibility: document.visibilityState,
|
|
160
|
-
focusedControl:
|
|
161
|
-
headings: [...document.querySelectorAll("h1,h2,h3")].filter((e) => !e.closest("[data-research-assistant]")).slice(0, 12).map((e) =>
|
|
161
|
+
focusedControl: j(document.activeElement),
|
|
162
|
+
headings: [...document.querySelectorAll("h1,h2,h3")].filter((e) => !e.closest("[data-research-assistant]")).slice(0, 12).map((e) => c(e.textContent ?? "", 80)),
|
|
162
163
|
domNodes: document.getElementsByTagName("*").length,
|
|
163
164
|
iframeCount: document.querySelectorAll("iframe").length
|
|
164
165
|
};
|
|
165
166
|
}
|
|
166
|
-
function
|
|
167
|
+
function N(e) {
|
|
167
168
|
try {
|
|
168
|
-
return Array.from({ length: Math.min(window[e].length, 60) }, (t, n) =>
|
|
169
|
+
return Array.from({ length: Math.min(window[e].length, 60) }, (t, n) => c(window[e].key(n) ?? "", 100));
|
|
169
170
|
} catch {
|
|
170
171
|
return ["[浏览器禁止访问]"];
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
|
-
function
|
|
174
|
+
function P() {
|
|
174
175
|
let e = performance, t = navigator, n = [];
|
|
175
176
|
try {
|
|
176
|
-
n = document.cookie.split(";").filter((e) => e.trim()).slice(0, 60).map((e) =>
|
|
177
|
+
n = document.cookie.split(";").filter((e) => e.trim()).slice(0, 60).map((e) => c(e.split("=")[0].trim(), 100));
|
|
177
178
|
} catch {
|
|
178
179
|
n = ["[浏览器禁止访问]"];
|
|
179
180
|
}
|
|
180
181
|
return {
|
|
181
|
-
userAgent:
|
|
182
|
+
userAgent: c(navigator.userAgent, 300),
|
|
182
183
|
language: navigator.language,
|
|
183
184
|
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
184
185
|
online: navigator.onLine,
|
|
@@ -196,80 +197,80 @@ function M() {
|
|
|
196
197
|
saveData: t.connection.saveData
|
|
197
198
|
} : null,
|
|
198
199
|
cookies: n,
|
|
199
|
-
localStorageKeys:
|
|
200
|
-
sessionStorageKeys:
|
|
200
|
+
localStorageKeys: N("localStorage"),
|
|
201
|
+
sessionStorageKeys: N("sessionStorage"),
|
|
201
202
|
coverage: "仅当前窗口;跨域 iframe 未接入。Cookie 不包含 HttpOnly,所有存储值均不采集。"
|
|
202
203
|
};
|
|
203
204
|
}
|
|
204
|
-
function
|
|
205
|
-
return
|
|
205
|
+
function F(e = "手动截取现场") {
|
|
206
|
+
return k(), structuredClone({
|
|
206
207
|
schema: "zhidao-research-assistant",
|
|
207
208
|
version: 1,
|
|
208
209
|
capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
209
|
-
reason:
|
|
210
|
-
page:
|
|
211
|
-
environment:
|
|
212
|
-
metrics:
|
|
213
|
-
performance:
|
|
214
|
-
events:
|
|
215
|
-
requests:
|
|
210
|
+
reason: c(e),
|
|
211
|
+
page: M(),
|
|
212
|
+
environment: P(),
|
|
213
|
+
metrics: y.metrics,
|
|
214
|
+
performance: y.performance,
|
|
215
|
+
events: y.events,
|
|
216
|
+
requests: y.requests,
|
|
216
217
|
limits: {
|
|
217
|
-
events:
|
|
218
|
-
requests:
|
|
219
|
-
retentionMinutes:
|
|
218
|
+
events: g,
|
|
219
|
+
requests: _,
|
|
220
|
+
retentionMinutes: v / 6e4
|
|
220
221
|
}
|
|
221
222
|
});
|
|
222
223
|
}
|
|
223
|
-
function
|
|
224
|
-
|
|
225
|
-
...
|
|
226
|
-
frozen:
|
|
227
|
-
},
|
|
224
|
+
function I(e) {
|
|
225
|
+
y = {
|
|
226
|
+
...y,
|
|
227
|
+
frozen: F(e)
|
|
228
|
+
}, O();
|
|
228
229
|
}
|
|
229
|
-
function
|
|
230
|
-
!
|
|
230
|
+
function L(e, t) {
|
|
231
|
+
!C || y.paused || (A("error", e, t), I(e));
|
|
231
232
|
}
|
|
232
|
-
var
|
|
233
|
-
isActive: () =>
|
|
233
|
+
var R = {
|
|
234
|
+
isActive: () => C,
|
|
234
235
|
subscribe(e) {
|
|
235
|
-
return
|
|
236
|
-
|
|
236
|
+
return E.add(e), () => {
|
|
237
|
+
E.delete(e);
|
|
237
238
|
};
|
|
238
239
|
},
|
|
239
|
-
getState: () =>
|
|
240
|
+
getState: () => y,
|
|
240
241
|
pause(e) {
|
|
241
|
-
|
|
242
|
-
...
|
|
242
|
+
w++, y = {
|
|
243
|
+
...y,
|
|
243
244
|
paused: e,
|
|
244
|
-
performance:
|
|
245
|
-
},
|
|
245
|
+
performance: p()
|
|
246
|
+
}, b.clear(), O();
|
|
246
247
|
},
|
|
247
248
|
clear() {
|
|
248
|
-
|
|
249
|
-
...
|
|
249
|
+
w++, S = void 0, y = {
|
|
250
|
+
...y,
|
|
250
251
|
events: [],
|
|
251
252
|
requests: [],
|
|
252
253
|
metrics: {},
|
|
253
|
-
performance:
|
|
254
|
+
performance: p(),
|
|
254
255
|
frozen: null
|
|
255
|
-
},
|
|
256
|
+
}, b.clear(), O();
|
|
256
257
|
}
|
|
257
258
|
};
|
|
258
|
-
function
|
|
259
|
-
!
|
|
260
|
-
...
|
|
261
|
-
requests: [...
|
|
262
|
-
},
|
|
259
|
+
function z(e, t) {
|
|
260
|
+
!C || y.paused || w !== t || (y = {
|
|
261
|
+
...y,
|
|
262
|
+
requests: [...y.requests, e].slice(-_)
|
|
263
|
+
}, A("request", `${e.method} ${e.url} · ${e.status || "网络错误"} · ${Math.round(e.duration)} ms`, {
|
|
263
264
|
requestId: e.id,
|
|
264
265
|
failed: e.failed
|
|
265
|
-
}, e.time, e.actionId), e.failed &&
|
|
266
|
+
}, e.time, e.actionId), e.failed && L("接口调用失败", {
|
|
266
267
|
requestId: e.id,
|
|
267
268
|
url: e.url,
|
|
268
269
|
status: e.status,
|
|
269
270
|
message: e.message
|
|
270
271
|
}));
|
|
271
272
|
}
|
|
272
|
-
async function
|
|
273
|
+
async function B(e) {
|
|
273
274
|
if (!e.headers.get("content-type")?.includes("json")) return "[非 JSON 响应未采集]";
|
|
274
275
|
if (Number(e.headers.get("content-length")) > 16e3) return "[响应超过 16 KB,未采集]";
|
|
275
276
|
let t = e.clone().body?.getReader();
|
|
@@ -284,13 +285,13 @@ async function R(e) {
|
|
|
284
285
|
if (r += a.byteLength, r > 16e3) return t.cancel().catch(() => {}), "[响应超过 16 KB,已截断]";
|
|
285
286
|
n += i.decode(a, { stream: !0 });
|
|
286
287
|
}
|
|
287
|
-
return a ? "[响应预览超时,未采集]" :
|
|
288
|
+
return a ? "[响应预览超时,未采集]" : d(n + i.decode());
|
|
288
289
|
} finally {
|
|
289
290
|
clearTimeout(o), t.releaseLock();
|
|
290
291
|
}
|
|
291
292
|
}
|
|
292
|
-
function
|
|
293
|
-
if (
|
|
293
|
+
function V(r = {}) {
|
|
294
|
+
if (D) return D;
|
|
294
295
|
let a = (e) => {
|
|
295
296
|
try {
|
|
296
297
|
let t = new URL(e, location.href);
|
|
@@ -298,200 +299,200 @@ function z(r = {}) {
|
|
|
298
299
|
} catch {
|
|
299
300
|
return !1;
|
|
300
301
|
}
|
|
301
|
-
},
|
|
302
|
+
}, o = (e) => {
|
|
302
303
|
try {
|
|
303
304
|
return r.isBusinessFailure?.(e) === !0;
|
|
304
305
|
} catch {
|
|
305
306
|
return !1;
|
|
306
307
|
}
|
|
307
308
|
};
|
|
308
|
-
|
|
309
|
-
let
|
|
310
|
-
e.addEventListener(t, n, r),
|
|
309
|
+
C = !0;
|
|
310
|
+
let s = [], p = (e, t, n, r = !1) => {
|
|
311
|
+
e.addEventListener(t, n, r), s.push(() => e.removeEventListener(t, n, r));
|
|
311
312
|
};
|
|
312
313
|
p(document, "click", (r) => {
|
|
313
314
|
let a = r.target instanceof Element ? r.target : null;
|
|
314
315
|
if (a?.closest(n)) return;
|
|
315
316
|
let o = a?.closest(e);
|
|
316
|
-
o && !i(o) &&
|
|
317
|
+
o && !i(o) && A("click", "点击:" + j(o), { target: t(o) });
|
|
317
318
|
}, !0), p(document, "change", (e) => {
|
|
318
319
|
let r = e.target instanceof Element ? e.target : null;
|
|
319
|
-
!r || r.closest(n) || i(r) ||
|
|
320
|
+
!r || r.closest(n) || i(r) || A("change", "修改字段:" + j(r), {
|
|
320
321
|
target: t(r),
|
|
321
322
|
value: "[不采集输入值]"
|
|
322
323
|
});
|
|
323
324
|
}, !0);
|
|
324
|
-
let m = () =>
|
|
325
|
+
let m = () => A("route", "进入页面", { url: l(location.href) });
|
|
325
326
|
for (let e of ["pushState", "replaceState"]) {
|
|
326
327
|
let t = history[e], n = function(...e) {
|
|
327
328
|
let n = t.apply(this, e);
|
|
328
329
|
return m(), n;
|
|
329
330
|
};
|
|
330
|
-
history[e] = n,
|
|
331
|
+
history[e] = n, s.push(() => {
|
|
331
332
|
history[e] === n && (history[e] = t);
|
|
332
333
|
});
|
|
333
334
|
}
|
|
334
335
|
p(window, "popstate", m), p(window, "hashchange", m), p(window, "error", (e) => {
|
|
335
|
-
e instanceof ErrorEvent ?
|
|
336
|
+
e instanceof ErrorEvent ? L(e.message || "运行错误", e.error) : e.target instanceof Element && L("资源加载失败", {
|
|
336
337
|
tag: e.target.tagName,
|
|
337
|
-
url:
|
|
338
|
+
url: l(e.target.getAttribute("src") || e.target.getAttribute("href") || "")
|
|
338
339
|
});
|
|
339
|
-
}, !0), p(window, "unhandledrejection", (e) =>
|
|
340
|
-
let h = window.fetch,
|
|
341
|
-
if (
|
|
342
|
-
let n =
|
|
343
|
-
if (a(
|
|
344
|
-
let
|
|
345
|
-
id: ++
|
|
340
|
+
}, !0), p(window, "unhandledrejection", (e) => L("未处理的 Promise 错误", e.reason));
|
|
341
|
+
let h = window.fetch, g = async function(e, t) {
|
|
342
|
+
if (y.paused || !C) return h.call(this, e, t);
|
|
343
|
+
let n = w, r = performance.now(), i = Date.now(), s = typeof e == "string" ? e : e instanceof URL ? e.href : e.url;
|
|
344
|
+
if (a(s)) return h.call(this, e, t);
|
|
345
|
+
let u = f(s), p = {
|
|
346
|
+
id: ++x,
|
|
346
347
|
time: i,
|
|
347
|
-
actionId:
|
|
348
|
+
actionId: S,
|
|
348
349
|
source: "fetch",
|
|
349
350
|
method: (t?.method ?? (e instanceof Request ? e.method : "GET")).toUpperCase(),
|
|
350
|
-
url: s
|
|
351
|
+
url: l(s),
|
|
351
352
|
status: 0,
|
|
352
353
|
duration: 0,
|
|
353
354
|
failed: !1
|
|
354
355
|
};
|
|
355
356
|
try {
|
|
356
|
-
p.request =
|
|
357
|
+
p.request = u ? "[认证接口正文未采集]" : d(t?.body), p.resourceCode = c(new Headers(t?.headers ?? (e instanceof Request ? e.headers : void 0)).get("X-Resrc-Code") ?? "", 80);
|
|
357
358
|
} catch {}
|
|
358
359
|
try {
|
|
359
360
|
let i = await h.call(this, e, t);
|
|
360
361
|
return p.status = i.status, p.duration = performance.now() - r, p.failed = !i.ok, (async () => {
|
|
361
362
|
try {
|
|
362
|
-
p.response =
|
|
363
|
+
p.response = u ? "[认证接口正文未采集]" : await B(i), p.failed ||= o(p.response);
|
|
363
364
|
} catch {
|
|
364
365
|
p.response = "[响应不可读取]";
|
|
365
366
|
}
|
|
366
|
-
|
|
367
|
+
z(p, n);
|
|
367
368
|
})(), i;
|
|
368
369
|
} catch (e) {
|
|
369
|
-
throw p.duration = performance.now() - r, p.failed = !0, p.message =
|
|
370
|
+
throw p.duration = performance.now() - r, p.failed = !0, p.message = c(e instanceof Error ? e.message : String(e)), z(p, n), e;
|
|
370
371
|
}
|
|
371
372
|
};
|
|
372
|
-
window.fetch =
|
|
373
|
-
window.fetch ===
|
|
373
|
+
window.fetch = g, s.push(() => {
|
|
374
|
+
window.fetch === g && (window.fetch = h);
|
|
374
375
|
});
|
|
375
|
-
let
|
|
376
|
+
let _ = XMLHttpRequest.prototype.open, b = XMLHttpRequest.prototype.send, E = XMLHttpRequest.prototype.setRequestHeader, M = /* @__PURE__ */ new WeakMap(), N = function(e, t, n = !0, r, i) {
|
|
376
377
|
return M.set(this, {
|
|
377
378
|
method: e,
|
|
378
379
|
url: String(t)
|
|
379
|
-
}),
|
|
380
|
+
}), _.call(this, e, t, n, r, i);
|
|
380
381
|
}, P = function(e, t) {
|
|
381
|
-
let n =
|
|
382
|
-
return r && e.toLowerCase() === "x-resrc-code" && (r.resourceCode =
|
|
383
|
-
},
|
|
382
|
+
let n = E.call(this, e, t), r = M.get(this);
|
|
383
|
+
return r && e.toLowerCase() === "x-resrc-code" && (r.resourceCode = c(t, 80)), n;
|
|
384
|
+
}, F = function(e) {
|
|
384
385
|
let t = M.get(this);
|
|
385
|
-
if (!t || !
|
|
386
|
-
let n =
|
|
387
|
-
id: ++
|
|
386
|
+
if (!t || !C || y.paused || a(t.url)) return b.call(this, e);
|
|
387
|
+
let n = w, r = performance.now(), i = f(t.url), s = {
|
|
388
|
+
id: ++x,
|
|
388
389
|
time: Date.now(),
|
|
389
|
-
actionId:
|
|
390
|
+
actionId: S,
|
|
390
391
|
method: t.method.toUpperCase(),
|
|
391
|
-
url:
|
|
392
|
+
url: l(t.url),
|
|
392
393
|
source: "xhr",
|
|
393
394
|
resourceCode: t.resourceCode,
|
|
394
395
|
status: 0,
|
|
395
396
|
duration: 0,
|
|
396
397
|
failed: !1,
|
|
397
|
-
request: i ? "[认证接口正文未采集]" :
|
|
398
|
-
},
|
|
399
|
-
|
|
398
|
+
request: i ? "[认证接口正文未采集]" : d(e)
|
|
399
|
+
}, c = () => {
|
|
400
|
+
s.duration = performance.now() - r, s.status = this.status, s.failed = this.status === 0 || this.status >= 400;
|
|
400
401
|
try {
|
|
401
|
-
|
|
402
|
+
s.response = i ? "[认证接口正文未采集]" : this.responseType === "json" ? u(this.response) : this.responseType === "" || this.responseType === "text" ? d(this.responseText) : "[非文本响应未采集]", s.failed ||= o(s.response);
|
|
402
403
|
} catch {
|
|
403
|
-
|
|
404
|
+
s.response = "[响应不可读取]";
|
|
404
405
|
}
|
|
405
|
-
|
|
406
|
+
z(s, n);
|
|
406
407
|
};
|
|
407
|
-
this.addEventListener("loadend",
|
|
408
|
+
this.addEventListener("loadend", c, { once: !0 });
|
|
408
409
|
try {
|
|
409
|
-
return
|
|
410
|
+
return b.call(this, e);
|
|
410
411
|
} catch (e) {
|
|
411
|
-
throw this.removeEventListener("loadend",
|
|
412
|
+
throw this.removeEventListener("loadend", c), e;
|
|
412
413
|
}
|
|
413
414
|
};
|
|
414
|
-
XMLHttpRequest.prototype.open = N, XMLHttpRequest.prototype.send =
|
|
415
|
-
XMLHttpRequest.prototype.open === N && (XMLHttpRequest.prototype.open =
|
|
415
|
+
XMLHttpRequest.prototype.open = N, XMLHttpRequest.prototype.send = F, XMLHttpRequest.prototype.setRequestHeader = P, s.push(() => {
|
|
416
|
+
XMLHttpRequest.prototype.open === N && (XMLHttpRequest.prototype.open = _), XMLHttpRequest.prototype.send === F && (XMLHttpRequest.prototype.send = b), XMLHttpRequest.prototype.setRequestHeader === P && (XMLHttpRequest.prototype.setRequestHeader = E);
|
|
416
417
|
});
|
|
417
|
-
let
|
|
418
|
+
let I = (e, t) => {
|
|
418
419
|
try {
|
|
419
420
|
let n = new PerformanceObserver((e) => {
|
|
420
|
-
|
|
421
|
-
...
|
|
422
|
-
metrics: { ...
|
|
423
|
-
},
|
|
421
|
+
C && !y.paused && (e.getEntries().forEach(t), y = {
|
|
422
|
+
...y,
|
|
423
|
+
metrics: { ...y.metrics }
|
|
424
|
+
}, H(), O());
|
|
424
425
|
});
|
|
425
426
|
n.observe({
|
|
426
427
|
type: e,
|
|
427
428
|
buffered: !0
|
|
428
|
-
}),
|
|
429
|
+
}), s.push(() => n.disconnect());
|
|
429
430
|
} catch {}
|
|
430
431
|
};
|
|
431
|
-
|
|
432
|
+
I("navigation", (e) => {
|
|
432
433
|
let t = e;
|
|
433
|
-
|
|
434
|
-
}),
|
|
435
|
-
e.name === "first-contentful-paint" && (
|
|
436
|
-
}),
|
|
437
|
-
|
|
438
|
-
}),
|
|
439
|
-
|
|
434
|
+
y.metrics.TTFB = t.responseStart, y.metrics.DOMContentLoaded = t.domContentLoadedEventEnd, y.metrics.load = t.loadEventEnd;
|
|
435
|
+
}), I("paint", (e) => {
|
|
436
|
+
e.name === "first-contentful-paint" && (y.metrics.FCP = e.startTime);
|
|
437
|
+
}), I("largest-contentful-paint", (e) => {
|
|
438
|
+
y.metrics.LCP = e.startTime;
|
|
439
|
+
}), I("longtask", (e) => {
|
|
440
|
+
y.metrics.longTasks = (y.metrics.longTasks ?? 0) + 1, y.metrics.longTaskDuration = (y.metrics.longTaskDuration ?? 0) + e.duration;
|
|
440
441
|
let t = Date.now();
|
|
441
|
-
|
|
442
|
-
...
|
|
442
|
+
y = {
|
|
443
|
+
...y,
|
|
443
444
|
performance: {
|
|
444
|
-
...
|
|
445
|
-
longTasks: [...
|
|
445
|
+
...y.performance,
|
|
446
|
+
longTasks: [...y.performance.longTasks.filter((e) => t - e.time <= 3e4), {
|
|
446
447
|
time: performance.timeOrigin + e.startTime,
|
|
447
448
|
duration: e.duration
|
|
448
449
|
}].slice(-200)
|
|
449
450
|
}
|
|
450
|
-
}, e.duration > 200 &&
|
|
451
|
+
}, e.duration > 200 && A("performance", "主线程长任务", { duration: Math.round(e.duration) });
|
|
451
452
|
});
|
|
452
|
-
let
|
|
453
|
-
|
|
453
|
+
let R = 0, V = 0, U = 0;
|
|
454
|
+
I("layout-shift", (e) => {
|
|
454
455
|
let t = e;
|
|
455
|
-
t.hadRecentInput || ((e.startTime -
|
|
456
|
+
t.hadRecentInput || ((e.startTime - V > 1e3 || e.startTime - R > 5e3) && (R = e.startTime, U = 0), V = e.startTime, U += t.value, y.metrics.CLS = Math.max(y.metrics.CLS ?? 0, U));
|
|
456
457
|
});
|
|
457
458
|
let W = setInterval(() => {
|
|
458
|
-
|
|
459
|
+
k(), O();
|
|
459
460
|
}, 1e4);
|
|
460
|
-
|
|
461
|
+
s.push(() => clearInterval(W));
|
|
461
462
|
let G = () => {
|
|
462
|
-
if (!
|
|
463
|
+
if (!C || y.paused || document.visibilityState === "hidden") return;
|
|
463
464
|
let e = performance.memory, t = Date.now(), n = e && Number.isFinite(e.usedJSHeapSize) && e.usedJSHeapSize >= 0 && Number.isFinite(e.jsHeapSizeLimit) && e.jsHeapSizeLimit > 0 ? [{
|
|
464
465
|
time: t,
|
|
465
466
|
used: e.usedJSHeapSize,
|
|
466
467
|
limit: e.jsHeapSizeLimit
|
|
467
468
|
}] : [];
|
|
468
|
-
|
|
469
|
-
...
|
|
469
|
+
y = {
|
|
470
|
+
...y,
|
|
470
471
|
performance: {
|
|
471
|
-
heapSamples: [...
|
|
472
|
-
longTasks:
|
|
472
|
+
heapSamples: [...y.performance.heapSamples, ...n].filter((e) => t - e.time <= v).slice(-180),
|
|
473
|
+
longTasks: y.performance.longTasks.filter((e) => t - e.time <= 3e4)
|
|
473
474
|
}
|
|
474
|
-
},
|
|
475
|
+
}, H(), O();
|
|
475
476
|
}, K = setInterval(G, 5e3);
|
|
476
|
-
return
|
|
477
|
-
|
|
478
|
-
},
|
|
477
|
+
return s.push(() => clearInterval(K)), G(), m(), D = () => {
|
|
478
|
+
C = !1, w++, s.reverse().forEach((e) => e()), T && clearTimeout(T), T = void 0, D = void 0;
|
|
479
|
+
}, D;
|
|
479
480
|
}
|
|
480
|
-
function
|
|
481
|
-
|
|
482
|
-
...
|
|
481
|
+
function H() {
|
|
482
|
+
y = {
|
|
483
|
+
...y,
|
|
483
484
|
performanceUpdatedAt: Date.now()
|
|
484
485
|
};
|
|
485
|
-
let e =
|
|
486
|
-
for (let t of e)
|
|
486
|
+
let e = h(y.metrics, y.performance, y.performanceUpdatedAt), t = new Set(e.map((e) => e.id));
|
|
487
|
+
for (let t of e) b.has(t.id) || A("performance", t.title, {
|
|
487
488
|
evidence: t.evidence,
|
|
488
489
|
rule: t.rule
|
|
489
490
|
});
|
|
490
|
-
|
|
491
|
+
b = t;
|
|
491
492
|
}
|
|
492
493
|
//#endregion
|
|
493
494
|
//#region src/utils/diagnostics/snapshot.ts
|
|
494
|
-
function
|
|
495
|
+
function U(e) {
|
|
495
496
|
if (e.length > 2 * 1024 * 1024) throw Error("快照不能超过 2 MB");
|
|
496
497
|
let t = JSON.parse(e);
|
|
497
498
|
if (!t || t.schema !== "zhidao-research-assistant" || t.version !== 1 || typeof t.capturedAt != "string" || !Number.isFinite(Date.parse(t.capturedAt)) || typeof t.reason != "string" || typeof t.page?.url != "string" || !t.environment || typeof t.environment != "object" || !Array.isArray(t.events) || t.events.length > 300 || !Array.isArray(t.requests) || t.requests.length > 60 || !t.metrics || typeof t.metrics != "object") throw Error("不是受支持的研发小蜜快照");
|
|
@@ -513,21 +514,21 @@ function V(e) {
|
|
|
513
514
|
schema: t.schema,
|
|
514
515
|
version: 1,
|
|
515
516
|
capturedAt: t.capturedAt,
|
|
516
|
-
reason:
|
|
517
|
-
feedback: typeof t.feedback == "string" ?
|
|
517
|
+
reason: c(t.reason),
|
|
518
|
+
feedback: typeof t.feedback == "string" ? c(t.feedback, 1e3) : void 0,
|
|
518
519
|
page: {
|
|
519
|
-
...
|
|
520
|
-
url:
|
|
520
|
+
...u(t.page),
|
|
521
|
+
url: l(t.page.url)
|
|
521
522
|
},
|
|
522
523
|
environment: {
|
|
523
|
-
...
|
|
524
|
+
...u(t.environment),
|
|
524
525
|
...Object.fromEntries([
|
|
525
526
|
"cookies",
|
|
526
527
|
"localStorageKeys",
|
|
527
528
|
"sessionStorageKeys"
|
|
528
529
|
].map((e) => {
|
|
529
530
|
let n = t.environment[e];
|
|
530
|
-
return [e, Array.isArray(n) ? n.slice(0, 60).filter((e) => typeof e == "string").map((e) =>
|
|
531
|
+
return [e, Array.isArray(n) ? n.slice(0, 60).filter((e) => typeof e == "string").map((e) => c(e, 100)) : []];
|
|
531
532
|
}))
|
|
532
533
|
},
|
|
533
534
|
metrics: Object.fromEntries(Object.entries(t.metrics).filter(([, e]) => typeof e == "number" && Number.isFinite(e)).slice(0, 30)),
|
|
@@ -543,12 +544,12 @@ function V(e) {
|
|
|
543
544
|
}))
|
|
544
545
|
} } : {},
|
|
545
546
|
events: t.events.map((e) => ({
|
|
546
|
-
...
|
|
547
|
-
page:
|
|
547
|
+
...u(e),
|
|
548
|
+
page: l(e.page)
|
|
548
549
|
})),
|
|
549
550
|
requests: t.requests.map((e) => ({
|
|
550
|
-
...
|
|
551
|
-
url:
|
|
551
|
+
...u(e),
|
|
552
|
+
url: l(e.url)
|
|
552
553
|
})),
|
|
553
554
|
limits: {
|
|
554
555
|
events: 300,
|
|
@@ -557,54 +558,54 @@ function V(e) {
|
|
|
557
558
|
}
|
|
558
559
|
};
|
|
559
560
|
}
|
|
560
|
-
function
|
|
561
|
+
function W(e, t) {
|
|
561
562
|
let n = JSON.stringify({
|
|
562
563
|
...e,
|
|
563
|
-
feedback:
|
|
564
|
+
feedback: c(t || e.feedback || "", 1e3)
|
|
564
565
|
}, null, 2), r = new Blob([n], { type: "application/json;charset=utf-8" }), i = URL.createObjectURL(r), a = document.createElement("a");
|
|
565
566
|
a.href = i, a.download = `研发小蜜快照_${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.json`, document.body.append(a), a.click(), a.remove(), setTimeout(() => URL.revokeObjectURL(i), 3e4);
|
|
566
567
|
}
|
|
567
568
|
//#endregion
|
|
568
569
|
//#region src/utils/automation/recorder.ts
|
|
569
|
-
var
|
|
570
|
+
var G = () => ({
|
|
570
571
|
schema: "zhidao-recorded-case",
|
|
571
572
|
version: 1,
|
|
572
573
|
name: "页面操作录制",
|
|
573
574
|
path: typeof location > "u" ? "/" : location.pathname,
|
|
574
575
|
steps: []
|
|
575
|
-
}),
|
|
576
|
+
}), K = {
|
|
576
577
|
recording: !1,
|
|
577
|
-
draft:
|
|
578
|
+
draft: G(),
|
|
578
579
|
saved: null
|
|
579
|
-
},
|
|
580
|
-
function
|
|
581
|
-
|
|
582
|
-
...
|
|
580
|
+
}, q = /* @__PURE__ */ new Set(), J = () => {};
|
|
581
|
+
function Y(e) {
|
|
582
|
+
K = {
|
|
583
|
+
...K,
|
|
583
584
|
...e
|
|
584
|
-
},
|
|
585
|
+
}, q.forEach((e) => e());
|
|
585
586
|
}
|
|
586
|
-
function
|
|
587
|
-
if (
|
|
588
|
-
|
|
587
|
+
function X(e) {
|
|
588
|
+
if (K.draft.steps.length >= 100) {
|
|
589
|
+
Z.stop();
|
|
589
590
|
return;
|
|
590
591
|
}
|
|
591
|
-
let t = [...
|
|
592
|
-
e.kind === "fill" && n?.kind === "fill" && n.target?.selector === e.target?.selector && t.pop(), t.push(e),
|
|
593
|
-
...
|
|
592
|
+
let t = [...K.draft.steps], n = t.at(-1);
|
|
593
|
+
e.kind === "fill" && n?.kind === "fill" && n.target?.selector === e.target?.selector && t.pop(), t.push(e), Y({ draft: {
|
|
594
|
+
...K.draft,
|
|
594
595
|
steps: t
|
|
595
596
|
} });
|
|
596
597
|
}
|
|
597
|
-
var
|
|
598
|
+
var Z = {
|
|
598
599
|
subscribe(e) {
|
|
599
|
-
return
|
|
600
|
-
|
|
600
|
+
return q.add(e), () => {
|
|
601
|
+
q.delete(e);
|
|
601
602
|
};
|
|
602
603
|
},
|
|
603
|
-
getState: () =>
|
|
604
|
+
getState: () => K,
|
|
604
605
|
start() {
|
|
605
|
-
|
|
606
|
+
J(), Y({
|
|
606
607
|
recording: !0,
|
|
607
|
-
draft:
|
|
608
|
+
draft: G()
|
|
608
609
|
});
|
|
609
610
|
let t = -Infinity, a = (a) => {
|
|
610
611
|
if (!a.isTrusted || !(a.target instanceof Element) || a.target.closest(n) || a instanceof MouseEvent && a.type === "click" && a.detail === 0 && a.timeStamp - t < 500) return;
|
|
@@ -612,8 +613,8 @@ var Y = {
|
|
|
612
613
|
if (!o) return;
|
|
613
614
|
if (i(o)) {
|
|
614
615
|
if (a.type === "input") {
|
|
615
|
-
let e =
|
|
616
|
-
(e?.kind !== "unsupported" || e.value !== "敏感字段输入未录制") &&
|
|
616
|
+
let e = K.draft.steps.at(-1);
|
|
617
|
+
(e?.kind !== "unsupported" || e.value !== "敏感字段输入未录制") && X({
|
|
617
618
|
kind: "unsupported",
|
|
618
619
|
value: "敏感字段输入未录制"
|
|
619
620
|
});
|
|
@@ -628,28 +629,28 @@ var Y = {
|
|
|
628
629
|
"range",
|
|
629
630
|
"color"
|
|
630
631
|
].includes(o.type)) {
|
|
631
|
-
a.type === "change" &&
|
|
632
|
+
a.type === "change" && X({
|
|
632
633
|
kind: "unsupported",
|
|
633
634
|
value: `${s.label}:该控件需要手动适配`
|
|
634
635
|
});
|
|
635
636
|
return;
|
|
636
637
|
}
|
|
637
|
-
if (a.type === "input" && (o instanceof HTMLInputElement || o instanceof HTMLTextAreaElement)) ["checkbox", "radio"].includes(o.type) ||
|
|
638
|
+
if (a.type === "input" && (o instanceof HTMLInputElement || o instanceof HTMLTextAreaElement)) ["checkbox", "radio"].includes(o.type) || X({
|
|
638
639
|
kind: "fill",
|
|
639
640
|
target: s,
|
|
640
641
|
value: o.value
|
|
641
642
|
});
|
|
642
|
-
else if (a.type === "change" && o instanceof HTMLSelectElement)
|
|
643
|
+
else if (a.type === "change" && o instanceof HTMLSelectElement) X({
|
|
643
644
|
kind: "select",
|
|
644
645
|
target: s,
|
|
645
646
|
value: o.value
|
|
646
647
|
});
|
|
647
|
-
else if (a.type === "change" && o instanceof HTMLInputElement && ["checkbox", "radio"].includes(o.type))
|
|
648
|
+
else if (a.type === "change" && o instanceof HTMLInputElement && ["checkbox", "radio"].includes(o.type)) X({
|
|
648
649
|
kind: "check",
|
|
649
650
|
target: s,
|
|
650
651
|
checked: o.checked
|
|
651
652
|
});
|
|
652
|
-
else if (a.type === "click" && !(o instanceof HTMLSelectElement) && !(o instanceof HTMLInputElement && ["checkbox", "radio"].includes(o.type)))
|
|
653
|
+
else if (a.type === "click" && !(o instanceof HTMLSelectElement) && !(o instanceof HTMLInputElement && ["checkbox", "radio"].includes(o.type))) X({
|
|
653
654
|
kind: "click",
|
|
654
655
|
target: s
|
|
655
656
|
});
|
|
@@ -659,7 +660,7 @@ var Y = {
|
|
|
659
660
|
"Tab"
|
|
660
661
|
].includes(a.key)) {
|
|
661
662
|
if (a.key === "Enter" && o.matches("button,[role=\"button\"]")) return;
|
|
662
|
-
a.key === "Enter" && (t = a.timeStamp),
|
|
663
|
+
a.key === "Enter" && (t = a.timeStamp), X({
|
|
663
664
|
kind: "press",
|
|
664
665
|
target: s,
|
|
665
666
|
value: a.key
|
|
@@ -672,7 +673,7 @@ var Y = {
|
|
|
672
673
|
"change",
|
|
673
674
|
"keydown"
|
|
674
675
|
]) document.addEventListener(e, a, !0);
|
|
675
|
-
|
|
676
|
+
J = () => {
|
|
676
677
|
for (let e of [
|
|
677
678
|
"click",
|
|
678
679
|
"input",
|
|
@@ -682,36 +683,36 @@ var Y = {
|
|
|
682
683
|
};
|
|
683
684
|
},
|
|
684
685
|
stop() {
|
|
685
|
-
|
|
686
|
+
J(), Y({ recording: !1 });
|
|
686
687
|
},
|
|
687
688
|
edit(e) {
|
|
688
|
-
|
|
689
|
+
Y({ draft: e });
|
|
689
690
|
},
|
|
690
691
|
loadDraft(e) {
|
|
691
|
-
if (
|
|
692
|
-
|
|
692
|
+
if (K.recording) throw Error("请先结束主动录制,再生成时间线草稿");
|
|
693
|
+
Y({ draft: structuredClone(e) });
|
|
693
694
|
},
|
|
694
695
|
checkpoint(e) {
|
|
695
|
-
|
|
696
|
+
X({
|
|
696
697
|
kind: "assert-text",
|
|
697
698
|
value: e
|
|
698
699
|
});
|
|
699
700
|
},
|
|
700
701
|
save(e) {
|
|
701
|
-
|
|
702
|
+
Y({
|
|
702
703
|
saved: structuredClone(e),
|
|
703
704
|
draft: e
|
|
704
705
|
});
|
|
705
706
|
},
|
|
706
707
|
clear() {
|
|
707
|
-
|
|
708
|
+
J(), Y({
|
|
708
709
|
recording: !1,
|
|
709
|
-
draft:
|
|
710
|
+
draft: G(),
|
|
710
711
|
saved: null
|
|
711
712
|
});
|
|
712
713
|
}
|
|
713
714
|
};
|
|
714
715
|
//#endregion
|
|
715
|
-
export {
|
|
716
|
+
export { U as a, P as c, V as d, h as f, l as g, c as h, W as i, I as l, m, o as n, R as o, p, Z as r, F as s, a as t, L as u };
|
|
716
717
|
|
|
717
|
-
//# sourceMappingURL=
|
|
718
|
+
//# sourceMappingURL=core-DWx1hG8M.js.map
|