harborrag-runtime 2.0.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 (271) hide show
  1. harborrag_runtime/__init__.py +22 -0
  2. harborrag_runtime/application/README.md +39 -0
  3. harborrag_runtime/application/__init__.py +39 -0
  4. harborrag_runtime/application/chat/__init__.py +7 -0
  5. harborrag_runtime/application/chat/citations.py +149 -0
  6. harborrag_runtime/application/chat/client.py +201 -0
  7. harborrag_runtime/application/chat/completion.py +92 -0
  8. harborrag_runtime/application/chat/completion_request.py +130 -0
  9. harborrag_runtime/application/chat/evidence.py +202 -0
  10. harborrag_runtime/application/chat/options.py +43 -0
  11. harborrag_runtime/application/chat/preparation.py +135 -0
  12. harborrag_runtime/application/chat/presenters.py +130 -0
  13. harborrag_runtime/application/chat/prompting.py +127 -0
  14. harborrag_runtime/application/chat/query_scope.py +146 -0
  15. harborrag_runtime/application/chat/replay.py +141 -0
  16. harborrag_runtime/application/chat/request_filters.py +134 -0
  17. harborrag_runtime/application/chat/retrieval.py +127 -0
  18. harborrag_runtime/application/chat/service.py +371 -0
  19. harborrag_runtime/application/composition/__init__.py +1 -0
  20. harborrag_runtime/application/composition/factories.py +106 -0
  21. harborrag_runtime/application/composition/resources.py +141 -0
  22. harborrag_runtime/application/composition/selection.py +65 -0
  23. harborrag_runtime/application/composition/service.py +550 -0
  24. harborrag_runtime/application/composition/tenant_models.py +45 -0
  25. harborrag_runtime/application/control_plane/__init__.py +1 -0
  26. harborrag_runtime/application/control_plane/active_runs.py +38 -0
  27. harborrag_runtime/application/control_plane/connection_models.py +109 -0
  28. harborrag_runtime/application/control_plane/connection_testing.py +91 -0
  29. harborrag_runtime/application/control_plane/connection_writes.py +227 -0
  30. harborrag_runtime/application/control_plane/connections.py +749 -0
  31. harborrag_runtime/application/control_plane/effect_recovery.py +235 -0
  32. harborrag_runtime/application/control_plane/projects.py +313 -0
  33. harborrag_runtime/application/control_plane/settings_import.py +239 -0
  34. harborrag_runtime/application/control_plane/settings_service.py +233 -0
  35. harborrag_runtime/application/control_plane/tenants.py +55 -0
  36. harborrag_runtime/application/errors.py +110 -0
  37. harborrag_runtime/application/ingestion/__init__.py +1 -0
  38. harborrag_runtime/application/ingestion/client.py +65 -0
  39. harborrag_runtime/application/ingestion/connection_sources.py +96 -0
  40. harborrag_runtime/application/ingestion/direct.py +120 -0
  41. harborrag_runtime/application/ingestion/follower.py +83 -0
  42. harborrag_runtime/application/ingestion/ports.py +174 -0
  43. harborrag_runtime/application/ingestion/progress_bridge.py +221 -0
  44. harborrag_runtime/application/ingestion/retry_selection.py +71 -0
  45. harborrag_runtime/application/ingestion/service.py +564 -0
  46. harborrag_runtime/application/ingestion/starter.py +78 -0
  47. harborrag_runtime/application/memory/__init__.py +21 -0
  48. harborrag_runtime/application/memory/client.py +114 -0
  49. harborrag_runtime/application/memory/composition.py +90 -0
  50. harborrag_runtime/application/memory/context.py +45 -0
  51. harborrag_runtime/application/memory/sessions.py +117 -0
  52. harborrag_runtime/application/ports.py +133 -0
  53. harborrag_runtime/application/retrieval/__init__.py +1 -0
  54. harborrag_runtime/application/retrieval/access.py +26 -0
  55. harborrag_runtime/application/scheduling/service.py +58 -0
  56. harborrag_runtime/application/schemas.py +15 -0
  57. harborrag_runtime/chat/README.md +40 -0
  58. harborrag_runtime/chat/__init__.py +18 -0
  59. harborrag_runtime/chat/composition.py +53 -0
  60. harborrag_runtime/chat/facade.py +46 -0
  61. harborrag_runtime/chat/service.py +183 -0
  62. harborrag_runtime/chat/tenant_clients.py +341 -0
  63. harborrag_runtime/chat/tenant_config.py +235 -0
  64. harborrag_runtime/chat/tenant_models.py +22 -0
  65. harborrag_runtime/composition/__init__.py +5 -0
  66. harborrag_runtime/composition/config_store.py +53 -0
  67. harborrag_runtime/composition/connection_removal.py +120 -0
  68. harborrag_runtime/composition/connection_stores.py +107 -0
  69. harborrag_runtime/composition/control_plane.py +401 -0
  70. harborrag_runtime/composition/mcp_auth.py +39 -0
  71. harborrag_runtime/composition/readers.py +113 -0
  72. harborrag_runtime/composition/resources.py +336 -0
  73. harborrag_runtime/composition/storage_providers.py +113 -0
  74. harborrag_runtime/config/__init__.py +84 -0
  75. harborrag_runtime/config/checkout.py +212 -0
  76. harborrag_runtime/config/chunking.py +167 -0
  77. harborrag_runtime/config/connectors/__init__.py +19 -0
  78. harborrag_runtime/config/connectors/fingerprints.py +54 -0
  79. harborrag_runtime/config/connectors/importing.py +611 -0
  80. harborrag_runtime/config/connectors/loader.py +95 -0
  81. harborrag_runtime/config/connectors/models/__init__.py +30 -0
  82. harborrag_runtime/config/connectors/models/atlassian.py +199 -0
  83. harborrag_runtime/config/connectors/models/builder.py +208 -0
  84. harborrag_runtime/config/connectors/models/common.py +45 -0
  85. harborrag_runtime/config/connectors/models/fields.py +134 -0
  86. harborrag_runtime/config/connectors/models/github.py +143 -0
  87. harborrag_runtime/config/connectors/models/local_file.py +119 -0
  88. harborrag_runtime/config/connectors/models/registry.py +149 -0
  89. harborrag_runtime/config/connectors/models/sharepoint.py +186 -0
  90. harborrag_runtime/config/connectors/models/spec.py +563 -0
  91. harborrag_runtime/config/connectors/parsing.py +275 -0
  92. harborrag_runtime/config/connectors/providers.py +177 -0
  93. harborrag_runtime/config/connectors/schemas.py +215 -0
  94. harborrag_runtime/config/errors.py +26 -0
  95. harborrag_runtime/config/graph_build.py +335 -0
  96. harborrag_runtime/config/graph_build_loading.py +38 -0
  97. harborrag_runtime/config/loading.py +245 -0
  98. harborrag_runtime/config/models.py +95 -0
  99. harborrag_runtime/config/ontology_loading.py +76 -0
  100. harborrag_runtime/config/parsers/__init__.py +19 -0
  101. harborrag_runtime/config/parsers/loader.py +85 -0
  102. harborrag_runtime/config/parsers/parsing.py +285 -0
  103. harborrag_runtime/config/parsers/providers.py +305 -0
  104. harborrag_runtime/config/parsers/schemas.py +614 -0
  105. harborrag_runtime/config/settings.py +378 -0
  106. harborrag_runtime/config/settings_document.py +133 -0
  107. harborrag_runtime/config/temporal.py +331 -0
  108. harborrag_runtime/config/temporal_loading.py +310 -0
  109. harborrag_runtime/config_store/__init__.py +5 -0
  110. harborrag_runtime/config_store/defaults.py +47 -0
  111. harborrag_runtime/config_store/provider.py +153 -0
  112. harborrag_runtime/config_store/run_settings.py +72 -0
  113. harborrag_runtime/connections/__init__.py +27 -0
  114. harborrag_runtime/connections/secrets.py +348 -0
  115. harborrag_runtime/contracts.py +237 -0
  116. harborrag_runtime/document_stage_catalog.py +82 -0
  117. harborrag_runtime/errors.py +64 -0
  118. harborrag_runtime/events/__init__.py +3 -0
  119. harborrag_runtime/events/in_process.py +100 -0
  120. harborrag_runtime/execution/__init__.py +26 -0
  121. harborrag_runtime/execution/contracts.py +32 -0
  122. harborrag_runtime/execution/direct.py +169 -0
  123. harborrag_runtime/execution/gateway.py +97 -0
  124. harborrag_runtime/execution/source_conversion.py +61 -0
  125. harborrag_runtime/execution/source_submission.py +278 -0
  126. harborrag_runtime/execution/submission.py +64 -0
  127. harborrag_runtime/execution/task_registry.py +387 -0
  128. harborrag_runtime/execution/temporal.py +165 -0
  129. harborrag_runtime/ingestion/README.md +79 -0
  130. harborrag_runtime/ingestion/__init__.py +59 -0
  131. harborrag_runtime/ingestion/chunking_profile.py +97 -0
  132. harborrag_runtime/ingestion/composition.py +279 -0
  133. harborrag_runtime/ingestion/connection_checks.py +239 -0
  134. harborrag_runtime/ingestion/connections.py +507 -0
  135. harborrag_runtime/ingestion/document/__init__.py +1 -0
  136. harborrag_runtime/ingestion/document/normalization.py +14 -0
  137. harborrag_runtime/ingestion/document/normalizers/__init__.py +9 -0
  138. harborrag_runtime/ingestion/document/normalizers/builtins.py +39 -0
  139. harborrag_runtime/ingestion/document/normalizers/transform.py +30 -0
  140. harborrag_runtime/ingestion/document/run_tools.py +152 -0
  141. harborrag_runtime/ingestion/failure_classification.py +82 -0
  142. harborrag_runtime/ingestion/field_indexes.py +56 -0
  143. harborrag_runtime/ingestion/maintenance/__init__.py +1 -0
  144. harborrag_runtime/ingestion/maintenance/connection_removal.py +115 -0
  145. harborrag_runtime/ingestion/maintenance/projection_admin.py +180 -0
  146. harborrag_runtime/ingestion/maintenance/relation_repair.py +555 -0
  147. harborrag_runtime/ingestion/maintenance/retention.py +353 -0
  148. harborrag_runtime/ingestion/observability.py +3 -0
  149. harborrag_runtime/ingestion/profiles.py +127 -0
  150. harborrag_runtime/ingestion/runtime_builder.py +339 -0
  151. harborrag_runtime/ingestion/source/__init__.py +1 -0
  152. harborrag_runtime/ingestion/source/descriptor_mapping.py +144 -0
  153. harborrag_runtime/ingestion/source/discovery.py +290 -0
  154. harborrag_runtime/ingestion/source/documents.py +184 -0
  155. harborrag_runtime/ingestion/source/finalization.py +288 -0
  156. harborrag_runtime/ingestion/source/operations.py +175 -0
  157. harborrag_runtime/ingestion/source/plan.py +413 -0
  158. harborrag_runtime/ingestion/source/retry.py +150 -0
  159. harborrag_runtime/ingestion/source/service.py +470 -0
  160. harborrag_runtime/ingestion/source/skips.py +172 -0
  161. harborrag_runtime/ingestion_contracts.py +107 -0
  162. harborrag_runtime/memory/__init__.py +81 -0
  163. harborrag_runtime/memory/access.py +47 -0
  164. harborrag_runtime/memory/administration.py +460 -0
  165. harborrag_runtime/memory/context/__init__.py +5 -0
  166. harborrag_runtime/memory/context/result.py +20 -0
  167. harborrag_runtime/memory/directory.py +166 -0
  168. harborrag_runtime/memory/erasure.py +122 -0
  169. harborrag_runtime/memory/locks.py +170 -0
  170. harborrag_runtime/memory/messages.py +202 -0
  171. harborrag_runtime/memory/presenters.py +117 -0
  172. harborrag_runtime/memory/projects.py +38 -0
  173. harborrag_runtime/memory/tiers/__init__.py +1 -0
  174. harborrag_runtime/memory/tiers/in_memory.py +491 -0
  175. harborrag_runtime/memory/titles.py +32 -0
  176. harborrag_runtime/memory/usage.py +131 -0
  177. harborrag_runtime/observability/__init__.py +1 -0
  178. harborrag_runtime/observability/connector_metrics.py +14 -0
  179. harborrag_runtime/observability/discovery_metrics.py +46 -0
  180. harborrag_runtime/observability/model.py +410 -0
  181. harborrag_runtime/observability/observability_types.py +47 -0
  182. harborrag_runtime/observability/stage_observation.py +96 -0
  183. harborrag_runtime/observability/tool_audit.py +17 -0
  184. harborrag_runtime/plugins.py +56 -0
  185. harborrag_runtime/rate_limiting.py +39 -0
  186. harborrag_runtime/reader_contracts.py +149 -0
  187. harborrag_runtime/retrieval/__init__.py +1 -0
  188. harborrag_runtime/retrieval/composition.py +174 -0
  189. harborrag_runtime/retrieval/facades.py +224 -0
  190. harborrag_runtime/scheduling/__init__.py +48 -0
  191. harborrag_runtime/scheduling/config.py +185 -0
  192. harborrag_runtime/scheduling/errors.py +37 -0
  193. harborrag_runtime/scheduling/models.py +146 -0
  194. harborrag_runtime/scheduling/service.py +297 -0
  195. harborrag_runtime/scheduling/validation.py +213 -0
  196. harborrag_runtime/sdk/__init__.py +86 -0
  197. harborrag_runtime/sdk/configuration.py +44 -0
  198. harborrag_runtime/sdk/facades.py +47 -0
  199. harborrag_runtime/sdk/runtime.py +242 -0
  200. harborrag_runtime/security/__init__.py +1 -0
  201. harborrag_runtime/security/api_key_operations.py +236 -0
  202. harborrag_runtime/serialization.py +35 -0
  203. harborrag_runtime/temporal/__init__.py +19 -0
  204. harborrag_runtime/temporal/activity_observability.py +313 -0
  205. harborrag_runtime/temporal/client.py +580 -0
  206. harborrag_runtime/temporal/connection.py +39 -0
  207. harborrag_runtime/temporal/conversion.py +147 -0
  208. harborrag_runtime/temporal/dispatch.py +38 -0
  209. harborrag_runtime/temporal/document_workflow.py +154 -0
  210. harborrag_runtime/temporal/failure_handling.py +68 -0
  211. harborrag_runtime/temporal/gateway.py +121 -0
  212. harborrag_runtime/temporal/heartbeats.py +67 -0
  213. harborrag_runtime/temporal/identity.py +14 -0
  214. harborrag_runtime/temporal/ingestion_activities.py +435 -0
  215. harborrag_runtime/temporal/maintenance_activities.py +251 -0
  216. harborrag_runtime/temporal/maintenance_schemas.py +88 -0
  217. harborrag_runtime/temporal/optional.py +19 -0
  218. harborrag_runtime/temporal/plan_resolver.py +149 -0
  219. harborrag_runtime/temporal/policies.py +18 -0
  220. harborrag_runtime/temporal/reindex_workflow.py +71 -0
  221. harborrag_runtime/temporal/retry_activities.py +147 -0
  222. harborrag_runtime/temporal/retry_workflow.py +222 -0
  223. harborrag_runtime/temporal/sandbox.py +51 -0
  224. harborrag_runtime/temporal/schedules.py +341 -0
  225. harborrag_runtime/temporal/schemas.py +482 -0
  226. harborrag_runtime/temporal/source_activities.py +590 -0
  227. harborrag_runtime/temporal/source_batch_workflow.py +226 -0
  228. harborrag_runtime/temporal/source_workflow.py +908 -0
  229. harborrag_runtime/temporal/submission.py +23 -0
  230. harborrag_runtime/temporal/worker.py +478 -0
  231. harborrag_runtime/temporal/worker_registry.py +141 -0
  232. harborrag_runtime/temporal_models.py +227 -0
  233. harborrag_runtime/testing/chat_fakes.py +309 -0
  234. harborrag_runtime/testing/chat_service_double.py +126 -0
  235. harborrag_runtime/testing/connection_fakes.py +278 -0
  236. harborrag_runtime/testing/memory_fakes.py +128 -0
  237. harborrag_runtime/topology/__init__.py +1 -0
  238. harborrag_runtime/topology/budgeted_extractor.py +110 -0
  239. harborrag_runtime/topology/chunk_runner.py +41 -0
  240. harborrag_runtime/topology/composition.py +168 -0
  241. harborrag_runtime/topology/configuration.py +126 -0
  242. harborrag_runtime/topology/contextual.py +140 -0
  243. harborrag_runtime/topology/derived.py +238 -0
  244. harborrag_runtime/topology/derived_coverage.py +5 -0
  245. harborrag_runtime/topology/derived_dispatch.py +63 -0
  246. harborrag_runtime/topology/derived_factory.py +175 -0
  247. harborrag_runtime/topology/derived_models.py +251 -0
  248. harborrag_runtime/topology/derived_projection.py +127 -0
  249. harborrag_runtime/topology/description_factory.py +81 -0
  250. harborrag_runtime/topology/embedding_profile.py +85 -0
  251. harborrag_runtime/topology/entity_summary_index.py +304 -0
  252. harborrag_runtime/topology/maintenance.py +126 -0
  253. harborrag_runtime/topology/operations.py +277 -0
  254. harborrag_runtime/topology/parent_materializer.py +167 -0
  255. harborrag_runtime/topology/run_cost.py +43 -0
  256. harborrag_runtime/topology/security_operations.py +46 -0
  257. harborrag_runtime/topology/service.py +349 -0
  258. harborrag_runtime/topology/summary_factory.py +164 -0
  259. harborrag_runtime/topology/summary_inputs.py +129 -0
  260. harborrag_runtime/topology/summary_operations.py +128 -0
  261. harborrag_runtime/topology/summary_policy.py +39 -0
  262. harborrag_runtime/topology/summary_products.py +43 -0
  263. harborrag_runtime/topology/summary_service.py +625 -0
  264. harborrag_runtime/topology/summary_worker.py +129 -0
  265. harborrag_runtime/topology/summary_workflow.py +32 -0
  266. harborrag_runtime/topology/worker.py +101 -0
  267. harborrag_runtime/topology/workflow.py +32 -0
  268. harborrag_runtime-2.0.0.dist-info/METADATA +267 -0
  269. harborrag_runtime-2.0.0.dist-info/RECORD +271 -0
  270. harborrag_runtime-2.0.0.dist-info/WHEEL +4 -0
  271. harborrag_runtime-2.0.0.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,237 @@
