Chrome DevTools for coding agents
refactor: extract the pagination logic (#242)
Nikolay Vitkov9af943176ef9
diff --git a/src/McpResponse.ts b/src/McpResponse.tsindex 77ab5e5a..fa3c69ae 100644--- a/src/McpResponse.ts+++ b/src/McpResponse.ts@@ -210,30 +210,12 @@ Call ${handleDialog.name} to handle it before continuing.`);response.push('## Network requests');if (requests.length) {- const paginationResult = paginate(+ const data = this.#dataWithPagination(requests,this.#networkRequestsOptions.pagination,);- if (paginationResult.invalidPage) {- response.push('Invalid page number provided. Showing first page.');- }-- const {startIndex, endIndex, currentPage, totalPages} =- paginationResult;- response.push(- `Showing ${startIndex + 1}-${endIndex} of ${requests.length} (Page ${currentPage + 1} of ${totalPages}).`,- );-- if (this.#networkRequestsOptions.pagination) {- if (paginationResult.hasNextPage) {- response.push(`Next page: ${currentPage + 1}`);- }- if (paginationResult.hasPreviousPage) {- response.push(`Previous page: ${currentPage - 1}`);- }- }-- for (const request of paginationResult.items) {+ response.push(...data.info);+ for (const request of data.items) {response.push(getShortDescriptionForRequest(request));}} else {@@ -264,6 +246,32 @@ Call ${handleDialog.name} to handle it before continuing.`);return [text, ...images];}+ #dataWithPagination<T>(data: T[], pagination?: PaginationOptions) {+ const response = [];+ const paginationResult = paginate<T>(data, pagination);+ if (paginationResult.invalidPage) {+ response.push('Invalid page number provided. Showing first page.');+ }++ const {startIndex, endIndex, currentPage, totalPages} = paginationResult;+ response.push(+ `Showing ${startIndex + 1}-${endIndex} of ${data.length} (Page ${currentPage + 1} of ${totalPages}).`,+ );+ if (pagination) {+ if (paginationResult.hasNextPage) {+ response.push(`Next page: ${currentPage + 1}`);+ }+ if (paginationResult.hasPreviousPage) {+ response.push(`Previous page: ${currentPage - 1}`);+ }+ }++ return {+ info: response,+ items: paginationResult.items,+ };+ }+#getIncludeNetworkRequestsData(context: McpContext): string[] {const response: string[] = [];const url = this.#attachedNetworkRequestUrl;