Browse Source

fix(smartfetch): add explicit type annotations to resolve tsc errors (#267)

Add type annotations to implicit-any parameters in turndown callbacks,
LRUCache sizeCalculation, redirectChain.map calls, and querySelectorAll
result mapping.

This fixes the tsc --emitDeclarationOnly step that was blocking the
build chain, which in turn caused stale dist/ files to be published
with absolute maintainer paths (issue #265).
ReqX 2 days ago
parent
commit
8a21486667
3 changed files with 27 additions and 15 deletions
  1. 1 1
      src/tools/smartfetch/cache.ts
  2. 15 8
      src/tools/smartfetch/tool.ts
  3. 11 6
      src/tools/smartfetch/utils.ts

+ 1 - 1
src/tools/smartfetch/cache.ts

@@ -5,7 +5,7 @@ import type { FetchResult } from './types';
 export const CACHE = new LRUCache<string, FetchResult>({
   maxSize: 50 * 1024 * 1024,
   ttl: 15 * 60 * 1000,
-  sizeCalculation: (value) => {
+  sizeCalculation: (value: FetchResult) => {
     if ('binary' in value) return value.data?.byteLength ?? 1024;
     const rawContent =
       value.rawContent ?? value.html ?? value.markdown ?? value.text ?? '';

+ 15 - 8
src/tools/smartfetch/tool.ts

@@ -44,7 +44,7 @@ import {
   readSecondaryModelFromConfig,
   runSecondaryModelWithFallback,
 } from './secondary-model';
-import type { SmartfetchOptions } from './types';
+import type { RedirectStep, SmartfetchOptions } from './types';
 import {
   buildLlmsRequiredMessage,
   buildRedirectResultMessage,
@@ -273,7 +273,8 @@ export function createWebfetchTool(
                     redirect_url: result.redirectUrl,
                     status_code: result.statusCode,
                     redirect_chain: result.redirectChain.map(
-                      (step) => `${step.status} ${step.from} -> ${step.to}`,
+                      (step: RedirectStep) =>
+                        `${step.status} ${step.from} -> ${step.to}`,
                     ),
                     upgraded_to_https: upgradedToHttps,
                   })
@@ -547,7 +548,8 @@ export function createWebfetchTool(
                   filename: fetchResult.filename,
                   binary_kind: fetchResult.binaryKind,
                   redirect_chain: fetchResult.redirectChain.map(
-                    (step) => `${step.status} ${step.from} -> ${step.to}`,
+                    (step: RedirectStep) =>
+                      `${step.status} ${step.from} -> ${step.to}`,
                   ),
                   upgraded_to_https: fetchResult.upgradedToHttps,
                   llms_probe_error: fetchResult.llmsProbeError,
@@ -584,7 +586,8 @@ export function createWebfetchTool(
                   filename: fetchResult.filename,
                   binary_kind: fetchResult.binaryKind,
                   redirect_chain: fetchResult.redirectChain.map(
-                    (step) => `${step.status} ${step.from} -> ${step.to}`,
+                    (step: RedirectStep) =>
+                      `${step.status} ${step.from} -> ${step.to}`,
                   ),
                   upgraded_to_https: fetchResult.upgradedToHttps,
                   truncated: fetchResult.truncated,
@@ -621,7 +624,8 @@ export function createWebfetchTool(
                 filename: fetchResult.filename,
                 binary_kind: fetchResult.binaryKind,
                 redirect_chain: fetchResult.redirectChain.map(
-                  (step) => `${step.status} ${step.from} -> ${step.to}`,
+                  (step: RedirectStep) =>
+                    `${step.status} ${step.from} -> ${step.to}`,
                 ),
                 upgraded_to_https: fetchResult.upgradedToHttps,
                 llms_probe_error: fetchResult.llmsProbeError,
@@ -668,7 +672,8 @@ export function createWebfetchTool(
               used_llms_txt: fetchResult.usedLlmsTxt,
               extracted_main: fetchResult.extractedMain,
               redirect_chain: fetchResult.redirectChain.map(
-                (step) => `${step.status} ${step.from} -> ${step.to}`,
+                (step: RedirectStep) =>
+                  `${step.status} ${step.from} -> ${step.to}`,
               ),
               upgraded_to_https: fetchResult.upgradedToHttps,
               llms_probe_error: fetchResult.llmsProbeError,
@@ -733,7 +738,8 @@ export function createWebfetchTool(
                 used_llms_txt: fetchResult.usedLlmsTxt,
                 extracted_main: fetchResult.extractedMain,
                 redirect_chain: fetchResult.redirectChain.map(
-                  (step) => `${step.status} ${step.from} -> ${step.to}`,
+                  (step: RedirectStep) =>
+                    `${step.status} ${step.from} -> ${step.to}`,
                 ),
                 upgraded_to_https: fetchResult.upgradedToHttps,
                 llms_probe_error: fetchResult.llmsProbeError,
@@ -777,7 +783,8 @@ export function createWebfetchTool(
               used_llms_txt: fetchResult.usedLlmsTxt,
               extracted_main: fetchResult.extractedMain,
               redirect_chain: fetchResult.redirectChain.map(
-                (step) => `${step.status} ${step.from} -> ${step.to}`,
+                (step: RedirectStep) =>
+                  `${step.status} ${step.from} -> ${step.to}`,
               ),
               upgraded_to_https: fetchResult.upgradedToHttps,
               llms_probe_error: fetchResult.llmsProbeError,

+ 11 - 6
src/tools/smartfetch/utils.ts

@@ -255,17 +255,22 @@ const turndown = new TurndownService({
 
 turndown.remove(['script', 'style', 'noscript', 'meta', 'link']);
 turndown.remove(
-  (node) =>
-    node.nodeName === 'A' &&
+  (node: unknown) =>
+    (node as Element).nodeName === 'A' &&
     /permanent link/i.test((node as Element).getAttribute('title') || ''),
 );
 turndown.addRule('fenced-pre-code', {
-  filter(node) {
-    return node.nodeName === 'PRE' && !!(node as Element).querySelector('code');
+  filter(node: unknown) {
+    return (
+      (node as Element).nodeName === 'PRE' &&
+      !!(node as Element).querySelector('code')
+    );
   },
-  replacement(_content, node) {
+  replacement(_content: string, node: unknown) {
     const code = (node as Element).querySelector('code');
-    const text = trimBlankRuns(code?.textContent || node.textContent || '');
+    const text = trimBlankRuns(
+      code?.textContent || (node as Element).textContent || '',
+    );
     if (!text) return '';
     return `\n\n\`\`\`\n${text}\n\`\`\`\n\n`;
   },