( stopReason: BetaStopReason | null, model: string, )
| 1237 | } |
| 1238 | |
| 1239 | export function getErrorMessageIfRefusal( |
| 1240 | stopReason: BetaStopReason | null, |
| 1241 | model: string, |
| 1242 | ): AssistantMessage | undefined { |
| 1243 | if (stopReason !== 'refusal') { |
| 1244 | return |
| 1245 | } |
| 1246 | |
| 1247 | logEvent('ncode_refusal_api_response', {}) |
| 1248 | |
| 1249 | const baseMessage = getIsNonInteractiveSession() |
| 1250 | ? `${API_ERROR_MESSAGE_PREFIX}: Code is unable to respond to this request, which appears to violate our Usage Policy (https://www.anthropic.com/legal/aup). Try rephrasing the request or attempting a different approach.` |
| 1251 | : `${API_ERROR_MESSAGE_PREFIX}: Code is unable to respond to this request, which appears to violate our Usage Policy (https://www.anthropic.com/legal/aup). Please double press esc to edit your last message or start a new session for Code to assist with a different task.` |
| 1252 | |
| 1253 | const modelSuggestion = |
| 1254 | model !== 'claude-sonnet-4-20250514' |
| 1255 | ? ' If you are seeing this refusal repeatedly, try running /model claude-sonnet-4-20250514 to switch models.' |
| 1256 | : '' |
| 1257 | |
| 1258 | return createAssistantAPIErrorMessage({ |
| 1259 | content: baseMessage + modelSuggestion, |
| 1260 | error: 'invalid_request', |
| 1261 | }) |
| 1262 | } |
no test coverage detected