Stores metadata about an attachment tracked inside a workflow run.
| 17 | |
| 18 | @dataclass |
| 19 | class AttachmentRecord: |
| 20 | """Stores metadata about an attachment tracked inside a workflow run.""" |
| 21 | |
| 22 | ref: AttachmentRef |
| 23 | kind: MessageBlockType = MessageBlockType.FILE |
| 24 | description: Optional[str] = None |
| 25 | extra: Dict[str, Any] = field(default_factory=dict) |
| 26 | |
| 27 | def to_dict(self) -> Dict[str, Any]: |
| 28 | return { |
| 29 | "ref": self.ref.to_dict(), |
| 30 | "kind": self.kind.value, |
| 31 | "description": self.description, |
| 32 | "extra": self.extra, |
| 33 | } |
| 34 | |
| 35 | @classmethod |
| 36 | def from_dict(cls, data: Dict[str, Any]) -> "AttachmentRecord": |
| 37 | ref_data = data.get("ref") or {} |
| 38 | raw_kind = data.get("kind", MessageBlockType.FILE.value) |
| 39 | try: |
| 40 | kind = MessageBlockType(raw_kind) |
| 41 | except ValueError: |
| 42 | kind = MessageBlockType.FILE |
| 43 | return cls( |
| 44 | ref=AttachmentRef.from_dict(ref_data), |
| 45 | kind=kind, |
| 46 | description=data.get("description"), |
| 47 | extra=data.get("extra") or {}, |
| 48 | ) |
| 49 | |
| 50 | def as_message_block(self) -> MessageBlock: |
| 51 | """Convert to a MessageBlock referencing this attachment.""" |
| 52 | return MessageBlock( |
| 53 | type=self.kind, |
| 54 | attachment=self.ref.copy(), |
| 55 | data=dict(self.extra), |
| 56 | ) |
| 57 | |
| 58 | |
| 59 | class AttachmentStore: |
no outgoing calls
no test coverage detected