main
py 35 lines 919 Bytes
Raw
1 """
2 Write attachment files into execution runtime.
3
4 No agent/tool dependencies.
5 """
6
7 import base64
8 from typing import TypedDict
9
10
11 # ------------------------------------------------------------------
12 # Data models
13 # ------------------------------------------------------------------
14
15 class WriteResult(TypedDict):
16 path: str
17 error: str
18
19
20 # ------------------------------------------------------------------
21 # File writer
22 # ------------------------------------------------------------------
23
24 def write_attachment(rel_path: str, content_b64: str) -> WriteResult:
25 try:
26 from helpers import files
27 abs_path = files.get_abs_path(rel_path)
28 files.make_dirs(abs_path)
29
30 content = base64.b64decode(content_b64)
31 files.write_file_bin(abs_path, content)
32
33 return WriteResult(path=abs_path, error="")
34 except Exception as e:
35 return WriteResult(path="", error=str(e))