Skip to content

Conversation

@zknill
Copy link
Contributor

@zknill zknill commented Dec 11, 2025

Add doc explaining streaming tokens with appendMessage and update compaction allowing message-per-response history.

@coderabbitai
Copy link

coderabbitai bot commented Dec 11, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch zak/message-per-response

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.

@zknill zknill requested a review from mschristensen December 11, 2025 12:07
@zknill zknill force-pushed the zak/message-per-response branch from 9c6215e to bb19f32 Compare December 11, 2025 12:13
@GregHolmes GregHolmes added the review-app Create a Heroku review app label Dec 11, 2025
@ably-ci ably-ci temporarily deployed to ably-docs-zak-message-p-qhwg0d December 11, 2025 15:38 Inactive
@GregHolmes GregHolmes added review-app Create a Heroku review app and removed review-app Create a Heroku review app labels Dec 11, 2025
@ably-ci ably-ci temporarily deployed to ably-docs-zak-message-p-iolbqn December 11, 2025 15:45 Inactive
Copy link
Contributor

@GregHolmes GregHolmes left a comment

Choose a reason for hiding this comment

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

I've received from a docs perspective, just a couple comments. Happy to discuss if needed.

@ably-ci ably-ci temporarily deployed to ably-docs-zak-message-p-iolbqn December 11, 2025 17:40 Inactive
@zknill zknill force-pushed the zak/message-per-response branch from 65e1836 to 87dd2a2 Compare December 11, 2025 17:41
@ably-ci ably-ci temporarily deployed to ably-docs-zak-message-p-iolbqn December 11, 2025 17:41 Inactive
@GregHolmes GregHolmes force-pushed the AIT-129-AIT-Docs-release-branch branch from 8c010c8 to 5014fd3 Compare December 12, 2025 09:41
@GregHolmes GregHolmes self-requested a review December 12, 2025 09:45
Copy link
Contributor

@GregHolmes GregHolmes left a comment

Choose a reason for hiding this comment

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

Happy with this from a docs perspective.

@GregHolmes GregHolmes force-pushed the zak/message-per-response branch from 87dd2a2 to 0e4d434 Compare December 12, 2025 09:49
@GregHolmes GregHolmes temporarily deployed to ably-docs-zak-message-p-iolbqn December 12, 2025 09:49 Inactive
@GregHolmes GregHolmes force-pushed the AIT-129-AIT-Docs-release-branch branch 2 times, most recently from a863e09 to 2f792d4 Compare December 15, 2025 09:37

This pattern allows publishing append operations for multiple concurrent model responses on the same
channel. As long as you append to the correct message serial, tokens from different responses will
not interfere with each other. And the final concatenated message for each response will contain only the tokens
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
not interfere with each other. And the final concatenated message for each response will contain only the tokens
not interfere with each other, and the final concatenated message for each response will contain only the tokens


<Code>
```javascript
const realtime = new Ably.Realtime('YOUR_API_KEY');
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use {{API_KEY}} which will interpolate a value


## Requirements and restrictions

### Channel rule
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should appear earlier in the page, as the user has no indication that they need to configure the rule to use the code examples above until this point. Also the code examples should have a namespace prefix in the channel name


const { serials: [msgSerial] } = await channel.publish('ai-response', { data: '' });

for await (const token of streamedResponse) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should include a comment indicating what this example assumes is returned from the stream, like we do in https://github.com/ably/docs/pull/3014/changes#diff-b66bbc76507fb59b061f92037a82a9884804c3668f11a277fb5495b6a3819deb

Also nit, but we should use a consistent variable name for the stream, it is called stream elsewhere

not interfere with each other. And the final concatenated message for each response will contain only the tokens
from that response.

### Complete publish example
Copy link
Contributor

Choose a reason for hiding this comment

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

After this header we should have some preamble text describing what the example shows

case 'message.append':
console.log('Token received:', msg.data);
// Append the token to your UI
appendToResponse(msg.data);
Copy link
Contributor

Choose a reason for hiding this comment

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

I tried to avoid using this kind of pattern in the other docs: https://github.com/ably/docs/pull/3014/changes#diff-b66bbc76507fb59b061f92037a82a9884804c3668f11a277fb5495b6a3819deb

I'm not sure what the recommended approach is, but I'd rather include examples that are self contained and how some kind of simple handling of the results.

So I think in this case, it would make sense to have a Map with messages stored by serial, and we show how to add a value to the map on create (or replace it on update) and concatenate tokens to it on append. Then remove the imaginary displayNewResponse, appendToResponse and replaceResponse functions.

concatenated response.

Occasionally you may receive a `message.update` action, which indicates that the channel needs to
stream the entire message data so far. This can happen if a client has been offline for a while, and
Copy link
Contributor

Choose a reason for hiding this comment

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

This can happen if a client has been offline for a while

I think we should be more precise here, e.g.:

For example, this can happen if the client resumes after a transient disconnection and the channel ...

case 'message.create':
console.log('New response started:', msg.data);
// A new response has started
displayNewResponse(msg.data);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above

from the point of attachment backward:

<Code>
```javascript
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we align this code example with the one used in #3014 ? They shouldn't be too different and I think good to document a consistent approach

