swarmauri-core 0.6.0.dev129__tar.gz → 0.6.0.dev130__tar.gz

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 (113) hide show
  1. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/PKG-INFO +1 -1
  2. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/pyproject.toml +1 -1
  3. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/ComponentBase.py +45 -39
  4. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/README.md +0 -0
  5. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/README.md +0 -0
  6. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/__init__.py +0 -0
  7. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/agent_apis/IAgentCommands.py +0 -0
  8. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/agent_apis/IAgentRouterCRUD.py +0 -0
  9. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/agent_apis/__init__.py +0 -0
  10. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/agent_factories/IExportConf.py +0 -0
  11. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/agent_factories/__init__.py +0 -0
  12. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/agents/IAgent.py +0 -0
  13. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/agents/IAgentConversation.py +0 -0
  14. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/agents/IAgentParser.py +0 -0
  15. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/agents/IAgentRetrieve.py +0 -0
  16. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/agents/IAgentSystemContext.py +0 -0
  17. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/agents/IAgentToolkit.py +0 -0
  18. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/agents/IAgentVectorStore.py +0 -0
  19. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/agents/__init__.py +0 -0
  20. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/chains/ICallableChain.py +0 -0
  21. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/chains/IChain.py +0 -0
  22. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/chains/IChainContext.py +0 -0
  23. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/chains/IChainContextLoader.py +0 -0
  24. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/chains/IChainDependencyResolver.py +0 -0
  25. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/chains/IChainFactory.py +0 -0
  26. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/chains/IChainStep.py +0 -0
  27. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/chains/__init__.py +0 -0
  28. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/chunkers/IChunker.py +0 -0
  29. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/chunkers/__init__.py +0 -0
  30. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/control_panels/IControlPanel.py +0 -0
  31. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/control_panels/__init__.py +0 -0
  32. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/conversations/IConversation.py +0 -0
  33. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/conversations/IMaxSize.py +0 -0
  34. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/conversations/ISystemContext.py +0 -0
  35. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/conversations/__init__.py +0 -0
  36. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/dataconnectors/IDataConnector.py +0 -0
  37. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/dataconnectors/__init__.py +0 -0
  38. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/distances/IDistanceSimilarity.py +0 -0
  39. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/distances/__init__.py +0 -0
  40. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/document_stores/IDocumentRetrieve.py +0 -0
  41. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/document_stores/IDocumentStore.py +0 -0
  42. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/document_stores/__init__.py +0 -0
  43. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/documents/IDocument.py +0 -0
  44. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/documents/IExperimentDocument.py +0 -0
  45. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/documents/__init__.py +0 -0
  46. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/embeddings/IFeature.py +0 -0
  47. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/embeddings/ISaveModel.py +0 -0
  48. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/embeddings/IVectorize.py +0 -0
  49. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/embeddings/__init__.py +0 -0
  50. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/experiment_stores/IExperimentStore.py +0 -0
  51. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/experiment_stores/__init__.py +0 -0
  52. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/factories/IFactory.py +0 -0
  53. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/factories/__init__.py +0 -0
  54. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/image_gens/IGenImage.py +0 -0
  55. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/image_gens/__init__.py +0 -0
  56. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/llms/IFit.py +0 -0
  57. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/llms/IPredict.py +0 -0
  58. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/llms/__init__.py +0 -0
  59. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/measurements/IMeasurement.py +0 -0
  60. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/measurements/IMeasurementAggregate.py +0 -0
  61. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/measurements/IMeasurementCalculate.py +0 -0
  62. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/measurements/IThreshold.py +0 -0
  63. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/measurements/__init__.py +0 -0
  64. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/messages/IMessage.py +0 -0
  65. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/messages/__init__.py +0 -0
  66. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/parsers/IParser.py +0 -0
  67. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/parsers/__init__.py +0 -0
  68. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/pipelines/IPipeline.py +0 -0
  69. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/pipelines/__init__.py +0 -0
  70. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/prompts/IPrompt.py +0 -0
  71. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/prompts/IPromptMatrix.py +0 -0
  72. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/prompts/ITemplate.py +0 -0
  73. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/prompts/__init__.py +0 -0
  74. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/schema_converters/ISchemaConvert.py +0 -0
  75. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/schema_converters/__init__.py +0 -0
  76. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/service_registries/IServiceRegistry.py +0 -0
  77. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/service_registries/__init__.py +0 -0
  78. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/state/IState.py +0 -0
  79. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/swarm_apis/IAgentRegistrationAPI.py +0 -0
  80. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/swarm_apis/ISwarmAPI.py +0 -0
  81. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/swarm_apis/__init__.py +0 -0
  82. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/swarms/ISwarm.py +0 -0
  83. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/swarms/__init__.py +0 -0
  84. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/task_mgmt_strategies/ITaskMgmtStrategy.py +0 -0
  85. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/task_mgmt_strategies/__init__.py +0 -0
  86. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/toolkits/IToolkit.py +0 -0
  87. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/toolkits/__init__.py +0 -0
  88. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/tools/IParameter.py +0 -0
  89. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/tools/ITool.py +0 -0
  90. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/tools/__init__.py +0 -0
  91. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/tracing/IChainTracer.py +0 -0
  92. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/tracing/ITraceContext.py +0 -0
  93. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/tracing/ITracer.py +0 -0
  94. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/tracing/__init__.py +0 -0
  95. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/transports/ITransport.py +0 -0
  96. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/transports/__init__.py +0 -0
  97. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/utils/ITransactional.py +0 -0
  98. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/utils/__init__.py +0 -0
  99. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vcms/IPredictVision.py +0 -0
  100. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vcms/__init__.py +0 -0
  101. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vector_stores/ICloudVectorStore.py +0 -0
  102. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vector_stores/IPersistentVectorStore.py +0 -0
  103. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vector_stores/ISimilarity.py +0 -0
  104. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vector_stores/IVectorNorm.py +0 -0
  105. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vector_stores/IVectorStore.py +0 -0
  106. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vector_stores/IVectorStoreRetrieve.py +0 -0
  107. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vector_stores/IVectorStoreSaveLoad.py +0 -0
  108. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vector_stores/__init__.py +0 -0
  109. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vectors/IVector.py +0 -0
  110. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vectors/IVectorMeta.py +0 -0
  111. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vectors/IVectorProduct.py +0 -0
  112. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vectors/IVectorTransform.py +0 -0
  113. {swarmauri_core-0.6.0.dev129 → swarmauri_core-0.6.0.dev130}/swarmauri_core/vectors/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: swarmauri-core
