### 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>
196 lines
8.2 KiB
Python
196 lines
8.2 KiB
Python
from typing import Annotated
|
|
|
|
from arcade_tdk import ToolContext, tool
|
|
from stripe_agent_toolkit.api import StripeAPI
|
|
|
|
|
|
def run_stripe_tool(context: ToolContext, method_name: str, params: dict) -> str:
|
|
"""
|
|
Helper function that retrieves the Stripe secret key, initializes the API,
|
|
and executes the specified method with the provided parameters.
|
|
"""
|
|
api_key = context.get_secret("STRIPE_SECRET_KEY")
|
|
stripe_api = StripeAPI(secret_key=api_key, context=None)
|
|
params = {k: v for k, v in params.items() if v is not None}
|
|
return stripe_api.run(method_name, **params) # type: ignore[no-any-return]
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def create_customer(
|
|
context: ToolContext,
|
|
name: Annotated[str, "The name of the customer."],
|
|
email: Annotated[str | None, "The email of the customer."] = None,
|
|
) -> Annotated[str, "This tool will create a customer in Stripe."]:
|
|
"""This tool will create a customer in Stripe."""
|
|
return run_stripe_tool(context, "create_customer", {"name": name, "email": email})
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def list_customers(
|
|
context: ToolContext,
|
|
limit: Annotated[
|
|
int | None,
|
|
"A limit on the number of objects to be returned. Limit can range between 1 and 100.",
|
|
] = None,
|
|
email: Annotated[
|
|
str | None,
|
|
"A case-sensitive filter on the list based on the customer's email field. "
|
|
"The value must be a string.",
|
|
] = None,
|
|
) -> Annotated[str, "This tool will fetch a list of Customers from Stripe."]:
|
|
"""This tool will fetch a list of Customers from Stripe."""
|
|
return run_stripe_tool(context, "list_customers", {"limit": limit, "email": email})
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def create_product(
|
|
context: ToolContext,
|
|
name: Annotated[str, "The name of the product."],
|
|
description: Annotated[str | None, "The description of the product."] = None,
|
|
) -> Annotated[str, "This tool will create a product in Stripe."]:
|
|
"""This tool will create a product in Stripe."""
|
|
return run_stripe_tool(context, "create_product", {"name": name, "description": description})
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def list_products(
|
|
context: ToolContext,
|
|
limit: Annotated[
|
|
int | None,
|
|
"A limit on the number of objects to be returned. Limit can range between 1 and 100, "
|
|
"and the default is 10.",
|
|
] = None,
|
|
) -> Annotated[str, "This tool will fetch a list of Products from Stripe."]:
|
|
"""This tool will fetch a list of Products from Stripe."""
|
|
return run_stripe_tool(context, "list_products", {"limit": limit})
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def create_price(
|
|
context: ToolContext,
|
|
product: Annotated[str, "The ID of the product to create the price for."],
|
|
unit_amount: Annotated[int, "The unit amount of the price in cents."],
|
|
currency: Annotated[str, "The currency of the price."],
|
|
) -> Annotated[str, "This tool will create a price in Stripe. If a product has not already been"]:
|
|
"""This tool will create a price in Stripe. If a product has not already been"""
|
|
return run_stripe_tool(
|
|
context,
|
|
"create_price",
|
|
{"product": product, "unit_amount": unit_amount, "currency": currency},
|
|
)
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def list_prices(
|
|
context: ToolContext,
|
|
product: Annotated[str | None, "The ID of the product to list prices for."] = None,
|
|
limit: Annotated[
|
|
int | None,
|
|
"A limit on the number of objects to be returned. Limit can range between 1 and 100, "
|
|
"and the default is 10.",
|
|
] = None,
|
|
) -> Annotated[str, "This tool will fetch a list of Prices from Stripe."]:
|
|
"""This tool will fetch a list of Prices from Stripe."""
|
|
return run_stripe_tool(context, "list_prices", {"product": product, "limit": limit})
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def create_payment_link(
|
|
context: ToolContext,
|
|
price: Annotated[str, "The ID of the price to create the payment link for."],
|
|
quantity: Annotated[int, "The quantity of the product to include."],
|
|
) -> Annotated[str, "This tool will create a payment link in Stripe."]:
|
|
"""This tool will create a payment link in Stripe."""
|
|
return run_stripe_tool(context, "create_payment_link", {"price": price, "quantity": quantity})
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def list_invoices(
|
|
context: ToolContext,
|
|
customer: Annotated[str | None, "The ID of the customer to list invoices for."] = None,
|
|
limit: Annotated[
|
|
int | None,
|
|
"A limit on the number of objects to be returned. Limit can range between 1 and 100, "
|
|
"and the default is 10.",
|
|
] = None,
|
|
) -> Annotated[str, "This tool will list invoices in Stripe."]:
|
|
"""This tool will list invoices in Stripe."""
|
|
return run_stripe_tool(context, "list_invoices", {"customer": customer, "limit": limit})
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def create_invoice(
|
|
context: ToolContext,
|
|
customer: Annotated[str, "The ID of the customer to create the invoice for."],
|
|
days_until_due: Annotated[int | None, "The number of days until the invoice is due."] = None,
|
|
) -> Annotated[str, "This tool will create an invoice in Stripe."]:
|
|
"""This tool will create an invoice in Stripe."""
|
|
return run_stripe_tool(
|
|
context, "create_invoice", {"customer": customer, "days_until_due": days_until_due}
|
|
)
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def create_invoice_item(
|
|
context: ToolContext,
|
|
customer: Annotated[str, "The ID of the customer to create the invoice item for."],
|
|
price: Annotated[str, "The ID of the price for the item."],
|
|
invoice: Annotated[str, "The ID of the invoice to create the item for."],
|
|
) -> Annotated[str, "This tool will create an invoice item in Stripe."]:
|
|
"""This tool will create an invoice item in Stripe."""
|
|
return run_stripe_tool(
|
|
context, "create_invoice_item", {"customer": customer, "price": price, "invoice": invoice}
|
|
)
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def finalize_invoice(
|
|
context: ToolContext, invoice: Annotated[str, "The ID of the invoice to finalize."]
|
|
) -> Annotated[str, "This tool will finalize an invoice in Stripe."]:
|
|
"""This tool will finalize an invoice in Stripe."""
|
|
return run_stripe_tool(context, "finalize_invoice", {"invoice": invoice})
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def retrieve_balance(
|
|
context: ToolContext,
|
|
) -> Annotated[str, "This tool will retrieve the balance from Stripe. It takes no input."]:
|
|
"""This tool will retrieve the balance from Stripe. It takes no input."""
|
|
return run_stripe_tool(context, "retrieve_balance", {})
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def create_refund(
|
|
context: ToolContext,
|
|
payment_intent: Annotated[str, "The ID of the PaymentIntent to refund."],
|
|
amount: Annotated[int | None, "The amount to refund in cents."] = None,
|
|
) -> Annotated[str, "This tool will refund a payment intent in Stripe."]:
|
|
"""This tool will refund a payment intent in Stripe."""
|
|
return run_stripe_tool(
|
|
context, "create_refund", {"payment_intent": payment_intent, "amount": amount}
|
|
)
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def list_payment_intents(
|
|
context: ToolContext,
|
|
customer: Annotated[str | None, "The ID of the customer to list payment intents for."] = None,
|
|
limit: Annotated[
|
|
int | None,
|
|
"A limit on the number of objects to be returned. Limit can range between 1 and 100.",
|
|
] = None,
|
|
) -> Annotated[str, "This tool will list payment intents in Stripe."]:
|
|
"""This tool will list payment intents in Stripe."""
|
|
return run_stripe_tool(context, "list_payment_intents", {"customer": customer, "limit": limit})
|
|
|
|
|
|
@tool(requires_secrets=["STRIPE_SECRET_KEY"])
|
|
def create_billing_portal_session(
|
|
context: ToolContext,
|
|
customer: Annotated[str, "The ID of the customer to create the billing portal session for."],
|
|
return_url: Annotated[str | None, "The default URL to return to afterwards."] = None,
|
|
) -> Annotated[str, "This tool will create a billing portal session."]:
|
|
"""This tool will create a billing portal session."""
|
|
return run_stripe_tool(
|
|
context, "create_billing_portal_session", {"customer": customer, "return_url": return_url}
|
|
)
|