</Code>


### Using history with untilAttach
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a pattern for aligning with complete responses loaded from your database, like we do in #3014 ?

@GregHolmes GregHolmes force-pushed the zak/message-per-response branch from 0e4d434 to e1dd9a8 Compare December 15, 2025 14:07
@GregHolmes GregHolmes temporarily deployed to ably-docs-zak-message-p-iolbqn December 15, 2025 14:07 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-zak-message-p-iolbqn December 15, 2025 15:49 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-zak-message-p-iolbqn December 15, 2025 15:55 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-zak-message-p-iolbqn December 15, 2025 16:07 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-zak-message-p-iolbqn December 15, 2025 16:09 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-zak-message-p-iolbqn December 15, 2025 16:13 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-zak-message-p-iolbqn December 15, 2025 20:17 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-zak-message-p-iolbqn December 15, 2025 20:20 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-zak-message-p-iolbqn December 15, 2025 20:22 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-zak-message-p-iolbqn December 15, 2025 20:25 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-zak-message-p-iolbqn December 15, 2025 20:33 Inactive
@mschristensen mschristensen force-pushed the zak/message-per-response branch from a1a1183 to 7ef1e17 Compare December 16, 2025 23:02
@ably-ci ably-ci temporarily deployed to ably-docs-zak-message-p-iolbqn December 16, 2025 23:03 Inactive
zknill and others added 13 commits December 16, 2025 23:04
Add doc explaining streaming tokens with appendMessage and update
compaction allowing message-per-response history.
Unifies the token streaming nav for token streaming after rebase.
Refines the intro copy in message-per-response to have structural
similarity with the message-per-token page.
Refine the Publishing section of the message-per-response docs.

- Include anchor tags on title
- Describe the `serial` identifier
- Align with stream pattern used in message-per-token docs
- Remove duplicate example
Refine the Subscribing section of the message-per-response docs.

- Add anchor tag to heading
- Describes each action upfront
- Uses RANDOM_CHANNEL_NAME
Refine the rewind section of the message-per-response docs.

- Include description of allowed rewind paameters
- Tweak copy
Refines the history section for the message-per-response docs.

- Adds anchor to heading
- Uses RANDOM_CHANNEL_NAME
- Use message serial in code snippet instead of ID
- Tweaks copy
Fix the hydration of in progress responses via rewind by using the responseId in the extras to correlate messages with completed responses loaded from the database.
Fix the hydration of in progress responses using history by obtaining
the timestamp of the last completed response loaded from the database
and paginating history forwards from that point.
Removes the headers/metadata section, as this covers the specific
semantics of extras.headers handling with appends, which is better
addressed by the (upcoming) message append pub/sub docs. Instead, a
callout is used to describe header mixin semantics in the appropriate
place insofar as it relates to the discussion at hand.
Update the token streaming with message per token docs to include a
callout describing resume behaviour in case of transient disconnection.
Fix the message per token docs headers to include anchors and align with
naming in the message per response page.
@mschristensen mschristensen force-pushed the zak/message-per-response branch from 7ef1e17 to 5438a58 Compare December 16, 2025 23:07
@ably-ci ably-ci temporarily deployed to ably-docs-zak-message-p-iolbqn December 16, 2025 23:07 Inactive
@GregHolmes GregHolmes merged commit 400eb09 into AIT-129-AIT-Docs-release-branch Dec 17, 2025
7 checks passed
@GregHolmes GregHolmes deleted the zak/message-per-response branch December 17, 2025 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-app Create a Heroku review app

Development

Successfully merging this pull request may close these issues.

5 participants