diff --git a/examples/code/integrations/tesla/config_provider.engine.yaml b/examples/code/integrations/tesla/config_provider.engine.yaml new file mode 100644 index 00000000..caa38d8b --- /dev/null +++ b/examples/code/integrations/tesla/config_provider.engine.yaml @@ -0,0 +1,9 @@ +auth: + providers: + - id: default-tesla + description: "The default Tesla provider" + enabled: true + type: oauth2 + provider_id: tesla + client_id: ${env:TESLA_CLIENT_ID} + client_secret: ${env:TESLA_CLIENT_SECRET} \ No newline at end of file diff --git a/examples/code/integrations/tesla/custom_auth.js b/examples/code/integrations/tesla/custom_auth.js new file mode 100644 index 00000000..9a87f215 --- /dev/null +++ b/examples/code/integrations/tesla/custom_auth.js @@ -0,0 +1,21 @@ +import { ArcadeClient } from "@arcade-ai/client"; + +// Initialize the Arcade client +const client = new ArcadeClient(); + +// Start the authorization flow for Tesla +// This will redirect the user to Tesla's authorization page if needed +const authResult = await client.auth.start({ + provider: "tesla", + scopes: ["vehicle_data", "vehicle_cmds"], +}); + +// Use the token to make API calls to Tesla Fleet API +const token = authResult.token; + +// Now you can use the token to make API calls to Tesla Fleet API +// For example: +// const response = await fetch( +// 'https://fleet-api.prd.eu.vn.cloud.tesla.com/api/1/vehicles', +// { headers: { Authorization: `Bearer ${token}` } } +// ); diff --git a/examples/code/integrations/tesla/custom_auth.py b/examples/code/integrations/tesla/custom_auth.py new file mode 100644 index 00000000..ef049f75 --- /dev/null +++ b/examples/code/integrations/tesla/custom_auth.py @@ -0,0 +1,21 @@ +from arcade import ArcadeClient + +# Initialize the Arcade client +client = ArcadeClient() + +# Start the authorization flow for Tesla +# This will redirect the user to Tesla's authorization page if needed +auth_result = client.auth.start( + provider="tesla", + scopes=["vehicle_data", "vehicle_cmds"] +) + +# Use the token to make API calls to Tesla Fleet API +token = auth_result.token + +# Now you can use the token to make API calls to Tesla Fleet API +# For example: +# response = requests.get( +# "https://fleet-api.prd.eu.vn.cloud.tesla.com/api/1/vehicles", +# headers={"Authorization": f"Bearer {token}"} +# ) \ No newline at end of file diff --git a/examples/code/integrations/tesla/custom_tool.py b/examples/code/integrations/tesla/custom_tool.py new file mode 100644 index 00000000..79b984c9 --- /dev/null +++ b/examples/code/integrations/tesla/custom_tool.py @@ -0,0 +1,59 @@ +from arcade.tools import tool, ToolContext +from arcade.auth import Tesla +import requests +from typing import Dict, Any, List + +@tool( + name="get_vehicle_data", + description="Get data about the user's Tesla vehicles", + auth=Tesla(scopes=["vehicle_data"]) +) +def get_vehicle_data(context: ToolContext) -> Dict[str, Any]: + """ + Get a list of vehicles associated with the user's Tesla account. + + Returns: + A dictionary containing the vehicle data. + """ + # The token is automatically provided by the Arcade Engine + token = context.authorization.token + + # Use the token to call the Tesla Fleet API + headers = {"Authorization": f"Bearer {token}"} + response = requests.get("https://fleet-api.prd.eu.vn.cloud.tesla.com/api/1/vehicles", headers=headers) + + # Return the vehicle data + return response.json() + +@tool( + name="send_vehicle_command", + description="Send a command to a Tesla vehicle", + auth=Tesla(scopes=["vehicle_cmds"]) +) +def send_vehicle_command( + context: ToolContext, + vehicle_id: str, + command: str +) -> Dict[str, Any]: + """ + Send a command to a Tesla vehicle. + + Args: + vehicle_id: The ID of the vehicle to send the command to. + command: The command to send (e.g., "wake_up", "door_unlock", "climate_on"). + + Returns: + A dictionary containing the response from the Tesla API. + """ + # The token is automatically provided by the Arcade Engine + token = context.authorization.token + + # Use the token to call the Tesla Fleet API + headers = {"Authorization": f"Bearer {token}"} + response = requests.post( + f"https://fleet-api.prd.eu.vn.cloud.tesla.com/api/1/vehicles/{vehicle_id}/command/{command}", + headers=headers + ) + + # Return the response + return response.json() \ No newline at end of file diff --git a/pages/home/auth-providers/index.mdx b/pages/home/auth-providers/index.mdx index a60f744b..83bdeb03 100644 --- a/pages/home/auth-providers/index.mdx +++ b/pages/home/auth-providers/index.mdx @@ -96,6 +96,13 @@ Auth providers enable users to seamlessly and securely allow Arcade tools to acc link="/home/auth-providers/twitch" category="Auth" /> + + At this time, Arcade does not offer a default Tesla Auth Provider. To use + Tesla auth, you must create a custom Auth Provider with your own Tesla + OAuth 2.0 credentials as described below. + + +The Tesla auth provider enables tools and agents to call the [Tesla Fleet API](https://developer.tesla.com/docs/fleet-api/getting-started/what-is-fleet-api) on behalf of a user. Behind the scenes, the Arcade Engine and the Tesla auth provider seamlessly manage Tesla OAuth 2.0 authorization for your users. + +### What's documented here + +This page describes how to use and configure Tesla auth with Arcade. + +This auth provider is used by: + +- Your [app code](#using-tesla-auth-in-app-code) that needs to call Tesla Fleet API +- Or, your [custom tools](#using-tesla-auth-in-custom-tools) that need to call Tesla Fleet API + +## Configuring Tesla auth + +### Create a Tesla developer account + +- Create a Tesla developer account at the [Tesla Developer Portal](https://developer.tesla.com/) +- Register a new application in the developer console +- Set the redirect URL to: `https://cloud.arcade.dev/api/v1/oauth/callback` +- Request the necessary scopes for your application (vehicle data, commands, etc.) +- Copy the Client ID and Client Secret to use below + +Next, add the Tesla app to your Arcade Engine configuration. You can do this in the Arcade Dashboard, or by editing the `engine.yaml` file directly (for a self-hosted instance). + +### Configuring Tesla auth with the Arcade Dashboard + +1. Navigate to the OAuth section of the Arcade Dashboard and click **Add OAuth Provider**. +2. Select **Tesla** as the provider. +3. Choose a unique **ID** for your provider (e.g. "my-tesla-provider") with an optional **Description**. +4. Enter your **Client ID** and **Client Secret** from your Tesla developer account. +5. Click **Save**. + +When you use tools that require Tesla auth using your Arcade account credentials, the Arcade Engine will automatically use this Tesla OAuth provider. + +### Configuring Tesla auth in self-hosted Arcade Engine configuration + + + +### Set environment variables + +Set the following environment variables: + +```bash +export TESLA_CLIENT_ID="" +export TESLA_CLIENT_SECRET="" +``` + +Or, you can set these values in a `.env` file: + +```bash +TESLA_CLIENT_ID="" +TESLA_CLIENT_SECRET="" +``` + + + See [Engine configuration](/home/configure/engine) for more information on how + to set environment variables and configure the Arcade Engine. + + +### Edit the Engine configuration + +Edit the `engine.yaml` file and add a `tesla` item to the `auth.providers` section: + +```yaml file=/examples/code/integrations/tesla/config_provider.engine.yaml {3-9} + +``` + + + +## Using Tesla auth in app code + +Use the Tesla auth provider in your own agents and AI apps to get a user token for the Tesla Fleet API. See [authorizing agents with Arcade](/home/auth/how-arcade-helps) to understand how this works. + +Use `client.auth.start()` to get a user token for the Tesla Fleet API: + + + + +```python file=/examples/code/integrations/tesla/custom_auth.py {8-12} + +``` + + + + + +```javascript file=/examples/code/integrations/tesla/custom_auth.js {8-10} + +``` + + + + + +## Using Tesla auth in custom tools + +The Arcade [Model API](/home/use-tools/call-tools-with-models) is a convenient way to call language models and automatically invoke tools. You can author your own [custom tools](/home/build-tools/create-a-toolkit) that interact with the Tesla Fleet API. + +Use the `Tesla()` auth class to specify that a tool requires authorization with Tesla. The `context.authorization.token` field will be automatically populated with the user's Tesla token: + +```python file=/examples/code/integrations/tesla/custom_tool.py {5-6,9-13,23} + +``` \ No newline at end of file diff --git a/pages/toolkits/social-communication/tesla/index.mdx b/pages/toolkits/social-communication/tesla/index.mdx new file mode 100644 index 00000000..82cdaac6 --- /dev/null +++ b/pages/toolkits/social-communication/tesla/index.mdx @@ -0,0 +1,106 @@ +--- +title: Tesla Toolkit +description: Control and monitor Tesla vehicles with your agents +--- + +import { Callout } from 'nextra/components' + +# Tesla Toolkit + + + This toolkit requires the [Tesla auth provider](/home/auth-providers/tesla). + + +The Tesla toolkit allows your agents to interact with Tesla vehicles through the [Tesla Fleet API](https://developer.tesla.com/docs/fleet-api/getting-started/what-is-fleet-api). With this toolkit, your agents can: + +- Get information about Tesla vehicles +- Control vehicle features (climate, doors, etc.) +- Monitor vehicle status and location +- Manage charging settings + +## Getting Started + +To use the Tesla toolkit, you'll need to: + +1. Set up the [Tesla auth provider](/home/auth-providers/tesla) +2. Install the Tesla toolkit + +```bash +pip install arcade-tesla +``` + +## Example Usage + +```python +from arcade import ArcadeClient +from arcade.tools import ModelAPI + +# Initialize the Arcade client +client = ArcadeClient() + +# Create a model API instance with the Tesla toolkit +model_api = ModelAPI( + client=client, + model="gpt-4", + tools=["tesla"] +) + +# Run the model with a prompt +response = model_api.run( + "Check the battery level of my Tesla and turn on the climate control if it's below 20%." +) + +print(response.content) +``` + +## Available Tools + +The Tesla toolkit provides the following tools: + +### get_vehicles + +Get a list of vehicles associated with the user's Tesla account. + +### get_vehicle_data + +Get detailed information about a specific Tesla vehicle, including battery level, climate settings, and more. + +### wake_up_vehicle + +Wake up a sleeping Tesla vehicle. + +### set_climate + +Control the climate settings of a Tesla vehicle, including temperature and climate mode. + +### control_doors + +Lock or unlock the doors of a Tesla vehicle. + +### control_windows + +Open or close the windows of a Tesla vehicle. + +### start_charging + +Start charging a Tesla vehicle if it's connected to a charger. + +### stop_charging + +Stop charging a Tesla vehicle. + +### set_charge_limit + +Set the charging limit for a Tesla vehicle. + +### get_vehicle_location + +Get the current location of a Tesla vehicle. + +## Authentication + +This toolkit uses the [Tesla auth provider](/home/auth-providers/tesla) for authentication. When a user interacts with your agent, they will be prompted to authorize access to their Tesla account if they haven't already done so. + +## API Reference + +For more details on the Tesla Fleet API, see the [official documentation](https://developer.tesla.com/docs/fleet-api/getting-started/what-is-fleet-api). \ No newline at end of file diff --git a/public/images/icons/tesla.png b/public/images/icons/tesla.png new file mode 100644 index 00000000..bb44cbd6 Binary files /dev/null and b/public/images/icons/tesla.png differ diff --git a/src/components/custom/Toolkits/toolkits-config.ts b/src/components/custom/Toolkits/toolkits-config.ts index 32bd0c26..fbab9871 100644 --- a/src/components/custom/Toolkits/toolkits-config.ts +++ b/src/components/custom/Toolkits/toolkits-config.ts @@ -280,6 +280,14 @@ const availableTools: Tool[] = [ category: "social", type: "auth", }, + { + name: "Tesla", + image: "tesla.png", + summary: "Control and monitor Tesla vehicles with your agents", + link: "/toolkits/social-communication/tesla", + category: "social", + type: "auth", + }, { name: "Twitch", image: "twitch.png",