maivn-shared 0.2.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 (51) hide show
  1. maivn_shared/__init__.py +269 -0
  2. maivn_shared/__version__.py +11 -0
  3. maivn_shared/core/__init__.py +105 -0
  4. maivn_shared/core/data/__init__.py +11 -0
  5. maivn_shared/core/data/id_generator.py +94 -0
  6. maivn_shared/core/events.py +211 -0
  7. maivn_shared/domain/__init__.py +84 -0
  8. maivn_shared/domain/entities/__init__.py +139 -0
  9. maivn_shared/domain/entities/dependencies.py +114 -0
  10. maivn_shared/domain/entities/memory_config.py +184 -0
  11. maivn_shared/domain/entities/messages.py +387 -0
  12. maivn_shared/domain/entities/pii_whitelist.py +276 -0
  13. maivn_shared/domain/entities/session.py +515 -0
  14. maivn_shared/domain/entities/session_config.py +731 -0
  15. maivn_shared/domain/entities/swarm_actions.py +98 -0
  16. maivn_shared/domain/entities/tool_execution.py +25 -0
  17. maivn_shared/domain/entities/tool_spec.py +245 -0
  18. maivn_shared/domain/exceptions.py +321 -0
  19. maivn_shared/domain/factories/__init__.py +15 -0
  20. maivn_shared/domain/factories/tool_spec_factory/__init__.py +23 -0
  21. maivn_shared/domain/factories/tool_spec_factory/docstring_utils.py +129 -0
  22. maivn_shared/domain/factories/tool_spec_factory/function_factory.py +103 -0
  23. maivn_shared/domain/factories/tool_spec_factory/schema_utils.py +268 -0
  24. maivn_shared/domain/factories/tool_spec_factory/state_factory.py +224 -0
  25. maivn_shared/infrastructure/__init__.py +50 -0
  26. maivn_shared/infrastructure/api/__init__.py +14 -0
  27. maivn_shared/infrastructure/api/endpoints.py +29 -0
  28. maivn_shared/infrastructure/client.py +161 -0
  29. maivn_shared/infrastructure/http_client.py +229 -0
  30. maivn_shared/infrastructure/logging/__init__.py +36 -0
  31. maivn_shared/infrastructure/logging/config.py +204 -0
  32. maivn_shared/infrastructure/logging/context.py +85 -0
  33. maivn_shared/infrastructure/logging/formatters.py +294 -0
  34. maivn_shared/infrastructure/logging/logger.py +52 -0
  35. maivn_shared/infrastructure/logging/maivn_logger.py +637 -0
  36. maivn_shared/infrastructure/logging/null_logger.py +99 -0
  37. maivn_shared/infrastructure/logging/protocols.py +60 -0
  38. maivn_shared/infrastructure/logging/writers.py +181 -0
  39. maivn_shared/py.typed +1 -0
  40. maivn_shared/utils/__init__.py +61 -0
  41. maivn_shared/utils/env.py +100 -0
  42. maivn_shared/utils/prompt_utils.py +221 -0
  43. maivn_shared/utils/serialization.py +245 -0
  44. maivn_shared/utils/time.py +20 -0
  45. maivn_shared/utils/token_models.py +58 -0
  46. maivn_shared/utils/tool_utils.py +34 -0
  47. maivn_shared-0.2.0.dist-info/METADATA +450 -0
  48. maivn_shared-0.2.0.dist-info/RECORD +51 -0
  49. maivn_shared-0.2.0.dist-info/WHEEL +4 -0
  50. maivn_shared-0.2.0.dist-info/licenses/LICENSE +191 -0
  51. maivn_shared-0.2.0.dist-info/licenses/NOTICE +8 -0
