Skip to content

feat(upstream)!: read Bedrock's stream, and drop the provider layer - #144

Merged
fylorn merged 1 commit into
mainfrom
chore/drop-tw-provider
Sep 23, 2026
Merged

fylorn merged 1 commit into
mainfrom
chore/drop-tw-provider

Conversation

@fylorn

@fylorn fylorn commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

The server edition now forwards bytes and converts through tw-dialect (ThinkWatch refactor/dialect-passthrough), so tw-provider has no users left, and tw-protocol was only there for it. Both are deleted.

Going through what tw-provider did for Bedrock turned up two things nothing else does yet:

  • ConverseStream is AWS eventstream, not SSE. tw-dialect reads Bedrock frames as event: <:event-type> / data: <payload> and leaves the unframing to the transport. tw_upstream::eventstream::Transcoder is that step: binary frames in, SSE out. aws-smithy-eventstream checks the CRC, a frame cut on any byte is held until it is whole, and an in-stream exception (e.g. throttlingException) comes out as an error, not an event.
  • The usage sniffer did not know Converse's camelCase names, so every Bedrock call was billed on an estimate. It now reads inputTokens / outputTokens / cacheReadInputTokens / cacheWriteInputTokens, with inputTokens excluding cache, as tw_dialect::bedrock::usage already assumes.

The sigv4 feature is renamed to bedrock and covers both signing and unframing. Nothing in this workspace turns it on, so CI never compiled the SigV4 module. A new CI step runs clippy and the tests with it on.

Tests

  • tests/bedrock_stream.rs: a Converse stream as wire bytes, seven at a time, goes through the transcoder, the Chat converter and the sniffer. It checks the text (天气晴), finish_reason: stop and usage (60 / 40 cached / 20).
  • Transcoder unit tests: one frame becomes one SSE event, byte-by-byte feeding matches whole feeding, an exception is an error, and a corrupted CRC is refused.
  • A sniffer test covers Bedrock's whole body and its metadata event.

Breaking

  • tw-provider and tw-protocol are removed.
  • tw-upstream's sigv4 feature is now bedrock.

🤖 Generated with Claude Code

@fylorn
fylorn force-pushed the chore/drop-tw-provider branch from ac1f940 to 02b5097 Compare September 23, 2026 15:40
The server edition now forwards bytes and converts through tw-dialect,
so tw-provider has no users left, and tw-protocol was only there for it.
Both go.

Going through what tw-provider did for Bedrock turned up two things
nothing else does yet:

- ConverseStream is AWS eventstream, not SSE. tw-dialect reads Bedrock
  frames as `event: <:event-type>` / `data: <payload>` and leaves the
  unframing to the transport. `tw_upstream::eventstream::Transcoder`
  is that transport step: binary frames in, SSE out, CRC checked by
  aws-smithy-eventstream, a frame cut on any byte held until it is
  whole, an in-stream exception surfaced as an error.
- The usage sniffer did not know Converse's camelCase names, so every
  Bedrock call was billed on an estimate. It reads inputTokens,
  outputTokens, cacheReadInputTokens and cacheWriteInputTokens now,
  with inputTokens excluding cache as tw-dialect already assumes.

The `sigv4` feature becomes `bedrock`, covering both signing and
unframing. Nothing in this workspace turns it on, so CI never compiled
it; a step now runs clippy and the tests with it on.

A test takes a Converse stream as bytes on the wire, seven at a time,
through the transcoder, the Chat converter and the sniffer, and checks
the text, the finish reason and the usage that come out.

BREAKING: tw-provider and tw-protocol are gone; tw-upstream's `sigv4`
feature is now `bedrock`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fylorn
fylorn force-pushed the chore/drop-tw-provider branch from 02b5097 to ccca498 Compare September 23, 2026 16:19
@fylorn
fylorn merged commit 45ecfa7 into main Sep 23, 2026
2 checks passed
@fylorn
fylorn deleted the chore/drop-tw-provider branch September 23, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant