mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-22 02:03:42 +00:00
Fix thinking tag leakage by converting unsigned blocks to plain text
Closes #302
This commit is contained in:
parent
2b22c3ce75
commit
29379ea0a6
2 changed files with 9 additions and 2 deletions
|
|
@ -1,5 +1,11 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- **Thinking tag leakage**: Fixed Claude mimicking literal `</thinking>` tags in responses. Unsigned thinking blocks (from aborted streams) are now converted to plain text without `<thinking>` tags. The TUI still displays them as thinking blocks. ([#302](https://github.com/badlogic/pi-mono/pull/302) by [@nicobailon](https://github.com/nicobailon))
|
||||||
|
|
||||||
## [0.25.1] - 2025-12-21
|
## [0.25.1] - 2025-12-21
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -463,11 +463,12 @@ function convertMessages(messages: Message[], model: Model<"anthropic-messages">
|
||||||
} else if (block.type === "thinking") {
|
} else if (block.type === "thinking") {
|
||||||
if (block.thinking.trim().length === 0) continue;
|
if (block.thinking.trim().length === 0) continue;
|
||||||
// If thinking signature is missing/empty (e.g., from aborted stream),
|
// If thinking signature is missing/empty (e.g., from aborted stream),
|
||||||
// convert to text block to avoid API rejection
|
// convert to plain text block without <thinking> tags to avoid API rejection
|
||||||
|
// and prevent Claude from mimicking the tags in responses
|
||||||
if (!block.thinkingSignature || block.thinkingSignature.trim().length === 0) {
|
if (!block.thinkingSignature || block.thinkingSignature.trim().length === 0) {
|
||||||
blocks.push({
|
blocks.push({
|
||||||
type: "text",
|
type: "text",
|
||||||
text: sanitizeSurrogates(`<thinking>\n${block.thinking}\n</thinking>`),
|
text: sanitizeSurrogates(block.thinking),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
blocks.push({
|
blocks.push({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue