fix(ai): handle sensitive stop_reason from Anthropic API (fixes #978)

This commit is contained in:
mom 2026-01-28 02:18:16 +00:00
parent 41d2c7ff38
commit ee7c0a7d18
2 changed files with 10 additions and 5 deletions

View file

@ -2,6 +2,10 @@
## [Unreleased] ## [Unreleased]
### Fixed
- Fixed Anthropic provider to handle `sensitive` stop_reason returned by API ([#978](https://github.com/badlogic/pi-mono/issues/978))
## [0.50.1] - 2026-01-26 ## [0.50.1] - 2026-01-26
### Fixed ### Fixed

View file

@ -672,7 +672,7 @@ function convertTools(tools: Tool[], isOAuthToken: boolean): Anthropic.Messages.
}); });
} }
function mapStopReason(reason: Anthropic.Messages.StopReason): StopReason { function mapStopReason(reason: Anthropic.Messages.StopReason | string): StopReason {
switch (reason) { switch (reason) {
case "end_turn": case "end_turn":
return "stop"; return "stop";
@ -686,9 +686,10 @@ function mapStopReason(reason: Anthropic.Messages.StopReason): StopReason {
return "stop"; return "stop";
case "stop_sequence": case "stop_sequence":
return "stop"; // We don't supply stop sequences, so this should never happen return "stop"; // We don't supply stop sequences, so this should never happen
default: { case "sensitive": // Content flagged by safety filters (not yet in SDK types)
const _exhaustive: never = reason; return "error";
throw new Error(`Unhandled stop reason: ${_exhaustive}`); default:
} // Handle unknown stop reasons gracefully (API may add new values)
throw new Error(`Unhandled stop reason: ${reason}`);
} }
} }