@mind2flow/daemon 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/command-center-client.d.ts +32 -0
- package/dist/command-center-client.d.ts.map +1 -0
- package/dist/command-center-client.js +137 -0
- package/dist/command-center-client.js.map +1 -0
- package/dist/config.d.ts +51 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +89 -0
- package/dist/config.js.map +1 -0
- package/dist/daemon.d.ts +21 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +1937 -0
- package/dist/daemon.js.map +1 -0
- package/dist/gateway-client.d.ts +175 -0
- package/dist/gateway-client.d.ts.map +1 -0
- package/dist/gateway-client.js +494 -0
- package/dist/gateway-client.js.map +1 -0
- package/dist/heartbeat.d.ts +35 -0
- package/dist/heartbeat.d.ts.map +1 -0
- package/dist/heartbeat.js +116 -0
- package/dist/heartbeat.js.map +1 -0
- package/dist/openclaw-manager.d.ts +41 -0
- package/dist/openclaw-manager.d.ts.map +1 -0
- package/dist/openclaw-manager.js +199 -0
- package/dist/openclaw-manager.js.map +1 -0
- package/dist/protocols/index.d.ts +21 -0
- package/dist/protocols/index.d.ts.map +1 -0
- package/dist/protocols/index.js +30 -0
- package/dist/protocols/index.js.map +1 -0
- package/dist/protocols/jsonrpc-protocol.d.ts +24 -0
- package/dist/protocols/jsonrpc-protocol.d.ts.map +1 -0
- package/dist/protocols/jsonrpc-protocol.js +83 -0
- package/dist/protocols/jsonrpc-protocol.js.map +1 -0
- package/dist/protocols/openclaw-protocol.d.ts +33 -0
- package/dist/protocols/openclaw-protocol.d.ts.map +1 -0
- package/dist/protocols/openclaw-protocol.js +131 -0
- package/dist/protocols/openclaw-protocol.js.map +1 -0
- package/dist/protocols/types.d.ts +86 -0
- package/dist/protocols/types.d.ts.map +1 -0
- package/dist/protocols/types.js +13 -0
- package/dist/protocols/types.js.map +1 -0
- package/package.json +40 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Center WebSocket client — persistent connection upstream
|
|
3
|
+
* to the Mind2Flow OpenClaw Command Center API.
|
|
4
|
+
*
|
|
5
|
+
* Handles: auto-reconnect, authentication, message dispatch.
|
|
6
|
+
*/
|
|
7
|
+
import { EventEmitter } from "node:events";
|
|
8
|
+
import type { DaemonConfig } from "./config.js";
|
|
9
|
+
export interface ServerMessage {
|
|
10
|
+
type: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export declare class CommandCenterClient extends EventEmitter {
|
|
14
|
+
private ws;
|
|
15
|
+
private config;
|
|
16
|
+
private reconnectDelay;
|
|
17
|
+
private maxReconnectDelay;
|
|
18
|
+
private reconnectTimer;
|
|
19
|
+
private shouldReconnect;
|
|
20
|
+
private pingInterval;
|
|
21
|
+
constructor(config: DaemonConfig);
|
|
22
|
+
connect(): void;
|
|
23
|
+
send(data: Record<string, unknown>): boolean;
|
|
24
|
+
private scheduleReconnect;
|
|
25
|
+
private startPing;
|
|
26
|
+
private stopPing;
|
|
27
|
+
disconnect(): void;
|
|
28
|
+
private cleanup;
|
|
29
|
+
get isConnected(): boolean;
|
|
30
|
+
private log;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=command-center-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-center-client.d.ts","sourceRoot":"","sources":["../src/command-center-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAID,qBAAa,mBAAoB,SAAQ,YAAY;IACnD,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,iBAAiB,CAAU;IACnC,OAAO,CAAC,cAAc,CAA8C;IACpE,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,YAAY,CAA+C;gBAEvD,MAAM,EAAE,YAAY;IAOhC,OAAO,IAAI,IAAI;IAwCf,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO;IAiB5C,OAAO,CAAC,iBAAiB;IAkBzB,OAAO,CAAC,SAAS;IASjB,OAAO,CAAC,QAAQ;IAShB,UAAU,IAAI,IAAI;IASlB,OAAO,CAAC,OAAO;IAWf,IAAI,WAAW,IAAI,OAAO,CAEzB;IAID,OAAO,CAAC,GAAG;CAYZ"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Center WebSocket client — persistent connection upstream
|
|
3
|
+
* to the Mind2Flow OpenClaw Command Center API.
|
|
4
|
+
*
|
|
5
|
+
* Handles: auto-reconnect, authentication, message dispatch.
|
|
6
|
+
*/
|
|
7
|
+
import WebSocket from "ws";
|
|
8
|
+
import { EventEmitter } from "node:events";
|
|
9
|
+
// ── Client ─────────────────────────────────────────────────────────
|
|
10
|
+
export class CommandCenterClient extends EventEmitter {
|
|
11
|
+
ws = null;
|
|
12
|
+
config;
|
|
13
|
+
reconnectDelay = 1_000;
|
|
14
|
+
maxReconnectDelay = 60_000;
|
|
15
|
+
reconnectTimer = null;
|
|
16
|
+
shouldReconnect = true;
|
|
17
|
+
pingInterval = null;
|
|
18
|
+
constructor(config) {
|
|
19
|
+
super();
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
// ── Connect ────────────────────────────────────────────────────
|
|
23
|
+
connect() {
|
|
24
|
+
if (this.ws)
|
|
25
|
+
return;
|
|
26
|
+
const url = `${this.config.serverUrl}/ws/instance/${this.config.instanceId}?api_key=${encodeURIComponent(this.config.apiKey)}`;
|
|
27
|
+
this.log("info", `Connecting to Command Center: ${this.config.serverUrl}`);
|
|
28
|
+
this.ws = new WebSocket(url);
|
|
29
|
+
this.ws.on("open", () => {
|
|
30
|
+
this.log("info", "Connected to Command Center");
|
|
31
|
+
this.reconnectDelay = 1_000; // reset backoff
|
|
32
|
+
this.emit("connected");
|
|
33
|
+
this.startPing();
|
|
34
|
+
});
|
|
35
|
+
this.ws.on("message", (raw) => {
|
|
36
|
+
try {
|
|
37
|
+
const msg = JSON.parse(raw.toString());
|
|
38
|
+
this.log("debug", `← ${msg.type}`);
|
|
39
|
+
this.emit("message", msg);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
this.log("warn", "Received invalid JSON from server");
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
this.ws.on("close", (code, reason) => {
|
|
46
|
+
this.log("info", `Disconnected from Command Center (code=${code} reason=${reason.toString()})`);
|
|
47
|
+
this.cleanup();
|
|
48
|
+
this.emit("disconnected");
|
|
49
|
+
this.scheduleReconnect();
|
|
50
|
+
});
|
|
51
|
+
this.ws.on("error", (err) => {
|
|
52
|
+
this.log("error", `WebSocket error: ${err.message}`);
|
|
53
|
+
// 'close' event will fire after this, triggering reconnect
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
// ── Send ───────────────────────────────────────────────────────
|
|
57
|
+
send(data) {
|
|
58
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
59
|
+
this.log("warn", "Cannot send — not connected");
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
this.ws.send(JSON.stringify(data));
|
|
64
|
+
this.log("debug", `→ ${data.type}`);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
this.log("error", "Failed to send message");
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// ── Reconnect ──────────────────────────────────────────────────
|
|
73
|
+
scheduleReconnect() {
|
|
74
|
+
if (!this.shouldReconnect)
|
|
75
|
+
return;
|
|
76
|
+
this.log("info", `Reconnecting in ${this.reconnectDelay / 1000}s…`);
|
|
77
|
+
this.reconnectTimer = setTimeout(() => {
|
|
78
|
+
this.reconnectTimer = null;
|
|
79
|
+
this.connect();
|
|
80
|
+
}, this.reconnectDelay);
|
|
81
|
+
// Exponential backoff with jitter
|
|
82
|
+
this.reconnectDelay = Math.min(this.reconnectDelay * 2 + Math.random() * 1_000, this.maxReconnectDelay);
|
|
83
|
+
}
|
|
84
|
+
// ── Keep-alive ─────────────────────────────────────────────────
|
|
85
|
+
startPing() {
|
|
86
|
+
this.stopPing();
|
|
87
|
+
this.pingInterval = setInterval(() => {
|
|
88
|
+
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
89
|
+
this.ws.ping();
|
|
90
|
+
}
|
|
91
|
+
}, 20_000);
|
|
92
|
+
}
|
|
93
|
+
stopPing() {
|
|
94
|
+
if (this.pingInterval) {
|
|
95
|
+
clearInterval(this.pingInterval);
|
|
96
|
+
this.pingInterval = null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// ── Shutdown ───────────────────────────────────────────────────
|
|
100
|
+
disconnect() {
|
|
101
|
+
this.shouldReconnect = false;
|
|
102
|
+
this.cleanup();
|
|
103
|
+
if (this.ws) {
|
|
104
|
+
this.ws.close(1000, "Daemon shutting down");
|
|
105
|
+
this.ws = null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
cleanup() {
|
|
109
|
+
this.stopPing();
|
|
110
|
+
if (this.reconnectTimer) {
|
|
111
|
+
clearTimeout(this.reconnectTimer);
|
|
112
|
+
this.reconnectTimer = null;
|
|
113
|
+
}
|
|
114
|
+
this.ws = null;
|
|
115
|
+
}
|
|
116
|
+
// ── State ──────────────────────────────────────────────────────
|
|
117
|
+
get isConnected() {
|
|
118
|
+
return this.ws?.readyState === WebSocket.OPEN;
|
|
119
|
+
}
|
|
120
|
+
// ── Logging ────────────────────────────────────────────────────
|
|
121
|
+
log(level, msg) {
|
|
122
|
+
const levels = ["debug", "info", "warn", "error"];
|
|
123
|
+
const configIdx = levels.indexOf(this.config.logLevel);
|
|
124
|
+
const msgIdx = levels.indexOf(level);
|
|
125
|
+
if (msgIdx >= configIdx) {
|
|
126
|
+
const ts = new Date().toISOString();
|
|
127
|
+
const prefix = `[${ts}] [CC-Client] [${level.toUpperCase()}]`;
|
|
128
|
+
if (level === "error")
|
|
129
|
+
console.error(`${prefix} ${msg}`);
|
|
130
|
+
else if (level === "warn")
|
|
131
|
+
console.warn(`${prefix} ${msg}`);
|
|
132
|
+
else
|
|
133
|
+
console.log(`${prefix} ${msg}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=command-center-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-center-client.js","sourceRoot":"","sources":["../src/command-center-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAU3C,sEAAsE;AAEtE,MAAM,OAAO,mBAAoB,SAAQ,YAAY;IAC3C,EAAE,GAAqB,IAAI,CAAC;IAC5B,MAAM,CAAe;IACrB,cAAc,GAAG,KAAK,CAAC;IACvB,iBAAiB,GAAG,MAAM,CAAC;IAC3B,cAAc,GAAyC,IAAI,CAAC;IAC5D,eAAe,GAAG,IAAI,CAAC;IACvB,YAAY,GAA0C,IAAI,CAAC;IAEnE,YAAY,MAAoB;QAC9B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,kEAAkE;IAElE,OAAO;QACL,IAAI,IAAI,CAAC,EAAE;YAAE,OAAO;QAEpB,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,gBAAgB,IAAI,CAAC,MAAM,CAAC,UAA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B,CAAC;IAED,kEAAkE;IAElE,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,EAAE,EAAE,UAAU,KAAK,SAAS,CAAC,IAAI,CAAC;IAChD,CAAC;IAED,kEAAkE;IAE1D,GAAG,CAAC,KAAa,EAAE,GAAW;QACpC,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAClD,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACvD,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,MAAM,IAAI,SAAS,EAAE,CAAC;YACxB,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;YACpC,MAAM,MAAM,GAAG,IAAI,EAAE,kBAAkB,KAAK,CAAC,WAAW,EAAE,GAAG,CAAC;YAC9D,IAAI,KAAK,KAAK,OAAO;gBAAE,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC;iBACpD,IAAI,KAAK,KAAK,MAAM;gBAAE,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC;;gBACvD,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;CACF"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daemon configuration — loaded from environment and config file.
|
|
3
|
+
*
|
|
4
|
+
* Priority: CLI flags > env vars > config file > defaults
|
|
5
|
+
*/
|
|
6
|
+
import type { ProtocolType } from "./protocols/index.js";
|
|
7
|
+
export interface DaemonConfig {
|
|
8
|
+
/** Instance UUID assigned by the Command Center */
|
|
9
|
+
instanceId: string;
|
|
10
|
+
/** Persistent API key (oclaw_…) for authenticating with the server */
|
|
11
|
+
apiKey: string;
|
|
12
|
+
/** Command Center WebSocket URL */
|
|
13
|
+
serverUrl: string;
|
|
14
|
+
/** Local OpenClaw Gateway RPC port */
|
|
15
|
+
gatewayPort: number;
|
|
16
|
+
/** Wire protocol for gateway communication.
|
|
17
|
+
* "openclaw" = native OpenClaw frame format (default)
|
|
18
|
+
* "jsonrpc" = standard JSON-RPC 2.0 */
|
|
19
|
+
gatewayProtocol: ProtocolType;
|
|
20
|
+
/** Heartbeat interval in milliseconds */
|
|
21
|
+
heartbeatIntervalMs: number;
|
|
22
|
+
/** Auto-start the OpenClaw Gateway process */
|
|
23
|
+
autoStartGateway: boolean;
|
|
24
|
+
/** Path to the openclaw binary (resolved from $PATH if not set) */
|
|
25
|
+
openclawBin: string | null;
|
|
26
|
+
/** Log level */
|
|
27
|
+
logLevel: "debug" | "info" | "warn" | "error";
|
|
28
|
+
}
|
|
29
|
+
export declare function loadConfig(): DaemonConfig;
|
|
30
|
+
export declare function saveConfig(config: Partial<DaemonConfig>): void;
|
|
31
|
+
export declare function getConfigPath(): string;
|
|
32
|
+
/** LLM configuration pushed from the server (never persisted to disk) */
|
|
33
|
+
export interface LLMConfig {
|
|
34
|
+
provider: string;
|
|
35
|
+
apiKey: string;
|
|
36
|
+
model: string;
|
|
37
|
+
baseUrl?: string;
|
|
38
|
+
temperature?: number;
|
|
39
|
+
maxTokens?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Runtime-only state that is NOT written to the config file.
|
|
43
|
+
* LLM keys live here and are wiped on process exit.
|
|
44
|
+
*/
|
|
45
|
+
export declare const runtimeState: {
|
|
46
|
+
llmConfig: LLMConfig | null;
|
|
47
|
+
gatewayPid: number | null;
|
|
48
|
+
gatewayReady: boolean;
|
|
49
|
+
connected: boolean;
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AASzD,MAAM,WAAW,YAAY;IAC3B,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;IAEnB,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC;IAEf,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAElB,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IAEpB;;6CAEyC;IACzC,eAAe,EAAE,YAAY,CAAC;IAE9B,yCAAyC;IACzC,mBAAmB,EAAE,MAAM,CAAC;IAE5B,8CAA8C;IAC9C,gBAAgB,EAAE,OAAO,CAAC;IAE1B,mEAAmE;IACnE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAE3B,gBAAgB;IAChB,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CAC/C;AAsBD,wBAAgB,UAAU,IAAI,YAAY,CAyBzC;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAY9D;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAID,yEAAyE;AACzE,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY;eACJ,SAAS,GAAG,IAAI;gBACf,MAAM,GAAG,IAAI;;;CAGlC,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daemon configuration — loaded from environment and config file.
|
|
3
|
+
*
|
|
4
|
+
* Priority: CLI flags > env vars > config file > defaults
|
|
5
|
+
*/
|
|
6
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
// ── Paths ──────────────────────────────────────────────────────────
|
|
10
|
+
const CONFIG_DIR = join(homedir(), ".m2f-daemon");
|
|
11
|
+
const CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
12
|
+
const DEFAULTS = {
|
|
13
|
+
instanceId: "",
|
|
14
|
+
apiKey: "",
|
|
15
|
+
serverUrl: "ws://localhost:5100",
|
|
16
|
+
gatewayPort: 18789,
|
|
17
|
+
gatewayProtocol: "openclaw",
|
|
18
|
+
heartbeatIntervalMs: 30_000,
|
|
19
|
+
autoStartGateway: true,
|
|
20
|
+
openclawBin: null,
|
|
21
|
+
logLevel: "info",
|
|
22
|
+
};
|
|
23
|
+
// ── Persistence ────────────────────────────────────────────────────
|
|
24
|
+
function ensureDir() {
|
|
25
|
+
if (!existsSync(CONFIG_DIR)) {
|
|
26
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function loadConfig() {
|
|
30
|
+
const config = { ...DEFAULTS };
|
|
31
|
+
// 1. Config file (lowest priority)
|
|
32
|
+
if (existsSync(CONFIG_FILE)) {
|
|
33
|
+
try {
|
|
34
|
+
const raw = readFileSync(CONFIG_FILE, "utf-8");
|
|
35
|
+
Object.assign(config, JSON.parse(raw));
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Ignore corrupt file
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// 2. Environment variables
|
|
42
|
+
if (process.env.M2F_INSTANCE_ID)
|
|
43
|
+
config.instanceId = process.env.M2F_INSTANCE_ID;
|
|
44
|
+
if (process.env.M2F_API_KEY)
|
|
45
|
+
config.apiKey = process.env.M2F_API_KEY;
|
|
46
|
+
if (process.env.M2F_SERVER_URL)
|
|
47
|
+
config.serverUrl = process.env.M2F_SERVER_URL;
|
|
48
|
+
if (process.env.M2F_GATEWAY_PORT)
|
|
49
|
+
config.gatewayPort = parseInt(process.env.M2F_GATEWAY_PORT, 10);
|
|
50
|
+
if (process.env.M2F_GATEWAY_PROTOCOL)
|
|
51
|
+
config.gatewayProtocol = process.env.M2F_GATEWAY_PROTOCOL;
|
|
52
|
+
if (process.env.M2F_HEARTBEAT_MS)
|
|
53
|
+
config.heartbeatIntervalMs = parseInt(process.env.M2F_HEARTBEAT_MS, 10);
|
|
54
|
+
if (process.env.M2F_AUTO_START_GATEWAY)
|
|
55
|
+
config.autoStartGateway = process.env.M2F_AUTO_START_GATEWAY !== "false";
|
|
56
|
+
if (process.env.M2F_OPENCLAW_BIN)
|
|
57
|
+
config.openclawBin = process.env.M2F_OPENCLAW_BIN;
|
|
58
|
+
if (process.env.M2F_LOG_LEVEL)
|
|
59
|
+
config.logLevel = process.env.M2F_LOG_LEVEL;
|
|
60
|
+
return config;
|
|
61
|
+
}
|
|
62
|
+
export function saveConfig(config) {
|
|
63
|
+
ensureDir();
|
|
64
|
+
let existing = {};
|
|
65
|
+
if (existsSync(CONFIG_FILE)) {
|
|
66
|
+
try {
|
|
67
|
+
existing = JSON.parse(readFileSync(CONFIG_FILE, "utf-8"));
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Start fresh
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const merged = { ...existing, ...config };
|
|
74
|
+
writeFileSync(CONFIG_FILE, JSON.stringify(merged, null, 2), "utf-8");
|
|
75
|
+
}
|
|
76
|
+
export function getConfigPath() {
|
|
77
|
+
return CONFIG_FILE;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Runtime-only state that is NOT written to the config file.
|
|
81
|
+
* LLM keys live here and are wiped on process exit.
|
|
82
|
+
*/
|
|
83
|
+
export const runtimeState = {
|
|
84
|
+
llmConfig: null,
|
|
85
|
+
gatewayPid: null,
|
|
86
|
+
gatewayReady: false,
|
|
87
|
+
connected: false,
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,sEAAsE;AAEtE,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,aAAa,CAAC,CAAC;AAClD,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAmCpD,MAAM,QAAQ,GAAiB;IAC7B,UAAU,EAAE,EAAE;IACd,MAAM,EAAE,EAAE;IACV,SAAS,EAAE,qBAAqB;IAChC,WAAW,EAAE,KAAK;IAClB,eAAe,EAAE,UAAU;IAC3B,mBAAmB,EAAE,MAAM;IAC3B,gBAAgB,EAAE,IAAI;IACtB,WAAW,EAAE,IAAI;IACjB,QAAQ,EAAE,MAAM;CACjB,CAAC;AAEF,sEAAsE;AAEtE,SAAS,SAAS;IAChB,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5B,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,MAAM,MAAM,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;IAE/B,mCAAmC;IACnC,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC5B,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;Y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G,CAAC,aAAyC,CAAC;IAEvG,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAA6B;IACtD,SAAS,EAAE,CAAC;IACZ,IAAI,QAAQ,GAA4B,EAAE,CAAC;IAC3C,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC5B,IAAI,CAAC;YACH,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;QAC5D,CAAC;QAAC,MAAM,CAAC;YACP,cAAc;QAChB,CAAC;IACH,CAAC;IACD,MAAM,MAAM,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,MAAM,EAAE,CAAC;IAC1C,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,WAAW,CAAC;AACrB,CAAC;AAcD;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,SAAS,EAAE,IAAwB;IACnC,UAAU,EAAE,IAAqB;IACjC,YAAY,EAAE,KAAK;IACnB,SAAS,EAAE,KAAK;CACjB,CAAC"}
|
package/dist/daemon.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Mind2Flow OpenClaw Daemon — main entry point.
|
|
4
|
+
*
|
|
5
|
+
* This is the bridge process that runs on the user's machine alongside
|
|
6
|
+
* their local OpenClaw Gateway instance. It:
|
|
7
|
+
*
|
|
8
|
+
* 1. Connects upstream to the Mind2Flow Command Center via WebSocket
|
|
9
|
+
* 2. Starts and manages the local OpenClaw Gateway subprocess
|
|
10
|
+
* 3. Connects locally to the Gateway's WS RPC (port 18789)
|
|
11
|
+
* 4. Bridges commands between Command Center ↔ Gateway
|
|
12
|
+
* 5. Sends periodic heartbeats with system info
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* m2f-daemon # uses config from ~/.m2f-daemon/config.json
|
|
16
|
+
* m2f-daemon --token <install_token> # first-time registration
|
|
17
|
+
*
|
|
18
|
+
* Environment variables: see config.ts for M2F_* variables.
|
|
19
|
+
*/
|
|
20
|
+
import "dotenv/config";
|
|
21
|
+
//# sourceMappingURL=daemon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daemon.d.ts","sourceRoot":"","sources":["../src/daemon.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,eAAe,CAAC"}
|