governed-objects 0.2.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.
Files changed (88) hide show
  1. governed_objects/__init__.py +7 -0
  2. governed_objects/_version.py +38 -0
  3. governed_objects/adapters/base.py +80 -0
  4. governed_objects/adapters/context.py +58 -0
  5. governed_objects/adapters/mandate.py +45 -0
  6. governed_objects/adapters/registry.py +25 -0
  7. governed_objects/agent/session.py +111 -0
  8. governed_objects/applications/registry.py +39 -0
  9. governed_objects/authority/rules.py +63 -0
  10. governed_objects/delegation/configuration.py +74 -0
  11. governed_objects/delegation/mandate.py +44 -0
  12. governed_objects/delegation/materializer.py +152 -0
  13. governed_objects/delegation/projection.py +48 -0
  14. governed_objects/delegation/resolver.py +180 -0
  15. governed_objects/delegation/scope.py +75 -0
  16. governed_objects/delegation/service.py +245 -0
  17. governed_objects/delegation/validator.py +159 -0
  18. governed_objects/domain/__init__.py +21 -0
  19. governed_objects/domain/actor_manifest.py +40 -0
  20. governed_objects/domain/actors.py +55 -0
  21. governed_objects/domain/clock.py +28 -0
  22. governed_objects/domain/command.py +95 -0
  23. governed_objects/domain/command_context.py +35 -0
  24. governed_objects/domain/models.py +110 -0
  25. governed_objects/domain/traversal.py +25 -0
  26. governed_objects/events/lineage.py +71 -0
  27. governed_objects/events/reducers/__init__.py +2 -0
  28. governed_objects/events/reducers/mandate.py +31 -0
  29. governed_objects/events/replay.py +208 -0
  30. governed_objects/idempotency/store.py +160 -0
  31. governed_objects/interchange/__init__.py +49 -0
  32. governed_objects/interchange/artifact.py +310 -0
  33. governed_objects/interchange/export.py +345 -0
  34. governed_objects/interchange/governance.py +26 -0
  35. governed_objects/interchange/importer.py +672 -0
  36. governed_objects/interchange/prc.py +76 -0
  37. governed_objects/interchange/types.py +228 -0
  38. governed_objects/llm/__init__.py +16 -0
  39. governed_objects/llm/loop.py +130 -0
  40. governed_objects/llm/model.py +44 -0
  41. governed_objects/llm/tools/registry.py +87 -0
  42. governed_objects/llm/tools/results.py +53 -0
  43. governed_objects/llm/tools/schemas.py +67 -0
  44. governed_objects/llm/tools/surface.py +252 -0
  45. governed_objects/llm/trace.py +58 -0
  46. governed_objects/materialization/service.py +107 -0
  47. governed_objects/observations/__init__.py +3 -0
  48. governed_objects/observations/ingestion.py +375 -0
  49. governed_objects/observations/mapping.py +48 -0
  50. governed_objects/observations/models.py +81 -0
  51. governed_objects/observations/store.py +214 -0
  52. governed_objects/observations/validation.py +188 -0
  53. governed_objects/outbound/__init__.py +3 -0
  54. governed_objects/outbound/models.py +94 -0
  55. governed_objects/outbound/service.py +502 -0
  56. governed_objects/outbound/store.py +147 -0
  57. governed_objects/persistence/sqlite.py +635 -0
  58. governed_objects/policy/constraints.py +9 -0
  59. governed_objects/policy/context.py +28 -0
  60. governed_objects/policy/evaluator.py +301 -0
  61. governed_objects/policy/outcomes.py +93 -0
  62. governed_objects/policy/reasons.py +43 -0
  63. governed_objects/providers/base.py +26 -0
  64. governed_objects/providers/binding.py +42 -0
  65. governed_objects/providers/capabilities.py +27 -0
  66. governed_objects/providers/errors.py +48 -0
  67. governed_objects/providers/projection.py +25 -0
  68. governed_objects/providers/registry.py +59 -0
  69. governed_objects/query/service.py +171 -0
  70. governed_objects/query/traversal.py +154 -0
  71. governed_objects/reconciliation/service.py +213 -0
  72. governed_objects/registration/detach.py +43 -0
  73. governed_objects/registration/service.py +113 -0
  74. governed_objects/relationships/canonical.py +55 -0
  75. governed_objects/relationships/sync.py +63 -0
  76. governed_objects/relationships/vocabulary.py +12 -0
  77. governed_objects/runtime/runtime.py +1919 -0
  78. governed_objects/types/canonicalizers/base.py +15 -0
  79. governed_objects/types/extensions.py +48 -0
  80. governed_objects/types/lifecycle.py +65 -0
  81. governed_objects/types/registry.py +171 -0
  82. governed_objects/types/schema.py +90 -0
  83. governed_objects/types/validation.py +57 -0
  84. governed_objects-0.2.1.dist-info/METADATA +184 -0
  85. governed_objects-0.2.1.dist-info/RECORD +88 -0
  86. governed_objects-0.2.1.dist-info/WHEEL +4 -0
  87. governed_objects-0.2.1.dist-info/licenses/LICENSE +202 -0
  88. governed_objects-0.2.1.dist-info/licenses/NOTICE +12 -0
