@code-yeongyu/senpi-ai 2026.9.8 → 2026.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1618,11 +1618,19 @@ function buildParams(model, context, isOAuthToken, options, unsignedThinkingRepl
1618
1618
  disableThinkingForRequest(params, model, compat);
1619
1619
  }
1620
1620
  }
1621
- // Anthropic rejects a thinking-enabled request whose final assistant turn
1622
- // contains tool_use but does not begin with a thinking block. Cross-model
1623
- // histories lose their signed thinking blocks (demoted to text or dropped),
1624
- // so degrade thinking for this request instead of failing every turn.
1625
- if (params.thinking && params.thinking.type !== "disabled" && finalAssistantTurnStartsWithToolUse(params.messages))
1621
+ // A budget-thinking request whose final assistant turn came from another API
1622
+ // and starts with tool_use (its thinking demoted to text or dropped) is the
1623
+ // history shape Anthropic has rejected with "final assistant message must
1624
+ // start with a thinking block", so that request degrades thinking instead of
1625
+ // failing every turn. Nothing else degrades: adaptive families accept a
1626
+ // tool_use-first final turn (verified live 2026-09-09 on claude-opus-5,
1627
+ // claude-opus-4-6 and claude-fable-5), the model itself skips thinking before
1628
+ // trivial tool calls, and every change to `thinking` re-keys the prompt
1629
+ // cache - degrading here re-wrote the whole cached prefix on each tool
1630
+ // continuation (the "cache misses every second prompt" report).
1631
+ if (params.thinking?.type === "enabled" &&
1632
+ finalAssistantTurnIsForeign(context.messages) &&
1633
+ finalAssistantTurnStartsWithToolUse(params.messages))
1626
1634
  disableThinkingForRequest(params, model, compat);
1627
1635
  if (options?.metadata) {
1628
1636
  const userId = options.metadata.user_id;
@@ -1663,6 +1671,16 @@ function applyExtraBodyToAnthropicParams(params, extraBody) {
1663
1671
  * thinking/redacted_thinking block. Anthropic requires thinking-enabled
1664
1672
  * requests to start that turn with a thinking block.
1665
1673
  */
1674
+ /** True when the last assistant message was produced through a different wire API. */
1675
+ function finalAssistantTurnIsForeign(messages) {
1676
+ for (let index = messages.length - 1; index >= 0; index--) {
1677
+ const message = messages[index];
1678
+ if (message.role !== "assistant")
1679
+ continue;
1680
+ return message.api !== "anthropic-messages";
1681
+ }
1682
+ return false;
1683
+ }
1666
1684
  function finalAssistantTurnStartsWithToolUse(messages) {
1667
1685
  for (let index = messages.length - 1; index >= 0; index--) {
1668
1686
  const message = messages[index];