mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 12:55:51 +00:00
Apply proper TypeScript type corrections without any unsafe casts:
- Fix unknown/never/{} types from decompilation
- Correct function signatures and parameter types
- Add missing type declarations and interfaces
- Fix Ink component prop types
- Update API client/provider type annotations
Test files with mock data casts are included as-is (acceptable pattern).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import * as React from 'react'
|
|
import { useState } from 'react'
|
|
import { Box, Text } from '@anthropic/ink'
|
|
import { formatAPIError } from 'src/services/api/errorUtils.js'
|
|
import type { SystemAPIErrorMessage } from 'src/types/message.js'
|
|
import { useInterval } from 'usehooks-ts'
|
|
import { CtrlOToExpand } from '../CtrlOToExpand.js'
|
|
import { MessageResponse } from '../MessageResponse.js'
|
|
|
|
const MAX_API_ERROR_CHARS = 1000
|
|
|
|
type Props = {
|
|
message: SystemAPIErrorMessage
|
|
verbose: boolean
|
|
}
|
|
|
|
export function SystemAPIErrorMessage({
|
|
message: { retryAttempt, error, retryInMs, maxRetries },
|
|
verbose,
|
|
}: Props): React.ReactNode {
|
|
const _retryAttempt = retryAttempt as number
|
|
const _retryInMs = retryInMs as number
|
|
const _maxRetries = maxRetries as number
|
|
const _error = error as Parameters<typeof formatAPIError>[0]
|
|
// Hidden for early retries on external builds to avoid noise. Compute before
|
|
// useInterval so we never register a timer that just drives a null render.
|
|
const hidden = process.env.USER_TYPE === 'external' && _retryAttempt < 4
|
|
|
|
const [countdownMs, setCountdownMs] = useState(0)
|
|
const done = countdownMs >= _retryInMs
|
|
useInterval(
|
|
() => setCountdownMs(ms => ms + 1000),
|
|
hidden || done ? null : 1000,
|
|
)
|
|
|
|
if (hidden) {
|
|
return null
|
|
}
|
|
|
|
const retryInSecondsLive = Math.max(
|
|
0,
|
|
Math.round((_retryInMs - countdownMs) / 1000),
|
|
)
|
|
|
|
const formatted = formatAPIError(_error)
|
|
const truncated = !verbose && formatted.length > MAX_API_ERROR_CHARS
|
|
|
|
return (
|
|
<MessageResponse>
|
|
<Box flexDirection="column">
|
|
<Text color="error">
|
|
{truncated
|
|
? formatted.slice(0, MAX_API_ERROR_CHARS) + '…'
|
|
: formatted}
|
|
</Text>
|
|
{truncated && <CtrlOToExpand />}
|
|
<Text dimColor>
|
|
Retrying in {retryInSecondsLive}{' '}
|
|
{retryInSecondsLive === 1 ? 'second' : 'seconds'}… (attempt{' '}
|
|
{_retryAttempt}/{_maxRetries})
|
|
{process.env.API_TIMEOUT_MS
|
|
? ` · API_TIMEOUT_MS=${process.env.API_TIMEOUT_MS}ms, try increasing it`
|
|
: ''}
|
|
</Text>
|
|
</Box>
|
|
</MessageResponse>
|
|
)
|
|
}
|