kodit 0.4.3__py3-none-any.whl → 0.5.1__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.

Potentially problematic release.


This version of kodit might be problematic. Click here for more details.

Files changed (135) hide show
  1. kodit/_version.py +2 -2
  2. kodit/app.py +51 -23
  3. kodit/application/factories/reporting_factory.py +6 -2
  4. kodit/application/factories/server_factory.py +353 -0
  5. kodit/application/services/code_search_application_service.py +144 -0
  6. kodit/application/services/commit_indexing_application_service.py +700 -0
  7. kodit/application/services/indexing_worker_service.py +13 -44
  8. kodit/application/services/queue_service.py +24 -3
  9. kodit/application/services/reporting.py +0 -2
  10. kodit/application/services/sync_scheduler.py +15 -31
  11. kodit/cli.py +2 -753
  12. kodit/cli_utils.py +2 -9
  13. kodit/config.py +4 -97
  14. kodit/database.py +38 -1
  15. kodit/domain/enrichments/__init__.py +1 -0
  16. kodit/domain/enrichments/architecture/__init__.py +1 -0
  17. kodit/domain/enrichments/architecture/architecture.py +20 -0
  18. kodit/domain/enrichments/architecture/physical/__init__.py +1 -0
  19. kodit/domain/enrichments/architecture/physical/discovery_notes.py +14 -0
  20. kodit/domain/enrichments/architecture/physical/formatter.py +11 -0
  21. kodit/domain/enrichments/architecture/physical/physical.py +17 -0
  22. kodit/domain/enrichments/development/__init__.py +1 -0
  23. kodit/domain/enrichments/development/development.py +18 -0
  24. kodit/domain/enrichments/development/snippet/__init__.py +1 -0
  25. kodit/domain/enrichments/development/snippet/snippet.py +21 -0
  26. kodit/domain/enrichments/enricher.py +17 -0
  27. kodit/domain/enrichments/enrichment.py +39 -0
  28. kodit/domain/enrichments/request.py +12 -0
  29. kodit/domain/enrichments/response.py +11 -0
  30. kodit/domain/enrichments/usage/__init__.py +1 -0
  31. kodit/domain/enrichments/usage/api_docs.py +19 -0
  32. kodit/domain/enrichments/usage/usage.py +18 -0
  33. kodit/domain/{entities.py → entities/__init__.py} +50 -195
  34. kodit/domain/entities/git.py +190 -0
  35. kodit/domain/factories/__init__.py +1 -0
  36. kodit/domain/factories/git_repo_factory.py +76 -0
  37. kodit/domain/protocols.py +264 -64
  38. kodit/domain/services/bm25_service.py +5 -1
  39. kodit/domain/services/embedding_service.py +3 -0
  40. kodit/domain/services/enrichment_service.py +9 -30
  41. kodit/domain/services/git_repository_service.py +429 -0
  42. kodit/domain/services/git_service.py +300 -0
  43. kodit/domain/services/physical_architecture_service.py +182 -0
  44. kodit/domain/services/task_status_query_service.py +2 -2
  45. kodit/domain/value_objects.py +87 -135
  46. kodit/infrastructure/api/client/__init__.py +0 -2
  47. kodit/infrastructure/api/v1/__init__.py +0 -4
  48. kodit/infrastructure/api/v1/dependencies.py +92 -46
  49. kodit/infrastructure/api/v1/routers/__init__.py +0 -6
  50. kodit/infrastructure/api/v1/routers/commits.py +352 -0
  51. kodit/infrastructure/api/v1/routers/queue.py +2 -2
  52. kodit/infrastructure/api/v1/routers/repositories.py +282 -0
  53. kodit/infrastructure/api/v1/routers/search.py +31 -14
  54. kodit/infrastructure/api/v1/schemas/__init__.py +0 -24
  55. kodit/infrastructure/api/v1/schemas/commit.py +96 -0
  56. kodit/infrastructure/api/v1/schemas/context.py +2 -0
  57. kodit/infrastructure/api/v1/schemas/enrichment.py +29 -0
  58. kodit/infrastructure/api/v1/schemas/repository.py +128 -0
  59. kodit/infrastructure/api/v1/schemas/search.py +12 -9
  60. kodit/infrastructure/api/v1/schemas/snippet.py +58 -0
  61. kodit/infrastructure/api/v1/schemas/tag.py +31 -0
  62. kodit/infrastructure/api/v1/schemas/task_status.py +2 -0
  63. kodit/infrastructure/bm25/local_bm25_repository.py +16 -4
  64. kodit/infrastructure/bm25/vectorchord_bm25_repository.py +68 -52
  65. kodit/infrastructure/cloning/git/git_python_adaptor.py +534 -0
  66. kodit/infrastructure/cloning/git/working_copy.py +1 -1
  67. kodit/infrastructure/embedding/embedding_factory.py +3 -2
  68. kodit/infrastructure/embedding/local_vector_search_repository.py +1 -1
  69. kodit/infrastructure/embedding/vectorchord_vector_search_repository.py +111 -84
  70. kodit/infrastructure/enricher/__init__.py +1 -0
  71. kodit/infrastructure/enricher/enricher_factory.py +53 -0
  72. kodit/infrastructure/{enrichment/litellm_enrichment_provider.py → enricher/litellm_enricher.py} +36 -56
  73. kodit/infrastructure/{enrichment/local_enrichment_provider.py → enricher/local_enricher.py} +19 -24
  74. kodit/infrastructure/enricher/null_enricher.py +36 -0
  75. kodit/infrastructure/indexing/fusion_service.py +1 -1
  76. kodit/infrastructure/mappers/enrichment_mapper.py +83 -0
  77. kodit/infrastructure/mappers/git_mapper.py +193 -0
  78. kodit/infrastructure/mappers/snippet_mapper.py +104 -0
  79. kodit/infrastructure/mappers/task_mapper.py +5 -44
  80. kodit/infrastructure/physical_architecture/__init__.py +1 -0
  81. kodit/infrastructure/physical_architecture/detectors/__init__.py +1 -0
  82. kodit/infrastructure/physical_architecture/detectors/docker_compose_detector.py +336 -0
  83. kodit/infrastructure/physical_architecture/formatters/__init__.py +1 -0
  84. kodit/infrastructure/physical_architecture/formatters/narrative_formatter.py +149 -0
  85. kodit/infrastructure/reporting/log_progress.py +8 -5
  86. kodit/infrastructure/reporting/telemetry_progress.py +21 -0
  87. kodit/infrastructure/slicing/api_doc_extractor.py +836 -0
  88. kodit/infrastructure/slicing/ast_analyzer.py +1128 -0
  89. kodit/infrastructure/slicing/slicer.py +87 -421
  90. kodit/infrastructure/sqlalchemy/embedding_repository.py +43 -23
  91. kodit/infrastructure/sqlalchemy/enrichment_v2_repository.py +118 -0
  92. kodit/infrastructure/sqlalchemy/entities.py +402 -158
  93. kodit/infrastructure/sqlalchemy/git_branch_repository.py +274 -0
  94. kodit/infrastructure/sqlalchemy/git_commit_repository.py +346 -0
  95. kodit/infrastructure/sqlalchemy/git_repository.py +262 -0
  96. kodit/infrastructure/sqlalchemy/git_tag_repository.py +268 -0
  97. kodit/infrastructure/sqlalchemy/snippet_v2_repository.py +479 -0
  98. kodit/infrastructure/sqlalchemy/task_repository.py +29 -23
  99. kodit/infrastructure/sqlalchemy/task_status_repository.py +24 -12
  100. kodit/infrastructure/sqlalchemy/unit_of_work.py +10 -14
  101. kodit/mcp.py +12 -30
  102. kodit/migrations/env.py +1 -0
  103. kodit/migrations/versions/04b80f802e0c_foreign_key_review.py +100 -0
  104. kodit/migrations/versions/19f8c7faf8b9_add_generic_enrichment_type.py +260 -0
  105. kodit/migrations/versions/7f15f878c3a1_add_new_git_entities.py +690 -0
  106. kodit/migrations/versions/f9e5ef5e688f_add_git_commits_number.py +43 -0
  107. kodit/py.typed +0 -0
  108. kodit/utils/dump_config.py +361 -0
  109. kodit/utils/dump_openapi.py +6 -4
  110. kodit/utils/path_utils.py +29 -0
  111. {kodit-0.4.3.dist-info → kodit-0.5.1.dist-info}/METADATA +3 -3
  112. kodit-0.5.1.dist-info/RECORD +168 -0
  113. kodit/application/factories/code_indexing_factory.py +0 -195
  114. kodit/application/services/auto_indexing_service.py +0 -99
  115. kodit/application/services/code_indexing_application_service.py +0 -410
  116. kodit/domain/services/index_query_service.py +0 -70
  117. kodit/domain/services/index_service.py +0 -269
  118. kodit/infrastructure/api/client/index_client.py +0 -57
  119. kodit/infrastructure/api/v1/routers/indexes.py +0 -164
  120. kodit/infrastructure/api/v1/schemas/index.py +0 -101
  121. kodit/infrastructure/bm25/bm25_factory.py +0 -28
  122. kodit/infrastructure/cloning/__init__.py +0 -1
  123. kodit/infrastructure/cloning/metadata.py +0 -98
  124. kodit/infrastructure/enrichment/__init__.py +0 -1
  125. kodit/infrastructure/enrichment/enrichment_factory.py +0 -52
  126. kodit/infrastructure/enrichment/null_enrichment_provider.py +0 -19
  127. kodit/infrastructure/mappers/index_mapper.py +0 -345
  128. kodit/infrastructure/reporting/tdqm_progress.py +0 -38
  129. kodit/infrastructure/slicing/language_detection_service.py +0 -18
  130. kodit/infrastructure/sqlalchemy/index_repository.py +0 -646
  131. kodit-0.4.3.dist-info/RECORD +0 -125
  132. /kodit/infrastructure/{enrichment → enricher}/utils.py +0 -0
  133. {kodit-0.4.3.dist-info → kodit-0.5.1.dist-info}/WHEEL +0 -0
  134. {kodit-0.4.3.dist-info → kodit-0.5.1.dist-info}/entry_points.txt +0 -0
  135. {kodit-0.4.3.dist-info → kodit-0.5.1.dist-info}/licenses/LICENSE +0 -0
