Skip to content

feat: accept chunks as arguments to chat stream helper #2470

Merged
srtaalej merged 19 commits intofeat-ai-apps-thinking-stepsfrom
ale-chunks-stream-helper
Jan 26, 2026
Merged

feat: accept chunks as arguments to chat stream helper #2470
srtaalej merged 19 commits intofeat-ai-apps-thinking-stepsfrom
ale-chunks-stream-helper

Conversation

@srtaalej
Copy link
Contributor

Summary

This PR enables chunks processing in the chat stream helper

    const streamer = new ChatStreamer(client, client.logger, {
      channel: CHANNEL_ID,
      thread_ts: threadTs,
      recipient_team_id: 'TEAM_ID,
      recipient_user_id: 'USER_ID',
    }, { buffer_size: 1 });

    await streamer.append({
      chunks: [
        {
          type: 'markdown_text',
          text: '**Hello!** I am starting to process your request...\n\n'
        }]
    });

    await streamer.stop({
      chunks: [
        {
          type: 'markdown_text',
          text: '\n\n---\n\n✅ **All tasks completed successfully!**\n',
        },
        {
          type: 'markdown_text',
          text: 'Thank you for using the streaming API with chunks.',
        },
      ],
    });

Requirements (place an x in each [ ])

@codecov
Copy link

codecov bot commented Jan 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (feat-ai-apps-thinking-steps@e410413). Learn more about missing BASE report.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@                      Coverage Diff                       @@
##             feat-ai-apps-thinking-steps    #2470   +/-   ##
==============================================================
  Coverage                               ?   93.07%           
==============================================================
  Files                                  ?       40           
  Lines                                  ?    11213           
  Branches                               ?      708           
==============================================================
  Hits                                   ?    10437           
  Misses                                 ?      764           
  Partials                               ?       12           
Flag Coverage Δ
cli-hooks 95.23% <ø> (?)
cli-test 94.79% <ø> (?)
webhook 96.66% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@srtaalej srtaalej self-assigned this Jan 16, 2026
@srtaalej srtaalej marked this pull request as ready for review January 20, 2026 17:04
@srtaalej srtaalej requested a review from a team as a code owner January 20, 2026 17:04
@srtaalej srtaalej added the enhancement M-T: A feature request for new functionality label Jan 20, 2026
Copy link
Member

@mwbrooks mwbrooks left a comment

Choose a reason for hiding this comment

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

🙌🏻 Exciting, thanks for opening this PR @srtaalej!

It looks like you've also added the new task_update check along with the plan_update 😄

🧪 @zimeg and I will take a look at the PR soon. In the meantime, it looks like there are some failed tests that will need to be resolved.

