MCPcopy Create free account
hub / github.com/MemTensor/MemOS / DefaultHubRuntime

Class DefaultHubRuntime

apps/memos-local-plugin/core/hub/runtime.ts:70–368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70class DefaultHubRuntime implements HubRuntime {
71 private server: HubServerRuntime | null = null;
72 private client: HubClientRuntime | null = null;
73 private status: HubAdminPayload["status"] = "disabled";
74 private error: string | null = null;
75
76 constructor(
77 private readonly deps: {
78 repos: Repos;
79 config: ResolvedConfig;
80 log: Logger;
81 agent: string;
82 version: string;
83 },
84 ) {}
85
86 async start(): Promise<void> {
87 if (!this.deps.config.hub.enabled) {
88 this.status = "disabled";
89 return;
90 }
91 this.status = "starting";
92 this.error = null;
93 try {
94 if (this.deps.config.hub.role === "hub") {
95 this.server = new HubServerRuntime({
96 repo: this.deps.repos.hub,
97 config: this.deps.config,
98 log: this.deps.log.child({ channel: "core.hub.server" }),
99 version: this.deps.version,
100 });
101 await this.server.start();
102 this.status = "running";
103 } else {
104 this.client = new HubClientRuntime({
105 repo: this.deps.repos.hub,
106 config: this.deps.config,
107 log: this.deps.log.child({ channel: "core.hub.client" }),
108 });
109 const conn = await this.client.start();
110 this.status = conn?.userToken ? "connected" : "pending";
111 }
112 } catch (err) {
113 this.status = "error";
114 this.error = err instanceof Error ? err.message : String(err);
115 this.deps.log.warn("hub.start.failed", { err: this.error });
116 }
117 }
118
119 async stop(): Promise<void> {
120 await this.client?.stop();
121 await this.server?.stop();
122 this.client = null;
123 this.server = null;
124 }
125
126 async adminSnapshot(): Promise<HubAdminPayload> {
127 const cfg = this.deps.config.hub;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected