julee 0.1.0__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.
Files changed (161) hide show
  1. julee/__init__.py +3 -0
  2. julee/api/__init__.py +20 -0
  3. julee/api/app.py +180 -0
  4. julee/api/dependencies.py +257 -0
  5. julee/api/requests.py +175 -0
  6. julee/api/responses.py +43 -0
  7. julee/api/routers/__init__.py +43 -0
  8. julee/api/routers/assembly_specifications.py +212 -0
  9. julee/api/routers/documents.py +182 -0
  10. julee/api/routers/knowledge_service_configs.py +79 -0
  11. julee/api/routers/knowledge_service_queries.py +293 -0
  12. julee/api/routers/system.py +137 -0
  13. julee/api/routers/workflows.py +234 -0
  14. julee/api/services/__init__.py +20 -0
  15. julee/api/services/system_initialization.py +214 -0
  16. julee/api/tests/__init__.py +14 -0
  17. julee/api/tests/routers/__init__.py +17 -0
  18. julee/api/tests/routers/test_assembly_specifications.py +749 -0
  19. julee/api/tests/routers/test_documents.py +301 -0
  20. julee/api/tests/routers/test_knowledge_service_configs.py +234 -0
  21. julee/api/tests/routers/test_knowledge_service_queries.py +738 -0
  22. julee/api/tests/routers/test_system.py +179 -0
  23. julee/api/tests/routers/test_workflows.py +393 -0
  24. julee/api/tests/test_app.py +285 -0
  25. julee/api/tests/test_dependencies.py +245 -0
  26. julee/api/tests/test_requests.py +250 -0
  27. julee/domain/__init__.py +22 -0
  28. julee/domain/models/__init__.py +49 -0
  29. julee/domain/models/assembly/__init__.py +17 -0
  30. julee/domain/models/assembly/assembly.py +103 -0
  31. julee/domain/models/assembly/tests/__init__.py +0 -0
  32. julee/domain/models/assembly/tests/factories.py +37 -0
  33. julee/domain/models/assembly/tests/test_assembly.py +430 -0
  34. julee/domain/models/assembly_specification/__init__.py +24 -0
  35. julee/domain/models/assembly_specification/assembly_specification.py +172 -0
  36. julee/domain/models/assembly_specification/knowledge_service_query.py +123 -0
  37. julee/domain/models/assembly_specification/tests/__init__.py +0 -0
  38. julee/domain/models/assembly_specification/tests/factories.py +78 -0
  39. julee/domain/models/assembly_specification/tests/test_assembly_specification.py +490 -0
  40. julee/domain/models/assembly_specification/tests/test_knowledge_service_query.py +310 -0
  41. julee/domain/models/custom_fields/__init__.py +0 -0
  42. julee/domain/models/custom_fields/content_stream.py +68 -0
  43. julee/domain/models/custom_fields/tests/__init__.py +0 -0
  44. julee/domain/models/custom_fields/tests/test_custom_fields.py +53 -0
  45. julee/domain/models/document/__init__.py +17 -0
  46. julee/domain/models/document/document.py +150 -0
  47. julee/domain/models/document/tests/__init__.py +0 -0
  48. julee/domain/models/document/tests/factories.py +76 -0
  49. julee/domain/models/document/tests/test_document.py +297 -0
  50. julee/domain/models/knowledge_service_config/__init__.py +17 -0
  51. julee/domain/models/knowledge_service_config/knowledge_service_config.py +86 -0
  52. julee/domain/models/policy/__init__.py +15 -0
  53. julee/domain/models/policy/document_policy_validation.py +220 -0
  54. julee/domain/models/policy/policy.py +203 -0
  55. julee/domain/models/policy/tests/__init__.py +0 -0
  56. julee/domain/models/policy/tests/factories.py +47 -0
  57. julee/domain/models/policy/tests/test_document_policy_validation.py +420 -0
  58. julee/domain/models/policy/tests/test_policy.py +546 -0
  59. julee/domain/repositories/__init__.py +27 -0
  60. julee/domain/repositories/assembly.py +45 -0
  61. julee/domain/repositories/assembly_specification.py +52 -0
  62. julee/domain/repositories/base.py +146 -0
  63. julee/domain/repositories/document.py +49 -0
  64. julee/domain/repositories/document_policy_validation.py +52 -0
  65. julee/domain/repositories/knowledge_service_config.py +54 -0
  66. julee/domain/repositories/knowledge_service_query.py +44 -0
  67. julee/domain/repositories/policy.py +49 -0
  68. julee/domain/use_cases/__init__.py +17 -0
  69. julee/domain/use_cases/decorators.py +107 -0
  70. julee/domain/use_cases/extract_assemble_data.py +649 -0
  71. julee/domain/use_cases/initialize_system_data.py +842 -0
  72. julee/domain/use_cases/tests/__init__.py +7 -0
  73. julee/domain/use_cases/tests/test_extract_assemble_data.py +548 -0
  74. julee/domain/use_cases/tests/test_initialize_system_data.py +455 -0
  75. julee/domain/use_cases/tests/test_validate_document.py +1228 -0
  76. julee/domain/use_cases/validate_document.py +736 -0
  77. julee/fixtures/assembly_specifications.yaml +70 -0
  78. julee/fixtures/documents.yaml +178 -0
  79. julee/fixtures/knowledge_service_configs.yaml +37 -0
  80. julee/fixtures/knowledge_service_queries.yaml +27 -0
  81. julee/repositories/__init__.py +17 -0
  82. julee/repositories/memory/__init__.py +31 -0
  83. julee/repositories/memory/assembly.py +84 -0
  84. julee/repositories/memory/assembly_specification.py +125 -0
  85. julee/repositories/memory/base.py +227 -0
  86. julee/repositories/memory/document.py +149 -0
  87. julee/repositories/memory/document_policy_validation.py +104 -0
  88. julee/repositories/memory/knowledge_service_config.py +123 -0
  89. julee/repositories/memory/knowledge_service_query.py +120 -0
  90. julee/repositories/memory/policy.py +87 -0
  91. julee/repositories/memory/tests/__init__.py +0 -0
  92. julee/repositories/memory/tests/test_document.py +212 -0
  93. julee/repositories/memory/tests/test_document_policy_validation.py +161 -0
  94. julee/repositories/memory/tests/test_policy.py +443 -0
  95. julee/repositories/minio/__init__.py +31 -0
  96. julee/repositories/minio/assembly.py +103 -0
  97. julee/repositories/minio/assembly_specification.py +170 -0
  98. julee/repositories/minio/client.py +570 -0
  99. julee/repositories/minio/document.py +530 -0
  100. julee/repositories/minio/document_policy_validation.py +120 -0
  101. julee/repositories/minio/knowledge_service_config.py +187 -0
  102. julee/repositories/minio/knowledge_service_query.py +211 -0
  103. julee/repositories/minio/policy.py +106 -0
  104. julee/repositories/minio/tests/__init__.py +0 -0
  105. julee/repositories/minio/tests/fake_client.py +213 -0
  106. julee/repositories/minio/tests/test_assembly.py +374 -0
  107. julee/repositories/minio/tests/test_assembly_specification.py +391 -0
  108. julee/repositories/minio/tests/test_client_protocol.py +57 -0
  109. julee/repositories/minio/tests/test_document.py +591 -0
  110. julee/repositories/minio/tests/test_document_policy_validation.py +192 -0
  111. julee/repositories/minio/tests/test_knowledge_service_config.py +374 -0
  112. julee/repositories/minio/tests/test_knowledge_service_query.py +438 -0
  113. julee/repositories/minio/tests/test_policy.py +559 -0
  114. julee/repositories/temporal/__init__.py +38 -0
  115. julee/repositories/temporal/activities.py +114 -0
  116. julee/repositories/temporal/activity_names.py +34 -0
  117. julee/repositories/temporal/proxies.py +159 -0
  118. julee/services/__init__.py +18 -0
  119. julee/services/knowledge_service/__init__.py +48 -0
  120. julee/services/knowledge_service/anthropic/__init__.py +12 -0
  121. julee/services/knowledge_service/anthropic/knowledge_service.py +331 -0
  122. julee/services/knowledge_service/anthropic/tests/test_knowledge_service.py +318 -0
  123. julee/services/knowledge_service/factory.py +138 -0
  124. julee/services/knowledge_service/knowledge_service.py +160 -0
  125. julee/services/knowledge_service/memory/__init__.py +13 -0
  126. julee/services/knowledge_service/memory/knowledge_service.py +278 -0
  127. julee/services/knowledge_service/memory/test_knowledge_service.py +345 -0
  128. julee/services/knowledge_service/test_factory.py +112 -0
  129. julee/services/temporal/__init__.py +38 -0
  130. julee/services/temporal/activities.py +86 -0
  131. julee/services/temporal/activity_names.py +22 -0
  132. julee/services/temporal/proxies.py +41 -0
  133. julee/util/__init__.py +0 -0
  134. julee/util/domain.py +119 -0
  135. julee/util/repos/__init__.py +0 -0
  136. julee/util/repos/minio/__init__.py +0 -0
  137. julee/util/repos/minio/file_storage.py +213 -0
  138. julee/util/repos/temporal/__init__.py +11 -0
  139. julee/util/repos/temporal/client_proxies/file_storage.py +68 -0
  140. julee/util/repos/temporal/data_converter.py +123 -0
  141. julee/util/repos/temporal/minio_file_storage.py +12 -0
  142. julee/util/repos/temporal/proxies/__init__.py +0 -0
  143. julee/util/repos/temporal/proxies/file_storage.py +58 -0
  144. julee/util/repositories.py +55 -0
  145. julee/util/temporal/__init__.py +22 -0
  146. julee/util/temporal/activities.py +123 -0
  147. julee/util/temporal/decorators.py +473 -0
  148. julee/util/tests/__init__.py +1 -0
  149. julee/util/tests/test_decorators.py +770 -0
  150. julee/util/validation/__init__.py +29 -0
  151. julee/util/validation/repository.py +100 -0
  152. julee/util/validation/type_guards.py +369 -0
  153. julee/worker.py +211 -0
  154. julee/workflows/__init__.py +26 -0
  155. julee/workflows/extract_assemble.py +215 -0
  156. julee/workflows/validate_document.py +228 -0
  157. julee-0.1.0.dist-info/METADATA +195 -0
  158. julee-0.1.0.dist-info/RECORD +161 -0
  159. julee-0.1.0.dist-info/WHEEL +5 -0
  160. julee-0.1.0.dist-info/licenses/LICENSE +674 -0
  161. julee-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,146 @@
