fix(translator): map Claude "refusal" stop_reason to content_filter and surface its explanation
Anthropic's API-level refusal (streaming classifier / ToS) ends the stream with stop_reason "refusal", stop_details carrying the reason, zero output tokens and no content blocks. Map refusal to content_filter in both directions, surface stop_details.explanation as message text, and add CLAUDE_STOP.REFUSAL to schema.
This commit is contained in:
@@ -149,6 +149,13 @@ export function claudeToOpenAIResponse(chunk, state) {
|
||||
|
||||
if (chunk.delta?.stop_reason) {
|
||||
state.finishReason = convertStopReason(chunk.delta.stop_reason);
|
||||
// A refusal produces no content blocks at all. Surface Anthropic's own
|
||||
// explanation as the message text so the client shows *why* the turn is
|
||||
// empty instead of a blank reply.
|
||||
const refusalNote = chunk.delta.stop_reason === "refusal" && chunk.delta.stop_details?.explanation;
|
||||
if (refusalNote) {
|
||||
results.push(createChunk(state, { content: refusalNote }));
|
||||
}
|
||||
const finalChunk = createChunk(state, {}, state.finishReason);
|
||||
|
||||
if (state.usage) {
|
||||
|
||||
Reference in New Issue
Block a user