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