Repository navigation
Count text limits in UTF-16 units, as the API does - #11
Merged
Merged
Conversation
Names, frameworks and descriptions were cut and validated by Python characters, while the API and the Node.js and Go SDKs count UTF-16 code units. An agent name with emoji could pass the SDK's checks at 128 characters and then be rejected by the API, losing the payment record. Adds halvorai_ingest.text (utf16_len, cut) and uses it in validation and in the Stripe and x402 mappers. An empty shared_payment_token in metadata is now kept, as in the Node.js SDK. New parity cases are generated from the Node.js mapper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CpycUZtFJDZbpUr3cUnE6Y
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CpycUZtFJDZbpUr3cUnE6Y
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This fixes a bug found in a pre-release check of #10, before 0.5.0 was published.
The SDK counted text limits (agent name 128, framework 64, descriptions 256) in Python characters. The API and the Node.js and Go SDKs count UTF-16 code units, and most emoji take 2. So an agent name with emoji could pass the SDK's own validation and then be rejected by the API, which loses the payment record.
halvorai_ingest/text.pyaddsutf16_lenandcut.cutworks like JavaScript'sslice(0, n), except it drops a character rather than splitting a surrogate pair.validate.pynow checks allS16toS500limits in UTF-16 units.cut.shared_payment_tokenin metadata is now kept, the same as the Node.js??.Tests and verification
expected.jsonwere generated from the Node.jsmapStripeEventandtagIssuingCard: emoji names, frameworks and merchant names, plus an empty SPT. Python's output matches them exactly.tests/test_text.pycovers UTF-16 length, the cut, and validation at 64 emoji (passes) and at 65 emoji (rejected).pytest: 194 passed.mypy --strict: clean.Brain update
halvorai-ingestvalidation and the Stripe and x402 mappers. No public API changes.Generated by Claude Code