MCPcopy Create free account
hub / github.com/Louisym/MiniCC / to_dict

Method to_dict

tutorials/12_session_persistence.py:93–112  ·  view source on GitHub ↗

序列化为字典(用于 JSON)

(self)

Source from the content-addressed store, hash-verified

91 is_error: bool = False
92
93 def to_dict(self) -> dict:
94 """序列化为字典(用于 JSON)"""
95 if self.block_type == "text":
96 return {"type": "text", "text": self.text}
97 elif self.block_type == "tool_use":
98 return {
99 "type": "tool_use",
100 "id": self.tool_id,
101 "name": self.tool_name,
102 "input": self.tool_input,
103 }
104 elif self.block_type == "tool_result":
105 return {
106 "type": "tool_result",
107 "tool_use_id": self.tool_use_id,
108 "tool_name": self.tool_name,
109 "output": self.output,
110 "is_error": self.is_error,
111 }
112 return {}
113
114 @staticmethod
115 def from_dict(data: dict) -> "ContentBlock":

Callers 3

to_dictMethod · 0.45
save_session_jsonFunction · 0.45
append_messageMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected