codecraftai-agent-kit 1.3.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 (230) hide show
  1. ccai/agentkit/__init__.py +304 -0
  2. ccai/agentkit/addressresolver.py +177 -0
  3. ccai/agentkit/agent.py +2945 -0
  4. ccai/agentkit/agentaddress.py +187 -0
  5. ccai/agentkit/agentconfiguration.py +581 -0
  6. ccai/agentkit/agentidentity.py +152 -0
  7. ccai/agentkit/agentregistry.py +221 -0
  8. ccai/agentkit/agentstatemachine.py +134 -0
  9. ccai/agentkit/alternateproviderstrategy.py +36 -0
  10. ccai/agentkit/approvalgate.py +238 -0
  11. ccai/agentkit/approvalrequest.py +250 -0
  12. ccai/agentkit/asyncagent.py +187 -0
  13. ccai/agentkit/breakpoint.py +150 -0
  14. ccai/agentkit/builtinagentmetrics.py +114 -0
  15. ccai/agentkit/builtins/__init__.py +11 -0
  16. ccai/agentkit/builtins/filereadtool.py +90 -0
  17. ccai/agentkit/builtins/filewritetool.py +93 -0
  18. ccai/agentkit/builtins/httprequesttool.py +169 -0
  19. ccai/agentkit/builtins/shellcommandtool.py +190 -0
  20. ccai/agentkit/cachedresultstrategy.py +43 -0
  21. ccai/agentkit/checkpointmanager.py +219 -0
  22. ccai/agentkit/circuitbreaker.py +230 -0
  23. ccai/agentkit/circuitbreakerconfiguration.py +158 -0
  24. ccai/agentkit/circuitbreakerevent.py +158 -0
  25. ccai/agentkit/circuitbreakerhealthcheck.py +32 -0
  26. ccai/agentkit/circuitbreakerregistry.py +116 -0
  27. ccai/agentkit/circuitbreakerstate.py +44 -0
  28. ccai/agentkit/clearcacheaction.py +46 -0
  29. ccai/agentkit/concurrencybridge.py +143 -0
  30. ccai/agentkit/concurrencymodel.py +19 -0
  31. ccai/agentkit/conditionevaluator.py +594 -0
  32. ccai/agentkit/configurationchangeevent.py +179 -0
  33. ccai/agentkit/configurationerrors.py +152 -0
  34. ccai/agentkit/configurationlayer.py +160 -0
  35. ccai/agentkit/configurationlayersource.py +46 -0
  36. ccai/agentkit/configurationmanager.py +680 -0
  37. ccai/agentkit/configurationschema.py +224 -0
  38. ccai/agentkit/configurationschemafield.py +217 -0
  39. ccai/agentkit/configurationserializer.py +163 -0
  40. ccai/agentkit/configurationvalidationresult.py +118 -0
  41. ccai/agentkit/contextsummarizer.py +170 -0
  42. ccai/agentkit/contextwindow.py +264 -0
  43. ccai/agentkit/contextwindowstrategy.py +57 -0
  44. ccai/agentkit/correlationcontext.py +156 -0
  45. ccai/agentkit/costestimate.py +139 -0
  46. ccai/agentkit/costtracker.py +121 -0
  47. ccai/agentkit/deadletterentry.py +134 -0
  48. ccai/agentkit/deadletterquery.py +119 -0
  49. ccai/agentkit/deadletterqueue.py +123 -0
  50. ccai/agentkit/deadletterstore.py +86 -0
  51. ccai/agentkit/debuginspector.py +211 -0
  52. ccai/agentkit/debugsession.py +223 -0
  53. ccai/agentkit/defaultvaluestrategy.py +43 -0
  54. ccai/agentkit/degradationchangeevent.py +120 -0
  55. ccai/agentkit/degradationlevel.py +44 -0
  56. ccai/agentkit/degradationmanager.py +212 -0
  57. ccai/agentkit/degradationpolicy.py +130 -0
  58. ccai/agentkit/degradationstrategy.py +66 -0
  59. ccai/agentkit/embeddingprovider.py +106 -0
  60. ccai/agentkit/errors.py +95 -0
  61. ccai/agentkit/executionrecord.py +213 -0
  62. ccai/agentkit/executionrecorder.py +180 -0
  63. ccai/agentkit/executionrecording.py +230 -0
  64. ccai/agentkit/executionreplayer.py +187 -0
  65. ccai/agentkit/expirationpolicy.py +116 -0
  66. ccai/agentkit/fallbackchain.py +82 -0
  67. ccai/agentkit/featureflag.py +154 -0
  68. ccai/agentkit/featureflagevaluator.py +109 -0
  69. ccai/agentkit/featureflagregistry.py +258 -0
  70. ccai/agentkit/filedeadletterstore.py +112 -0
  71. ccai/agentkit/filememorystore.py +291 -0
  72. ccai/agentkit/healthcheck.py +46 -0
  73. ccai/agentkit/healthcheckregistry.py +51 -0
  74. ccai/agentkit/healthmonitor.py +258 -0
  75. ccai/agentkit/healthstatus.py +105 -0
  76. ccai/agentkit/hotreloadmonitor.py +214 -0
  77. ccai/agentkit/hotreloadpolicy.py +160 -0
  78. ccai/agentkit/inmemorydeadletterstore.py +61 -0
  79. ccai/agentkit/inmemorystore.py +173 -0
  80. ccai/agentkit/jsonmessageserializer.py +89 -0
  81. ccai/agentkit/jsonoutputparser.py +50 -0
  82. ccai/agentkit/lifecyclestate.py +22 -0
  83. ccai/agentkit/llmconversation.py +153 -0
  84. ccai/agentkit/llmerrors.py +193 -0
  85. ccai/agentkit/llmmessage.py +158 -0
  86. ccai/agentkit/llmprovider.py +158 -0
  87. ccai/agentkit/llmproviderregistry.py +200 -0
  88. ccai/agentkit/llmresponse.py +190 -0
  89. ccai/agentkit/llmstreamchunk.py +65 -0
  90. ccai/agentkit/llmstreamhandler.py +48 -0
  91. ccai/agentkit/llmtoolbridge.py +154 -0
  92. ccai/agentkit/logexporter.py +316 -0
  93. ccai/agentkit/logformatter.py +169 -0
  94. ccai/agentkit/memoryconfiguration.py +243 -0
  95. ccai/agentkit/memoryentry.py +254 -0
  96. ccai/agentkit/memoryerrors.py +135 -0
  97. ccai/agentkit/memoryindex.py +213 -0
  98. ccai/agentkit/memoryquery.py +248 -0
  99. ccai/agentkit/memoryqueryresult.py +86 -0
  100. ccai/agentkit/memoryscope.py +54 -0
  101. ccai/agentkit/memorystore.py +260 -0
  102. ccai/agentkit/memorystorehealthcheck.py +33 -0
  103. ccai/agentkit/memorystoreregistry.py +106 -0
  104. ccai/agentkit/message.py +310 -0
  105. ccai/agentkit/messageenvelope.py +144 -0
  106. ccai/agentkit/messagepattern.py +50 -0
  107. ccai/agentkit/messagerouter.py +290 -0
  108. ccai/agentkit/messageserializer.py +106 -0
  109. ccai/agentkit/messageserializerregistry.py +163 -0
  110. ccai/agentkit/messagingconfiguration.py +397 -0
  111. ccai/agentkit/messagingerrors.py +338 -0
  112. ccai/agentkit/metricdefinition.py +164 -0
  113. ccai/agentkit/metricmeasurement.py +178 -0
  114. ccai/agentkit/metricscollector.py +258 -0
  115. ccai/agentkit/metricsexporter.py +303 -0
  116. ccai/agentkit/metricsregistry.py +130 -0
  117. ccai/agentkit/metricssnapshot.py +155 -0
  118. ccai/agentkit/metrictype.py +51 -0
  119. ccai/agentkit/msgpackmessageserializer.py +97 -0
  120. ccai/agentkit/observabilityconfiguration.py +546 -0
  121. ccai/agentkit/observabilityerror.py +67 -0
  122. ccai/agentkit/observabilitypipeline.py +252 -0
  123. ccai/agentkit/outputparser.py +82 -0
  124. ccai/agentkit/outputschema.py +142 -0
  125. ccai/agentkit/parallelbranch.py +87 -0
  126. ccai/agentkit/platform/__init__.py +43 -0
  127. ccai/agentkit/platform/adapters/__init__.py +18 -0
  128. ccai/agentkit/platform/adapters/awsplatformadapter.py +1272 -0
  129. ccai/agentkit/platform/adapters/azureplatformadapter.py +1227 -0
  130. ccai/agentkit/platform/adapters/gcpplatformadapter.py +1257 -0
  131. ccai/agentkit/platform/adapters/localplatformadapter.py +956 -0
  132. ccai/agentkit/platform/adapters/platformadapter.py +139 -0
  133. ccai/agentkit/platform/deployment/__init__.py +15 -0
  134. ccai/agentkit/platform/deployment/deploymentdescriptor.py +234 -0
  135. ccai/agentkit/platform/deployment/deploymentdescriptorparser.py +178 -0
  136. ccai/agentkit/platform/deployment/deploymentdescriptorprinter.py +97 -0
  137. ccai/agentkit/platform/errors.py +224 -0
  138. ccai/agentkit/platform/platformconfiguration.py +412 -0
  139. ccai/agentkit/platform/platformdetector.py +125 -0
  140. ccai/agentkit/platform/platformruntime.py +331 -0
  141. ccai/agentkit/platform/platformserviceregistry.py +149 -0
  142. ccai/agentkit/platform/platformtype.py +60 -0
  143. ccai/agentkit/platform/services/__init__.py +19 -0
  144. ccai/agentkit/platform/services/computeservice.py +112 -0
  145. ccai/agentkit/platform/services/invocationresult.py +173 -0
  146. ccai/agentkit/platform/services/messagingservice.py +135 -0
  147. ccai/agentkit/platform/services/platformservice.py +111 -0
  148. ccai/agentkit/platform/services/queuemessage.py +193 -0
  149. ccai/agentkit/platform/services/storageobject.py +195 -0
  150. ccai/agentkit/platform/services/storageservice.py +159 -0
  151. ccai/agentkit/pluginconfiguration.py +241 -0
  152. ccai/agentkit/plugindependency.py +129 -0
  153. ccai/agentkit/plugindescriptor.py +225 -0
  154. ccai/agentkit/pluginlifecyclehook.py +41 -0
  155. ccai/agentkit/pluginmanager.py +360 -0
  156. ccai/agentkit/pluginstatus.py +47 -0
  157. ccai/agentkit/pooledagent.py +116 -0
  158. ccai/agentkit/prompttemplate.py +221 -0
  159. ccai/agentkit/prompttemplateregistry.py +145 -0
  160. ccai/agentkit/protobufmessageserializer.py +144 -0
  161. ccai/agentkit/pubsubbroker.py +311 -0
  162. ccai/agentkit/py.typed +0 -0
  163. ccai/agentkit/reconnecttransportaction.py +47 -0
  164. ccai/agentkit/regexoutputparser.py +68 -0
  165. ccai/agentkit/requestresponsehandler.py +274 -0
  166. ccai/agentkit/resetcircuitbreakeraction.py +48 -0
  167. ccai/agentkit/resilienceconfiguration.py +191 -0
  168. ccai/agentkit/resilienceerrors.py +103 -0
  169. ccai/agentkit/resiliencepipeline.py +201 -0
  170. ccai/agentkit/retryattempt.py +158 -0
  171. ccai/agentkit/retryexecutor.py +157 -0
  172. ccai/agentkit/retrypolicy.py +195 -0
  173. ccai/agentkit/retryresult.py +186 -0
  174. ccai/agentkit/selfhealingaction.py +42 -0
  175. ccai/agentkit/selfhealingpolicy.py +67 -0
  176. ccai/agentkit/selfhealingresult.py +130 -0
  177. ccai/agentkit/stepexecutionstatus.py +52 -0
  178. ccai/agentkit/stepresult.py +198 -0
  179. ccai/agentkit/steps/__init__.py +9 -0
  180. ccai/agentkit/steps/agentstep.py +247 -0
  181. ccai/agentkit/steps/approvalstep.py +276 -0
  182. ccai/agentkit/steps/llmstep.py +403 -0
  183. ccai/agentkit/steps/subworkflowstep.py +270 -0
  184. ccai/agentkit/steps/toolstep.py +265 -0
  185. ccai/agentkit/structuredlogentry.py +222 -0
  186. ccai/agentkit/structuredlogger.py +189 -0
  187. ccai/agentkit/subscription.py +141 -0
  188. ccai/agentkit/threadedagent.py +94 -0
  189. ccai/agentkit/tokenusage.py +136 -0
  190. ccai/agentkit/tool.py +203 -0
  191. ccai/agentkit/toolchain.py +268 -0
  192. ccai/agentkit/toolchainexecutor.py +134 -0
  193. ccai/agentkit/toolchainresult.py +166 -0
  194. ccai/agentkit/tooldescriptor.py +203 -0
  195. ccai/agentkit/toolerrors.py +160 -0
  196. ccai/agentkit/toolexecutor.py +168 -0
  197. ccai/agentkit/toolfactory.py +60 -0
  198. ccai/agentkit/toolregistry.py +184 -0
  199. ccai/agentkit/toolresult.py +142 -0
  200. ccai/agentkit/toolschema.py +197 -0
  201. ccai/agentkit/tracecontext.py +294 -0
  202. ccai/agentkit/traceevent.py +166 -0
  203. ccai/agentkit/traceexporter.py +305 -0
  204. ccai/agentkit/tracer.py +234 -0
  205. ccai/agentkit/tracespan.py +349 -0
  206. ccai/agentkit/transitionrecord.py +84 -0
  207. ccai/agentkit/transport.py +334 -0
  208. ccai/agentkit/transportconfiguration.py +436 -0
  209. ccai/agentkit/transporthealthcheck.py +36 -0
  210. ccai/agentkit/transportregistry.py +224 -0
  211. ccai/agentkit/transports/__init__.py +28 -0
  212. ccai/agentkit/transports/grpctransport.py +410 -0
  213. ccai/agentkit/transports/httptransport.py +423 -0
  214. ccai/agentkit/transports/messagequeuetransport.py +489 -0
  215. ccai/agentkit/transports/websockettransport.py +473 -0
  216. ccai/agentkit/workflowcheckpoint.py +208 -0
  217. ccai/agentkit/workflowconfiguration.py +295 -0
  218. ccai/agentkit/workflowcontext.py +249 -0
  219. ccai/agentkit/workflowdefinition.py +790 -0
  220. ccai/agentkit/workflowedge.py +128 -0
  221. ccai/agentkit/workflowerrors.py +295 -0
  222. ccai/agentkit/workflowexecutionstatus.py +48 -0
  223. ccai/agentkit/workflowexecutor.py +1121 -0
  224. ccai/agentkit/workflowregistry.py +185 -0
  225. ccai/agentkit/workflowresult.py +250 -0
  226. ccai/agentkit/workflowstep.py +195 -0
  227. codecraftai_agent_kit-1.3.0.dist-info/METADATA +99 -0
  228. codecraftai_agent_kit-1.3.0.dist-info/RECORD +230 -0
  229. codecraftai_agent_kit-1.3.0.dist-info/WHEEL +4 -0
  230. codecraftai_agent_kit-1.3.0.dist-info/licenses/LICENSE.md +204 -0
@@ -0,0 +1,139 @@
1
+ """
2
+ Defines the PlatformAdapter abstract base class that bundles a complete
3
+ set of platform service implementations (ComputeService, StorageService,
4
+ MessagingService) for a specific platform. Concrete implementations
5
+ provide AwsPlatformAdapter, AzurePlatformAdapter, GcpPlatformAdapter,
6
+ and LocalPlatformAdapter.
7
+
8
+ .. module:: ccai.agentkit.platform.adapters.platformadapter
9
+ :platform: Darwin, Linux, Unix, Windows
10
+ :synopsis: Abstract platform adapter base class bundling platform services.
11
+ """
12
+
13
+ import abc
14
+ import logging
15
+
16
+ from ccai.agentkit.platform.platformconfiguration import PlatformConfiguration
17
+ from ccai.agentkit.platform.platformtype import PlatformType
18
+ from ccai.agentkit.platform.services.computeservice import ComputeService
19
+ from ccai.agentkit.platform.services.messagingservice import MessagingService
20
+ from ccai.agentkit.platform.services.storageservice import StorageService
21
+
22
+
23
+ logger = logging.getLogger("ccai.agentkit.platform.adapters")
24
+
25
+
26
+ class PlatformAdapter(abc.ABC):
27
+ """
28
+ Abstract base class that bundles a complete set of platform service
29
+ implementations for a specific platform. Concrete implementations
30
+ provide compute, storage, and messaging services as a unit.
31
+
32
+ Swapping platforms means swapping one adapter, not three services.
33
+
34
+ :param configuration: The PlatformConfiguration for initializing
35
+ platform-specific service clients.
36
+ """
37
+
38
+ def __init__(self, configuration: PlatformConfiguration) -> None:
39
+ self._configuration = configuration
40
+ return
41
+
42
+ @property
43
+ @abc.abstractmethod
44
+ def platform_type(self) -> PlatformType:
45
+ """
46
+ Returns the PlatformType for this adapter.
47
+
48
+ :returns: The PlatformType value.
49
+ """
50
+
51
+ @abc.abstractmethod
52
+ def get_compute_service(self) -> ComputeService:
53
+ """
54
+ Returns the ComputeService for this platform.
55
+
56
+ :returns: A ComputeService instance.
57
+ """
58
+
59
+ @abc.abstractmethod
60
+ def get_storage_service(self) -> StorageService:
61
+ """
62
+ Returns the StorageService for this platform.
63
+
64
+ :returns: A StorageService instance.
65
+ """
66
+
67
+ @abc.abstractmethod
68
+ def get_messaging_service(self) -> MessagingService:
69
+ """
70
+ Returns the MessagingService for this platform.
71
+
72
+ :returns: A MessagingService instance.
73
+ """
74
+
75
+ def get_all_services(self) -> list:
76
+ """
77
+ Returns a list of all PlatformService instances provided by
78
+ this adapter.
79
+
80
+ :returns: List of PlatformService instances.
81
+ """
82
+ rtnval = [
83
+ self.get_compute_service(),
84
+ self.get_storage_service(),
85
+ self.get_messaging_service()
86
+ ]
87
+ return rtnval
88
+
89
+ def health_check(self) -> dict:
90
+ """
91
+ Invokes health_check on each service and returns a dictionary
92
+ mapping service names to boolean health status values.
93
+
94
+ If a service health check raises an exception, the failure is
95
+ logged at WARNING level and the service is reported as unhealthy.
96
+
97
+ :returns: Dictionary of service name to health boolean.
98
+ """
99
+ result = {}
100
+ services = self.get_all_services()
101
+
102
+ for service in services:
103
+ try:
104
+ healthy = service.health_check()
105
+ result[service.service_name] = healthy
106
+ except Exception as ex:
107
+ logger.warning(
108
+ "Health check failed for service '%s' on platform '%s': %s",
109
+ service.service_name, self.platform_type.to_string(), str(ex)
110
+ )
111
+ result[service.service_name] = False
112
+
113
+ rtnval = result
114
+ return rtnval
115
+
116
+ def __repr__(self) -> str:
117
+ """
118
+ Returns a detailed string representation including class name
119
+ and platform type.
120
+
121
+ :returns: A repr string for debugging.
122
+ """
123
+ rtnval = "{}(platform_type={})".format(
124
+ self.__class__.__name__, self.platform_type.to_string()
125
+ )
126
+ return rtnval
127
+
128
+ def __str__(self) -> str:
129
+ """
130
+ Returns a human-readable summary including the platform type
131
+ and the list of available service names.
132
+
133
+ :returns: A human-readable string.
134
+ """
135
+ service_names = [s.service_name for s in self.get_all_services()]
136
+ rtnval = "{}: platform={}, services={}".format(
137
+ self.__class__.__name__, self.platform_type.to_string(), service_names
138
+ )
139
+ return rtnval
@@ -0,0 +1,15 @@
1
+ """
2
+ ccai.agentkit.platform.deployment - Deployment descriptor support.
3
+
4
+ Provides the DeploymentDescriptor immutable configuration object,
5
+ DeploymentDescriptorParser for reading descriptors from JSON/YAML/files,
6
+ and DeploymentDescriptorPrinter for writing descriptors to JSON/YAML/files.
7
+
8
+ .. module:: ccai.agentkit.platform.deployment
9
+ :platform: Darwin, Linux, Unix, Windows
10
+ :synopsis: Deployment descriptor, parser, and printer for platform deployments.
11
+ """
12
+
13
+ from ccai.agentkit.platform.deployment.deploymentdescriptor import DeploymentDescriptor
14
+ from ccai.agentkit.platform.deployment.deploymentdescriptorparser import DeploymentDescriptorParser
15
+ from ccai.agentkit.platform.deployment.deploymentdescriptorprinter import DeploymentDescriptorPrinter
@@ -0,0 +1,234 @@
1
+ """
2
+ Defines the DeploymentDescriptor class representing a declarative
3
+ configuration object that defines how an agent is deployed on a
4
+ specific platform. Contains compute, storage, messaging configuration,
5
+ environment variables, and scaling parameters.
6
+
7
+ Supports serialization to and from dictionary, JSON, and YAML
8
+ representations.
9
+
10
+ .. module:: ccai.agentkit.platform.deployment.deploymentdescriptor
11
+ :platform: Darwin, Linux, Unix, Windows
12
+ :synopsis: Immutable deployment descriptor for platform deployments.
13
+ """
14
+
15
+ import json
16
+
17
+ from typing import Any
18
+ from typing import Dict
19
+ from typing import Optional
20
+
21
+ import yaml
22
+
23
+ from ccai.agentkit.platform.platformtype import PlatformType
24
+
25
+
26
+ class DeploymentDescriptor:
27
+ """
28
+ Declarative configuration object defining how an agent is deployed
29
+ on a specific platform, including compute, storage, messaging
30
+ configuration, environment variables, and scaling parameters.
31
+
32
+ All fields are exposed as read-only properties.
33
+
34
+ :param name: The descriptor name string.
35
+ :param target_platform: The target PlatformType value.
36
+ :param compute_config: An optional compute configuration dictionary.
37
+ :param storage_config: An optional storage configuration dictionary.
38
+ :param messaging_config: An optional messaging configuration dictionary.
39
+ :param environment_variables: An optional environment variables dictionary.
40
+ :param scaling_parameters: An optional scaling parameters dictionary.
41
+ """
42
+
43
+ def __init__(self, name: str, target_platform: PlatformType,
44
+ compute_config: Optional[Dict[str, Any]] = None,
45
+ storage_config: Optional[Dict[str, Any]] = None,
46
+ messaging_config: Optional[Dict[str, Any]] = None,
47
+ environment_variables: Optional[Dict[str, str]] = None,
48
+ scaling_parameters: Optional[Dict[str, Any]] = None) -> None:
49
+ self._name = name
50
+ self._target_platform = target_platform
51
+ self._compute_config = dict(compute_config) if compute_config is not None else {}
52
+ self._storage_config = dict(storage_config) if storage_config is not None else {}
53
+ self._messaging_config = dict(messaging_config) if messaging_config is not None else {}
54
+ self._environment_variables = dict(environment_variables) if environment_variables is not None else {}
55
+ self._scaling_parameters = dict(scaling_parameters) if scaling_parameters is not None else {}
56
+ return
57
+
58
+ @property
59
+ def name(self) -> str:
60
+ """
61
+ The descriptor name string.
62
+
63
+ :returns: The name string.
64
+ """
65
+ rtnval = self._name
66
+ return rtnval
67
+
68
+ @property
69
+ def target_platform(self) -> PlatformType:
70
+ """
71
+ The target platform type.
72
+
73
+ :returns: The PlatformType value.
74
+ """
75
+ rtnval = self._target_platform
76
+ return rtnval
77
+
78
+ @property
79
+ def compute_config(self) -> dict:
80
+ """
81
+ A defensive copy of the compute configuration dictionary.
82
+
83
+ :returns: A dictionary of compute configuration.
84
+ """
85
+ rtnval = dict(self._compute_config)
86
+ return rtnval
87
+
88
+ @property
89
+ def storage_config(self) -> dict:
90
+ """
91
+ A defensive copy of the storage configuration dictionary.
92
+
93
+ :returns: A dictionary of storage configuration.
94
+ """
95
+ rtnval = dict(self._storage_config)
96
+ return rtnval
97
+
98
+ @property
99
+ def messaging_config(self) -> dict:
100
+ """
101
+ A defensive copy of the messaging configuration dictionary.
102
+
103
+ :returns: A dictionary of messaging configuration.
104
+ """
105
+ rtnval = dict(self._messaging_config)
106
+ return rtnval
107
+
108
+ @property
109
+ def environment_variables(self) -> dict:
110
+ """
111
+ A defensive copy of the environment variables dictionary.
112
+
113
+ :returns: A dictionary of environment variables.
114
+ """
115
+ rtnval = dict(self._environment_variables)
116
+ return rtnval
117
+
118
+ @property
119
+ def scaling_parameters(self) -> dict:
120
+ """
121
+ A defensive copy of the scaling parameters dictionary.
122
+
123
+ :returns: A dictionary of scaling parameters.
124
+ """
125
+ rtnval = dict(self._scaling_parameters)
126
+ return rtnval
127
+
128
+ def as_dict(self) -> dict:
129
+ """
130
+ Returns a dictionary representation of the descriptor fields.
131
+
132
+ :returns: A dictionary with all descriptor fields.
133
+ """
134
+ rtnval = {
135
+ "name": self._name,
136
+ "target_platform": self._target_platform.to_string(),
137
+ "compute_config": dict(self._compute_config),
138
+ "storage_config": dict(self._storage_config),
139
+ "messaging_config": dict(self._messaging_config),
140
+ "environment_variables": dict(self._environment_variables),
141
+ "scaling_parameters": dict(self._scaling_parameters)
142
+ }
143
+ return rtnval
144
+
145
+ def to_json(self) -> str:
146
+ """
147
+ Returns a JSON string representation of the descriptor fields.
148
+
149
+ :returns: A JSON string.
150
+ """
151
+ data = self.as_dict()
152
+ rtnval = json.dumps(data, indent=2)
153
+ return rtnval
154
+
155
+ def to_yaml(self) -> str:
156
+ """
157
+ Returns a YAML string representation of the descriptor fields.
158
+
159
+ :returns: A YAML string.
160
+ """
161
+ data = self.as_dict()
162
+ rtnval = yaml.dump(data, default_flow_style=False)
163
+ return rtnval
164
+
165
+ @classmethod
166
+ def from_dict(cls, data: dict) -> "DeploymentDescriptor":
167
+ """
168
+ Constructs a DeploymentDescriptor from a dictionary.
169
+
170
+ :param data: Dictionary containing descriptor fields.
171
+
172
+ :returns: A DeploymentDescriptor instance.
173
+ """
174
+ platform_type = PlatformType.from_string(data["target_platform"])
175
+ rtnval = cls(
176
+ name=data["name"],
177
+ target_platform=platform_type,
178
+ compute_config=data.get("compute_config", {}),
179
+ storage_config=data.get("storage_config", {}),
180
+ messaging_config=data.get("messaging_config", {}),
181
+ environment_variables=data.get("environment_variables", {}),
182
+ scaling_parameters=data.get("scaling_parameters", {})
183
+ )
184
+ return rtnval
185
+
186
+ @classmethod
187
+ def from_json(cls, json_str: str) -> "DeploymentDescriptor":
188
+ """
189
+ Deserializes a JSON string into a DeploymentDescriptor instance.
190
+
191
+ :param json_str: A JSON string containing descriptor fields.
192
+
193
+ :returns: A DeploymentDescriptor instance.
194
+ """
195
+ data = json.loads(json_str)
196
+ rtnval = cls.from_dict(data)
197
+ return rtnval
198
+
199
+ @classmethod
200
+ def from_yaml(cls, yaml_str: str) -> "DeploymentDescriptor":
201
+ """
202
+ Deserializes a YAML string into a DeploymentDescriptor instance.
203
+
204
+ :param yaml_str: A YAML string containing descriptor fields.
205
+
206
+ :returns: A DeploymentDescriptor instance.
207
+ """
208
+ data = yaml.safe_load(yaml_str)
209
+ rtnval = cls.from_dict(data)
210
+ return rtnval
211
+
212
+ def __repr__(self) -> str:
213
+ """
214
+ Returns a detailed string representation including class name,
215
+ descriptor name, and target platform type.
216
+
217
+ :returns: A repr string for debugging.
218
+ """
219
+ rtnval = "DeploymentDescriptor(name={}, target_platform={})".format(
220
+ self._name, self._target_platform.to_string()
221
+ )
222
+ return rtnval
223
+
224
+ def __str__(self) -> str:
225
+ """
226
+ Returns a human-readable summary including the descriptor name,
227
+ target platform type, and the scaling parameters.
228
+
229
+ :returns: A human-readable string.
230
+ """
231
+ rtnval = "DeploymentDescriptor: name={}, platform={}, scaling={}".format(
232
+ self._name, self._target_platform.to_string(), self._scaling_parameters
233
+ )
234
+ return rtnval
@@ -0,0 +1,178 @@
1
+ """
2
+ Defines the DeploymentDescriptorParser class for parsing
3
+ DeploymentDescriptor objects from JSON strings, YAML strings,
4
+ or files. Validates required fields and detects file format
5
+ from extension.
6
+
7
+ .. module:: ccai.agentkit.platform.deployment.deploymentdescriptorparser
8
+ :platform: Darwin, Linux, Unix, Windows
9
+ :synopsis: Parser for deployment descriptors from JSON/YAML/files.
10
+ """
11
+
12
+ import json
13
+ import logging
14
+ import os
15
+
16
+ import yaml
17
+
18
+ from ccai.agentkit.platform.deployment.deploymentdescriptor import DeploymentDescriptor
19
+ from ccai.agentkit.platform.errors import DeploymentDescriptorError
20
+
21
+
22
+ logger = logging.getLogger("ccai.agentkit.platform.deployment")
23
+
24
+
25
+ class DeploymentDescriptorParser:
26
+ """
27
+ Parses DeploymentDescriptor objects from JSON, YAML, or files.
28
+ Validates descriptors against required fields and resolves
29
+ platform-specific defaults.
30
+ """
31
+
32
+ SUPPORTED_EXTENSIONS = (".json", ".yaml", ".yml")
33
+ REQUIRED_FIELDS = ["name", "target_platform"]
34
+
35
+ def parse_json(self, json_str: str) -> DeploymentDescriptor:
36
+ """
37
+ Parses a JSON string into a DeploymentDescriptor.
38
+
39
+ :param json_str: A JSON string containing descriptor fields.
40
+
41
+ :returns: A DeploymentDescriptor instance.
42
+ :raises: DeploymentDescriptorError
43
+ """
44
+ try:
45
+ data = json.loads(json_str)
46
+ except (json.JSONDecodeError, TypeError) as exc:
47
+ err_msg_lines = [
48
+ "Failed to parse JSON deployment descriptor string."
49
+ ]
50
+ err_msg_lines.append(" Error: {}".format(str(exc)))
51
+ err_msg = os.linesep.join(err_msg_lines)
52
+ raise DeploymentDescriptorError(err_msg)
53
+
54
+ self._validate_schema(data)
55
+ rtnval = DeploymentDescriptor.from_dict(data)
56
+ logger.debug("Parsed deployment descriptor from JSON: name=%s, platform=%s",
57
+ rtnval.name, rtnval.target_platform.to_string())
58
+ return rtnval
59
+
60
+ def parse_yaml(self, yaml_str: str) -> DeploymentDescriptor:
61
+ """
62
+ Parses a YAML string into a DeploymentDescriptor.
63
+
64
+ :param yaml_str: A YAML string containing descriptor fields.
65
+
66
+ :returns: A DeploymentDescriptor instance.
67
+ :raises: DeploymentDescriptorError
68
+ """
69
+ try:
70
+ data = yaml.safe_load(yaml_str)
71
+ except yaml.YAMLError as exc:
72
+ err_msg_lines = [
73
+ "Failed to parse YAML deployment descriptor string."
74
+ ]
75
+ err_msg_lines.append(" Error: {}".format(str(exc)))
76
+ err_msg = os.linesep.join(err_msg_lines)
77
+ raise DeploymentDescriptorError(err_msg)
78
+
79
+ self._validate_schema(data)
80
+ rtnval = DeploymentDescriptor.from_dict(data)
81
+ logger.debug("Parsed deployment descriptor from YAML: name=%s, platform=%s",
82
+ rtnval.name, rtnval.target_platform.to_string())
83
+ return rtnval
84
+
85
+ def parse_file(self, file_path: str, app_context=None) -> DeploymentDescriptor:
86
+ """
87
+ Parses a deployment descriptor from a file, detecting format
88
+ from the file extension.
89
+
90
+ :param file_path: Path to the descriptor file.
91
+ :param app_context: Optional AppContext for path resolution.
92
+
93
+ :returns: A DeploymentDescriptor instance.
94
+ :raises: DeploymentDescriptorError
95
+ """
96
+ resolved_path = self._resolve_path(file_path, app_context)
97
+ ext = os.path.splitext(resolved_path)[1].lower()
98
+
99
+ if ext == ".json":
100
+ try:
101
+ with open(resolved_path, "r") as file_handle:
102
+ content = file_handle.read()
103
+ except (OSError, IOError) as exc:
104
+ err_msg_lines = [
105
+ "Failed to read deployment descriptor file."
106
+ ]
107
+ err_msg_lines.append(" File path: {!r}".format(resolved_path))
108
+ err_msg_lines.append(" Error: {}".format(str(exc)))
109
+ err_msg = os.linesep.join(err_msg_lines)
110
+ raise DeploymentDescriptorError(err_msg)
111
+ rtnval = self.parse_json(content)
112
+ return rtnval
113
+
114
+ if ext in (".yaml", ".yml"):
115
+ try:
116
+ with open(resolved_path, "r") as file_handle:
117
+ content = file_handle.read()
118
+ except (OSError, IOError) as exc:
119
+ err_msg_lines = [
120
+ "Failed to read deployment descriptor file."
121
+ ]
122
+ err_msg_lines.append(" File path: {!r}".format(resolved_path))
123
+ err_msg_lines.append(" Error: {}".format(str(exc)))
124
+ err_msg = os.linesep.join(err_msg_lines)
125
+ raise DeploymentDescriptorError(err_msg)
126
+ rtnval = self.parse_yaml(content)
127
+ return rtnval
128
+
129
+ err_msg_lines = [
130
+ "Unrecognized file extension '{}'.".format(ext),
131
+ "Supported extensions: {}".format(list(self.SUPPORTED_EXTENSIONS))
132
+ ]
133
+ err_msg = os.linesep.join(err_msg_lines)
134
+ raise DeploymentDescriptorError(err_msg)
135
+
136
+ def _validate_schema(self, data: dict) -> None:
137
+ """
138
+ Validates the descriptor data against the required schema.
139
+
140
+ :param data: Dictionary to validate.
141
+
142
+ :raises: DeploymentDescriptorError
143
+ """
144
+ for field in self.REQUIRED_FIELDS:
145
+ if field not in data:
146
+ err_msg = "Missing required field '{}' in deployment descriptor.".format(field)
147
+ raise DeploymentDescriptorError(err_msg)
148
+ return
149
+
150
+ def _resolve_path(self, file_path: str, app_context) -> str:
151
+ """
152
+ Resolves the file path relative to the AppContext directory.
153
+
154
+ :param file_path: The file path to resolve.
155
+ :param app_context: Optional AppContext.
156
+
157
+ :returns: The resolved absolute file path.
158
+ """
159
+ resolved_path = file_path
160
+
161
+ if app_context is not None:
162
+ try:
163
+ base_dir = app_context.directory
164
+ resolved_path = os.path.join(base_dir, file_path)
165
+ except Exception:
166
+ resolved_path = file_path
167
+
168
+ rtnval = resolved_path
169
+ return rtnval
170
+
171
+ def __repr__(self) -> str:
172
+ """
173
+ Returns a string representation including the class name.
174
+
175
+ :returns: A repr string for debugging.
176
+ """
177
+ rtnval = "DeploymentDescriptorParser()"
178
+ return rtnval
@@ -0,0 +1,97 @@
1
+ """
2
+ Defines the DeploymentDescriptorPrinter class for formatting
3
+ DeploymentDescriptor objects into JSON or YAML strings, or
4
+ writing them to files with format detection from file extension.
5
+
6
+ .. module:: ccai.agentkit.platform.deployment.deploymentdescriptorprinter
7
+ :platform: Darwin, Linux, Unix, Windows
8
+ :synopsis: Printer for deployment descriptors to JSON/YAML/files.
9
+ """
10
+
11
+ import logging
12
+ import os
13
+
14
+ from ccai.agentkit.platform.deployment.deploymentdescriptor import DeploymentDescriptor
15
+ from ccai.agentkit.platform.errors import DeploymentDescriptorError
16
+
17
+
18
+ logger = logging.getLogger("ccai.agentkit.platform.deployment")
19
+
20
+
21
+ class DeploymentDescriptorPrinter:
22
+ """
23
+ Formats DeploymentDescriptor objects into JSON or YAML strings
24
+ or writes them to files.
25
+ """
26
+
27
+ def print_json(self, descriptor: DeploymentDescriptor) -> str:
28
+ """
29
+ Returns a JSON string representation of the descriptor.
30
+
31
+ :param descriptor: The DeploymentDescriptor to format.
32
+
33
+ :returns: A JSON string.
34
+ """
35
+ rtnval = descriptor.to_json()
36
+ return rtnval
37
+
38
+ def print_yaml(self, descriptor: DeploymentDescriptor) -> str:
39
+ """
40
+ Returns a YAML string representation of the descriptor.
41
+
42
+ :param descriptor: The DeploymentDescriptor to format.
43
+
44
+ :returns: A YAML string.
45
+ """
46
+ rtnval = descriptor.to_yaml()
47
+ return rtnval
48
+
49
+ def print_file(self, descriptor: DeploymentDescriptor,
50
+ file_path: str) -> None:
51
+ """
52
+ Writes the descriptor to a file in the format determined
53
+ by the file extension.
54
+
55
+ :param descriptor: The DeploymentDescriptor to write.
56
+ :param file_path: Path to the output file.
57
+
58
+ :raises: DeploymentDescriptorError
59
+ """
60
+ ext = os.path.splitext(file_path)[1].lower()
61
+
62
+ if ext == ".json":
63
+ content = self.print_json(descriptor)
64
+ elif ext in (".yaml", ".yml"):
65
+ content = self.print_yaml(descriptor)
66
+ else:
67
+ err_msg_lines = [
68
+ "Unrecognized file extension '{}'.".format(ext),
69
+ "Supported extensions: .json, .yaml, .yml"
70
+ ]
71
+ err_msg = os.linesep.join(err_msg_lines)
72
+ raise DeploymentDescriptorError(err_msg)
73
+
74
+ try:
75
+ with open(file_path, "w") as file_handle:
76
+ file_handle.write(content)
77
+ except (OSError, IOError) as exc:
78
+ err_msg_lines = [
79
+ "Failed to write deployment descriptor file."
80
+ ]
81
+ err_msg_lines.append(" File path: {!r}".format(file_path))
82
+ err_msg_lines.append(" Error: {}".format(str(exc)))
83
+ err_msg = os.linesep.join(err_msg_lines)
84
+ raise DeploymentDescriptorError(err_msg)
85
+
86
+ logger.debug("Deployment descriptor written: name=%s, platform=%s",
87
+ descriptor.name, descriptor.target_platform.to_string())
88
+ return
89
+
90
+ def __repr__(self) -> str:
91
+ """
92
+ Returns a string representation including the class name.
93
+
94
+ :returns: A repr string for debugging.
95
+ """
96
+ rtnval = "DeploymentDescriptorPrinter()"
97
+ return rtnval