MCPcopy Create free account
hub / github.com/BUPT-GAMMA/MASFactory / VisualizerClient

Class VisualizerClient

masfactory/visualizer/client.py:24–319  ·  view source on GitHub ↗

A small, stable facade for interacting with the `masfactory-visualizer` VS Code extension. Design goals: - Keep call-sites simple: `visualizer.connect()`, `visualizer.request_user_input()`, `visualizer.open_file()` - Best-effort only: never break normal execution when Visualizer is

Source from the content-addressed store, hash-verified

22 preserve_focus: bool | None = None
23
24class VisualizerClient:
25 """
26 A small, stable facade for interacting with the `masfactory-visualizer` VS Code extension.
27
28 Design goals:
29 - Keep call-sites simple: `visualizer.connect()`, `visualizer.request_user_input()`, `visualizer.open_file()`
30 - Best-effort only: never break normal execution when Visualizer is absent.
31 - Loose coupling: call-sites don't depend on WS message shapes.
32 """
33
34 def __init__(self, runtime: VisualizerRuntime):
35 """Create a VisualizerClient facade.
36
37 Args:
38 runtime: Connected VisualizerRuntime instance used for transport.
39 """
40 self._runtime = runtime
41
42 @property
43 def pid(self) -> int | None:
44 try:
45 v = getattr(self._runtime, "_pid", None)
46 return int(v) if isinstance(v, int) else None
47 except Exception:
48 return None
49
50 @property
51 def mode(self) -> str:
52 try:
53 return str(getattr(self._runtime, "mode", "unknown") or "unknown")
54 except Exception:
55 return "unknown"
56
57 def connect(self, *, timeout_s: float = 2.0) -> bool:
58 try:
59 self._runtime.start()
60 return self._runtime.wait_connected(timeout_s=max(0.0, float(timeout_s)))
61 except Exception:
62 return False
63
64 def is_connected(self) -> bool:
65 try:
66 return self._runtime.is_connected()
67 except Exception:
68 return False
69
70 # Graph lifecycle APIs for framework internals.
71 def attach_graph(self, root_graph: object) -> None:
72 """
73 Attach Visualizer runtime hooks to a built RootGraph.
74
75 This should be called once after the graph is fully built (nodes/edges exist),
76 so we don't need to re-register hooks per-invocation.
77 """
78 try:
79 from .runtime_hooks import install_root_graph_runtime_hooks
80
81 self.set_active_graph(root_graph)

Callers 2

get_clientFunction · 0.85
connectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected