Skip to content

Commit 373fe34

Browse files
committed
fix: clean query processor return types, remove deprecated fields, better handling for few errors
1 parent aa718a5 commit 373fe34

File tree

7 files changed

+34
-54
lines changed

7 files changed

+34
-54
lines changed

src/server/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def validate_input_text(cls, v: str) -> str:
5555
@classmethod
5656
def validate_pattern(cls, v: str) -> str:
5757
"""Validate pattern field."""
58-
return v.strip() if v else ""
58+
return v.strip()
5959

6060

6161
class IngestSuccessResponse(BaseModel):
@@ -73,7 +73,7 @@ class IngestSuccessResponse(BaseModel):
7373
File tree structure of the repository.
7474
content : str
7575
Processed content from the repository files.
76-
default_file_size : int
76+
default_max_file_size : int
7777
The file size slider position used.
7878
pattern_type : str
7979
The pattern type used for filtering.
@@ -87,7 +87,7 @@ class IngestSuccessResponse(BaseModel):
8787
summary: str = Field(..., description="Ingestion summary with token estimates")
8888
tree: str = Field(..., description="File tree structure")
8989
content: str = Field(..., description="Processed file content")
90-
default_file_size: int = Field(..., description="File size slider position used")
90+
default_max_file_size: int = Field(..., description="File size slider position used")
9191
pattern_type: str = Field(..., description="Pattern type used")
9292
pattern: str = Field(..., description="Pattern used")
9393

src/server/query_processor.py

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
from __future__ import annotations
44

55
from pathlib import Path
6-
from typing import Any, cast
6+
from typing import cast
77