1
+ """
2
+ Generic base repository protocol for common CRUD operations.
3
+
4
+ This module defines a generic BaseRepository protocol that captures the common
5
+ patterns shared across all domain repositories in the Capture, Extract,
6
+ Assemble, Publish workflow. This reduces code duplication while maintaining
7
+ type safety and clean interfaces.
8
+
9
+ All repository operations follow the same principles:
10
+
11
+ - **Idempotency**: All methods are designed to be idempotent and safe for
12
+ retry. Multiple calls with the same parameters will produce the same
13
+ result without unintended side effects.
14
+
15
+ - **Workflow Safety**: All operations are safe to call from deterministic
16
+ workflow contexts. Non-deterministic operations (like ID generation) are
17
+ explicitly delegated to activities.
18
+
19
+ - **Domain Objects**: Methods accept and return domain objects or primitives,
20
+ never framework-specific types.
21
+
22
+ In Temporal workflow contexts, these protocols are implemented by workflow
23
+ stubs that delegate to activities for durability and proper error handling.
24
+ """
25
+
26
+ from typing import Protocol, Optional, runtime_checkable, TypeVar, List, Dict
27
+ from pydantic import BaseModel
28
+
29
+ # Type variable bound to Pydantic BaseModel for domain entities
30
+ T = TypeVar("T", bound=BaseModel)
31
+
32
+
33
+ @runtime_checkable
34
+ class BaseRepository(Protocol[T]):
35
+ """Generic base repository protocol for common CRUD operations.
36
+
37
+ This protocol defines the common interface shared by all domain
38
+ repositories in the system. It uses generics to provide type safety
39
+ while eliminating code duplication.
40
+
41
+ Type Parameter:
42
+ T: The domain entity type (must extend Pydantic BaseModel)
43
+ """
44
+
45
+ async def get(self, entity_id: str) -> Optional[T]:
46
+ """Retrieve an entity by ID.
47
+
48
+ Args:
49
+ entity_id: Unique entity identifier
50
+
51
+ Returns:
52
+ Entity if found, None otherwise
53
+
54
+ Implementation Notes:
55
+ - Must be idempotent: multiple calls return same result
56
+ - Should handle missing entities gracefully (return None)
57
+ - Loads complete entity with all relationships
58
+ """
59
+ ...
60
+
61
+ async def get_many(self, entity_ids: List[str]) -> Dict[str, Optional[T]]:
62
+ """Retrieve multiple entities by ID.
63
+
64
+ Args:
65
+ entity_ids: List of unique entity identifiers
66
+
67
+ Returns:
68
+ Dict mapping entity_id to entity (or None if not found)
69
+
70
+ Implementation Notes:
71
+ - Must be idempotent: multiple calls return same result
72
+ - Should handle missing entities gracefully (return None for missing)
73
+ - Implementations may optimize with batch operations or fall back
74
+ to individual get() calls
75
+ - Keys in returned dict correspond exactly to input entity_ids
76
+ - Missing entities have None values in the returned dict
77
+
78
+ Workflow Context:
79
+ In Temporal workflows, this method is implemented as an activity
80
+ to ensure batch operations are durably stored and consistent
81
+ across workflow replays.
82
+ """
83
+ ...
84
+
85
+ async def save(self, entity: T) -> None:
86
+ """Save an entity.
87
+
88
+ Args:
89
+ entity: Complete entity to save
90
+
91
+ Implementation Notes:
92
+ - Must be idempotent: saving same entity state is safe
93
+ - Should update the updated_at timestamp
94
+ - Must save complete entity with all relationships
95
+ - Handles both new entities and updates to existing ones
96
+ """
97
+ ...
98
+
99
+ async def list_all(self) -> List[T]:
100
+ """List all entities.
101
+
102
+ Returns:
103
+ List of all entities in the repository
104
+
105
+ Implementation Notes:
106
+ - Must be idempotent: multiple calls return same result
107
+ - Returns empty list if no entities exist
108
+ - Should return entities in a consistent order (e.g., by ID)
109
+ - For large datasets, consider pagination at the use case level
110
+
111
+ Workflow Context:
112
+ In Temporal workflows, this method is implemented as an activity
113
+ to ensure the list operation is durably stored and consistent
114
+ across workflow replays.
115
+
116
+ Default Implementation:
117
+ Base protocol provides a default that returns empty list.
118
+ Repository implementations should override this method as needed.
119
+
120
+ TODO: This default implementation returns empty list to avoid
121
+ breaking existing repositories. Specific repositories should
122
+ implement proper list_all() functionality as needed.
123
+ """
124
+ return []
125
+
126
+ async def generate_id(self) -> str:
127
+ """Generate a unique entity identifier.
128
+
129
+ This operation is non-deterministic and must be called from
130
+ workflow activities, not directly from workflow code.
131
+
132
+ Returns:
133
+ Unique entity ID string
134
+
135
+ Implementation Notes:
136
+ - Must generate globally unique identifiers
137
+ - May use UUIDs, database sequences, or distributed ID generators
138
+ - Should be fast and reliable
139
+ - Failure here should be rare but handled gracefully
140
+
141
+ Workflow Context:
142
+ In Temporal workflows, this method is implemented as an activity
143
+ to ensure the generated ID is durably stored and consistent
144
+ across workflow replays.
145
+ """
146
+ ...
@@ -0,0 +1,49 @@
1
+ """
2
+ Document repository interface defined as Protocol for the Capture, Extract,
3
+ Assemble, Publish workflow.
4
+
5
+ This module defines the core document storage and retrieval repository
6
+ protocol. The repository works with Document domain objects that use BinaryIO
7
+ streams for efficient content handling.
8
+
9
+ All repository operations follow the same principles as the sample
10
+ repositories:
11
+
12
+ - **Idempotency**: All methods are designed to be idempotent and safe for
13
+ retry. Multiple calls with the same parameters will produce the same
14
+ result without unintended side effects.
15
+
16
+ - **Workflow Safety**: All operations are safe to call from deterministic
17
+ workflow contexts. Non-deterministic operations (like ID generation) are
18
+ explicitly delegated to activities.
19
+
20
+ - **Domain Objects**: Methods accept and return domain objects or primitives,
21
+ never framework-specific types. Content streams are handled through the
22
+ BinaryIO interface.
23
+
24
+ - **Content Streaming**: Repository implementations should support both
25
+ small content (via BytesIO) and large content (via file streams) through
26
+ the unified ContentStream interface wrapping io.IOBase.
27
+
28
+ In Temporal workflow contexts, these protocols are implemented by workflow
29
+ stubs that delegate to activities for durability and proper error handling.
30
+ """
31
+
32
+ from typing import runtime_checkable, Protocol
33
+ from julee.domain.models import Document
34
+ from .base import BaseRepository
35
+
36
+
37
+ @runtime_checkable
38
+ class DocumentRepository(BaseRepository[Document], Protocol):
39
+ """Handles document storage and retrieval operations.
40
+
41
+ This repository manages the core document storage and metadata
42
+ operations within the Capture, Extract, Assemble, Publish workflow.
43
+
44
+ Inherits common CRUD operations (get, save, generate_id) from
45
+ BaseRepository. The save method handles both content and metadata
46
+ storage atomically.
47
+ """
48
+
49
+ pass
@@ -0,0 +1,52 @@
1
+ """
2
+ DocumentPolicyValidation repository interface defined as Protocol for the
3
+ Capture, Extract, Assemble, Publish workflow.
4
+
5
+ This module defines the core document policy validation storage and retrieval
6
+ repository protocol. The repository works with DocumentPolicyValidation
7
+ domain objects that track the validation of documents against policies.
8
+
9
+ All repository operations follow the same principles as the sample
10
+ repositories:
11
+
12
+ - **Idempotency**: All methods are designed to be idempotent and safe for
13
+ retry. Multiple calls with the same parameters will produce the same
14
+ result without unintended side effects.
15
+
16
+ - **Workflow Safety**: All operations are safe to call from deterministic
17
+ workflow contexts. Non-deterministic operations (like ID generation) are
18
+ explicitly delegated to activities.
19
+
20
+ - **Domain Objects**: Methods accept and return domain objects or primitives,
21
+ never framework-specific types. DocumentPolicyValidation contains
22
+ validation results, scores, and transformation tracking.
23
+
24
+ - **Validation Management**: Repository handles DocumentPolicyValidation
25
+ entities with their status tracking, score recording, and transformation
26
+ results for the quality assurance workflow.
27
+
28
+ In Temporal workflow contexts, these protocols are implemented by workflow
29
+ stubs that delegate to activities for durability and proper error handling.
30
+ """
31
+
32
+ from typing import runtime_checkable, Protocol
33
+ from julee.domain.models.policy import DocumentPolicyValidation
34
+ from .base import BaseRepository
35
+
36
+
37
+ @runtime_checkable
38
+ class DocumentPolicyValidationRepository(
39
+ BaseRepository[DocumentPolicyValidation], Protocol
40
+ ):
41
+ """Handles document policy validation storage and retrieval operations.
42
+
43
+ This repository manages DocumentPolicyValidation entities within the
44
+ Capture, Extract, Assemble, Publish workflow. These entities track the
45
+ complete lifecycle of validating documents against policies, including
46
+ initial validation scores, transformation results, and final outcomes.
47
+
48
+ Inherits common CRUD operations (get, save, generate_id) from
49
+ BaseRepository.
50
+ """
51
+
52
+ pass
@@ -0,0 +1,54 @@
1
+ """
2
+ KnowledgeServiceConfig repository interface defined as Protocol for the
3
+ Capture, Extract, Assemble, Publish workflow.
4
+
5
+ This module defines the knowledge service configuration repository protocol.
6
+ The repository works with KnowledgeService domain objects for metadata
7
+ persistence only. External service operations are handled by the service
8
+ layer.
9
+
10
+ All repository operations follow the same principles as the sample
11
+ repositories:
12
+
13
+ - **Idempotency**: All methods are designed to be idempotent and safe for
14
+ retry. Multiple calls with the same parameters will produce the same
15
+ result without unintended side effects.
16
+
17
+ - **Workflow Safety**: All operations are safe to call from deterministic
18
+ workflow contexts. Non-deterministic operations (like ID generation) are
19
+ explicitly delegated to activities.
20
+
21
+ - **Domain Objects**: Methods accept and return domain objects or primitives,
22
+ never framework-specific types. Results are returned as structured domain
23
+ objects.
24
+
25
+ - **External Service Integration**: Repository implementations handle the
26
+ complexities of integrating with external knowledge services while
27
+ maintaining a clean, consistent interface.
28
+
29
+ In Temporal workflow contexts, these protocols are implemented by workflow
30
+ stubs that delegate to activities for durability and proper error handling.
31
+ """
32
+
33
+ from typing import Protocol, runtime_checkable
34
+ from julee.domain.models.knowledge_service_config import (
35
+ KnowledgeServiceConfig,
36
+ )
37
+ from .base import BaseRepository
38
+
39
+
40
+ @runtime_checkable
41
+ class KnowledgeServiceConfigRepository(
42
+ BaseRepository[KnowledgeServiceConfig], Protocol
43
+ ):
44
+ """Handles knowledge service configuration persistence.
45
+
46
+ This repository manages knowledge service metadata and configuration
47
+ storage within the Capture, Extract, Assemble, Publish workflow.
48
+ External service operations are handled separately by the service layer.
49
+
50
+ Inherits common CRUD operations (get, save, generate_id) from
51
+ BaseRepository.
52
+ """
53
+
54
+ pass
@@ -0,0 +1,44 @@
1
+ """
2
+ KnowledgeServiceQuery repository interface defined as Protocol for the
3
+ Capture, Extract, Assemble, Publish workflow.
4
+
5
+ This module defines the knowledge service query repository protocol.
6
+ The repository works with KnowledgeServiceQuery domain objects for
7
+ storing and retrieving query configurations that define how to extract
8
+ data using external knowledge services.
9
+
10
+ All repository operations follow the same principles as the sample
11
+ repositories:
12
+ - Protocol-based design for Clean Architecture
13
+ - Type safety with runtime validation
14
+ - Idempotent operations
15
+ - Proper error handling
16
+ - Framework independence
17
+
18
+ The repository handles the persistence of query definitions including
19
+ prompts, assistant prompts, metadata, and service configurations
20
+ that are used during the assembly process.
21
+ """
22
+
23
+ from typing import Protocol, runtime_checkable
24
+
25
+ from julee.domain.models.assembly_specification import (
26
+ KnowledgeServiceQuery,
27
+ )
28
+ from .base import BaseRepository
29
+
30
+
31
+ @runtime_checkable
32
+ class KnowledgeServiceQueryRepository(BaseRepository[KnowledgeServiceQuery], Protocol):
33
+ """Handles knowledge service query persistence and retrieval.
34
+
35
+ This repository manages the storage and retrieval of
36
+ KnowledgeServiceQuery domain objects within the Capture, Extract,
37
+ Assemble, Publish workflow. These queries define how to extract
38
+ specific data using external knowledge services during assembly.
39
+
40
+ Inherits common CRUD operations (get, save, generate_id) from
41
+ BaseRepository.
42
+ """
43
+
44
+ pass
@@ -0,0 +1,49 @@
1
+ """
2
+ Policy repository interface defined as Protocol for the Capture, Extract,
3
+ Assemble, Publish workflow.
4
+
5
+ This module defines the core policy storage and retrieval repository
6
+ protocol. The repository works with Policy domain objects that define
7
+ validation criteria and optional transformations for documents.
8
+
9
+ All repository operations follow the same principles as the sample
10
+ repositories:
11
+
12
+ - **Idempotency**: All methods are designed to be idempotent and safe for
13
+ retry. Multiple calls with the same parameters will produce the same
14
+ result without unintended side effects.
15
+
16
+ - **Workflow Safety**: All operations are safe to call from deterministic
17
+ workflow contexts. Non-deterministic operations (like ID generation) are
18
+ explicitly delegated to activities.
19
+
20
+ - **Domain Objects**: Methods accept and return domain objects or primitives,
21
+ never framework-specific types. Policy contains validation scores and
22
+ optional transformation queries.
23
+
24
+ - **Policy Management**: Repository handles Policy entities with their
25
+ validation criteria, transformation queries, and status management for
26
+ the quality assurance workflow.
27
+
28
+ In Temporal workflow contexts, these protocols are implemented by workflow
29
+ stubs that delegate to activities for durability and proper error handling.
30
+ """
31
+
32
+ from typing import runtime_checkable, Protocol
33
+ from julee.domain.models import Policy
34
+ from .base import BaseRepository
35
+
36
+
37
+ @runtime_checkable
38
+ class PolicyRepository(BaseRepository[Policy], Protocol):
39
+ """Handles policy storage and retrieval operations.
40
+
41
+ This repository manages Policy entities within the Capture, Extract,
42
+ Assemble, Publish workflow. Policies define validation criteria and
43
+ optional transformations for documents in the quality assurance process.
44
+
45
+ Inherits common CRUD operations (get, save, generate_id) from
46
+ BaseRepository.
47
+ """
48
+
49
+ pass
@@ -0,0 +1,17 @@
1
+ """
2
+ Use cases for julee domain.
3
+
4
+ This package contains use case classes that orchestrate business logic
5
+ for the Capture, Extract, Assemble, Publish workflow while remaining
6
+ framework-agnostic following Clean Architecture principles.
7
+ """
8
+
9
+ from .extract_assemble_data import ExtractAssembleDataUseCase
10
+ from .initialize_system_data import InitializeSystemDataUseCase
11
+ from .validate_document import ValidateDocumentUseCase
12
+
13
+ __all__ = [
14
+ "ExtractAssembleDataUseCase",
15
+ "InitializeSystemDataUseCase",
16
+ "ValidateDocumentUseCase",
17
+ ]
@@ -0,0 +1,107 @@
1
+ """
2
+ Decorators for use case step error handling and logging.
3
+
4
+ This module provides decorators that implement consistent error handling
5
+ and logging patterns across all use cases in the julee domain,
6
+ following the patterns established in the sample use cases.
7
+ """
8
+
9
+ import logging
10
+ from functools import wraps
11
+ from typing import Any, Callable, Dict, Optional, TypeVar, Awaitable
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+ F = TypeVar("F", bound=Callable[..., Awaitable[Any]])
16
+
17
+
18
+ def try_use_case_step(
19
+ step_name: str,
20
+ extra_context: Optional[Dict[str, Any]] = None,
21
+ ) -> Callable[[F], F]:
22
+ """
23
+ Decorator that wraps use case steps with consistent error handling and
24
+ logging.
25
+
26
+ This decorator provides the same error handling and logging pattern used
27
+ in the sample use cases, eliminating boilerplate and ensuring consistency
28
+ across all use case implementations.
29
+
30
+ Args:
31
+ step_name: Name of the step (e.g., "assembly_id_generation")
32
+ extra_context: Optional additional context to include in all log
33
+ messages
34
+
35
+ Returns:
36
+ Decorated function with consistent error handling and logging
37
+
38
+ Example:
39
+ >>> @try_use_case_step(
40
+ ... "assembly_id_generation", {"document_id": "doc-123"}
41
+ ... )
42
+ >>> async def generate_assembly_id(self) -> str:
43
+ ... return await self.assembly_repo.generate_id()
44
+ """
45
+
46
+ def decorator(func: F) -> F:
47
+ @wraps(func)
48
+ async def wrapper(*args: Any, **kwargs: Any) -> Any:
49
+ # Build base logging context
50
+ log_context = {
51
+ "debug_step": f"before_{step_name}",
52
+ }
53
+ if extra_context:
54
+ log_context.update(extra_context)
55
+
56
+ # Pre-step logging
57
+ logger.debug(
58
+ f"About to {step_name}",
59
+ extra=log_context,
60
+ )
61
+
62
+ try:
63
+ # Execute the wrapped function
64
+ result = await func(*args, **kwargs)
65
+
66
+ # Success logging with result information
67
+ success_context = {
68
+ "debug_step": f"{step_name}_success",
69
+ }
70
+ if extra_context:
71
+ success_context.update(extra_context)
72
+
73
+ # Add result to logging context if it's a simple type
74
+ if isinstance(result, str):
75
+ success_context["result"] = result
76
+ elif hasattr(result, "id"):
77
+ success_context["result_id"] = result.id
78
+ elif hasattr(result, "__dict__"):
79
+ # For complex objects, just log the type
80
+ success_context["result_type"] = type(result).__name__
81
+
82
+ logger.debug(
83
+ f"{step_name} completed successfully",
84
+ extra=success_context,
85
+ )
86
+
87
+ return result
88
+
89
+ except Exception as e:
90
+ # Error logging
91
+ error_context = {
92
+ "error": str(e),
93
+ "error_type": type(e).__name__,
94
+ "debug_step": f"{step_name}_failed",
95
+ }
96
+ if extra_context:
97
+ error_context.update(extra_context)
98
+
99
+ logger.error(
100
+ f"Failed to {step_name}",
101
+ extra=error_context,
102
+ )
103
+ raise
104
+
105
+ return wrapper # type: ignore[return-value]
106
+
107
+ return decorator