11import logging
2- from typing import Any , Dict , Optional , Sequence , Set , Union
2+ from typing import Dict , Optional , Sequence , Set , Union
33
4- from slack_sdk .errors import SlackObjectFormationError
54from slack_sdk .models import show_unknown_key_warning
65from slack_sdk .models .basic_objects import JsonObject
6+ from slack_sdk .models .blocks .block_elements import UrlSourceElement
77
88
99class Chunk (JsonObject ):
@@ -67,44 +67,6 @@ def __init__(
6767 self .text = text
6868
6969
70- class URLSource (JsonObject ):
71- type = "url"
72-
73- @property
74- def attributes (self ) -> Set [str ]:
75- return super ().attributes .union (
76- {
77- "url" ,
78- "text" ,
79- "icon_url" ,
80- }
81- )
82-
83- def __init__ (
84- self ,
85- * ,
86- url : str ,
87- text : str ,
88- icon_url : Optional [str ] = None ,
89- ** others : Dict ,
90- ):
91- show_unknown_key_warning (self , others )
92- self ._url = url
93- self ._text = text
94- self ._icon_url = icon_url
95-
96- def to_dict (self ) -> Dict [str , Any ]:
97- self .validate_json ()
98- json : Dict [str , Union [str , Dict ]] = {
99- "type" : self .type ,
100- "url" : self ._url ,
101- "text" : self ._text ,
102- }
103- if self ._icon_url :
104- json ["icon_url" ] = self ._icon_url
105- return json
106-
107-
10870class TaskUpdateChunk (Chunk ):
10971 type = "task_update"
11072
@@ -129,7 +91,7 @@ def __init__(
12991 status : str , # "pending", "in_progress", "complete", "error"
13092 details : Optional [str ] = None ,
13193 output : Optional [str ] = None ,
132- sources : Optional [Sequence [Union [Dict , URLSource ]]] = None ,
94+ sources : Optional [Sequence [Union [Dict , UrlSourceElement ]]] = None ,
13395 ** others : Dict ,
13496 ):
13597 """Used for displaying tool execution progress in a timeline-style UI.
@@ -144,12 +106,4 @@ def __init__(
144106 self .status = status
145107 self .details = details
146108 self .output = output
147- if sources is not None :
148- self .sources = []
149- for src in sources :
150- if isinstance (src , Dict ):
151- self .sources .append (src )
152- elif isinstance (src , URLSource ):
153- self .sources .append (src .to_dict ())
154- else :
155- raise SlackObjectFormationError (f"Unsupported type for source in task update chunk: { type (src )} " )
109+ self .sources = sources
0 commit comments