Skip to content

Commit 1881258

Browse files
author
Piotr Paulski
committed
Update zod imports for better readability.
1 parent 82163cf commit 1881258

File tree

11 files changed

+65
-63
lines changed

11 files changed

+65
-63
lines changed

src/third_party/modelcontextprotocol-sdk/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ export {
1212
type ImageContent,
1313
type TextContent,
1414
} from '@modelcontextprotocol/sdk/types.js';
15-
export {default as z} from 'zod';
15+
export {z as zod} from 'zod';

src/tools/ToolDefinition.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
import type {Dialog, ElementHandle, Page} from 'puppeteer-core';
88

99
import type {TextSnapshotNode} from '../McpContext.js';
10-
import {z} from '../third_party/modelcontextprotocol-sdk/index.js';
10+
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
1111
import type {TraceResult} from '../trace-processing/parse.js';
1212
import type {PaginationOptions} from '../utils/types.js';
1313

1414
import type {ToolCategories} from './categories.js';
1515

16-
export interface ToolDefinition<Schema extends z.ZodRawShape = z.ZodRawShape> {
16+
export interface ToolDefinition<
17+
Schema extends zod.ZodRawShape = zod.ZodRawShape,
18+
> {
1719
name: string;
1820
description: string;
1921
annotations: {
@@ -32,8 +34,8 @@ export interface ToolDefinition<Schema extends z.ZodRawShape = z.ZodRawShape> {
3234
) => Promise<void>;
3335
}
3436

35-
export interface Request<Schema extends z.ZodRawShape> {
36-
params: z.objectOutputType<Schema, z.ZodTypeAny>;
37+
export interface Request<Schema extends zod.ZodRawShape> {
38+
params: zod.objectOutputType<Schema, zod.ZodTypeAny>;
3739
}
3840

3941
export interface ImageContentData {
@@ -92,7 +94,7 @@ export type Context = Readonly<{
9294
waitForEventsAfterAction(action: () => Promise<unknown>): Promise<void>;
9395
}>;
9496

95-
export function defineTool<Schema extends z.ZodRawShape>(
97+
export function defineTool<Schema extends zod.ZodRawShape>(
9698
definition: ToolDefinition<Schema>,
9799
) {
98100
return definition;
@@ -102,7 +104,7 @@ export const CLOSE_PAGE_ERROR =
102104
'The last open page cannot be closed. It is fine to keep it open.';
103105

104106
export const timeoutSchema = {
105-
timeout: z
107+
timeout: zod
106108
.number()
107109
.int()
108110
.optional()

src/tools/console.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import type {ConsoleMessageType} from 'puppeteer-core';
88

9-
import {z} from '../third_party/modelcontextprotocol-sdk/index.js';
9+
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
1010

1111
import {ToolCategories} from './categories.js';
1212
import {defineTool} from './ToolDefinition.js';
@@ -45,24 +45,24 @@ export const consoleTool = defineTool({
4545
readOnlyHint: true,
4646
},
4747
schema: {
48-
pageSize: z
48+
pageSize: zod
4949
.number()
5050
.int()
5151
.positive()
5252
.optional()
5353
.describe(
5454
'Maximum number of messages to return. When omitted, returns all requests.',
5555
),
56-
pageIdx: z
56+
pageIdx: zod
5757
.number()
5858
.int()
5959
.min(0)
6060
.optional()
6161
.describe(
6262
'Page number to return (0-based). When omitted, returns the first page.',
6363
),
64-
types: z
65-
.array(z.enum(FILTERABLE_MESSAGE_TYPES))
64+
types: zod
65+
.array(zod.enum(FILTERABLE_MESSAGE_TYPES))
6666
.optional()
6767
.describe(
6868
'Filter messages to only return messages of the specified resource types. When omitted or empty, returns all messages.',

src/tools/emulation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import {PredefinedNetworkConditions} from 'puppeteer-core';
88

9-
import {z} from '../third_party/modelcontextprotocol-sdk/index.js';
9+
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
1010

1111
import {ToolCategories} from './categories.js';
1212
import {defineTool} from './ToolDefinition.js';
@@ -25,7 +25,7 @@ export const emulateNetwork = defineTool({
2525
readOnlyHint: false,
2626
},
2727
schema: {
28-
throttlingOption: z
28+
throttlingOption: zod
2929
.enum(throttlingOptions)
3030
.describe(
3131
`The network throttling option to emulate. Available throttling options are: ${throttlingOptions.join(', ')}. Set to "No emulation" to disable. Set to "Offline" to simulate offline network conditions.`,
@@ -71,7 +71,7 @@ export const emulateCpu = defineTool({
7171
readOnlyHint: false,
7272
},
7373
schema: {
74-
throttlingRate: z
74+
throttlingRate: zod
7575
.number()
7676
.min(1)
7777
.max(20)

src/tools/input.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import type {ElementHandle} from 'puppeteer-core';
88

99
import type {McpContext, TextSnapshotNode} from '../McpContext.js';
10-
import {z} from '../third_party/modelcontextprotocol-sdk/index.js';
10+
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
1111

1212
import {ToolCategories} from './categories.js';
1313
import {defineTool} from './ToolDefinition.js';
@@ -20,12 +20,12 @@ export const click = defineTool({
2020
readOnlyHint: false,
2121
},
2222
schema: {
23-
uid: z
23+
uid: zod
2424
.string()
2525
.describe(
2626
'The uid of an element on the page from the page content snapshot',
2727
),
28-
dblClick: z
28+
dblClick: zod
2929
.boolean()
3030
.optional()
3131
.describe('Set to true for double clicks. Default is false.'),
@@ -59,7 +59,7 @@ export const hover = defineTool({
5959
readOnlyHint: false,
6060
},
6161
schema: {
62-
uid: z
62+
uid: zod
6363
.string()
6464
.describe(
6565
'The uid of an element on the page from the page content snapshot',
@@ -143,12 +143,12 @@ export const fill = defineTool({
143143
readOnlyHint: false,
144144
},
145145
schema: {
146-
uid: z
146+
uid: zod
147147
.string()
148148
.describe(
149149
'The uid of an element on the page from the page content snapshot',
150150
),
151-
value: z.string().describe('The value to fill in'),
151+
value: zod.string().describe('The value to fill in'),
152152
},
153153
handler: async (request, response, context) => {
154154
await context.waitForEventsAfterAction(async () => {
@@ -171,8 +171,8 @@ export const drag = defineTool({
171171
readOnlyHint: false,
172172
},
173173
schema: {
174-
from_uid: z.string().describe('The uid of the element to drag'),
175-
to_uid: z.string().describe('The uid of the element to drop into'),
174+
from_uid: zod.string().describe('The uid of the element to drag'),
175+
to_uid: zod.string().describe('The uid of the element to drop into'),
176176
},
177177
handler: async (request, response, context) => {
178178
const fromHandle = await context.getElementByUid(request.params.from_uid);
@@ -200,11 +200,11 @@ export const fillForm = defineTool({
200200
readOnlyHint: false,
201201
},
202202
schema: {
203-
elements: z
203+
elements: zod
204204
.array(
205-
z.object({
206-
uid: z.string().describe('The uid of the element to fill out'),
207-
value: z.string().describe('Value for the element'),
205+
zod.object({
206+
uid: zod.string().describe('The uid of the element to fill out'),
207+
value: zod.string().describe('Value for the element'),
208208
}),
209209
)
210210
.describe('Elements from snapshot to fill out.'),
@@ -232,12 +232,12 @@ export const uploadFile = defineTool({
232232
readOnlyHint: false,
233233
},
234234
schema: {
235-
uid: z
235+
uid: zod
236236
.string()
237237
.describe(
238238
'The uid of the file input element or an element that will open file chooser on the page from the page content snapshot',
239239
),
240-
filePath: z.string().describe('The local path of the file to upload'),
240+
filePath: zod.string().describe('The local path of the file to upload'),
241241
},
242242
handler: async (request, response, context) => {
243243
const {uid, filePath} = request.params;

src/tools/network.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import type {ResourceType} from 'puppeteer-core';
88

9-
import {z} from '../third_party/modelcontextprotocol-sdk/index.js';
9+
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
1010

1111
import {ToolCategories} from './categories.js';
1212
import {defineTool} from './ToolDefinition.js';
@@ -41,24 +41,24 @@ export const listNetworkRequests = defineTool({
4141
readOnlyHint: true,
4242
},
4343
schema: {
44-
pageSize: z
44+
pageSize: zod
4545
.number()
4646
.int()
4747
.positive()
4848
.optional()
4949
.describe(
5050
'Maximum number of requests to return. When omitted, returns all requests.',
5151
),
52-
pageIdx: z
52+
pageIdx: zod
5353
.number()
5454
.int()
5555
.min(0)
5656
.optional()
5757
.describe(
5858
'Page number to return (0-based). When omitted, returns the first page.',
5959
),
60-
resourceTypes: z
61-
.array(z.enum(FILTERABLE_RESOURCE_TYPES))
60+
resourceTypes: zod
61+
.array(zod.enum(FILTERABLE_RESOURCE_TYPES))
6262
.optional()
6363
.describe(
6464
'Filter requests to only return requests of the specified resource types. When omitted or empty, returns all requests.',
@@ -81,7 +81,7 @@ export const getNetworkRequest = defineTool({
8181
readOnlyHint: true,
8282
},
8383
schema: {
84-
reqid: z
84+
reqid: zod
8585
.number()
8686
.describe(
8787
'The reqid of a request on the page from the listed network requests',

src/tools/pages.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import {logger} from '../logger.js';
8-
import {z} from '../third_party/modelcontextprotocol-sdk/index.js';
8+
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
99

1010
import {ToolCategories} from './categories.js';
1111
import {CLOSE_PAGE_ERROR, defineTool, timeoutSchema} from './ToolDefinition.js';
@@ -31,7 +31,7 @@ export const selectPage = defineTool({
3131
readOnlyHint: true,
3232
},
3333
schema: {
34-
pageIdx: z
34+
pageIdx: zod
3535
.number()
3636
.describe(
3737
'The index of the page to select. Call list_pages to list pages.',
@@ -53,7 +53,7 @@ export const closePage = defineTool({
5353
readOnlyHint: false,
5454
},
5555
schema: {
56-
pageIdx: z
56+
pageIdx: zod
5757
.number()
5858
.describe(
5959
'The index of the page to close. Call list_pages to list pages.',
@@ -81,7 +81,7 @@ export const newPage = defineTool({
8181
readOnlyHint: false,
8282
},
8383
schema: {
84-
url: z.string().describe('URL to load in a new page.'),
84+
url: zod.string().describe('URL to load in a new page.'),
8585
...timeoutSchema,
8686
},
8787
handler: async (request, response, context) => {
@@ -105,7 +105,7 @@ export const navigatePage = defineTool({
105105
readOnlyHint: false,
106106
},
107107
schema: {
108-
url: z.string().describe('URL to navigate the page to'),
108+
url: zod.string().describe('URL to navigate the page to'),
109109
...timeoutSchema,
110110
},
111111
handler: async (request, response, context) => {
@@ -129,7 +129,7 @@ export const navigatePageHistory = defineTool({
129129
readOnlyHint: false,
130130
},
131131
schema: {
132-
navigate: z
132+
navigate: zod
133133
.enum(['back', 'forward'])
134134
.describe(
135135
'Whether to navigate back or navigate forward in the selected pages history',
@@ -166,8 +166,8 @@ export const resizePage = defineTool({
166166
readOnlyHint: false,
167167
},
168168
schema: {
169-
width: z.number().describe('Page width'),
170-
height: z.number().describe('Page height'),
169+
width: zod.number().describe('Page width'),
170+
height: zod.number().describe('Page height'),
171171
},
172172
handler: async (request, response, context) => {
173173
const page = context.getSelectedPage();
@@ -190,10 +190,10 @@ export const handleDialog = defineTool({
190190
readOnlyHint: false,
191191
},
192192
schema: {
193-
action: z
193+
action: zod
194194
.enum(['accept', 'dismiss'])
195195
.describe('Whether to dismiss or accept the dialog'),
196-
promptText: z
196+
promptText: zod
197197
.string()
198198
.optional()
199199
.describe('Optional prompt text to enter into the dialog.'),

src/tools/performance.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import type {Page} from 'puppeteer-core';
88

99
import {logger} from '../logger.js';
10-
import {z} from '../third_party/modelcontextprotocol-sdk/index.js';
10+
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
1111
import type {InsightName} from '../trace-processing/parse.js';
1212
import {
1313
getInsightOutput,
@@ -29,12 +29,12 @@ export const startTrace = defineTool({
2929
readOnlyHint: true,
3030
},
3131
schema: {
32-
reload: z
32+
reload: zod
3333
.boolean()
3434
.describe(
3535
'Determines if, once tracing has started, the page should be automatically reloaded.',
3636
),
37-
autoStop: z
37+
autoStop: zod
3838
.boolean()
3939
.describe(
4040
'Determines if the trace recording should be automatically stopped.',
@@ -128,7 +128,7 @@ export const analyzeInsight = defineTool({
128128
readOnlyHint: true,
129129
},
130130
schema: {
131-
insightName: z
131+
insightName: zod
132132
.string()
133133
.describe(
134134
'The name of the Insight you want more information on. For example: "DocumentLatency" or "LCPBreakdown"',

0 commit comments

Comments
 (0)