Skip to content

feat(core): stable LinkButton id (chat@4.31 171657a)#153

Merged
patrick-chinchill merged 1 commit into
mainfrom
feat/4.31-core-linkbutton-id
Jun 19, 2026
Merged

feat(core): stable LinkButton id (chat@4.31 171657a)#153
patrick-chinchill merged 1 commit into
mainfrom
feat/4.31-core-linkbutton-id

Conversation

@patrick-chinchill

Copy link
Copy Markdown
Collaborator

Summary

Ports the core half of upstream stable-id-for-link-buttons (chat@4.31.0, commit 171657a). 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.ts vs /tmp/vercel-chat-431/.../cards.ts. Part of the 4.31 Wave-A parity sync (#152).

Changes

File Change Upstream ref
src/chat_sdk/cards.py Optional id on LinkButtonElement TypedDict; keyword-only id_: str | None = None on the LinkButton() factory cards.ts:81-82, 399-400, 421
src/chat_sdk/types.py Sync Author.is_me field comment to upstream wording types.ts:1430
docs/UPSTREAM_SYNC.md Divergence row for the jsx-runtime id prop (non-port) jsx-runtime.ts:124, 651
tests/test_cards.py 4 Python-only regression tests

Faithful-port note (the load-bearing hazard)

Upstream sets id: options.id unconditionally (cards.ts:421) and relies on JSON.stringify dropping undefined. Python must NOT write a literal None/null, and must NOT use id_ or ... (that would also drop an explicit ""). So:

if id_ is not None:
    element["id"] = id_
  • Builtin-shadowing avoided: param is id_, emitted wire key stays the lowercase string "id".
  • The wire key id is already lowercase (no camel/snake split) — cross-SDK state stays compatible.
  • New optional outbound key → old persisted cards deserialize unchanged (no migration).

jsx-runtime portion — skipped (documented non-parity)

The same upstream commit also adds LinkButtonProps.id + resolveJSXElement forwarding in jsx-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 to docs/UPSTREAM_SYNC.md.

Regression tests (tests/test_cards.py::TestLinkButtonId)

cards.test.ts is byte-identical 4.30→4.31, so upstream ships no test for this — these are Python-only regressions:

  1. id_="open-docs" → element has {"id": "open-docs"}
  2. omitting id_no id key (emit/parse symmetry guard)
  3. id_="" → emits "" (explicit empty distinct from unset — guards against the or trap)
  4. id survives card wire-serialization (json.dumps/loads) unchanged

Verified 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 passed
  • ruff format --check: 259 files already formatted
  • audit_test_quality.py: Hard failures: 0 (39 pre-existing dup-name warnings)
  • pyrefly check: 0 errors
  • pytest tests/: 4837 passed, 4 skipped (4 skips pre-existing)

Not editing CHANGELOG.md — the 0.4.31 entry lands in the version-cut PR.

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.
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@patrick-chinchill, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5a6b87b9-eb72-49bd-bb33-419de7936aab

📥 Commits

Reviewing files that changed from the base of the PR and between 34314dd and 75b9f90.

📒 Files selected for processing (4)
  • docs/UPSTREAM_SYNC.md
  • src/chat_sdk/cards.py
  • src/chat_sdk/types.py
  • tests/test_cards.py

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@patrick-chinchill patrick-chinchill marked this pull request as ready for review June 19, 2026 22:57
@patrick-chinchill patrick-chinchill merged commit 36495eb into main Jun 19, 2026
9 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/chat_sdk/cards.py
"""
element: LinkButtonElement = {"type": "link-button", "url": url, "label": label}
if id_ is not None:
element["id"] = id_

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

patrick-chinchill added a commit that referenced this pull request Jun 19, 2026
…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).
patrick-chinchill added a commit that referenced this pull request Jun 19, 2026
…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).
@patrick-chinchill patrick-chinchill deleted the feat/4.31-core-linkbutton-id branch June 21, 2026 19:09
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