Accept Realtime client + channelName in sessions#89
Open
zknill wants to merge 3 commits into
Open
Conversation
This comment was marked as low quality.
This comment was marked as low quality.
Replace `channel: Ably.RealtimeChannel` on `createClientSession` and
`createAgentSession` (core + Vercel) with `{ client: Ably.Realtime,
channelName: string }`. The session resolves the channel itself via
`client.channels.get(channelName)` and registers an `ai-transport-js`
agent identifier on `client.options.agents` for SDK usage tracking,
mirroring the pattern used by ably-chat-js. The agent registration
is idempotent so multiple sessions sharing one client are safe.
This shifts boilerplate (`client.channels.get(...)`) out of every
caller and gives the backend a way to attribute usage to this SDK.
The caller still owns the client's lifecycle — `session.close()`
does not release the channel or close the client.
The React `ClientSessionProvider` drops Ably's `ChannelProvider` /
`useChannel` plumbing and now reads the client from the surrounding
`<AblyProvider>` via `useAbly()`. The Vercel `ChatTransportProvider`
inherits the simplification.
Spec points `AIT-ST1` and `AIT-CT1` are amended; new sub-points
`AIT-ST1a` / `AIT-CT1a` describe the agent registration and channel
ownership contract. The `/release` skill is updated to bump
`src/version.ts` alongside `package.json`.
Demos and the custom-codec example are updated to the new shape.
Tests use a new shared `createMockClient(channel)` helper.
fc3bc5b to
c021968
Compare
Contributor
Author
Contributor
|
It seems to me like there are two separate pieces of work here:
Whilst 1 seems necessary to enable 2, it also seems from the PR description like you believe that 1 is a valid standalone change ("shifts boilerplate"). Would this PR benefit from multiple commits in that case? |
Contributor
Sessions now also carry the `ai-transport-js` agent on the channel
ATTACH via `client.channels.get(name, { params: { agent } })`, in
addition to the existing `options.agents` mutation. The agents-map
path only attaches the identifier to the initial WebSocket connect;
when the supplied client is already CONNECTING/CONNECTED it gets
missed. Mirroring chat-js's two-path approach closes that gap.
`registerAgent` now returns the channel options the caller passes
to `channels.get`, so each session constructor configures the
client and resolves the channel in one go.
Public JSDoc on `AgentSessionOptions`, `ClientSessionOptions`, the
two factory functions, the React provider, and the React hooks
loses its leaked-implementation prose ("calls channels.get
internally", "registers the agent for usage tracking", "via
useAbly()"). It is replaced with an ownership contract: the caller
owns the client; the session owns the channel — don't resolve the
same channel name elsewhere with conflicting options. Three docs
files get the same sweep.
New tests in test/core/transport/{agent,client}-session.test.ts
assert that constructing a session both writes
options.agents['ai-transport-js'] and forwards
params.agent: 'ai-transport-js/<VERSION>' to channels.get, and
that pre-seeded unrelated agents survive across multiple sessions
sharing one client.
Contributor
Author
Probably, but if it's ok I will leave them in one. It would have been better to open as 2 commits, but now we are here 🤷 |
lawrence-forooghian
approved these changes
May 11, 2026
Contributor
lawrence-forooghian
left a comment
There was a problem hiding this comment.
Happy with the tracking changes but I'd appreciate eyes on the React changes from someone who knows React
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.
Replace
channel: Ably.RealtimeChanneloncreateClientSessionandcreateAgentSession(core + Vercel) with{ client: Ably.Realtime, channelName: string }. The session resolves the channel itself viaclient.channels.get(channelName)and registers anai-transport-jsagent identifier onclient.options.agentsfor SDK usage tracking, mirroring the pattern used by ably-chat-js. The agent registration is idempotent so multiple sessions sharing one client are safe.This shifts boilerplate (
client.channels.get(...)) out of every caller and gives the backend a way to attribute usage to this SDK. The caller still owns the client's lifecycle —session.close()does not release the channel or close the client.The React
ClientSessionProviderdrops Ably'sChannelProvider/useChannelplumbing and now reads the client from the surrounding<AblyProvider>viauseAbly(). The VercelChatTransportProviderinherits the simplification.Spec points
AIT-ST1andAIT-CT1are amended; new sub-pointsAIT-ST1a/AIT-CT1adescribe the agent registration and channel ownership contract. The/releaseskill is updated to bumpsrc/version.tsalongsidepackage.json.Demos and the custom-codec example are updated to the new shape. Tests use a new shared
createMockClient(channel)helper.