-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into agent_websocket
- Loading branch information
Showing
32 changed files
with
751 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Backend Service Docker Image Builder | ||
|
||
on: | ||
push: | ||
branches: ["dev"] | ||
pull_request: | ||
branches: ["dev"] | ||
|
||
jobs: | ||
build_on_pr: | ||
if: github.event_name == 'pull_request' | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
steps: | ||
- name: Checkout code with submodules | ||
uses: actions/checkout@v2 | ||
with: | ||
submodules: "recursive" | ||
|
||
- name: Setup Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Build Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
push: false | ||
tags: backend:latest | ||
context: autonomous_agent_api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
name: Backend Service Testing ( Pytest ) | ||
|
||
on: | ||
push: | ||
branches: ["master", "dev"] | ||
pull_request: | ||
branches: ["dev"] | ||
|
||
jobs: | ||
run_backend_tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Enable Access for Branch for Workflow | ||
uses: actions/checkout@v2 | ||
with: | ||
submodules: "recursive" | ||
|
||
- name: setup python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.12.2 | ||
|
||
- name: Install Poetry | ||
working-directory: autonomous_agent_api | ||
run: pip install poetry==1.8.2 | ||
|
||
- name: Install Dependencies | ||
working-directory: autonomous_agent_api | ||
run: | | ||
poetry install | ||
poetry run prisma generate | ||
- name: Run test cases | ||
working-directory: autonomous_agent_api | ||
env: | ||
DATABASE_URL : "" | ||
run: poetry run pytest -m github_actions | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
autonomous_agent_api/backend/app/controllers/trigger_router.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from http import HTTPStatus | ||
from typing import List | ||
|
||
from classy_fastapi import Routable, get, post, put, delete | ||
from fastapi import HTTPException | ||
|
||
from backend.app.models import TriggerResponse | ||
from backend.app.models import TriggerCreateDTO | ||
from backend.app.services.trigger_service import TriggerService | ||
from backend.dependency import get_trigger_service | ||
|
||
|
||
class TriggerRouter(Routable): | ||
def __init__(self, trigger_service: TriggerService = get_trigger_service(), *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.trigger_service = trigger_service | ||
|
||
@post("/agents/{agent_id}/triggers", status_code=HTTPStatus.CREATED) | ||
async def create_trigger(self, agent_id: str, trigger_data: TriggerCreateDTO): | ||
trigger = await self.trigger_service.create_trigger(agent_id, trigger_data) | ||
return trigger | ||
|
||
@get("/agents/{agent_id}/triggers", response_model=List[TriggerResponse]) | ||
async def list_triggers_by_agent_id(self, agent_id: str): | ||
triggers = await self.trigger_service.list_triggers_by_agent_id(agent_id) | ||
return triggers | ||
|
||
@get("/triggers/{trigger_id}", response_model=TriggerResponse) | ||
async def list_trigger_by_trigger_id(self, trigger_id: str): | ||
trigger = await self.trigger_service.list_trigger_by_id(trigger_id) | ||
return trigger | ||
|
||
@put("/triggers/{trigger_id}", response_model=TriggerResponse) | ||
async def update_trigger_by_trigger_id(self, trigger_id: str, trigger_data: TriggerCreateDTO): | ||
trigger = await self.trigger_service.update_trigger_by_id(trigger_id, trigger_data) | ||
return trigger | ||
|
||
@delete("/triggers/{trigger_id}", status_code=HTTPStatus.NO_CONTENT) | ||
async def delete_trigger_by_trigger_id(self, trigger_id: str): | ||
success = await self.trigger_service.delete_by_id(trigger_id) | ||
if not success: | ||
raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail="Trigger not found") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
"""Application implementation - models.""" | ||
# backend/app/models/__init__.py | ||
|
||
from .trigger.resposne_dto import TriggerResponse | ||
from .trigger.trigger_dto import TriggerCreateDTO, TopicTriggerDTO, CronTriggerDTO |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,3 @@ class AgentResponse(BaseModel): | |
id: str | ||
name: str | ||
action: List[str] = [] | ||
triggers: List[str] = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
17 changes: 17 additions & 0 deletions
17
autonomous_agent_api/backend/app/models/trigger/resposne_dto.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from pydantic import BaseModel | ||
from typing import Union | ||
|
||
from backend.app.models.trigger.trigger_dto import CronTriggerDTO, TopicTriggerDTO | ||
|
||
|
||
class TriggerResponse(BaseModel): | ||
id: str | ||
agent_id: str | ||
type: str | ||
data: Union[CronTriggerDTO, TopicTriggerDTO] | ||
|
||
|
||
# class TriggerResponse_agent_id(BaseModel): | ||
# agentId: str | ||
# type: str | ||
# data: Union[CronTriggerDTO, TopicTriggerDTO] |
36 changes: 36 additions & 0 deletions
36
autonomous_agent_api/backend/app/models/trigger/trigger_dto.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from fastapi import HTTPException | ||
from typing import Union | ||
from pydantic import BaseModel | ||
from croniter import croniter | ||
|
||
|
||
class CronTriggerDTO(BaseModel): | ||
frequency: str | ||
probability: float | ||
|
||
|
||
class TopicTriggerDTO(BaseModel): | ||
topic: str | ||
|
||
|
||
class TriggerCreateDTO(BaseModel): | ||
type: str | ||
data: Union[CronTriggerDTO, TopicTriggerDTO] | ||
|
||
|
||
# validation for cron expression | ||
async def validate_type_CRON(cron_expression: str): | ||
try: | ||
croniter(cron_expression) | ||
except ValueError as e: | ||
raise HTTPException(400, f"Invalid CRON expression: {str(e)}") | ||
|
||
|
||
# validation for Topic | ||
async def validate_type_TOPIC(value: str): | ||
try: | ||
if value.isnumeric(): | ||
raise HTTPException(400, f"Invalid topic :") | ||
|
||
except ValueError as e: | ||
return f"Validation error: {e}" |
Oops, something went wrong.