Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
chore(frontend): replace 19 explicit `any` with precise types
Sergey Kozyrenko1ee2a6f7c95d
diff --git a/frontend/src/components/shared/markdown.tsx b/frontend/src/components/shared/markdown.tsxindex 4d02fa14..f99fb285 100644--- a/frontend/src/components/shared/markdown.tsx+++ b/frontend/src/components/shared/markdown.tsx@@ -19,8 +19,8 @@ import xml from 'highlight.js/lib/languages/xml';import yaml from 'highlight.js/lib/languages/yaml';import 'highlight.js/styles/atom-one-dark.css';import { common, createLowlight } from 'lowlight';-import { useCallback, useMemo } from 'react';-import ReactMarkdown from 'react-markdown';+import { isValidElement, type ReactNode, useCallback, useMemo } from 'react';+import ReactMarkdown, { type Components } from 'react-markdown';import rehypeHighlight from 'rehype-highlight';import rehypeSlug from 'rehype-slug';import remarkGfm from 'remark-gfm';@@ -141,7 +141,12 @@ function Markdown({ children, className, searchValue }: MarkdownProps) {);const processTextNode = useMemo(() => {- const fn = (nodeChildren: any): any => {+ const hasChildrenProp = (+ node: unknown,+ ): node is { key?: null | React.Key; props: { children: ReactNode } } =>+ isValidElement(node) && (node.props as { children?: ReactNode }).children !== undefined;++ const fn = (nodeChildren: ReactNode): ReactNode => {if (!processedSearch) {return nodeChildren;}@@ -156,7 +161,7 @@ function Markdown({ children, className, searchValue }: MarkdownProps) {return createHighlightedText(child);}- if (child && typeof child === 'object' && child.props && child.props.children !== undefined) {+ if (hasChildrenProp(child)) {return {...child,key: child.key || `processed-${index}`,@@ -171,12 +176,7 @@ function Markdown({ children, className, searchValue }: MarkdownProps) {});}- if (- nodeChildren &&- typeof nodeChildren === 'object' &&- nodeChildren.props &&- nodeChildren.props.children !== undefined- ) {+ if (hasChildrenProp(nodeChildren)) {return {...nodeChildren,props: {@@ -210,20 +210,21 @@ function Markdown({ children, className, searchValue }: MarkdownProps) {);const customComponents = useMemo(() => {- const components: Record<string, any> = {};+ const components: Components = {};if (processedSearch) {textElements.forEach((element) => {- components[element] = createComponentRenderer(element);+ (components as Record<string, ReturnType<typeof createComponentRenderer>>)[element] =+ createComponentRenderer(element);});// Code blocks pass through untouched — highlighting injected `<span>`s into a `<code>`// breaks rehype-highlight's tokenization and the rendered listing.- components.code = ({ children: nodeChildren, ...props }: any) => {+ components.code = ({ children: nodeChildren, ...props }) => {return <code {...props}>{nodeChildren}</code>;};- components.pre = ({ children: nodeChildren, ...props }: any) => {+ components.pre = ({ children: nodeChildren, ...props }) => {return <pre {...props}>{nodeChildren}</pre>;};}diff --git a/frontend/src/lib/log.ts b/frontend/src/lib/log.tsindex 5aff8f3b..6ac3209b 100644--- a/frontend/src/lib/log.ts+++ b/frontend/src/lib/log.ts@@ -7,7 +7,7 @@ export const Level = {export type Level = (typeof Level)[keyof typeof Level];-const dump = (prefix: string, obj: any) => {+const dump = (prefix: string, obj: unknown) => {if (console) {console.log(prefix, obj);}@@ -20,23 +20,23 @@ const valid = (checkLevel: Level) => {};export const Log = {- debug(msg: any) {+ debug(msg: unknown) {if (valid(Level.DEBUG)) {dump('[DEBUG] ', msg);}},- error(msg: any, err?: unknown) {+ error(msg: unknown, err?: unknown) {if (valid(Level.ERROR)) {dump('[ERROR] ', msg);console.error(err);}},- info(msg: any) {+ info(msg: unknown) {if (valid(Level.INFO)) {dump('[INFO] ', msg);}},- warn(msg: any) {+ warn(msg: unknown) {if (valid(Level.WARN)) {dump('[WARN] ', msg);}diff --git a/frontend/src/pages/settings/settings-prompt.tsx b/frontend/src/pages/settings/settings-prompt.tsxindex 43d57855..b5ce9e98 100644--- a/frontend/src/pages/settings/settings-prompt.tsx+++ b/frontend/src/pages/settings/settings-prompt.tsx@@ -14,11 +14,11 @@ import {} from 'lucide-react';import { useCallback, useEffect, useMemo, useRef, useState } from 'react';import ReactDiffViewer from 'react-diff-viewer-continued';-import { useController, useForm, useFormState } from 'react-hook-form';+import { type Control, type ControllerRenderProps, type FieldValues, useController, useForm, useFormState } from 'react-hook-form';import { useNavigate, useParams } from 'react-router-dom';import { z } from 'zod';-import type { AgentPrompt, AgentPrompts, DefaultPrompt, PromptType } from '@/graphql/types';+import type { AgentPrompt, AgentPrompts, DefaultPrompt, PromptType, ValidatePromptMutation } from '@/graphql/types';import ConfirmationDialog from '@/components/shared/confirmation-dialog';import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';@@ -56,7 +56,7 @@ interface BaseTextareaProps {}interface ControllerProps {- control: any;+ control: Control<FieldValues>;disabled?: boolean;name: string;}@@ -133,7 +133,7 @@ function SettingsPrompt() {const [submitError, setSubmitError] = useState<null | string>(null);const [activeTab, setActiveTab] = useState<'human' | 'system'>('system');const [resetDialogOpen, setResetDialogOpen] = useState(false);- const [validationResult, setValidationResult] = useState<any>(null);+ const [validationResult, setValidationResult] = useState<null | ValidatePromptMutation['validatePrompt']>(null);const [validationDialogOpen, setValidationDialogOpen] = useState(false);const [isDiffDialogOpen, setIsDiffDialogOpen] = useState(false);const [isLeaveDialogOpen, setIsLeaveDialogOpen] = useState(false);@@ -143,7 +143,7 @@ function SettingsPrompt() {const isLoading = isCreateLoading || isUpdateLoading || isDeleteLoading || isValidateLoading;- const handleVariableClick = (variable: string, field: any, formId: string) => {+ const handleVariableClick = (variable: string, field: ControllerRenderProps<FieldValues, string>, formId: string) => {const textarea = document.querySelector(`#${formId} textarea`) as HTMLTextAreaElement;if (textarea) {@@ -421,7 +421,7 @@ function SettingsPrompt() {window.addEventListener('popstate', handlePopState, { capture: true });return () => {- window.removeEventListener('popstate', handlePopState, { capture: true } as any);+ window.removeEventListener('popstate', handlePopState, { capture: true });};}, [isDirty]);diff --git a/frontend/src/pages/settings/settings-prompts.tsx b/frontend/src/pages/settings/settings-prompts.tsxindex a2fa9c2f..ab8945d5 100644--- a/frontend/src/pages/settings/settings-prompts.tsx+++ b/frontend/src/pages/settings/settings-prompts.tsx@@ -1,4 +1,4 @@-import type { ColumnDef } from '@tanstack/react-table';+import type { ColumnDef, Row } from '@tanstack/react-table';import {AlertCircle,@@ -593,8 +593,8 @@ function SettingsPrompts() {},];- const renderAgentSubComponent = ({ row }: { row: any }) => {- const agent = row.original as AgentPromptTableData;+ const renderAgentSubComponent = ({ row }: { row: Row<AgentPromptTableData> }) => {+ const agent = row.original;const userSystemPrompt = data?.settingsPrompts?.userDefined?.find((p) => p.type === agent.systemType);const userHumanPrompt = data?.settingsPrompts?.userDefined?.find((p) => p.type === agent.humanType);@@ -652,8 +652,8 @@ function SettingsPrompts() {);};- const renderToolSubComponent = ({ row }: { row: any }) => {- const tool = row.original as ToolPromptTableData;+ const renderToolSubComponent = ({ row }: { row: Row<ToolPromptTableData> }) => {+ const tool = row.original;const userToolPrompt = data?.settingsPrompts?.userDefined?.find((p) => p.type === tool.promptType);diff --git a/frontend/src/pages/settings/settings-providers.tsx b/frontend/src/pages/settings/settings-providers.tsxindex a311c5f1..a0d3fff6 100644--- a/frontend/src/pages/settings/settings-providers.tsx+++ b/frontend/src/pages/settings/settings-providers.tsx@@ -1,4 +1,4 @@-import type { ColumnDef } from '@tanstack/react-table';+import type { ColumnDef, Row } from '@tanstack/react-table';import { AlertCircle, ChevronDown, Copy, Ellipsis, Loader2, Pencil, Plus, Settings, Trash } from 'lucide-react';import { useCallback, useMemo, useState } from 'react';@@ -35,7 +35,7 @@ import { useTableState } from '@/hooks/use-table-state';import { formatDate } from '@/lib/utils/format';type Provider = ProviderConfigFragmentFragment;-const providerIcons: Record<ProviderType, React.ComponentType<any>> = {+const providerIcons: Record<ProviderType, React.ComponentType<React.SVGProps<SVGSVGElement>>> = {[ProviderType.Anthropic]: Anthropic,[ProviderType.Bedrock]: Bedrock,[ProviderType.Custom]: Custom,@@ -259,8 +259,8 @@ function SettingsProviders() {[handleProviderClone, handleProviderDeleteDialogOpen, handleProviderEdit, isDeleteLoading, deletingProvider],);- const renderSubComponent = ({ row }: { row: any }) => {- const provider = row.original as Provider;+ const renderSubComponent = ({ row }: { row: Row<Provider> }) => {+ const provider = row.original;const { agents } = provider;if (!agents) {@@ -270,12 +270,12 @@ function SettingsProviders() {const getName = (key: string): string =>key.replaceAll(/([A-Z])/g, ' $1').replace(/^./, (item) => item.toUpperCase());- const getFields = (obj: any, prefix = ''): { label: string; value: boolean | number | string }[] => {+ const getFields = (obj: unknown, prefix = ''): { label: string; value: boolean | number | string }[] => {if (!obj || typeof obj !== 'object') {return [];}- return Object.entries(obj)+ return Object.entries(obj as Record<string, unknown>).filter(([key, value]) => key !== '__typename' && !!value).flatMap(([key, value]) => {const label = `${prefix ? `${prefix} ` : ''}${getName(key)}`;