-
Notifications
You must be signed in to change notification settings - Fork 4
add engine cloud service #35
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
Conversation
WalkthroughThe changes introduce a new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant EngineCloud
participant EngineCloudAPI
User->>EngineCloud: Initialize (secret_key, vault_access_token)
User->>EngineCloud: create_server_wallet(label)
EngineCloud->>EngineCloudAPI: POST /server-wallets {label}
EngineCloudAPI-->>EngineCloud: Response (wallet info)
EngineCloud-->>User: Wallet info
User->>EngineCloud: write_contract(from_address, chain_id, method, params, contract_address, abi, value)
EngineCloud->>EngineCloudAPI: POST /contract/write {params}
EngineCloudAPI-->>EngineCloud: Response (tx result)
EngineCloud-->>User: Tx result
User->>EngineCloud: send_transaction(from_address, chain_id, to_address, data, value)
EngineCloud->>EngineCloudAPI: POST /transaction/send {params}
EngineCloudAPI-->>EngineCloud: Response (tx result)
EngineCloud-->>User: Tx result
User->>EngineCloud: read_contract(multicall_address, chain_id, from_address, method, params, contract_address, abi)
EngineCloud->>EngineCloudAPI: POST /contract/read {params}
EngineCloudAPI-->>EngineCloud: Response (read result)
EngineCloud-->>User: Read result
User->>EngineCloud: get_native_balance(chain_id, address)
EngineCloud->>EngineCloudAPI: POST /balance/native {params}
EngineCloudAPI-->>EngineCloud: Response (balance)
EngineCloud-->>User: Balance
User->>EngineCloud: search_transactions(filters, filters_operation, page, limit, sort_by, sort_direction)
EngineCloud->>EngineCloudAPI: POST /transactions/search {params}
EngineCloudAPI-->>EngineCloud: Response (transactions)
EngineCloud-->>User: Transactions
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
python/thirdweb-ai/src/thirdweb_ai/services/__init__.py (1)
1-8
: Well-structured module exports.The file properly imports and explicitly exports the service classes, making the API surface clear and well-defined. The inclusion of
EngineCloud
alongside the other services integrates it nicely into the package.Add a newline at the end of the file to fix the static analysis warning:
__all__ = ["Engine", "EngineCloud", "Insight", "Nebula", "Service", "Storage"] +
🧰 Tools
🪛 Ruff (0.11.9)
8-8: No newline at end of file
Add trailing newline
(W292)
python/thirdweb-ai/src/thirdweb_ai/services/engine_cloud.py (1)
168-214
: Consider simplifying the complex type annotation.The
filters
parameter has a complex type annotation that might be difficult to maintain. Consider defining a dedicated type alias or class to improve readability.+# At the top of the file, add: +from typing import TypedDict, Union, Literal + +class FilterField(TypedDict): + field: Literal["id", "batchIndex", "from", "signerAddress", "smartAccountAddress", "chainId"] + +class FilterValues(TypedDict): + values: list[int] + +class FilterOperator(TypedDict): + operator: Literal["AND", "OR"] + +FilterCondition = Union[FilterField, FilterValues, FilterOperator] + @tool( description="Search for transactions with flexible filtering options. Retrieve transaction history with customizable filters for addresses, chains, statuses, and more." ) def search_transactions( self, filters: Annotated[ - list[ - dict[ - Literal["field"], - Literal["id", "batchIndex", "from", "signerAddress", "smartAccountAddress", "chainId"], - ] - | dict[Literal["values"], list[int]] - | dict[Literal["operator"], Literal["AND", "OR"]] - ], + list[FilterCondition], "List of filter conditions to apply", ], # Rest of the method remains unchanged
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
python/thirdweb-ai/README.md
(3 hunks)python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/__init__.py
(1 hunks)python/thirdweb-ai/src/thirdweb_ai/services/__init__.py
(1 hunks)python/thirdweb-ai/src/thirdweb_ai/services/engine_cloud.py
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/__init__.py (1)
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py (1)
get_google_adk_tools
(64-73)
🪛 Ruff (0.11.9)
python/thirdweb-ai/src/thirdweb_ai/services/__init__.py
8-8: No newline at end of file
Add trailing newline
(W292)
🔇 Additional comments (12)
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/__init__.py (1)
1-3
: Well-structured module initialization.Clean implementation that clearly defines the module's public API by importing and explicitly exporting the
get_google_adk_tools
function. This follows Python best practices for package structure.python/thirdweb-ai/README.md (4)
52-53
: Good addition of the new service to the import statement.The addition of
EngineCloud
to the import statement clearly shows users how to access the new service.
58-59
: Clear documentation for authentication requirements.The note about
vault_access_token
being required for server wallet operations provides important information for users to properly initialize the service.
68-69
: Good inclusion of Engine Cloud tools with helpful comment.The addition of
engine_cloud.get_tools()
with a descriptive comment helps users understand when to use this service.
74-83
: Well-structured documentation of available services.The new "Available Services" section provides a clear and concise overview of all the core services, including the new
EngineCloud
service. The description effectively communicates the purpose and capabilities of each service.python/thirdweb-ai/src/thirdweb_ai/services/engine_cloud.py (7)
7-21
: Well-implemented authentication handling.The class properly extends the base
Service
class and implements custom header handling for the vault access token. The implementation follows the Open/Closed principle by extending the parent class's behavior rather than modifying it.
22-34
: Good implementation of server wallet creation.The
create_server_wallet
method is well-documented and properly implements the API endpoint for creating a new server wallet with KMS integration.
35-70
: Well-documented contract interaction method.The
write_contract
method is thoroughly documented with clear parameter annotations explaining each field's purpose. The payload construction is properly structured for the API endpoint.
71-109
: Well-implemented transaction sending method.The
send_transaction
method handles low-level transactions with appropriate parameter validation and documentation. The payload structure follows the API requirements.
110-149
: Comprehensive contract reading implementation.The
read_contract
method provides a flexible interface for read-only contract calls with support for multicall batching. All parameters are well-documented with clear type annotations.
150-167
: Simple and effective balance query method.The
get_native_balance
method provides a straightforward way to query native cryptocurrency balances with minimal required parameters.
1-214
:❌ Incorrect review comment
Consider adding error handling for API responses.
While the implementation is solid, there's no explicit error handling for the API responses. Consider adding try/except blocks or documenting the error handling approach.
You could add a helper method to handle errors consistently:
def _handle_api_response(self, response: dict[str, Any]) -> dict[str, Any]: """Process API response and handle errors consistently.""" if "error" in response: # Extract error details and raise appropriate exception error_message = response.get("error", {}).get("message", "Unknown error") error_code = response.get("error", {}).get("code", "unknown") raise ValueError(f"API Error ({error_code}): {error_message}") return responseThen update your methods to use this helper:
def create_server_wallet(self, label: Annotated[str, "A human-readable label to identify this wallet."]) -> dict[str, Any]: payload = {"label": label} response = self._post("accounts", payload) return self._handle_api_response(response)
🏁 Script executed:
#!/bin/bash # Look for error handling in the parent Service class echo "Checking for error handling in Service class" rg -A 5 "_post" | grep -A 10 "def _post"Length of output: 1763
🏁 Script executed:
#!/bin/bash # Display the full implementation of Service._post to check for built-in error handling rg -A 50 "def _post" python/thirdweb-ai/src/thirdweb_ai/services/service.pyLength of output: 845
Service._post already handles HTTP errors
TheService._post
implementation invokesresponse.raise_for_status()
, so any non-2xx response will raise anHTTPError
before you callresponse.json()
. You’ll get built-in error handling for HTTP failures. If you need to standardize or enrich error messages (e.g. wrapHTTPError
or inspect JSON error bodies on 2xx), you could extend or wrap_post
, but the basic error-raising is already in place.Likely an incorrect or invalid review comment.
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py (1)
43-65
: Good fix: Prevent schema mutation with deep copy and recursive cleaning.The changes correctly fix potential side effects by:
- Deep copying the parameters to avoid modifying the original schema
- Implementing a recursive helper to clean nested dictionaries
This is a much safer approach than modifying the original schema.
I suggest some style improvements to make the code cleaner:
- # Deep copy the parameters to avoid modifying the original + # Deep copy the parameters to avoid modifying the original schema import copy parameters = copy.deepcopy(self.tool.schema["parameters"]) - if "additionalProperties" in parameters: - del parameters["additionalProperties"] + parameters.pop("additionalProperties") - def remove_additional_properties(obj: dict[str, Any]): if "additionalProperties" in obj: - del obj["additionalProperties"] + obj.pop("additionalProperties") - if "items" in obj and isinstance(obj["items"], dict): remove_additional_properties(obj["items"]) - if "properties" in obj and isinstance(obj["properties"], dict): for prop in obj["properties"].values(): if isinstance(prop, dict): remove_additional_properties(prop) - if "properties" in parameters: for prop in parameters["properties"].values(): remove_additional_properties(prop) -🧰 Tools
🪛 Ruff (0.11.9)
46-46: Blank line contains whitespace
Remove whitespace from blank line
(W293)
49-49: Blank line contains whitespace
Remove whitespace from blank line
(W293)
52-52: Use
pop
instead ofkey in dict
followed bydel dict[key]
Replace
if
statement with.pop(..., None)
(RUF051)
53-53: Blank line contains whitespace
Remove whitespace from blank line
(W293)
56-56: Blank line contains whitespace
Remove whitespace from blank line
(W293)
61-61: Blank line contains whitespace
Remove whitespace from blank line
(W293)
65-65: Blank line contains whitespace
Remove whitespace from blank line
(W293)
python/thirdweb-mcp/README.md (1)
83-84
: Fix URL formatting in documentation.The environment variables section has been properly updated, but there's a markdown formatting issue with the bare URL.
-- `THIRDWEB_ENGINE_CLOUD_URL`: URL endpoint for EngineCloud service (defaults to https://engine.thirdweb.com/v1) +- `THIRDWEB_ENGINE_CLOUD_URL`: URL endpoint for EngineCloud service (defaults to `https://engine.thirdweb.com/v1`)🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
83-83: Bare URL used
null(MD034, no-bare-urls)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
README.md
(6 hunks)python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py
(1 hunks)python/thirdweb-ai/src/thirdweb_ai/services/engine_cloud.py
(1 hunks)python/thirdweb-mcp/README.md
(7 hunks)python/thirdweb-mcp/src/mcp.py
(5 hunks)
✅ Files skipped from review due to trivial changes (1)
- README.md
🚧 Files skipped from review as they are similar to previous changes (1)
- python/thirdweb-ai/src/thirdweb_ai/services/engine_cloud.py
🧰 Additional context used
🪛 Ruff (0.11.9)
python/thirdweb-ai/src/thirdweb_ai/adapters/google_adk/google_adk.py
46-46: Blank line contains whitespace
Remove whitespace from blank line
(W293)
49-49: Blank line contains whitespace
Remove whitespace from blank line
(W293)
52-52: Use pop
instead of key in dict
followed by del dict[key]
Replace if
statement with .pop(..., None)
(RUF051)
53-53: Blank line contains whitespace
Remove whitespace from blank line
(W293)
56-56: Blank line contains whitespace
Remove whitespace from blank line
(W293)
61-61: Blank line contains whitespace
Remove whitespace from blank line
(W293)
65-65: Blank line contains whitespace
Remove whitespace from blank line
(W293)
🪛 markdownlint-cli2 (0.17.2)
python/thirdweb-mcp/README.md
83-83: Bare URL used
null
(MD034, no-bare-urls)
🔇 Additional comments (10)
python/thirdweb-mcp/src/mcp.py (5)
4-4
: LGTM: Import statement properly updated.The import statement has been correctly updated to include the new
EngineCloud
service alongside other existing services.
57-68
: CLI options well-defined for EngineCloud configuration.The added CLI options follow the established pattern in the codebase:
--engine-cloud-url
with a sensible default URL--vault-access-token
for authenticationBoth options properly fall back to environment variables, maintaining consistency with other service configurations.
77-78
: LGTM: Function signature properly extended.The main function signature has been correctly updated to include the new parameters, using appropriate typing with
str
andstr | None
.
87-87
: LGTM: Service registration properly updated.The
engine_cloud
service is correctly added to the list of enabled services when a secret key is provided, following the pattern used for other services.
119-126
: LGTM: EngineCloud service correctly initialized and registered.The EngineCloud service initialization follows the established pattern:
- Check if the service is enabled
- Create an instance with the appropriate configuration
- Register the service tools with the MCP server
The implementation is clean and consistent with how other services are handled.
python/thirdweb-mcp/README.md (5)
12-12
: LGTM: EngineCloud added to overview.The EngineCloud service is properly added to the overview section with a clear, concise description of its capabilities.
49-52
: LGTM: Configuration requirements updated.Configuration requirements have been properly updated to include EngineCloud with the required thirdweb Secret Key and Vault Access Token.
71-72
: LGTM: Command-line example updated.The command-line example has been extended to include the new vault-access-token parameter, maintaining the established format.
108-109
: LGTM: Claude Desktop integration instructions updated.The Claude Desktop integration instructions have been properly updated to include the new vault access token environment variable.
151-158
: LGTM: EngineCloud service documentation added.A comprehensive section has been added for the EngineCloud service, clearly describing its capabilities:
- Server wallet management with KMS integration
- Smart contract interactions
- Transaction management
- Native token balance checks
The documentation is concise and consistent with other service descriptions.
Summary by CodeRabbit
New Features
Documentation