mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
lint
This commit is contained in:
1 parent
d2971fcdb9
commit
4ebca7f077
3 files changed
+134
-134
No files matched your search
@@ -6,75 +6,75 @@ import { ProjectPreviewConsoleError } from '@/lib/tools/ReadConsoleMessagesTool'
|
|||||||
|
|
||||||
// Mock all required hooks and components
|
// Mock all required hooks and components
|
||||||
vi.mock('@/hooks/useAISettings', () => ({
|
vi.mock('@/hooks/useAISettings', () => ({
|
||||||
useAISettings: () => ({
|
useAISettings: () => ({
|
||||||
settings: {
|
settings: {
|
||||||
providers: []
|
providers: []
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('@/hooks/useAICredits', () => ({
|
vi.mock('@/hooks/useAICredits', () => ({
|
||||||
useAICredits: () => ({
|
useAICredits: () => ({
|
||||||
data: null
|
data: null
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('react-router-dom', () => ({
|
vi.mock('react-router-dom', () => ({
|
||||||
useNavigate: () => vi.fn()
|
useNavigate: () => vi.fn()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Mock CreditsDialog to avoid NostrProvider dependency
|
// Mock CreditsDialog to avoid NostrProvider dependency
|
||||||
vi.mock('./CreditsDialog', () => ({
|
vi.mock('./CreditsDialog', () => ({
|
||||||
CreditsDialog: () => null
|
CreditsDialog: () => null
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('Quilly', () => {
|
describe('Quilly', () => {
|
||||||
const defaultProps = {
|
const defaultProps = {
|
||||||
error: new Error('Generic error'),
|
error: new Error('Generic error'),
|
||||||
onDismiss: vi.fn(),
|
onDismiss: vi.fn(),
|
||||||
onNewChat: vi.fn(),
|
onNewChat: vi.fn(),
|
||||||
onOpenModelSelector: vi.fn(),
|
onOpenModelSelector: vi.fn(),
|
||||||
providerModel: 'test/model'
|
providerModel: 'test/model'
|
||||||
};
|
};
|
||||||
|
|
||||||
it('renders generic error message', () => {
|
it('renders generic error message', () => {
|
||||||
render(<Quilly {...defaultProps} />);
|
render(<Quilly {...defaultProps} />);
|
||||||
|
|
||||||
expect(screen.getByText(/AI service error: Generic error/)).toBeInTheDocument();
|
expect(screen.getByText(/AI service error: Generic error/)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders correctly for malformed tool call errors', () => {
|
it('renders correctly for malformed tool call errors', () => {
|
||||||
const error = new MalformedToolCallError(
|
const error = new MalformedToolCallError(
|
||||||
'The AI provider sent an incomplete response.',
|
'The AI provider sent an incomplete response.',
|
||||||
'call_abc123',
|
'call_abc123',
|
||||||
'test/model'
|
'test/model'
|
||||||
);
|
);
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<Quilly
|
<Quilly
|
||||||
{...defaultProps}
|
{...defaultProps}
|
||||||
error={error}
|
error={error}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(screen.getByText(/The AI sent an incomplete response/)).toBeInTheDocument();
|
expect(screen.getByText(/The AI sent an incomplete response/)).toBeInTheDocument();
|
||||||
expect(screen.getByText(/Change model/)).toBeInTheDocument();
|
expect(screen.getByText(/Change model/)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders correctly for console errors', () => {
|
it('renders correctly for console errors', () => {
|
||||||
const error = new ProjectPreviewConsoleError(
|
const error = new ProjectPreviewConsoleError(
|
||||||
'Console error',
|
'Console error',
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<Quilly
|
<Quilly
|
||||||
{...defaultProps}
|
{...defaultProps}
|
||||||
error={error}
|
error={error}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(screen.getByText(/I noticed some console errors/)).toBeInTheDocument();
|
expect(screen.getByText(/I noticed some console errors/)).toBeInTheDocument();
|
||||||
expect(screen.getByText(/Help fix errors/)).toBeInTheDocument();
|
expect(screen.getByText(/Help fix errors/)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
+71
-71
@@ -56,92 +56,92 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (errorCode) {
|
switch (errorCode) {
|
||||||
// Application-specific error codes
|
// Application-specific error codes
|
||||||
case 'console_error':
|
case 'console_error':
|
||||||
return {
|
return {
|
||||||
message: 'I noticed some console errors in your project preview. Would you like me to take a look and help fix them?',
|
message: 'I noticed some console errors in your project preview. Would you like me to take a look and help fix them?',
|
||||||
action: {
|
action: {
|
||||||
label: 'Help fix errors',
|
label: 'Help fix errors',
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
onRequestConsoleErrorHelp?.(error as ProjectPreviewConsoleError);
|
onRequestConsoleErrorHelp?.(error as ProjectPreviewConsoleError);
|
||||||
onDismiss();
|
onDismiss();
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
|
};
|
||||||
|
|
||||||
case 'malformed_tool_call':
|
case 'malformed_tool_call':
|
||||||
return {
|
return {
|
||||||
message: 'The AI sent an incomplete response, possibly due to a network issue or provider problem. Try sending your message again, or switch to a different model if this persists.',
|
message: 'The AI sent an incomplete response, possibly due to a network issue or provider problem. Try sending your message again, or switch to a different model if this persists.',
|
||||||
action: {
|
action: {
|
||||||
label: 'Change model',
|
label: 'Change model',
|
||||||
onClick: onOpenModelSelector,
|
onClick: onOpenModelSelector,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// OpenAI API error codes
|
// OpenAI API error codes
|
||||||
case 'invalid_api_key':
|
case 'invalid_api_key':
|
||||||
case 'invalid_request_error':
|
case 'invalid_request_error':
|
||||||
|
return {
|
||||||
|
message: 'Authentication error: Please check your API key in AI settings.',
|
||||||
|
action: {
|
||||||
|
label: 'Check API key',
|
||||||
|
onClick: () => navigate('/settings/ai'),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
case 'insufficient_quota': {
|
||||||
|
if (credits.data) {
|
||||||
return {
|
return {
|
||||||
message: 'Authentication error: Please check your API key in AI settings.',
|
message: `Your account has $${credits.data.amount.toFixed(2)} credits. Please add credits to keep creating.`,
|
||||||
action: {
|
action: {
|
||||||
label: 'Check API key',
|
label: 'Add credits',
|
||||||
|
onClick: () => setShowCreditsDialog(true),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
message: 'Your API key has reached its usage limit. Please check your billing or try a different provider.',
|
||||||
|
action: {
|
||||||
|
label: 'Check AI settings',
|
||||||
onClick: () => navigate('/settings/ai'),
|
onClick: () => navigate('/settings/ai'),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
case 'insufficient_quota': {
|
|
||||||
if (credits.data) {
|
|
||||||
return {
|
|
||||||
message: `Your account has $${credits.data.amount.toFixed(2)} credits. Please add credits to keep creating.`,
|
|
||||||
action: {
|
|
||||||
label: 'Add credits',
|
|
||||||
onClick: () => setShowCreditsDialog(true),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
message: 'Your API key has reached its usage limit. Please check your billing or try a different provider.',
|
|
||||||
action: {
|
|
||||||
label: 'Check AI settings',
|
|
||||||
onClick: () => navigate('/settings/ai'),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case 'rate_limit_exceeded':
|
case 'rate_limit_exceeded':
|
||||||
return {
|
return {
|
||||||
message: 'Rate limit exceeded. Please wait a moment before trying again.',
|
message: 'Rate limit exceeded. Please wait a moment before trying again.',
|
||||||
};
|
};
|
||||||
|
|
||||||
case 'model_not_found':
|
case 'model_not_found':
|
||||||
return {
|
return {
|
||||||
message: 'The selected AI model is not available. Please choose a different model.',
|
message: 'The selected AI model is not available. Please choose a different model.',
|
||||||
action: {
|
action: {
|
||||||
label: 'Choose model',
|
label: 'Choose model',
|
||||||
onClick: onOpenModelSelector,
|
onClick: onOpenModelSelector,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
case 'context_length_exceeded':
|
case 'context_length_exceeded':
|
||||||
return {
|
return {
|
||||||
message: 'Your conversation is too long for this model. Try starting a new chat or switching to a model with a larger context window.',
|
message: 'Your conversation is too long for this model. Try starting a new chat or switching to a model with a larger context window.',
|
||||||
action: {
|
action: {
|
||||||
label: 'New chat',
|
label: 'New chat',
|
||||||
onClick: onNewChat,
|
onClick: onNewChat,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
case 'server_error':
|
case 'server_error':
|
||||||
case 'service_unavailable':
|
case 'service_unavailable':
|
||||||
return {
|
return {
|
||||||
message: 'The AI service is temporarily unavailable. Please try again in a moment.',
|
message: 'The AI service is temporarily unavailable. Please try again in a moment.',
|
||||||
};
|
};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return {
|
return {
|
||||||
message: `AI service error: ${error.message}`,
|
message: `AI service error: ${error.message}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,20 +3,20 @@
|
|||||||
* (e.g., missing function name in the streaming response)
|
* (e.g., missing function name in the streaming response)
|
||||||
*/
|
*/
|
||||||
export class MalformedToolCallError extends Error {
|
export class MalformedToolCallError extends Error {
|
||||||
public readonly code = 'malformed_tool_call' as const;
|
public readonly code = 'malformed_tool_call' as const;
|
||||||
public readonly toolCallId: string;
|
public readonly toolCallId: string;
|
||||||
public readonly providerModel: string;
|
public readonly providerModel: string;
|
||||||
|
|
||||||
constructor(message: string, toolCallId: string, providerModel: string) {
|
constructor(message: string, toolCallId: string, providerModel: string) {
|
||||||
super(message);
|
super(message);
|
||||||
this.name = 'MalformedToolCallError';
|
this.name = 'MalformedToolCallError';
|
||||||
this.toolCallId = toolCallId;
|
this.toolCallId = toolCallId;
|
||||||
this.providerModel = providerModel;
|
this.providerModel = providerModel;
|
||||||
|
|
||||||
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
||||||
if (Error.captureStackTrace) {
|
if (Error.captureStackTrace) {
|
||||||
Error.captureStackTrace(this, MalformedToolCallError);
|
Error.captureStackTrace(this, MalformedToolCallError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user