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,125 @@
1
+ """
2
+ Defines the PlatformDetector class that inspects the runtime environment
3
+ to determine which platform the agent is running on. Checks environment
4
+ variables and optional configuration hints to return a PlatformType value.
5
+
6
+ .. module:: ccai.agentkit.platform.platformdetector
7
+ :platform: Darwin, Linux, Unix, Windows
8
+ :synopsis: Environment-based platform detection returning PlatformType.
9
+ """
10
+
11
+ import logging
12
+ import os
13
+
14
+ from ccai.agentkit.platform.errors import PlatformDetectionError
15
+ from ccai.agentkit.platform.platformtype import PlatformType
16
+
17
+
18
+ logger = logging.getLogger("ccai.agentkit.platform.detector")
19
+
20
+
21
+ class PlatformDetector:
22
+ """
23
+ Inspects the runtime environment to determine which platform the agent
24
+ is running on. Checks environment variables and optional configuration
25
+ hints to return a PlatformType value.
26
+ """
27
+
28
+ AWS_ENV_VARS = ("AWS_LAMBDA_FUNCTION_NAME", "AWS_EXECUTION_ENV", "AWS_REGION")
29
+ AZURE_ENV_VARS = ("AZURE_FUNCTIONS_ENVIRONMENT", "WEBSITE_SITE_NAME", "AZURE_REGION")
30
+ GCP_ENV_VARS = ("GOOGLE_CLOUD_PROJECT", "FUNCTION_NAME", "GCP_REGION")
31
+
32
+ def __init__(self) -> None:
33
+ self._last_detected = None
34
+ return
35
+
36
+ def detect(self, configuration=None) -> PlatformType:
37
+ """
38
+ Inspects the runtime environment and returns the detected PlatformType.
39
+
40
+ When a configuration hint is provided with a non-None platform_type,
41
+ the hint overrides environment-based detection.
42
+
43
+ :param configuration: Optional PlatformConfiguration hint that
44
+ overrides environment detection.
45
+
46
+ :returns: The detected PlatformType value.
47
+ :raises: PlatformDetectionError
48
+ """
49
+ if configuration is not None and configuration.platform_type is not None:
50
+ detected = configuration.platform_type
51
+ logger.info("Platform detected from configuration hint: %s", detected.to_string())
52
+ self._last_detected = detected
53
+ rtnval = detected
54
+ return rtnval
55
+
56
+ detected_platforms = []
57
+ indicators = {}
58
+
59
+ aws_found = self._check_env_vars(self.AWS_ENV_VARS)
60
+ if len(aws_found) > 0:
61
+ detected_platforms.append(PlatformType.AWS)
62
+ indicators["aws"] = aws_found
63
+
64
+ azure_found = self._check_env_vars(self.AZURE_ENV_VARS)
65
+ if len(azure_found) > 0:
66
+ detected_platforms.append(PlatformType.AZURE)
67
+ indicators["azure"] = azure_found
68
+
69
+ gcp_found = self._check_env_vars(self.GCP_ENV_VARS)
70
+ if len(gcp_found) > 0:
71
+ detected_platforms.append(PlatformType.GCP)
72
+ indicators["gcp"] = gcp_found
73
+
74
+ if len(detected_platforms) > 1:
75
+ err_msg_lines = [
76
+ "Multiple cloud platforms detected simultaneously.",
77
+ "Conflicting indicators: {}".format(indicators)
78
+ ]
79
+ err_msg = os.linesep.join(err_msg_lines)
80
+ raise PlatformDetectionError(err_msg)
81
+
82
+ if len(detected_platforms) == 1:
83
+ detected = detected_platforms[0]
84
+ else:
85
+ detected = PlatformType.LOCAL
86
+
87
+ logger.info("Platform detected: %s, indicators: %s", detected.to_string(), indicators)
88
+ self._last_detected = detected
89
+ rtnval = detected
90
+ return rtnval
91
+
92
+ def _check_env_vars(self, var_names: tuple) -> list:
93
+ """
94
+ Checks which of the given environment variable names are present.
95
+
96
+ :param var_names: Tuple of environment variable names to check.
97
+
98
+ :returns: List of environment variable names that are set.
99
+ """
100
+ found = []
101
+ for var_name in var_names:
102
+ if os.environ.get(var_name) is not None:
103
+ found.append(var_name)
104
+ rtnval = found
105
+ return rtnval
106
+
107
+ def __repr__(self) -> str:
108
+ """
109
+ Returns a detailed string representation including the class name.
110
+
111
+ :returns: A repr string for debugging.
112
+ """
113
+ rtnval = "PlatformDetector()"
114
+ return rtnval
115
+
116
+ def __str__(self) -> str:
117
+ """
118
+ Returns a human-readable summary including the last detected
119
+ platform type.
120
+
121
+ :returns: A human-readable string.
122
+ """
123
+ last = self._last_detected.to_string() if self._last_detected is not None else "none"
124
+ rtnval = "PlatformDetector(last_detected={})".format(last)
125
+ return rtnval
@@ -0,0 +1,331 @@
1
+ """
2
+ Defines the PlatformRuntime class that manages the active platform
3
+ environment for an Agent, providing access to platform services through
4
+ a single entry point. Supports auto-configuration via platform detection
5
+ and extension point integration for plugin adapters.
6
+
7
+ .. module:: ccai.agentkit.platform.platformruntime
8
+ :platform: Darwin, Linux, Unix, Windows
9
+ :synopsis: Entry point for agents to access platform services with auto-configuration.
10
+ """
11
+
12
+ import logging
13
+ import os
14
+
15
+ from typing import Optional
16
+
17
+ from ccai.agentkit.platform.errors import PlatformError
18
+ from ccai.agentkit.platform.platformconfiguration import PlatformConfiguration
19
+ from ccai.agentkit.platform.platformdetector import PlatformDetector
20
+ from ccai.agentkit.platform.platformserviceregistry import PlatformServiceRegistry
21
+ from ccai.agentkit.platform.platformtype import PlatformType
22
+ from ccai.agentkit.platform.services.computeservice import ComputeService
23
+ from ccai.agentkit.platform.services.messagingservice import MessagingService
24
+ from ccai.agentkit.platform.services.platformservice import PlatformService
25
+ from ccai.agentkit.platform.services.storageservice import StorageService
26
+
27
+
28
+ logger = logging.getLogger("ccai.agentkit.platform.runtime")
29
+
30
+
31
+ class PlatformRuntime:
32
+ """
33
+ Manages the active platform environment for an Agent, providing
34
+ access to platform services through a single entry point.
35
+
36
+ The PlatformRuntime accepts a PlatformConfiguration and a
37
+ PlatformAdapter at construction, registers all adapter services
38
+ into a PlatformServiceRegistry, and exposes convenience methods
39
+ for accessing compute, storage, and messaging services.
40
+
41
+ The create_auto class method provides auto-configuration by
42
+ detecting the current platform, building a default configuration
43
+ from the environment when needed, and selecting the appropriate
44
+ adapter (checking extension points for plugin adapters first,
45
+ then falling back to built-in adapters).
46
+
47
+ :param configuration: The PlatformConfiguration for the runtime.
48
+ :param adapter: The PlatformAdapter providing platform services.
49
+ """
50
+
51
+ def __init__(self, configuration: PlatformConfiguration,
52
+ adapter: "PlatformAdapter") -> None:
53
+ self._configuration = configuration
54
+ self._adapter = adapter
55
+ self._registry = PlatformServiceRegistry()
56
+ self._initialize_services()
57
+ logger.info(
58
+ "PlatformRuntime initialized: platform=%s, region=%s, services=%s",
59
+ configuration.platform_type.to_string(),
60
+ configuration.region,
61
+ [s.service_name for s in self._registry.list_all()]
62
+ )
63
+ return
64
+
65
+ def _initialize_services(self) -> None:
66
+ """
67
+ Registers all services from the adapter into the service registry.
68
+ """
69
+ services = self._adapter.get_all_services()
70
+ for service in services:
71
+ self._registry.register(service)
72
+ return
73
+
74
+ @property
75
+ def platform_type(self) -> PlatformType:
76
+ """
77
+ Returns the PlatformType of the active platform.
78
+
79
+ :returns: The PlatformType value.
80
+ """
81
+ rtnval = self._configuration.platform_type
82
+ return rtnval
83
+
84
+ @property
85
+ def configuration(self) -> PlatformConfiguration:
86
+ """
87
+ Returns the PlatformConfiguration for this runtime.
88
+
89
+ :returns: The PlatformConfiguration instance.
90
+ """
91
+ rtnval = self._configuration
92
+ return rtnval
93
+
94
+ @property
95
+ def adapter(self) -> "PlatformAdapter":
96
+ """
97
+ Returns the PlatformAdapter for this runtime.
98
+
99
+ :returns: The PlatformAdapter instance.
100
+ """
101
+ rtnval = self._adapter
102
+ return rtnval
103
+
104
+ def get_compute_service(self) -> ComputeService:
105
+ """
106
+ Returns the ComputeService from the active adapter.
107
+
108
+ :returns: A ComputeService instance.
109
+ """
110
+ rtnval = self._adapter.get_compute_service()
111
+ return rtnval
112
+
113
+ def get_storage_service(self) -> StorageService:
114
+ """
115
+ Returns the StorageService from the active adapter.
116
+
117
+ :returns: A StorageService instance.
118
+ """
119
+ rtnval = self._adapter.get_storage_service()
120
+ return rtnval
121
+
122
+ def get_messaging_service(self) -> MessagingService:
123
+ """
124
+ Returns the MessagingService from the active adapter.
125
+
126
+ :returns: A MessagingService instance.
127
+ """
128
+ rtnval = self._adapter.get_messaging_service()
129
+ return rtnval
130
+
131
+ def get_service(self, service_name: str) -> Optional[PlatformService]:
132
+ """
133
+ Returns a PlatformService by name from the registry.
134
+
135
+ :param service_name: Name of the service to look up.
136
+
137
+ :returns: The PlatformService instance or None.
138
+ """
139
+ rtnval = self._registry.lookup_by_name(service_name)
140
+ return rtnval
141
+
142
+ def health_check(self) -> dict:
143
+ """
144
+ Delegates to the adapter health_check and logs the results
145
+ at INFO level.
146
+
147
+ :returns: Dictionary of service name to health boolean.
148
+ """
149
+ rtnval = self._adapter.health_check()
150
+ logger.info(
151
+ "PlatformRuntime health check: platform=%s, results=%s",
152
+ self.platform_type.to_string(), rtnval
153
+ )
154
+ return rtnval
155
+
156
+ @classmethod
157
+ def create_auto(cls, configuration: Optional[PlatformConfiguration] = None) -> "PlatformRuntime":
158
+ """
159
+ Auto-configures a PlatformRuntime by detecting the current platform
160
+ and creating the appropriate adapter.
161
+
162
+ When no configuration is provided, a default PlatformConfiguration
163
+ is built from the detected platform type. When a partial
164
+ configuration is provided (with platform_type as None), the
165
+ detected platform type is merged with the provided settings.
166
+
167
+ The method checks the codecraftai-extension ExtensionPoint for
168
+ plugin adapters before falling back to built-in adapters.
169
+
170
+ :param configuration: Optional PlatformConfiguration. If None or
171
+ partial, environment-derived defaults are used.
172
+
173
+ :returns: A configured PlatformRuntime instance.
174
+ :raises: PlatformError
175
+ """
176
+ try:
177
+ detector = PlatformDetector()
178
+ detected_type = detector.detect(configuration=configuration)
179
+
180
+ if configuration is None:
181
+ configuration = PlatformConfiguration(platform_type=detected_type)
182
+ elif configuration.platform_type is None:
183
+ configuration = PlatformConfiguration(
184
+ platform_type=detected_type,
185
+ region=configuration.region,
186
+ credential_references=configuration.credential_references,
187
+ service_endpoint_overrides=configuration.service_endpoint_overrides,
188
+ options=configuration.options
189
+ )
190
+
191
+ # Check extension point for plugin adapters
192
+ adapter = cls._load_adapter_from_extensions(detected_type, configuration)
193
+ if adapter is None:
194
+ adapter = cls._create_builtin_adapter(detected_type, configuration)
195
+
196
+ rtnval = cls(configuration=configuration, adapter=adapter)
197
+ return rtnval
198
+
199
+ except PlatformError:
200
+ raise
201
+ except Exception as ex:
202
+ err_msg_lines = [
203
+ "Auto-configuration failed for platform runtime.",
204
+ "Reason: {}".format(str(ex))
205
+ ]
206
+ err_msg = os.linesep.join(err_msg_lines)
207
+ raise PlatformError(err_msg, cause=ex)
208
+
209
+ @classmethod
210
+ def _load_adapter_from_extensions(cls, platform_type: PlatformType,
211
+ configuration: PlatformConfiguration) -> Optional["PlatformAdapter"]:
212
+ """
213
+ Discovers and loads PlatformAdapter implementations from the
214
+ "ccai.agentkit.platform.adapters" extension point.
215
+
216
+ Returns the first adapter whose platform_type matches the
217
+ target platform type. If no plugin adapter matches, returns None.
218
+
219
+ Plugin load failures are logged at WARNING level and remaining
220
+ plugins continue loading.
221
+
222
+ :param platform_type: The target PlatformType.
223
+ :param configuration: The PlatformConfiguration.
224
+
225
+ :returns: A PlatformAdapter instance or None.
226
+ """
227
+ try:
228
+ from ccai.extension import ExtensionPoint
229
+ extension_point = ExtensionPoint("ccai.agentkit.platform.adapters")
230
+ discovered_adapters = extension_point.query()
231
+
232
+ for adapter_entry in discovered_adapters:
233
+ try:
234
+ if hasattr(adapter_entry, "platform_type"):
235
+ adapter_platform = adapter_entry.platform_type
236
+ else:
237
+ adapter_instance = adapter_entry(configuration=configuration)
238
+ adapter_platform = adapter_instance.platform_type
239
+
240
+ if adapter_platform == platform_type:
241
+ rtnval = adapter_instance
242
+ return rtnval
243
+ continue
244
+
245
+ if adapter_platform == platform_type:
246
+ adapter_instance = adapter_entry(configuration=configuration)
247
+ rtnval = adapter_instance
248
+ return rtnval
249
+
250
+ except Exception as plugin_err:
251
+ logger.warning(
252
+ "Failed to load platform adapter plugin '%s': %s",
253
+ str(adapter_entry), str(plugin_err)
254
+ )
255
+
256
+ except ImportError:
257
+ logger.info(
258
+ "codecraftai-extension not available; skipping platform adapter "
259
+ "plugin discovery."
260
+ )
261
+ except Exception as discovery_err:
262
+ logger.warning(
263
+ "Platform adapter plugin discovery failed: %s",
264
+ str(discovery_err)
265
+ )
266
+
267
+ return None
268
+
269
+ @classmethod
270
+ def _create_builtin_adapter(cls, platform_type: PlatformType,
271
+ configuration: PlatformConfiguration) -> "PlatformAdapter":
272
+ """
273
+ Creates a built-in PlatformAdapter for the given platform type.
274
+
275
+ :param platform_type: The target PlatformType.
276
+ :param configuration: The PlatformConfiguration.
277
+
278
+ :returns: A PlatformAdapter instance.
279
+ :raises: PlatformError
280
+ """
281
+ from ccai.agentkit.platform.adapters.awsplatformadapter import AwsPlatformAdapter
282
+ from ccai.agentkit.platform.adapters.azureplatformadapter import AzurePlatformAdapter
283
+ from ccai.agentkit.platform.adapters.gcpplatformadapter import GcpPlatformAdapter
284
+ from ccai.agentkit.platform.adapters.localplatformadapter import LocalPlatformAdapter
285
+
286
+ adapter_map = {
287
+ PlatformType.AWS: AwsPlatformAdapter,
288
+ PlatformType.AZURE: AzurePlatformAdapter,
289
+ PlatformType.GCP: GcpPlatformAdapter,
290
+ PlatformType.LOCAL: LocalPlatformAdapter,
291
+ }
292
+
293
+ adapter_cls = adapter_map.get(platform_type)
294
+ if adapter_cls is None:
295
+ err_msg_lines = [
296
+ "No built-in adapter for platform type '{}'.".format(platform_type.to_string()),
297
+ "Supported platform types: {}".format(
298
+ [pt.to_string() for pt in adapter_map.keys()]
299
+ )
300
+ ]
301
+ err_msg = os.linesep.join(err_msg_lines)
302
+ raise PlatformError(err_msg, platform_type=platform_type)
303
+
304
+ rtnval = adapter_cls(configuration=configuration)
305
+ return rtnval
306
+
307
+ def __repr__(self) -> str:
308
+ """
309
+ Returns a detailed string representation including the class
310
+ name and platform type.
311
+
312
+ :returns: A repr string for debugging.
313
+ """
314
+ rtnval = "PlatformRuntime(platform_type={})".format(
315
+ self._configuration.platform_type.to_string()
316
+ )
317
+ return rtnval
318
+
319
+ def __str__(self) -> str:
320
+ """
321
+ Returns a human-readable summary including the platform type,
322
+ region, and the count of available services.
323
+
324
+ :returns: A human-readable string.
325
+ """
326
+ rtnval = "PlatformRuntime: platform={}, region={}, services={}".format(
327
+ self._configuration.platform_type.to_string(),
328
+ self._configuration.region,
329
+ self._registry.count
330
+ )
331
+ return rtnval
@@ -0,0 +1,149 @@
1
+ """
2
+ Defines the PlatformServiceRegistry that tracks all available
3
+ PlatformService instances within a PlatformRuntime, providing
4
+ lookup by service name and service type.
5
+
6
+ .. module:: ccai.agentkit.platform.platformserviceregistry
7
+ :platform: Darwin, Linux, Unix, Windows
8
+ :synopsis: Registry for platform service discovery by name and type.
9
+ """
10
+
11
+ import logging
12
+
13
+ from typing import List
14
+ from typing import Optional
15
+
16
+ from ccai.agentkit.errors import SemanticError
17
+ from ccai.agentkit.platform.services.platformservice import PlatformService
18
+
19
+
20
+ logger = logging.getLogger("ccai.agentkit.platform.registry")
21
+
22
+
23
+ class PlatformServiceRegistry:
24
+ """
25
+ Registry that tracks all available PlatformService instances within
26
+ a PlatformRuntime, providing lookup by service name and service type.
27
+
28
+ Each PlatformRuntime owns its own registry instance. The registry
29
+ is keyed by service name and supports lookup by name, lookup by
30
+ service type, enumeration, and count.
31
+ """
32
+
33
+ def __init__(self) -> None:
34
+ self._services: dict = {}
35
+ return
36
+
37
+ def register(self, service: PlatformService) -> None:
38
+ """
39
+ Registers a PlatformService instance using the service name as key.
40
+
41
+ :param service: The PlatformService to register.
42
+
43
+ :raises: SemanticError
44
+ """
45
+ name = service.service_name
46
+ if name in self._services:
47
+ err_msg = "Duplicate service name '{}' in PlatformServiceRegistry.".format(name)
48
+ raise SemanticError(err_msg)
49
+ self._services[name] = service
50
+ logger.debug(
51
+ "Registered service '%s' (type=%s, platform=%s) in PlatformServiceRegistry.",
52
+ name, service.service_type, service.platform_type.to_string()
53
+ )
54
+ return
55
+
56
+ def deregister(self, service_name: str) -> None:
57
+ """
58
+ Removes a PlatformService by name. If the name is not found,
59
+ the method does nothing.
60
+
61
+ :param service_name: Name of the service to remove.
62
+ """
63
+ if service_name in self._services:
64
+ del self._services[service_name]
65
+ logger.debug(
66
+ "Deregistered service '%s' from PlatformServiceRegistry.",
67
+ service_name
68
+ )
69
+ return
70
+
71
+ def lookup_by_name(self, service_name: str) -> Optional[PlatformService]:
72
+ """
73
+ Returns the PlatformService with the given name, or None if
74
+ no service with that name is registered.
75
+
76
+ :param service_name: Name of the service to look up.
77
+
78
+ :returns: The PlatformService instance or None.
79
+ """
80
+ rtnval = self._services.get(service_name)
81
+ return rtnval
82
+
83
+ def lookup_by_type(self, service_type: str) -> List[PlatformService]:
84
+ """
85
+ Returns a list of PlatformService instances matching the
86
+ provided service type string.
87
+
88
+ :param service_type: The service type string to filter by.
89
+
90
+ :returns: List of matching PlatformService instances.
91
+ """
92
+ rtnval = []
93
+ for service in self._services.values():
94
+ if service.service_type == service_type:
95
+ rtnval.append(service)
96
+ return rtnval
97
+
98
+ def list_all(self) -> List[PlatformService]:
99
+ """
100
+ Returns a list of all registered PlatformService instances.
101
+
102
+ :returns: List of PlatformService instances.
103
+ """
104
+ rtnval = list(self._services.values())
105
+ return rtnval
106
+
107
+ @property
108
+ def count(self) -> int:
109
+ """
110
+ Returns the count of currently registered services.
111
+
112
+ :returns: Integer count.
113
+ """
114
+ rtnval = len(self._services)
115
+ return rtnval
116
+
117
+ def has_service(self, service_name: str) -> bool:
118
+ """
119
+ Returns whether a service with the given name is registered.
120
+
121
+ :param service_name: Name of the service to check.
122
+
123
+ :returns: True if registered, False otherwise.
124
+ """
125
+ rtnval = service_name in self._services
126
+ return rtnval
127
+
128
+ def __repr__(self) -> str:
129
+ """
130
+ Returns a detailed string representation including the class
131
+ name and the count of registered services.
132
+
133
+ :returns: A repr string for debugging.
134
+ """
135
+ rtnval = "PlatformServiceRegistry(count={})".format(self.count)
136
+ return rtnval
137
+
138
+ def __str__(self) -> str:
139
+ """
140
+ Returns a human-readable summary listing the registered
141
+ service names and their service types.
142
+
143
+ :returns: A human-readable string.
144
+ """
145
+ entries = []
146
+ for name, service in self._services.items():
147
+ entries.append("{}({})".format(name, service.service_type))
148
+ rtnval = "PlatformServiceRegistry: [{}]".format(", ".join(entries))
149
+ return rtnval
@@ -0,0 +1,60 @@
1
+ """
2
+ Defines the PlatformType enumeration representing the supported
3
+ platform types for the cross-platform runtime feature.
4
+
5
+ .. module:: ccai.agentkit.platform.platformtype
6
+ :platform: Darwin, Linux, Unix, Windows
7
+ :synopsis: Enumeration of supported platform types (AWS, Azure, GCP, Local).
8
+ """
9
+
10
+ import enum
11
+ import os
12
+
13
+ from ccai.agentkit.errors import SemanticError
14
+
15
+
16
+ class PlatformType(enum.Enum):
17
+ """
18
+ Enumeration of supported platform types.
19
+
20
+ Defines the cloud providers and local environment that the
21
+ cross-platform runtime can target.
22
+ """
23
+
24
+ AWS = "aws"
25
+ AZURE = "azure"
26
+ GCP = "gcp"
27
+ LOCAL = "local"
28
+
29
+ @classmethod
30
+ def from_string(cls, value: str) -> "PlatformType":
31
+ """
32
+ Returns the PlatformType member matching the given case-insensitive string.
33
+
34
+ :param value: A string representing the platform type.
35
+
36
+ :returns: The matching PlatformType member.
37
+ :raises: SemanticError
38
+ """
39
+ normalized = value.strip().lower()
40
+ for member in cls:
41
+ if member.value == normalized:
42
+ rtnval = member
43
+ return rtnval
44
+
45
+ valid_values = [m.value for m in cls]
46
+ err_msg_lines = [
47
+ "Invalid platform type value '{}'.".format(value),
48
+ "Valid platform types: {}".format(valid_values)
49
+ ]
50
+ err_msg = os.linesep.join(err_msg_lines)
51
+ raise SemanticError(err_msg)
52
+
53
+ def to_string(self) -> str:
54
+ """
55
+ Returns the lowercase string representation of the platform type.
56
+
57
+ :returns: The lowercase string value.
58
+ """
59
+ rtnval = self.value
60
+ return rtnval
@@ -0,0 +1,19 @@
1
+ """
2
+ ccai.agentkit.platform.services - Platform service abstractions and DTOs.
3
+
4
+ Provides abstract base classes for platform services (compute, storage,
5
+ messaging) and immutable data transfer objects (StorageObject,
6
+ QueueMessage, InvocationResult) used across all platform adapters.
7
+
8
+ .. module:: ccai.agentkit.platform.services
9
+ :platform: Darwin, Linux, Unix, Windows
10
+ :synopsis: Platform service abstractions and data transfer objects.
11
+ """
12
+
13
+ from ccai.agentkit.platform.services.computeservice import ComputeService
14
+ from ccai.agentkit.platform.services.invocationresult import InvocationResult
15
+ from ccai.agentkit.platform.services.messagingservice import MessagingService
16
+ from ccai.agentkit.platform.services.platformservice import PlatformService
17
+ from ccai.agentkit.platform.services.queuemessage import QueueMessage
18
+ from ccai.agentkit.platform.services.storageobject import StorageObject
19
+ from ccai.agentkit.platform.services.storageservice import StorageService