Skip to content

Commit 8c0f66b

Browse files
committed
Merge branch 'main' into AGE-3403-/-add-response-type-feature-back-to-the-system
2 parents ea91c4f + e5c5864 commit 8c0f66b

File tree

283 files changed

+5428
-1412
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

283 files changed

+5428
-1412
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: 01 - create release branch
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release-type:
7+
description: "release type"
8+
required: true
9+
default: "patch"
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
16+
jobs:
17+
bump-version:
18+
name: Bump version and create PR
19+
runs-on: ubuntu-latest
20+
outputs:
21+
new_version: ${{ steps.bump_versions.outputs.NEW_VERSION }}
22+
versions_match: ${{ steps.bump_versions.outputs.VERSIONS_MATCH }}
23+
pr_number: ${{ steps.create-pr.outputs.pull-request-number }}
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
with:
29+
ref: ${{ github.ref }}
30+
31+
- name: Install pnpm
32+
uses: pnpm/action-setup@v4
33+
with:
34+
version: 10
35+
36+
- name: Set up Node.js
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: 20
40+
41+
- name: Set up Python
42+
uses: actions/setup-python@v5
43+
with:
44+
python-version: 3.11
45+
46+
- name: Install Poetry
47+
run: |
48+
curl -sSL https://install.python-poetry.org | python3 -
49+
50+
- name: Bump versions and compare
51+
id: bump_versions
52+
run: |
53+
BUMP_TYPE=${{ inputs.release-type }}
54+
echo "Bumping versions to $BUMP_TYPE"
55+
56+
npm install semver -g
57+
58+
cd web
59+
pnpm version $BUMP_TYPE
60+
WEB_VERSION=$(pnpm pkg get version | tr -d '"')
61+
62+
cd ee
63+
current_version=$(pnpm pkg get version | awk -F': ' '/[0-9]+\.[0-9]+\.[0-9]+/ {print $2}' | tr -d '"')
64+
new_version=$(npx semver "$current_version" -i $BUMP_TYPE)
65+
pnpm pkg set version="$new_version"
66+
EE_VERSION=$new_version
67+
cd ..
68+
69+
cd oss
70+
current_version=$(pnpm pkg get version | awk -F': ' '/[0-9]+\.[0-9]+\.[0-9]+/ {print $2}' | tr -d '"')
71+
new_version=$(npx semver "$current_version" -i $BUMP_TYPE)
72+
pnpm pkg set version="$new_version"
73+
OSS_VERSION=$new_version
74+
cd ..
75+
76+
cd ..
77+
78+
cd sdk
79+
poetry version $BUMP_TYPE
80+
SDK_VERSION=$(poetry version -s)
81+
cd ..
82+
83+
cd api
84+
poetry version $BUMP_TYPE
85+
API_VERSION=$(poetry version -s)
86+
cd ..
87+
88+
WEB_VERSION=$(echo "$WEB_VERSION" | tr -d '[:space:]')
89+
EE_VERSION=$(echo "$EE_VERSION" | tr -d '[:space:]')
90+
OSS_VERSION=$(echo "$OSS_VERSION" | tr -d '[:space:]')
91+
SDK_VERSION=$(echo "$SDK_VERSION" | tr -d '[:space:]')
92+
API_VERSION=$(echo "$API_VERSION" | tr -d '[:space:]')
93+
94+
echo "WEB_VERSION='$WEB_VERSION'"
95+
echo "EE_VERSION='$EE_VERSION'"
96+
echo "OSS_VERSION='$OSS_VERSION'"
97+
echo "SDK_VERSION='$SDK_VERSION'"
98+
echo "API_VERSION='$API_VERSION'"
99+
100+
if [ "$EE_VERSION" = "$OSS_VERSION" ] && [ "$OSS_VERSION" = "$WEB_VERSION" ] && [ "$WEB_VERSION" = "$SDK_VERSION" ] && [ "$SDK_VERSION" = "$API_VERSION" ]; then
101+
echo "VERSIONS_MATCH=true" >> $GITHUB_OUTPUT
102+
echo "NEW_VERSION=$WEB_VERSION" >> $GITHUB_OUTPUT
103+
else
104+
echo "VERSIONS_MATCH=false" >> $GITHUB_OUTPUT
105+
fi
106+
107+
- name: Create Pull Request
108+
if: steps.bump_versions.outputs.VERSIONS_MATCH == 'true'
109+
uses: peter-evans/create-pull-request@v6
110+
with:
111+
commit-message: v${{ steps.bump_versions.outputs.NEW_VERSION }}
112+
author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
113+
branch: release/v${{ steps.bump_versions.outputs.NEW_VERSION }}
114+
delete-branch: true
115+
title: "v${{ steps.bump_versions.outputs.NEW_VERSION }}"
116+
body: |
117+
New version v${{ steps.bump_versions.outputs.NEW_VERSION }} in
118+
- (web)
119+
- web/oss
120+
- web/ee
121+
- sdk
122+
- api
123+
124+
- name: Fail if versions don't match
125+
if: steps.bump_versions.outputs.VERSIONS_MATCH != 'true'
126+
run: |
127+
echo "Versions in the three folders do not match. Please check and update manually."
128+
exit 1
129+
130+
create-tag:
131+
needs: bump-version
132+
runs-on: ubuntu-latest
133+
134+
steps:
135+
- name: Checkout repository
136+
uses: actions/checkout@v4
137+
138+
- name: Create and push tag
139+
run: |
140+
git config --global user.name "${{ github.actor }}"
141+
git config --global user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
142+
git tag -a "v${{ needs.bump-version.outputs.new_version }}" -m "Version ${{ needs.bump-version.outputs.new_version }}"
143+
git push origin "v${{ needs.bump-version.outputs.new_version }}"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: 02 - check python formatting
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
paths:
9+
- 'api/**'
10+
- 'sdk/**'
11+
workflow_dispatch:
12+
13+
jobs:
14+
ruff:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.11'
23+
24+
- name: Install Ruff
25+
run: pip install ruff==0.14.0
26+
27+
- name: Run Ruff formatting check
28+
run: ruff format --check api sdk
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: 03 - check python linting
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
paths:
9+
- 'api/**'
10+
- 'sdk/**'
11+
workflow_dispatch:
12+
13+
jobs:
14+
ruff:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.11'
23+
24+
- name: Install Ruff
25+
run: pip install ruff==0.14.0
26+
27+
- name: Run Ruff linting check
28+
run: ruff check api sdk

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ sdk/agenta/templates/agenta.py
4747
web/ee/public/__env.js
4848
web/oss/public/__env.js
4949