@@ -1,6 +1,5 @@
1
1
  """Pure domain value objects and DTOs."""
2
2
 
3
- import json
4
3
  from dataclasses import dataclass
5
4
  from datetime import datetime
6
5
  from enum import Enum, IntEnum, StrEnum
@@ -18,12 +17,27 @@ class SourceType(IntEnum):
18
17
  GIT = 2
19
18
 
20
19
 
21
- class SnippetContentType(IntEnum):
20
+ class SnippetContentType(StrEnum):
22
21
  """Type of snippet content."""
23
22
 
24
- UNKNOWN = 0
25
- ORIGINAL = 1
26
- SUMMARY = 2
23
+ UNKNOWN = "unknown"
24
+ ORIGINAL = "original"
25
+ SUMMARY = "summary"
26
+
27
+
28
+ class EnrichmentType(StrEnum):
29
+ """Type of enrichment."""
30
+
31
+ UNKNOWN = "unknown"
32
+ SUMMARIZATION = "summarization"
33
+
34
+
35
+ @dataclass(frozen=True)
36
+ class Enrichment:
37
+ """Enrichment domain value object."""
38
+
39
+ type: EnrichmentType
40
+ content: str
27
41
 
28
42
 
29
43
  class SnippetContent(BaseModel):
@@ -31,7 +45,6 @@ class SnippetContent(BaseModel):
31
45
 
