File size: 1,375 Bytes
6e02dfb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import uuid
import datetime
class WorkspaceManager:
def __init__(self):
# The "State" dictionary
self.artifacts = {}
self.history = []
def create_artifact(self, type, content, metadata=None):
"""
Creates a new artifact (Image, Data, Note)
"""
artifact_id = str(uuid.uuid4())[:8] # Short ID
artifact = {
"id": artifact_id,
"type": type, # 'text', 'code', 'image', 'chart'
"content": content,
"metadata": metadata or {},
"created_at": str(datetime.datetime.now()),
"version": 1
}
self.artifacts[artifact_id] = artifact
self.history.append(f"Created artifact {artifact_id} ({type})")
return artifact
def update_artifact(self, artifact_id, new_content):
"""
Updates an existing artifact.
"""
if artifact_id in self.artifacts:
self.artifacts[artifact_id]["content"] = new_content
self.artifacts[artifact_id]["version"] += 1
self.history.append(f"Updated artifact {artifact_id}")
return self.artifacts[artifact_id]
return None
def get_artifact(self, artifact_id):
return self.artifacts.get(artifact_id)
def list_artifacts(self):
return list(self.artifacts.values()) |