agentr 0.1.3__py3-none-any.whl → 0.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentr/__init__.py +1 -1
- agentr/application.py +56 -56
- agentr/applications/github/app.py +55 -51
- agentr/applications/google_calendar/app.py +73 -73
- agentr/applications/google_mail/app.py +67 -67
- agentr/applications/reddit/app.py +29 -29
- agentr/applications/resend/app.py +43 -43
- agentr/applications/tavily/app.py +57 -57
- agentr/applications/zenquotes/app.py +20 -20
- agentr/cli.py +75 -58
- agentr/exceptions.py +5 -0
- agentr/integration.py +98 -91
- agentr/server.py +105 -105
- agentr/store.py +70 -70
- agentr/test.py +37 -37
- agentr/utils/openapi.py +184 -184
- agentr-0.1.4.dist-info/METADATA +156 -0
- agentr-0.1.4.dist-info/RECORD +22 -0
- agentr-0.1.3.dist-info/METADATA +0 -10
- agentr-0.1.3.dist-info/RECORD +0 -21
- {agentr-0.1.3.dist-info → agentr-0.1.4.dist-info}/WHEEL +0 -0
- {agentr-0.1.3.dist-info → agentr-0.1.4.dist-info}/entry_points.txt +0 -0
agentr/__init__.py
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
def main():
|
1
|
+
def main():
|
2
2
|
print("hello")
|
agentr/application.py
CHANGED
@@ -1,57 +1,57 @@
|
|
1
|
-
from abc import ABC, abstractmethod
|
2
|
-
from agentr.integration import Integration
|
3
|
-
import httpx
|
4
|
-
|
5
|
-
class Application(ABC):
|
6
|
-
"""
|
7
|
-
Application is collection of tools that can be used by an agent.
|
8
|
-
"""
|
9
|
-
def __init__(self, name: str, **kwargs):
|
10
|
-
self.name = name
|
11
|
-
|
12
|
-
@abstractmethod
|
13
|
-
def list_tools(self):
|
14
|
-
pass
|
15
|
-
|
16
|
-
|
17
|
-
class APIApplication(Application):
|
18
|
-
"""
|
19
|
-
APIApplication is an application that uses an API to interact with the world.
|
20
|
-
"""
|
21
|
-
def __init__(self, name: str, integration: Integration = None, **kwargs):
|
22
|
-
super().__init__(name, **kwargs)
|
23
|
-
self.integration = integration
|
24
|
-
|
25
|
-
def _get_headers(self):
|
26
|
-
return {}
|
27
|
-
|
28
|
-
def _get(self, url, params=None):
|
29
|
-
headers = self._get_headers()
|
30
|
-
response = httpx.get(url, headers=headers, params=params)
|
31
|
-
response.raise_for_status()
|
32
|
-
return response
|
33
|
-
|
34
|
-
def _post(self, url, data):
|
35
|
-
headers = self._get_headers()
|
36
|
-
response = httpx.post(url, headers=headers, json=data)
|
37
|
-
response.raise_for_status()
|
38
|
-
return response
|
39
|
-
|
40
|
-
def _put(self, url, data):
|
41
|
-
headers = self._get_headers()
|
42
|
-
response = httpx.put(url, headers=headers, json=data)
|
43
|
-
response.raise_for_status()
|
44
|
-
return response
|
45
|
-
|
46
|
-
def _delete(self, url):
|
47
|
-
headers = self._get_headers()
|
48
|
-
response = httpx.delete(url, headers=headers)
|
49
|
-
response.raise_for_status()
|
50
|
-
return response
|
51
|
-
|
52
|
-
def validate(self):
|
53
|
-
pass
|
54
|
-
|
55
|
-
@abstractmethod
|
56
|
-
def list_tools(self):
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
from agentr.integration import Integration
|
3
|
+
import httpx
|
4
|
+
|
5
|
+
class Application(ABC):
|
6
|
+
"""
|
7
|
+
Application is collection of tools that can be used by an agent.
|
8
|
+
"""
|
9
|
+
def __init__(self, name: str, **kwargs):
|
10
|
+
self.name = name
|
11
|
+
|
12
|
+
@abstractmethod
|
13
|
+
def list_tools(self):
|
14
|
+
pass
|
15
|
+
|
16
|
+
|
17
|
+
class APIApplication(Application):
|
18
|
+
"""
|
19
|
+
APIApplication is an application that uses an API to interact with the world.
|
20
|
+
"""
|
21
|
+
def __init__(self, name: str, integration: Integration = None, **kwargs):
|
22
|
+
super().__init__(name, **kwargs)
|
23
|
+
self.integration = integration
|
24
|
+
|
25
|
+
def _get_headers(self):
|
26
|
+
return {}
|
27
|
+
|
28
|
+
def _get(self, url, params=None):
|
29
|
+
headers = self._get_headers()
|
30
|
+
response = httpx.get(url, headers=headers, params=params)
|
31
|
+
response.raise_for_status()
|
32
|
+
return response
|
33
|
+
|
34
|
+
def _post(self, url, data):
|
35
|
+
headers = self._get_headers()
|
36
|
+
response = httpx.post(url, headers=headers, json=data)
|
37
|
+
response.raise_for_status()
|
38
|
+
return response
|
39
|
+
|
40
|
+
def _put(self, url, data):
|
41
|
+
headers = self._get_headers()
|
42
|
+
response = httpx.put(url, headers=headers, json=data)
|
43
|
+
response.raise_for_status()
|
44
|
+
return response
|
45
|
+
|
46
|
+
def _delete(self, url):
|
47
|
+
headers = self._get_headers()
|
48
|
+
response = httpx.delete(url, headers=headers)
|
49
|
+
response.raise_for_status()
|
50
|
+
return response
|
51
|
+
|
52
|
+
def validate(self):
|
53
|
+
pass
|
54
|
+
|
55
|
+
@abstractmethod
|
56
|
+
def list_tools(self):
|
57
57
|
pass
|
@@ -1,52 +1,56 @@
|
|
1
|
-
from agentr.integration import Integration
|
2
|
-
from agentr.application import APIApplication
|
3
|
-
from loguru import logger
|
4
|
-
|
5
|
-
|
6
|
-
class GithubApp(APIApplication):
|
7
|
-
def __init__(self, integration: Integration) -> None:
|
8
|
-
super().__init__(name="github", integration=integration)
|
9
|
-
|
10
|
-
def _get_headers(self):
|
11
|
-
if not self.integration:
|
12
|
-
raise ValueError("Integration not configured")
|
13
|
-
credentials = self.integration.get_credentials()
|
14
|
-
if not credentials:
|
15
|
-
logger.warning("No credentials found")
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
"
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
return
|
49
|
-
|
50
|
-
|
51
|
-
|
1
|
+
from agentr.integration import Integration
|
2
|
+
from agentr.application import APIApplication
|
3
|
+
from loguru import logger
|
4
|
+
from agentr.exceptions import NotAuthorizedError
|
5
|
+
|
6
|
+
class GithubApp(APIApplication):
|
7
|
+
def __init__(self, integration: Integration) -> None:
|
8
|
+
super().__init__(name="github", integration=integration)
|
9
|
+
|
10
|
+
def _get_headers(self):
|
11
|
+
if not self.integration:
|
12
|
+
raise ValueError("Integration not configured")
|
13
|
+
credentials = self.integration.get_credentials()
|
14
|
+
if not credentials:
|
15
|
+
logger.warning("No credentials found")
|
16
|
+
action = self.integration.authorize()
|
17
|
+
raise NotAuthorizedError(action)
|
18
|
+
if "headers" in credentials:
|
19
|
+
return credentials["headers"]
|
20
|
+
return {
|
21
|
+
"Authorization": f"Bearer {credentials['access_token']}",
|
22
|
+
"Accept": "application/vnd.github.v3+json"
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
def star_repository(self, repo_full_name: str) -> str:
|
27
|
+
"""Star a GitHub repository
|
28
|
+
|
29
|
+
Args:
|
30
|
+
repo_full_name: The full name of the repository (e.g. 'owner/repo')
|
31
|
+
|
32
|
+
Returns:
|
33
|
+
|
34
|
+
A confirmation message
|
35
|
+
"""
|
36
|
+
try:
|
37
|
+
url = f"https://api.github.com/user/starred/{repo_full_name}"
|
38
|
+
response = self._put(url, data={})
|
39
|
+
|
40
|
+
if response.status_code == 204:
|
41
|
+
return f"Successfully starred repository {repo_full_name}"
|
42
|
+
elif response.status_code == 404:
|
43
|
+
return f"Repository {repo_full_name} not found"
|
44
|
+
else:
|
45
|
+
logger.error(response.text)
|
46
|
+
return f"Error starring repository: {response.text}"
|
47
|
+
except NotAuthorizedError as e:
|
48
|
+
return e.message
|
49
|
+
except Exception as e:
|
50
|
+
logger.error(e)
|
51
|
+
raise e
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
def list_tools(self):
|
52
56
|
return [self.star_repository]
|
@@ -1,74 +1,74 @@
|
|
1
|
-
from agentr.application import APIApplication
|
2
|
-
from agentr.integration import Integration
|
3
|
-
from loguru import logger
|
4
|
-
from datetime import datetime, timedelta
|
5
|
-
|
6
|
-
class GoogleCalendarApp(APIApplication):
|
7
|
-
def __init__(self, integration: Integration) -> None:
|
8
|
-
super().__init__(name="google-calendar", integration=integration)
|
9
|
-
|
10
|
-
def _get_headers(self):
|
11
|
-
credentials = self.integration.get_credentials()
|
12
|
-
if "headers" in credentials:
|
13
|
-
return credentials["headers"]
|
14
|
-
return {
|
15
|
-
"Authorization": f"Bearer {credentials['access_token']}",
|
16
|
-
"Accept": "application/json"
|
17
|
-
}
|
18
|
-
|
19
|
-
|
20
|
-
def get_today_events(self) -> str:
|
21
|
-
"""Get events from your Google Calendar for today
|
22
|
-
|
23
|
-
Returns:
|
24
|
-
A formatted list of today's events or an error message
|
25
|
-
"""
|
26
|
-
if not self.validate():
|
27
|
-
logger.warning("Connection not configured correctly")
|
28
|
-
return self.authorize()
|
29
|
-
|
30
|
-
try:
|
31
|
-
# Get today's date in ISO format
|
32
|
-
today = datetime.now().date()
|
33
|
-
tomorrow = today + timedelta(days=1)
|
34
|
-
|
35
|
-
# Format dates for API
|
36
|
-
time_min = f"{today.isoformat()}T00:00:00Z"
|
37
|
-
time_max = f"{tomorrow.isoformat()}T00:00:00Z"
|
38
|
-
|
39
|
-
url = "https://www.googleapis.com/calendar/v3/calendars/primary/events"
|
40
|
-
params = {
|
41
|
-
"timeMin": time_min,
|
42
|
-
"timeMax": time_max,
|
43
|
-
"singleEvents": "true",
|
44
|
-
"orderBy": "startTime"
|
45
|
-
}
|
46
|
-
|
47
|
-
response = self._get(url, params=params)
|
48
|
-
|
49
|
-
if response.status_code == 200:
|
50
|
-
events = response.json().get("items", [])
|
51
|
-
if not events:
|
52
|
-
return "No events scheduled for today."
|
53
|
-
|
54
|
-
result = "Today's events:\n\n"
|
55
|
-
for event in events:
|
56
|
-
start = event.get("start", {})
|
57
|
-
start_time = start.get("dateTime", start.get("date", "All day"))
|
58
|
-
if "T" in start_time: # Format datetime
|
59
|
-
start_dt = datetime.fromisoformat(start_time.replace("Z", "+00:00"))
|
60
|
-
start_time = start_dt.strftime("%I:%M %p")
|
61
|
-
|
62
|
-
summary = event.get("summary", "Untitled event")
|
63
|
-
result += f"- {start_time}: {summary}\n"
|
64
|
-
|
65
|
-
return result
|
66
|
-
else:
|
67
|
-
logger.error(response.text)
|
68
|
-
return f"Error retrieving calendar events: {response.text}"
|
69
|
-
except Exception as e:
|
70
|
-
logger.error(e)
|
71
|
-
return f"Error retrieving calendar events: {e}"
|
72
|
-
|
73
|
-
def list_tools(self):
|
1
|
+
from agentr.application import APIApplication
|
2
|
+
from agentr.integration import Integration
|
3
|
+
from loguru import logger
|
4
|
+
from datetime import datetime, timedelta
|
5
|
+
|
6
|
+
class GoogleCalendarApp(APIApplication):
|
7
|
+
def __init__(self, integration: Integration) -> None:
|
8
|
+
super().__init__(name="google-calendar", integration=integration)
|
9
|
+
|
10
|
+
def _get_headers(self):
|
11
|
+
credentials = self.integration.get_credentials()
|
12
|
+
if "headers" in credentials:
|
13
|
+
return credentials["headers"]
|
14
|
+
return {
|
15
|
+
"Authorization": f"Bearer {credentials['access_token']}",
|
16
|
+
"Accept": "application/json"
|
17
|
+
}
|
18
|
+
|
19
|
+
|
20
|
+
def get_today_events(self) -> str:
|
21
|
+
"""Get events from your Google Calendar for today
|
22
|
+
|
23
|
+
Returns:
|
24
|
+
A formatted list of today's events or an error message
|
25
|
+
"""
|
26
|
+
if not self.validate():
|
27
|
+
logger.warning("Connection not configured correctly")
|
28
|
+
return self.authorize()
|
29
|
+
|
30
|
+
try:
|
31
|
+
# Get today's date in ISO format
|
32
|
+
today = datetime.now().date()
|
33
|
+
tomorrow = today + timedelta(days=1)
|
34
|
+
|
35
|
+
# Format dates for API
|
36
|
+
time_min = f"{today.isoformat()}T00:00:00Z"
|
37
|
+
time_max = f"{tomorrow.isoformat()}T00:00:00Z"
|
38
|
+
|
39
|
+
url = "https://www.googleapis.com/calendar/v3/calendars/primary/events"
|
40
|
+
params = {
|
41
|
+
"timeMin": time_min,
|
42
|
+
"timeMax": time_max,
|
43
|
+
"singleEvents": "true",
|
44
|
+
"orderBy": "startTime"
|
45
|
+
}
|
46
|
+
|
47
|
+
response = self._get(url, params=params)
|
48
|
+
|
49
|
+
if response.status_code == 200:
|
50
|
+
events = response.json().get("items", [])
|
51
|
+
if not events:
|
52
|
+
return "No events scheduled for today."
|
53
|
+
|
54
|
+
result = "Today's events:\n\n"
|
55
|
+
for event in events:
|
56
|
+
start = event.get("start", {})
|
57
|
+
start_time = start.get("dateTime", start.get("date", "All day"))
|
58
|
+
if "T" in start_time: # Format datetime
|
59
|
+
start_dt = datetime.fromisoformat(start_time.replace("Z", "+00:00"))
|
60
|
+
start_time = start_dt.strftime("%I:%M %p")
|
61
|
+
|
62
|
+
summary = event.get("summary", "Untitled event")
|
63
|
+
result += f"- {start_time}: {summary}\n"
|
64
|
+
|
65
|
+
return result
|
66
|
+
else:
|
67
|
+
logger.error(response.text)
|
68
|
+
return f"Error retrieving calendar events: {response.text}"
|
69
|
+
except Exception as e:
|
70
|
+
logger.error(e)
|
71
|
+
return f"Error retrieving calendar events: {e}"
|
72
|
+
|
73
|
+
def list_tools(self):
|
74
74
|
return [self.get_today_events]
|
@@ -1,68 +1,68 @@
|
|
1
|
-
from agentr.application import APIApplication
|
2
|
-
from agentr.integration import Integration
|
3
|
-
from loguru import logger
|
4
|
-
import base64
|
5
|
-
from email.message import EmailMessage
|
6
|
-
|
7
|
-
class GmailApp(APIApplication):
|
8
|
-
def __init__(self, integration: Integration) -> None:
|
9
|
-
super().__init__(name="gmail", integration=integration)
|
10
|
-
|
11
|
-
def _get_headers(self):
|
12
|
-
credentials = self.integration.get_credentials()
|
13
|
-
if "headers" in credentials:
|
14
|
-
return credentials["headers"]
|
15
|
-
return {
|
16
|
-
"Authorization": f"Bearer {credentials['access_token']}",
|
17
|
-
'Content-Type': 'application/json'
|
18
|
-
}
|
19
|
-
|
20
|
-
def send_email(self, to: str, subject: str, body: str) -> str:
|
21
|
-
"""Send an email
|
22
|
-
|
23
|
-
Args:
|
24
|
-
to: The email address of the recipient
|
25
|
-
subject: The subject of the email
|
26
|
-
body: The body of the email
|
27
|
-
|
28
|
-
Returns:
|
29
|
-
|
30
|
-
A confirmation message
|
31
|
-
"""
|
32
|
-
if not self.validate():
|
33
|
-
logger.warning("Connection not configured correctly")
|
34
|
-
return self.authorize()
|
35
|
-
try:
|
36
|
-
url = "https://gmail.googleapis.com/gmail/v1/users/me/messages/send"
|
37
|
-
|
38
|
-
# Create email in base64 encoded format
|
39
|
-
email_message = {
|
40
|
-
"raw": self._create_message(to, subject, body)
|
41
|
-
}
|
42
|
-
logger.info(email_message)
|
43
|
-
|
44
|
-
# Use json parameter instead of data to properly format JSON
|
45
|
-
response = self._post(url, email_message)
|
46
|
-
|
47
|
-
if response.status_code == 200:
|
48
|
-
return f"Successfully sent email to {to}"
|
49
|
-
else:
|
50
|
-
logger.error(response.text)
|
51
|
-
return f"Error sending email: {response.text}"
|
52
|
-
except Exception as e:
|
53
|
-
logger.error(e)
|
54
|
-
return f"Error sending email: {e}"
|
55
|
-
|
56
|
-
def _create_message(self, to, subject, body):
|
57
|
-
message = EmailMessage()
|
58
|
-
message['to'] = to
|
59
|
-
message['from'] = "manojbajaj95@gmail.com"
|
60
|
-
message['subject'] = subject
|
61
|
-
message.set_content(body)
|
62
|
-
|
63
|
-
# Encode as base64 string
|
64
|
-
raw = base64.urlsafe_b64encode(message.as_bytes()).decode()
|
65
|
-
return raw
|
66
|
-
|
67
|
-
def list_tools(self):
|
1
|
+
from agentr.application import APIApplication
|
2
|
+
from agentr.integration import Integration
|
3
|
+
from loguru import logger
|
4
|
+
import base64
|
5
|
+
from email.message import EmailMessage
|
6
|
+
|
7
|
+
class GmailApp(APIApplication):
|
8
|
+
def __init__(self, integration: Integration) -> None:
|
9
|
+
super().__init__(name="gmail", integration=integration)
|
10
|
+
|
11
|
+
def _get_headers(self):
|
12
|
+
credentials = self.integration.get_credentials()
|
13
|
+
if "headers" in credentials:
|
14
|
+
return credentials["headers"]
|
15
|
+
return {
|
16
|
+
"Authorization": f"Bearer {credentials['access_token']}",
|
17
|
+
'Content-Type': 'application/json'
|
18
|
+
}
|
19
|
+
|
20
|
+
def send_email(self, to: str, subject: str, body: str) -> str:
|
21
|
+
"""Send an email
|
22
|
+
|
23
|
+
Args:
|
24
|
+
to: The email address of the recipient
|
25
|
+
subject: The subject of the email
|
26
|
+
body: The body of the email
|
27
|
+
|
28
|
+
Returns:
|
29
|
+
|
30
|
+
A confirmation message
|
31
|
+
"""
|
32
|
+
if not self.validate():
|
33
|
+
logger.warning("Connection not configured correctly")
|
34
|
+
return self.authorize()
|
35
|
+
try:
|
36
|
+
url = "https://gmail.googleapis.com/gmail/v1/users/me/messages/send"
|
37
|
+
|
38
|
+
# Create email in base64 encoded format
|
39
|
+
email_message = {
|
40
|
+
"raw": self._create_message(to, subject, body)
|
41
|
+
}
|
42
|
+
logger.info(email_message)
|
43
|
+
|
44
|
+
# Use json parameter instead of data to properly format JSON
|
45
|
+
response = self._post(url, email_message)
|
46
|
+
|
47
|
+
if response.status_code == 200:
|
48
|
+
return f"Successfully sent email to {to}"
|
49
|
+
else:
|
50
|
+
logger.error(response.text)
|
51
|
+
return f"Error sending email: {response.text}"
|
52
|
+
except Exception as e:
|
53
|
+
logger.error(e)
|
54
|
+
return f"Error sending email: {e}"
|
55
|
+
|
56
|
+
def _create_message(self, to, subject, body):
|
57
|
+
message = EmailMessage()
|
58
|
+
message['to'] = to
|
59
|
+
message['from'] = "manojbajaj95@gmail.com"
|
60
|
+
message['subject'] = subject
|
61
|
+
message.set_content(body)
|
62
|
+
|
63
|
+
# Encode as base64 string
|
64
|
+
raw = base64.urlsafe_b64encode(message.as_bytes()).decode()
|
65
|
+
return raw
|
66
|
+
|
67
|
+
def list_tools(self):
|
68
68
|
return [self.send_email]
|
@@ -1,29 +1,29 @@
|
|
1
|
-
from agentr.application import APIApplication
|
2
|
-
from agentr.integration import Integration
|
3
|
-
|
4
|
-
class RedditApp(APIApplication):
|
5
|
-
def __init__(self, integration: Integration) -> None:
|
6
|
-
super().__init__(name="reddit", integration=integration)
|
7
|
-
|
8
|
-
def _get_headers(self):
|
9
|
-
credentials = self.integration.get_credentials()
|
10
|
-
if "headers" in credentials:
|
11
|
-
return credentials["headers"]
|
12
|
-
return {
|
13
|
-
"Authorization": f"Bearer {credentials['access_token']}",
|
14
|
-
}
|
15
|
-
|
16
|
-
def get_subreddit_posts(self, subreddit: str) -> str:
|
17
|
-
"""Get the latest posts from a subreddit
|
18
|
-
|
19
|
-
Args:
|
20
|
-
subreddit: The subreddit to get posts from
|
21
|
-
|
22
|
-
Returns:
|
23
|
-
A list of posts from the subreddit
|
24
|
-
"""
|
25
|
-
|
26
|
-
|
27
|
-
def list_tools(self):
|
28
|
-
return []
|
29
|
-
|
1
|
+
from agentr.application import APIApplication
|
2
|
+
from agentr.integration import Integration
|
3
|
+
|
4
|
+
class RedditApp(APIApplication):
|
5
|
+
def __init__(self, integration: Integration) -> None:
|
6
|
+
super().__init__(name="reddit", integration=integration)
|
7
|
+
|
8
|
+
def _get_headers(self):
|
9
|
+
credentials = self.integration.get_credentials()
|
10
|
+
if "headers" in credentials:
|
11
|
+
return credentials["headers"]
|
12
|
+
return {
|
13
|
+
"Authorization": f"Bearer {credentials['access_token']}",
|
14
|
+
}
|
15
|
+
|
16
|
+
def get_subreddit_posts(self, subreddit: str) -> str:
|
17
|
+
"""Get the latest posts from a subreddit
|
18
|
+
|
19
|
+
Args:
|
20
|
+
subreddit: The subreddit to get posts from
|
21
|
+
|
22
|
+
Returns:
|
23
|
+
A list of posts from the subreddit
|
24
|
+
"""
|
25
|
+
|
26
|
+
|
27
|
+
def list_tools(self):
|
28
|
+
return []
|
29
|
+
|
@@ -1,43 +1,43 @@
|
|
1
|
-
from agentr.application import APIApplication
|
2
|
-
from agentr.integration import Integration
|
3
|
-
|
4
|
-
class ResendApp(APIApplication):
|
5
|
-
def __init__(self, integration: Integration) -> None:
|
6
|
-
super().__init__(name="resend", integration=integration)
|
7
|
-
|
8
|
-
def _get_headers(self):
|
9
|
-
credentials = self.integration.get_credentials()
|
10
|
-
if not credentials:
|
11
|
-
raise ValueError("No credentials found")
|
12
|
-
return {
|
13
|
-
"Authorization": f"Bearer {credentials['api_key']}",
|
14
|
-
}
|
15
|
-
|
16
|
-
def send_email(self, to: str, subject: str, content: str) -> str:
|
17
|
-
"""Send an email using the Resend API
|
18
|
-
|
19
|
-
Args:
|
20
|
-
to: The email address to send the email to
|
21
|
-
subject: The subject of the email
|
22
|
-
content: The content of the email
|
23
|
-
|
24
|
-
Returns:
|
25
|
-
A message indicating that the email was sent successfully
|
26
|
-
"""
|
27
|
-
credentials = self.integration.get_credentials()
|
28
|
-
if not credentials:
|
29
|
-
raise ValueError("No credentials found")
|
30
|
-
from_email = credentials.get("from_email", "Manoj <manoj@agentr.dev>")
|
31
|
-
url = "https://api.resend.com/emails"
|
32
|
-
body = {
|
33
|
-
"from": from_email,
|
34
|
-
"to": [to],
|
35
|
-
"subject": subject,
|
36
|
-
"text": content
|
37
|
-
}
|
38
|
-
self._post(url, body)
|
39
|
-
return "Sent Successfully"
|
40
|
-
|
41
|
-
def list_tools(self):
|
42
|
-
return [self.send_email]
|
43
|
-
|
1
|
+
from agentr.application import APIApplication
|
2
|
+
from agentr.integration import Integration
|
3
|
+
|
4
|
+
class ResendApp(APIApplication):
|
5
|
+
def __init__(self, integration: Integration) -> None:
|
6
|
+
super().__init__(name="resend", integration=integration)
|
7
|
+
|
8
|
+
def _get_headers(self):
|
9
|
+
credentials = self.integration.get_credentials()
|
10
|
+
if not credentials:
|
11
|
+
raise ValueError("No credentials found")
|
12
|
+
return {
|
13
|
+
"Authorization": f"Bearer {credentials['api_key']}",
|
14
|
+
}
|
15
|
+
|
16
|
+
def send_email(self, to: str, subject: str, content: str) -> str:
|
17
|
+
"""Send an email using the Resend API
|
18
|
+
|
19
|
+
Args:
|
20
|
+
to: The email address to send the email to
|
21
|
+
subject: The subject of the email
|
22
|
+
content: The content of the email
|
23
|
+
|
24
|
+
Returns:
|
25
|
+
A message indicating that the email was sent successfully
|
26
|
+
"""
|
27
|
+
credentials = self.integration.get_credentials()
|
28
|
+
if not credentials:
|
29
|
+
raise ValueError("No credentials found")
|
30
|
+
from_email = credentials.get("from_email", "Manoj <manoj@agentr.dev>")
|
31
|
+
url = "https://api.resend.com/emails"
|
32
|
+
body = {
|
33
|
+
"from": from_email,
|
34
|
+
"to": [to],
|
35
|
+
"subject": subject,
|
36
|
+
"text": content
|
37
|
+
}
|
38
|
+
self._post(url, body)
|
39
|
+
return "Sent Successfully"
|
40
|
+
|
41
|
+
def list_tools(self):
|
42
|
+
return [self.send_email]
|
43
|
+
|