@@ -0,0 +1,214 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Brafford Labs, LLC
3
+ """SQLite persistence for external observations and review cases."""
4
+
5
+ from __future__ import annotations
6
+
7
+ import json
8
+ from datetime import UTC, datetime
9
+ from typing import Any
10
+
11
+ from governed_objects.observations.models import (
12
+ ExternalObservation,
13
+ FieldChange,
14
+ ObservationDecision,
15
+ ObservationResult,
16
+ ObservationSource,
17
+ )
18
+ from governed_objects.persistence.sqlite import SQLiteStore, _connection_locked
19
+
20
+
21
+ class ObservationStore:
22
+ def __init__(self, store: SQLiteStore) -> None:
23
+ self._store = store
24
+ self._connection_guard = store._connection_guard
25
+ self._ensure_schema()
26
+
27
+ @_connection_locked
28
+ def _ensure_schema(self) -> None:
29
+ self._store._require_autonomous()
30
+ self._store._conn.executescript(
31
+ """
32
+ CREATE TABLE IF NOT EXISTS observations (
33
+ id TEXT PRIMARY KEY,
34
+ object_id TEXT NOT NULL,
35
+ provider_name TEXT NOT NULL,
36
+ external_id TEXT,
37
+ provider_type TEXT,
38
+ observed_at TEXT NOT NULL,
39
+ source TEXT NOT NULL,
40
+ dedupe_key TEXT UNIQUE,
41
+ changes_json TEXT NOT NULL,
42
+ state_change_json TEXT,
43
+ provider_actor_id TEXT,
44
+ provider_event_id TEXT,
45
+ provider_version TEXT,
46
+ provider_sequence INTEGER,
47
+ raw_metadata_json TEXT,
48
+ decision TEXT,
49
+ decision_reason TEXT,
50
+ canonical_event_id TEXT,
51
+ created_at TEXT NOT NULL
52
+ );
53
+ CREATE INDEX IF NOT EXISTS idx_observations_object ON observations(object_id);
54
+ CREATE TABLE IF NOT EXISTS review_cases (
55
+ id TEXT PRIMARY KEY,
56
+ object_id TEXT NOT NULL,
57
+ observation_id TEXT NOT NULL,
58
+ field_name TEXT NOT NULL,
59
+ canonical_value TEXT,
60
+ observed_value TEXT,
61
+ state TEXT NOT NULL,
62
+ resolved_by TEXT,
63
+ resolution TEXT,
64
+ canonical_event_id TEXT,
65
+ created_at TEXT NOT NULL,
66
+ resolved_at TEXT
67
+ );
68
+ CREATE INDEX IF NOT EXISTS idx_review_cases_object ON review_cases(object_id);
69
+ """
70
+ )
71
+ self._store._conn.commit()
72
+
73
+ @property
74
+ @_connection_locked
75
+ def stats(self) -> dict[str, int]:
76
+ received = self._store._conn.execute("SELECT COUNT(*) FROM observations").fetchone()[0]
77
+ deduped = self._store._conn.execute(
78
+ "SELECT COUNT(*) FROM observations WHERE decision = ?", (ObservationDecision.NO_CHANGE.value,)
79
+ ).fetchone()[0]
80
+ emitted = self._store._conn.execute(
81
+ "SELECT COUNT(*) FROM observations WHERE canonical_event_id IS NOT NULL"
82
+ ).fetchone()[0]
83
+ return {
84
+ "observations_received": received,
85
+ "observations_deduplicated": deduped,
86
+ "canonical_changes_emitted": emitted,
87
+ }
88
+
89
+ @_connection_locked
90
+ def exists_dedupe_key(self, key: str) -> bool:
91
+ row = self._store._conn.execute(
92
+ "SELECT 1 FROM observations WHERE dedupe_key = ?", (key,)
93
+ ).fetchone()
94
+ return row is not None
95
+
96
+ @_connection_locked
97
+ def save_observation(
98
+ self,
99
+ obs: ExternalObservation,
100
+ *,
101
+ decision: ObservationDecision,
102
+ reason: str = "",
103
+ canonical_event_id: str | None = None,
104
+ ) -> None:
105
+ now = datetime.now(UTC).isoformat()
106
+ self._store._conn.execute(
107
+ """
108
+ INSERT INTO observations (
109
+ id, object_id, provider_name, external_id, provider_type,
110
+ observed_at, source, dedupe_key, changes_json, state_change_json,
111
+ provider_actor_id, provider_event_id, provider_version, provider_sequence,
112
+ raw_metadata_json, decision, decision_reason, canonical_event_id, created_at
113
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
114
+ """,
115
+ (
116
+ obs.id,
117
+ obs.object_id,
118
+ obs.provider_name,
119
+ obs.external_id,
120
+ obs.provider_type,
121
+ obs.observed_at.isoformat(),
122
+ obs.source.value,
123
+ obs.dedupe_key(),
124
+ json.dumps({k: v.model_dump() for k, v in obs.changes.items()}),
125
+ json.dumps(obs.state_change.model_dump()) if obs.state_change else None,
126
+ obs.provider_actor_id,
127
+ obs.provider_event_id,
128
+ obs.provider_version,
129
+ obs.provider_sequence,
130
+ json.dumps(obs.raw_metadata),
131
+ decision.value,
132
+ reason,
133
+ canonical_event_id,
134
+ now,
135
+ ),
136
+ )
137
+ self._store._commit_if_autonomous()
138
+
139
+ @_connection_locked
140
+ def list_for_object(self, object_id: str) -> list[dict[str, Any]]:
141
+ rows = self._store._conn.execute(
142
+ "SELECT * FROM observations WHERE object_id = ? ORDER BY created_at",
143
+ (object_id,),
144
+ ).fetchall()
145
+ return [dict(r) for r in rows]
146
+
147
+ @_connection_locked
148
+ def create_review_case(
149
+ self,
150
+ *,
151
+ case_id: str,
152
+ object_id: str,
153
+ observation_id: str,
154
+ field_name: str,
155
+ canonical_value: Any,
156
+ observed_value: Any,
157
+ ) -> None:
158
+ now = datetime.now(UTC).isoformat()
159
+ self._store._conn.execute(
160
+ """
161
+ INSERT INTO review_cases (
162
+ id, object_id, observation_id, field_name,
163
+ canonical_value, observed_value, state, created_at
164
+ ) VALUES (?, ?, ?, ?, ?, ?, 'open', ?)
165
+ """,
166
+ (
167
+ case_id,
168
+ object_id,
169
+ observation_id,
170
+ field_name,
171
+ json.dumps(canonical_value),
172
+ json.dumps(observed_value),
173
+ now,
174
+ ),
175
+ )
176
+ self._store._commit_if_autonomous()
177
+
178
+ @_connection_locked
179
+ def get_review_case(self, case_id: str) -> dict[str, Any] | None:
180
+ row = self._store._conn.execute(
181
+ "SELECT * FROM review_cases WHERE id = ?", (case_id,)
182
+ ).fetchone()
183
+ return dict(row) if row else None
184
+
185
+ @_connection_locked
186
+ def resolve_review_case(
187
+ self,
188
+ case_id: str,
189
+ *,
190
+ resolution: str,
191
+ resolved_by: str,
192
+ canonical_event_id: str | None = None,
193
+ ) -> None:
194
+ now = datetime.now(UTC).isoformat()
195
+ self._store._conn.execute(
196
+ """
197
+ UPDATE review_cases SET
198
+ state = ?,
199
+ resolution = ?,
200
+ resolved_by = ?,
201
+ canonical_event_id = ?,
202
+ resolved_at = ?
203
+ WHERE id = ?
204
+ """,
205
+ (
206
+ "accepted" if resolution == "ACCEPT_EXTERNAL" else "rejected",
207
+ resolution,
208
+ resolved_by,
209
+ canonical_event_id,
210
+ now,
211
+ case_id,
212
+ ),
213
+ )
214
+ self._store._commit_if_autonomous()
@@ -0,0 +1,188 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Brafford Labs, LLC
3
+ """Python candidate admission mechanics, not provider or authority operations."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from copy import deepcopy
8
+ from dataclasses import dataclass
9
+ from enum import StrEnum
10
+ import math
11
+ from types import MappingProxyType
12
+ from typing import Any, Mapping, TYPE_CHECKING
13
+
14
+ from governed_objects.domain.models import GovernedObject
15
+ from governed_objects.types.schema import ObjectTypeDefinition
16
+
17
+ if TYPE_CHECKING:
18
+ from governed_objects.adapters.base import TypeAdapter
19
+ from governed_objects.adapters.registry import AdapterRegistry
20
+ from governed_objects.types.registry import TypeRegistry
21
+
22
+
23
+ class CandidateVerdict(StrEnum):
24
+ VALID = "VALID"
25
+ INVALID = "INVALID"
26
+ UNAVAILABLE = "UNAVAILABLE"
27
+
28
+
29
+ class CandidateMode(StrEnum):
30
+ REGISTRATION_INITIAL = "REGISTRATION_INITIAL"
31
+ OBSERVATION = "OBSERVATION"
32
+ REVIEW_ACCEPT = "REVIEW_ACCEPT"
33
+ REPAIR_EXISTING = "REPAIR_EXISTING"
34
+
35
+
36
+ @dataclass(frozen=True)
37
+ class CandidateImage:
38
+ identity: str
39
+ type_identity: str
40
+ type_version: str
41
+ state: str
42
+ data: Mapping[str, Any]
43
+
44
+
45
+ def candidate_image(obj: GovernedObject) -> CandidateImage:
46
+ return CandidateImage(obj.id, obj.type, obj.type_version, obj.state, deepcopy(obj.data))
47
+
48
+
49
+ def _json_value(value: Any, active: set[int]) -> bool:
50
+ if value is None or type(value) in (str, bool, int):
51
+ return True
52
+ if type(value) is float:
53
+ return math.isfinite(value)
54
+ if type(value) not in (dict, list) or id(value) in active:
55
+ return False
56
+ active.add(id(value))
57
+ try:
58
+ if type(value) is dict:
59
+ return all(type(k) is str and _json_value(v, active) for k, v in value.items())
60
+ return all(_json_value(v, active) for v in value)
61
+ finally:
62
+ active.remove(id(value))
63
+
64
+
65
+ def _readonly(value: Any) -> Any:
66
+ if isinstance(value, dict):
67
+ return MappingProxyType({k: _readonly(v) for k, v in value.items()})
68
+ if isinstance(value, list):
69
+ return tuple(_readonly(v) for v in value)
70
+ return value
71
+
72
+
73
+ def _hook_image(image: CandidateImage) -> CandidateImage:
74
+ return CandidateImage(image.identity, image.type_identity, image.type_version,
75
+ image.state, _readonly(deepcopy(image.data)))
76
+
77
+
78
+ def validate_candidate(
79
+ *, type_def: ObjectTypeDefinition, current: CandidateImage | None,
80
+ candidate: CandidateImage, mode: CandidateMode, adapter: TypeAdapter | None,
81
+ ) -> CandidateVerdict:
82
+ """Check a detached full candidate without allocation, I/O or coercion.
83
+
84
+ Callers establish exact support and capture definition/adapter identity first.
85
+ The domain hook sees neither tokens nor operational/provider metadata.
86
+ """
87
+ try:
88
+ if (not candidate.identity or not type_def.type_version or
89
+ (candidate.type_identity, candidate.type_version) != (type_def.kind, type_def.type_version) or
90
+ (current is not None and (candidate.identity, candidate.type_identity, candidate.type_version) !=
91
+ (current.identity, current.type_identity, current.type_version))):
92
+ return CandidateVerdict.INVALID
93
+ if not isinstance(candidate.state, str) or not candidate.state or not _json_value(candidate.data, set()):
94
+ return CandidateVerdict.INVALID
95
+ predicates = {
96
+ "string": lambda v: type(v) is str,
97
+ "integer": lambda v: type(v) is int,
98
+ "number": lambda v: type(v) in (int, float),
99
+ "float": lambda v: type(v) in (int, float),
100
+ "double": lambda v: type(v) in (int, float),
101
+ "boolean": lambda v: type(v) is bool,
102
+ "array": lambda v: type(v) is list,
103
+ "object": lambda v: type(v) is dict,
104
+ "date": lambda v: type(v) is str,
105
+ "datetime": lambda v: type(v) is str,
106
+ }
107
+ for name, field in type_def.fields.items():
108
+ if field.type not in predicates:
109
+ return CandidateVerdict.UNAVAILABLE
110
+ value = candidate.data.get(name)
111
+ if field.required and (value is None or value == ""):
112
+ return CandidateVerdict.INVALID
113
+ if value is not None and not predicates[field.type](value):
114
+ return CandidateVerdict.INVALID
115
+ if type_def.states:
116
+ if candidate.state not in type_def.states:
117
+ return CandidateVerdict.INVALID
118
+ if current is not None and candidate.state != current.state:
119
+ state = type_def.states.get(current.state)
120
+ if state is None or state.terminal or candidate.state not in state.transitions.values():
121
+ return CandidateVerdict.INVALID
122
+ elif current is None:
123
+ if not type_def.initial_state:
124
+ return CandidateVerdict.UNAVAILABLE
125
+ if candidate.state != type_def.initial_state:
126
+ return CandidateVerdict.INVALID
127
+ elif candidate.state != current.state:
128
+ return CandidateVerdict.UNAVAILABLE
129
+ if adapter is None:
130
+ return CandidateVerdict.UNAVAILABLE
131
+ definition = type_def.model_copy(deep=True)
132
+ original = definition.model_copy(deep=True)
133
+ result = adapter.validate_observation_candidate(
134
+ type_def=definition, current=None if current is None else _hook_image(current),
135
+ candidate=_hook_image(candidate), mode=mode,
136
+ )
137
+ if definition != original or not isinstance(result, CandidateVerdict):
138
+ return CandidateVerdict.UNAVAILABLE
139
+ return result
140
+ except Exception:
141
+ return CandidateVerdict.UNAVAILABLE
142
+
143
+
144
+ @dataclass(frozen=True)
145
+ class AdmissionSnapshot:
146
+ """Per-call captured meaning; not a multi-version support registry."""
147
+ definitions: tuple[ObjectTypeDefinition, ...]
148
+ originals: tuple[ObjectTypeDefinition, ...]
149
+ adapter: TypeAdapter | None
150
+ adapter_order: tuple[TypeAdapter, ...]
151
+
152
+ @property
153
+ def definition(self) -> ObjectTypeDefinition:
154
+ return self.definitions[-1]
155
+
156
+ def matches(self, types: TypeRegistry, adapters: AdapterRegistry | None, obj: GovernedObject) -> bool:
157
+ try:
158
+ for original, captured in zip(self.originals, self.definitions):
159
+ if types.get(captured.kind) is not original or original != captured:
160
+ return False
161
+ order = () if adapters is None else tuple(adapters._adapters)
162
+ return len(order) == len(self.adapter_order) and all(
163
+ a is b for a, b in zip(order, self.adapter_order)
164
+ )
165
+ except Exception:
166
+ return False
167
+
168
+
169
+ def capture_admission(types: TypeRegistry, adapters: AdapterRegistry | None,
170
+ obj: GovernedObject) -> AdmissionSnapshot:
171
+ """Capture explicit supported meaning outside the pure validator/transaction."""
172
+ from governed_objects.events.replay import bound_type_definition
173
+ definition = bound_type_definition(types, obj)
174
+ if definition is None:
175
+ raise ValueError("unsupported binding")
176
+ chain = []
177
+ while definition is not None:
178
+ if definition.kind in {d.kind for d in chain}:
179
+ raise ValueError("unavailable ancestry")
180
+ chain.append(definition)
181
+ definition = types.get(definition.extends) if definition.extends else None
182
+ try:
183
+ adapter = None if adapters is None else adapters.resolve(obj)
184
+ except KeyError:
185
+ adapter = None
186
+ originals = tuple(reversed(chain))
187
+ order = () if adapters is None else tuple(adapters._adapters)
188
+ return AdmissionSnapshot(tuple(d.model_copy(deep=True) for d in originals), originals, adapter, order)
@@ -0,0 +1,3 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Brafford Labs, LLC
3
+ """Outbound reconciliation — canonical authority over provider representations."""
@@ -0,0 +1,94 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Brafford Labs, LLC
3
+ """Outbound provider repair models."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from datetime import UTC, datetime
8
+ from enum import StrEnum
9
+ from typing import Any
10
+ from uuid import uuid4
11
+
12
+ from pydantic import BaseModel, Field
13
+
14
+
15
+ class RepairStatus(StrEnum):
16
+ PLANNED = "PLANNED"
17
+ APPLIED = "APPLIED"
18
+ ALREADY_IN_SYNC = "ALREADY_IN_SYNC"
19
+ CANONICAL_CONFLICT = "CANONICAL_CONFLICT"
20
+ PROVIDER_CONFLICT = "PROVIDER_CONFLICT"
21
+ PROVIDER_UNAVAILABLE = "PROVIDER_UNAVAILABLE"
22
+ PROVIDER_NOT_FOUND = "PROVIDER_NOT_FOUND"
23
+ PROVIDER_INVALID_RESPONSE = "PROVIDER_INVALID_RESPONSE"
24
+ PROVIDER_OUTCOME_UNKNOWN = "PROVIDER_OUTCOME_UNKNOWN"
25
+ UNREPAIRABLE_FIELD = "UNREPAIRABLE_FIELD"
26
+ REJECTED_TAMPER = "REJECTED_TAMPER"
27
+ UNSUPPORTED_PROVIDER = "UNSUPPORTED_PROVIDER"
28
+
29
+
30
+ class ProviderRepairRequest(BaseModel):
31
+ """Organization intends to make provider conform to accepted canonical state."""
32
+
33
+ repair_id: str = Field(default_factory=lambda: str(uuid4()))
34
+ object_id: str
35
+ provider_name: str
36
+ external_id: str
37
+ canonical_expected_version: int
38
+ provider_expected_version: str
39
+ changes: dict[str, Any] = Field(default_factory=dict)
40
+ reason: str = "CANONICAL_AUTHORITATIVE_DRIFT"
41
+ originating_observation_id: str | None = None
42
+ review_case_id: str | None = None
43
+ correlation_id: str | None = None
44
+ initiated_by: str = "system"
45
+
46
+
47
+ class ProviderRepairPlan(BaseModel):
48
+ """Dry-run repair plan derived only from canonical accepted state."""
49
+
50
+ plan_id: str = Field(default_factory=lambda: str(uuid4()))
51
+ object_id: str
52
+ provider_name: str
53
+ external_id: str
54
+ type_identity: str
55
+ type_version: str
56
+ projection_token: str
57
+ canonical_expected_version: int
58
+ provider_expected_version: str
59
+ changes: dict[str, Any] = Field(default_factory=dict)
60
+ drifts: list[str] = Field(default_factory=list)
61
+ repair_fields: list[str] = Field(default_factory=list)
62
+ projection_gaps: list[str] = Field(default_factory=list)
63
+ unrepairable_fields: list[str] = Field(default_factory=list)
64
+ reason: str = "CANONICAL_AUTHORITATIVE_DRIFT"
65
+ originating_observation_id: str | None = None
66
+ created_at: datetime = Field(default_factory=lambda: datetime.now(UTC))
67
+
68
+ def to_request(self, *, initiated_by: str = "system") -> ProviderRepairRequest:
69
+ return ProviderRepairRequest(
70
+ repair_id=self.plan_id,
71
+ object_id=self.object_id,
72
+ provider_name=self.provider_name,
73
+ external_id=self.external_id,
74
+ canonical_expected_version=self.canonical_expected_version,
75
+ provider_expected_version=self.provider_expected_version,
76
+ changes=dict(self.changes),
77
+ reason=self.reason,
78
+ originating_observation_id=self.originating_observation_id,
79
+ initiated_by=initiated_by,
80
+ )
81
+
82
+
83
+ class ProviderRepairResult(BaseModel):
84
+ object_id: str
85
+ repair_id: str
86
+ status: RepairStatus
87
+ reason: str = ""
88
+ canonical_expected_version: int | None = None
89
+ canonical_actual_version: int | None = None
90
+ provider_expected_version: str | None = None
91
+ provider_actual_version: str | None = None
92
+ provider_name: str | None = None
93
+ changes: dict[str, Any] = Field(default_factory=dict)
94
+ correlation_id: str | None = None