chrome-devtools-mcp 1.9.0 → 1.10.0
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/build/src/BrowserManager.js +401 -0
- package/build/src/McpContext.js +5 -5
- package/build/src/McpPage.js +107 -3
- package/build/src/McpResponse.js +68 -3
- package/build/src/ToolHandler.js +172 -118
- package/build/src/bin/chrome-devtools-mcp-main.js +11 -6
- package/build/src/bin/chrome-devtools.js +6 -12
- package/build/src/collectors/PageCollector.js +66 -3
- package/build/src/config/browser-options.js +2 -0
- package/build/src/config/category-options.js +13 -4
- package/build/src/config/cli-commands.js +26 -0
- package/build/src/config/cli-options.js +32 -0
- package/build/src/config/mcp-options.js +40 -1
- package/build/src/devtools/DevToolsCommentBridge.js +91 -0
- package/build/src/formatters/CommentFormatter.js +82 -0
- package/build/src/formatters/CssFormatter.js +812 -0
- package/build/src/index.js +53 -72
- package/build/src/processors/ChunkedTraceParser.js +361 -0
- package/build/src/processors/PerformanceTrace.js +60 -13
- package/build/src/telemetry/ClearcutLogger.js +91 -34
- package/build/src/telemetry/metricsRegistry.js +3 -0
- package/build/src/telemetry/persistence.js +17 -7
- package/build/src/telemetry/transformation.js +53 -4
- package/build/src/telemetry/types.js +1 -0
- package/build/src/third_party/THIRD_PARTY_NOTICES +685 -131
- package/build/src/third_party/bundled-packages.json +6 -3
- package/build/src/third_party/devtools-formatter-worker.js +136 -5
- package/build/src/third_party/devtools-heap-snapshot-worker.js +567 -6
- package/build/src/third_party/index.js +54945 -35497
- package/build/src/third_party/issue-descriptions/webInstallManifestMissingId.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallManifestMissingNameOrShortName.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallManifestParsingOrNetworkError.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallNoManifest.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallStartUrlInvalid.md +3 -0
- package/build/src/tools/ToolDefinition.js +13 -21
- package/build/src/tools/comments.js +169 -0
- package/build/src/tools/console.js +3 -3
- package/build/src/tools/css.js +45 -0
- package/build/src/tools/emulation.js +5 -5
- package/build/src/tools/extensions.js +10 -10
- package/build/src/tools/input.js +159 -87
- package/build/src/tools/lighthouse.js +18 -7
- package/build/src/tools/memory.js +26 -26
- package/build/src/tools/network.js +4 -4
- package/build/src/tools/pages.js +14 -14
- package/build/src/tools/performance.js +6 -6
- package/build/src/tools/pwa.js +8 -8
- package/build/src/tools/screencast.js +4 -4
- package/build/src/tools/screenshot.js +2 -2
- package/build/src/tools/script.js +7 -7
- package/build/src/tools/slim/tools.js +5 -5
- package/build/src/tools/snapshot.js +4 -4
- package/build/src/tools/thirdPartyDeveloper.js +4 -4
- package/build/src/tools/tools.js +6 -9
- package/build/src/tools/webmcp.js +4 -4
- package/build/src/types.js +4 -1
- package/build/src/utils/WaitForHelper.js +14 -8
- package/build/src/utils/logger.js +7 -6
- package/build/src/version.js +1 -1
- package/package.json +8 -5
- package/skills/chrome-devtools/SKILL.md +2 -1
- package/skills/chrome-devtools-cli/SKILL.md +2 -0
- package/build/src/browser.js +0 -233
- package/build/src/third_party/issue-descriptions/cookieExcludeBlockedWithinRelatedWebsiteSet.md +0 -4
|
@@ -5,34 +5,65 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { DevTools } from '../third_party/index.js';
|
|
7
7
|
import { logger } from '../utils/logger.js';
|
|
8
|
-
|
|
8
|
+
import { parseTraceEventsFromBuffer } from './ChunkedTraceParser.js';
|
|
9
|
+
/**
|
|
10
|
+
* Type guard that verifies if an operation returned a valid TraceResult.
|
|
11
|
+
*
|
|
12
|
+
* @param x - The result or error object to inspect.
|
|
13
|
+
* @returns True if the object is a TraceResult; otherwise false.
|
|
14
|
+
*/
|
|
9
15
|
export function traceResultIsSuccess(x) {
|
|
10
16
|
return 'parsedTrace' in x;
|
|
11
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Parses raw JSON trace buffer bytes into a DevTools TraceEngine representation.
|
|
20
|
+
*
|
|
21
|
+
* Accepts either a JSON array of trace events or an object with a `traceEvents` field.
|
|
22
|
+
* Events are parsed in chunks directly from the raw byte buffer to avoid V8 string
|
|
23
|
+
* allocation limits. A new trace engine model is created per call to ensure session
|
|
24
|
+
* isolation and prevent memory retention.
|
|
25
|
+
*
|
|
26
|
+
* @param buffer - Raw binary trace data representing trace events and metadata.
|
|
27
|
+
* @param metadata - Optional throttling configurations applied during recording; overrides embedded file metadata when defined.
|
|
28
|
+
* @returns A promise resolving to a {@link TraceResult} with parsed traces and insights, or a {@link TraceParseError} on failure.
|
|
29
|
+
*/
|
|
12
30
|
export async function parseRawTraceBuffer(buffer, metadata) {
|
|
13
|
-
|
|
14
|
-
if (!buffer) {
|
|
31
|
+
if (!buffer || buffer.length === 0) {
|
|
15
32
|
return {
|
|
16
33
|
error: 'No buffer was provided.',
|
|
17
34
|
};
|
|
18
35
|
}
|
|
19
|
-
const asString = new TextDecoder().decode(buffer);
|
|
20
|
-
if (!asString) {
|
|
21
|
-
return {
|
|
22
|
-
error: 'Decoding the trace buffer returned an empty string.',
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
36
|
try {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
const { events, metadata: fileMetadata } = parseTraceEventsFromBuffer(buffer);
|
|
38
|
+
if (events.length === 0) {
|
|
39
|
+
return {
|
|
40
|
+
error: 'No trace events were found in the trace buffer.',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const combinedMetadata = {
|
|
44
|
+
...fileMetadata,
|
|
45
|
+
...(metadata?.cpuThrottling !== undefined
|
|
46
|
+
? { cpuThrottling: metadata.cpuThrottling }
|
|
47
|
+
: {}),
|
|
48
|
+
...(metadata?.networkThrottling !== undefined
|
|
49
|
+
? { networkThrottling: metadata.networkThrottling }
|
|
50
|
+
: {}),
|
|
51
|
+
};
|
|
52
|
+
const hasMetadata = Object.keys(combinedMetadata).length > 0;
|
|
53
|
+
// Instantiate a fresh TraceModel per invocation because Model permanently
|
|
54
|
+
// retains parsed traces in its internal `#traces` array, which causes an
|
|
55
|
+
// unbounded memory leak if reused across sessions.
|
|
56
|
+
const engine = DevTools.TraceEngine.TraceModel.Model.createWithAllHandlers();
|
|
57
|
+
await engine.parse(events, {
|
|
58
|
+
metadata: hasMetadata ? combinedMetadata : undefined,
|
|
59
|
+
});
|
|
29
60
|
const parsedTrace = engine.parsedTrace();
|
|
30
61
|
if (!parsedTrace) {
|
|
31
62
|
return {
|
|
32
63
|
error: 'No parsed trace was returned from the trace engine.',
|
|
33
64
|
};
|
|
34
65
|
}
|
|
35
|
-
const insights = parsedTrace
|
|
66
|
+
const insights = parsedTrace.insights ?? null;
|
|
36
67
|
return {
|
|
37
68
|
parsedTrace,
|
|
38
69
|
insights,
|
|
@@ -51,6 +82,13 @@ const extraFormatDescriptions = `Information on performance traces may contain m
|
|
|
51
82
|
${DevTools.PerformanceTraceFormatter.callFrameDataFormatDescription}
|
|
52
83
|
|
|
53
84
|
${DevTools.PerformanceTraceFormatter.networkDataFormatDescription}`;
|
|
85
|
+
/**
|
|
86
|
+
* Generates a Markdown summary of main thread activity and network metrics from a parsed trace.
|
|
87
|
+
*
|
|
88
|
+
* @param result - The parsed trace result to summarize.
|
|
89
|
+
* @param deviceScope - Optional CrUX device scope to filter field data.
|
|
90
|
+
* @returns Formatted Markdown text describing performance findings.
|
|
91
|
+
*/
|
|
54
92
|
export function getTraceSummary(result, deviceScope) {
|
|
55
93
|
const focus = DevTools.AgentFocus.fromParsedTrace(result.parsedTrace);
|
|
56
94
|
const formatter = new DevTools.PerformanceTraceFormatter(focus, deviceScope);
|
|
@@ -61,6 +99,15 @@ ${summaryText}
|
|
|
61
99
|
## Details on call tree & network request formats:
|
|
62
100
|
${extraFormatDescriptions}`;
|
|
63
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Formats a specific performance insight from a parsed trace for display.
|
|
104
|
+
*
|
|
105
|
+
* @param result - The parsed trace result containing computed insight sets.
|
|
106
|
+
* @param insightSetId - The identifier of the target insight set.
|
|
107
|
+
* @param insightName - The name of the insight model to extract.
|
|
108
|
+
* @param deviceScope - Optional CrUX device scope to contextualize metrics.
|
|
109
|
+
* @returns An object containing the formatted insight output text or an error message.
|
|
110
|
+
*/
|
|
64
111
|
export function getInsightOutput(result, insightSetId, insightName, deviceScope) {
|
|
65
112
|
if (!result.insights) {
|
|
66
113
|
return {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import process from 'node:process';
|
|
7
7
|
import { DAEMON_CLIENT_NAME } from '../daemon/utils.js';
|
|
8
8
|
import { logger } from '../utils/logger.js';
|
|
9
|
-
import { bucketizeLatency, buildContext, sanitizeParams, stripUnderscoreBeforeNumber, } from './transformation.js';
|
|
9
|
+
import { bucketizeDaysSince, bucketizeLatency, buildContext, sanitizeClientName, sanitizeParams, stripUnderscoreBeforeNumber, } from './transformation.js';
|
|
10
10
|
import { McpClient, WatchdogMessageType, OsType, } from './types.js';
|
|
11
11
|
import { WatchdogClient } from './WatchdogClient.js';
|
|
12
12
|
const MS_PER_DAY = 24 * 60 * 60 * 1000;
|
|
@@ -22,12 +22,33 @@ function detectOsType() {
|
|
|
22
22
|
return OsType.OS_TYPE_UNSPECIFIED;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
function isSameDay(d1, d2) {
|
|
26
|
+
return (d1.getUTCFullYear() === d2.getUTCFullYear() &&
|
|
27
|
+
d1.getUTCMonth() === d2.getUTCMonth() &&
|
|
28
|
+
d1.getUTCDate() === d2.getUTCDate());
|
|
29
|
+
}
|
|
30
|
+
function shouldLogDailyActive(state) {
|
|
31
|
+
if (!state.lastActive) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return !isSameDay(new Date(state.lastActive), new Date());
|
|
35
|
+
}
|
|
36
|
+
function calculateDaysSince(lastDateString, now = new Date()) {
|
|
37
|
+
if (!lastDateString) {
|
|
38
|
+
return -1;
|
|
39
|
+
}
|
|
40
|
+
const lastDate = new Date(lastDateString);
|
|
41
|
+
const diffTime = Math.abs(now.getTime() - lastDate.getTime());
|
|
42
|
+
return Math.ceil(diffTime / MS_PER_DAY);
|
|
43
|
+
}
|
|
25
44
|
// Not const to allow resetting the instance for testing purposes.
|
|
26
45
|
let _clearcut_logger_instance;
|
|
27
46
|
export class ClearcutLogger {
|
|
28
47
|
#persistence;
|
|
29
48
|
#watchdog;
|
|
30
49
|
#mcpClient;
|
|
50
|
+
#rawClientName;
|
|
51
|
+
#state;
|
|
31
52
|
static initialize(options) {
|
|
32
53
|
if (_clearcut_logger_instance) {
|
|
33
54
|
throw new Error('ClearcutLogger is already initialized');
|
|
@@ -55,6 +76,15 @@ export class ClearcutLogger {
|
|
|
55
76
|
clearcutIncludePidHeader: options.clearcutIncludePidHeader,
|
|
56
77
|
});
|
|
57
78
|
this.#mcpClient = McpClient.MCP_CLIENT_UNSPECIFIED;
|
|
79
|
+
void this.#persistence
|
|
80
|
+
.loadState()
|
|
81
|
+
.then(state => {
|
|
82
|
+
this.#state = state;
|
|
83
|
+
})
|
|
84
|
+
.catch(error => {
|
|
85
|
+
this.#state = undefined;
|
|
86
|
+
logger?.('Failed to load telemetry state:', error);
|
|
87
|
+
});
|
|
58
88
|
}
|
|
59
89
|
setClientName(clientName) {
|
|
60
90
|
const lowerName = clientName.toLowerCase();
|
|
@@ -88,11 +118,31 @@ export class ClearcutLogger {
|
|
|
88
118
|
else if (lowerName.includes('copilot')) {
|
|
89
119
|
this.#mcpClient = McpClient.MCP_CLIENT_GITHUB_COPILOT;
|
|
90
120
|
}
|
|
121
|
+
else if (lowerName.includes('hermes-agent')) {
|
|
122
|
+
this.#mcpClient = McpClient.MCP_CLIENT_HERMES;
|
|
123
|
+
}
|
|
91
124
|
else {
|
|
92
125
|
this.#mcpClient = McpClient.MCP_CLIENT_OTHER;
|
|
126
|
+
this.#rawClientName = sanitizeClientName(clientName);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
#addMcpClient(payload) {
|
|
130
|
+
const ext = {
|
|
131
|
+
...payload,
|
|
132
|
+
mcp_client: this.#mcpClient,
|
|
133
|
+
};
|
|
134
|
+
if (this.#mcpClient === McpClient.MCP_CLIENT_OTHER &&
|
|
135
|
+
this.#rawClientName !== undefined) {
|
|
136
|
+
ext.raw_mcp_client_info = {
|
|
137
|
+
raw_client_name: this.#rawClientName,
|
|
138
|
+
};
|
|
93
139
|
}
|
|
140
|
+
return ext;
|
|
94
141
|
}
|
|
95
142
|
async logToolInvocation(args) {
|
|
143
|
+
void this.#logToolActiveIfNeeded().catch(error => {
|
|
144
|
+
logger?.('Error in logToolActiveIfNeeded:', error);
|
|
145
|
+
});
|
|
96
146
|
const context = buildContext(args.devToolsData, args.pageUrl);
|
|
97
147
|
const sanitizedToolName = stripUnderscoreBeforeNumber(args.toolName);
|
|
98
148
|
const tool_invocation = {
|
|
@@ -110,45 +160,36 @@ export class ClearcutLogger {
|
|
|
110
160
|
}
|
|
111
161
|
this.#watchdog.send({
|
|
112
162
|
type: WatchdogMessageType.LOG_EVENT,
|
|
113
|
-
payload: {
|
|
114
|
-
mcp_client: this.#mcpClient,
|
|
163
|
+
payload: this.#addMcpClient({
|
|
115
164
|
tool_invocation: tool_invocation,
|
|
116
|
-
},
|
|
165
|
+
}),
|
|
117
166
|
});
|
|
118
167
|
}
|
|
119
168
|
async logServerStart(flagUsage) {
|
|
120
169
|
this.#watchdog.send({
|
|
121
170
|
type: WatchdogMessageType.LOG_EVENT,
|
|
122
|
-
payload: {
|
|
123
|
-
mcp_client: this.#mcpClient,
|
|
171
|
+
payload: this.#addMcpClient({
|
|
124
172
|
server_start: {
|
|
125
173
|
flag_usage: flagUsage,
|
|
126
174
|
},
|
|
127
|
-
},
|
|
175
|
+
}),
|
|
128
176
|
});
|
|
129
177
|
}
|
|
130
178
|
async logDailyActiveIfNeeded() {
|
|
131
179
|
try {
|
|
132
|
-
|
|
133
|
-
if (this.#
|
|
134
|
-
|
|
135
|
-
if (state.lastActive) {
|
|
136
|
-
const lastActiveDate = new Date(state.lastActive);
|
|
137
|
-
const now = new Date();
|
|
138
|
-
const diffTime = Math.abs(now.getTime() - lastActiveDate.getTime());
|
|
139
|
-
daysSince = Math.ceil(diffTime / MS_PER_DAY);
|
|
140
|
-
}
|
|
180
|
+
this.#state = await this.#persistence.loadState();
|
|
181
|
+
if (shouldLogDailyActive(this.#state)) {
|
|
182
|
+
const daysSince = calculateDaysSince(this.#state.lastActive);
|
|
141
183
|
this.#watchdog.send({
|
|
142
184
|
type: WatchdogMessageType.LOG_EVENT,
|
|
143
|
-
payload: {
|
|
144
|
-
mcp_client: this.#mcpClient,
|
|
185
|
+
payload: this.#addMcpClient({
|
|
145
186
|
daily_active: {
|
|
146
|
-
days_since_last_active: daysSince,
|
|
187
|
+
days_since_last_active: bucketizeDaysSince(daysSince),
|
|
147
188
|
},
|
|
148
|
-
},
|
|
189
|
+
}),
|
|
149
190
|
});
|
|
150
|
-
state.lastActive = new Date().toISOString();
|
|
151
|
-
await this.#persistence.saveState(state);
|
|
191
|
+
this.#state.lastActive = new Date().toISOString();
|
|
192
|
+
await this.#persistence.saveState(this.#state);
|
|
152
193
|
}
|
|
153
194
|
}
|
|
154
195
|
catch (err) {
|
|
@@ -158,28 +199,44 @@ export class ClearcutLogger {
|
|
|
158
199
|
async logServerError(args) {
|
|
159
200
|
this.#watchdog.send({
|
|
160
201
|
type: WatchdogMessageType.LOG_EVENT,
|
|
161
|
-
payload: {
|
|
162
|
-
mcp_client: this.#mcpClient,
|
|
202
|
+
payload: this.#addMcpClient({
|
|
163
203
|
server_error: {
|
|
164
204
|
tool_name: args.toolName
|
|
165
205
|
? stripUnderscoreBeforeNumber(args.toolName)
|
|
166
206
|
: '',
|
|
167
207
|
error_code: args.errorCode,
|
|
168
208
|
},
|
|
169
|
-
},
|
|
209
|
+
}),
|
|
170
210
|
});
|
|
171
211
|
}
|
|
172
|
-
#
|
|
173
|
-
if
|
|
174
|
-
|
|
212
|
+
async #logToolActiveIfNeeded() {
|
|
213
|
+
// Expect state loaded at first tool call, if not, just skip logging.
|
|
214
|
+
if (!this.#state) {
|
|
215
|
+
return;
|
|
175
216
|
}
|
|
176
|
-
|
|
217
|
+
// Don't log tool active if it has already been logged today.
|
|
177
218
|
const now = new Date();
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
219
|
+
if (this.#state.lastToolCall &&
|
|
220
|
+
isSameDay(now, new Date(this.#state.lastToolCall))) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
// Refresh state in case it now contains more recent value, and test again.
|
|
224
|
+
const state = await this.#persistence.loadState();
|
|
225
|
+
this.#state = state;
|
|
226
|
+
if (state.lastToolCall && isSameDay(now, new Date(state.lastToolCall))) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const daysSinceToolCall = calculateDaysSince(state.lastToolCall, now);
|
|
230
|
+
this.#watchdog.send({
|
|
231
|
+
type: WatchdogMessageType.LOG_EVENT,
|
|
232
|
+
payload: this.#addMcpClient({
|
|
233
|
+
tool_active: {
|
|
234
|
+
days_since_last_tool_call: bucketizeDaysSince(daysSinceToolCall),
|
|
235
|
+
},
|
|
236
|
+
}),
|
|
237
|
+
});
|
|
238
|
+
this.#state.lastToolCall = now.toISOString();
|
|
239
|
+
await this.#persistence.saveState(this.#state);
|
|
183
240
|
}
|
|
184
241
|
}
|
|
185
242
|
//# sourceMappingURL=ClearcutLogger.js.map
|
|
@@ -42,6 +42,9 @@ export function applyToExisting(existing, update) {
|
|
|
42
42
|
if (!updatedNames.has(entry.name)) {
|
|
43
43
|
toAdd.isDeprecated = true;
|
|
44
44
|
}
|
|
45
|
+
else {
|
|
46
|
+
delete toAdd.isDeprecated;
|
|
47
|
+
}
|
|
45
48
|
result.push(toAdd);
|
|
46
49
|
}
|
|
47
50
|
// New entries must be added to the very back of the list.
|
|
@@ -10,6 +10,18 @@ import process from 'node:process';
|
|
|
10
10
|
import { logger } from '../utils/logger.js';
|
|
11
11
|
import { ClearcutLogger } from './ClearcutLogger.js';
|
|
12
12
|
import { ErrorCode } from './errors.js';
|
|
13
|
+
function isValidTime(time) {
|
|
14
|
+
if (time === undefined) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (typeof time !== 'string' || time === '') {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return !Number.isNaN(new Date(time).getTime());
|
|
21
|
+
}
|
|
22
|
+
function isContextValid(state) {
|
|
23
|
+
return isValidTime(state.lastActive) && isValidTime(state.lastToolCall);
|
|
24
|
+
}
|
|
13
25
|
const STATE_FILE_NAME = 'telemetry_state.json';
|
|
14
26
|
function getDataFolder() {
|
|
15
27
|
const homedir = os.homedir();
|
|
@@ -36,23 +48,21 @@ export class FilePersistence {
|
|
|
36
48
|
}
|
|
37
49
|
catch {
|
|
38
50
|
// File doesn't exist. Not an error because new users do not have the state file.
|
|
39
|
-
return {
|
|
40
|
-
lastActive: '',
|
|
41
|
-
};
|
|
51
|
+
return {};
|
|
42
52
|
}
|
|
53
|
+
let state;
|
|
43
54
|
try {
|
|
44
55
|
const content = await fs.readFile(filePath, 'utf-8');
|
|
45
|
-
|
|
56
|
+
state = JSON.parse(content);
|
|
46
57
|
}
|
|
47
58
|
catch (error) {
|
|
48
59
|
logger?.(`Failed to read telemetry state from ${filePath}:`, error);
|
|
49
60
|
void ClearcutLogger.get()?.logServerError({
|
|
50
61
|
errorCode: ErrorCode.ERROR_CODE_PERSISTENCE_FILE_READ_FAILED,
|
|
51
62
|
});
|
|
52
|
-
return {
|
|
53
|
-
lastActive: '',
|
|
54
|
-
};
|
|
63
|
+
return {};
|
|
55
64
|
}
|
|
65
|
+
return isContextValid(state) ? state : {};
|
|
56
66
|
}
|
|
57
67
|
async saveState(state) {
|
|
58
68
|
const filePath = path.join(this.#dataFolder, STATE_FILE_NAME);
|
|
@@ -13,6 +13,21 @@ export function bucketizeLatency(latencyMs) {
|
|
|
13
13
|
}
|
|
14
14
|
return LATENCY_BUCKETS[LATENCY_BUCKETS.length - 1];
|
|
15
15
|
}
|
|
16
|
+
export const MAX_ACTIVE_DAYS = 31;
|
|
17
|
+
export function bucketizeDaysSince(days) {
|
|
18
|
+
return Math.min(days, MAX_ACTIVE_DAYS);
|
|
19
|
+
}
|
|
20
|
+
export const REDACTED_CLIENT_NAME = '<redacted>';
|
|
21
|
+
const VALID_CLIENT_NAME_REGEX = /^[a-zA-Z0-9_-]+$/;
|
|
22
|
+
const MAX_CLIENT_NAME_LENGTH = 32;
|
|
23
|
+
export function sanitizeClientName(clientName) {
|
|
24
|
+
if (clientName.length > 0 &&
|
|
25
|
+
clientName.length < MAX_CLIENT_NAME_LENGTH &&
|
|
26
|
+
VALID_CLIENT_NAME_REGEX.test(clientName)) {
|
|
27
|
+
return clientName;
|
|
28
|
+
}
|
|
29
|
+
return REDACTED_CLIENT_NAME;
|
|
30
|
+
}
|
|
16
31
|
export const PARAM_BLOCKLIST = new Set(['uid', 'reqid', 'msgid']);
|
|
17
32
|
const SUPPORTED_ZOD_TYPES = [
|
|
18
33
|
'ZodString',
|
|
@@ -21,12 +36,21 @@ const SUPPORTED_ZOD_TYPES = [
|
|
|
21
36
|
'ZodArray',
|
|
22
37
|
'ZodEnum',
|
|
23
38
|
];
|
|
39
|
+
function isObjectWithDef(val) {
|
|
40
|
+
return typeof val === 'object' && val !== null && '_def' in val;
|
|
41
|
+
}
|
|
24
42
|
function isZodType(type) {
|
|
25
43
|
return SUPPORTED_ZOD_TYPES.includes(type);
|
|
26
44
|
}
|
|
27
45
|
export function getZodType(zodType) {
|
|
46
|
+
if (!isObjectWithDef(zodType)) {
|
|
47
|
+
throw new Error('Invalid zod schema');
|
|
48
|
+
}
|
|
28
49
|
const def = zodType._def;
|
|
29
|
-
|
|
50
|
+
let typeName = def.typeName;
|
|
51
|
+
if (!typeName && def.type) {
|
|
52
|
+
typeName = 'Zod' + def.type.charAt(0).toUpperCase() + def.type.slice(1);
|
|
53
|
+
}
|
|
30
54
|
if (typeName === 'ZodOptional' ||
|
|
31
55
|
typeName === 'ZodDefault' ||
|
|
32
56
|
typeName === 'ZodNullable') {
|
|
@@ -35,7 +59,14 @@ export function getZodType(zodType) {
|
|
|
35
59
|
if (typeName === 'ZodEffects') {
|
|
36
60
|
return getZodType(def.schema);
|
|
37
61
|
}
|
|
38
|
-
if (
|
|
62
|
+
if (typeName === 'ZodPipeline' || typeName === 'ZodPipe') {
|
|
63
|
+
return getZodType(isObjectWithDef(def.in) &&
|
|
64
|
+
(def.in._def.type === 'transform' ||
|
|
65
|
+
def.in._def.typeName === 'ZodTransform')
|
|
66
|
+
? def.out
|
|
67
|
+
: def.in);
|
|
68
|
+
}
|
|
69
|
+
if (typeName && isZodType(typeName)) {
|
|
39
70
|
return typeName;
|
|
40
71
|
}
|
|
41
72
|
throw new Error(`Unsupported zod type for tool parameter: ${typeName}`);
|
|
@@ -45,8 +76,14 @@ export function getZodType(zodType) {
|
|
|
45
76
|
* nullable/effects wrappers (in any order), mirroring {@link getZodType}.
|
|
46
77
|
*/
|
|
47
78
|
export function getEnumValues(zodType) {
|
|
79
|
+
if (!isObjectWithDef(zodType)) {
|
|
80
|
+
throw new Error('Invalid zod schema');
|
|
81
|
+
}
|
|
48
82
|
const def = zodType._def;
|
|
49
|
-
|
|
83
|
+
let typeName = def.typeName;
|
|
84
|
+
if (!typeName && def.type) {
|
|
85
|
+
typeName = 'Zod' + def.type.charAt(0).toUpperCase() + def.type.slice(1);
|
|
86
|
+
}
|
|
50
87
|
if (typeName === 'ZodOptional' ||
|
|
51
88
|
typeName === 'ZodDefault' ||
|
|
52
89
|
typeName === 'ZodNullable') {
|
|
@@ -55,8 +92,20 @@ export function getEnumValues(zodType) {
|
|
|
55
92
|
if (typeName === 'ZodEffects') {
|
|
56
93
|
return getEnumValues(def.schema);
|
|
57
94
|
}
|
|
95
|
+
if (typeName === 'ZodPipeline' || typeName === 'ZodPipe') {
|
|
96
|
+
return getEnumValues(isObjectWithDef(def.in) &&
|
|
97
|
+
(def.in._def.type === 'transform' ||
|
|
98
|
+
def.in._def.typeName === 'ZodTransform')
|
|
99
|
+
? def.out
|
|
100
|
+
: def.in);
|
|
101
|
+
}
|
|
58
102
|
if (typeName === 'ZodEnum') {
|
|
59
|
-
|
|
103
|
+
if (def.values) {
|
|
104
|
+
return def.values;
|
|
105
|
+
}
|
|
106
|
+
if (def.entries) {
|
|
107
|
+
return Object.values(def.entries);
|
|
108
|
+
}
|
|
60
109
|
}
|
|
61
110
|
throw new Error(`Cannot resolve enum values for zod type: ${typeName}`);
|
|
62
111
|
}
|
|
@@ -24,6 +24,7 @@ export var McpClient;
|
|
|
24
24
|
McpClient[McpClient["MCP_CLIENT_OPENCODE"] = 9] = "MCP_CLIENT_OPENCODE";
|
|
25
25
|
McpClient[McpClient["MCP_CLIENT_CLAUDE_DESKTOP"] = 10] = "MCP_CLIENT_CLAUDE_DESKTOP";
|
|
26
26
|
McpClient[McpClient["MCP_CLIENT_GITHUB_COPILOT"] = 11] = "MCP_CLIENT_GITHUB_COPILOT";
|
|
27
|
+
McpClient[McpClient["MCP_CLIENT_HERMES"] = 12] = "MCP_CLIENT_HERMES";
|
|
27
28
|
McpClient[McpClient["MCP_CLIENT_OTHER"] = 3] = "MCP_CLIENT_OTHER";
|
|
28
29
|
})(McpClient || (McpClient = {}));
|
|
29
30
|
// IPC types for messages between the main process and the
|