mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
add typecheck script and fix TypeScript errors (#48)
This commit is contained in:
1 parent
e853660ad3
commit
ed4bc17987
14 files changed
+371
-137
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import React from 'react'
|
||||
import { Copy } from 'lucide-react'
|
||||
import { CopyButton } from '@/components/ui/copy-button'
|
||||
import { useMobile } from '@/hooks/useMobile'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
@@ -59,7 +59,6 @@ function detectLanguage(fileName: string): string {
|
||||
|
||||
export function CodePreview({ fileName, content }: CodePreviewProps) {
|
||||
const isMobile = useMobile()
|
||||
const [copied, setCopied] = React.useState(false)
|
||||
const [showMore, setShowMore] = React.useState(false)
|
||||
|
||||
const language = detectLanguage(fileName)
|
||||
@@ -73,27 +72,11 @@ export function CodePreview({ fileName, content }: CodePreviewProps) {
|
||||
? lines.slice(0, INITIAL_CODE_LINES).join('\n')
|
||||
: content
|
||||
|
||||
const handleCopy = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(content)
|
||||
setCopied(true)
|
||||
setTimeout(() => setCopied(false), 2000)
|
||||
} catch (err) {
|
||||
console.error('Failed to copy:', err)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col bg-background">
|
||||
<div className="px-3 py-2 bg-muted/30 border-b border-border/50 flex items-center justify-between text-xs">
|
||||
<span className="font-medium truncate flex-1">{extractFileFromPath(fileName)}</span>
|
||||
<button
|
||||
onClick={handleCopy}
|
||||
className="p-1 hover:bg-accent rounded flex-shrink-0"
|
||||
title={copied ? 'Copied!' : 'Copy'}
|
||||
>
|
||||
<Copy className={cn('w-3.5 h-3.5', copied && 'text-green-500')} />
|
||||
</button>
|
||||
<CopyButton content={content} title="Copy" iconSize="sm" variant="ghost" className="flex-shrink-0" />
|
||||
</div>
|
||||
|
||||
<div className={cn('overflow-y-auto', isMobile ? 'max-h-64' : 'max-h-96')}>
|
||||
|
||||
@@ -145,7 +145,8 @@ export const MessagePart = memo(function MessagePart({ part, role, allParts, par
|
||||
)
|
||||
case 'step-finish': {
|
||||
const isFree = part.cost === 0
|
||||
const costText = isMobile && isFree ? null : <span>${part.cost.toFixed(4)} • {part.tokens.input + part.tokens.output} tokens</span>
|
||||
const totalTokens = part.tokens.input + part.tokens.output + (part.tokens.cache?.read || 0)
|
||||
const costText = isMobile && isFree ? null : <span>${part.cost.toFixed(4)} • {totalTokens} tokens</span>
|
||||
return (
|
||||
<div className="text-xs text-muted-foreground my-1 flex items-center gap-2">
|
||||
{costText}
|
||||
|
||||
@@ -4,7 +4,8 @@ import remarkGfm from 'remark-gfm'
|
||||
import rehypeHighlight from 'rehype-highlight'
|
||||
import rehypeRaw from 'rehype-raw'
|
||||
import mermaid from 'mermaid'
|
||||
import { Copy, Check, Maximize2, X, AlertCircle } from 'lucide-react'
|
||||
import { Maximize2, X, AlertCircle } from 'lucide-react'
|
||||
import { CopyButton } from '@/components/ui/copy-button'
|
||||
import type { components } from '@/api/opencode-types'
|
||||
import { useTheme } from '@/hooks/useTheme'
|
||||
import 'highlight.js/styles/github-dark.css'
|
||||
@@ -23,7 +24,6 @@ function MermaidBlock({ code }: MermaidBlockProps) {
|
||||
const [svg, setSvg] = useState<string | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [isExpanded, setIsExpanded] = useState(false)
|
||||
const [copied, setCopied] = useState(false)
|
||||
const theme = useTheme()
|
||||
const uniqueId = useId().replace(/:/g, '-')
|
||||
const renderAttempt = React.useRef(0)
|
||||
@@ -71,16 +71,6 @@ function MermaidBlock({ code }: MermaidBlockProps) {
|
||||
renderDiagram()
|
||||
}, [renderDiagram, theme])
|
||||
|
||||
const handleCopy = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(code)
|
||||
setCopied(true)
|
||||
setTimeout(() => setCopied(false), 2000)
|
||||
} catch (err) {
|
||||
console.error('Failed to copy:', err)
|
||||
}
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="relative my-4">
|
||||
@@ -94,13 +84,7 @@ function MermaidBlock({ code }: MermaidBlockProps) {
|
||||
<code>{code}</code>
|
||||
</pre>
|
||||
</div>
|
||||
<button
|
||||
onClick={handleCopy}
|
||||
className="absolute top-2 right-2 p-1.5 rounded bg-card hover:bg-card-hover text-muted-foreground hover:text-foreground"
|
||||
title="Copy code"
|
||||
>
|
||||
{copied ? <Check className="w-4 h-4" /> : <Copy className="w-4 h-4" />}
|
||||
</button>
|
||||
<CopyButton content={code} title="Copy code" className="absolute top-2 right-2" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -128,13 +112,7 @@ function MermaidBlock({ code }: MermaidBlockProps) {
|
||||
>
|
||||
<Maximize2 className="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
onClick={handleCopy}
|
||||
className="p-1.5 rounded bg-card hover:bg-card-hover text-muted-foreground hover:text-foreground"
|
||||
title="Copy code"
|
||||
>
|
||||
{copied ? <Check className="w-4 h-4" /> : <Copy className="w-4 h-4" />}
|
||||
</button>
|
||||
<CopyButton content={code} title="Copy code" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -172,8 +150,6 @@ interface CodeBlockProps {
|
||||
}
|
||||
|
||||
function CodeBlock({ children, className, ...props }: CodeBlockProps) {
|
||||
const [copied, setCopied] = React.useState(false)
|
||||
|
||||
const extractTextContent = (node: React.ReactNode): string => {
|
||||
if (typeof node === 'string') return node
|
||||
if (typeof node === 'number') return node.toString()
|
||||
@@ -188,29 +164,13 @@ function CodeBlock({ children, className, ...props }: CodeBlockProps) {
|
||||
}
|
||||
|
||||
const codeContent = extractTextContent(children)
|
||||
|
||||
const handleCopyCode = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(codeContent)
|
||||
setCopied(true)
|
||||
setTimeout(() => setCopied(false), 2000)
|
||||
} catch (error) {
|
||||
console.error('Failed to copy code:', error)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<pre className={`bg-accent p-1 rounded-lg overflow-x-auto whitespace-pre-wrap break-words border border-border my-4 ${className || ''}`} {...props}>
|
||||
{children}
|
||||
</pre>
|
||||
<button
|
||||
onClick={handleCopyCode}
|
||||
className="absolute top-2 right-2 p-1.5 rounded bg-card hover:bg-card-hover text-muted-foreground hover:text-foreground"
|
||||
title="Copy code"
|
||||
>
|
||||
{copied ? <Check className="w-4 h-4" /> : <Copy className="w-4 h-4" />}
|
||||
</button>
|
||||
<CopyButton content={codeContent} title="Copy code" className="absolute top-2 right-2" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -247,11 +247,12 @@ export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCal
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<pre className="bg-accent p-3 rounded text-xs overflow-x-auto whitespace-pre-wrap cursor-pointer hover:bg-accent/80 transition-colors"
|
||||
onClick={() => navigator.clipboard.writeText(output)}
|
||||
title="Click to copy output">
|
||||
{output}
|
||||
</pre>
|
||||
<div className="relative">
|
||||
<pre className="bg-accent p-3 rounded text-xs overflow-x-auto whitespace-pre-wrap">
|
||||
{output}
|
||||
</pre>
|
||||
<CopyButton content={output} title="Copy output" className="absolute top-2 right-2" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -387,11 +388,14 @@ export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCal
|
||||
)}
|
||||
<div className="text-sm">
|
||||
<div className="text-muted-foreground mb-1">Output:</div>
|
||||
<pre className="bg-accent p-2 rounded text-xs overflow-x-auto whitespace-pre-wrap break-all cursor-pointer hover:bg-accent/80 transition-colors"
|
||||
onClick={() => part.state.status === 'completed' && navigator.clipboard.writeText(part.state.output)}
|
||||
title="Click to copy output">
|
||||
{part.state.status === 'completed' ? part.state.output : ''}
|
||||
</pre>
|
||||
<div className="relative">
|
||||
<pre className="bg-accent p-2 rounded text-xs overflow-x-auto whitespace-pre-wrap break-all">
|
||||
{part.state.status === 'completed' ? part.state.output : ''}
|
||||
</pre>
|
||||
{part.state.status === 'completed' && part.state.output && (
|
||||
<CopyButton content={part.state.output} title="Copy output" className="absolute top-1 right-1" iconSize="sm" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{part.state.time && (
|
||||
<div className="text-xs text-muted-foreground">
|
||||
|
||||
Reference in new issue
Block a user