1
+ """Stable request and response contracts for the runtime SDK.
2
+
3
+ The ``harborrag`` package re-exports these as public API. Add a field only with
4
+ a default, so code that already builds them keeps working.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from dataclasses import dataclass, field
10
+ from enum import StrEnum
11
+ from uuid import uuid4
12
+
13
+ from harborrag_core.contracts.reader import (
14
+ EntityFindRequest as EntityFindRequest,
15
+ )
16
+ from harborrag_core.contracts.reader import (
17
+ EntityFindResponse as EntityFindResponse,
18
+ )
19
+ from harborrag_core.contracts.reader import (
20
+ EntityMatch as EntityMatch,
21
+ )
22
+ from harborrag_core.contracts.reader import (
23
+ EntityResolveRequest as EntityResolveRequest,
24
+ )
25
+ from harborrag_core.contracts.reader import (
26
+ EntityResolveResponse as EntityResolveResponse,
27
+ )
28
+ from harborrag_core.contracts.reader import (
29
+ EvidenceFetchRequest as EvidenceFetchRequest,
30
+ )
31
+ from harborrag_core.contracts.reader import (
32
+ EvidenceFetchResponse as EvidenceFetchResponse,
33
+ )
34
+ from harborrag_core.contracts.reader import (
35
+ GraphPathRequest as GraphPathRequest,
36
+ )
37
+ from harborrag_core.contracts.reader import (
38
+ GraphPathResponse as GraphPathResponse,
39
+ )
40
+ from harborrag_core.contracts.reader import (
41
+ GraphSubgraphRequest as GraphSubgraphRequest,
42
+ )
43
+ from harborrag_core.contracts.reader import (
44
+ GraphSubgraphResponse as GraphSubgraphResponse,
45
+ )
46
+ from harborrag_core.contracts.reader import (
47
+ GraphTripletRequest as GraphTripletRequest,
48
+ )
49
+ from harborrag_core.contracts.reader import (
50
+ GraphTripletResponse as GraphTripletResponse,
51
+ )
52
+ from harborrag_core.contracts.reader import (
53
+ RelationSearchRequest as RelationSearchRequest,
54
+ )
55
+ from harborrag_core.contracts.reader import (
56
+ RelationSearchResponse as RelationSearchResponse,
57
+ )
58
+ from harborrag_core.contracts.reader import (
59
+ RetrievalLane as RetrievalLane,
60
+ )
61
+ from harborrag_core.contracts.reader import (
62
+ RetrievalMode as RetrievalMode,
63
+ )
64
+ from harborrag_core.contracts.reader import (
65
+ RetrievalRequest as RetrievalRequest,
66
+ )
67
+ from harborrag_core.contracts.reader import (
68
+ RetrievalResponse as RetrievalResponse,
69
+ )
70
+ from harborrag_core.contracts.reader import (
71
+ SemanticPathRequest as SemanticPathRequest,
72
+ )
73
+ from harborrag_core.contracts.reader import (
74
+ SemanticPathResponse as SemanticPathResponse,
75
+ )
76
+ from harborrag_core.ingestion.limits import (
77
+ validate_discovery_concurrency,
78
+ validate_discovery_page_size,
79
+ validate_document_concurrency,
80
+ )
81
+ from harborrag_core.security import AccessContext
82
+ from harborrag_runtime.reader_contracts import (
83
+ DocumentContextChunk as DocumentContextChunk,
84
+ )
85
+ from harborrag_runtime.reader_contracts import (
86
+ DocumentContextRequest as DocumentContextRequest,
87
+ )
88
+ from harborrag_runtime.reader_contracts import (
89
+ DocumentContextResponse as DocumentContextResponse,
90
+ )
91
+ from harborrag_runtime.reader_contracts import (
92
+ EvidenceReadItem as EvidenceReadItem,
93
+ )
94
+ from harborrag_runtime.reader_contracts import (
95
+ EvidenceReadRequest as EvidenceReadRequest,
96
+ )
97
+ from harborrag_runtime.reader_contracts import (
98
+ EvidenceReadResponse as EvidenceReadResponse,
99
+ )
100
+ from harborrag_runtime.reader_contracts import (
101
+ EvidenceReadSelector as EvidenceReadSelector,
102
+ )
103
+ from harborrag_runtime.reader_contracts import (
104
+ GraphNodeResolveRequest as GraphNodeResolveRequest,
105
+ )
106
+ from harborrag_runtime.reader_contracts import (
107
+ GraphNodeResolveResponse as GraphNodeResolveResponse,
108
+ )
109
+ from harborrag_runtime.reader_contracts import (
110
+ SourceListRequest as SourceListRequest,
111
+ )
112
+ from harborrag_runtime.reader_contracts import (
113
+ SourceListResponse as SourceListResponse,
114
+ )
115
+
116
+
117
+ class ExecutionMode(StrEnum):
118
+ """Where the SDK runs an ingestion.
119
+
120
+ Attributes:
121
+ DIRECT: Inline in the calling process, without Temporal.
122
+ TEMPORAL: As a durable Temporal workflow that can be paused and cancelled.
123
+ """
124
+
125
+ DIRECT = "direct"
126
+ TEMPORAL = "temporal"
127
+
128
+
129
+ @dataclass(frozen=True, slots=True)
130
+ class IngestionRequest:
131
+ """One ingestion run of a stored connection, with its scope and tuning.
132
+
133
+ Attributes:
134
+ access: Caller and the tenant the run acts in.
135
+ connector_name: ``source_key`` of the connection when ``connection_id`` is unset.
136
+ task_id: Stable run ID. Generated when omitted.
137
+ connection_id: ``source_key`` of the connection. Overrides ``connector_name``.
138
+ source_scope_id: Stable source scope ID. Derived when omitted.
139
+ path: Path inside the connector's source root.
140
+ pattern: Case-insensitive substring, or a glob matched against the path
141
+ relative to the source root.
142
+ recursive: Whether to traverse the source recursively.
143
+ updated_after: Only content updated after this ISO-8601 timestamp.
144
+ limit: Stop after this many artifacts. Positive when set.
145
+ include_attachments: Whether to admit attachments as documents.
146
+ filters: Connector filters. A local connector rejects unknown keys.
147
+ force_reprocess: Whether to reprocess unchanged documents.
148
+ discovery_page_size: Items per discovery page, from 1 to 300.
149
+ discovery_concurrency: Items described at once during discovery, from 1 to 32.
150
+ document_concurrency: Documents processed at once, from 1 to 100.
151
+ """
152
+
153
+ access: AccessContext
154
+ connector_name: str
155
+ task_id: str = field(default_factory=lambda: f"ingest-{uuid4().hex}")
156
+ connection_id: str | None = None
157
+ source_scope_id: str | None = None
158
+ path: str | None = None
159
+ pattern: str | None = None
160
+ recursive: bool = True
161
+ updated_after: str | None = None
162
+ limit: int | None = None
163
+ include_attachments: bool = True
164
+ filters: dict[str, object] = field(default_factory=dict)
165
+ force_reprocess: bool = False
166
+ discovery_page_size: int = 50
167
+ discovery_concurrency: int = 4
168
+ document_concurrency: int = 8
169
+
170
+ def __post_init__(self) -> None:
171
+ """Reject blank identities and out-of-range limits.
172
+
173
+ Raises:
174
+ ValueError: An identity is blank, or a limit or concurrency is out of range.
175
+ """
176
+ if not self.connector_name.strip() or not self.task_id.strip():
177
+ raise ValueError("ingestion connector and task identities must be non-empty")
178
+ if self.limit is not None and self.limit < 1:
179
+ raise ValueError("ingestion limit must be positive")
180
+ validate_document_concurrency(self.document_concurrency)
181
+ validate_discovery_page_size(self.discovery_page_size)
182
+ validate_discovery_concurrency(self.discovery_concurrency)
183
+
184
+
185
+ @dataclass(frozen=True, slots=True)
186
+ class IngestionTaskReference:
187
+ """The durable run that a submit started.
188
+
189
+ Attributes:
190
+ task_id: Run ID to pass to status, pause, resume and cancel.
191
+ workflow_id: Temporal workflow ID, when the run has one.
192
+ """
193
+
194
+ task_id: str
195
+ workflow_id: str | None = None
196
+
197
+
198
+ @dataclass(frozen=True, slots=True)
199
+ class IngestionResult:
200
+ """Outcome of a finished ingestion run.
201
+
202
+ Attributes:
203
+ task_id: Run ID.
204
+ status: Final run state, such as ``COMPLETED`` or ``PARTIAL``.
205
+ discovered: Documents the run planned to process.
206
+ published: Documents the run published.
207
+ unchanged: Documents left as they were because their content had not changed.
208
+ failed: Documents that failed.
209
+ skipped: Items the run skipped, at discovery or later, for example because a
210
+ document failed to parse. Discovery skips are not in ``discovered``, and
211
+ a later skip also counts in ``failed``.
212
+ """
213
+
214
+ task_id: str
215
+ status: str
216
+ discovered: int
217
+ published: int
218
+ unchanged: int
219
+ failed: int
220
+ skipped: int = 0
221
+
222
+
223
+ @dataclass(frozen=True, slots=True)
224
+ class IngestionStatus:
225
+ """Workflow state of a durable run, without progress counts.
226
+
227
+ Attributes:
228
+ task_id: Run ID.
229
+ status: The workflow's own state, such as ``RUNNING``.
230
+ paused: Whether the run has stopped at a safe boundary after a pause.
231
+ cancel_requested: Whether a cancel was requested.
232
+ """
233
+
234
+ task_id: str
235
+ status: str
236
+ paused: bool = False
237
+ cancel_requested: bool = False
@@ -0,0 +1,82 @@
1
+ """Pure, sandbox-safe catalog of ordered document processing stages."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+
7
+ from harborrag_runtime.temporal_models import TaskQueueRole
8
+
9
+
10
+ @dataclass(frozen=True, slots=True)
11
+ class DocumentStageSpec:
12
+ name: str
13
+ activity: str
14
+ task_queue: str
15
+
16
+ @property
17
+ def method_name(self) -> str:
18
+ """Return the matching ``IngestionActivities`` method name."""
19
+ return self.activity.removeprefix("harborrag.")
20
+
21
+ @property
22
+ def task_queue_role(self) -> TaskQueueRole:
23
+ """Return the logical lane represented by the stable default queue."""
24
+ roles: dict[str, TaskQueueRole] = {
25
+ "harborrag-transform": "transform",
26
+ "harborrag-io": "io",
27
+ "harborrag-model": "model",
28
+ "harborrag-index": "index",
29
+ }
30
+ try:
31
+ return roles[self.task_queue]
32
+ except KeyError as exc:
33
+ raise ValueError(f"unknown document-stage task queue: {self.task_queue}") from exc
34
+
35
+
36
+ DOCUMENT_STAGE_CATALOG = (
37
+ DocumentStageSpec(
38
+ "SyncContentUnits",
39
+ "harborrag.sync_content_units",
40
+ "harborrag-transform",
41
+ ),
42
+ DocumentStageSpec(
43
+ "PersistCanonical",
44
+ "harborrag.persist_canonical",
45
+ "harborrag-io",
46
+ ),
47
+ DocumentStageSpec(
48
+ "ChunkAndValidate",
49
+ "harborrag.chunk_and_validate",
50
+ "harborrag-transform",
51
+ ),
52
+ DocumentStageSpec(
53
+ "EncodeChunks",
54
+ "harborrag.encode_chunks",
55
+ "harborrag-model",
56
+ ),
57
+ DocumentStageSpec(
58
+ "BuildRelations",
59
+ "harborrag.build_relations",
60
+ "harborrag-transform",
61
+ ),
62
+ DocumentStageSpec(
63
+ "BuildProjections",
64
+ "harborrag.build_projections",
65
+ "harborrag-transform",
66
+ ),
67
+ DocumentStageSpec(
68
+ "WriteVectorProjection",
69
+ "harborrag.write_vector_projection",
70
+ "harborrag-index",
71
+ ),
72
+ DocumentStageSpec(
73
+ "WriteGraphProjection",
74
+ "harborrag.write_graph_projection",
75
+ "harborrag-index",
76
+ ),
77
+ DocumentStageSpec(
78
+ "VerifyProjections",
79
+ "harborrag.verify_projections",
80
+ "harborrag-index",
81
+ ),
82
+ )
@@ -0,0 +1,64 @@
1
+ """Errors raised only at the runtime and Temporal boundary."""
2
+
3
+ from __future__ import annotations
4
+
5
+
6
+ class RuntimeConfigurationError(ValueError):
7
+ """Raised when runtime configuration is internally inconsistent."""
8
+
9
+
10
+ class MissingOptionalDependencyError(RuntimeConfigurationError):
11
+ """A requested runtime capability was not installed."""
12
+
13
+
14
+ class VectorIndexSchemaError(RuntimeConfigurationError):
15
+ """The existing vector index does not match the configured vector schema.
16
+
17
+ Raised while a run provisions its projection structures. Retrying cannot
18
+ help, and the operator needs both dimensions to decide between changing the
19
+ configuration and re-creating the index.
20
+ """
21
+
22
+
23
+ class RuntimeConnectionError(ConnectionError):
24
+ """Raised when the runtime cannot reach Temporal or a storage backend."""
25
+
26
+
27
+ class WorkflowSubmissionError(RuntimeError):
28
+ """Raised when an ingestion workflow cannot be submitted."""
29
+
30
+
31
+ class WorkflowRunAlreadyStartedError(WorkflowSubmissionError):
32
+ """Raised when the requested run ID is already in use.
33
+
34
+ Separated from the general submission failure so transports can answer a
35
+ reused run ID with "conflict" rather than reporting an upstream fault. Named
36
+ distinctly from ``temporalio.exceptions.WorkflowAlreadyStartedError``, which
37
+ it wraps, so both can be referenced in the same module.
38
+ """
39
+
40
+
41
+ class WorkflowOperationError(RuntimeError):
42
+ """Raised when a query, signal, update, or cancellation fails."""
43
+
44
+
45
+ class WorkflowNotFoundError(WorkflowOperationError):
46
+ """Raised when the addressed ingestion run does not exist in Temporal.
47
+
48
+ Separated from the general operation failure so transports can answer a
49
+ missing run with "not found" instead of reporting an upstream fault.
50
+ """
51
+
52
+
53
+ class WorkflowNotRunningError(WorkflowOperationError):
54
+ """Raised when a control action addresses a run that has already finished.
55
+
56
+ Temporal answers NOT_FOUND for signals sent to a closed execution, which
57
+ is indistinguishable from a genuinely unknown run even though queries still
58
+ succeed against it. This names the difference so operators are not sent
59
+ looking for a run that plainly exists.
60
+ """
61
+
62
+
63
+ class WorkerStartupError(RuntimeError):
64
+ """Raised when a runtime worker cannot be constructed or started."""
@@ -0,0 +1,3 @@
1
+ from .in_process import InProcessEventBus
2
+
3
+ __all__ = ["InProcessEventBus"]
@@ -0,0 +1,100 @@
1
+ """In-process EventBusPort: asyncio queues, one process, streams indefinitely.
2
+
3
+ Single-process dev/prod implementation; a Redis-backed one is future work
4
+ once the API and workers run as separate processes. Lives in harborrag_runtime
5
+ (not harborrag_adapters) because it has no I/O dependency of its own -- it's a
6
+ process-local singleton, not a repository over external storage.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import asyncio
12
+ import logging
13
+ import weakref
14
+ from collections.abc import AsyncGenerator
15
+
16
+ from harborrag_core.contracts.events import HarborEvent
17
+
18
+ logger = logging.getLogger("harborrag.runtime.events.in_process")
19
+
20
+ _Subscription = tuple[str, "asyncio.Queue[HarborEvent]"]
21
+
22
+ # A subscriber that never reads (a stalled/leaked consumer) must not retain
23
+ # every event forever, so a full queue drops its oldest entry rather than
24
+ # blocking publish() or growing unbounded. A drop is a gap in the stored
25
+ # per-task sequence: the ingestion event stream detects the gap and reads the
26
+ # missing events back from the store, so no event type depends on coalescing.
27
+ _DEFAULT_MAX_QUEUE_SIZE = 256
28
+
29
+
30
+ class InProcessEventBus:
31
+ """EventBusPort over per-subscriber asyncio queues, filtered by name prefix."""
32
+
33
+ def __init__(self, max_queue_size: int = _DEFAULT_MAX_QUEUE_SIZE) -> None:
34
+ self._max_queue_size = max_queue_size
35
+ self._subscribers: list[_Subscription] = []
36
+
37
+ async def publish(self, event: HarborEvent) -> None:
38
+ """Deliver the event to every subscriber whose prefix matches.
39
+
40
+ Never blocks: a full queue drops its oldest entry to make room
41
+ rather than making publish() wait on a slow consumer.
42
+ """
43
+ for prefix, queue in list(self._subscribers):
44
+ if not event.name.startswith(prefix):
45
+ continue
46
+ while True:
47
+ try:
48
+ queue.put_nowait(event)
49
+ break
50
+ except asyncio.QueueFull:
51
+ try:
52
+ queue.get_nowait()
53
+ except asyncio.QueueEmpty:
54
+ continue
55
+ logger.warning(
56
+ "Subscriber queue full for prefix=%r; dropped the oldest event "
57
+ "to admit event.name=%r",
58
+ prefix,
59
+ event.name,
60
+ )
61
+
62
+ def subscribe(self, name_prefix: str) -> AsyncGenerator[HarborEvent, None]:
63
+ """Stream events whose name starts with name_prefix, indefinitely.
64
+
65
+ Registration happens synchronously, here, before returning -- not
66
+ inside the async generator below, which wouldn't run any code until
67
+ first iterated. That laziness would otherwise open a gap: a caller
68
+ that reads a DB backlog and only *then* starts consuming this stream
69
+ must be guaranteed that anything published in between is captured
70
+ the moment subscribe() is called, not the moment iteration begins.
71
+
72
+ The flip side of that same laziness: if the returned iterator is
73
+ abandoned before it's ever iterated -- e.g. a caller subscribes,
74
+ then gets cancelled while still reading a backlog -- the async
75
+ generator's frame never starts, so its try/finally below never
76
+ runs and closing/GC'ing it would leave the subscription registered
77
+ forever. A weakref.finalize tied to the generator object itself
78
+ (not to its execution reaching the finally) closes that gap: it
79
+ fires on GC regardless of whether the generator ever started.
80
+ """
81
+ queue: asyncio.Queue[HarborEvent] = asyncio.Queue(maxsize=self._max_queue_size)
82
+ subscription = (name_prefix, queue)
83
+ self._subscribers.append(subscription)
84
+ agen = self._consume(subscription)
85
+ weakref.finalize(agen, self._discard, subscription)
86
+ return agen
87
+
88
+ def _discard(self, subscription: _Subscription) -> None:
89
+ try:
90
+ self._subscribers.remove(subscription)
91
+ except ValueError:
92
+ pass
93
+
94
+ async def _consume(self, subscription: _Subscription) -> AsyncGenerator[HarborEvent, None]:
95
+ _, queue = subscription
96
+ try:
97
+ while True:
98
+ yield await queue.get()
99
+ finally:
100
+ self._discard(subscription)
@@ -0,0 +1,26 @@
1
+ """Direct and durable ingestion execution strategies."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from harborrag_runtime.config.settings import RuntimeSettings
6
+ from harborrag_runtime.contracts import ExecutionMode
7
+ from harborrag_runtime.execution.contracts import IngestionExecutor
8
+
9
+
10
+ def build_ingestion_executor(
11
+ mode: ExecutionMode,
12
+ settings: RuntimeSettings,
13
+ ) -> IngestionExecutor:
14
+ """Select an execution strategy without leaking its implementation to the SDK."""
15
+
16
+ if mode is ExecutionMode.DIRECT:
17
+ from harborrag_runtime.execution.direct import DirectIngestionExecutor
18
+
19
+ return DirectIngestionExecutor(settings)
20
+
21
+ from harborrag_runtime.execution.temporal import TemporalIngestionExecutor
22
+
23
+ return TemporalIngestionExecutor(settings)
24
+
25
+
26
+ __all__ = ["IngestionExecutor", "build_ingestion_executor"]
@@ -0,0 +1,32 @@
1
+ """Execution strategy contracts used by the SDK orchestration layer."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Protocol
6
+
7
+ from harborrag_runtime.contracts import (
8
+ IngestionRequest,
9
+ IngestionResult,
10
+ IngestionStatus,
11
+ IngestionTaskReference,
12
+ )
13
+
14
+
15
+ class IngestionExecutor(Protocol):
16
+ async def start(self) -> None: ...
17
+
18
+ async def run(self, request: IngestionRequest) -> IngestionResult: ...
19
+
20
+ async def aclose(self) -> None: ...
21
+
22
+
23
+ class DurableIngestionExecutor(IngestionExecutor, Protocol):
24
+ async def submit(self, request: IngestionRequest) -> IngestionTaskReference: ...
25
+
26
+ async def status(self, task_id: str) -> IngestionStatus: ...
27
+
28
+ async def pause(self, task_id: str) -> None: ...
29
+
30
+ async def resume(self, task_id: str) -> None: ...
31
+
32
+ async def cancel(self, task_id: str) -> None: ...