@@ -0,0 +1,269 @@
1
+ """Maivn Core - Core domain models and utilities for the Maivn platform.
2
+
3
+ This package provides the fundamental building blocks for Maivn applications:
4
+ - Domain entities (tools, sessions, messages, dependencies)
5
+ - Infrastructure (logging, HTTP client, API endpoints)
6
+ - Utilities
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from .core import (
12
+ ASSIGNMENT_COMPLETED_EVENT_NAME,
13
+ ASSIGNMENT_RECEIVED_EVENT_NAME,
14
+ ENRICHMENT_EVENT_NAME,
15
+ ERROR_EVENT_NAME,
16
+ FINAL_EVENT_NAME,
17
+ HEARTBEAT_EVENT_NAME,
18
+ INTERRUPT_REQUEST_EVENT_NAME,
19
+ INTERRUPT_REQUIRED_EVENT_NAME,
20
+ MEMORY_ENRICHMENT_PHASES,
21
+ MEMORY_GRAPH_EXTRACTING_ENRICHMENT_PHASE,
22
+ MEMORY_INDEXED_ENRICHMENT_PHASE,
23
+ MEMORY_INDEXING_ENRICHMENT_PHASE,
24
+ MEMORY_INSIGHT_EXTRACTED_ENRICHMENT_PHASE,
25
+ MEMORY_INSIGHT_EXTRACTING_ENRICHMENT_PHASE,
26
+ MEMORY_RETRIEVED_ENRICHMENT_PHASE,
27
+ MEMORY_RETRIEVING_ENRICHMENT_PHASE,
28
+ MEMORY_SKILL_EXTRACTED_ENRICHMENT_PHASE,
29
+ MEMORY_SKILL_EXTRACTING_ENRICHMENT_PHASE,
30
+ MEMORY_SUMMARIZED_ENRICHMENT_PHASE,
31
+ MEMORY_SUMMARIZING_ENRICHMENT_PHASE,
32
+ MESSAGE_REDACTION_APPLIED_ENRICHMENT_PHASE,
33
+ MODEL_TOOL_COMPLETE_EVENT_NAME,
34
+ PROGRESS_UPDATE_EVENT_NAME,
35
+ REDACTION_ENRICHMENT_PHASES,
36
+ REDACTION_PREVIEWED_ENRICHMENT_PHASE,
37
+ RESOURCE_DEDUP_REUSED_ENRICHMENT_PHASE,
38
+ RESOURCE_ENRICHMENT_PHASES,
39
+ RESOURCE_EXTRACTED_ENRICHMENT_PHASE,
40
+ RESOURCE_EXTRACTING_ENRICHMENT_PHASE,
41
+ RESOURCE_REGISTERED_ENRICHMENT_PHASE,
42
+ RESOURCE_REGISTERING_ENRICHMENT_PHASE,
43
+ RESOURCE_VERSION_SUPERSEDED_ENRICHMENT_PHASE,
44
+ STATUS_MESSAGE_EVENT_NAME,
45
+ SYSTEM_TOOL_CHUNK_EVENT_NAME,
46
+ SYSTEM_TOOL_COMPLETE_EVENT_NAME,
47
+ SYSTEM_TOOL_ERROR_EVENT_NAME,
48
+ SYSTEM_TOOL_START_EVENT_NAME,
49
+ TOOL_EVENT_NAME,
50
+ UPDATE_EVENT_NAME,
51
+ create_uuid,
52
+ )
53
+ from .domain.entities import (
54
+ HIPAA_SAFE_HARBOR_CATEGORIES,
55
+ SWARM_AGENT_INVOCATION_METADATA_KEY,
56
+ SWARM_INVOCATION_INTENT_METADATA_KEY,
57
+ AgentDependency,
58
+ AIMessage,
59
+ ArgsSchema,
60
+ AwaitForDependency,
61
+ BaseDependency,
62
+ BaseMessage,
63
+ DataDependency,
64
+ ExecutionInstanceControl,
65
+ ExecutionTiming,
66
+ HumanMessage,
67
+ InterruptDependency,
68
+ MemoryAssetsConfig,
69
+ MemoryConfig,
70
+ MemoryInsightExtractionConfig,
71
+ MemoryLevel,
72
+ MemoryPersistenceMode,
73
+ MemoryResourceConfig,
74
+ MemoryRetrievalConfig,
75
+ MemorySharingScope,
76
+ MemorySkillConfig,
77
+ MemorySkillExtractionConfig,
78
+ NestedSynthesisMode,
79
+ PIIWhitelist,
80
+ PIIWhitelistEntry,
81
+ PrivateData,
82
+ RedactedMessage,
83
+ RedactionPreviewRequest,
84
+ RedactionPreviewResponse,
85
+ ReevaluateDependency,
86
+ SessionExecutionConfig,
87
+ SessionOrchestrationConfig,
88
+ SessionRequest,
89
+ SessionResponse,
90
+ SessionStartRequest,
91
+ SessionStartupResponse,
92
+ StructuredOutputConfig,
93
+ SwarmAgentConfig,
94
+ SwarmConfig,
95
+ SystemMessage,
96
+ SystemToolsConfig,
97
+ ToolCall,
98
+ ToolDependency,
99
+ ToolExecutionResult,
100
+ ToolMessage,
101
+ ToolResumePayload,
102
+ ToolSpec,
103
+ ToolType,
104
+ apply_session_configs_to_metadata,
105
+ )
106
+ from .domain.exceptions import (
107
+ ConfigurationError,
108
+ MaivnError,
109
+ SerializationError,
110
+ ValidationError,
111
+ is_retryable,
112
+ wrap_exception,
113
+ )
114
+ from .domain.factories import build_tool_spec_from_function
115
+ from .infrastructure import (
116
+ HttpClient,
117
+ HttpClientProtocol,
118
+ HttpError,
119
+ MaivnLogger,
120
+ ServerEndpoints,
121
+ SessionClientProtocol,
122
+ SSEClientProtocol,
123
+ get_logger,
124
+ get_optional_logger,
125
+ )
126
+ from .infrastructure.logging import Colors, LogLevel, LogStyles
127
+ from .utils import (
128
+ dumps,
129
+ dumps_bytes,
130
+ extract_tool_names,
131
+ loads,
132
+ serialize_error,
133
+ serialize_with_metadata,
134
+ to_jsonable,
135
+ )
136
+
137
+ __all__ = [
138
+ # Core - Utilities
139
+ "create_uuid",
140
+ # Core - Events
141
+ "TOOL_EVENT_NAME",
142
+ "INTERRUPT_REQUEST_EVENT_NAME",
143
+ "INTERRUPT_REQUIRED_EVENT_NAME",
144
+ "ASSIGNMENT_RECEIVED_EVENT_NAME",
145
+ "ASSIGNMENT_COMPLETED_EVENT_NAME",
146
+ "MODEL_TOOL_COMPLETE_EVENT_NAME",
147
+ "HEARTBEAT_EVENT_NAME",
148
+ "UPDATE_EVENT_NAME",
149
+ "PROGRESS_UPDATE_EVENT_NAME",
150
+ "STATUS_MESSAGE_EVENT_NAME",
151
+ "FINAL_EVENT_NAME",
152
+ "ERROR_EVENT_NAME",
153
+ "SYSTEM_TOOL_START_EVENT_NAME",
154
+ "SYSTEM_TOOL_CHUNK_EVENT_NAME",
155
+ "SYSTEM_TOOL_COMPLETE_EVENT_NAME",
156
+ "SYSTEM_TOOL_ERROR_EVENT_NAME",
157
+ "ENRICHMENT_EVENT_NAME",
158
+ "MEMORY_SUMMARIZING_ENRICHMENT_PHASE",
159
+ "MEMORY_SUMMARIZED_ENRICHMENT_PHASE",
160
+ "MEMORY_RETRIEVING_ENRICHMENT_PHASE",
161
+ "MEMORY_RETRIEVED_ENRICHMENT_PHASE",
162
+ "MEMORY_INDEXING_ENRICHMENT_PHASE",
163
+ "MEMORY_INDEXED_ENRICHMENT_PHASE",
164
+ "MEMORY_GRAPH_EXTRACTING_ENRICHMENT_PHASE",
165
+ "MEMORY_SKILL_EXTRACTING_ENRICHMENT_PHASE",
166
+ "MEMORY_INSIGHT_EXTRACTING_ENRICHMENT_PHASE",
167
+ "MEMORY_SKILL_EXTRACTED_ENRICHMENT_PHASE",
168
+ "MEMORY_INSIGHT_EXTRACTED_ENRICHMENT_PHASE",
169
+ "MEMORY_ENRICHMENT_PHASES",
170
+ "MESSAGE_REDACTION_APPLIED_ENRICHMENT_PHASE",
171
+ "REDACTION_PREVIEWED_ENRICHMENT_PHASE",
172
+ "REDACTION_ENRICHMENT_PHASES",
173
+ "RESOURCE_REGISTERING_ENRICHMENT_PHASE",
174
+ "RESOURCE_REGISTERED_ENRICHMENT_PHASE",
175
+ "RESOURCE_DEDUP_REUSED_ENRICHMENT_PHASE",
176
+ "RESOURCE_VERSION_SUPERSEDED_ENRICHMENT_PHASE",
177
+ "RESOURCE_EXTRACTING_ENRICHMENT_PHASE",
178
+ "RESOURCE_EXTRACTED_ENRICHMENT_PHASE",
179
+ "RESOURCE_ENRICHMENT_PHASES",
180
+ # Domain - Entities - Memory Config
181
+ "MemoryConfig",
182
+ "MemoryAssetsConfig",
183
+ "MemoryInsightExtractionConfig",
184
+ "MemoryLevel",
185
+ "MemoryPersistenceMode",
186
+ "MemoryResourceConfig",
187
+ "MemoryRetrievalConfig",
188
+ "MemorySharingScope",
189
+ "MemorySkillConfig",
190
+ "MemorySkillExtractionConfig",
191
+ "NestedSynthesisMode",
192
+ # Domain - Entities - Session
193
+ "SWARM_AGENT_INVOCATION_METADATA_KEY",
194
+ "SWARM_INVOCATION_INTENT_METADATA_KEY",
195
+ "RedactionPreviewRequest",
196
+ "RedactionPreviewResponse",
197
+ "SessionExecutionConfig",
198
+ "SessionOrchestrationConfig",
199
+ "SessionRequest",
200
+ "SessionResponse",
201
+ "SessionStartupResponse",
202
+ "SessionStartRequest",
203
+ "StructuredOutputConfig",
204
+ "SwarmAgentConfig",
205
+ "SwarmConfig",
206
+ "SystemToolsConfig",
207
+ "apply_session_configs_to_metadata",
208
+ # Domain - Entities - Tool Specification
209
+ "ArgsSchema",
210
+ "ToolSpec",
211
+ "ToolType",
212
+ "ToolCall",
213
+ "ToolExecutionResult",
214
+ # Domain - Entities - Messages
215
+ "BaseMessage",
216
+ "HumanMessage",
217
+ "PrivateData",
218
+ "RedactedMessage",
219
+ "AIMessage",
220
+ "SystemMessage",
221
+ "ToolMessage",
222
+ # Domain - Entities - PII Whitelist
223
+ "HIPAA_SAFE_HARBOR_CATEGORIES",
224
+ "PIIWhitelist",
225
+ "PIIWhitelistEntry",
226
+ # Domain - Entities - Dependencies
227
+ "BaseDependency",
228
+ "AgentDependency",
229
+ "AwaitForDependency",
230
+ "DataDependency",
231
+ "ExecutionInstanceControl",
232
+ "ExecutionTiming",
233
+ "InterruptDependency",
234
+ "ReevaluateDependency",
235
+ "ToolDependency",
236
+ "ToolResumePayload",
237
+ # Domain - Exceptions
238
+ "MaivnError",
239
+ "ConfigurationError",
240
+ "ValidationError",
241
+ "SerializationError",
242
+ "wrap_exception",
243
+ "is_retryable",
244
+ # Domain - Factories
245
+ "build_tool_spec_from_function",
246
+ # Infrastructure - Logging
247
+ "MaivnLogger",
248
+ "LogLevel",
249
+ "Colors",
250
+ "LogStyles",
251
+ "get_logger",
252
+ "get_optional_logger",
253
+ # Infrastructure - HTTP
254
+ "HttpClient",
255
+ "HttpError",
256
+ "HttpClientProtocol",
257
+ "SSEClientProtocol",
258
+ "ServerEndpoints",
259
+ "SessionClientProtocol",
260
+ # Utilities - Serialization
261
+ "dumps",
262
+ "dumps_bytes",
263
+ "loads",
264
+ "to_jsonable",
265
+ "serialize_error",
266
+ "serialize_with_metadata",
267
+ # Utilities - Tools
268
+ "extract_tool_names",
269
+ ]
@@ -0,0 +1,11 @@
1
+ """Package version for maivn-shared.
2
+
3
+ Exposed via ``maivn_shared.__version__`` for tooling and client diagnostics.
4
+ """
5
+
6
+ # MARK: Version
7
+ from __future__ import annotations
8
+
9
+ __all__ = ["__version__"]
10
+
11
+ __version__ = "0.2.0"
@@ -0,0 +1,105 @@
1
+ """Core application services and utilities for maivn-core."""
2
+
3
+ from __future__ import annotations
4
+
5
+ # MARK: - Utilities
6
+ from .data import create_uuid
7
+
8
+ # MARK: - Events
9
+ from .events import (
10
+ ASSIGNMENT_COMPLETED_EVENT_NAME,
11
+ # MARK: - Assignment Events
12
+ ASSIGNMENT_RECEIVED_EVENT_NAME,
13
+ # MARK: - Enrichment Events
14
+ ENRICHMENT_EVENT_NAME,
15
+ ERROR_EVENT_NAME,
16
+ FINAL_EVENT_NAME,
17
+ # MARK: - Lifecycle Events
18
+ HEARTBEAT_EVENT_NAME,
19
+ INTERRUPT_REQUEST_EVENT_NAME,
20
+ INTERRUPT_REQUIRED_EVENT_NAME,
21
+ MEMORY_ENRICHMENT_PHASES,
22
+ MEMORY_GRAPH_EXTRACTING_ENRICHMENT_PHASE,
23
+ MEMORY_INDEXED_ENRICHMENT_PHASE,
24
+ MEMORY_INDEXING_ENRICHMENT_PHASE,
25
+ MEMORY_INSIGHT_EXTRACTED_ENRICHMENT_PHASE,
26
+ MEMORY_INSIGHT_EXTRACTING_ENRICHMENT_PHASE,
27
+ MEMORY_RETRIEVED_ENRICHMENT_PHASE,
28
+ MEMORY_RETRIEVING_ENRICHMENT_PHASE,
29
+ MEMORY_SKILL_EXTRACTED_ENRICHMENT_PHASE,
30
+ MEMORY_SKILL_EXTRACTING_ENRICHMENT_PHASE,
31
+ MEMORY_SUMMARIZED_ENRICHMENT_PHASE,
32
+ MEMORY_SUMMARIZING_ENRICHMENT_PHASE,
33
+ MESSAGE_REDACTION_APPLIED_ENRICHMENT_PHASE,
34
+ # MARK: - Model Events
35
+ MODEL_TOOL_COMPLETE_EVENT_NAME,
36
+ PROGRESS_UPDATE_EVENT_NAME,
37
+ REDACTION_ENRICHMENT_PHASES,
38
+ REDACTION_PREVIEWED_ENRICHMENT_PHASE,
39
+ RESOURCE_DEDUP_REUSED_ENRICHMENT_PHASE,
40
+ RESOURCE_ENRICHMENT_PHASES,
41
+ RESOURCE_EXTRACTED_ENRICHMENT_PHASE,
42
+ RESOURCE_EXTRACTING_ENRICHMENT_PHASE,
43
+ RESOURCE_REGISTERED_ENRICHMENT_PHASE,
44
+ RESOURCE_REGISTERING_ENRICHMENT_PHASE,
45
+ RESOURCE_VERSION_SUPERSEDED_ENRICHMENT_PHASE,
46
+ STATUS_MESSAGE_EVENT_NAME,
47
+ SYSTEM_TOOL_CHUNK_EVENT_NAME,
48
+ SYSTEM_TOOL_COMPLETE_EVENT_NAME,
49
+ SYSTEM_TOOL_ERROR_EVENT_NAME,
50
+ # MARK: - System Tool Events
51
+ SYSTEM_TOOL_START_EVENT_NAME,
52
+ # MARK: - Tool Events
53
+ TOOL_EVENT_NAME,
54
+ UPDATE_EVENT_NAME,
55
+ )
56
+
57
+ __all__ = [
58
+ # MARK: - Utilities
59
+ "create_uuid",
60
+ # MARK: - Tool Events
61
+ "TOOL_EVENT_NAME",
62
+ "INTERRUPT_REQUEST_EVENT_NAME",
63
+ "INTERRUPT_REQUIRED_EVENT_NAME",
64
+ # MARK: - Assignment Events
65
+ "ASSIGNMENT_RECEIVED_EVENT_NAME",
66
+ "ASSIGNMENT_COMPLETED_EVENT_NAME",
67
+ # MARK: - Model Events
68
+ "MODEL_TOOL_COMPLETE_EVENT_NAME",
69
+ # MARK: - Lifecycle Events
70
+ "HEARTBEAT_EVENT_NAME",
71
+ "UPDATE_EVENT_NAME",
72
+ "PROGRESS_UPDATE_EVENT_NAME",
73
+ "STATUS_MESSAGE_EVENT_NAME",
74
+ "FINAL_EVENT_NAME",
75
+ "ERROR_EVENT_NAME",
76
+ # MARK: - System Tool Events
77
+ "SYSTEM_TOOL_START_EVENT_NAME",
78
+ "SYSTEM_TOOL_CHUNK_EVENT_NAME",
79
+ "SYSTEM_TOOL_COMPLETE_EVENT_NAME",
80
+ "SYSTEM_TOOL_ERROR_EVENT_NAME",
81
+ # MARK: - Enrichment Events
82
+ "ENRICHMENT_EVENT_NAME",
83
+ "MEMORY_SUMMARIZING_ENRICHMENT_PHASE",
84
+ "MEMORY_SUMMARIZED_ENRICHMENT_PHASE",
85
+ "MEMORY_RETRIEVING_ENRICHMENT_PHASE",
86
+ "MEMORY_RETRIEVED_ENRICHMENT_PHASE",
87
+ "MEMORY_INDEXING_ENRICHMENT_PHASE",
88
+ "MEMORY_INDEXED_ENRICHMENT_PHASE",
89
+ "MEMORY_GRAPH_EXTRACTING_ENRICHMENT_PHASE",
90
+ "MEMORY_SKILL_EXTRACTING_ENRICHMENT_PHASE",
91
+ "MEMORY_INSIGHT_EXTRACTING_ENRICHMENT_PHASE",
92
+ "MEMORY_SKILL_EXTRACTED_ENRICHMENT_PHASE",
93
+ "MEMORY_INSIGHT_EXTRACTED_ENRICHMENT_PHASE",
94
+ "MEMORY_ENRICHMENT_PHASES",
95
+ "MESSAGE_REDACTION_APPLIED_ENRICHMENT_PHASE",
96
+ "REDACTION_PREVIEWED_ENRICHMENT_PHASE",
97
+ "REDACTION_ENRICHMENT_PHASES",
98
+ "RESOURCE_REGISTERING_ENRICHMENT_PHASE",
99
+ "RESOURCE_REGISTERED_ENRICHMENT_PHASE",
100
+ "RESOURCE_DEDUP_REUSED_ENRICHMENT_PHASE",
101
+ "RESOURCE_VERSION_SUPERSEDED_ENRICHMENT_PHASE",
102
+ "RESOURCE_EXTRACTING_ENRICHMENT_PHASE",
103
+ "RESOURCE_EXTRACTED_ENRICHMENT_PHASE",
104
+ "RESOURCE_ENRICHMENT_PHASES",
105
+ ]
@@ -0,0 +1,11 @@
1
+ """Data utilities for maivn-core."""
2
+
3
+ from __future__ import annotations
4
+
5
+ # MARK: - ID Generation
6
+ from .id_generator import create_uuid
7
+
8
+ __all__ = [
9
+ # MARK: - ID Generation
10
+ "create_uuid",
11
+ ]
@@ -0,0 +1,94 @@
1
+ """UUID generation utilities for maivn-core.
2
+
3
+ This module provides utilities for generating unique identifiers,
4
+ supporting both random and deterministic UUID generation.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import uuid
10
+
11
+ # MARK: - UUID Utilities
12
+
13
+
14
+ def create_uuid(obj: object | None = None) -> str:
15
+ """Create a unique identifier as a string.
16
+
17
+ If an object is provided, generate a deterministic UUID v5 using the object's
18
+ intrinsic properties (module + qualname for functions/classes, or repr for others).
19
+ Otherwise, return a random UUID v4.
20
+
21
+ Args:
22
+ obj: Optional object to generate deterministic UUID from
23
+
24
+ Returns:
25
+ UUID string (deterministic if obj provided, random otherwise)
26
+ """
27
+ if obj is None:
28
+ return str(uuid.uuid4())
29
+
30
+ identifier = _get_deterministic_identifier(obj)
31
+ return str(uuid.uuid5(uuid.NAMESPACE_DNS, identifier))
32
+
33
+
34
+ # MARK: - Helper Functions
35
+
36
+
37
+ def _get_deterministic_identifier(obj: object) -> str:
38
+ """Get a deterministic identifier string for an object.
39
+
40
+ For functions and classes, uses module + qualname for consistency across runs.
41
+ For other objects, falls back to type name + repr.
42
+
43
+ Args:
44
+ obj: Object to generate identifier for
45
+
46
+ Returns:
47
+ Deterministic identifier string
48
+ """
49
+ if callable(obj) or isinstance(obj, type):
50
+ identifier = _get_callable_identifier(obj)
51
+ if identifier:
52
+ return identifier
53
+
54
+ return _get_fallback_identifier(obj)
55
+
56
+
57
+ def _get_callable_identifier(obj: object) -> str | None:
58
+ """Get identifier for callable objects using module and qualname.
59
+
60
+ Args:
61
+ obj: Callable object or type
62
+
63
+ Returns:
64
+ Identifier string or None if not determinable
65
+ """
66
+ module = getattr(obj, "__module__", None)
67
+ if not module:
68
+ return None
69
+
70
+ qualname = getattr(obj, "__qualname__", None)
71
+ if qualname:
72
+ return f"{module}.{qualname}"
73
+
74
+ name = getattr(obj, "__name__", None)
75
+ if name:
76
+ return f"{module}.{name}"
77
+
78
+ return None
79
+
80
+
81
+ def _get_fallback_identifier(obj: object) -> str:
82
+ """Get fallback identifier using type and repr.
83
+
84
+ Args:
85
+ obj: Object to generate identifier for
86
+
87
+ Returns:
88
+ Fallback identifier string
89
+ """
90
+ type_name = type(obj).__name__
91
+ try:
92
+ return f"{type_name}:{repr(obj)}"
93
+ except Exception:
94
+ return f"{type_name}:{id(obj)}"
@@ -0,0 +1,211 @@
1
+ """Shared event-name constants used across Maivn services and SDK."""
2
+
3
+ from __future__ import annotations
4
+
5
+ # MARK: - Tool Events
6
+
7
+ TOOL_EVENT_NAME = "tool_event"
8
+ """Primary event name emitted by the server bridge and consumed by the SDK."""
9
+
10
+ INTERRUPT_REQUEST_EVENT_NAME = "interrupt_request"
11
+ """Interrupt request event emitted when a tool requires user input."""
12
+
13
+ INTERRUPT_REQUIRED_EVENT_NAME = "interrupt_required"
14
+ """Interrupt required event indicating user action is needed."""
15
+
16
+ # MARK: - Assignment Events
17
+
18
+ ASSIGNMENT_RECEIVED_EVENT_NAME = "assignment_received"
19
+ """Emitted when an assignment is received by an agent."""
20
+
21
+ ASSIGNMENT_COMPLETED_EVENT_NAME = "assignment_completed"
22
+ """Emitted when an assignment is completed by an agent."""
23
+
24
+ # MARK: - Model Events
25
+
26
+ MODEL_TOOL_COMPLETE_EVENT_NAME = "model_tool_complete"
27
+ """Emitted when a model tool call completes."""
28
+
29
+ # MARK: - Lifecycle Events
30
+
31
+ HEARTBEAT_EVENT_NAME = "heartbeat"
32
+ """Periodic heartbeat event for connection health."""
33
+
34
+ UPDATE_EVENT_NAME = "update"
35
+ """Progress update event during execution."""
36
+
37
+ PROGRESS_UPDATE_EVENT_NAME = "progress_update"
38
+ """Progress update event for streamed response content during execution."""
39
+
40
+ STATUS_MESSAGE_EVENT_NAME = "status_message"
41
+ """Standalone status message emitted at swarm lifecycle milestones.
42
+
43
+ Unlike ``progress_update`` (which carries streaming deltas that accumulate
44
+ into a single response), a ``status_message`` is a self-contained,
45
+ human-readable notification (e.g. "Dispatching 3 agents: ..."). Clients
46
+ should display each one as its own UI element rather than appending to
47
+ the assistant response stream.
48
+
49
+ Payload: ``{"message": str, "assistant_id": str}``
50
+ """
51
+
52
+ FINAL_EVENT_NAME = "final"
53
+ """Final event indicating execution completion."""
54
+
55
+ ERROR_EVENT_NAME = "error"
56
+ """Error event indicating execution failure."""
57
+
58
+ # MARK: - System Tool Events
59
+
60
+ SYSTEM_TOOL_START_EVENT_NAME = "system_tool_start"
61
+ """Emitted when a system tool (web_search, repl, think) starts execution."""
62
+
63
+ SYSTEM_TOOL_CHUNK_EVENT_NAME = "system_tool_chunk"
64
+ """Emitted when a system tool produces a streaming chunk during execution."""
65
+
66
+ SYSTEM_TOOL_COMPLETE_EVENT_NAME = "system_tool_complete"
67
+ """Emitted when a system tool completes execution."""
68
+
69
+ SYSTEM_TOOL_ERROR_EVENT_NAME = "system_tool_error"
70
+ """Emitted when a system tool encounters an error."""
71
+
72
+ # MARK: - Enrichment Events
73
+
74
+ ENRICHMENT_EVENT_NAME = "enrichment"
75
+ """Emitted when an agent transitions to a new execution phase (evaluating, planning, etc.)."""
76
+
77
+ MEMORY_SUMMARIZING_ENRICHMENT_PHASE = "memory_summarizing"
78
+ """Enrichment phase emitted before memory summarize-mode execution."""
79
+
80
+ MEMORY_SUMMARIZED_ENRICHMENT_PHASE = "memory_summarized"
81
+ """Enrichment phase emitted after memory summarize-mode execution completes."""
82
+
83
+ MEMORY_RETRIEVING_ENRICHMENT_PHASE = "memory_retrieving"
84
+ """Enrichment phase emitted before memory retrieve-mode execution."""
85
+
86
+ MEMORY_RETRIEVED_ENRICHMENT_PHASE = "memory_retrieved"
87
+ """Enrichment phase emitted after memory retrieval completes."""
88
+
89
+ MEMORY_INDEXING_ENRICHMENT_PHASE = "memory_indexing"
90
+ """Enrichment phase emitted before memory index-mode execution."""
91
+
92
+ MEMORY_INDEXED_ENRICHMENT_PHASE = "memory_indexed"
93
+ """Enrichment phase emitted after memory index-mode execution completes."""
94
+
95
+ MEMORY_GRAPH_EXTRACTING_ENRICHMENT_PHASE = "memory_graph_extracting"
96
+ """Enrichment phase emitted before graph/entity extraction in index-mode."""
97
+
98
+ MEMORY_SKILL_EXTRACTING_ENRICHMENT_PHASE = "memory_skill_extracting"
99
+ """Enrichment phase emitted while post-run skill extraction is in progress."""
100
+
101
+ MEMORY_INSIGHT_EXTRACTING_ENRICHMENT_PHASE = "memory_insight_extracting"
102
+ """Enrichment phase emitted while post-run insight extraction is in progress."""
103
+
104
+ MEMORY_SKILL_EXTRACTED_ENRICHMENT_PHASE = "memory_skill_extracted"
105
+ """Enrichment phase emitted after post-run skill extraction completes."""
106
+
107
+ MEMORY_INSIGHT_EXTRACTED_ENRICHMENT_PHASE = "memory_insight_extracted"
108
+ """Enrichment phase emitted after post-run insight extraction completes."""
109
+
110
+ MEMORY_ENRICHMENT_PHASES = (
111
+ MEMORY_SUMMARIZING_ENRICHMENT_PHASE,
112
+ MEMORY_SUMMARIZED_ENRICHMENT_PHASE,
113
+ MEMORY_RETRIEVING_ENRICHMENT_PHASE,
114
+ MEMORY_RETRIEVED_ENRICHMENT_PHASE,
115
+ MEMORY_INDEXING_ENRICHMENT_PHASE,
116
+ MEMORY_INDEXED_ENRICHMENT_PHASE,
117
+ MEMORY_GRAPH_EXTRACTING_ENRICHMENT_PHASE,
118
+ MEMORY_SKILL_EXTRACTING_ENRICHMENT_PHASE,
119
+ MEMORY_INSIGHT_EXTRACTING_ENRICHMENT_PHASE,
120
+ MEMORY_SKILL_EXTRACTED_ENRICHMENT_PHASE,
121
+ MEMORY_INSIGHT_EXTRACTED_ENRICHMENT_PHASE,
122
+ )
123
+ """Canonical memory-related enrichment phase identifiers."""
124
+
125
+ REDACTION_PREVIEWED_ENRICHMENT_PHASE = "redaction_previewed"
126
+ """Enrichment phase emitted when an explicit redaction preview completes."""
127
+
128
+ MESSAGE_REDACTION_APPLIED_ENRICHMENT_PHASE = "message_redaction_applied"
129
+ """Enrichment phase emitted when message redaction is applied during normal execution setup."""
130
+
131
+ REDACTION_ENRICHMENT_PHASES = (
132
+ REDACTION_PREVIEWED_ENRICHMENT_PHASE,
133
+ MESSAGE_REDACTION_APPLIED_ENRICHMENT_PHASE,
134
+ )
135
+ """Canonical redaction-related enrichment phase identifiers."""
136
+
137
+ RESOURCE_REGISTERING_ENRICHMENT_PHASE = "resource_registering"
138
+ """Enrichment phase emitted when resource registration begins."""
139
+
140
+ RESOURCE_REGISTERED_ENRICHMENT_PHASE = "resource_registered"
141
+ """Enrichment phase emitted when resource registration completes."""
142
+
143
+ RESOURCE_DEDUP_REUSED_ENRICHMENT_PHASE = "resource_dedup_reused"
144
+ """Enrichment phase emitted when existing resource content is reused (dedup)."""
145
+
146
+ RESOURCE_VERSION_SUPERSEDED_ENRICHMENT_PHASE = "resource_version_superseded"
147
+ """Enrichment phase emitted when a previous resource version is superseded."""
148
+
149
+ RESOURCE_EXTRACTING_ENRICHMENT_PHASE = "resource_extracting"
150
+ """Enrichment phase emitted when resource extraction starts."""
151
+
152
+ RESOURCE_EXTRACTED_ENRICHMENT_PHASE = "resource_extracted"
153
+ """Enrichment phase emitted when resource extraction completes."""
154
+
155
+ RESOURCE_ENRICHMENT_PHASES = (
156
+ RESOURCE_REGISTERING_ENRICHMENT_PHASE,
157
+ RESOURCE_REGISTERED_ENRICHMENT_PHASE,
158
+ RESOURCE_DEDUP_REUSED_ENRICHMENT_PHASE,
159
+ RESOURCE_VERSION_SUPERSEDED_ENRICHMENT_PHASE,
160
+ RESOURCE_EXTRACTING_ENRICHMENT_PHASE,
161
+ RESOURCE_EXTRACTED_ENRICHMENT_PHASE,
162
+ )
163
+ """Canonical resource-related enrichment phase identifiers."""
164
+
165
+ __all__ = [
166
+ # Tool Events
167
+ "TOOL_EVENT_NAME",
168
+ "INTERRUPT_REQUEST_EVENT_NAME",
169
+ "INTERRUPT_REQUIRED_EVENT_NAME",
170
+ # Assignment Events
171
+ "ASSIGNMENT_RECEIVED_EVENT_NAME",
172
+ "ASSIGNMENT_COMPLETED_EVENT_NAME",
173
+ # Model Events
174
+ "MODEL_TOOL_COMPLETE_EVENT_NAME",
175
+ # Lifecycle Events
176
+ "HEARTBEAT_EVENT_NAME",
177
+ "UPDATE_EVENT_NAME",
178
+ "PROGRESS_UPDATE_EVENT_NAME",
179
+ "STATUS_MESSAGE_EVENT_NAME",
180
+ "FINAL_EVENT_NAME",
181
+ "ERROR_EVENT_NAME",
182
+ # System Tool Events
183
+ "SYSTEM_TOOL_START_EVENT_NAME",
184
+ "SYSTEM_TOOL_CHUNK_EVENT_NAME",
185
+ "SYSTEM_TOOL_COMPLETE_EVENT_NAME",
186
+ "SYSTEM_TOOL_ERROR_EVENT_NAME",
187
+ # Enrichment Events
188
+ "ENRICHMENT_EVENT_NAME",
189
+ "MEMORY_SUMMARIZING_ENRICHMENT_PHASE",
190
+ "MEMORY_SUMMARIZED_ENRICHMENT_PHASE",
191
+ "MEMORY_RETRIEVING_ENRICHMENT_PHASE",
192
+ "MEMORY_RETRIEVED_ENRICHMENT_PHASE",
193
+ "MEMORY_INDEXING_ENRICHMENT_PHASE",
194
+ "MEMORY_INDEXED_ENRICHMENT_PHASE",
195
+ "MEMORY_GRAPH_EXTRACTING_ENRICHMENT_PHASE",
196
+ "MEMORY_SKILL_EXTRACTING_ENRICHMENT_PHASE",
197
+ "MEMORY_INSIGHT_EXTRACTING_ENRICHMENT_PHASE",
198
+ "MEMORY_SKILL_EXTRACTED_ENRICHMENT_PHASE",
199
+ "MEMORY_INSIGHT_EXTRACTED_ENRICHMENT_PHASE",
200
+ "MEMORY_ENRICHMENT_PHASES",
201
+ "REDACTION_PREVIEWED_ENRICHMENT_PHASE",
202
+ "MESSAGE_REDACTION_APPLIED_ENRICHMENT_PHASE",
203
+ "REDACTION_ENRICHMENT_PHASES",
204
+ "RESOURCE_REGISTERING_ENRICHMENT_PHASE",
205
+ "RESOURCE_REGISTERED_ENRICHMENT_PHASE",
206
+ "RESOURCE_DEDUP_REUSED_ENRICHMENT_PHASE",
207
+ "RESOURCE_VERSION_SUPERSEDED_ENRICHMENT_PHASE",
208
+ "RESOURCE_EXTRACTING_ENRICHMENT_PHASE",
209
+ "RESOURCE_EXTRACTED_ENRICHMENT_PHASE",
210
+ "RESOURCE_ENRICHMENT_PHASES",
211
+ ]