MCPcopy Create free account
hub / github.com/1jehuang/jcode / _load_final_payload

Function _load_final_payload

scripts/jcode_harbor_agent.py:149–183  ·  view source on GitHub ↗
(output_dir: Path)

Source from the content-addressed store, hash-verified

147
148
149def _load_final_payload(output_dir: Path) -> dict[str, Any] | None:
150 result_json_path = output_dir / "result.json"
151 if result_json_path.exists():
152 raw = result_json_path.read_text()
153 if raw.strip():
154 return json.loads(raw)
155
156 events_path = output_dir / "events.ndjson"
157 if not events_path.exists():
158 return None
159
160 final_done: dict[str, Any] | None = None
161 for line in events_path.read_text().splitlines():
162 line = line.strip()
163 if not line:
164 continue
165 try:
166 event = json.loads(line)
167 except json.JSONDecodeError:
168 continue
169 if event.get("type") == "done":
170 final_done = event
171
172 if final_done is None:
173 return None
174
175 payload = {
176 "session_id": final_done.get("session_id"),
177 "provider": final_done.get("provider"),
178 "model": final_done.get("model"),
179 "text": final_done.get("text", ""),
180 "usage": final_done.get("usage") or {},
181 }
182 result_json_path.write_text(json.dumps(payload, indent=2) + "\n")
183 return payload
184
185
186class JcodeHarborAgent(BaseAgent):

Callers 1

runMethod · 0.70

Calls 1

getMethod · 0.45

Tested by

no test coverage detected