32
46
  type: SnippetContentType
33
47
  value: str
34
- language: str
35
48
 
36
49
 
37
50
  class SnippetSearchResult(BaseModel):
@@ -138,7 +151,7 @@ class SearchType(Enum):
138
151
  class Document:
139
152
  """Generic document model for indexing."""
140
153
 
141
- snippet_id: int
154
+ snippet_id: str
142
155
  text: str
143
156
 
144
157
 
@@ -146,7 +159,7 @@ class Document:
146
159
  class DocumentSearchResult:
147
160
  """Generic document search result model."""
148
161
 
149
- snippet_id: int
162
+ snippet_id: str
150
163
  score: float
151
164
 
152
165
 
@@ -154,7 +167,7 @@ class DocumentSearchResult:
154
167
  class SearchResult:
155
168
  """Generic search result model."""
156
169
 
157
- snippet_id: int
170
+ snippet_id: str
158
171
  score: float
159
172
 
160
173
 
@@ -171,21 +184,21 @@ class SearchRequest:
171
184
 
172
185
  query: str
173
186
  top_k: int = 10
174
- snippet_ids: list[int] | None = None
187
+ snippet_ids: list[str] | None = None
175
188
 
176
189
 
177
190
  @dataclass
178
191
  class DeleteRequest:
179
192
  """Generic deletion request."""
180
193
 
181
- snippet_ids: list[int]
194
+ snippet_ids: list[str]
182
195
 
183
196
 
184
197
  @dataclass
185
198
  class IndexResult:
186
199
  """Generic indexing result."""
187
200
 
188
- snippet_id: int
201
+ snippet_id: str
189
202
 
190
203
 
191
204
  @dataclass(frozen=True)
@@ -271,98 +284,11 @@ class MultiSearchRequest:
271
284
  filters: SnippetSearchFilters | None = None
272
285
 
273
286
 
274
- @dataclass
275
- class MultiSearchResult:
276
- """Enhanced search result with comprehensive snippet metadata."""
277
-
278
- id: int
279
- content: str
280
- original_scores: list[float]
281
- source_uri: str
282
- relative_path: str
283
- language: str
284
- authors: list[str]
285
- created_at: datetime
286
- summary: str
287
-
288
- def __str__(self) -> str:
289
- """Return enhanced formatted string representation."""
290
- lines = [
291
- "---",
292
- f"id: {self.id}",
293
- f"source: {self.source_uri}",
294
- f"path: {self.relative_path}",
295
- f"lang: {self.language}",
296
- f"created: {self.created_at.isoformat()}",
297
- f"authors: {', '.join(self.authors)}",
298
- f"scores: {self.original_scores}",
299
- "---",
300
- f"{self.summary}\n",
301
- f"```{self.language}",
302
- f"{self.content}",
303
- "```\n",
304
- ]
305
- return "\n".join(lines)
306
-
307
- def to_json(self) -> str:
308
- """Return LLM-optimized JSON representation following the compact schema."""
309
- json_obj = {
310
- "id": self.id,
311
- "source": self.source_uri,
312
- "path": self.relative_path,
313
- "lang": self.language.lower(),
314
- "created": self.created_at.isoformat() if self.created_at else "",
315
- "author": ", ".join(self.authors),
316
- "score": self.original_scores,
317
- "code": self.content,
318
- "summary": self.summary,
319
- }
320
-
321
- return json.dumps(json_obj, separators=(",", ":"))
322
-
323
- @classmethod
324
- def to_jsonlines(cls, results: list["MultiSearchResult"]) -> str:
325
- """Convert multiple MultiSearchResult objects to JSON Lines format.
326
-
327
- Args:
328
- results: List of MultiSearchResult objects
329
- include_summary: Whether to include summary fields
330
-
331
- Returns:
332
- JSON Lines string (one JSON object per line)
333
-
334
- """
335
- return "\n".join(result.to_json() for result in results)
336
-
337
- @classmethod
338
- def to_string(cls, results: list["MultiSearchResult"]) -> str:
339
- """Convert multiple MultiSearchResult objects to a string."""
340
- return "\n\n".join(str(result) for result in results)
341
-
342
- @staticmethod
343
- def calculate_relative_path(file_path: str, source_path: str) -> str:
344
- """Calculate relative path from source root."""
345
- try:
346
- return str(Path(file_path).relative_to(Path(source_path)))
347
- except ValueError:
348
- # If file_path is not relative to source_path, return the file name
349
- return Path(file_path).name
350
-
351
- @staticmethod
352
- def detect_language_from_extension(extension: str) -> str:
353
- """Detect programming language from file extension."""
354
- try:
355
- return LanguageMapping.get_language_for_extension(extension).title()
356
- except ValueError:
357
- # Unknown extension, return a default
358
- return "Unknown"
359
-
360
-
361
287
  @dataclass
362
288
  class FusionRequest:
363
289
  """Domain model for fusion request."""
364
290
 
365
- id: int
291
+ id: str
366
292
  score: float
367
293
 
368
294
 
@@ -370,7 +296,7 @@ class FusionRequest:
370
296
  class FusionResult:
371
297
  """Domain model for fusion result."""
372
298
 
373
- id: int
299
+ id: str
374
300
  score: float
375
301
  original_scores: list[float]
376
302
 
@@ -408,7 +334,7 @@ class ProgressState:
408
334
  class EmbeddingRequest:
409
335
  """Domain model for embedding request."""
410
336
 
411
- snippet_id: int
337
+ snippet_id: str
412
338
  text: str
413
339
 
414
340
 
@@ -416,33 +342,10 @@ class EmbeddingRequest:
416
342
  class EmbeddingResponse:
417
343
  """Domain model for embedding response."""
418
344
 
419
- snippet_id: int
345
+ snippet_id: str
420
346
  embedding: list[float]
421
347
 
422
348
 
423
- @dataclass
424
- class EnrichmentRequest:
425
- """Domain model for enrichment request."""
426
-
427
- snippet_id: int
428
- text: str
429
-
430
-
431
- @dataclass
432
- class EnrichmentResponse:
433
- """Domain model for enrichment response."""
434
-
435
- snippet_id: int
436
- text: str
437
-
438
-
439
- @dataclass
440
- class EnrichmentIndexRequest:
441
- """Domain model for enrichment index request."""
442
-
443
- requests: list[EnrichmentRequest]
444
-
445
-
446
349
  @dataclass
447
350
  class IndexView:
448
351
  """Domain model for index information."""
@@ -651,22 +554,14 @@ class FunctionDefinition:
651
554
  end_byte: int
652
555
 
653
556
 
654
- class TaskType(Enum):
655
- """Task type."""
656
-
657
- INDEX_UPDATE = 1
658
-
659
-
660
557
  class QueuePriority(IntEnum):
661
558
  """Queue priority."""
662
559
 
663
560
  BACKGROUND = 10
561
+ NORMAL = 20
664
562
  USER_INITIATED = 50
665
563
 
666
564
 
667
- # Reporting value objects
668
-
669
-
670
565
  class ReportingState(StrEnum):
671
566
  """Reporting state."""
672
567
 
@@ -690,6 +585,8 @@ class TrackableType(StrEnum):
690
585
  """Trackable type."""
691
586
 
692
587
  INDEX = "indexes"
588
+ KODIT_REPOSITORY = "kodit.repository"
589
+ KODIT_COMMIT = "kodit.commit"
693
590
 
694
591
 
695
592
  class TaskOperation(StrEnum):
@@ -707,3 +604,58 @@ class TaskOperation(StrEnum):
707
604
  CREATE_TEXT_EMBEDDINGS = "kodit.index.run.create_text_embeddings"
708
605
  UPDATE_INDEX_TIMESTAMP = "kodit.index.run.update_index_timestamp"
709
606
  CLEAR_FILE_PROCESSING_STATUSES = "kodit.index.run.clear_file_processing_statuses"
607
+
608
+ # New commit-based workflow
609
+ KODIT_REPOSITORY = "kodit.repository"
610
+ CREATE_REPOSITORY = "kodit.repository.create"
611
+ DELETE_REPOSITORY = "kodit.repository.delete"
612
+ CLONE_REPOSITORY = "kodit.repository.clone"
613
+ SCAN_REPOSITORY = "kodit.repository.scan"
614
+ KODIT_COMMIT = "kodit.commit"
615
+ EXTRACT_SNIPPETS_FOR_COMMIT = "kodit.commit.extract_snippets"
616
+ CREATE_BM25_INDEX_FOR_COMMIT = "kodit.commit.create_bm25_index"
617
+ CREATE_CODE_EMBEDDINGS_FOR_COMMIT = "kodit.commit.create_code_embeddings"
618
+ CREATE_SUMMARY_ENRICHMENT_FOR_COMMIT = "kodit.commit.create_summary_enrichment"
619
+ CREATE_SUMMARY_EMBEDDINGS_FOR_COMMIT = "kodit.commit.create_summary_embeddings"
620
+ CREATE_ARCHITECTURE_ENRICHMENT_FOR_COMMIT = (
621
+ "kodit.commit.create_architecture_enrichment"
622
+ )
623
+ CREATE_PUBLIC_API_DOCS_FOR_COMMIT = "kodit.commit.create_public_api_docs"
624
+
625
+ def is_repository_operation(self) -> bool:
626
+ """Check if the task operation is a repository operation."""
627
+ return self.startswith("kodit.repository.")
628
+
629
+ def is_commit_operation(self) -> bool:
630
+ """Check if the task operation is a commit operation."""
631
+ return self.startswith("kodit.commit.")
632
+
633
+
634
+ class PrescribedOperations:
635
+ """Prescribed common operations."""
636
+
637
+ CREATE_NEW_REPOSITORY: ClassVar[list[TaskOperation]] = [
638
+ TaskOperation.CLONE_REPOSITORY,
639
+ TaskOperation.SCAN_REPOSITORY,
640
+ ]
641
+ INDEX_COMMIT: ClassVar[list[TaskOperation]] = [
642
+ TaskOperation.EXTRACT_SNIPPETS_FOR_COMMIT,
643
+ TaskOperation.CREATE_BM25_INDEX_FOR_COMMIT,
644
+ TaskOperation.CREATE_CODE_EMBEDDINGS_FOR_COMMIT,
645
+ TaskOperation.CREATE_SUMMARY_ENRICHMENT_FOR_COMMIT,
646
+ TaskOperation.CREATE_SUMMARY_EMBEDDINGS_FOR_COMMIT,
647
+ TaskOperation.CREATE_ARCHITECTURE_ENRICHMENT_FOR_COMMIT,
648
+ TaskOperation.CREATE_PUBLIC_API_DOCS_FOR_COMMIT,
649
+ ]
650
+ SYNC_REPOSITORY: ClassVar[list[TaskOperation]] = [
651
+ TaskOperation.SCAN_REPOSITORY,
652
+ ]
653
+
654
+
655
+ class IndexStatus(StrEnum):
656
+ """Status of commit indexing."""
657
+
658
+ PENDING = "pending"
659
+ IN_PROGRESS = "in_progress"
660
+ COMPLETED = "completed"
661
+ FAILED = "failed"
@@ -2,13 +2,11 @@
2
2
 
3
3
  from .base import BaseAPIClient
4
4
  from .exceptions import AuthenticationError, KoditAPIError
5
- from .index_client import IndexClient
6
5
  from .search_client import SearchClient
7
6
 
