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,193 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the QueueMessage class representing an immutable message in a
|
|
3
|
+
queue with identifier, queue name, body, attributes, receipt handle,
|
|
4
|
+
and timestamp. Supports serialization to and from dictionary and JSON
|
|
5
|
+
representations.
|
|
6
|
+
|
|
7
|
+
.. module:: ccai.agentkit.platform.services.queuemessage
|
|
8
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
9
|
+
:synopsis: Immutable queue message representation for platform messaging services.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
|
|
14
|
+
from datetime import datetime
|
|
15
|
+
from typing import Dict
|
|
16
|
+
from typing import Optional
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class QueueMessage:
|
|
20
|
+
"""
|
|
21
|
+
Immutable object representing a message in a queue. Contains a
|
|
22
|
+
unique identifier, queue name, body as a Python object, attributes
|
|
23
|
+
dictionary, receipt handle string for acknowledgment, and timestamp.
|
|
24
|
+
|
|
25
|
+
All fields are exposed as read-only properties.
|
|
26
|
+
|
|
27
|
+
:param identifier: A unique identifier string for this message.
|
|
28
|
+
:param queue_name: The name of the queue this message belongs to.
|
|
29
|
+
:param body: The message body as a Python object.
|
|
30
|
+
:param attributes: A dictionary of message attributes.
|
|
31
|
+
:param receipt_handle: A receipt handle string for acknowledgment.
|
|
32
|
+
:param timestamp: The timestamp when the message was created.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def __init__(self, identifier: str, queue_name: str, body: object,
|
|
36
|
+
attributes: Optional[Dict[str, str]] = None,
|
|
37
|
+
receipt_handle: str = "",
|
|
38
|
+
timestamp: Optional[datetime] = None) -> None:
|
|
39
|
+
self._identifier = identifier
|
|
40
|
+
self._queue_name = queue_name
|
|
41
|
+
self._body = body
|
|
42
|
+
self._attributes = dict(attributes) if attributes is not None else {}
|
|
43
|
+
self._receipt_handle = receipt_handle
|
|
44
|
+
self._timestamp = timestamp
|
|
45
|
+
return
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def identifier(self) -> str:
|
|
49
|
+
"""
|
|
50
|
+
The unique identifier string for this message.
|
|
51
|
+
|
|
52
|
+
:returns: The identifier string.
|
|
53
|
+
"""
|
|
54
|
+
rtnval = self._identifier
|
|
55
|
+
return rtnval
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def queue_name(self) -> str:
|
|
59
|
+
"""
|
|
60
|
+
The name of the queue this message belongs to.
|
|
61
|
+
|
|
62
|
+
:returns: The queue name string.
|
|
63
|
+
"""
|
|
64
|
+
rtnval = self._queue_name
|
|
65
|
+
return rtnval
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def body(self) -> object:
|
|
69
|
+
"""
|
|
70
|
+
The message body as a Python object.
|
|
71
|
+
|
|
72
|
+
:returns: The body object.
|
|
73
|
+
"""
|
|
74
|
+
rtnval = self._body
|
|
75
|
+
return rtnval
|
|
76
|
+
|
|
77
|
+
@property
|
|
78
|
+
def attributes(self) -> dict:
|
|
79
|
+
"""
|
|
80
|
+
A defensive copy of the message attributes dictionary.
|
|
81
|
+
|
|
82
|
+
:returns: A dictionary copy of the attributes.
|
|
83
|
+
"""
|
|
84
|
+
rtnval = dict(self._attributes)
|
|
85
|
+
return rtnval
|
|
86
|
+
|
|
87
|
+
@property
|
|
88
|
+
def receipt_handle(self) -> str:
|
|
89
|
+
"""
|
|
90
|
+
The receipt handle string for message acknowledgment.
|
|
91
|
+
|
|
92
|
+
:returns: The receipt handle string.
|
|
93
|
+
"""
|
|
94
|
+
rtnval = self._receipt_handle
|
|
95
|
+
return rtnval
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def timestamp(self) -> datetime:
|
|
99
|
+
"""
|
|
100
|
+
The timestamp when the message was created.
|
|
101
|
+
|
|
102
|
+
:returns: The timestamp datetime.
|
|
103
|
+
"""
|
|
104
|
+
rtnval = self._timestamp
|
|
105
|
+
return rtnval
|
|
106
|
+
|
|
107
|
+
def as_dict(self) -> dict:
|
|
108
|
+
"""
|
|
109
|
+
Returns a dictionary representation of the message fields.
|
|
110
|
+
|
|
111
|
+
:returns: A dictionary with all message fields.
|
|
112
|
+
"""
|
|
113
|
+
timestamp_str = self._timestamp.isoformat() if self._timestamp is not None else None
|
|
114
|
+
rtnval = {
|
|
115
|
+
"identifier": self._identifier,
|
|
116
|
+
"queue_name": self._queue_name,
|
|
117
|
+
"body": self._body,
|
|
118
|
+
"attributes": dict(self._attributes),
|
|
119
|
+
"receipt_handle": self._receipt_handle,
|
|
120
|
+
"timestamp": timestamp_str
|
|
121
|
+
}
|
|
122
|
+
return rtnval
|
|
123
|
+
|
|
124
|
+
def to_json(self) -> str:
|
|
125
|
+
"""
|
|
126
|
+
Returns a JSON string representation of the message fields.
|
|
127
|
+
|
|
128
|
+
:returns: A JSON string.
|
|
129
|
+
"""
|
|
130
|
+
data = self.as_dict()
|
|
131
|
+
rtnval = json.dumps(data)
|
|
132
|
+
return rtnval
|
|
133
|
+
|
|
134
|
+
@classmethod
|
|
135
|
+
def from_dict(cls, data: dict) -> "QueueMessage":
|
|
136
|
+
"""
|
|
137
|
+
Constructs a QueueMessage from a dictionary.
|
|
138
|
+
|
|
139
|
+
:param data: Dictionary containing message fields.
|
|
140
|
+
|
|
141
|
+
:returns: A QueueMessage instance.
|
|
142
|
+
"""
|
|
143
|
+
timestamp_raw = data.get("timestamp")
|
|
144
|
+
timestamp = datetime.fromisoformat(timestamp_raw) if timestamp_raw is not None else None
|
|
145
|
+
rtnval = cls(
|
|
146
|
+
identifier=data["identifier"],
|
|
147
|
+
queue_name=data["queue_name"],
|
|
148
|
+
body=data["body"],
|
|
149
|
+
attributes=data.get("attributes", {}),
|
|
150
|
+
receipt_handle=data.get("receipt_handle", ""),
|
|
151
|
+
timestamp=timestamp
|
|
152
|
+
)
|
|
153
|
+
return rtnval
|
|
154
|
+
|
|
155
|
+
@classmethod
|
|
156
|
+
def from_json(cls, json_str: str) -> "QueueMessage":
|
|
157
|
+
"""
|
|
158
|
+
Deserializes a JSON string into a QueueMessage instance.
|
|
159
|
+
|
|
160
|
+
:param json_str: A JSON string containing message fields.
|
|
161
|
+
|
|
162
|
+
:returns: A QueueMessage instance.
|
|
163
|
+
"""
|
|
164
|
+
data = json.loads(json_str)
|
|
165
|
+
rtnval = cls.from_dict(data)
|
|
166
|
+
return rtnval
|
|
167
|
+
|
|
168
|
+
def __repr__(self) -> str:
|
|
169
|
+
"""
|
|
170
|
+
Returns a detailed string representation including class name,
|
|
171
|
+
identifier, and queue name.
|
|
172
|
+
|
|
173
|
+
:returns: A repr string for debugging.
|
|
174
|
+
"""
|
|
175
|
+
rtnval = "QueueMessage(identifier={}, queue_name={})".format(
|
|
176
|
+
self._identifier, self._queue_name
|
|
177
|
+
)
|
|
178
|
+
return rtnval
|
|
179
|
+
|
|
180
|
+
def __str__(self) -> str:
|
|
181
|
+
"""
|
|
182
|
+
Returns a human-readable summary including the identifier,
|
|
183
|
+
queue name, and a truncated body preview (max 50 chars).
|
|
184
|
+
|
|
185
|
+
:returns: A human-readable string.
|
|
186
|
+
"""
|
|
187
|
+
body_preview = str(self._body)
|
|
188
|
+
if len(body_preview) > 50:
|
|
189
|
+
body_preview = body_preview[:50] + "..."
|
|
190
|
+
rtnval = "QueueMessage: id={}, queue={}, body={}".format(
|
|
191
|
+
self._identifier, self._queue_name, body_preview
|
|
192
|
+
)
|
|
193
|
+
return rtnval
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the StorageObject class representing an immutable stored object
|
|
3
|
+
with key, content, content type, metadata, size, and last modified
|
|
4
|
+
timestamp. Supports serialization to and from dictionary and JSON
|
|
5
|
+
representations with base64-encoded content.
|
|
6
|
+
|
|
7
|
+
.. module:: ccai.agentkit.platform.services.storageobject
|
|
8
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
9
|
+
:synopsis: Immutable stored object representation for platform storage services.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import base64
|
|
13
|
+
import json
|
|
14
|
+
|
|
15
|
+
from datetime import datetime
|
|
16
|
+
from typing import Dict
|
|
17
|
+
from typing import Optional
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class StorageObject:
|
|
21
|
+
"""
|
|
22
|
+
Immutable object representing a stored object in a platform storage
|
|
23
|
+
service. Contains the object key, content as bytes, content type,
|
|
24
|
+
metadata dictionary, size in bytes, and last modified timestamp.
|
|
25
|
+
|
|
26
|
+
All fields are exposed as read-only properties. Serialization
|
|
27
|
+
encodes content as base64 for safe transport in JSON.
|
|
28
|
+
|
|
29
|
+
:param key: The object key string identifying this object.
|
|
30
|
+
:param content: The object content as bytes.
|
|
31
|
+
:param content_type: The MIME content type string.
|
|
32
|
+
:param metadata: A dictionary of metadata key-value pairs.
|
|
33
|
+
:param size: The size of the content in bytes.
|
|
34
|
+
:param last_modified: The timestamp when the object was last modified.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(self, key: str, content: bytes, content_type: str,
|
|
38
|
+
metadata: Optional[Dict[str, str]] = None,
|
|
39
|
+
size: int = 0, last_modified: Optional[datetime] = None) -> None:
|
|
40
|
+
self._key = key
|
|
41
|
+
self._content = content
|
|
42
|
+
self._content_type = content_type
|
|
43
|
+
self._metadata = dict(metadata) if metadata is not None else {}
|
|
44
|
+
self._size = size
|
|
45
|
+
self._last_modified = last_modified
|
|
46
|
+
return
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def key(self) -> str:
|
|
50
|
+
"""
|
|
51
|
+
The object key string identifying this object.
|
|
52
|
+
|
|
53
|
+
:returns: The key string.
|
|
54
|
+
"""
|
|
55
|
+
rtnval = self._key
|
|
56
|
+
return rtnval
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def content(self) -> bytes:
|
|
60
|
+
"""
|
|
61
|
+
The object content as bytes.
|
|
62
|
+
|
|
63
|
+
:returns: The content bytes.
|
|
64
|
+
"""
|
|
65
|
+
rtnval = self._content
|
|
66
|
+
return rtnval
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def content_type(self) -> str:
|
|
70
|
+
"""
|
|
71
|
+
The MIME content type string.
|
|
72
|
+
|
|
73
|
+
:returns: The content type string.
|
|
74
|
+
"""
|
|
75
|
+
rtnval = self._content_type
|
|
76
|
+
return rtnval
|
|
77
|
+
|
|
78
|
+
@property
|
|
79
|
+
def metadata(self) -> dict:
|
|
80
|
+
"""
|
|
81
|
+
A defensive copy of the metadata dictionary.
|
|
82
|
+
|
|
83
|
+
:returns: A dictionary copy of the metadata.
|
|
84
|
+
"""
|
|
85
|
+
rtnval = dict(self._metadata)
|
|
86
|
+
return rtnval
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def size(self) -> int:
|
|
90
|
+
"""
|
|
91
|
+
The size of the content in bytes.
|
|
92
|
+
|
|
93
|
+
:returns: The size integer.
|
|
94
|
+
"""
|
|
95
|
+
rtnval = self._size
|
|
96
|
+
return rtnval
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def last_modified(self) -> datetime:
|
|
100
|
+
"""
|
|
101
|
+
The timestamp when the object was last modified.
|
|
102
|
+
|
|
103
|
+
:returns: The last modified datetime.
|
|
104
|
+
"""
|
|
105
|
+
rtnval = self._last_modified
|
|
106
|
+
return rtnval
|
|
107
|
+
|
|
108
|
+
def as_dict(self) -> dict:
|
|
109
|
+
"""
|
|
110
|
+
Returns a dictionary representation of the object fields.
|
|
111
|
+
Content is encoded as base64 for safe serialization.
|
|
112
|
+
|
|
113
|
+
:returns: A dictionary with all object fields.
|
|
114
|
+
"""
|
|
115
|
+
encoded_content = base64.b64encode(self._content).decode("utf-8")
|
|
116
|
+
last_modified_str = self._last_modified.isoformat() if self._last_modified is not None else None
|
|
117
|
+
rtnval = {
|
|
118
|
+
"key": self._key,
|
|
119
|
+
"content": encoded_content,
|
|
120
|
+
"content_type": self._content_type,
|
|
121
|
+
"metadata": dict(self._metadata),
|
|
122
|
+
"size": self._size,
|
|
123
|
+
"last_modified": last_modified_str
|
|
124
|
+
}
|
|
125
|
+
return rtnval
|
|
126
|
+
|
|
127
|
+
def to_json(self) -> str:
|
|
128
|
+
"""
|
|
129
|
+
Returns a JSON string representation of the object fields.
|
|
130
|
+
|
|
131
|
+
:returns: A JSON string.
|
|
132
|
+
"""
|
|
133
|
+
data = self.as_dict()
|
|
134
|
+
rtnval = json.dumps(data)
|
|
135
|
+
return rtnval
|
|
136
|
+
|
|
137
|
+
@classmethod
|
|
138
|
+
def from_dict(cls, data: dict) -> "StorageObject":
|
|
139
|
+
"""
|
|
140
|
+
Constructs a StorageObject from a dictionary, decoding base64
|
|
141
|
+
content back to bytes.
|
|
142
|
+
|
|
143
|
+
:param data: Dictionary containing object fields.
|
|
144
|
+
|
|
145
|
+
:returns: A StorageObject instance.
|
|
146
|
+
"""
|
|
147
|
+
content = base64.b64decode(data["content"])
|
|
148
|
+
last_modified_raw = data.get("last_modified")
|
|
149
|
+
last_modified = datetime.fromisoformat(last_modified_raw) if last_modified_raw is not None else None
|
|
150
|
+
rtnval = cls(
|
|
151
|
+
key=data["key"],
|
|
152
|
+
content=content,
|
|
153
|
+
content_type=data["content_type"],
|
|
154
|
+
metadata=data.get("metadata", {}),
|
|
155
|
+
size=data["size"],
|
|
156
|
+
last_modified=last_modified
|
|
157
|
+
)
|
|
158
|
+
return rtnval
|
|
159
|
+
|
|
160
|
+
@classmethod
|
|
161
|
+
def from_json(cls, json_str: str) -> "StorageObject":
|
|
162
|
+
"""
|
|
163
|
+
Deserializes a JSON string into a StorageObject instance.
|
|
164
|
+
|
|
165
|
+
:param json_str: A JSON string containing object fields.
|
|
166
|
+
|
|
167
|
+
:returns: A StorageObject instance.
|
|
168
|
+
"""
|
|
169
|
+
data = json.loads(json_str)
|
|
170
|
+
rtnval = cls.from_dict(data)
|
|
171
|
+
return rtnval
|
|
172
|
+
|
|
173
|
+
def __repr__(self) -> str:
|
|
174
|
+
"""
|
|
175
|
+
Returns a detailed string representation including class name,
|
|
176
|
+
object key, content type, and size.
|
|
177
|
+
|
|
178
|
+
:returns: A repr string for debugging.
|
|
179
|
+
"""
|
|
180
|
+
rtnval = "StorageObject(key={}, content_type={}, size={})".format(
|
|
181
|
+
self._key, self._content_type, self._size
|
|
182
|
+
)
|
|
183
|
+
return rtnval
|
|
184
|
+
|
|
185
|
+
def __str__(self) -> str:
|
|
186
|
+
"""
|
|
187
|
+
Returns a human-readable summary including the object key,
|
|
188
|
+
content type, and size.
|
|
189
|
+
|
|
190
|
+
:returns: A human-readable string.
|
|
191
|
+
"""
|
|
192
|
+
rtnval = "StorageObject: key={}, content_type={}, size={}".format(
|
|
193
|
+
self._key, self._content_type, self._size
|
|
194
|
+
)
|
|
195
|
+
return rtnval
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Defines the StorageService abstract base class representing an object
|
|
3
|
+
storage service that can store, retrieve, list, and delete objects by
|
|
4
|
+
key. Concrete implementations wrap AWS S3, Azure Blob Storage, GCP
|
|
5
|
+
Cloud Storage, and local file system storage.
|
|
6
|
+
|
|
7
|
+
.. module:: ccai.agentkit.platform.services.storageservice
|
|
8
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
9
|
+
:synopsis: Abstract storage service interface for platform storage services.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import abc
|
|
13
|
+
|
|
14
|
+
from ccai.agentkit.platform.platformtype import PlatformType
|
|
15
|
+
from ccai.agentkit.platform.services.platformservice import PlatformService
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class StorageService(PlatformService, abc.ABC):
|
|
19
|
+
"""
|
|
20
|
+
Abstract base class representing an object storage service that can
|
|
21
|
+
store, retrieve, list, and delete objects by key.
|
|
22
|
+
|
|
23
|
+
Inherits from PlatformService with service_type fixed to "storage".
|
|
24
|
+
Subclasses must implement put_object, get_object, delete_object,
|
|
25
|
+
list_objects, object_exists, create_container, delete_container,
|
|
26
|
+
and list_containers in addition to is_available and health_check.
|
|
27
|
+
|
|
28
|
+
:param service_name: A string identifying this storage service instance.
|
|
29
|
+
:param platform_type: The PlatformType this service targets.
|
|
30
|
+
:param configuration: An optional PlatformConfiguration for service-specific settings.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, service_name: str, platform_type: PlatformType,
|
|
34
|
+
configuration: "PlatformConfiguration" = None) -> None:
|
|
35
|
+
super().__init__(
|
|
36
|
+
service_name=service_name,
|
|
37
|
+
service_type="storage",
|
|
38
|
+
platform_type=platform_type,
|
|
39
|
+
configuration=configuration
|
|
40
|
+
)
|
|
41
|
+
return
|
|
42
|
+
|
|
43
|
+
@abc.abstractmethod
|
|
44
|
+
def put_object(self, container_name: str, object_key: str,
|
|
45
|
+
content: bytes, content_type: str = None,
|
|
46
|
+
metadata: dict = None) -> None:
|
|
47
|
+
"""
|
|
48
|
+
Stores an object in the specified container.
|
|
49
|
+
|
|
50
|
+
:param container_name: Name of the storage container.
|
|
51
|
+
:param object_key: Key identifying the object.
|
|
52
|
+
:param content: Object content as bytes.
|
|
53
|
+
:param content_type: Optional MIME content type string.
|
|
54
|
+
:param metadata: Optional metadata dictionary.
|
|
55
|
+
|
|
56
|
+
:raises: StorageError
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
@abc.abstractmethod
|
|
60
|
+
def get_object(self, container_name: str, object_key: str) -> "StorageObject":
|
|
61
|
+
"""
|
|
62
|
+
Retrieves an object from the specified container.
|
|
63
|
+
|
|
64
|
+
:param container_name: Name of the storage container.
|
|
65
|
+
:param object_key: Key identifying the object.
|
|
66
|
+
|
|
67
|
+
:returns: A StorageObject instance.
|
|
68
|
+
:raises: StorageError
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
@abc.abstractmethod
|
|
72
|
+
def delete_object(self, container_name: str, object_key: str) -> None:
|
|
73
|
+
"""
|
|
74
|
+
Removes an object from the specified container.
|
|
75
|
+
|
|
76
|
+
:param container_name: Name of the storage container.
|
|
77
|
+
:param object_key: Key identifying the object.
|
|
78
|
+
|
|
79
|
+
:raises: StorageError
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
@abc.abstractmethod
|
|
83
|
+
def list_objects(self, container_name: str, prefix: str = None) -> list:
|
|
84
|
+
"""
|
|
85
|
+
Returns a list of object key strings matching the optional prefix.
|
|
86
|
+
|
|
87
|
+
:param container_name: Name of the storage container.
|
|
88
|
+
:param prefix: Optional prefix filter string.
|
|
89
|
+
|
|
90
|
+
:returns: List of object key strings.
|
|
91
|
+
:raises: StorageError
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
@abc.abstractmethod
|
|
95
|
+
def object_exists(self, container_name: str, object_key: str) -> bool:
|
|
96
|
+
"""
|
|
97
|
+
Checks whether an object exists in the specified container.
|
|
98
|
+
|
|
99
|
+
:param container_name: Name of the storage container.
|
|
100
|
+
:param object_key: Key identifying the object.
|
|
101
|
+
|
|
102
|
+
:returns: True if the object exists, False otherwise.
|
|
103
|
+
:raises: StorageError
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
@abc.abstractmethod
|
|
107
|
+
def create_container(self, container_name: str) -> None:
|
|
108
|
+
"""
|
|
109
|
+
Creates a storage container.
|
|
110
|
+
|
|
111
|
+
:param container_name: Name of the container to create.
|
|
112
|
+
|
|
113
|
+
:raises: StorageError
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
@abc.abstractmethod
|
|
117
|
+
def delete_container(self, container_name: str) -> None:
|
|
118
|
+
"""
|
|
119
|
+
Removes a storage container.
|
|
120
|
+
|
|
121
|
+
:param container_name: Name of the container to remove.
|
|
122
|
+
|
|
123
|
+
:raises: StorageError
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
@abc.abstractmethod
|
|
127
|
+
def list_containers(self) -> list:
|
|
128
|
+
"""
|
|
129
|
+
Returns a list of container name strings.
|
|
130
|
+
|
|
131
|
+
:returns: List of container name strings.
|
|
132
|
+
:raises: StorageError
|
|
133
|
+
"""
|
|
134
|
+
|
|
135
|
+
def __repr__(self) -> str:
|
|
136
|
+
"""
|
|
137
|
+
Returns a detailed string representation including class name,
|
|
138
|
+
service name, and platform type.
|
|
139
|
+
|
|
140
|
+
:returns: A repr string for debugging.
|
|
141
|
+
"""
|
|
142
|
+
rtnval = "{}(service_name={}, platform_type={})".format(
|
|
143
|
+
self.__class__.__name__, self._service_name,
|
|
144
|
+
self._platform_type.to_string()
|
|
145
|
+
)
|
|
146
|
+
return rtnval
|
|
147
|
+
|
|
148
|
+
def __str__(self) -> str:
|
|
149
|
+
"""
|
|
150
|
+
Returns a human-readable summary including the service name
|
|
151
|
+
and platform type.
|
|
152
|
+
|
|
153
|
+
:returns: A human-readable string.
|
|
154
|
+
"""
|
|
155
|
+
rtnval = "{}: name={}, platform={}".format(
|
|
156
|
+
self.__class__.__name__, self._service_name,
|
|
157
|
+
self._platform_type.to_string()
|
|
158
|
+
)
|
|
159
|
+
return rtnval
|