| import uuid |
| import datetime |
|
|
| class WorkspaceManager: |
| def __init__(self): |
| |
| 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] |
| |
| artifact = { |
| "id": artifact_id, |
| "type": type, |
| "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()) |