8
7
  __all__ = [
9
8
  "AuthenticationError",
10
9
  "BaseAPIClient",
11
- "IndexClient",
12
10
  "KoditAPIError",
13
11
  "SearchClient",
14
12
  ]
@@ -1,5 +1 @@
1
1
  """API v1 modules."""
2
-
3
- from .routers import indexes_router, queue_router, search_router
4
-
5
- __all__ = ["indexes_router", "queue_router", "search_router"]
@@ -1,23 +1,27 @@
1
1
  """FastAPI dependencies for the REST API."""
2
2
 
3
- from collections.abc import AsyncGenerator, Callable
3
+ from collections.abc import Callable
4
4
  from typing import Annotated, cast
5
5
 
6
6
  from fastapi import Depends, Request
7
7
  from sqlalchemy.ext.asyncio import AsyncSession
8
8
 
9
- from kodit.application.factories.code_indexing_factory import (
10
- create_server_code_indexing_application_service,
9
+ from kodit.application.factories.server_factory import ServerFactory
10
+ from kodit.application.services.code_search_application_service import (
11
+ CodeSearchApplicationService,
11
12
  )
12
- from kodit.application.services.code_indexing_application_service import (
13
- CodeIndexingApplicationService,
13
+ from kodit.application.services.commit_indexing_application_service import (
14
+ CommitIndexingApplicationService,
14
15
  )
15
16
  from kodit.application.services.queue_service import QueueService
16
17
  from kodit.config import AppContext
17
- from kodit.domain.services.index_query_service import IndexQueryService
18
+ from kodit.domain.protocols import (
19
+ GitBranchRepository,
20
+ GitCommitRepository,
21
+ GitRepoRepository,
22
+ GitTagRepository,
23
+ )
18
24
  from kodit.domain.services.task_status_query_service import TaskStatusQueryService
19
- from kodit.infrastructure.indexing.fusion_service import ReciprocalRankFusionService
20
- from kodit.infrastructure.sqlalchemy.index_repository import create_index_repository
21
25
  from kodit.infrastructure.sqlalchemy.task_status_repository import (
22
26
  create_task_status_repository,
23
27
  )
@@ -34,24 +38,22 @@ def get_app_context(request: Request) -> AppContext:
34
38
  AppContextDep = Annotated[AppContext, Depends(get_app_context)]
35
39
 
36
40
 
37
- async def get_db_session(
38
- app_context: AppContextDep,
39
- ) -> AsyncGenerator[AsyncSession, None]:
40
- """Get database session dependency."""
41
- db = await app_context.get_db()
42
- async with db.session_factory() as session:
43
- yield session
41
+ def get_server_factory(request: Request) -> ServerFactory:
42
+ """Get the server factory dependency."""
43
+ server_factory = cast("ServerFactory", request.state.server_factory)
44
+ if server_factory is None:
45
+ raise RuntimeError("Server factory not initialized")
46
+ return server_factory
44
47
 
45
48
 
46
- DBSessionDep = Annotated[AsyncSession, Depends(get_db_session)]
49
+ ServerFactoryDep = Annotated[ServerFactory, Depends(get_server_factory)]
47
50
 
48
51
 
49
52
  async def get_db_session_factory(
50
- app_context: AppContextDep,
51
- ) -> AsyncGenerator[Callable[[], AsyncSession], None]:
53
+ server_factory: ServerFactoryDep,
54
+ ) -> Callable[[], AsyncSession]:
52
55
  """Get database session dependency."""
53
- db = await app_context.get_db()
54
- yield db.session_factory
56
+ return server_factory.session_factory
55
57
 
56
58
 
57
59
  DBSessionFactoryDep = Annotated[
@@ -59,32 +61,6 @@ DBSessionFactoryDep = Annotated[
59
61
  ]
60
62
 
61
63
 
62
- async def get_index_query_service(
63
- session_factory: DBSessionFactoryDep,
64
- ) -> IndexQueryService:
65
- """Get index query service dependency."""
66
- return IndexQueryService(
67
- index_repository=create_index_repository(session_factory=session_factory),
68
- fusion_service=ReciprocalRankFusionService(),
69
- )
70
-
71
-
72
- IndexQueryServiceDep = Annotated[IndexQueryService, Depends(get_index_query_service)]
73
-
74
-
75
- async def get_indexing_app_service(
76
- app_context: AppContextDep,
77
- session_factory: DBSessionFactoryDep,
78
- ) -> CodeIndexingApplicationService:
79
- """Get indexing application service dependency."""
80
- return create_server_code_indexing_application_service(app_context, session_factory)
81
-
82
-
83
- IndexingAppServiceDep = Annotated[
84
- CodeIndexingApplicationService, Depends(get_indexing_app_service)
85
- ]
86
-
87
-
88
64
  async def get_queue_service(
89
65
  session_factory: DBSessionFactoryDep,
90
66
  ) -> QueueService:
@@ -109,3 +85,73 @@ async def get_task_status_query_service(
109
85
  TaskStatusQueryServiceDep = Annotated[
110
86
  TaskStatusQueryService, Depends(get_task_status_query_service)
111
87
  ]
88
+
89
+
90
+ async def get_git_repository(
91
+ server_factory: ServerFactoryDep,
92
+ ) -> GitRepoRepository:
93
+ """Get git repository dependency."""
94
+ return server_factory.repo_repository()
95
+
96
+
97
+ GitRepositoryDep = Annotated[GitRepoRepository, Depends(get_git_repository)]
98
+
99
+
100
+ async def get_git_commit_repository(
101
+ server_factory: ServerFactoryDep,
102
+ ) -> GitCommitRepository:
103
+ """Get git commit repository dependency."""
104
+ return server_factory.git_commit_repository()
105
+
106
+
107
+ GitCommitRepositoryDep = Annotated[
108
+ GitCommitRepository, Depends(get_git_commit_repository)
109
+ ]
110
+
111
+
112
+ async def get_git_branch_repository(
113
+ server_factory: ServerFactoryDep,
114
+ ) -> GitBranchRepository:
115
+ """Get git branch repository dependency."""
116
+ return server_factory.git_branch_repository()
117
+
118
+
119
+ GitBranchRepositoryDep = Annotated[
120
+ GitBranchRepository, Depends(get_git_branch_repository)
121
+ ]
122
+
123
+
124
+ async def get_git_tag_repository(
125
+ server_factory: ServerFactoryDep,
126
+ ) -> GitTagRepository:
127
+ """Get git tag repository dependency."""
128
+ return server_factory.git_tag_repository()
129
+
130
+
131
+ GitTagRepositoryDep = Annotated[
132
+ GitTagRepository, Depends(get_git_tag_repository)
133
+ ]
134
+
135
+
136
+ async def get_commit_indexing_app_service(
137
+ server_factory: ServerFactoryDep,
138
+ ) -> CommitIndexingApplicationService:
139
+ """Get commit indexing application service dependency."""
140
+ return server_factory.commit_indexing_application_service()
141
+
142
+
143
+ CommitIndexingAppServiceDep = Annotated[
144
+ CommitIndexingApplicationService, Depends(get_commit_indexing_app_service)
145
+ ]
146
+
147
+
148
+ async def get_code_search_app_service(
149
+ server_factory: ServerFactoryDep,
150
+ ) -> CodeSearchApplicationService:
151
+ """Get code search application service dependency."""
152
+ return server_factory.code_search_application_service()
153
+
154
+
155
+ CodeSearchAppServiceDep = Annotated[
156
+ CodeSearchApplicationService, Depends(get_code_search_app_service)
157
+ ]
@@ -1,7 +1 @@
1
1
  """API v1 routers."""
2
-
3
- from .indexes import router as indexes_router
4
- from .queue import router as queue_router
5
- from .search import router as search_router
6
-
7
- __all__ = ["indexes_router", "queue_router", "search_router"]