3
- Version: 0.6.0.dev129
3
+ Version: 0.6.0.dev130
4
4
  Summary: This repository includes core interfaces for the Swarmauri framework.
5
5
  Home-page: http://github.com/swarmauri/swarmauri-sdk
6
6
  License: Apache-2.0
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "swarmauri-core"
3
- version = "0.6.0.dev129"
3
+ version = "0.6.0.dev130"
4
4
  description = "This repository includes core interfaces for the Swarmauri framework."
5
5
  authors = ["Jacob Stewart <jacob@swarmauri.com>"]
6
6
  license = "Apache-2.0"
@@ -44,7 +44,7 @@ class SubclassUnion(type):
44
44
  """
45
45
  registered_classes = list(ComponentBase.TYPE_REGISTRY.get(resource_type, {}).values())
46
46
  if not registered_classes:
47
- logger.warning(f"No subclasses registered for resource type '{resource_type.__name__}'. Using 'Any' as a placeholder.")
47
+ logger.debug(f"No subclasses registered for resource type '{resource_type.__name__}'. Using 'Any' as a placeholder.")
48
48
  return Annotated[Any, Field(...)]
49
49
  else:
50
50
  union_type = Union[tuple(registered_classes)]
@@ -194,9 +194,9 @@ class ComponentBase(BaseModel):
194
194
  if model_cls not in cls.MODEL_REGISTRY:
195
195
  cls.MODEL_REGISTRY[model_cls] = []
196
196
 
197
- # Inspect all fields to find SubclassUnion annotations, including inherited fields
197
+ # Inspect all fields to find SubclassUnion annotations
198
198
  for field_name, field in model_cls.__fields__.items():
199
- field_annotation = cls.get_field_annotation(model_cls, field_name)
199
+ field_annotation = model_cls.__annotations__.get(field_name)
200
200
  if not field_annotation:
201
201
  continue
202
202
 
@@ -208,29 +208,10 @@ class ComponentBase(BaseModel):
208
208
  if resource_type not in cls.MODEL_REGISTRY[model_cls]:
209
209
  cls.MODEL_REGISTRY[model_cls].append(resource_type)
210
210
  logger.info(f"Registered model '{model_cls.__name__}' for resource '{resource_type.__name__}'")
211
+ cls.recreate_models()
211
212
  return model_cls
212
213
  return decorator
213
214
 
214
- @classmethod
215
- def get_field_annotation(cls, model_cls: Type[BaseModel], field_name: str):
216
- """
217
- Retrieve the field annotation for a given field, including inherited fields.
218
-
219
- Parameters:
220
- - model_cls: The Pydantic model class.
221
- - field_name: The name of the field.
222
-
223
- Returns:
224
- - The type annotation of the field, or None if not found.
225
- """
226
- for base in inspect.getmro(model_cls):
227
- if base == object:
228
- continue
229
- annotations = getattr(base, '__annotations__', {})
230
- if field_name in annotations:
231
- return annotations[field_name]
232
- return None
233
-
234
215
  @classmethod
235
216
  def get_class_by_type(cls, resource_type: Type[T], type_name: str) -> Type['ComponentBase']:
236
217
  """
