mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-19 06:45:50 +00:00
feat: 添加 UI 组件增强与测试覆盖
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,59 @@
|
||||
// Auto-generated stub — replace with real implementation
|
||||
export function useFrustrationDetection(
|
||||
_messages: unknown[],
|
||||
_isLoading: boolean,
|
||||
_hasActivePrompt: boolean,
|
||||
_otherSurveyOpen: boolean,
|
||||
): { state: 'closed' | 'open'; handleTranscriptSelect: () => void } {
|
||||
return { state: 'closed', handleTranscriptSelect: () => {} };
|
||||
import { useState } from 'react'
|
||||
import type { Message } from '../../types/message.js'
|
||||
import { getGlobalConfig, saveGlobalConfig } from '../../utils/config.js'
|
||||
import { isPolicyAllowed } from '../../services/policyLimits/index.js'
|
||||
import { submitTranscriptShare } from './submitTranscriptShare.js'
|
||||
|
||||
type FrustrationState = 'closed' | 'transcript_prompt' | 'submitted'
|
||||
|
||||
export type FrustrationDetectionResult = {
|
||||
state: FrustrationState
|
||||
handleTranscriptSelect: (choice: string) => void
|
||||
}
|
||||
|
||||
function detectFrustration(messages: Message[]): boolean {
|
||||
const apiErrors = messages.filter(m => (m as any).isApiErrorMessage)
|
||||
return apiErrors.length >= 2
|
||||
}
|
||||
|
||||
export function useFrustrationDetection(
|
||||
messages: Message[],
|
||||
isLoading: boolean,
|
||||
hasActivePrompt: boolean,
|
||||
otherSurveyOpen: boolean,
|
||||
): FrustrationDetectionResult {
|
||||
const [state, setState] = useState<FrustrationState>('closed')
|
||||
|
||||
const config = getGlobalConfig() as { transcriptShareDismissed?: boolean }
|
||||
if (config.transcriptShareDismissed) {
|
||||
return { state: 'closed', handleTranscriptSelect: () => {} }
|
||||
}
|
||||
|
||||
if (!isPolicyAllowed('product_feedback' as any)) {
|
||||
return { state: 'closed', handleTranscriptSelect: () => {} }
|
||||
}
|
||||
|
||||
if (isLoading || hasActivePrompt || otherSurveyOpen) {
|
||||
return { state: 'closed', handleTranscriptSelect: () => {} }
|
||||
}
|
||||
|
||||
const frustrated = detectFrustration(messages)
|
||||
|
||||
const effectiveState =
|
||||
frustrated && state === 'closed' ? 'transcript_prompt' : state
|
||||
|
||||
function handleTranscriptSelect(choice: string) {
|
||||
if (choice === 'yes') {
|
||||
void submitTranscriptShare(messages, 'frustration', crypto.randomUUID())
|
||||
setState('submitted')
|
||||
} else {
|
||||
saveGlobalConfig((current: any) => ({
|
||||
...current,
|
||||
transcriptShareDismissed: true,
|
||||
}))
|
||||
setState('closed')
|
||||
}
|
||||
}
|
||||
|
||||
return { state: effectiveState, handleTranscriptSelect }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user