Commit decb08b
fix(anthropic): normalize the messages baseUrl and harden stream quirks (#765)
Four defects an Anthropic-compatible relay exposes, all in the same
adapter.
A `baseUrl` pasted as `https://host/v1/messages` -- which is what the
provider's own docs show -- got `/v1/messages` appended again. The URL is
now normalized so both the bare-origin and full-endpoint forms resolve to
one request path.
`input_json_delta` was accepted regardless of the open block, so a relay
emitting JSON deltas outside a `tool_use` block corrupted the assembled
arguments; the delta is now scoped to `tool_use`. A `tool_use` block
arriving without an `id` was forwarded with an empty one, which downstream
treats as unpaired -- a `toolu_` id is synthesized instead. And a stream
that reached EOF carrying a `message_delta.stop_reason` but no
`message_stop` now settles from that stop reason rather than hanging.
Two changes on top of the contributed patch:
`toolUseArguments` re-encoded an unparseable string input as a JSON
*string*, so `"not json at all"` arrived where the tool contract requires
an object. That is the double-encoding half of #765 and it survived the
original fix. It degrades to `{}` now, which still fails -- but inside the
tool's own argument validation instead of as a type error. A test pins it.
`sawContent` was assigned in six places and read in none; removed.
The contributed branch also swapped three `/api/logs` test files onto a
`logsFromApiBody` helper that accepts both the bare array and a `{logs}`
envelope. That helper is not brought across: it would pre-accept the
response-shape change this round has not decided on, and a matcher that
tolerates both shapes cannot fail when the shape regresses. Only the
adapter and its own test come over.
#765 stays open -- it asks for broader relay quirk tolerance than these
four fixes.
Note for whoever runs the suite: `tests/claude-messages-endpoint.test.ts`
and `tests/claude-native-passthrough.test.ts` already fail together on an
unmodified tree ("unmapped claude model + sk-ant credential passes through
verbatim"), and pass individually. That interference predates this commit.
Co-authored-by: bitkyc08-arch <bitkyc08@gmail.com>1 parent ba77eb8 commit decb08b
2 files changed
Lines changed: 148 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
253 | 287 | | |
254 | 288 | | |
255 | 289 | | |
| |||
680 | 714 | | |
681 | 715 | | |
682 | 716 | | |
683 | | - | |
684 | | - | |
| 717 | + | |
685 | 718 | | |
686 | 719 | | |
687 | 720 | | |
| |||
773 | 806 | | |
774 | 807 | | |
775 | 808 | | |
776 | | - | |
| 809 | + | |
777 | 810 | | |
778 | 811 | | |
779 | 812 | | |
| |||
799 | 832 | | |
800 | 833 | | |
801 | 834 | | |
802 | | - | |
| 835 | + | |
803 | 836 | | |
804 | 837 | | |
805 | 838 | | |
| |||
831 | 864 | | |
832 | 865 | | |
833 | 866 | | |
| 867 | + | |
834 | 868 | | |
835 | 869 | | |
836 | 870 | | |
837 | 871 | | |
838 | 872 | | |
839 | | - | |
| 873 | + | |
840 | 874 | | |
841 | 875 | | |
842 | 876 | | |
| |||
867 | 901 | | |
868 | 902 | | |
869 | 903 | | |
870 | | - | |
871 | | - | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
872 | 907 | | |
873 | 908 | | |
874 | 909 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
0 commit comments