@@ -256,17 +237,25 @@ class ComponentBase(BaseModel):
256
237
  Returns:
257
238
  - True if SubclassUnion is present, False otherwise.
258
239
  """
240
+ logger.debug(f"Checking if field annotation '{field_annotation}' contains a SubclassUnion")
259
241
  if isinstance(field_annotation, type(SubclassUnion)):
242
+ logger.debug(f"Field annotation '{field_annotation}' is directly a SubclassUnion")
260
243
  return True
261
244
  origin = get_origin(field_annotation)
262
245
  if origin is Annotated:
263
246
  args = get_args(field_annotation)
247
+ logger.debug(f"Field annotation '{field_annotation}' is Annotated with args {args}")
264
248
  return cls.field_contains_subclass_union(args[0])
265
249
  elif origin in {list, List, dict, Dict, Union}:
266
250
  args = get_args(field_annotation)
267
- return any(cls.field_contains_subclass_union(arg) for arg in args)
251
+ logger.debug(f"Field annotation '{field_annotation}' has origin '{origin.__name__}' with args {args}")
252
+ result = any(cls.field_contains_subclass_union(arg) for arg in args)
253
+ logger.debug(f"Field annotation '{field_annotation}' contains SubclassUnion: {result}")
254
+ return result
255
+ logger.debug(f"Field annotation '{field_annotation}' does not contain a SubclassUnion")
268
256
  return False
269
257
 
258
+
270
259
  @classmethod
271
260
  def extract_resource_types_from_field(cls, field_annotation) -> List[Type['ComponentBase']]:
272
261
  """
@@ -278,6 +267,7 @@ class ComponentBase(BaseModel):
278
267
  Returns:
279
268
  - A list of resource type classes.
