Skip to content

Commit 84087b3

Browse files
committed
chore: refactor codebase for improved type safety and consistency
- Changed several type definitions from `type` to `interface` for better extensibility in components such as `PieSlice`, `ConfirmationContextValue`, and `QueueMessagePart`. - Updated function parameters and return types to use more consistent array syntax (e.g., `Array<Type>` instead of `Type[]`) in components like `DataTableProps` and `AttachmentsContext`. - Refactored various components to use `void` for fire-and-forget function calls, ensuring no promises are returned where void is expected, particularly in `ChatProvider` and `WorkflowActions`. - Removed unnecessary ESLint disable comments to clean up the code and improve readability. - Adjusted default parameter values to use shorthand syntax in hooks like `useDebounce` and `useToggle`. - Improved conditional return statements for clarity and consistency across multiple components. - Removed a test template file that was no longer needed. - Updated ESLint configuration to enhance type checking and ensure better adherence to coding standards.
1 parent b8cd678 commit 84087b3

53 files changed

Lines changed: 329 additions & 358 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/admin/_components/admin-sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
Settings,
1414
} from 'lucide-react'
1515

16-
type NavItem = {
16+
interface NavItem {
1717
title: string
1818
href: Route
1919
icon: React.ComponentType<{ className?: string }>

app/api/contact/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { NextRequest, NextResponse } from 'next/server'
1+
import type { NextRequest} from 'next/server';
2+
import { NextResponse } from 'next/server'
23

34
interface ContactFormData {
45
firstName: string

app/chat/components/agent-artifact.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import type { ArtifactData } from './chat.types'
3030
interface AgentArtifactProps {
3131
artifact: ArtifactData
3232
onClose?: () => void
33-
// eslint-disable-next-line no-unused-vars
33+
3434
onCodeUpdate?: (artifactId: string, newCode: string) => void
3535
}
3636

@@ -59,14 +59,17 @@ export function AgentArtifact({
5959
artifact.type === 'code' &&
6060
PREVIEWABLE_LANGUAGES.includes(normalizeLanguage(artifact.language))
6161

62-
const handleCopy = useCallback(async () => {
63-
try {
64-
await navigator.clipboard.writeText(editedCode)
65-
setCopied(true)
66-
setTimeout(() => setCopied(false), 2000)
67-
} catch (err) {
68-
void err
62+
const handleCopy = useCallback(() => {
63+
const doCopy = async () => {
64+
try {
65+
await navigator.clipboard.writeText(editedCode)
66+
setCopied(true)
67+
setTimeout(() => setCopied(false), 2000)
68+
} catch (err) {
69+
void err
70+
}
6971
}
72+
void doCopy()
7073
}, [editedCode])
7174

7275
const handleDownload = useCallback(() => {
@@ -233,7 +236,7 @@ export function AgentArtifactCompact({
233236
// Floating action button for quick access to editor
234237
interface ArtifactEditorFABProps {
235238
artifact: ArtifactData
236-
// eslint-disable-next-line no-unused-vars
239+
237240
onCodeChange?: (newCode: string) => void
238241
}
239242

app/chat/components/agent-confirmation.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ interface AgentConfirmationProps {
2828
state: ToolUIPart['state']
2929
severity?: ConfirmationSeverity
3030
className?: string
31-
// eslint-disable-next-line no-unused-vars
32-
onApprove(approvalId: string): void
33-
// eslint-disable-next-line no-unused-vars
34-
onReject(approvalId: string): void
31+
32+
onApprove: (approvalId: string) => void
33+
34+
onReject: (approvalId: string) => void
3535
}
3636

3737
const severityConfig: Record<

app/chat/components/agent-web-preview.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
CheckIcon,
3737
PlayIcon,
3838
RotateCcwIcon,
39-
// eslint-disable-next-line no-unused-vars
39+
4040
Edit3Icon,
4141
EyeIcon,
4242
SplitIcon,
@@ -54,7 +54,7 @@ type PreviewStatus = 'idle' | 'running' | 'success' | 'error'
5454
interface AgentWebPreviewProps {
5555
preview: WebPreviewData
5656
onClose?: () => void
57-
// eslint-disable-next-line no-unused-vars
57+
5858
onCodeChange?: (code: string) => void
5959
defaultTab?: 'preview' | 'code'
6060
height?: string | number
@@ -444,7 +444,7 @@ export function AgentWebPreview({
444444
variant="ghost"
445445
size="sm"
446446
className="h-6 gap-1 px-2 text-xs"
447-
onClick={handleCopy}
447+
onClick={() => void handleCopy()}
448448
>
449449
{copied ? (
450450
<>
@@ -786,7 +786,7 @@ interface AgentCodeSandboxProps {
786786
title?: string
787787
dependencies?: Record<string, string>
788788
onClose?: () => void
789-
// eslint-disable-next-line no-unused-vars
789+
790790
onCodeChange?: (code: string) => void
791791
editable?: boolean
792792
}

app/chat/components/chat-messages.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable no-unused-vars */
1+
22
/* eslint-disable no-console */
33
'use client'
44

@@ -75,6 +75,7 @@ import type {
7575
} from '@mastra/ai-sdk'
7676
import { AgentTool } from '@/ui/agent-tool'
7777
import { cn } from '@/lib/utils'
78+
import type { LLMStepResult } from '@mastra/core/agent'
7879

7980
type MastraDataPart =
8081
| AgentDataPart
@@ -189,14 +190,16 @@ function extractTasksFromText(content: string): AgentTaskData[] {
189190
function CopyButton({ text }: { text: string }) {
190191
const [copied, setCopied] = useState(false)
191192

192-
const handleCopy = useCallback(async () => {
193-
try {
194-
await navigator.clipboard.writeText(text)
195-
setCopied(true)
196-
setTimeout(() => setCopied(false), 2000)
197-
} catch (err) {
198-
console.error('Failed to copy:', err)
199-
}
193+
const handleCopy = useCallback(() => {
194+
navigator.clipboard
195+
.writeText(text)
196+
.then(() => {
197+
setCopied(true)
198+
setTimeout(() => setCopied(false), 2000)
199+
})
200+
.catch((err) => {
201+
console.error('Failed to copy:', err)
202+
})
200203
}, [text])
201204

202205
return (
@@ -618,13 +621,16 @@ function MessageItem({
618621
partType === 'data-tool-workflow' ||
619622
partType === 'data-tool-network'
620623
) {
621-
const nestedPart = part as any
624+
const nestedPart = part as MastraDataPart
625+
// Use the actual nested data as the prop value. Cast to the expected type for TypeScript
626+
// (LLMStepResult is a type-only import so it cannot be used as a runtime value).
627+
const dataValue = (nestedPart as { data?: unknown }).data ?? {}
622628
return (
623629
<AgentTool
624630
key={`${message.id}-${partType}-${index}`}
625631
id={nestedPart.id ?? partType}
626-
type={partType as any}
627-
data={nestedPart.data}
632+
type={partType as unknown as 'data-tool-agent'}
633+
data={dataValue as LLMStepResult}
628634
/>
629635
)
630636
}

app/chat/components/chat.types.ts

Lines changed: 64 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,111 @@
1-
import type { ReactNode } from 'react'
21
import type { DynamicToolUIPart } from 'ai'
2+
import type { ReactNode } from 'react'
33
import type { ToolInvocationState as ChatToolInvocationState } from '../providers/chat-context-types'
44

55
export interface Citation {
6-
id: string
7-
number: string
8-
title: string
9-
url: string
10-
description?: string
11-
quote?: string
6+
id: string
7+
number: string
8+
title: string
9+
url: string
10+
description?: string
11+
quote?: string
1212
}
1313

1414
export interface AgentToolsProps {
15-
tools: Array<ChatToolInvocationState | DynamicToolUIPart>
16-
className?: string
15+
tools: Array<ChatToolInvocationState | DynamicToolUIPart>
16+
className?: string
1717
}
1818

1919
export type TaskStepStatus = 'pending' | 'running' | 'completed' | 'error'
2020

2121
export interface TaskStep {
22-
id: string
23-
text: string
24-
status: TaskStepStatus
25-
file?: {
26-
name: string
27-
icon?: string
28-
}
22+
id: string
23+
text: string
24+
status: TaskStepStatus
25+
file?: {
26+
name: string
27+
icon?: string
28+
}
2929
}
3030

3131
export interface AgentTaskData {
32-
title: string
33-
steps: TaskStep[]
32+
title: string
33+
steps: TaskStep[]
3434
}
3535

3636
export interface ArtifactData {
37-
id: string
38-
title: string
39-
description?: string
40-
type: 'code' | 'markdown' | 'json' | 'text' | 'html' | 'react'
41-
language?: string
42-
content: string
37+
id: string
38+
title: string
39+
description?: string
40+
type: 'code' | 'markdown' | 'json' | 'text' | 'html' | 'react'
41+
language?: string
42+
content: string
4343
}
4444

4545
export interface PlanStep {
46-
text: string
47-
completed?: boolean
46+
text: string
47+
completed?: boolean
4848
}
4949

5050
export interface AgentPlanData {
51-
title: string
52-
description: string
53-
steps: PlanStep[] | string[]
54-
isStreaming?: boolean
55-
currentStep?: number
51+
title: string
52+
description: string
53+
steps: PlanStep[] | string[]
54+
isStreaming?: boolean
55+
currentStep?: number
5656
}
5757

5858
export interface ReasoningStep {
59-
id: string
60-
label: string
61-
description?: string
62-
status: 'complete' | 'active' | 'pending'
63-
searchResults?: string[]
64-
duration?: number
59+
id: string
60+
label: string
61+
description?: string
62+
status: 'complete' | 'active' | 'pending'
63+
searchResults?: string[]
64+
duration?: number
6565
}
6666

6767
export interface AgentSuggestionsProps {
68-
suggestions: string[]
69-
// eslint-disable-next-line no-unused-vars
70-
onSelect: (suggestion: string) => void
71-
disabled?: boolean
72-
className?: string
68+
suggestions: string[]
69+
onSelect: (suggestion: string) => void
70+
disabled?: boolean
71+
className?: string
7372
}
7473

7574
export interface AgentSourcesProps {
76-
sources: Array<{ url: string; title: string }>
77-
className?: string
78-
maxVisible?: number
75+
sources: Array<{ url: string; title: string }>
76+
className?: string
77+
maxVisible?: number
7978
}
8079

8180
export interface AgentReasoningProps {
82-
reasoning: string
83-
isStreaming: boolean
84-
duration?: number
85-
className?: string
81+
reasoning: string
82+
isStreaming: boolean
83+
duration?: number
84+
className?: string
8685
}
8786

8887
export type ConfirmationSeverity = 'info' | 'warning' | 'danger'
8988

9089
export interface QueuedTask {
91-
id: string
92-
title: string
93-
description?: string
94-
status: 'pending' | 'running' | 'completed' | 'failed'
95-
createdAt?: Date
96-
completedAt?: Date
97-
error?: string
90+
id: string
91+
title: string
92+
description?: string
93+
status: 'pending' | 'running' | 'completed' | 'failed'
94+
createdAt?: Date
95+
completedAt?: Date
96+
error?: string
9897
}
9998

10099
export interface WebPreviewData {
101-
id: string
102-
url: string
103-
title?: string
104-
code?: string
105-
language?: string
106-
html?: string
107-
editable?: boolean
108-
showConsole?: boolean
109-
height?: number
100+
id: string
101+
url: string
102+
title?: string
103+
code?: string
104+
language?: string
105+
html?: string
106+
editable?: boolean
107+
showConsole?: boolean
108+
height?: number
110109
}
111110

112111
export type InlineCitationRender = ReactNode[]

0 commit comments

Comments
 (0)