-
Notifications
You must be signed in to change notification settings - Fork 855
feat: add task_display_mode option to the start of chat streams #1820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zimeg
merged 12 commits into
feat-ai-apps-thinking-steps
from
zimeg-feat-ai-apps-task-display-mode
Jan 17, 2026
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c3bdb2d
feat: accept chunks as arguments to chat.{start,append,stop}Stream me…
zimeg 8c56e22
fix: remove unsupported and unused identifiers for full support
zimeg 783ada5
style: remove mypy extra ignore comment for overriden attributes
zimeg 1fb7355
test: confirm chunks parse as expected json values
zimeg 5de794b
feat: support and flush chunks in the chat stream helper
zimeg 61d6d53
test: dump chunks json before comparison for exact parsings
zimeg 85081e1
test: update async tests to expect chunks when flushing buffer
zimeg a6bb951
style: prefer using markdown text chunks in internal calls
zimeg 92c93e0
fix: support explicit json values as chunk objects
zimeg 7c32814
fix: mirror dictionary chunk option to async streamer
zimeg efb7ba2
feat: add task_display_mode option to the start of chat streams
zimeg 41b068d
chore: merge w base branch
zimeg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import logging | ||
| from typing import Any, Dict, Optional, Sequence, Set, Union | ||
|
|
||
| from slack_sdk.errors import SlackObjectFormationError | ||
| from slack_sdk.models import show_unknown_key_warning | ||
| from slack_sdk.models.basic_objects import JsonObject | ||
|
|
||
|
|
||
| class Chunk(JsonObject): | ||
| """ | ||
| Chunk for streaming messages. | ||
|
|
||
| https://docs.slack.dev/messaging/sending-and-scheduling-messages#text-streaming | ||
| """ | ||
|
|
||
| attributes = {"type"} | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| type: Optional[str] = None, | ||
| ): | ||
| self.type = type | ||
|
|
||
| @classmethod | ||
| def parse(cls, chunk: Union[Dict, "Chunk"]) -> Optional["Chunk"]: | ||
| if chunk is None: | ||
| return None | ||
| elif isinstance(chunk, Chunk): | ||
| return chunk | ||
| else: | ||
| if "type" in chunk: | ||
| type = chunk["type"] | ||
| if type == MarkdownTextChunk.type: | ||
| return MarkdownTextChunk(**chunk) | ||
| elif type == TaskUpdateChunk.type: | ||
| return TaskUpdateChunk(**chunk) | ||
| else: | ||
| cls.logger.warning(f"Unknown chunk detected and skipped ({chunk})") | ||
| return None | ||
| else: | ||
| cls.logger.warning(f"Unknown chunk detected and skipped ({chunk})") | ||
| return None | ||
|
|
||
|
|
||
| class MarkdownTextChunk(Chunk): | ||
| type = "markdown_text" | ||
|
|
||
| @property | ||
| def attributes(self) -> Set[str]: # type: ignore[override] | ||
| return super().attributes.union({"text"}) | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| text: str, | ||
| **others: Dict, | ||
| ): | ||
| """Used for streaming text content with markdown formatting support. | ||
|
|
||
| https://docs.slack.dev/messaging/sending-and-scheduling-messages#text-streaming | ||
| """ | ||
| super().__init__(type=self.type) | ||
| show_unknown_key_warning(self, others) | ||
|
|
||
| self.text = text | ||
|
|
||
|
|
||
| class URLSource(JsonObject): | ||
| type = "url" | ||
|
|
||
| @property | ||
| def attributes(self) -> Set[str]: | ||
| return super().attributes.union( | ||
| { | ||
| "url", | ||
| "text", | ||
| "icon_url", | ||
| } | ||
| ) | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| url: str, | ||
| text: str, | ||
| icon_url: Optional[str] = None, | ||
| **others: Dict, | ||
| ): | ||
| show_unknown_key_warning(self, others) | ||
| self._url = url | ||
| self._text = text | ||
| self._icon_url = icon_url | ||
|
|
||
| def to_dict(self) -> Dict[str, Any]: | ||
| self.validate_json() | ||
| json: Dict[str, Union[str, Dict]] = { | ||
| "type": self.type, | ||
| "url": self._url, | ||
| "text": self._text, | ||
| } | ||
| if self._icon_url: | ||
| json["icon_url"] = self._icon_url | ||
| return json | ||
|
|
||
|
|
||
| class TaskUpdateChunk(Chunk): | ||
| type = "task_update" | ||
|
|
||
| @property | ||
| def attributes(self) -> Set[str]: # type: ignore[override] | ||
| return super().attributes.union( | ||
| { | ||
| "id", | ||
| "title", | ||
| "status", | ||
| "details", | ||
| "output", | ||
| "sources", | ||
| } | ||
| ) | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| id: str, | ||
| title: str, | ||
| status: str, # "pending", "in_progress", "complete", "error" | ||
| details: Optional[str] = None, | ||
| output: Optional[str] = None, | ||
| sources: Optional[Sequence[Union[Dict, URLSource]]] = None, | ||
| **others: Dict, | ||
| ): | ||
| """Used for displaying tool execution progress in a timeline-style UI. | ||
|
|
||
| https://docs.slack.dev/messaging/sending-and-scheduling-messages#text-streaming | ||
| """ | ||
| super().__init__(type=self.type) | ||
| show_unknown_key_warning(self, others) | ||
|
|
||
| self.id = id | ||
| self.title = title | ||
| self.status = status | ||
| self.details = details | ||
| self.output = output | ||
| if sources is not None: | ||
| self.sources = [] | ||
| for src in sources: | ||
| if isinstance(src, Dict): | ||
| self.sources.append(src) | ||
| elif isinstance(src, URLSource): | ||
| self.sources.append(src.to_dict()) | ||
| else: | ||
| raise SlackObjectFormationError(f"Unsupported type for source in task update chunk: {type(src)}") |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(take it or leave it) we could potentially use enums here, but if it does not fall in line with existing patterns we shouldn't do it
Edit: actually maybe it would be worth having the web API return a proper error message with the possible options if an invalid value is passed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, I think it's good to expect the API return an error message with the the available options when an invalid option value is passed.
The display modes are aiming to support what's common in LLM UIs, so I imagine there will be more in the future that Slack will want to support. It would be nice for developers to have access to the new modes without upgrading the SDK version (I'm assuming an enum would require an SDK upgrade to support the new options?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WilliamBergamin @mwbrooks Oh dang, the tradeoffs are fascinating! 😳
I think I agree letting the API error for invalid values might be best for ongoing maintenance and I hope for now this comment is quick enough to jump to for fast reference. I'll update some notes to avoid using enums in adjacent changes too 📚
Prior art for me was found just above:
python-slack-sdk/slack_sdk/web/client.py
Line 2765 in efb7ba2