### Overview Major restructuring from monolithic `arcade-ai` package to modular library architecture with standardized uv-based dependency management.  ### New Package Structure - **`arcade-tdk`** - Lightweight toolkit development kit (core decorators, auth) - **`arcade-core`** - Core execution engine and catalog functionality - **`arcade-serve`** - FastAPI/MCP server components - **`arcade-ai`** - Meta package that includes CLI functionality. Optionally include evals via the `evals` extra. Optionally include all packages via the `all` extra. ### Key Benefits - **Lighter Dependencies**: Toolkits now depend only on `arcade-tdk` (~2 deps) vs full `arcade-ai` (~30+ deps) - **Faster Builds**: uv provides 10-100x faster dependency resolution and installation - **Better Modularity**: Clear separation of concerns, consumers import only what they need - **Standard Tooling**: Eliminates custom poetry scripts, uses standard Python packaging ### Migration Impact - All 20 toolkits converted from poetry → uv with `arcade-tdk` dependencies plus `arcade-ai[evals]` and `arcade-serve` dev dependencies. When developing locally, devs should install toolkits via `make install-local`. - Modern Python 3.10+ type hints throughout - Standardized build system with hatchling backend - Enhanced Makefile with robust toolkit management commands - Removed `arcade dev` CLI command - Reduce the number of files created by `arcade new` and add an option to not generate a tests and evals folder. This foundation enables faster development cycles and cleaner dependency chains for the growing toolkit ecosystem. ### Todo After this PR is merged - [ ] Post-merge workflow(s) (release & publish containers, etc) - [ ] Release order plan. @EricGustin suggests releasing in the following order: 1. `arcade-core` version 0.1.0 2. `arcade-serve` version 0.1.0 and `arcade-tdk` version 0.1.0 3. `arcade-ai` version 2.0.0 4. Patch release for all toolkits (all changes in toolkits are internal refactors) - [ ] [Update docs](https://github.com/ArcadeAI/docs/pull/318) --------- Co-authored-by: Eric Gustin <eric@arcade.dev> Co-authored-by: Eric Gustin <34000337+EricGustin@users.noreply.github.com>
116 lines
4.7 KiB
Python
116 lines
4.7 KiB
Python
from arcade_tdk import ToolContext
|
|
from msgraph.generated.models.message_collection_response import MessageCollectionResponse
|
|
from msgraph.generated.users.item.mail_folders.item.messages.messages_request_builder import (
|
|
MessagesRequestBuilder as MailFolderMessagesRequestBuilder,
|
|
)
|
|
from msgraph.generated.users.item.messages.item.reply.reply_post_request_body import (
|
|
ReplyPostRequestBody,
|
|
)
|
|
from msgraph.generated.users.item.messages.item.reply_all.reply_all_post_request_body import (
|
|
ReplyAllPostRequestBody,
|
|
)
|
|
from msgraph.generated.users.item.messages.messages_request_builder import (
|
|
MessagesRequestBuilder as UserMessagesRequestBuilder,
|
|
)
|
|
|
|
from arcade_microsoft.client import get_client
|
|
from arcade_microsoft.outlook_mail.constants import DEFAULT_MESSAGE_FIELDS
|
|
from arcade_microsoft.outlook_mail.enums import EmailFilterProperty, FilterOperator, ReplyType
|
|
|
|
|
|
def remove_none_values(data: dict) -> dict:
|
|
"""Remove all keys with None values from the dictionary."""
|
|
return {k: v for k, v in data.items() if v is not None}
|
|
|
|
|
|
def _create_filter_expression(
|
|
property_: EmailFilterProperty | None = None,
|
|
operator: FilterOperator | None = None,
|
|
value: str | None = None,
|
|
) -> str | None:
|
|
if property_ and operator and value:
|
|
property_value = property_.value
|
|
operator_value = operator.value
|
|
|
|
# Never use quotes around 'value' for booleans and numerics
|
|
value_quote = "'"
|
|
if value.lower() in ["true", "false"] or value.isdigit():
|
|
value_quote = ""
|
|
|
|
# Handle function operators (e.g., contains, startsWith, endsWith)
|
|
if operator.is_function():
|
|
filter_expr = f"{operator_value}({property_value}, {value_quote}{value}{value_quote})"
|
|
else:
|
|
# Handle comparison operators (e.g., eq, ne, gt, ge, lt, le)
|
|
filter_expr = f"{property_value} {operator_value} {value_quote}{value}{value_quote}"
|
|
|
|
if property_value == EmailFilterProperty.RECEIVED_DATE_TIME:
|
|
filter_expr = filter_expr
|
|
else: # Since receivedDateTime is in orderby, it must be in filter: https://learn.microsoft.com/en-us/graph/api/user-list-messages?view=graph-rest-1.0&tabs=http#optional-query-parameters
|
|
filter_expr = f"receivedDateTime ge 1900-01-01T00:00:00Z and {filter_expr}"
|
|
|
|
return filter_expr
|
|
|
|
return None
|
|
|
|
|
|
def prepare_list_emails_request_config(
|
|
limit: int,
|
|
property_: EmailFilterProperty | None = None,
|
|
operator: FilterOperator | None = None,
|
|
value: str | None = None,
|
|
) -> MailFolderMessagesRequestBuilder.MessagesRequestBuilderGetRequestConfiguration:
|
|
"""Prepare a request configuration for listing emails."""
|
|
limit = max(1, min(limit, 100)) # limit must be between 1 and 100
|
|
|
|
orderby = ["receivedDateTime DESC"]
|
|
filter_expr = _create_filter_expression(property_, operator, value)
|
|
|
|
query_params = MailFolderMessagesRequestBuilder.MessagesRequestBuilderGetQueryParameters(
|
|
count=True,
|
|
select=DEFAULT_MESSAGE_FIELDS,
|
|
orderby=orderby,
|
|
filter=filter_expr,
|
|
top=limit,
|
|
)
|
|
return MailFolderMessagesRequestBuilder.MessagesRequestBuilderGetRequestConfiguration(
|
|
query_parameters=query_params,
|
|
)
|
|
|
|
|
|
async def fetch_emails(
|
|
message_builder: MailFolderMessagesRequestBuilder | UserMessagesRequestBuilder,
|
|
pagination_token: str | None = None,
|
|
request_config: MailFolderMessagesRequestBuilder.MessagesRequestBuilderGetRequestConfiguration
|
|
| None = None,
|
|
) -> MessageCollectionResponse:
|
|
"""Fetch emails from the user's mailbox.
|
|
|
|
Microsoft Graph Python SDK does not support pagination (as of 2025-04-17),
|
|
so we use raw URL for pagination if a pagination token is provided.
|
|
"""
|
|
if pagination_token:
|
|
return await message_builder.with_url(pagination_token).get() # type: ignore[return-value]
|
|
return await message_builder.get(request_configuration=request_config) # type: ignore[return-value, arg-type]
|
|
|
|
|
|
async def send_reply_email(
|
|
context: ToolContext,
|
|
message_id: str,
|
|
body: str,
|
|
reply_type: ReplyType,
|
|
) -> dict:
|
|
"""Send a reply email to the sender or all recipients of an existing email."""
|
|
client = get_client(context.get_auth_token_or_empty())
|
|
|
|
if reply_type == ReplyType.REPLY:
|
|
reply_request_body = ReplyPostRequestBody(comment=body)
|
|
await client.me.messages.by_message_id(message_id).reply.post(reply_request_body)
|
|
elif reply_type == ReplyType.REPLY_ALL:
|
|
reply_all_request_body = ReplyAllPostRequestBody(comment=body)
|
|
await client.me.messages.by_message_id(message_id).reply_all.post(reply_all_request_body)
|
|
|
|
return {
|
|
"success": True,
|
|
"message": "Email sent successfully",
|
|
}
|