88
from gitingest.clone import clone_repo
99
from gitingest.ingestion import ingest_query
1010
from gitingest.query_parser import IngestionQuery, parse_query
1111
from gitingest.utils.git_utils import validate_github_token
12+
from server.models import IngestErrorResponse, IngestResponse, IngestSuccessResponse
1213
from server.server_config import (
13-
DEFAULT_FILE_SIZE_KB,
14-
EXAMPLE_REPOS,
14+
DEFAULT_MAX_FILE_SIZE_KB,
1515
MAX_DISPLAY_SIZE,
1616
)
1717
from server.server_utils import Colors, log_slider_to_size
@@ -23,7 +23,7 @@ async def process_query(
2323
pattern_type: str = "exclude",
2424
pattern: str = "",
2525
token: str | None = None,
26-
) -> dict[str, Any]:
26+
) -> IngestResponse:
2727
"""Process a query by parsing input, cloning a repository, and generating a summary.
2828
2929
Handle user input, process Git repository data, and prepare
@@ -44,8 +44,8 @@ async def process_query(
4444
4545
Returns
4646
-------
47-
dict[str, Any]
48-
A dictionary containing the processed results or an error message.
47+
IngestResponse
48+
A union type, corresponding to IngestErrorResponse or IngestSuccessResponse
4949
5050
Raises
5151
------
@@ -68,16 +68,8 @@ async def process_query(
6868

6969
max_file_size = log_slider_to_size(slider_position)
7070

71-
context = {
72-
"repo_url": input_text,
73-
"examples": EXAMPLE_REPOS,
74-
"default_file_size": slider_position,
75-
"pattern_type": pattern_type,
76-
"pattern": pattern,
77-
"token": token,
78-
}
79-
8071
query: IngestionQuery | None = None
72+
short_repo_url = ""
8173

8274
try:
8375
query = await parse_query(
@@ -91,7 +83,7 @@ async def process_query(
9183
query.ensure_url()
9284

9385
# Sets the "<user>/<repo>" for the page title
94-
context["short_repo_url"] = f"{query.user_name}/{query.repo_name}"
86+
short_repo_url = f"{query.user_name}/{query.repo_name}"
9587

9688
clone_config = query.extract_clone_config()
9789
await clone_repo(clone_config, token=token)
@@ -110,10 +102,10 @@ async def process_query(
110102
print(f"{Colors.BROWN}WARN{Colors.END}: {Colors.RED}<- {Colors.END}", end="")
111103
print(f"{Colors.RED}{exc}{Colors.END}")
112104

113-
context["error"] = f"Error: {exc}"
114-
if "405" in str(exc):
115-
context["error_message"] = "Repository not found. Please make sure it is public."
116-
return context
105+
return IngestErrorResponse(
106+
error="Repository not found. Please make sure it is public." if "405" in str(exc) else "",
107+
repo_url=short_repo_url,
108+
)
117109

118110
if len(content) > MAX_DISPLAY_SIZE:
119111
content = (
@@ -132,16 +124,17 @@ async def process_query(
132124
summary=summary,
133125
)
134126

135-
context.update(
136-
{
137-
"summary": summary,
138-
"tree": tree,
139-
"content": content,
140-
},
127+
return IngestSuccessResponse(
128+
repo_url=input_text,
129+
short_repo_url=short_repo_url,
130+
summary=summary,
131+
tree=tree,
132+
content=content,
133+
default_max_file_size=slider_position,
134+
pattern_type=pattern_type,
135+
pattern=pattern,
141136
)
142137

143-
return context
144-
145138

146139
def _print_query(url: str, max_file_size: int, pattern_type: str, pattern: str) -> None:
147140
"""Print a formatted summary of the query details for debugging.
@@ -159,7 +152,7 @@ def _print_query(url: str, max_file_size: int, pattern_type: str, pattern: str)
159152
160153
"""
161154
print(f"{Colors.WHITE}{url:<20}{Colors.END}", end="")
162-
if int(max_file_size / 1024) != DEFAULT_FILE_SIZE_KB:
155+
if int(max_file_size / 1024) != DEFAULT_MAX_FILE_SIZE_KB:
163156
print(
164157
f" | {Colors.YELLOW}Size: {int(max_file_size / 1024)}kb{Colors.END}",
165158
end="",

src/server/routers/dynamic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ async def catch_all(request: Request, full_path: str) -> HTMLResponse:
3434
{
3535
"request": request,
3636
"repo_url": full_path,
37-
"default_file_size": 243,
37+
"default_max_file_size": 243,
3838
},
3939
)

src/server/routers/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ async def home(request: Request) -> HTMLResponse:
3232
{
3333
"request": request,
3434
"examples": EXAMPLE_REPOS,
35-
"default_file_size": 243,
35+
"default_max_file_size": 243,
3636
},
3737
)

src/server/routers/ingest.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,38 +65,25 @@ async def api_ingest(
6565
token=token,
6666
)
6767

68-
context = await process_query(
68+
result = await process_query(
6969
input_text=ingest_request.input_text,
7070
slider_position=ingest_request.max_file_size,
7171
pattern_type=ingest_request.pattern_type,
7272
pattern=ingest_request.pattern,
7373
token=ingest_request.token,
7474
)
75-
if "error" in context:
75+
76+
if isinstance(result, IngestErrorResponse):
7677
# Return structured error response with 400 status code
77-
error_response = IngestErrorResponse(
78-
error=context["error"],
79-
repo_url=context.get("repo_url", input_text),
80-
)
8178
return JSONResponse(
8279
status_code=status.HTTP_400_BAD_REQUEST,
83-
content=error_response.model_dump(),
80+
content=result.model_dump(),
8481
)
8582

8683
# Return structured success response with 200 status code
87-
success_response = IngestSuccessResponse(
88-
repo_url=context["repo_url"],
89-
short_repo_url=context["short_repo_url"],
90-
summary=context["summary"],
91-
tree=context["tree"],
92-
content=context["content"],
93-
default_file_size=context["default_file_size"],
94-
pattern_type=context["pattern_type"],
95-
pattern=context["pattern"],
96-
)
9784
return JSONResponse(
9885
status_code=status.HTTP_200_OK,
99-
content=success_response.model_dump(),
86+
content=result.model_dump(),
10087
)
10188

10289
except ValueError as ve:

src/server/server_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
MAX_DISPLAY_SIZE: int = 300_000
88
DELETE_REPO_AFTER: int = 60 * 60 # In seconds (1 hour)
99

10-
DEFAULT_FILE_SIZE_KB: int = 50 # Default maximum file size to include in the digest
10+
DEFAULT_MAX_FILE_SIZE_KB: int = 50 # Default maximum file size to include in the digest
1111

1212
# Slider configuration (if updated, update the logSliderToSize function in src/static/js/utils.js)
1313
MAX_FILE_SIZE_KB: int = 100 * 1024 # 100 MB

src/server/templates/components/git_form.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
min="0"
113113
max="500"
114114
required
115-
value="{{ default_file_size }}"
115+
value="{{ default_max_file_size }}"
116116
class="w-full h-3 bg-[#FAFAFA] bg-no-repeat bg-[length:50%_100%] bg-[#ebdbb7] appearance-none border-[3px] border-gray-900 rounded-sm focus:outline-none bg-gradient-to-r from-[#FE4A60] to-[#FE4A60] [&::-webkit-slider-thumb]:w-5 [&::-webkit-slider-thumb]:h-7 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:bg-white [&::-webkit-slider-thumb]:rounded-sm [&::-webkit-slider-thumb]:cursor-pointer [&::-webkit-slider-thumb]:border-solid [&::-webkit-slider-thumb]:border-[3px] [&::-webkit-slider-thumb]:border-gray-900 [&::-webkit-slider-thumb]:shadow-[3px_3px_0_#000]">
117117
</div>
118118
<!-- PAT checkbox with PAT field below -->

0 commit comments

Comments
 (0)