280
269
  """
270
+ logger.debug(f"Extracting resource types from field annotation '{field_annotation}'")
281
271
  resource_types = []
282
272
 
283
273
  origin = get_origin(field_annotation)
@@ -285,29 +275,39 @@ class ComponentBase(BaseModel):
285
275
 
286
276
  if origin is Annotated:
287
277
  # Extract the actual type from Annotated
278
+ logger.debug(f"Field annotation '{field_annotation}' is Annotated")
288
279
  field_annotation = args[0]
289
280
  origin = get_origin(field_annotation)
290
281
  args = get_args(field_annotation)
291
282
 
292
283
  if origin is Union:
284
+ logger.debug(f"Field annotation '{field_annotation}' is a Union")
293
285
  for arg in args:
294
286
  if cls.field_contains_subclass_union(arg):
287
+ logger.debug(f"Union member '{arg}' contains a SubclassUnion")
295
288
  resource_types.extend(cls.extract_resource_types_from_field(arg))
296
289
  elif inspect.isclass(field_annotation) and issubclass(field_annotation, SubclassUnion):
297
290
  # Assuming SubclassUnion is generic and parameterized
291
+ logger.debug(f"Field annotation '{field_annotation}' is a subclass of SubclassUnion")
298
292
  subclass_args = get_args(field_annotation)
299
293
  if subclass_args:
300
294
  resource_type = subclass_args[0]
295
+ logger.debug(f"Extracted resource type '{resource_type.__name__}' from SubclassUnion")
301
296
  resource_types.append(resource_type)
302
297
  elif origin in {list, List}:
303
298
  # Handle List[SubclassUnion[ResourceType]]
304
299
  item_type = args[0]
300
+ logger.debug(f"Field annotation '{field_annotation}' is a List with item type '{item_type}'")
305
301
  resource_types.extend(cls.extract_resource_types_from_field(item_type))
306
302
  elif origin in {dict, Dict}:
307
303
  # Handle Dict[key_type, SubclassUnion[ResourceType]]
308
304
  value_type = args[1]
305
+ logger.debug(f"Field annotation '{field_annotation}' is a Dict with value type '{value_type}'")
309
306
  resource_types.extend(cls.extract_resource_types_from_field(value_type))
307
+ else:
308
+ logger.debug(f"Field annotation '{field_annotation}' does not match any known patterns for SubclassUnion")
310
309
 
310
+ logger.debug(f"Extracted resource types: {[rt.__name__ for rt in resource_types]}")
311
311
  return resource_types
312
312
 
313
313
  @classmethod
@@ -322,6 +322,7 @@ class ComponentBase(BaseModel):
322
322
  Returns:
323
323
  - The updated type annotation incorporating SubclassUnion.
324
324
  """
325
+ logger.debug(f"Determining new type for field annotation '{field_annotation}' with resource type '{resource_type.__name__}'")
325
326
  origin = get_origin(field_annotation)
326
327
  args = get_args(field_annotation)
327
328
 
@@ -330,20 +331,24 @@ class ComponentBase(BaseModel):
330
331
  if origin is Union and type(None) in args:
331
332
  # Handle Optional and Union types
332
333
  non_none_args = [arg for arg in args if arg is not type(None)]
334
+ logger.debug(f"Field annotation '{field_annotation}' is Optional/Union with non-None args {non_none_args}")
333
335
  if len(non_none_args) == 1:
334
336
  field_annotation = non_none_args[0]
335
337
  origin = get_origin(field_annotation)
336
338
  args = get_args(field_annotation)
337
339
  is_optional = True
340
+ logger.debug(f"Field is Optional with single non-None type '{field_annotation}'")
338
341
  else:
339
342
  field_annotation = Union[tuple(non_none_args)]
340
343
  origin = get_origin(field_annotation)
341
344
  args = get_args(field_annotation)
342
345
  is_optional = True
346
+ logger.debug(f"Field is Optional with multiple non-None types '{field_annotation}'")
343
347
 
344
348
  # Handle Annotated types by extracting the underlying type
345
349
  if origin is Annotated:
346
350
  # Extract the actual type from Annotated
351
+ logger.debug(f"Field annotation '{field_annotation}' is Annotated")
347
352
  field_annotation = args[0]
348
353
  origin = get_origin(field_annotation)
349
354
  args = get_args(field_annotation)
@@ -351,22 +356,28 @@ class ComponentBase(BaseModel):
351
356
  if origin in {list, List}:
352
357
  # Handle List[SubclassUnion[ResourceType]]
353
358
  new_type = List[SubclassUnion[resource_type]]
359
+ logger.debug(f"New type for List field: '{new_type}'")
354
360
  elif origin in {dict, Dict}:
355
361
  # Handle Dict[key_type, SubclassUnion[ResourceType]]
356
362
  key_type, value_type = args
357
363
  new_type = Dict[key_type, SubclassUnion[resource_type]]
364
+ logger.debug(f"New type for Dict field: '{new_type}'")
358
365
  elif origin is Union:
359
366
  # Handle Union types
360
367
  union_types = []
361
368
  for arg in args:
362
369
  if cls.field_contains_subclass_union(arg):
363
370
  union_types.append(SubclassUnion[resource_type])
371
+ logger.debug(f"Added SubclassUnion[{resource_type.__name__}] to Union types")
364
372
  else:
365
373
  union_types.append(arg)
374
+ logger.debug(f"Added type '{arg}' to Union types")
366
375
  new_type = Union[tuple(union_types)]
376
+ logger.debug(f"New Union type: '{new_type}'")
367
377
  else:
368
378
  # Handle non-generic types
369
379
  new_type = SubclassUnion[resource_type]
380
+ logger.debug(f"New non-generic SubclassUnion type: '{new_type}'")
370
381
 
371
382
  if is_optional:
372
383
  # Include None in the Union and maintain the discriminator
@@ -374,38 +385,34 @@ class ComponentBase(BaseModel):
374
385
  if not registered_classes:
375
386
  # Use Any as a placeholder if no subclasses are registered
376
387
  union_type = Any
388
+ logger.debug(f"No registered subclasses for resource type '{resource_type.__name__}'. Using 'Any' in Optional type.")
377
389
  else:
378
390
  union_type = Union[tuple(registered_classes)]
391
+ logger.debug(f"Registered subclasses for resource type '{resource_type.__name__}': {[cls.__name__ for cls in registered_classes]}")
379
392
  union_with_none = Union[tuple([union_type, type(None)])]
380
393
  new_type = Annotated[
381
394
  union_with_none,
382
395
  Field(discriminator="type")
383
396
  ]
397
+ logger.debug(f"Final new type with Optional: '{new_type}'")
384
398
 
399
+ logger.debug(f"Determined new type for field: '{new_type}'")
385
400
  return new_type
386
401
 
402
+
387
403
  @classmethod
388
404
  def generate_models_with_fields(cls) -> Dict[Type[BaseModel], Dict[str, Any]]:
389
405
  """
390
- Automatically generate the models_with_fields dictionary based on registered models,
391
- including subclasses that inherit fields using SubclassUnion.
392
-
406
+ Automatically generate the models_with_fields dictionary based on registered models.
407
+
393
408
  Returns:
394
409
  - A dictionary mapping model classes to their fields and corresponding resource types.
395
410
  """
396
411
  models_with_fields = {}
397
-
398
- # Collect all models, including subclasses of registered models
399
- all_models = set(cls.MODEL_REGISTRY.keys())
400
- for model_cls in list(all_models):
401
- for subclass in model_cls.__subclasses__():
402
- if issubclass(subclass, BaseModel):
403
- all_models.add(subclass)
404
-
405
- for model_cls in all_models:
412
+ for model_cls, resource_types in cls.MODEL_REGISTRY.items():
406
413
  models_with_fields[model_cls] = {}
407
- for field_name in model_cls.__fields__:
408
- field_annotation = cls.get_field_annotation(model_cls, field_name)
414
+ for field_name, field in model_cls.__fields__.items():
415
+ field_annotation = model_cls.__annotations__.get(field_name)
409
416
  if not field_annotation:
410
417
  continue
411
418
 
@@ -421,7 +428,6 @@ class ComponentBase(BaseModel):
421
428
 
422
429
  return models_with_fields
423
430
 
424
-
425
431
  @classmethod
426
432
  def recreate_models(cls):
427
433
  """