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.
- ccai/agentkit/__init__.py +304 -0
- ccai/agentkit/addressresolver.py +177 -0
- ccai/agentkit/agent.py +2945 -0
- ccai/agentkit/agentaddress.py +187 -0
- ccai/agentkit/agentconfiguration.py +581 -0
- ccai/agentkit/agentidentity.py +152 -0
- ccai/agentkit/agentregistry.py +221 -0
- ccai/agentkit/agentstatemachine.py +134 -0
- ccai/agentkit/alternateproviderstrategy.py +36 -0
- ccai/agentkit/approvalgate.py +238 -0
- ccai/agentkit/approvalrequest.py +250 -0
- ccai/agentkit/asyncagent.py +187 -0
- ccai/agentkit/breakpoint.py +150 -0
- ccai/agentkit/builtinagentmetrics.py +114 -0
- ccai/agentkit/builtins/__init__.py +11 -0
- ccai/agentkit/builtins/filereadtool.py +90 -0
- ccai/agentkit/builtins/filewritetool.py +93 -0
- ccai/agentkit/builtins/httprequesttool.py +169 -0
- ccai/agentkit/builtins/shellcommandtool.py +190 -0
- ccai/agentkit/cachedresultstrategy.py +43 -0
- ccai/agentkit/checkpointmanager.py +219 -0
- ccai/agentkit/circuitbreaker.py +230 -0
- ccai/agentkit/circuitbreakerconfiguration.py +158 -0
- ccai/agentkit/circuitbreakerevent.py +158 -0
- ccai/agentkit/circuitbreakerhealthcheck.py +32 -0
- ccai/agentkit/circuitbreakerregistry.py +116 -0
- ccai/agentkit/circuitbreakerstate.py +44 -0
- ccai/agentkit/clearcacheaction.py +46 -0
- ccai/agentkit/concurrencybridge.py +143 -0
- ccai/agentkit/concurrencymodel.py +19 -0
- ccai/agentkit/conditionevaluator.py +594 -0
- ccai/agentkit/configurationchangeevent.py +179 -0
- ccai/agentkit/configurationerrors.py +152 -0
- ccai/agentkit/configurationlayer.py +160 -0
- ccai/agentkit/configurationlayersource.py +46 -0
- ccai/agentkit/configurationmanager.py +680 -0
- ccai/agentkit/configurationschema.py +224 -0
- ccai/agentkit/configurationschemafield.py +217 -0
- ccai/agentkit/configurationserializer.py +163 -0
- ccai/agentkit/configurationvalidationresult.py +118 -0
- ccai/agentkit/contextsummarizer.py +170 -0
- ccai/agentkit/contextwindow.py +264 -0
- ccai/agentkit/contextwindowstrategy.py +57 -0
- ccai/agentkit/correlationcontext.py +156 -0
- ccai/agentkit/costestimate.py +139 -0
- ccai/agentkit/costtracker.py +121 -0
- ccai/agentkit/deadletterentry.py +134 -0
- ccai/agentkit/deadletterquery.py +119 -0
- ccai/agentkit/deadletterqueue.py +123 -0
- ccai/agentkit/deadletterstore.py +86 -0
- ccai/agentkit/debuginspector.py +211 -0
- ccai/agentkit/debugsession.py +223 -0
- ccai/agentkit/defaultvaluestrategy.py +43 -0
- ccai/agentkit/degradationchangeevent.py +120 -0
- ccai/agentkit/degradationlevel.py +44 -0
- ccai/agentkit/degradationmanager.py +212 -0
- ccai/agentkit/degradationpolicy.py +130 -0
- ccai/agentkit/degradationstrategy.py +66 -0
- ccai/agentkit/embeddingprovider.py +106 -0
- ccai/agentkit/errors.py +95 -0
- ccai/agentkit/executionrecord.py +213 -0
- ccai/agentkit/executionrecorder.py +180 -0
- ccai/agentkit/executionrecording.py +230 -0
- ccai/agentkit/executionreplayer.py +187 -0
- ccai/agentkit/expirationpolicy.py +116 -0
- ccai/agentkit/fallbackchain.py +82 -0
- ccai/agentkit/featureflag.py +154 -0
- ccai/agentkit/featureflagevaluator.py +109 -0
- ccai/agentkit/featureflagregistry.py +258 -0
- ccai/agentkit/filedeadletterstore.py +112 -0
- ccai/agentkit/filememorystore.py +291 -0
- ccai/agentkit/healthcheck.py +46 -0
- ccai/agentkit/healthcheckregistry.py +51 -0
- ccai/agentkit/healthmonitor.py +258 -0
- ccai/agentkit/healthstatus.py +105 -0
- ccai/agentkit/hotreloadmonitor.py +214 -0
- ccai/agentkit/hotreloadpolicy.py +160 -0
- ccai/agentkit/inmemorydeadletterstore.py +61 -0
- ccai/agentkit/inmemorystore.py +173 -0
- ccai/agentkit/jsonmessageserializer.py +89 -0
- ccai/agentkit/jsonoutputparser.py +50 -0
- ccai/agentkit/lifecyclestate.py +22 -0
- ccai/agentkit/llmconversation.py +153 -0
- ccai/agentkit/llmerrors.py +193 -0
- ccai/agentkit/llmmessage.py +158 -0
- ccai/agentkit/llmprovider.py +158 -0
- ccai/agentkit/llmproviderregistry.py +200 -0
- ccai/agentkit/llmresponse.py +190 -0
- ccai/agentkit/llmstreamchunk.py +65 -0
- ccai/agentkit/llmstreamhandler.py +48 -0
- ccai/agentkit/llmtoolbridge.py +154 -0
- ccai/agentkit/logexporter.py +316 -0
- ccai/agentkit/logformatter.py +169 -0
- ccai/agentkit/memoryconfiguration.py +243 -0
- ccai/agentkit/memoryentry.py +254 -0
- ccai/agentkit/memoryerrors.py +135 -0
- ccai/agentkit/memoryindex.py +213 -0
- ccai/agentkit/memoryquery.py +248 -0
- ccai/agentkit/memoryqueryresult.py +86 -0
- ccai/agentkit/memoryscope.py +54 -0
- ccai/agentkit/memorystore.py +260 -0
- ccai/agentkit/memorystorehealthcheck.py +33 -0
- ccai/agentkit/memorystoreregistry.py +106 -0
- ccai/agentkit/message.py +310 -0
- ccai/agentkit/messageenvelope.py +144 -0
- ccai/agentkit/messagepattern.py +50 -0
- ccai/agentkit/messagerouter.py +290 -0
- ccai/agentkit/messageserializer.py +106 -0
- ccai/agentkit/messageserializerregistry.py +163 -0
- ccai/agentkit/messagingconfiguration.py +397 -0
- ccai/agentkit/messagingerrors.py +338 -0
- ccai/agentkit/metricdefinition.py +164 -0
- ccai/agentkit/metricmeasurement.py +178 -0
- ccai/agentkit/metricscollector.py +258 -0
- ccai/agentkit/metricsexporter.py +303 -0
- ccai/agentkit/metricsregistry.py +130 -0
- ccai/agentkit/metricssnapshot.py +155 -0
- ccai/agentkit/metrictype.py +51 -0
- ccai/agentkit/msgpackmessageserializer.py +97 -0
- ccai/agentkit/observabilityconfiguration.py +546 -0
- ccai/agentkit/observabilityerror.py +67 -0
- ccai/agentkit/observabilitypipeline.py +252 -0
- ccai/agentkit/outputparser.py +82 -0
- ccai/agentkit/outputschema.py +142 -0
- ccai/agentkit/parallelbranch.py +87 -0
- ccai/agentkit/platform/__init__.py +43 -0
- ccai/agentkit/platform/adapters/__init__.py +18 -0
- ccai/agentkit/platform/adapters/awsplatformadapter.py +1272 -0
- ccai/agentkit/platform/adapters/azureplatformadapter.py +1227 -0
- ccai/agentkit/platform/adapters/gcpplatformadapter.py +1257 -0
- ccai/agentkit/platform/adapters/localplatformadapter.py +956 -0
- ccai/agentkit/platform/adapters/platformadapter.py +139 -0
- ccai/agentkit/platform/deployment/__init__.py +15 -0
- ccai/agentkit/platform/deployment/deploymentdescriptor.py +234 -0
- ccai/agentkit/platform/deployment/deploymentdescriptorparser.py +178 -0
- ccai/agentkit/platform/deployment/deploymentdescriptorprinter.py +97 -0
- ccai/agentkit/platform/errors.py +224 -0
- ccai/agentkit/platform/platformconfiguration.py +412 -0
- ccai/agentkit/platform/platformdetector.py +125 -0
- ccai/agentkit/platform/platformruntime.py +331 -0
- ccai/agentkit/platform/platformserviceregistry.py +149 -0
- ccai/agentkit/platform/platformtype.py +60 -0
- ccai/agentkit/platform/services/__init__.py +19 -0
- ccai/agentkit/platform/services/computeservice.py +112 -0
- ccai/agentkit/platform/services/invocationresult.py +173 -0
- ccai/agentkit/platform/services/messagingservice.py +135 -0
- ccai/agentkit/platform/services/platformservice.py +111 -0
- ccai/agentkit/platform/services/queuemessage.py +193 -0
- ccai/agentkit/platform/services/storageobject.py +195 -0
- ccai/agentkit/platform/services/storageservice.py +159 -0
- ccai/agentkit/pluginconfiguration.py +241 -0
- ccai/agentkit/plugindependency.py +129 -0
- ccai/agentkit/plugindescriptor.py +225 -0
- ccai/agentkit/pluginlifecyclehook.py +41 -0
- ccai/agentkit/pluginmanager.py +360 -0
- ccai/agentkit/pluginstatus.py +47 -0
- ccai/agentkit/pooledagent.py +116 -0
- ccai/agentkit/prompttemplate.py +221 -0
- ccai/agentkit/prompttemplateregistry.py +145 -0
- ccai/agentkit/protobufmessageserializer.py +144 -0
- ccai/agentkit/pubsubbroker.py +311 -0
- ccai/agentkit/py.typed +0 -0
- ccai/agentkit/reconnecttransportaction.py +47 -0
- ccai/agentkit/regexoutputparser.py +68 -0
- ccai/agentkit/requestresponsehandler.py +274 -0
- ccai/agentkit/resetcircuitbreakeraction.py +48 -0
- ccai/agentkit/resilienceconfiguration.py +191 -0
- ccai/agentkit/resilienceerrors.py +103 -0
- ccai/agentkit/resiliencepipeline.py +201 -0
- ccai/agentkit/retryattempt.py +158 -0
- ccai/agentkit/retryexecutor.py +157 -0
- ccai/agentkit/retrypolicy.py +195 -0
- ccai/agentkit/retryresult.py +186 -0
- ccai/agentkit/selfhealingaction.py +42 -0
- ccai/agentkit/selfhealingpolicy.py +67 -0
- ccai/agentkit/selfhealingresult.py +130 -0
- ccai/agentkit/stepexecutionstatus.py +52 -0
- ccai/agentkit/stepresult.py +198 -0
- ccai/agentkit/steps/__init__.py +9 -0
- ccai/agentkit/steps/agentstep.py +247 -0
- ccai/agentkit/steps/approvalstep.py +276 -0
- ccai/agentkit/steps/llmstep.py +403 -0
- ccai/agentkit/steps/subworkflowstep.py +270 -0
- ccai/agentkit/steps/toolstep.py +265 -0
- ccai/agentkit/structuredlogentry.py +222 -0
- ccai/agentkit/structuredlogger.py +189 -0
- ccai/agentkit/subscription.py +141 -0
- ccai/agentkit/threadedagent.py +94 -0
- ccai/agentkit/tokenusage.py +136 -0
- ccai/agentkit/tool.py +203 -0
- ccai/agentkit/toolchain.py +268 -0
- ccai/agentkit/toolchainexecutor.py +134 -0
- ccai/agentkit/toolchainresult.py +166 -0
- ccai/agentkit/tooldescriptor.py +203 -0
- ccai/agentkit/toolerrors.py +160 -0
- ccai/agentkit/toolexecutor.py +168 -0
- ccai/agentkit/toolfactory.py +60 -0
- ccai/agentkit/toolregistry.py +184 -0
- ccai/agentkit/toolresult.py +142 -0
- ccai/agentkit/toolschema.py +197 -0
- ccai/agentkit/tracecontext.py +294 -0
- ccai/agentkit/traceevent.py +166 -0
- ccai/agentkit/traceexporter.py +305 -0
- ccai/agentkit/tracer.py +234 -0
- ccai/agentkit/tracespan.py +349 -0
- ccai/agentkit/transitionrecord.py +84 -0
- ccai/agentkit/transport.py +334 -0
- ccai/agentkit/transportconfiguration.py +436 -0
- ccai/agentkit/transporthealthcheck.py +36 -0
- ccai/agentkit/transportregistry.py +224 -0
- ccai/agentkit/transports/__init__.py +28 -0
- ccai/agentkit/transports/grpctransport.py +410 -0
- ccai/agentkit/transports/httptransport.py +423 -0
- ccai/agentkit/transports/messagequeuetransport.py +489 -0
- ccai/agentkit/transports/websockettransport.py +473 -0
- ccai/agentkit/workflowcheckpoint.py +208 -0
- ccai/agentkit/workflowconfiguration.py +295 -0
- ccai/agentkit/workflowcontext.py +249 -0
- ccai/agentkit/workflowdefinition.py +790 -0
- ccai/agentkit/workflowedge.py +128 -0
- ccai/agentkit/workflowerrors.py +295 -0
- ccai/agentkit/workflowexecutionstatus.py +48 -0
- ccai/agentkit/workflowexecutor.py +1121 -0
- ccai/agentkit/workflowregistry.py +185 -0
- ccai/agentkit/workflowresult.py +250 -0
- ccai/agentkit/workflowstep.py +195 -0
- codecraftai_agent_kit-1.3.0.dist-info/METADATA +99 -0
- codecraftai_agent_kit-1.3.0.dist-info/RECORD +230 -0
- codecraftai_agent_kit-1.3.0.dist-info/WHEEL +4 -0
- codecraftai_agent_kit-1.3.0.dist-info/licenses/LICENSE.md +204 -0
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the TransportConfiguration class for declarative transport
|
|
3
|
+
protocol settings in the Communication & Messaging feature.
|
|
4
|
+
|
|
5
|
+
A TransportConfiguration contains the protocol type, host, port,
|
|
6
|
+
optional path, headers, timeout, protocol-specific options, and
|
|
7
|
+
credential references. The class provides JSON and YAML
|
|
8
|
+
serialization and deserialization, including file-based loading
|
|
9
|
+
with optional AppContext path resolution.
|
|
10
|
+
|
|
11
|
+
Credential reference values are excluded from serialized output
|
|
12
|
+
(as_dict, to_json, to_yaml) to prevent leaking secrets.
|
|
13
|
+
|
|
14
|
+
Requirements: 2.1-2.19, 26.21, 26.22
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
import os
|
|
19
|
+
|
|
20
|
+
from typing import Optional
|
|
21
|
+
|
|
22
|
+
import yaml
|
|
23
|
+
|
|
24
|
+
from ccai.agentkit.errors import ConfigurationError
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class TransportConfiguration:
|
|
28
|
+
"""
|
|
29
|
+
Configuration object defining transport protocol type, connection
|
|
30
|
+
parameters, authentication settings, and protocol-specific options.
|
|
31
|
+
|
|
32
|
+
Validation is performed at construction time:
|
|
33
|
+
- protocol_type must be one of the VALID_PROTOCOL_TYPES
|
|
34
|
+
- host must be provided and non-empty
|
|
35
|
+
- port must be provided
|
|
36
|
+
|
|
37
|
+
:param protocol_type: The transport protocol type string. Must be
|
|
38
|
+
one of "http", "websocket", "grpc", or "message_queue".
|
|
39
|
+
:param host: The host address string.
|
|
40
|
+
:param port: The port number integer.
|
|
41
|
+
:param path: An optional URL path string. Defaults to None.
|
|
42
|
+
:param headers: An optional dictionary of default headers.
|
|
43
|
+
Defaults to an empty dictionary.
|
|
44
|
+
:param timeout: The connection/request timeout in seconds as a
|
|
45
|
+
float. Defaults to 30.0.
|
|
46
|
+
:param options: An optional dictionary of protocol-specific
|
|
47
|
+
options. Defaults to an empty dictionary.
|
|
48
|
+
:param credential_references: An optional dictionary of named
|
|
49
|
+
credential references for authentication. Defaults to an
|
|
50
|
+
empty dictionary.
|
|
51
|
+
|
|
52
|
+
:raises ConfigurationError: If protocol_type is not valid, or
|
|
53
|
+
if required fields are missing.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
VALID_PROTOCOL_TYPES = {"http", "websocket", "grpc", "message_queue"}
|
|
57
|
+
REQUIRED_FIELDS = ["protocol_type", "host", "port"]
|
|
58
|
+
|
|
59
|
+
def __init__(self, protocol_type: str, host: str, port: int,
|
|
60
|
+
path: str = None, headers: dict = None,
|
|
61
|
+
timeout: float = 30.0, options: dict = None,
|
|
62
|
+
credential_references: dict = None) -> None:
|
|
63
|
+
|
|
64
|
+
self._validate_required_fields(
|
|
65
|
+
protocol_type=protocol_type, host=host, port=port
|
|
66
|
+
)
|
|
67
|
+
self._validate_protocol_type(protocol_type=protocol_type)
|
|
68
|
+
|
|
69
|
+
self._protocol_type = protocol_type
|
|
70
|
+
self._host = host
|
|
71
|
+
self._port = port
|
|
72
|
+
self._path = path
|
|
73
|
+
self._headers = dict(headers) if headers is not None else {}
|
|
74
|
+
self._timeout = timeout
|
|
75
|
+
self._options = dict(options) if options is not None else {}
|
|
76
|
+
self._credential_references = dict(credential_references) if credential_references is not None else {}
|
|
77
|
+
|
|
78
|
+
return
|
|
79
|
+
|
|
80
|
+
def _validate_required_fields(self, protocol_type: str, host: str,
|
|
81
|
+
port: int) -> None:
|
|
82
|
+
"""
|
|
83
|
+
Validates that all required fields are present and non-empty.
|
|
84
|
+
|
|
85
|
+
:param protocol_type: The protocol type value to validate.
|
|
86
|
+
:param host: The host value to validate.
|
|
87
|
+
:param port: The port value to validate.
|
|
88
|
+
|
|
89
|
+
:raises ConfigurationError: If any required field is missing
|
|
90
|
+
or empty.
|
|
91
|
+
"""
|
|
92
|
+
missing_fields = []
|
|
93
|
+
|
|
94
|
+
if protocol_type is None or (isinstance(protocol_type, str) and len(protocol_type.strip()) == 0):
|
|
95
|
+
missing_fields.append("protocol_type")
|
|
96
|
+
|
|
97
|
+
if host is None or (isinstance(host, str) and len(host.strip()) == 0):
|
|
98
|
+
missing_fields.append("host")
|
|
99
|
+
|
|
100
|
+
if port is None:
|
|
101
|
+
missing_fields.append("port")
|
|
102
|
+
|
|
103
|
+
if len(missing_fields) > 0:
|
|
104
|
+
errmsg = "TransportConfiguration is missing required field(s): {}.".format(
|
|
105
|
+
", ".join(missing_fields)
|
|
106
|
+
)
|
|
107
|
+
raise ConfigurationError(errmsg)
|
|
108
|
+
|
|
109
|
+
return
|
|
110
|
+
|
|
111
|
+
def _validate_protocol_type(self, protocol_type: str) -> None:
|
|
112
|
+
"""
|
|
113
|
+
Validates that the protocol type is one of the valid values.
|
|
114
|
+
|
|
115
|
+
:param protocol_type: The protocol type string to validate.
|
|
116
|
+
|
|
117
|
+
:raises ConfigurationError: If the protocol type is not valid.
|
|
118
|
+
"""
|
|
119
|
+
if protocol_type not in self.VALID_PROTOCOL_TYPES:
|
|
120
|
+
valid_types_str = ", ".join(sorted(self.VALID_PROTOCOL_TYPES))
|
|
121
|
+
errmsg = (
|
|
122
|
+
"Invalid protocol type '{}'. "
|
|
123
|
+
"Valid protocol types are: {}."
|
|
124
|
+
).format(protocol_type, valid_types_str)
|
|
125
|
+
raise ConfigurationError(errmsg)
|
|
126
|
+
|
|
127
|
+
return
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def protocol_type(self) -> str:
|
|
131
|
+
"""
|
|
132
|
+
The transport protocol type string.
|
|
133
|
+
|
|
134
|
+
:returns: One of "http", "websocket", "grpc", or
|
|
135
|
+
"message_queue".
|
|
136
|
+
"""
|
|
137
|
+
return self._protocol_type
|
|
138
|
+
|
|
139
|
+
@property
|
|
140
|
+
def host(self) -> str:
|
|
141
|
+
"""
|
|
142
|
+
The host address string.
|
|
143
|
+
|
|
144
|
+
:returns: The host address.
|
|
145
|
+
"""
|
|
146
|
+
return self._host
|
|
147
|
+
|
|
148
|
+
@property
|
|
149
|
+
def port(self) -> int:
|
|
150
|
+
"""
|
|
151
|
+
The port number integer.
|
|
152
|
+
|
|
153
|
+
:returns: The port number.
|
|
154
|
+
"""
|
|
155
|
+
return self._port
|
|
156
|
+
|
|
157
|
+
@property
|
|
158
|
+
def path(self) -> Optional[str]:
|
|
159
|
+
"""
|
|
160
|
+
The optional URL path string.
|
|
161
|
+
|
|
162
|
+
:returns: The path string or None.
|
|
163
|
+
"""
|
|
164
|
+
return self._path
|
|
165
|
+
|
|
166
|
+
@property
|
|
167
|
+
def headers(self) -> dict:
|
|
168
|
+
"""
|
|
169
|
+
The default headers dictionary.
|
|
170
|
+
|
|
171
|
+
:returns: A dictionary of header key-value pairs.
|
|
172
|
+
"""
|
|
173
|
+
return dict(self._headers)
|
|
174
|
+
|
|
175
|
+
@property
|
|
176
|
+
def timeout(self) -> float:
|
|
177
|
+
"""
|
|
178
|
+
The connection/request timeout in seconds.
|
|
179
|
+
|
|
180
|
+
:returns: A float representing the timeout in seconds.
|
|
181
|
+
"""
|
|
182
|
+
return self._timeout
|
|
183
|
+
|
|
184
|
+
@property
|
|
185
|
+
def options(self) -> dict:
|
|
186
|
+
"""
|
|
187
|
+
The protocol-specific options dictionary.
|
|
188
|
+
|
|
189
|
+
:returns: A dictionary of option key-value pairs.
|
|
190
|
+
"""
|
|
191
|
+
return dict(self._options)
|
|
192
|
+
|
|
193
|
+
@property
|
|
194
|
+
def credential_references(self) -> dict:
|
|
195
|
+
"""
|
|
196
|
+
The named credential references dictionary.
|
|
197
|
+
|
|
198
|
+
:returns: A dictionary of credential reference names
|
|
199
|
+
to their reference data.
|
|
200
|
+
"""
|
|
201
|
+
return dict(self._credential_references)
|
|
202
|
+
|
|
203
|
+
def as_dict(self) -> dict:
|
|
204
|
+
"""
|
|
205
|
+
Returns a dictionary representation of the configuration.
|
|
206
|
+
|
|
207
|
+
Credential reference values are excluded from the output
|
|
208
|
+
to prevent leaking secrets. Only the credential reference
|
|
209
|
+
names are included.
|
|
210
|
+
|
|
211
|
+
:returns: A dictionary containing all configuration fields
|
|
212
|
+
except resolved credential values.
|
|
213
|
+
"""
|
|
214
|
+
rtnval = {
|
|
215
|
+
"protocol_type": self._protocol_type,
|
|
216
|
+
"host": self._host,
|
|
217
|
+
"port": self._port,
|
|
218
|
+
"timeout": self._timeout,
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if self._path is not None:
|
|
222
|
+
rtnval["path"] = self._path
|
|
223
|
+
|
|
224
|
+
if len(self._headers) > 0:
|
|
225
|
+
rtnval["headers"] = dict(self._headers)
|
|
226
|
+
|
|
227
|
+
if len(self._options) > 0:
|
|
228
|
+
rtnval["options"] = dict(self._options)
|
|
229
|
+
|
|
230
|
+
if len(self._credential_references) > 0:
|
|
231
|
+
rtnval["credential_references"] = sorted(self._credential_references.keys())
|
|
232
|
+
|
|
233
|
+
return rtnval
|
|
234
|
+
|
|
235
|
+
def to_json(self) -> str:
|
|
236
|
+
"""
|
|
237
|
+
Returns a JSON string representation of the configuration.
|
|
238
|
+
|
|
239
|
+
Credential reference values are excluded from the output
|
|
240
|
+
to prevent leaking secrets.
|
|
241
|
+
|
|
242
|
+
:returns: A JSON string containing all configuration fields
|
|
243
|
+
except resolved credential values.
|
|
244
|
+
"""
|
|
245
|
+
data = self.as_dict()
|
|
246
|
+
rtnval = json.dumps(data)
|
|
247
|
+
return rtnval
|
|
248
|
+
|
|
249
|
+
def to_yaml(self) -> str:
|
|
250
|
+
"""
|
|
251
|
+
Returns a YAML string representation of the configuration.
|
|
252
|
+
|
|
253
|
+
Credential reference values are excluded from the output
|
|
254
|
+
to prevent leaking secrets.
|
|
255
|
+
|
|
256
|
+
:returns: A YAML string containing all configuration fields
|
|
257
|
+
except resolved credential values.
|
|
258
|
+
"""
|
|
259
|
+
data = self.as_dict()
|
|
260
|
+
rtnval = yaml.dump(data, default_flow_style=False)
|
|
261
|
+
return rtnval
|
|
262
|
+
|
|
263
|
+
@classmethod
|
|
264
|
+
def from_dict(cls, config_data: dict,
|
|
265
|
+
app_context=None) -> "TransportConfiguration":
|
|
266
|
+
"""
|
|
267
|
+
Constructs a TransportConfiguration from a dictionary.
|
|
268
|
+
|
|
269
|
+
:param config_data: A dictionary containing configuration
|
|
270
|
+
fields.
|
|
271
|
+
:param app_context: An optional AppContext for path
|
|
272
|
+
resolution. Currently unused for from_dict but
|
|
273
|
+
accepted for API consistency.
|
|
274
|
+
|
|
275
|
+
:returns: A TransportConfiguration instance.
|
|
276
|
+
|
|
277
|
+
:raises ConfigurationError: If required fields are missing
|
|
278
|
+
or the protocol type is invalid.
|
|
279
|
+
"""
|
|
280
|
+
protocol_type = config_data.get("protocol_type", None)
|
|
281
|
+
host = config_data.get("host", None)
|
|
282
|
+
port = config_data.get("port", None)
|
|
283
|
+
path = config_data.get("path", None)
|
|
284
|
+
headers = config_data.get("headers", None)
|
|
285
|
+
timeout = config_data.get("timeout", 30.0)
|
|
286
|
+
options = config_data.get("options", None)
|
|
287
|
+
credential_references = config_data.get("credential_references", None)
|
|
288
|
+
if isinstance(credential_references, (list, tuple)):
|
|
289
|
+
reference_names = credential_references
|
|
290
|
+
credential_references = {name: None for name in reference_names}
|
|
291
|
+
|
|
292
|
+
rtnval = cls(
|
|
293
|
+
protocol_type=protocol_type,
|
|
294
|
+
host=host,
|
|
295
|
+
port=port,
|
|
296
|
+
path=path,
|
|
297
|
+
headers=headers,
|
|
298
|
+
timeout=timeout,
|
|
299
|
+
options=options,
|
|
300
|
+
credential_references=credential_references
|
|
301
|
+
)
|
|
302
|
+
return rtnval
|
|
303
|
+
|
|
304
|
+
@classmethod
|
|
305
|
+
def from_json(cls, json_str: str,
|
|
306
|
+
app_context=None) -> "TransportConfiguration":
|
|
307
|
+
"""
|
|
308
|
+
Deserializes a JSON string into a TransportConfiguration
|
|
309
|
+
instance.
|
|
310
|
+
|
|
311
|
+
:param json_str: A JSON string containing configuration
|
|
312
|
+
fields.
|
|
313
|
+
:param app_context: An optional AppContext for path
|
|
314
|
+
resolution.
|
|
315
|
+
|
|
316
|
+
:returns: A TransportConfiguration instance.
|
|
317
|
+
|
|
318
|
+
:raises ConfigurationError: If required fields are missing
|
|
319
|
+
or the protocol type is invalid.
|
|
320
|
+
"""
|
|
321
|
+
data = json.loads(json_str)
|
|
322
|
+
rtnval = cls.from_dict(config_data=data, app_context=app_context)
|
|
323
|
+
return rtnval
|
|
324
|
+
|
|
325
|
+
@classmethod
|
|
326
|
+
def from_json_file(cls, file_path: str,
|
|
327
|
+
app_context=None) -> "TransportConfiguration":
|
|
328
|
+
"""
|
|
329
|
+
Loads a TransportConfiguration from a JSON file.
|
|
330
|
+
|
|
331
|
+
When an app_context is provided, the file path is
|
|
332
|
+
resolved relative to the AppContext directory.
|
|
333
|
+
|
|
334
|
+
:param file_path: The path to the JSON configuration
|
|
335
|
+
file.
|
|
336
|
+
:param app_context: An optional AppContext for path
|
|
337
|
+
resolution.
|
|
338
|
+
|
|
339
|
+
:returns: A TransportConfiguration instance.
|
|
340
|
+
|
|
341
|
+
:raises ConfigurationError: If required fields are missing
|
|
342
|
+
or the protocol type is invalid.
|
|
343
|
+
"""
|
|
344
|
+
resolved_path = file_path
|
|
345
|
+
|
|
346
|
+
if app_context is not None:
|
|
347
|
+
base_dir = app_context.home_directory
|
|
348
|
+
resolved_path = os.path.join(base_dir, file_path)
|
|
349
|
+
|
|
350
|
+
with open(resolved_path, "r") as fh:
|
|
351
|
+
json_str = fh.read()
|
|
352
|
+
|
|
353
|
+
rtnval = cls.from_json(json_str=json_str, app_context=app_context)
|
|
354
|
+
return rtnval
|
|
355
|
+
|
|
356
|
+
@classmethod
|
|
357
|
+
def from_yaml(cls, yaml_str: str,
|
|
358
|
+
app_context=None) -> "TransportConfiguration":
|
|
359
|
+
"""
|
|
360
|
+
Deserializes a YAML string into a TransportConfiguration
|
|
361
|
+
instance.
|
|
362
|
+
|
|
363
|
+
:param yaml_str: A YAML string containing configuration
|
|
364
|
+
fields.
|
|
365
|
+
:param app_context: An optional AppContext for path
|
|
366
|
+
resolution.
|
|
367
|
+
|
|
368
|
+
:returns: A TransportConfiguration instance.
|
|
369
|
+
|
|
370
|
+
:raises ConfigurationError: If required fields are missing
|
|
371
|
+
or the protocol type is invalid.
|
|
372
|
+
"""
|
|
373
|
+
data = yaml.safe_load(yaml_str)
|
|
374
|
+
rtnval = cls.from_dict(config_data=data, app_context=app_context)
|
|
375
|
+
return rtnval
|
|
376
|
+
|
|
377
|
+
@classmethod
|
|
378
|
+
def from_yaml_file(cls, file_path: str,
|
|
379
|
+
app_context=None) -> "TransportConfiguration":
|
|
380
|
+
"""
|
|
381
|
+
Loads a TransportConfiguration from a YAML file.
|
|
382
|
+
|
|
383
|
+
When an app_context is provided, the file path is
|
|
384
|
+
resolved relative to the AppContext directory.
|
|
385
|
+
|
|
386
|
+
:param file_path: The path to the YAML configuration
|
|
387
|
+
file.
|
|
388
|
+
:param app_context: An optional AppContext for path
|
|
389
|
+
resolution.
|
|
390
|
+
|
|
391
|
+
:returns: A TransportConfiguration instance.
|
|
392
|
+
|
|
393
|
+
:raises ConfigurationError: If required fields are missing
|
|
394
|
+
or the protocol type is invalid.
|
|
395
|
+
"""
|
|
396
|
+
resolved_path = file_path
|
|
397
|
+
|
|
398
|
+
if app_context is not None:
|
|
399
|
+
base_dir = app_context.home_directory
|
|
400
|
+
resolved_path = os.path.join(base_dir, file_path)
|
|
401
|
+
|
|
402
|
+
with open(resolved_path, "r") as fh:
|
|
403
|
+
yaml_str = fh.read()
|
|
404
|
+
|
|
405
|
+
rtnval = cls.from_yaml(yaml_str=yaml_str, app_context=app_context)
|
|
406
|
+
return rtnval
|
|
407
|
+
|
|
408
|
+
def __repr__(self) -> str:
|
|
409
|
+
"""
|
|
410
|
+
Returns a detailed string representation including the
|
|
411
|
+
class name, protocol type, host, and port.
|
|
412
|
+
|
|
413
|
+
:returns: A repr string for debugging.
|
|
414
|
+
"""
|
|
415
|
+
repr_str = "{}(protocol_type={!r}, host={!r}, port={})".format(
|
|
416
|
+
self.__class__.__name__, self._protocol_type,
|
|
417
|
+
self._host, self._port
|
|
418
|
+
)
|
|
419
|
+
return repr_str
|
|
420
|
+
|
|
421
|
+
def __str__(self) -> str:
|
|
422
|
+
"""
|
|
423
|
+
Returns a human-readable summary including the protocol
|
|
424
|
+
type, host, port, and timeout.
|
|
425
|
+
|
|
426
|
+
:returns: A human-readable string describing the
|
|
427
|
+
configuration.
|
|
428
|
+
"""
|
|
429
|
+
str_val = (
|
|
430
|
+
"TransportConfiguration: protocol_type={}, "
|
|
431
|
+
"host={}, port={}, timeout={}s"
|
|
432
|
+
).format(
|
|
433
|
+
self._protocol_type, self._host,
|
|
434
|
+
self._port, self._timeout
|
|
435
|
+
)
|
|
436
|
+
return str_val
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the TransportHealthCheck for checking Transport connectivity.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
from ccai.agentkit.healthcheck import HealthCheck
|
|
8
|
+
from ccai.agentkit.healthstatus import HealthStatus
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TransportHealthCheck(HealthCheck):
|
|
12
|
+
"""
|
|
13
|
+
Checks Transport connection status.
|
|
14
|
+
|
|
15
|
+
:param name: The health check name.
|
|
16
|
+
:param transport: The transport instance to check.
|
|
17
|
+
:param check_interval: The interval between checks in seconds.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, name: str, transport, check_interval: float = 30.0) -> None:
|
|
21
|
+
super().__init__(name, check_interval)
|
|
22
|
+
self._transport = transport
|
|
23
|
+
return
|
|
24
|
+
|
|
25
|
+
def check(self) -> HealthStatus:
|
|
26
|
+
start = time.monotonic()
|
|
27
|
+
try:
|
|
28
|
+
is_connected = self._transport.is_connected()
|
|
29
|
+
elapsed = time.monotonic() - start
|
|
30
|
+
if is_connected:
|
|
31
|
+
return HealthStatus(self._name, "healthy", response_time=elapsed)
|
|
32
|
+
else:
|
|
33
|
+
return HealthStatus(self._name, "unhealthy", detail="not connected", response_time=elapsed)
|
|
34
|
+
except Exception as exc:
|
|
35
|
+
elapsed = time.monotonic() - start
|
|
36
|
+
return HealthStatus(self._name, "unhealthy", detail=str(exc), response_time=elapsed)
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the TransportRegistry class for tracking available
|
|
3
|
+
Transport instances within an Agent in the Communication &
|
|
4
|
+
Messaging feature.
|
|
5
|
+
|
|
6
|
+
TransportRegistry provides registration, deregistration,
|
|
7
|
+
lookup by name, lookup by protocol type, lookup by tags,
|
|
8
|
+
enumeration, and existence checks for Transport instances.
|
|
9
|
+
Each Agent maintains its own TransportRegistry instance.
|
|
10
|
+
|
|
11
|
+
.. module:: ccai.agentkit.transportregistry
|
|
12
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
13
|
+
:synopsis: Per-agent transport registration and lookup.
|
|
14
|
+
|
|
15
|
+
Requirements: 3.1-3.11, 26.9, 26.10
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import os
|
|
19
|
+
|
|
20
|
+
from typing import Dict
|
|
21
|
+
from typing import List
|
|
22
|
+
from typing import Optional
|
|
23
|
+
|
|
24
|
+
from ccai.agentkit.errors import SemanticError
|
|
25
|
+
from ccai.agentkit.transport import Transport
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class TransportRegistry:
|
|
29
|
+
"""
|
|
30
|
+
Registry tracking available Transport instances for an Agent.
|
|
31
|
+
Provides lookup by name, protocol type, tags, and enumeration.
|
|
32
|
+
|
|
33
|
+
Transports are registered using their name as the key. Duplicate
|
|
34
|
+
names are rejected with a SemanticError. Lookup by name returns
|
|
35
|
+
None when the name is not found. Lookup by protocol type and
|
|
36
|
+
tags returns a list of matching Transport instances.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(self) -> None:
|
|
40
|
+
self._transports: Dict[str, Transport] = {}
|
|
41
|
+
return
|
|
42
|
+
|
|
43
|
+
def register(self, transport: Transport) -> None:
|
|
44
|
+
"""
|
|
45
|
+
Registers a Transport instance using its name as the key.
|
|
46
|
+
|
|
47
|
+
:param transport: The Transport instance to register.
|
|
48
|
+
|
|
49
|
+
:raises SemanticError: If a transport with the same name
|
|
50
|
+
is already registered.
|
|
51
|
+
"""
|
|
52
|
+
transport_name = transport.name
|
|
53
|
+
is_duplicate = transport_name in self._transports
|
|
54
|
+
|
|
55
|
+
if is_duplicate is True:
|
|
56
|
+
errmsg_lines = [
|
|
57
|
+
"Duplicate transport registration attempted.",
|
|
58
|
+
" Transport name: '{}'".format(transport_name),
|
|
59
|
+
" A transport with this name is already registered.",
|
|
60
|
+
]
|
|
61
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
62
|
+
raise SemanticError(errmsg)
|
|
63
|
+
|
|
64
|
+
self._transports[transport_name] = transport
|
|
65
|
+
|
|
66
|
+
return
|
|
67
|
+
|
|
68
|
+
def deregister(self, transport_name: str) -> None:
|
|
69
|
+
"""
|
|
70
|
+
Removes a Transport from the registry by its name.
|
|
71
|
+
|
|
72
|
+
If the transport name is not found, the operation is
|
|
73
|
+
a no-op.
|
|
74
|
+
|
|
75
|
+
:param transport_name: The name of the transport to remove.
|
|
76
|
+
"""
|
|
77
|
+
is_present = transport_name in self._transports
|
|
78
|
+
|
|
79
|
+
if is_present is True:
|
|
80
|
+
del self._transports[transport_name]
|
|
81
|
+
|
|
82
|
+
return
|
|
83
|
+
|
|
84
|
+
def lookup(self, transport_name: str) -> Optional[Transport]:
|
|
85
|
+
"""
|
|
86
|
+
Looks up a registered Transport by its name.
|
|
87
|
+
|
|
88
|
+
:param transport_name: The name of the transport to look up.
|
|
89
|
+
|
|
90
|
+
:returns: The Transport instance if found, or None if not
|
|
91
|
+
found.
|
|
92
|
+
"""
|
|
93
|
+
rtnval = self._transports.get(transport_name, None)
|
|
94
|
+
return rtnval
|
|
95
|
+
|
|
96
|
+
def lookup_by_protocol(self, protocol_type: str) -> List[Transport]:
|
|
97
|
+
"""
|
|
98
|
+
Looks up registered Transports by protocol type.
|
|
99
|
+
|
|
100
|
+
Returns all transports whose protocol_type matches the
|
|
101
|
+
provided value.
|
|
102
|
+
|
|
103
|
+
:param protocol_type: The protocol type string to match
|
|
104
|
+
(e.g. "http", "websocket", "grpc", "message_queue").
|
|
105
|
+
|
|
106
|
+
:returns: A list of Transport instances matching the
|
|
107
|
+
protocol type.
|
|
108
|
+
"""
|
|
109
|
+
matching_transports = []
|
|
110
|
+
|
|
111
|
+
for transport in self._transports.values():
|
|
112
|
+
transport_protocol = transport.protocol_type
|
|
113
|
+
is_match = transport_protocol == protocol_type
|
|
114
|
+
|
|
115
|
+
if is_match is True:
|
|
116
|
+
matching_transports.append(transport)
|
|
117
|
+
|
|
118
|
+
rtnval = matching_transports
|
|
119
|
+
return rtnval
|
|
120
|
+
|
|
121
|
+
def lookup_by_tags(self, **tags: str) -> List[Transport]:
|
|
122
|
+
"""
|
|
123
|
+
Looks up registered Transports by tag key-value pairs.
|
|
124
|
+
|
|
125
|
+
Returns transports that match ALL provided tag criteria.
|
|
126
|
+
|
|
127
|
+
:param tags: Keyword arguments representing tag key-value
|
|
128
|
+
pairs to match.
|
|
129
|
+
|
|
130
|
+
:returns: A list of Transport instances matching all tag
|
|
131
|
+
criteria.
|
|
132
|
+
"""
|
|
133
|
+
matching_transports = []
|
|
134
|
+
|
|
135
|
+
for transport in self._transports.values():
|
|
136
|
+
transport_tags = transport.tags
|
|
137
|
+
all_match = True
|
|
138
|
+
|
|
139
|
+
for tag_key, tag_value in tags.items():
|
|
140
|
+
has_key = tag_key in transport_tags
|
|
141
|
+
|
|
142
|
+
if has_key is not True:
|
|
143
|
+
all_match = False
|
|
144
|
+
break
|
|
145
|
+
|
|
146
|
+
transport_tag_value = transport_tags[tag_key]
|
|
147
|
+
values_match = transport_tag_value == tag_value
|
|
148
|
+
|
|
149
|
+
if values_match is not True:
|
|
150
|
+
all_match = False
|
|
151
|
+
break
|
|
152
|
+
|
|
153
|
+
if all_match is True:
|
|
154
|
+
matching_transports.append(transport)
|
|
155
|
+
|
|
156
|
+
rtnval = matching_transports
|
|
157
|
+
return rtnval
|
|
158
|
+
|
|
159
|
+
def list_all(self) -> List[Transport]:
|
|
160
|
+
"""
|
|
161
|
+
Returns a list of all registered Transport instances.
|
|
162
|
+
|
|
163
|
+
:returns: A list of all registered Transport instances.
|
|
164
|
+
"""
|
|
165
|
+
rtnval = list(self._transports.values())
|
|
166
|
+
return rtnval
|
|
167
|
+
|
|
168
|
+
def has_transport(self, transport_name: str) -> bool:
|
|
169
|
+
"""
|
|
170
|
+
Checks whether a Transport with the given name is
|
|
171
|
+
registered.
|
|
172
|
+
|
|
173
|
+
:param transport_name: The name of the transport to check.
|
|
174
|
+
|
|
175
|
+
:returns: True if a transport with the given name is
|
|
176
|
+
registered, False otherwise.
|
|
177
|
+
"""
|
|
178
|
+
rtnval = transport_name in self._transports
|
|
179
|
+
return rtnval
|
|
180
|
+
|
|
181
|
+
@property
|
|
182
|
+
def count(self) -> int:
|
|
183
|
+
"""
|
|
184
|
+
The number of currently registered transports.
|
|
185
|
+
|
|
186
|
+
:returns: The count of registered transports.
|
|
187
|
+
"""
|
|
188
|
+
rtnval = len(self._transports)
|
|
189
|
+
return rtnval
|
|
190
|
+
|
|
191
|
+
def __repr__(self) -> str:
|
|
192
|
+
"""
|
|
193
|
+
Returns a detailed string representation including the
|
|
194
|
+
class name and the count of registered transports.
|
|
195
|
+
|
|
196
|
+
:returns: A repr string for debugging.
|
|
197
|
+
"""
|
|
198
|
+
repr_str = "{}(count={})".format(
|
|
199
|
+
self.__class__.__name__, self.count
|
|
200
|
+
)
|
|
201
|
+
return repr_str
|
|
202
|
+
|
|
203
|
+
def __str__(self) -> str:
|
|
204
|
+
"""
|
|
205
|
+
Returns a human-readable summary listing the registered
|
|
206
|
+
transport names and protocol types.
|
|
207
|
+
|
|
208
|
+
:returns: A human-readable string describing the registry
|
|
209
|
+
contents.
|
|
210
|
+
"""
|
|
211
|
+
if self.count == 0:
|
|
212
|
+
str_val = "TransportRegistry: 0 transports registered"
|
|
213
|
+
return str_val
|
|
214
|
+
|
|
215
|
+
entries = []
|
|
216
|
+
for transport_name, transport in sorted(self._transports.items()):
|
|
217
|
+
entries.append("{}({})".format(
|
|
218
|
+
transport_name, transport.protocol_type
|
|
219
|
+
))
|
|
220
|
+
|
|
221
|
+
str_val = "TransportRegistry: {} transport(s) registered [{}]".format(
|
|
222
|
+
self.count, ", ".join(entries)
|
|
223
|
+
)
|
|
224
|
+
return str_val
|