50-
web/oss/tests/datalayer/results
50+
web/oss/tests/datalayer/results
51+
.*

.gitleaks.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ regexes = [
2626
'''YOUR_API_KEY''',
2727
'''_SECRET_KEY''',
2828
# ------------------------------------------------------------ PUBLIC KEYS
29-
'''phc_hmVSxIjTW1REBHXgj2aw4HW9X6CXb6FzerBgP9XenC7''',
29+
'''phc_hmVSxIjTW1REBHXgj2aw4HW9X6CXb6FzerBgP9XenC7''', # POSTHOG
30+
'''phc_3urGRy5TL1HhaHnRYL0JSHxJxigRVackhphHtozUmdp''', # POSTHOG
31+
'''18ab633e81d706cbda7c78d25d0fe763''', # ALGOLIA
3032
# ----------------------------------------------------------------------------
3133
]
3234

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<picture >
55
<source width="275" media="(prefers-color-scheme: dark)" srcset="https://github.com/user-attachments/assets/97e31bfc-b1fc-4d19-b443-5aedf6029017" >
66
<source width="275" media="(prefers-color-scheme: light)" srcset="https://github.com/user-attachments/assets/fdc5f23f-2095-4cfc-9511-14c6851c1262" >
7-
<img alt="Shows the logo of agenta" src="https://github.com/Agenta-AI/agenta/assets/4510758/68e055d4-d7b8-4943-992f-761558c64253" >
7+
<img alt="Shows the logo of agenta" src="https://github.com/user-attachments/assets/fdc5f23f-2095-4cfc-9511-14c6851c1262" >
88
</picture>
99
</a>
1010

api/ee/databases/postgres/migrations/core/data_migrations/workspaces.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def create_default_project_for_workspaces(session: Connection):
5656
for workspace in workspaces:
5757
# Create a new default project for each workspace
5858
get_or_create_workspace_default_project(
59-
session=session, workspace=workspace # type: ignore
59+
session=session,
60+
workspace=workspace, # type: ignore
6061
)
6162

6263
# Commit the changes for the current batch

api/ee/databases/postgres/migrations/core/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):
7373

7474
async with engine.connect() as connection:
7575
try:
76-
result = await connection.execute(text("SELECT version_num FROM alembic_version")) # type: ignore
76+
result = await connection.execute(
77+
text("SELECT version_num FROM alembic_version")
78+
) # type: ignore
7779
except (asyncpg.exceptions.UndefinedTableError, ProgrammingError):
7880
# Note: If the alembic_version table does not exist, it will result in raising an UndefinedTableError exception.
7981
# We need to suppress the error and return a list with the alembic_version table name to inform the user that there is a pending migration \
@@ -83,9 +85,9 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):
8385
return "alembic_version"
8486

