This PR includes several improvements to the Arcade client and adds LangGraph examples: 1. Enhanced error handling in the Arcade client: - Improved HTTP error handling in `BaseArcadeClient` - Simplified request methods in `SyncArcadeClient` and `AsyncArcadeClient` 2. Updated `ToolResource` class: - Changed base path from `/v1/tool` to `/v1/tools` - Added `tool_version` parameter to `authorize` method 3. Improved Toolkit discovery: - Updated `find_all_arcade_toolkits` to search only in the current Python interpreter's site-packages 5. Added LangGraph examples: - New `langgraph_auth.py` example demonstrating Gmail authentication - New `langgraph_with_tool_exec.py` example showing tool execution within a LangGraph 6. Minor updates: - Changed default `BASE_URL` to `https://api.arcade.com/` - Updated import error message for eval dependencies --------- Co-authored-by: Nate Barbettini <nate@arcade-ai.com>
90 lines
2.1 KiB
Python
90 lines
2.1 KiB
Python
import os
|
|
from enum import Enum
|
|
|
|
from pydantic import AnyUrl, BaseModel, Field
|
|
|
|
from arcade.core.schema import ToolAuthorizationContext, ToolCallOutput
|
|
|
|
OPENAI_API_VERSION = os.getenv("OPENAI_API_VERSION", "v1")
|
|
|
|
|
|
class AuthProvider(str, Enum):
|
|
"""The supported authorization providers."""
|
|
|
|
oauth2 = "oauth2"
|
|
"""OAuth 2.0 authorization"""
|
|
|
|
google = "google"
|
|
"""Google authorization"""
|
|
|
|
slack_user = "slack_user"
|
|
"""Slack (user token) authorization"""
|
|
|
|
github_app = "github_app"
|
|
"""GitHub App authorization"""
|
|
|
|
|
|
class AuthRequest(BaseModel):
|
|
"""
|
|
The requirements for authorization for a tool
|
|
# TODO (Nate): Make a validator here
|
|
"""
|
|
|
|
authority: AnyUrl | str | None = None
|
|
"""The URL of the OAuth 2.0 authorization server."""
|
|
|
|
scopes: list[str]
|
|
"""The scope(s) needed for authorization."""
|
|
|
|
|
|
class AuthStatus(str, Enum):
|
|
"""The status of an authorization request."""
|
|
|
|
pending = "pending"
|
|
failed = "failed"
|
|
completed = "completed"
|
|
|
|
|
|
class HealthCheckResponse(BaseModel):
|
|
"""Response from a health check request."""
|
|
|
|
healthy: bool
|
|
"""Whether the health check was successful."""
|
|
|
|
|
|
class AuthResponse(BaseModel):
|
|
"""Response from an authorization request."""
|
|
|
|
auth_id: str = Field(alias="authorization_id")
|
|
"""The ID of the authorization request"""
|
|
|
|
scopes: list[str]
|
|
"""The scope(s) requested in the authorization request"""
|
|
|
|
# TODO: Use AnyUrl?
|
|
auth_url: str | None = Field(None, alias="authorization_url")
|
|
"""The URL for the authorization"""
|
|
|
|
status: AuthStatus
|
|
"""Only completed implies presence of a token"""
|
|
|
|
context: ToolAuthorizationContext | None = None
|
|
|
|
|
|
class ExecuteToolResponse(BaseModel):
|
|
"""Response from executing a tool."""
|
|
|
|
invocation_id: str
|
|
"""The globally-unique ID for this tool invocation in the run."""
|
|
|
|
duration: float
|
|
"""The duration of the tool invocation in milliseconds."""
|
|
|
|
finished_at: str
|
|
"""The timestamp when the tool invocation finished."""
|
|
|
|
success: bool
|
|
"""Whether the tool invocation was successful."""
|
|
|
|
output: ToolCallOutput | None = None
|
|
"""The output of the tool invocation."""
|