arcade-slack 0.1.5__py3-none-any.whl → 0.4.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ import os
2
+
3
+ from arcade_slack.custom_types import PositiveInt
4
+
5
+ MAX_PAGINATION_SIZE_LIMIT = 200
6
+
7
+ MAX_PAGINATION_TIMEOUT_SECONDS = PositiveInt(
8
+ os.environ.get(
9
+ "MAX_PAGINATION_TIMEOUT_SECONDS",
10
+ os.environ.get("MAX_SLACK_PAGINATION_TIMEOUT_SECONDS", 30),
11
+ ),
12
+ name="MAX_PAGINATION_TIMEOUT_SECONDS or MAX_SLACK_PAGINATION_TIMEOUT_SECONDS",
13
+ )
@@ -0,0 +1,34 @@
1
+ from typing import Any
2
+
3
+ from arcade_evals import BinaryCritic
4
+
5
+
6
+ class RelativeTimeBinaryCritic(BinaryCritic):
7
+ def evaluate(self, expected: Any, actual: Any) -> dict[str, float | bool]:
8
+ """
9
+ Evaluates whether the expected and actual relative time strings are equivalent after
10
+ casting.
11
+
12
+ Args:
13
+ expected: The expected value.
14
+ actual: The actual value to compare, cast to the type of expected.
15
+
16
+ Returns:
17
+ dict: A dictionary containing the match status and score.
18
+ """
19
+ try:
20
+ actual_casted = self.cast_actual(expected, actual)
21
+ except TypeError:
22
+ actual_casted = actual
23
+
24
+ expected_parts = tuple(map(int, expected.split(":")))
25
+ actual_parts = tuple(map(int, actual_casted.split(":")))
26
+
27
+ if len(expected_parts) != 3 or len(actual_parts) != 3:
28
+ return {"match": False, "score": 0.0}
29
+
30
+ exp_days, exp_hours, exp_minutes = expected_parts
31
+ act_days, act_hours, act_minutes = actual_parts
32
+
33
+ match = exp_days == act_days and exp_hours == act_hours and exp_minutes == act_minutes
34
+ return {"match": match, "score": self.weight if match else 0.0}
@@ -0,0 +1,26 @@
1
+ from typing import NewType
2
+
3
+
4
+ class PositiveInt(int):
5
+ def __new__(cls, value: str | int, name: str = "value") -> "PositiveInt":
6
+ def validate(val: int) -> int:
7
+ if val <= 0:
8
+ raise ValueError(f"{name} must be positive, got {val}")
9
+ return val
10
+
11
+ try:
12
+ value = int(value)
13
+ except ValueError:
14
+ raise ValueError(f"{name} must be a valid integer, got {value!r}")
15
+
16
+ validated_value = validate(value)
17
+ instance = super().__new__(cls, validated_value)
18
+ return instance
19
+
20
+
21
+ SlackOffsetSecondsFromUTC = NewType("SlackOffsetSecondsFromUTC", int) # observe it can be negative
22
+ SlackPaginationNextCursor = str | None
23
+ SlackUserFieldId = NewType("SlackUserFieldId", str)
24
+ SlackUserId = NewType("SlackUserId", str)
25
+ SlackTeamId = NewType("SlackTeamId", str)
26
+ SlackTimestampStr = NewType("SlackTimestampStr", str)
@@ -0,0 +1,30 @@
1
+ class SlackToolkitError(Exception):
2
+ """Base class for all Slack toolkit errors."""
3
+
4
+
5
+ class PaginationTimeoutError(SlackToolkitError):
6
+ """Raised when a timeout occurs during pagination."""
7
+
8
+ def __init__(self, timeout_seconds: int):
9
+ self.timeout_seconds = timeout_seconds
10
+ super().__init__(f"The pagination process timed out after {timeout_seconds} seconds.")
11
+
12
+
13
+ class ItemNotFoundError(SlackToolkitError):
14
+ """Raised when an item is not found."""
15
+
16
+
17
+ class UsernameNotFoundError(SlackToolkitError):
18
+ """Raised when a user is not found by the username searched"""
19
+
20
+ def __init__(self, usernames_found: list[str], username_not_found: str) -> None:
21
+ self.usernames_found = usernames_found
22
+ self.username_not_found = username_not_found
23
+
24
+
25
+ class ConversationNotFoundError(SlackToolkitError):
26
+ """Raised when a conversation is not found"""
27
+
28
+
29
+ class DirectMessageConversationNotFoundError(ConversationNotFoundError):
30
+ """Raised when a direct message conversation searched is not found"""
arcade_slack/models.py ADDED
@@ -0,0 +1,206 @@
1
+ from enum import Enum
2
+ from typing import Literal, TypedDict
3
+
4
+ from arcade_slack.custom_types import (
5
+ SlackOffsetSecondsFromUTC,
6
+ SlackPaginationNextCursor,
7
+ SlackTeamId,
8
+ SlackTimestampStr,
9
+ SlackUserFieldId,
10
+ SlackUserId,
11
+ )
12
+
13
+
14
+ class ConversationTypeSlackName(str, Enum):
15
+ PUBLIC_CHANNEL = "public_channel" # Public channels are visible to all users in the workspace
16
+ PRIVATE_CHANNEL = "private_channel" # Private channels are visible to only specific users
17
+ MPIM = "mpim" # Multi-person direct message conversation
18
+ IM = "im" # Two person direct message conversation
19
+
20
+
21
+ class ConversationType(str, Enum):
22
+ PUBLIC_CHANNEL = "public_channel"
23
+ PRIVATE_CHANNEL = "private_channel"
24
+ MULTI_PERSON_DIRECT_MESSAGE = "multi_person_direct_message"
25
+ DIRECT_MESSAGE = "direct_message"
26
+
27
+
28
+ """
29
+ About Slack dictionaries: Slack does not guarantee the presence of all fields for a given
30
+ object. It will vary from endpoint to endpoint and even if the field is present, they say it may
31
+ contain a None value or an empty string instead of the actual expected value.
32
+
33
+ See, for example, the 'Common Fields' section of the user type definition at:
34
+ https://api.slack.com/types/user#fields (https://archive.is/RUZdL)
35
+
36
+ Because of that, our TypedDicts ended up having to be mostly total=False and most of the fields'
37
+ type hints are Optional. Use Slack dictionary fields with caution. It's advisable to validate the
38
+ value before using it and raise errors that are clear to understand, when appropriate.
39
+ """
40
+
41
+
42
+ class SlackUserFieldData(TypedDict, total=False):
43
+ """Type definition for Slack user field data dictionary.
44
+
45
+ Slack type definition: https://api.slack.com/methods/users.profile.set#custom-profile
46
+ """
47
+
48
+ value: str | None
49
+ alt: bool | None
50
+
51
+
52
+ class SlackStatusEmojiDisplayInfo(TypedDict, total=False):
53
+ """Type definition for Slack status emoji display info dictionary."""
54
+
55
+ emoji_name: str | None
56
+ display_url: str | None
57
+
58
+
59
+ class SlackUserProfile(TypedDict, total=False):
60
+ """Type definition for Slack user profile dictionary.
61
+
62
+ Slack type definition: https://api.slack.com/types/user#profile (https://archive.is/RUZdL)
63
+ """
64
+
65
+ title: str | None
66
+ phone: str | None
67
+ skype: str | None
68
+ email: str | None
69
+ real_name: str | None
70
+ real_name_normalized: str | None
71
+ display_name: str | None
72
+ display_name_normalized: str | None
73
+ first_name: str | None
74
+ last_name: str | None
75
+ fields: list[dict[SlackUserFieldId, SlackUserFieldData]] | None
76
+ image_original: str | None
77
+ is_custom_image: bool | None
78
+ image_24: str | None
79
+ image_32: str | None
80
+ image_48: str | None
81
+ image_72: str | None
82
+ image_192: str | None
83
+ image_512: str | None
84
+ image_1024: str | None
85
+ status_emoji: str | None
86
+ status_emoji_display_info: list[SlackStatusEmojiDisplayInfo] | None
87
+ status_text: str | None
88
+ status_text_canonical: str | None
89
+ status_expiration: int | None
90
+ avatar_hash: str | None
91
+ start_date: str | None
92
+ pronouns: str | None
93
+ huddle_state: str | None
94
+ huddle_state_expiration: int | None
95
+ team: SlackTeamId | None
96
+
97
+
98
+ class SlackUser(TypedDict, total=False):
99
+ """Type definition for Slack user dictionary.
100
+
101
+ Slack type definition: https://api.slack.com/types/user (https://archive.is/RUZdL)
102
+ """
103
+
104
+ id: SlackUserId
105
+ team_id: SlackTeamId
106
+ name: str | None
107
+ deleted: bool | None
108
+ color: str | None
109
+ real_name: str | None
110
+ tz: str | None
111
+ tz_label: str | None
112
+ tz_offset: SlackOffsetSecondsFromUTC | None
113
+ profile: SlackUserProfile | None
114
+ is_admin: bool | None
115
+ is_owner: bool | None
116
+ is_primary_owner: bool | None
117
+ is_restricted: bool | None
118
+ is_ultra_restricted: bool | None
119
+ is_bot: bool | None
120
+ is_app_user: bool | None
121
+ is_email_confirmed: bool | None
122
+ who_can_share_contact_card: str | None
123
+
124
+
125
+ class SlackUserList(TypedDict, total=False):
126
+ """Type definition for the returned user list dictionary."""
127
+
128
+ members: list[SlackUser]
129
+
130
+
131
+ class SlackConversationPurpose(TypedDict, total=False):
132
+ """Type definition for the Slack conversation purpose dictionary."""
133
+
134
+ value: str | None
135
+
136
+
137
+ class SlackConversation(TypedDict, total=False):
138
+ """Type definition for the Slack conversation dictionary."""
139
+
140
+ id: str | None
141
+ name: str | None
142
+ is_private: bool | None
143
+ is_archived: bool | None
144
+ is_member: bool | None
145
+ is_channel: bool | None
146
+ is_group: bool | None
147
+ is_im: bool | None
148
+ is_mpim: bool | None
149
+ purpose: SlackConversationPurpose | None
150
+ num_members: int | None
151
+ user: SlackUser | None
152
+ is_user_deleted: bool | None
153
+
154
+
155
+ class SlackMessage(TypedDict, total=True):
156
+ """Type definition for the Slack message dictionary."""
157
+
158
+ type: Literal["message"]
159
+ user: SlackUser
160
+ text: str
161
+ ts: SlackTimestampStr # Slack timestamp as a string (e.g. "1234567890.123456")
162
+
163
+
164
+ class Message(SlackMessage, total=False):
165
+ """Type definition for the message dictionary.
166
+
167
+ Having a human-readable datetime string is useful for LLMs when they need to display the
168
+ date/time for the user. If not, they'll try to convert the unix timestamp to a human-readable
169
+ date/time,which they don't usually do accurately.
170
+ """
171
+
172
+ datetime_timestamp: str # Human-readable datetime string (e.g. "2025-01-22 12:00:00")
173
+
174
+
175
+ class ConversationMetadata(TypedDict, total=False):
176
+ """Type definition for the conversation metadata dictionary."""
177
+
178
+ id: str | None
179
+ name: str | None
180
+ conversation_type: str | None
181
+ is_private: bool | None
182
+ is_archived: bool | None
183
+ is_member: bool | None
184
+ purpose: str | None
185
+ num_members: int | None
186
+ user: SlackUser | None
187
+ is_user_deleted: bool | None
188
+
189
+
190
+ class BasicUserInfo(TypedDict, total=False):
191
+ """Type definition for the returned basic user info dictionary."""
192
+
193
+ id: str | None
194
+ name: str | None
195
+ is_bot: bool | None
196
+ email: str | None
197
+ display_name: str | None
198
+ real_name: str | None
199
+ timezone: str | None
200
+
201
+
202
+ class SlackConversationsToolResponse(TypedDict, total=True):
203
+ """Type definition for the Slack conversations tool response dictionary."""
204
+
205
+ conversations: list[ConversationMetadata]
206
+ next_cursor: SlackPaginationNextCursor | None