8587
migration_heads = [row[0] for row in result.fetchall()]
86-
assert (
87-
len(migration_heads) == 1
88-
), "There can only be one migration head stored in the database."
88+
assert len(migration_heads) == 1, (
89+
"There can only be one migration head stored in the database."
90+
)
8991
return migration_heads[0]
9092

9193

api/ee/databases/postgres/migrations/tracing/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):
6666

6767
async with engine.connect() as connection:
6868
try:
69-
result = await connection.execute(text("SELECT version_num FROM alembic_version")) # type: ignore
69+
result = await connection.execute(
70+
text("SELECT version_num FROM alembic_version")
71+
) # type: ignore
7072
except (asyncpg.exceptions.UndefinedTableError, ProgrammingError):
7173
# Note: If the alembic_version table does not exist, it will result in raising an UndefinedTableError exception.
7274
# We need to suppress the error and return a list with the alembic_version table name to inform the user that there is a pending migration \
@@ -76,9 +78,9 @@ async def get_current_migration_head_from_db(engine: AsyncEngine):
7678
return "alembic_version"
7779

7880
migration_heads = [row[0] for row in result.fetchall()]
79-
assert (
80-
len(migration_heads) == 1
81-
), "There can only be one migration head stored in the database."
81+
assert len(migration_heads) == 1, (
82+
"There can only be one migration head stored in the database."
83+
)
8284
return migration_heads[0]
8385

8486

api/ee/src/apis/fastapi/billing/router.py

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
stripe.api_key = environ.get("STRIPE_API_KEY")
3737

38-
MAC_ADDRESS = ":".join(f"{(getnode() >> ele) & 0xff:02x}" for ele in range(40, -1, -8))
38+
MAC_ADDRESS = ":".join(f"{(getnode() >> ele) & 0xFF:02x}" for ele in range(40, -1, -8))
3939
STRIPE_WEBHOOK_SECRET = environ.get("STRIPE_WEBHOOK_SECRET")
4040
STRIPE_TARGET = environ.get("STRIPE_TARGET") or MAC_ADDRESS
4141
AGENTA_PRICING = loads(environ.get("AGENTA_PRICING") or "{}")
@@ -807,15 +807,66 @@ async def fetch_usage(
807807
async def report_usage(
808808
self,
809809
):
810+
log.info("[report] [endpoint] Trigger")
811+
810812
try:
811-
await self.subscription_service.meters_service.report()
812-
except Exception as e:
813-
raise HTTPException(status_code=500, detail="unexpected error") from e
813+
report_ongoing = await get_cache(
814+
namespace="meters:report",
815+
key={},
816+
)
814817

815-
return JSONResponse(
816-
status_code=status.HTTP_200_OK,
817-
content={"status": "success"},
818-
)
818+
if report_ongoing:
819+
log.info("[report] [endpoint] Skipped (ongoing)")
820+
return JSONResponse(
821+
status_code=status.HTTP_200_OK,
822+
content={"status": "skipped"},
823+
)
824+
825+
# await set_cache(
826+
# namespace="meters:report",
827+
# key={},
828+
# value=True,
829+
# ttl=60 * 60, # 1 hour
830+
# )
831+
log.info("[report] [endpoint] Lock acquired")
832+
833+
try:
834+
log.info("[report] [endpoint] Reporting usage started")
835+
await self.subscription_service.meters_service.report()
836+
log.info("[report] [endpoint] Reporting usage completed")
837+
838+
return JSONResponse(
839+
status_code=status.HTTP_200_OK,
840+
content={"status": "success"},
841+
)
842+
843+
except Exception:
844+
log.error(
845+
"[report] [endpoint] Report failed:",
846+
exc_info=True,
847+
)
848+
return JSONResponse(
849+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
850+
content={"status": "error", "message": "Report failed"},
851+
)
852+
853+
finally:
854+
await invalidate_cache(
855+
namespace="meters:report",
856+
key={},
857+
)
858+
log.info("[report] [endpoint] Lock released")
859+
860+
except Exception:
861+
# Catch-all for any errors, including cache errors
862+
log.error(
863+
"[report] [endpoint] Fatal error:",
864+
exc_info=True,
865+
)
866+
return JSONResponse(
867+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
868+
content={"status": "error", "message": "Fatal error"},
869+
)
819870

820871
# ROUTES
821872

0 commit comments

Comments
 (0)