feat(core): stable LinkButton id (chat@4.31 171657a)#153
Conversation
Port the core half of upstream stable-id-for-link-buttons (chat@4.31.0,
commit 171657a). Adds an optional stable identifier to link buttons that
platforms reporting link clicks can emit back.
- cards.py: add optional `id` to the `LinkButtonElement` TypedDict and a
keyword-only `id_: str | None = None` param to the `LinkButton()`
factory. Upstream sets `id: options.id` unconditionally and relies on
JSON.stringify dropping `undefined`; Python writes the `id` key ONLY
when `id_ is not None` so an unset id never serializes as a literal
null (and an explicit empty string is preserved — no `id_ or ...`).
The wire key stays the lowercase string `id` (builtin-shadowing avoided
by naming the param `id_`); this is a new optional outbound key, so old
persisted cards deserialize unchanged (no migration).
- types.py: sync the `Author.is_me` field comment to upstream wording
("Whether this message was sent by this bot/runtime").
- jsx-runtime half (`LinkButtonProps.id` / `resolveJSXElement`) is a
documented non-port — Python has no JSX runtime; noted in
docs/UPSTREAM_SYNC.md.
Tests (cards.test.ts is byte-identical 4.30->4.31, so these are
Python-only regressions): id written when provided; NO id key when
omitted (emit/parse symmetry); empty string emitted (explicit empty
distinct from unset); id survives wire serialization.
|
Warning Review limit reached
More reviews will be available in 1 hour. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request ports the optional stable id field for LinkButton elements from upstream (chat@4.31.0). It updates the LinkButtonElement TypedDict and the LinkButton factory function to accept and serialize the optional id_ parameter, and adds corresponding unit tests to verify correct serialization behavior. Additionally, it documents this port in UPSTREAM_SYNC.md and adds a minor comment to src/chat_sdk/types.py. I have no feedback to provide as there are no review comments.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 75b9f9091c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| """ | ||
| element: LinkButtonElement = {"type": "link-button", "url": url, "label": label} | ||
| if id_ is not None: | ||
| element["id"] = id_ |
There was a problem hiding this comment.
Propagate LinkButton ids to Slack action_id
When a Slack card uses LinkButton(..., id_="open-docs"), this stores the id on the card element, but the Slack renderers still ignore it: src/chat_sdk/adapters/slack/cards.py builds action_id as link-{url[:200]} and src/chat_sdk/adapters/slack/blocks/__init__.py does the same from the URL. Slack block-action inbound then copies that action_id into ActionEvent, and Chat.on_action("open-docs", ...) matches against event.action_id, so the stable id added here is never emitted back for Slack link clicks.
Useful? React with 👍 / 👎.
…ching Button/Select The Wave-A Slack PR's rebase onto #153 surfaced an API inconsistency: #153 landed LinkButton's optional stable-id param as `id_`, but Button/Select/RadioSelect all use `id`. Align LinkButton to the `id` convention — it's keyword-only with no real builtin-shadow issue (Button already does this; ruff's lint config does not select flake8-builtins), and 0.4.31 is unreleased so nothing depends on `id_` yet. Also drops this branch's duplicate jsx-runtime non-parity row (keeps #153's canonical one) and its redundant core LinkButton tests (keeps #153's TestLinkButtonId).
…ton action_id (chat@4.31) (#155) * feat(slack): stable link-button action_id from core id (chat@4.31, 171657a) Consume the new core LinkButtonElement.id as the Slack link-button action_id, with ?? semantics: an explicit (even empty-string) id is used verbatim; only a missing/None id falls back to link-{url}. - core cards.py: LinkButton() factory + LinkButtonElement gain optional id - adapters/slack/cards.py (_convert_link_button_to_element): id ?? link-{url[:200]} - adapters/slack/blocks/__init__.py (_link_button_to_element): id ?? link-{url}, still truncated via _truncate_text(..., LIMITS.action_id) on the id path - adapters/slack/blocks/types.py: SlackLinkButtonElement gains id: NotRequired[str] Tests lock custom id verbatim at both sites, URL fallback at both, and id=='' -> action_id=='' (locks 'is not None', not 'or'). * feat(slack): forward web_client_options to both WebClients (chat@4.31, 8336a3e) SlackAdapterConfig gains web_client_options: dict[str, Any] | None, spread into BOTH client construction sites — the default AsyncWebClient (_get_client) and the per-token sync WebClient (_get_web_client_for_token). DIVERGENCE: maps to slack_sdk WebClient kwargs (timeout in seconds, retry_handlers), not @slack/web-api axios options — slack_sdk has no 1:1 retryConfig/rejectRateLimitedCalls. Documented in the config docstring and a docs/UPSTREAM_SYNC.md row (plus a jsx-runtime LinkButtonProps.id non-port row). Hazards: gate the spread on 'is not None' so an explicit {} still applies; deep-copy any nested headers dict per client (_web_client_kwargs) so cached per-token clients never share a mutable dict and caller input is never mutated. Tests: an option reaches the default client and a per-token client; header isolation across two tokens with no input mutation; empty {} still spreads. * fix(slack): don't rewrite @Handles inside URLs as mentions (chat@4.31, a8bf99a) A bare @handle inside a URL (path, query string, or fragment) must NOT be rewritten into a <@handle> Slack mention, which corrupts the link. This is a confirmed pre-existing converter bug; the new regression tests fail on pre-fix code. In adapters/slack/format_converter.py: - widen the mention lookbehind (?<![<\w]) -> (?<![<\w/]) (kept fixed-width, single char) so a schemeless host path (mastodon.social/@user) is preserved - add URL_REGEX (\bhttps?://[^\s<>]+) and _link_bare_mentions_outside_urls(), which only mention-links the slices outside URL spans - call it from BOTH substitution sites — _finalize (string surface) and the _node_to_mrkdwn text branch (mrkdwn surface); our port had split upstream's single finalize into two bare subs - apply re.ASCII so \w matches JS's ASCII \w exactly (Python \w is Unicode-aware) Tests mirror upstream markdown.test.ts plus an adversarial sweep: @handle in path/query/fragment, schemeless host, real mention after a URL, (cc @george), email + mailto preserved, URL at start/end, multiple URLs, already-wrapped mention not double-wrapped — on both the string and mrkdwn surfaces. * fix(cards): align LinkButton stable-id param to `id` (not `id_`), matching Button/Select The Wave-A Slack PR's rebase onto #153 surfaced an API inconsistency: #153 landed LinkButton's optional stable-id param as `id_`, but Button/Select/RadioSelect all use `id`. Align LinkButton to the `id` convention — it's keyword-only with no real builtin-shadow issue (Button already does this; ruff's lint config does not select flake8-builtins), and 0.4.31 is unreleased so nothing depends on `id_` yet. Also drops this branch's duplicate jsx-runtime non-parity row (keeps #153's canonical one) and its redundant core LinkButton tests (keeps #153's TestLinkButtonId).
Summary
Ports the core half of upstream
stable-id-for-link-buttons(chat@4.31.0, commit171657a). Link buttons can now carry an optional stable identifier that platforms reporting link clicks emit back.Diffed
/tmp/vercel-chat-430/packages/chat/src/cards.tsvs/tmp/vercel-chat-431/.../cards.ts. Part of the 4.31 Wave-A parity sync (#152).Changes
src/chat_sdk/cards.pyidonLinkButtonElementTypedDict; keyword-onlyid_: str | None = Noneon theLinkButton()factorysrc/chat_sdk/types.pyAuthor.is_mefield comment to upstream wordingdocs/UPSTREAM_SYNC.mdidprop (non-port)tests/test_cards.pyFaithful-port note (the load-bearing hazard)
Upstream sets
id: options.idunconditionally (cards.ts:421) and relies onJSON.stringifydroppingundefined. Python must NOT write a literalNone/null, and must NOT useid_ or ...(that would also drop an explicit""). So:id_, emitted wire key stays the lowercase string"id".idis already lowercase (no camel/snake split) — cross-SDK state stays compatible.jsx-runtime portion — skipped (documented non-parity)
The same upstream commit also adds
LinkButtonProps.id+resolveJSXElementforwarding injsx-runtime.ts. We have no JSX runtime (existing documented non-parity), so that slice is intentionally not ported; a one-line divergence row was added todocs/UPSTREAM_SYNC.md.Regression tests (
tests/test_cards.py::TestLinkButtonId)cards.test.tsis byte-identical 4.30→4.31, so upstream ships no test for this — these are Python-only regressions:id_="open-docs"→ element has{"id": "open-docs"}id_→ noidkey (emit/parse symmetry guard)id_=""→ emits""(explicit empty distinct from unset — guards against theortrap)json.dumps/loads) unchangedVerified 3/4 fail on pre-port source (
TypeError: unexpected keyword argument 'id_'); test 2 (absence-of-key symmetry guard) correctly passes both before and after.Gauntlet (from
/tmp/w431-core)ruff check: All checks passedruff format --check: 259 files already formattedaudit_test_quality.py: Hard failures: 0 (39 pre-existing dup-name warnings)pyrefly check: 0 errorspytest tests/: 4837 passed, 4 skipped (4 skips pre-existing)Not editing
CHANGELOG.md— the 0.4.31 entry lands in the version-cut PR.