Skip to content
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

Feature/contrib_crewai #166

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 175 additions & 0 deletions contrib/common/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
.DS_Store
arcade.toml
docker/arcade.toml

*.lock

# example data
examples/data
scratch


docs/source

# From https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
21 changes: 21 additions & 0 deletions contrib/common/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024, Arcade AI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
62 changes: 62 additions & 0 deletions contrib/common/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
VERSION ?= "0.1.0"

.PHONY: install
install: ## Install the poetry environment and install the pre-commit hooks
@if ! command -v poetry >/dev/null 2>&1; then \
echo "🚫 Poetry is not installed. Please install poetry before proceeding."; \
exit 1; \
fi
@echo "🚀 Creating virtual environment using pyenv and poetry"
@poetry install --all-extras
@poetry run pre-commit install

.PHONY: check
check: ## Run code quality tools.
@echo "🚀 Checking Poetry lock file consistency with 'pyproject.toml': Running poetry check --lock"
@poetry check --lock
@echo "🚀 Linting code: Running pre-commit"
@poetry run pre-commit run -a
@echo "🚀 Static type checking: Running mypy"
@poetry run mypy $(git ls-files '*.py')

.PHONY: test
test: ## Test the code with pytest
@echo "🚀 Testing code: Running pytest"
@poetry run pytest -W ignore -v --cov --cov-config=pyproject.toml --cov-report=xml

.PHONY: set-version
set-version: ## Set the version in the pyproject.toml file
@echo "🚀 Setting version in pyproject.toml"
@poetry version $(VERSION)

.PHONY: unset-version
unset-version: ## Set the version in the pyproject.toml file
@echo "🚀 Setting version in pyproject.toml"
@poetry version 0.1.0

.PHONY: build
build: clean-build ## Build wheel file using poetry
@echo "🚀 Creating wheel file"
@poetry build

.PHONY: clean-build
clean-build: ## clean build artifacts
@rm -rf dist

.PHONY: publish
publish: ## publish a release to pypi.
@echo "🚀 Publishing: Dry run."
@poetry config pypi-token.pypi $(PYPI_TOKEN)
@poetry publish --dry-run
@echo "🚀 Publishing."
@poetry publish

.PHONY: build-and-publish
build-and-publish: build publish ## Build and publish.

.PHONY: help
help:
@echo "🛠️ Arcade AI Dev Commands:\n"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.DEFAULT_GOAL := help
Empty file.
75 changes: 75 additions & 0 deletions contrib/common/common_arcade/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import logging
import time

from arcadepy import Arcade
from arcadepy.types.shared import AuthorizationResponse, ToolDefinition

logger = logging.getLogger(__name__)


class ArcadeAuthMixin:
"""Mixin class providing authentication-related functionality for Arcade tools."""

client: Arcade
_tools: dict[str, ToolDefinition]

def authorize(self, tool_name: str, user_id: str) -> AuthorizationResponse:
"""Authorize a user for a tool.

Args:
tool_name: The name of the tool to authorize.
user_id: The user ID to authorize.

Returns:
AuthorizationResponse
"""
return self.client.tools.authorize(tool_name=tool_name, user_id=user_id)

def wait_for_completion(
self, auth_response: AuthorizationResponse, timeout: int = 120
) -> AuthorizationResponse:
"""Wait for an authorization process to complete.

Args:
auth_response: The authorization response from the initial authorize call.
timeout: Maximum time to wait in seconds (default: 300 seconds / 5 minutes)

Returns:
AuthorizationResponse with completed status

Raises:
TimeoutError: If authorization process takes longer than timeout
"""
logger.info(f"Authorization URL: {auth_response.authorization_url}")
print(f"\nAuthorization URL: {auth_response.authorization_url}\n")
start_time = time.time()

while True:
if time.time() - start_time > timeout:
timeout_msg = f"Authorization timed out after {timeout} seconds. URL: {auth_response.authorization_url}"
logger.error(timeout_msg)
print(f"\nError: {timeout_msg}\n")
return auth_response

# Use the built-in wait parameter (max 59 seconds)
auth_response = self.client.auth.status(
authorization_id=auth_response.authorization_id, # type: ignore[arg-type]
wait=60,
)
logger.info(f"Waiting for authorization completion... Status: {auth_response.status}")
print(f"Authorization status: {auth_response.status}")

if auth_response.status == "completed":
print("\nAuthorization completed successfully!\n")
return auth_response

def is_authorized(self, authorization_id: str) -> bool:
"""Check if a tool authorization is complete."""
return self.client.auth.status(authorization_id=authorization_id).status == "completed"

def requires_auth(self, tool_name: str) -> bool:
"""Check if a tool requires authorization."""
tool_def = self._tools.get(tool_name)
if tool_def is None or tool_def.requirements is None:
return False
return tool_def.requirements.authorization is not None
5 changes: 5 additions & 0 deletions contrib/common/common_arcade/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ToolExecutionError(Exception):
"""Custom exception for tool execution failures."""

def __init__(self, message: str):
super().__init__(message)
Loading