@srtaalej srtaalej force-pushed the ale-chunks-stream-helper branch 2 times, most recently from e797040 to 5e86b29 Compare January 23, 2026 21:42
private async flushBuffer(
args: Omit<ChatStartStreamArguments | ChatAppendStreamArguments, 'channel' | 'ts'>,
): Promise<ChatStartStreamResponse | ChatAppendStreamResponse> {
const finalArgs = this.buffer.length > 0 && !args.chunks ? { ...args, markdown_text: this.buffer } : args;
Copy link
Member

Choose a reason for hiding this comment

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

👀 note: We might want to add existing buffer to a new chunk with just markdown text, if the buffer has anything, then add the chunks argument. This would help make sure we're not appending while text is in the buffer!

Copy link
Member

@mwbrooks mwbrooks left a comment

Choose a reason for hiding this comment

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

Thanks for updating this PR @srtaalej!

🧪 I noticed that the tests were failing when I linked the dev @slack/types package. Commit fc5ed1a fixes the tests and I've made a few notes around what changes were required.

I'll start to look into manual testing next! 👌🏻

if (this.buffer.length >= this.options.buffer_size) {
if (args?.markdown_text) {
this.buffer += args.markdown_text;
args.markdown_text = undefined;
Copy link
Member

Choose a reason for hiding this comment

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

note: I pushed commit fc5ed1a to unset the args.markdown_text after adding it to the buffer.

If this is not done, then the markdown_text will be added to the API request, which is also included in the chunks: [{ type: "markdown_text", "text": "...." }].

@zimeg Does this look correct to you? I noticed this wasn't explicitly done in the Python SDK.

Copy link
Member

Choose a reason for hiding this comment

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

@mwbrooks A change similar to other comments might be useful to destructure markdown_text and chunks from the rest of args before a chance to flush the buffer?

const { markdown_text, chunks, ...opts } = args;

IIRC the arguments alongside **kwargs in the Python implementation do this without added lines!

channel: this.streamArgs.channel,
ts: this.streamTs,
chunks: flushings,
...args,
Copy link
Member

Choose a reason for hiding this comment

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

note: I made commit fc5ed1a which added back ..args,. If we don't have this, then we may drop additional args like token. This also has the side effect of adding markdown_text as an arg, which is why we now must unset it. .cc @zimeg

Copy link
Member

Choose a reason for hiding this comment

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

@mwbrooks Thanks so much for catching this! We might want to consider a "destructured" approach to separate markdown_text and also chunks from the remaining options:

const { markdown_text, chunks, ...opts } = args;

This might help us avoid overriding new chunks with ...args as well, or chunks can be a following parameter?

.post('/api/chat.stopStream', {
channel: 'C0123456789',
ts: '123.123',
chunks: JSON.stringify([{ type: 'markdown_text', text: 'nice!' }]),
Copy link
Member

Choose a reason for hiding this comment

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

note: I made commit fc5ed1a which updates this test to support chunks instead of markdown_text because the streaming helper will now convert all markdown text into a chunk.

@zimeg zimeg added the pkg:web-api applies to `@slack/web-api` label Jan 24, 2026
Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

📝 A quick note on separating markdown_text and chunks from extra options since we might be adding from the buffer to chunks before making an API call!

👁️‍🗨️ Appreciate these catches different from python nuance @mwbrooks!

channel: this.streamArgs.channel,
ts: this.streamTs,
chunks: flushings,
...args,
Copy link
Member

Choose a reason for hiding this comment

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

@mwbrooks Thanks so much for catching this! We might want to consider a "destructured" approach to separate markdown_text and also chunks from the remaining options:

const { markdown_text, chunks, ...opts } = args;

This might help us avoid overriding new chunks with ...args as well, or chunks can be a following parameter?

if (this.buffer.length >= this.options.buffer_size) {
if (args?.markdown_text) {
this.buffer += args.markdown_text;
args.markdown_text = undefined;
Copy link
Member

Choose a reason for hiding this comment

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

@mwbrooks A change similar to other comments might be useful to destructure markdown_text and chunks from the rest of args before a chance to flush the buffer?

const { markdown_text, chunks, ...opts } = args;

IIRC the arguments alongside **kwargs in the Python implementation do this without added lines!

Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

@srtaalej LGTM! Thanks for bringing chunks to the streamer! I left a quibble on internals but testing works well for me 🤓

this.state = 'in_progress';
}

const flushings: AnyChunk[] = [];
Copy link
Member

Choose a reason for hiding this comment

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

🙊 quibble: This variable was changed alike to "chunks to flush" in updates to the Python SDK that we might mirror here? Also unrelated but empty lines might be nice to remove before merging-

Copy link
Member

@mwbrooks mwbrooks left a comment

Choose a reason for hiding this comment

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

🧪 Manually testing with a modified sample app works well for chunks as markdown_text, task_update, and plan_update. 🎉 👏🏻

@srtaalej srtaalej merged commit 8d237be into feat-ai-apps-thinking-steps Jan 26, 2026
72 of 111 checks passed
@srtaalej srtaalej deleted the ale-chunks-stream-helper branch January 26, 2026 21:54
zimeg added a commit that referenced this pull request Jan 29, 2026
Co-authored-by: Michael Brooks <mbrooks@slack-corp.com>
Co-authored-by: Eden Zimbelman <eden.zimbelman@salesforce.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement M-T: A feature request for new functionality pkg:web-api applies to `@slack/web-api` semver:minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants