@jshookmcp/jshook 0.2.7 → 0.2.9
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 +36 -5
- package/README.zh.md +36 -5
- package/dist/{AntiCheatDetector-S8VRj-dD.mjs → AntiCheatDetector-BNk-EoBt.mjs} +3 -3
- package/dist/{CodeInjector-4Z3ngPoX.mjs → CodeInjector-Cq8q01kp.mjs} +5 -5
- package/dist/ConsoleMonitor-CPVQW1Y-.mjs +2201 -0
- package/dist/{DarwinAPI-B8hg_yhz.mjs → DarwinAPI-BNPxu0RH.mjs} +1 -1
- package/dist/DetailedDataManager-BQQcxh64.mjs +217 -0
- package/dist/EventBus-DgPmwpeu.mjs +141 -0
- package/dist/EvidenceGraphBridge-SFesNera.mjs +153 -0
- package/dist/{ExtensionManager-CZ6IveoV.mjs → ExtensionManager-CWYgw0YW.mjs} +13 -6
- package/dist/{FingerprintManager-BVxFJL2-.mjs → FingerprintManager-gzWtkKuf.mjs} +1 -1
- package/dist/{HardwareBreakpoint-DK1yjWkV.mjs → HardwareBreakpoint-B9gZCdFP.mjs} +3 -3
- package/dist/{HeapAnalyzer-CEbo10xU.mjs → HeapAnalyzer-BLDH0dCv.mjs} +4 -4
- package/dist/HookGeneratorBuilders.core.generators.storage-CtcdK78Q.mjs +639 -0
- package/dist/InstrumentationSession-CvPC7Jwy.mjs +244 -0
- package/dist/{MemoryController-DdtnBdD4.mjs → MemoryController-CbVdCIJF.mjs} +3 -3
- package/dist/{MemoryScanSession-RMixN3bX.mjs → MemoryScanSession-BsDZbLYm.mjs} +81 -78
- package/dist/{MemoryScanner-QjK4ld0B.mjs → MemoryScanner-Bcpml6II.mjs} +44 -18
- package/dist/{NativeMemoryManager.impl-CB6gJ0NM.mjs → NativeMemoryManager.impl-dZtA1ZGn.mjs} +14 -53
- package/dist/{NativeMemoryManager.utils-BML4q1ry.mjs → NativeMemoryManager.utils-B-FjA2mJ.mjs} +1 -1
- package/dist/{PEAnalyzer-CK0xe0Fs.mjs → PEAnalyzer-D1lzJ_VG.mjs} +2 -2
- package/dist/PageController-Bqm2kZ_X.mjs +417 -0
- package/dist/{PointerChainEngine-Cd73qu5b.mjs → PointerChainEngine-BOhyVsjx.mjs} +4 -4
- package/dist/PrerequisiteError-Dl33Svkz.mjs +20 -0
- package/dist/ResponseBuilder-D3iFYx2N.mjs +143 -0
- package/dist/ReverseEvidenceGraph-Dlsk94LC.mjs +269 -0
- package/dist/ScriptManager-aHHq0X7U.mjs +3000 -0
- package/dist/{Speedhack-CeF0XmEz.mjs → Speedhack-CqdIFlQl.mjs} +2 -2
- package/dist/{StructureAnalyzer-D4GkMduU.mjs → StructureAnalyzer-DhFaPvRO.mjs} +3 -3
- package/dist/ToolCatalog-C0JGZoOm.mjs +582 -0
- package/dist/ToolError-jh9whhMd.mjs +15 -0
- package/dist/ToolProbe-oC7aPrkv.mjs +45 -0
- package/dist/ToolRegistry-BjaF4oNz.mjs +131 -0
- package/dist/ToolRouter.policy-BWV67ZK-.mjs +304 -0
- package/dist/TraceRecorder-DgxyVbdQ.mjs +519 -0
- package/dist/{Win32API-Bc0QnQsN.mjs → Win32API-CePkipZY.mjs} +1 -1
- package/dist/{Win32Debug-DUHt9XUn.mjs → Win32Debug-BvKs-gxc.mjs} +2 -2
- package/dist/WorkflowEngine-CuvkZtWu.mjs +598 -0
- package/dist/analysis-CL9uACt9.mjs +463 -0
- package/dist/antidebug-CqDTB_uk.mjs +1081 -0
- package/dist/artifactRetention-CFEprwPw.mjs +591 -0
- package/dist/artifacts-Bk2-_uPq.mjs +59 -0
- package/dist/betterSqlite3-0pqusHHH.mjs +74 -0
- package/dist/binary-instrument-CXfpx6fT.mjs +979 -0
- package/dist/bind-helpers-xFfRF-qm.mjs +22 -0
- package/dist/boringssl-inspector-BH2D3VKc.mjs +180 -0
- package/dist/browser-BpOr5PEx.mjs +4082 -0
- package/dist/concurrency-Bt0yv1kJ.mjs +41 -0
- package/dist/{constants-CCvsN80K.mjs → constants-B0OANIBL.mjs} +88 -46
- package/dist/coordination-qUbyF8KU.mjs +259 -0
- package/dist/debugger-gnKxRSN0.mjs +1271 -0
- package/dist/definitions-6M-eejaT.mjs +53 -0
- package/dist/definitions-B18eyf0B.mjs +18 -0
- package/dist/definitions-B3QdlrHv.mjs +34 -0
- package/dist/definitions-B4rAvHNZ.mjs +63 -0
- package/dist/definitions-BB_4jnmy.mjs +37 -0
- package/dist/definitions-BMfYXoNC.mjs +43 -0
- package/dist/definitions-Beid2EB3.mjs +27 -0
- package/dist/definitions-C1UvM5Iy.mjs +126 -0
- package/dist/definitions-CXEI7QC72.mjs +216 -0
- package/dist/definitions-C_4r7Fo-2.mjs +14 -0
- package/dist/definitions-CkFDALoa.mjs +26 -0
- package/dist/definitions-Cke7zEb8.mjs +94 -0
- package/dist/definitions-ClJLzsJQ.mjs +25 -0
- package/dist/definitions-Cq-zroAU.mjs +28 -0
- package/dist/definitions-Cy3Sl6gV.mjs +34 -0
- package/dist/definitions-D3VsGcvz.mjs +47 -0
- package/dist/definitions-DVGfrn7y.mjs +96 -0
- package/dist/definitions-LKpC3-nL.mjs +9 -0
- package/dist/definitions-bAhHQJq9.mjs +359 -0
- package/dist/encoding-Bvz5jLRv.mjs +1065 -0
- package/dist/evidence-graph-bridge-C_fv9PuC.mjs +135 -0
- package/dist/{factory-CibqTNC8.mjs → factory-DxlGh9Xf.mjs} +37 -52
- package/dist/graphql-DYWzJ29s.mjs +1026 -0
- package/dist/handlers-9sAbfIg-.mjs +2552 -0
- package/dist/handlers-Bl8zkwz1.mjs +2716 -0
- package/dist/handlers-C67ktuRN.mjs +710 -0
- package/dist/handlers-C87g8oCe.mjs +276 -0
- package/dist/handlers-CTsDAO6p.mjs +681 -0
- package/dist/handlers-Cgyg6c0U.mjs +645 -0
- package/dist/handlers-D6j6yka7.mjs +2124 -0
- package/dist/handlers-DdFzXLvF.mjs +446 -0
- package/dist/handlers-DeLOCd5m.mjs +799 -0
- package/dist/handlers-DlCJN4Td.mjs +757 -0
- package/dist/handlers-DxGIq15_2.mjs +917 -0
- package/dist/handlers-U6L4xhuF.mjs +585 -0
- package/dist/handlers-tB9Mp9ZK.mjs +84 -0
- package/dist/handlers-tiy7EIBp.mjs +572 -0
- package/dist/handlers.impl-DS0d9fUw.mjs +761 -0
- package/dist/hooks-CzCWByww.mjs +898 -0
- package/dist/index.mjs +384 -155
- package/dist/{logger-BmWzC2lM.mjs → logger-Dh_xb7_2.mjs} +14 -6
- package/dist/maintenance-P7ePRXQC.mjs +830 -0
- package/dist/manifest-2ToTpjv8.mjs +106 -0
- package/dist/manifest-3g71z6Bg.mjs +79 -0
- package/dist/manifest-82baTv4U.mjs +45 -0
- package/dist/manifest-B3QVVeBS.mjs +82 -0
- package/dist/manifest-BB2J8IMJ.mjs +149 -0
- package/dist/manifest-BKbgbSiY.mjs +60 -0
- package/dist/manifest-Bcf-TJzH.mjs +848 -0
- package/dist/manifest-BmtZzQiQ2.mjs +45 -0
- package/dist/manifest-Bnd7kqEY.mjs +55 -0
- package/dist/manifest-BqQX6OQC2.mjs +65 -0
- package/dist/manifest-BqrQ4Tpj.mjs +81 -0
- package/dist/manifest-Br4RPFt5.mjs +370 -0
- package/dist/manifest-C5qDjysN.mjs +107 -0
- package/dist/manifest-C9RT5nk32.mjs +34 -0
- package/dist/manifest-CAhOuvSl.mjs +204 -0
- package/dist/manifest-CBYWCUBJ.mjs +51 -0
- package/dist/manifest-CFADCRa1.mjs +37 -0
- package/dist/manifest-CQVhavRF.mjs +114 -0
- package/dist/manifest-CT7zZBV1.mjs +48 -0
- package/dist/manifest-CV12bcrF.mjs +121 -0
- package/dist/manifest-CXsRWjjI.mjs +224 -0
- package/dist/manifest-CZLUCfG02.mjs +95 -0
- package/dist/manifest-D6phHKFd.mjs +131 -0
- package/dist/manifest-DCyjf4n2.mjs +294 -0
- package/dist/manifest-DHsnKgP6.mjs +60 -0
- package/dist/manifest-Df_dliIe.mjs +55 -0
- package/dist/manifest-Dh8WBmEW.mjs +129 -0
- package/dist/manifest-DhKRAT8_.mjs +92 -0
- package/dist/manifest-DlpTj4ic2.mjs +193 -0
- package/dist/manifest-DrbmZcFl2.mjs +253 -0
- package/dist/manifest-DuwHjUa5.mjs +70 -0
- package/dist/manifest-DzwvxPJX.mjs +38 -0
- package/dist/manifest-NXctwWQq.mjs +68 -0
- package/dist/manifest-Sc_0JQ13.mjs +418 -0
- package/dist/manifest-gZ4s_UtG.mjs +96 -0
- package/dist/manifest-qSleDqdO.mjs +1023 -0
- package/dist/modules-C184v-S9.mjs +11365 -0
- package/dist/mojo-ipc-B_H61Afw.mjs +525 -0
- package/dist/network-671Cw6hV.mjs +3346 -0
- package/dist/{artifacts-BbdOMET5.mjs → outputPaths-B1uGmrWZ.mjs} +219 -212
- package/dist/parse-args-BlRjqlkL.mjs +39 -0
- package/dist/platform-WmNn8Sxb.mjs +2070 -0
- package/dist/process-QcbIy5Zq.mjs +1401 -0
- package/dist/proxy-DqNs0bAd.mjs +170 -0
- package/dist/registry-D-6e18lB.mjs +34 -0
- package/dist/response-BQVP-xUn.mjs +28 -0
- package/dist/server/plugin-api.mjs +2 -2
- package/dist/shared-state-board-DV-dpHFJ.mjs +586 -0
- package/dist/sourcemap-Dq8ez8vS.mjs +650 -0
- package/dist/ssrf-policy-ZaUfvhq7.mjs +166 -0
- package/dist/streaming-BUQ0VJsg.mjs +725 -0
- package/dist/tool-builder-DCbIC5Eo.mjs +186 -0
- package/dist/transform-CiYJfNX0.mjs +1007 -0
- package/dist/types-Bx92KJfT.mjs +4 -0
- package/dist/wasm-DQTnHDs4.mjs +531 -0
- package/dist/workflow-f3xJOcjx.mjs +725 -0
- package/package.json +48 -78
- package/dist/ExtensionManager-DqUSOamB.mjs +0 -2
- package/dist/ToolCatalog-CnwmMIw3.mjs +0 -61483
- package/dist/{CacheAdapters-CzFNpD9a.mjs → CacheAdapters-CDe5WPSV.mjs} +0 -0
- package/dist/{StealthVerifier-BzBCFiwx.mjs → StealthVerifier-Bo4T3bz8.mjs} +0 -0
- package/dist/{VersionDetector-CNXcvD46.mjs → VersionDetector-CwVLVdDM.mjs} +0 -0
- package/dist/{formatAddress-ChCSIRWT.mjs → formatAddress-DVkj9kpI.mjs} +0 -0
- package/dist/{types-BBjOqye-.mjs → types-CPhOReNX.mjs} +1 -1
|
@@ -0,0 +1,725 @@
|
|
|
1
|
+
import { t as logger } from "./logger-Dh_xb7_2.mjs";
|
|
2
|
+
import { Ar as WS_PAYLOAD_SAMPLE_LIMIT, kr as WS_PAYLOAD_PREVIEW_LIMIT } from "./constants-B0OANIBL.mjs";
|
|
3
|
+
import { o as evaluateOnNewDocumentWithTimeout, s as evaluateWithTimeout } from "./PageController-Bqm2kZ_X.mjs";
|
|
4
|
+
import "./definitions-BB_4jnmy.mjs";
|
|
5
|
+
//#region src/utils/RingBuffer.ts
|
|
6
|
+
/**
|
|
7
|
+
* Fixed-capacity ring buffer with O(1) push/shift.
|
|
8
|
+
* Drop-in replacement for arrays used as bounded FIFO queues.
|
|
9
|
+
*/
|
|
10
|
+
var RingBuffer = class {
|
|
11
|
+
buf;
|
|
12
|
+
head = 0;
|
|
13
|
+
tail = 0;
|
|
14
|
+
count = 0;
|
|
15
|
+
constructor(capacity) {
|
|
16
|
+
this.capacity = capacity;
|
|
17
|
+
this.buf = Array.from({ length: capacity });
|
|
18
|
+
}
|
|
19
|
+
get length() {
|
|
20
|
+
return this.count;
|
|
21
|
+
}
|
|
22
|
+
push(item) {
|
|
23
|
+
if (this.count === this.buf.length) if (this.buf.length < this.capacity) this.grow();
|
|
24
|
+
else {
|
|
25
|
+
this.buf[this.tail] = item;
|
|
26
|
+
this.tail = (this.tail + 1) % this.buf.length;
|
|
27
|
+
this.head = (this.head + 1) % this.buf.length;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
this.buf[this.tail] = item;
|
|
31
|
+
this.tail = (this.tail + 1) % this.buf.length;
|
|
32
|
+
this.count++;
|
|
33
|
+
}
|
|
34
|
+
shift() {
|
|
35
|
+
if (this.count === 0) return void 0;
|
|
36
|
+
const item = this.buf[this.head];
|
|
37
|
+
this.buf[this.head] = void 0;
|
|
38
|
+
this.head = (this.head + 1) % this.buf.length;
|
|
39
|
+
this.count--;
|
|
40
|
+
return item;
|
|
41
|
+
}
|
|
42
|
+
clear() {
|
|
43
|
+
this.buf = Array.from({ length: Math.min(64, this.capacity) });
|
|
44
|
+
this.head = 0;
|
|
45
|
+
this.tail = 0;
|
|
46
|
+
this.count = 0;
|
|
47
|
+
}
|
|
48
|
+
*[Symbol.iterator]() {
|
|
49
|
+
for (let i = 0; i < this.count; i++) yield this.buf[(this.head + i) % this.buf.length];
|
|
50
|
+
}
|
|
51
|
+
toArray() {
|
|
52
|
+
const result = Array.from({ length: this.count });
|
|
53
|
+
for (let i = 0; i < this.count; i++) result[i] = this.buf[(this.head + i) % this.buf.length];
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
map(fn) {
|
|
57
|
+
const result = Array.from({ length: this.count });
|
|
58
|
+
for (let i = 0; i < this.count; i++) result[i] = fn(this.buf[(this.head + i) % this.buf.length], i);
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
grow() {
|
|
62
|
+
const newSize = Math.min(this.buf.length * 2, this.capacity);
|
|
63
|
+
const newBuf = Array.from({ length: newSize });
|
|
64
|
+
for (let i = 0; i < this.count; i++) newBuf[i] = this.buf[(this.head + i) % this.buf.length];
|
|
65
|
+
this.buf = newBuf;
|
|
66
|
+
this.head = 0;
|
|
67
|
+
this.tail = this.count;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/server/domains/streaming/handlers/shared.ts
|
|
72
|
+
function createStreamingSharedState(collector) {
|
|
73
|
+
return {
|
|
74
|
+
collector,
|
|
75
|
+
wsSession: null,
|
|
76
|
+
wsListeners: null,
|
|
77
|
+
wsConfig: {
|
|
78
|
+
enabled: false,
|
|
79
|
+
maxFrames: 1e3
|
|
80
|
+
},
|
|
81
|
+
wsFramesByRequest: /* @__PURE__ */ new Map(),
|
|
82
|
+
wsFrameOrder: new RingBuffer(1e3),
|
|
83
|
+
wsConnections: /* @__PURE__ */ new Map(),
|
|
84
|
+
sseConfig: { maxEvents: 2e3 }
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function asJson(payload) {
|
|
88
|
+
return { content: [{
|
|
89
|
+
type: "text",
|
|
90
|
+
text: JSON.stringify(payload, null, 2)
|
|
91
|
+
}] };
|
|
92
|
+
}
|
|
93
|
+
function parseOptionalStringArg(value) {
|
|
94
|
+
if (typeof value !== "string") return void 0;
|
|
95
|
+
const normalized = value.trim();
|
|
96
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
97
|
+
}
|
|
98
|
+
function parseNumberArg(value, options) {
|
|
99
|
+
let parsed;
|
|
100
|
+
if (typeof value === "number" && Number.isFinite(value)) parsed = value;
|
|
101
|
+
else if (typeof value === "string") {
|
|
102
|
+
const n = Number(value.trim());
|
|
103
|
+
if (Number.isFinite(n)) parsed = n;
|
|
104
|
+
}
|
|
105
|
+
if (parsed === void 0) parsed = options.defaultValue;
|
|
106
|
+
if (options.integer) parsed = Math.trunc(parsed);
|
|
107
|
+
if (parsed < options.min) parsed = options.min;
|
|
108
|
+
if (parsed > options.max) parsed = options.max;
|
|
109
|
+
return parsed;
|
|
110
|
+
}
|
|
111
|
+
function parseWsDirection(value) {
|
|
112
|
+
if (value === "sent" || value === "received" || value === "all") return value;
|
|
113
|
+
return "all";
|
|
114
|
+
}
|
|
115
|
+
function compileRegex(pattern) {
|
|
116
|
+
try {
|
|
117
|
+
return { regex: new RegExp(pattern) };
|
|
118
|
+
} catch (error) {
|
|
119
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/server/domains/streaming/handlers/ws-handlers.ts
|
|
124
|
+
/**
|
|
125
|
+
* WebSocket monitoring handlers — enable, disable, get frames, get connections.
|
|
126
|
+
*/
|
|
127
|
+
const asRecord = (value) => typeof value === "object" && value !== null ? value : void 0;
|
|
128
|
+
const getStringField = (value, key) => {
|
|
129
|
+
const field = asRecord(value)?.[key];
|
|
130
|
+
return typeof field === "string" ? field : void 0;
|
|
131
|
+
};
|
|
132
|
+
const getNumberField = (value, key) => {
|
|
133
|
+
const field = asRecord(value)?.[key];
|
|
134
|
+
return typeof field === "number" ? field : void 0;
|
|
135
|
+
};
|
|
136
|
+
const getRecordField = (value, key) => {
|
|
137
|
+
const nested = asRecord(value)?.[key];
|
|
138
|
+
return asRecord(nested);
|
|
139
|
+
};
|
|
140
|
+
var WsHandlers = class {
|
|
141
|
+
constructor(s) {
|
|
142
|
+
this.s = s;
|
|
143
|
+
}
|
|
144
|
+
async teardownWsSession() {
|
|
145
|
+
if (this.s.wsSession && this.s.wsListeners) {
|
|
146
|
+
try {
|
|
147
|
+
this.s.wsSession.off("Network.webSocketCreated", this.s.wsListeners.created);
|
|
148
|
+
} catch (e) {
|
|
149
|
+
logger.debug("[ws-teardown] Failed to remove webSocketCreated listener", e);
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
this.s.wsSession.off("Network.webSocketClosed", this.s.wsListeners.closed);
|
|
153
|
+
} catch (e) {
|
|
154
|
+
logger.debug("[ws-teardown] Failed to remove webSocketClosed listener", e);
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
this.s.wsSession.off("Network.webSocketHandshakeResponseReceived", this.s.wsListeners.handshake);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
logger.debug("[ws-teardown] Failed to remove handshakeResponseReceived listener", e);
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
this.s.wsSession.off("Network.webSocketFrameSent", this.s.wsListeners.frameSent);
|
|
163
|
+
} catch (e) {
|
|
164
|
+
logger.debug("[ws-teardown] Failed to remove webSocketFrameSent listener", e);
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
this.s.wsSession.off("Network.webSocketFrameReceived", this.s.wsListeners.frameReceived);
|
|
168
|
+
} catch (e) {
|
|
169
|
+
logger.debug("[ws-teardown] Failed to remove webSocketFrameReceived listener", e);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (this.s.wsSession) try {
|
|
173
|
+
await this.s.wsSession.detach();
|
|
174
|
+
} catch (e) {
|
|
175
|
+
logger.debug("[ws-teardown] Failed to detach CDP session", e);
|
|
176
|
+
}
|
|
177
|
+
this.s.wsSession = null;
|
|
178
|
+
this.s.wsListeners = null;
|
|
179
|
+
}
|
|
180
|
+
handleWsFrame(direction, params) {
|
|
181
|
+
const requestId = getStringField(params, "requestId");
|
|
182
|
+
if (!requestId) return;
|
|
183
|
+
if (!this.s.wsConnections.get(requestId)) {
|
|
184
|
+
if (this.s.wsConfig.urlFilter) return;
|
|
185
|
+
this.s.wsConnections.set(requestId, {
|
|
186
|
+
requestId,
|
|
187
|
+
url: "unknown",
|
|
188
|
+
status: "open",
|
|
189
|
+
framesCount: 0,
|
|
190
|
+
createdTimestamp: Date.now() / 1e3
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
const connection = this.s.wsConnections.get(requestId);
|
|
194
|
+
if (!connection) return;
|
|
195
|
+
if (this.s.wsConfig.urlFilter && connection.url !== "unknown" && !this.s.wsConfig.urlFilter.test(connection.url)) return;
|
|
196
|
+
const response = getRecordField(params, "response");
|
|
197
|
+
const opcode = getNumberField(response, "opcode") ?? -1;
|
|
198
|
+
const payloadData = getStringField(response, "payloadData") ?? "";
|
|
199
|
+
const payloadPreview = payloadData.length > WS_PAYLOAD_PREVIEW_LIMIT ? `${payloadData.slice(0, WS_PAYLOAD_PREVIEW_LIMIT)}…` : payloadData;
|
|
200
|
+
const payloadSample = payloadData.length > WS_PAYLOAD_SAMPLE_LIMIT ? payloadData.slice(0, WS_PAYLOAD_SAMPLE_LIMIT) : payloadData;
|
|
201
|
+
const frame = {
|
|
202
|
+
requestId,
|
|
203
|
+
timestamp: getNumberField(params, "timestamp") ?? Date.now() / 1e3,
|
|
204
|
+
direction,
|
|
205
|
+
opcode,
|
|
206
|
+
payloadLength: payloadData.length,
|
|
207
|
+
payloadPreview,
|
|
208
|
+
payloadSample,
|
|
209
|
+
isBinary: opcode === 2
|
|
210
|
+
};
|
|
211
|
+
this.appendWsFrame(requestId, frame);
|
|
212
|
+
}
|
|
213
|
+
appendWsFrame(requestId, frame) {
|
|
214
|
+
const list = this.s.wsFramesByRequest.get(requestId) ?? [];
|
|
215
|
+
list.push(frame);
|
|
216
|
+
this.s.wsFramesByRequest.set(requestId, list);
|
|
217
|
+
const connection = this.s.wsConnections.get(requestId);
|
|
218
|
+
if (connection) {
|
|
219
|
+
connection.framesCount += 1;
|
|
220
|
+
if (connection.status === "connecting") connection.status = "open";
|
|
221
|
+
}
|
|
222
|
+
this.s.wsFrameOrder.push({
|
|
223
|
+
requestId,
|
|
224
|
+
frame
|
|
225
|
+
});
|
|
226
|
+
this.enforceWsFrameLimit();
|
|
227
|
+
}
|
|
228
|
+
enforceWsFrameLimit() {
|
|
229
|
+
while (this.s.wsFrameOrder.length > this.s.wsConfig.maxFrames) {
|
|
230
|
+
const oldest = this.s.wsFrameOrder.shift();
|
|
231
|
+
if (!oldest) break;
|
|
232
|
+
const bucket = this.s.wsFramesByRequest.get(oldest.requestId);
|
|
233
|
+
if (bucket && bucket.length > 0) {
|
|
234
|
+
bucket.shift();
|
|
235
|
+
if (bucket.length === 0) this.s.wsFramesByRequest.delete(oldest.requestId);
|
|
236
|
+
else this.s.wsFramesByRequest.set(oldest.requestId, bucket);
|
|
237
|
+
}
|
|
238
|
+
const connection = this.s.wsConnections.get(oldest.requestId);
|
|
239
|
+
if (connection) connection.framesCount = Math.max(0, connection.framesCount - 1);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
getWsFrameStats() {
|
|
243
|
+
let sent = 0;
|
|
244
|
+
let received = 0;
|
|
245
|
+
for (const entry of this.s.wsFrameOrder) if (entry.frame.direction === "sent") sent += 1;
|
|
246
|
+
else received += 1;
|
|
247
|
+
return {
|
|
248
|
+
total: this.s.wsFrameOrder.length,
|
|
249
|
+
sent,
|
|
250
|
+
received
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
async handleWsMonitorEnable(args) {
|
|
254
|
+
const maxFrames = parseNumberArg(args.maxFrames, {
|
|
255
|
+
defaultValue: 1e3,
|
|
256
|
+
min: 1,
|
|
257
|
+
max: 2e4,
|
|
258
|
+
integer: true
|
|
259
|
+
});
|
|
260
|
+
const urlFilterRaw = parseOptionalStringArg(args.urlFilter);
|
|
261
|
+
let urlFilter;
|
|
262
|
+
if (urlFilterRaw) {
|
|
263
|
+
const compiled = compileRegex(urlFilterRaw);
|
|
264
|
+
if (compiled.error) return asJson({
|
|
265
|
+
success: false,
|
|
266
|
+
error: `Invalid urlFilter regex: ${compiled.error}`
|
|
267
|
+
});
|
|
268
|
+
urlFilter = compiled.regex;
|
|
269
|
+
}
|
|
270
|
+
await this.teardownWsSession();
|
|
271
|
+
this.s.wsFramesByRequest.clear();
|
|
272
|
+
this.s.wsFrameOrder = new RingBuffer(maxFrames);
|
|
273
|
+
this.s.wsConnections.clear();
|
|
274
|
+
const session = await (await this.s.collector.getActivePage()).createCDPSession();
|
|
275
|
+
await session.send("Network.enable");
|
|
276
|
+
const listeners = {
|
|
277
|
+
created: (params) => {
|
|
278
|
+
const reqId = getStringField(params, "requestId");
|
|
279
|
+
const url = getStringField(params, "url");
|
|
280
|
+
if (!reqId || !url) return;
|
|
281
|
+
if (urlFilter && !urlFilter.test(url)) return;
|
|
282
|
+
const existing = this.s.wsConnections.get(reqId);
|
|
283
|
+
this.s.wsConnections.set(reqId, {
|
|
284
|
+
requestId: reqId,
|
|
285
|
+
url,
|
|
286
|
+
status: existing?.status ?? "connecting",
|
|
287
|
+
framesCount: existing?.framesCount ?? 0,
|
|
288
|
+
createdTimestamp: existing?.createdTimestamp ?? Date.now() / 1e3,
|
|
289
|
+
closedTimestamp: existing?.closedTimestamp,
|
|
290
|
+
handshakeStatus: existing?.handshakeStatus
|
|
291
|
+
});
|
|
292
|
+
},
|
|
293
|
+
closed: (params) => {
|
|
294
|
+
const reqId = getStringField(params, "requestId");
|
|
295
|
+
if (!reqId) return;
|
|
296
|
+
const connection = this.s.wsConnections.get(reqId);
|
|
297
|
+
if (!connection) return;
|
|
298
|
+
connection.status = "closed";
|
|
299
|
+
const ts = getNumberField(params, "timestamp");
|
|
300
|
+
connection.closedTimestamp = ts !== void 0 ? ts : Date.now() / 1e3;
|
|
301
|
+
},
|
|
302
|
+
handshake: (params) => {
|
|
303
|
+
const reqId = getStringField(params, "requestId");
|
|
304
|
+
if (!reqId) return;
|
|
305
|
+
const connection = this.s.wsConnections.get(reqId);
|
|
306
|
+
if (!connection) return;
|
|
307
|
+
const status = getNumberField(getRecordField(params, "response"), "status");
|
|
308
|
+
if (status !== void 0) {
|
|
309
|
+
connection.handshakeStatus = status;
|
|
310
|
+
connection.status = status >= 100 && status < 400 ? "open" : "error";
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
frameSent: (params) => {
|
|
314
|
+
this.handleWsFrame("sent", params);
|
|
315
|
+
},
|
|
316
|
+
frameReceived: (params) => {
|
|
317
|
+
this.handleWsFrame("received", params);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
session.on("Network.webSocketCreated", listeners.created);
|
|
321
|
+
session.on("Network.webSocketClosed", listeners.closed);
|
|
322
|
+
session.on("Network.webSocketHandshakeResponseReceived", listeners.handshake);
|
|
323
|
+
session.on("Network.webSocketFrameSent", listeners.frameSent);
|
|
324
|
+
session.on("Network.webSocketFrameReceived", listeners.frameReceived);
|
|
325
|
+
this.s.wsSession = session;
|
|
326
|
+
this.s.wsListeners = listeners;
|
|
327
|
+
this.s.wsConfig = {
|
|
328
|
+
enabled: true,
|
|
329
|
+
maxFrames,
|
|
330
|
+
urlFilterRaw,
|
|
331
|
+
urlFilter
|
|
332
|
+
};
|
|
333
|
+
return asJson({
|
|
334
|
+
success: true,
|
|
335
|
+
message: "WebSocket monitor enabled",
|
|
336
|
+
config: {
|
|
337
|
+
maxFrames,
|
|
338
|
+
urlFilter: urlFilterRaw ?? null
|
|
339
|
+
},
|
|
340
|
+
stats: {
|
|
341
|
+
trackedConnections: this.s.wsConnections.size,
|
|
342
|
+
capturedFrames: this.s.wsFrameOrder.length
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
async handleWsMonitorDisable(_args) {
|
|
347
|
+
const stats = this.getWsFrameStats();
|
|
348
|
+
const connections = Array.from(this.s.wsConnections.values());
|
|
349
|
+
const summary = {
|
|
350
|
+
success: true,
|
|
351
|
+
message: "WebSocket monitor disabled",
|
|
352
|
+
config: {
|
|
353
|
+
maxFrames: this.s.wsConfig.maxFrames,
|
|
354
|
+
urlFilter: this.s.wsConfig.urlFilterRaw ?? null
|
|
355
|
+
},
|
|
356
|
+
summary: {
|
|
357
|
+
trackedConnections: connections.length,
|
|
358
|
+
activeConnections: connections.filter((c) => c.status === "open" || c.status === "connecting").length,
|
|
359
|
+
closedConnections: connections.filter((c) => c.status === "closed").length,
|
|
360
|
+
totalFrames: stats.total,
|
|
361
|
+
sentFrames: stats.sent,
|
|
362
|
+
receivedFrames: stats.received
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
await this.teardownWsSession();
|
|
366
|
+
this.s.wsConfig = {
|
|
367
|
+
...this.s.wsConfig,
|
|
368
|
+
enabled: false
|
|
369
|
+
};
|
|
370
|
+
return asJson(summary);
|
|
371
|
+
}
|
|
372
|
+
async handleWsGetFrames(args) {
|
|
373
|
+
const direction = parseWsDirection(args.direction);
|
|
374
|
+
const limit = parseNumberArg(args.limit, {
|
|
375
|
+
defaultValue: 100,
|
|
376
|
+
min: 1,
|
|
377
|
+
max: 5e3,
|
|
378
|
+
integer: true
|
|
379
|
+
});
|
|
380
|
+
const offset = parseNumberArg(args.offset, {
|
|
381
|
+
defaultValue: 0,
|
|
382
|
+
min: 0,
|
|
383
|
+
max: Number.MAX_SAFE_INTEGER,
|
|
384
|
+
integer: true
|
|
385
|
+
});
|
|
386
|
+
const payloadFilterRaw = parseOptionalStringArg(args.payloadFilter);
|
|
387
|
+
let payloadFilter;
|
|
388
|
+
if (payloadFilterRaw) {
|
|
389
|
+
const compiled = compileRegex(payloadFilterRaw);
|
|
390
|
+
if (compiled.error) return asJson({
|
|
391
|
+
success: false,
|
|
392
|
+
error: `Invalid payloadFilter regex: ${compiled.error}`
|
|
393
|
+
});
|
|
394
|
+
payloadFilter = compiled.regex;
|
|
395
|
+
}
|
|
396
|
+
const filtered = this.s.wsFrameOrder.toArray().map((entry) => entry.frame).filter((frame) => direction === "all" ? true : frame.direction === direction).filter((frame) => payloadFilter ? payloadFilter.test(frame.payloadSample) : true);
|
|
397
|
+
const pageItems = filtered.slice(offset, offset + limit).map((frame) => ({
|
|
398
|
+
requestId: frame.requestId,
|
|
399
|
+
timestamp: frame.timestamp,
|
|
400
|
+
direction: frame.direction,
|
|
401
|
+
opcode: frame.opcode,
|
|
402
|
+
payloadLength: frame.payloadLength,
|
|
403
|
+
payloadPreview: frame.payloadPreview,
|
|
404
|
+
isBinary: frame.isBinary
|
|
405
|
+
}));
|
|
406
|
+
return asJson({
|
|
407
|
+
success: true,
|
|
408
|
+
monitorEnabled: this.s.wsConfig.enabled,
|
|
409
|
+
filters: {
|
|
410
|
+
direction,
|
|
411
|
+
payloadFilter: payloadFilterRaw ?? null
|
|
412
|
+
},
|
|
413
|
+
page: {
|
|
414
|
+
offset,
|
|
415
|
+
limit,
|
|
416
|
+
returned: pageItems.length,
|
|
417
|
+
totalAfterFilter: filtered.length,
|
|
418
|
+
hasMore: offset + pageItems.length < filtered.length,
|
|
419
|
+
nextOffset: offset + pageItems.length < filtered.length ? offset + pageItems.length : null
|
|
420
|
+
},
|
|
421
|
+
frames: pageItems
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
async handleWsGetConnections(_args) {
|
|
425
|
+
const connections = Array.from(this.s.wsConnections.values()).toSorted((a, b) => a.createdTimestamp - b.createdTimestamp).map((conn) => ({
|
|
426
|
+
requestId: conn.requestId,
|
|
427
|
+
url: conn.url,
|
|
428
|
+
status: conn.status,
|
|
429
|
+
framesCount: conn.framesCount
|
|
430
|
+
}));
|
|
431
|
+
return asJson({
|
|
432
|
+
success: true,
|
|
433
|
+
monitorEnabled: this.s.wsConfig.enabled,
|
|
434
|
+
total: connections.length,
|
|
435
|
+
connections
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region src/server/domains/streaming/handlers/sse-handlers.ts
|
|
441
|
+
function toDataString(value) {
|
|
442
|
+
if (typeof value === "string") return value;
|
|
443
|
+
if (value === null || value === void 0) return "";
|
|
444
|
+
if (typeof value === "object") try {
|
|
445
|
+
return JSON.stringify(value);
|
|
446
|
+
} catch {
|
|
447
|
+
return "[unserializable]";
|
|
448
|
+
}
|
|
449
|
+
return String(value);
|
|
450
|
+
}
|
|
451
|
+
function sseInjectionFn(config) {
|
|
452
|
+
const globalWindow = window;
|
|
453
|
+
if (!globalWindow.__jshookSSEMonitor) globalWindow.__jshookSSEMonitor = {
|
|
454
|
+
enabled: true,
|
|
455
|
+
patched: false,
|
|
456
|
+
maxEvents: config.maxEvents,
|
|
457
|
+
urlFilterRaw: config.urlFilterRaw,
|
|
458
|
+
events: [],
|
|
459
|
+
sources: {}
|
|
460
|
+
};
|
|
461
|
+
const state = globalWindow.__jshookSSEMonitor;
|
|
462
|
+
state.enabled = true;
|
|
463
|
+
state.maxEvents = config.maxEvents;
|
|
464
|
+
state.urlFilterRaw = config.urlFilterRaw;
|
|
465
|
+
if (state.events.length > state.maxEvents) state.events = state.events.slice(-state.maxEvents);
|
|
466
|
+
const shouldCapture = (sourceUrl) => {
|
|
467
|
+
if (!state.urlFilterRaw) return true;
|
|
468
|
+
try {
|
|
469
|
+
return new RegExp(state.urlFilterRaw).test(sourceUrl);
|
|
470
|
+
} catch {
|
|
471
|
+
return true;
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
const pushEvent = (sourceUrl, eventType, rawData, lastEventId) => {
|
|
475
|
+
if (!state.enabled || !shouldCapture(sourceUrl)) return;
|
|
476
|
+
const dataString = toDataString(rawData);
|
|
477
|
+
const record = {
|
|
478
|
+
sourceUrl,
|
|
479
|
+
eventType,
|
|
480
|
+
dataPreview: dataString.length > 200 ? `${dataString.slice(0, 200)}…` : dataString,
|
|
481
|
+
dataLength: dataString.length,
|
|
482
|
+
lastEventId,
|
|
483
|
+
timestamp: Date.now()
|
|
484
|
+
};
|
|
485
|
+
state.events.push(record);
|
|
486
|
+
while (state.events.length > state.maxEvents) state.events.shift();
|
|
487
|
+
const source = state.sources[sourceUrl] ?? {
|
|
488
|
+
url: sourceUrl,
|
|
489
|
+
status: "connecting",
|
|
490
|
+
eventCount: 0
|
|
491
|
+
};
|
|
492
|
+
source.eventCount += 1;
|
|
493
|
+
source.lastEventTimestamp = record.timestamp;
|
|
494
|
+
state.sources[sourceUrl] = source;
|
|
495
|
+
};
|
|
496
|
+
if (typeof globalWindow.EventSource === "undefined") return {
|
|
497
|
+
success: false,
|
|
498
|
+
error: "EventSource is not available in current page context"
|
|
499
|
+
};
|
|
500
|
+
if (!state.patched) {
|
|
501
|
+
const OriginalEventSource = globalWindow.EventSource;
|
|
502
|
+
const WrappedEventSource = function(url, eventSourceInitDict) {
|
|
503
|
+
const sourceUrl = String(url);
|
|
504
|
+
const es = new OriginalEventSource(url, eventSourceInitDict);
|
|
505
|
+
if (shouldCapture(sourceUrl)) {
|
|
506
|
+
const source = state.sources[sourceUrl] ?? {
|
|
507
|
+
url: sourceUrl,
|
|
508
|
+
status: "connecting",
|
|
509
|
+
eventCount: 0
|
|
510
|
+
};
|
|
511
|
+
state.sources[sourceUrl] = source;
|
|
512
|
+
}
|
|
513
|
+
es.addEventListener("open", () => {
|
|
514
|
+
const source = state.sources[sourceUrl];
|
|
515
|
+
if (source) source.status = "open";
|
|
516
|
+
pushEvent(sourceUrl, "open", "", null);
|
|
517
|
+
});
|
|
518
|
+
es.addEventListener("error", () => {
|
|
519
|
+
const source = state.sources[sourceUrl];
|
|
520
|
+
if (source) source.status = "error";
|
|
521
|
+
pushEvent(sourceUrl, "error", "", null);
|
|
522
|
+
});
|
|
523
|
+
es.addEventListener("message", (event) => {
|
|
524
|
+
const lastEventId = typeof event.lastEventId === "string" && event.lastEventId.length > 0 ? event.lastEventId : null;
|
|
525
|
+
pushEvent(sourceUrl, event.type || "message", event.data, lastEventId);
|
|
526
|
+
});
|
|
527
|
+
const originalAddEventListener = es.addEventListener.bind(es);
|
|
528
|
+
const callOriginalAddEventListener = (type, listener, listenerOpts) => {
|
|
529
|
+
originalAddEventListener(type, listener, listenerOpts);
|
|
530
|
+
};
|
|
531
|
+
const wrappedAddEventListener = (type, listener, listenerOpts) => {
|
|
532
|
+
if (type !== "message" && type !== "open" && type !== "error" && listener) {
|
|
533
|
+
const wrapped = (evt) => {
|
|
534
|
+
const messageEvent = evt;
|
|
535
|
+
const lastEventId = typeof messageEvent.lastEventId === "string" && messageEvent.lastEventId.length > 0 ? messageEvent.lastEventId : null;
|
|
536
|
+
pushEvent(sourceUrl, type, messageEvent.data, lastEventId);
|
|
537
|
+
if (typeof listener === "function") listener.call(es, evt);
|
|
538
|
+
else listener.handleEvent(evt);
|
|
539
|
+
};
|
|
540
|
+
callOriginalAddEventListener(type, wrapped, listenerOpts);
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
callOriginalAddEventListener(type, listener, listenerOpts);
|
|
544
|
+
};
|
|
545
|
+
Object.defineProperty(es, "addEventListener", {
|
|
546
|
+
value: wrappedAddEventListener,
|
|
547
|
+
configurable: true,
|
|
548
|
+
writable: true
|
|
549
|
+
});
|
|
550
|
+
return es;
|
|
551
|
+
};
|
|
552
|
+
WrappedEventSource.prototype = OriginalEventSource.prototype;
|
|
553
|
+
try {
|
|
554
|
+
Object.defineProperty(WrappedEventSource, "CONNECTING", { value: OriginalEventSource.CONNECTING });
|
|
555
|
+
Object.defineProperty(WrappedEventSource, "OPEN", { value: OriginalEventSource.OPEN });
|
|
556
|
+
Object.defineProperty(WrappedEventSource, "CLOSED", { value: OriginalEventSource.CLOSED });
|
|
557
|
+
} catch {}
|
|
558
|
+
globalWindow.EventSource = WrappedEventSource;
|
|
559
|
+
state.originalEventSource = OriginalEventSource;
|
|
560
|
+
state.patched = true;
|
|
561
|
+
}
|
|
562
|
+
return {
|
|
563
|
+
success: true,
|
|
564
|
+
message: "SSE monitor enabled",
|
|
565
|
+
patched: state.patched,
|
|
566
|
+
urlFilter: state.urlFilterRaw,
|
|
567
|
+
maxEvents: state.maxEvents,
|
|
568
|
+
existingEvents: state.events.length
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
var SseHandlers = class {
|
|
572
|
+
constructor(s) {
|
|
573
|
+
this.s = s;
|
|
574
|
+
}
|
|
575
|
+
async enableSseInterceptor(maxEvents, urlFilterRaw, options) {
|
|
576
|
+
const page = await this.s.collector.getActivePage();
|
|
577
|
+
if (options?.persistent) {
|
|
578
|
+
await evaluateOnNewDocumentWithTimeout(page, sseInjectionFn, {
|
|
579
|
+
maxEvents,
|
|
580
|
+
urlFilterRaw
|
|
581
|
+
});
|
|
582
|
+
return {
|
|
583
|
+
success: true,
|
|
584
|
+
message: "SSE monitor enabled (persistent — survives navigations)",
|
|
585
|
+
patched: true,
|
|
586
|
+
urlFilter: urlFilterRaw,
|
|
587
|
+
maxEvents,
|
|
588
|
+
existingEvents: 0
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
return await evaluateWithTimeout(page, sseInjectionFn, {
|
|
592
|
+
maxEvents,
|
|
593
|
+
urlFilterRaw
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
async handleSseMonitorEnable(args) {
|
|
597
|
+
const maxEvents = parseNumberArg(args.maxEvents, {
|
|
598
|
+
defaultValue: 2e3,
|
|
599
|
+
min: 1,
|
|
600
|
+
max: 5e4,
|
|
601
|
+
integer: true
|
|
602
|
+
});
|
|
603
|
+
const urlFilterRaw = parseOptionalStringArg(args.urlFilter);
|
|
604
|
+
if (urlFilterRaw) {
|
|
605
|
+
const compiled = compileRegex(urlFilterRaw);
|
|
606
|
+
if (compiled.error) return asJson({
|
|
607
|
+
success: false,
|
|
608
|
+
error: `Invalid urlFilter regex: ${compiled.error}`
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
const persistent = args.persistent === true;
|
|
612
|
+
const result = await this.enableSseInterceptor(maxEvents, urlFilterRaw, { persistent });
|
|
613
|
+
if (!result.success) return asJson(result);
|
|
614
|
+
this.s.sseConfig = {
|
|
615
|
+
maxEvents,
|
|
616
|
+
urlFilterRaw
|
|
617
|
+
};
|
|
618
|
+
return asJson({
|
|
619
|
+
success: true,
|
|
620
|
+
message: result.message,
|
|
621
|
+
patched: result.patched,
|
|
622
|
+
config: {
|
|
623
|
+
maxEvents: this.s.sseConfig.maxEvents,
|
|
624
|
+
urlFilter: this.s.sseConfig.urlFilterRaw ?? null
|
|
625
|
+
},
|
|
626
|
+
existingEvents: result.existingEvents
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
async handleSseGetEvents(args) {
|
|
630
|
+
const sourceUrl = parseOptionalStringArg(args.sourceUrl);
|
|
631
|
+
const eventType = parseOptionalStringArg(args.eventType);
|
|
632
|
+
const limit = parseNumberArg(args.limit, {
|
|
633
|
+
defaultValue: 100,
|
|
634
|
+
min: 1,
|
|
635
|
+
max: 5e3,
|
|
636
|
+
integer: true
|
|
637
|
+
});
|
|
638
|
+
const offset = parseNumberArg(args.offset, {
|
|
639
|
+
defaultValue: 0,
|
|
640
|
+
min: 0,
|
|
641
|
+
max: Number.MAX_SAFE_INTEGER,
|
|
642
|
+
integer: true
|
|
643
|
+
});
|
|
644
|
+
return asJson(await evaluateWithTimeout(await this.s.collector.getActivePage(), (query) => {
|
|
645
|
+
const state = window.__jshookSSEMonitor;
|
|
646
|
+
if (!state) return {
|
|
647
|
+
success: false,
|
|
648
|
+
message: "SSE monitor is not enabled. Call sse_monitor_enable first."
|
|
649
|
+
};
|
|
650
|
+
let events = state.events;
|
|
651
|
+
if (query.sourceUrl) events = events.filter((evt) => evt.sourceUrl === query.sourceUrl);
|
|
652
|
+
if (query.eventType) events = events.filter((evt) => evt.eventType === query.eventType);
|
|
653
|
+
const totalAfterFilter = events.length;
|
|
654
|
+
const paged = events.slice(query.offset, query.offset + query.limit);
|
|
655
|
+
return {
|
|
656
|
+
success: true,
|
|
657
|
+
filters: {
|
|
658
|
+
sourceUrl: query.sourceUrl ?? null,
|
|
659
|
+
eventType: query.eventType ?? null
|
|
660
|
+
},
|
|
661
|
+
page: {
|
|
662
|
+
offset: query.offset,
|
|
663
|
+
limit: query.limit,
|
|
664
|
+
returned: paged.length,
|
|
665
|
+
totalAfterFilter,
|
|
666
|
+
hasMore: query.offset + paged.length < totalAfterFilter,
|
|
667
|
+
nextOffset: query.offset + paged.length < totalAfterFilter ? query.offset + paged.length : null
|
|
668
|
+
},
|
|
669
|
+
monitor: {
|
|
670
|
+
enabled: state.enabled,
|
|
671
|
+
patched: state.patched,
|
|
672
|
+
maxEvents: state.maxEvents,
|
|
673
|
+
urlFilter: state.urlFilterRaw ?? null,
|
|
674
|
+
sourceCount: Object.keys(state.sources).length
|
|
675
|
+
},
|
|
676
|
+
events: paged
|
|
677
|
+
};
|
|
678
|
+
}, {
|
|
679
|
+
sourceUrl,
|
|
680
|
+
eventType,
|
|
681
|
+
limit,
|
|
682
|
+
offset
|
|
683
|
+
}));
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
//#endregion
|
|
687
|
+
//#region src/server/domains/streaming/handlers.impl.core.ts
|
|
688
|
+
var StreamingToolHandlers = class {
|
|
689
|
+
collector;
|
|
690
|
+
state;
|
|
691
|
+
ws;
|
|
692
|
+
sse;
|
|
693
|
+
get wsConnections() {
|
|
694
|
+
return this.state.wsConnections;
|
|
695
|
+
}
|
|
696
|
+
get wsFrameOrder() {
|
|
697
|
+
return this.state.wsFrameOrder;
|
|
698
|
+
}
|
|
699
|
+
get wsConfig() {
|
|
700
|
+
return this.state.wsConfig;
|
|
701
|
+
}
|
|
702
|
+
get wsFramesByRequest() {
|
|
703
|
+
return this.state.wsFramesByRequest;
|
|
704
|
+
}
|
|
705
|
+
get sseConfig() {
|
|
706
|
+
return this.state.sseConfig;
|
|
707
|
+
}
|
|
708
|
+
constructor(collector) {
|
|
709
|
+
this.collector = collector;
|
|
710
|
+
this.state = createStreamingSharedState(collector);
|
|
711
|
+
this.ws = new WsHandlers(this.state);
|
|
712
|
+
this.sse = new SseHandlers(this.state);
|
|
713
|
+
}
|
|
714
|
+
handleWsMonitorDispatch = (args) => {
|
|
715
|
+
return String(args["action"] ?? "") === "disable" ? this.ws.handleWsMonitorDisable(args) : this.ws.handleWsMonitorEnable(args);
|
|
716
|
+
};
|
|
717
|
+
handleWsMonitorEnable = (args) => this.ws.handleWsMonitorEnable(args);
|
|
718
|
+
handleWsMonitorDisable = (args) => this.ws.handleWsMonitorDisable(args);
|
|
719
|
+
handleWsGetFrames = (args) => this.ws.handleWsGetFrames(args);
|
|
720
|
+
handleWsGetConnections = (args) => this.ws.handleWsGetConnections(args);
|
|
721
|
+
handleSseMonitorEnable = (args) => this.sse.handleSseMonitorEnable(args);
|
|
722
|
+
handleSseGetEvents = (args) => this.sse.handleSseGetEvents(args);
|
|
723
|
+
};
|
|
724
|
+
//#endregion
|
|
725
|
+
export { StreamingToolHandlers };
|