bambu-printer-mcp 1.1.66 → 1.1.68
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/README.md +40 -5
- package/dist/bambu-network-bridge.d.ts +51 -1
- package/dist/bambu-network-bridge.js +230 -20
- package/dist/counterpart/remote.js +4 -0
- package/dist/counterpart/setup.d.ts +2 -2
- package/dist/design-app-setup.d.ts +384 -0
- package/dist/design-app-setup.js +654 -0
- package/dist/design-guidance.d.ts +14 -0
- package/dist/design-guidance.js +27 -1
- package/dist/fusion-mcp-bridge.d.ts +11 -2
- package/dist/fusion-mcp-bridge.js +9 -4
- package/dist/index.js +58 -6
- package/dist/safety/artifact.d.ts +5 -2
- package/dist/safety/artifact.js +6 -3
- package/dist/tool-annotations.js +4 -0
- package/package.json +1 -1
- package/src/bambu-network-bridge.ts +227 -24
- package/src/counterpart/remote.ts +4 -0
- package/src/design-app-setup.ts +640 -0
- package/src/design-guidance.ts +30 -1
- package/src/fusion-mcp-bridge.ts +9 -4
- package/src/index.ts +58 -6
- package/src/safety/artifact.ts +6 -3
- package/src/tool-annotations.ts +4 -0
package/README.md
CHANGED
|
@@ -1254,6 +1254,18 @@ Blender. Set the command to your full `uvx` path and the argument array to
|
|
|
1254
1254
|
`["blender-mcp"]`. The Claude Desktop extension also offers these two optional
|
|
1255
1255
|
settings. Printer tools work without Blender configured.
|
|
1256
1256
|
|
|
1257
|
+
`blender_mcp_setup` checks the MCP for Blender add-on that the configured
|
|
1258
|
+
package needs, when the bridge is that package run with `uvx`: which add-on file
|
|
1259
|
+
Blender loads (for the running Blender's version), its protocol and the one the
|
|
1260
|
+
package expects, whether Blender is listening, and the running add-on's own
|
|
1261
|
+
`get_addon_status`. It changes nothing. With `{"update": true}` it stages the
|
|
1262
|
+
add-on with the package's own installer (`mcp-for-blender install-addon`) at the
|
|
1263
|
+
inspected version, checks that the installed and staged files are both regular
|
|
1264
|
+
MCP for Blender add-ons and that the staged one carries the expected protocol,
|
|
1265
|
+
keeps the old file as a backup next to it, and renames the new one into place.
|
|
1266
|
+
It never starts, stops or edits Blender: re-enable the add-on or restart Blender
|
|
1267
|
+
to load it. Another bridge reports `supported: false` and keeps its own installer.
|
|
1268
|
+
|
|
1257
1269
|
1. Call `blender_mcp_status` with `{"connect": true}` to initialize the server
|
|
1258
1270
|
and discover its tools and input schemas. A connected MCP server does not
|
|
1259
1271
|
by itself prove that the Blender addon is running.
|
|
@@ -1318,14 +1330,36 @@ Design a part from scratch in Autodesk Fusion through
|
|
|
1318
1330
|
free personal-use licence, are yours: this server never installs or requires
|
|
1319
1331
|
Fusion, and printer tools work without it.
|
|
1320
1332
|
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1333
|
+
The bridge and its setup pin [DMontgomery40/fusion360-mcp-server](https://github.com/DMontgomery40/fusion360-mcp-server) at commit
|
|
1334
|
+
`86a3016a5a5b`: faust-machines' server and add-in with document binding, which
|
|
1335
|
+
`fusion_mcp_new_design`'s `bind_document` needs, while that change is reviewed
|
|
1336
|
+
upstream.
|
|
1337
|
+
|
|
1338
|
+
On macOS, `fusion_mcp_setup` sets it up. Without arguments it reports, changing
|
|
1339
|
+
nothing: whether Fusion is installed, whether the add-in in
|
|
1340
|
+
`~/Library/Application Support/Autodesk/Autodesk Fusion 360/API/AddIns/Fusion360MCP`
|
|
1341
|
+
is at the pin and runs on startup, whether the login item that gives Fusion
|
|
1342
|
+
`FUSION_MCP_PORT` is installed, and whether this server has its Fusion settings.
|
|
1343
|
+
With `{"install": true}` it installs what is missing:
|
|
1344
|
+
|
|
1345
|
+
- the add-in from the pinned commit's archive, after checking every file against
|
|
1346
|
+
its SHA-256 (a symlink, an extra file or a changed byte installs nothing), set
|
|
1347
|
+
to **Run on Startup**. An add-in already at the pin is left in place;
|
|
1348
|
+
- a login LaunchAgent, `com.scantomake.mac.fusion-port`, that runs
|
|
1349
|
+
`launchctl setenv FUSION_MCP_PORT 9877` at login, because Fusion opened from the
|
|
1350
|
+
Dock never reads this server's env file;
|
|
1351
|
+
- the settings this server is missing, added to its own `.env` after a copy of
|
|
1352
|
+
the file. A configured `FUSION_MCP_COMMAND` is kept with its arguments, so a
|
|
1353
|
+
reviewed local runtime isn't replaced. The running server uses them at once.
|
|
1354
|
+
|
|
1355
|
+
It never starts or quits Fusion; `fusion_mcp_status` checks the connection. On
|
|
1356
|
+
other systems, or by hand: copy the repository's `addon/` folder at that commit
|
|
1357
|
+
to the AddIns folder above, set it to **Run on Startup**, and add these settings
|
|
1358
|
+
next to the Blender ones in your env file:
|
|
1325
1359
|
|
|
1326
1360
|
```bash
|
|
1327
1361
|
FUSION_MCP_COMMAND=uvx
|
|
1328
|
-
FUSION_MCP_ARGS='["--from","git+https://github.com/
|
|
1362
|
+
FUSION_MCP_ARGS='["--from","git+https://github.com/DMontgomery40/fusion360-mcp-server@86a3016a5a5b","fusion360-mcp-server","--mode","socket"]'
|
|
1329
1363
|
FUSION_MCP_TIMEOUT_MS=180000
|
|
1330
1364
|
FUSION_MCP_HOST=localhost
|
|
1331
1365
|
# The default here; Blender's MCP add-on holds the add-in's own default, 9876.
|
|
@@ -1423,6 +1457,7 @@ The server carries manufacturing judgment for agents that design or edit a model
|
|
|
1423
1457
|
- `fdm_multicolor` -- when several colours or support materials share a print: filament transitions across layers, colour placement, plate scheduling and flushing.
|
|
1424
1458
|
- `fdm_assembly` -- when a split, accent insert or joint could materially improve the result.
|
|
1425
1459
|
- `fdm_after_slice` -- a separate review turn after `slice_stl`, before presenting the manufacturing recommendation: keep, revise, or validate one specific uncertainty, using the returned `slicer_result`.
|
|
1460
|
+
- `fdm_slicing` -- for every design or model-editing task, next to `fdm_design`: how this server's configured slicer (`SLICER_TYPE`) orients a model and generates supports, and how to check a choice with a checkpoint `slice_stl`. Its text follows the slicer: Bambu Studio's auto-orient and `enable_support`, or plainly that a slicer here doesn't orient or take support settings.
|
|
1426
1461
|
- `guidance://fdm/capability-guidance` (resource) -- planning bands and sources for bridges and overhangs, for when one is consequential and there is no sufficiently specific measured capability for the printer, material and profile.
|
|
1427
1462
|
|
|
1428
1463
|
mcp-3D-printer-server serves the same guidance.
|
|
@@ -106,6 +106,50 @@ export type BambuNetworkBridgeStatus = {
|
|
|
106
106
|
export declare function bambuNetworkCertDir(configDir: string, env?: NodeJS.ProcessEnv): string;
|
|
107
107
|
export declare function prepareBambuNetworkCertDir(configDir: string, env?: NodeJS.ProcessEnv): string;
|
|
108
108
|
export declare function defaultBambuNetworkConfigDir(): string;
|
|
109
|
+
/**
|
|
110
|
+
* FULU's Linux host run in a Docker image (BAMBU_NETWORK_BRIDGE_IMAGE), for a Mac or any machine without the
|
|
111
|
+
* x86-64 Linux runtime installed natively. The image holds FULU's host runtime in /fulu (pjarczak_bambu_linux_host
|
|
112
|
+
* and ca-certificates.crt) and the networking plug-in in /plugins (libbambu_networking.so, libBambuSource.so).
|
|
113
|
+
*/
|
|
114
|
+
export type BridgeContainer = {
|
|
115
|
+
image: string;
|
|
116
|
+
docker: string;
|
|
117
|
+
dockerHost?: string;
|
|
118
|
+
/** A Colima profile started (never stopped or restarted) when Docker doesn't answer. */
|
|
119
|
+
colima?: {
|
|
120
|
+
executable: string;
|
|
121
|
+
profile: string;
|
|
122
|
+
home?: string;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
export declare function bridgeContainer(env?: NodeJS.ProcessEnv): BridgeContainer | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Where a print's checked snapshot is written when the host runs in the Docker image: inside the agent's config
|
|
128
|
+
* folder, which the container mounts. The system temporary folder is no good there: Colima shares the home
|
|
129
|
+
* folder but not /tmp or /var/folders, so the host would see an empty folder. Undefined without the image.
|
|
130
|
+
*/
|
|
131
|
+
export declare function bridgeSnapshotRoot(env?: NodeJS.ProcessEnv): string | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* The folders the host must see at the same absolute paths: the agent's config folder (the plug-in writes its
|
|
134
|
+
* logs and session there; a host given a log_dir it can't open aborts, FULU #54), the folder print snapshots are
|
|
135
|
+
* written to, and the certificate folder.
|
|
136
|
+
*/
|
|
137
|
+
export declare function bridgeContainerMounts(configDir: string, env?: NodeJS.ProcessEnv): string[];
|
|
138
|
+
/**
|
|
139
|
+
* docker run for the host: stdin/stdout are the bridge's framed protocol; the host is piped through cat (FULU #50).
|
|
140
|
+
* `--init` puts an init process first, so the SIGTERM docker forwards on stop reaches the host: a shell as the
|
|
141
|
+
* container's first process ignores it, and the container kept running after the server stopped. `name` lets stop
|
|
142
|
+
* remove the container even when the docker client was killed.
|
|
143
|
+
*/
|
|
144
|
+
export declare function bridgeContainerArgs(container: BridgeContainer, mounts: string[], name?: string): string[];
|
|
145
|
+
/**
|
|
146
|
+
* Docker must answer before the host starts. When it doesn't and a Colima profile is configured, that profile is
|
|
147
|
+
* started without changing Docker's global context; a running profile is never stopped or restarted.
|
|
148
|
+
*/
|
|
149
|
+
export declare function ensureBridgeContainerRuntime(container: BridgeContainer, timeouts?: {
|
|
150
|
+
infoMs: number;
|
|
151
|
+
startMs: number;
|
|
152
|
+
}): Promise<void>;
|
|
109
153
|
/**
|
|
110
154
|
* The client identity FULU's GUI gives the plug-in before agent start
|
|
111
155
|
* (GUI_App::init_http_extra_header). Through the Linux bridge FULU presents
|
|
@@ -127,6 +171,9 @@ export declare function linuxPluginLibraryEnv(env: NodeJS.ProcessEnv, platform:
|
|
|
127
171
|
export declare class BambuNetworkBridge {
|
|
128
172
|
private child?;
|
|
129
173
|
private commandLine?;
|
|
174
|
+
/** This bridge's own container, when the host runs in the Docker image: unique, so two servers never remove each other's. */
|
|
175
|
+
private readonly containerName;
|
|
176
|
+
private runningContainer?;
|
|
130
177
|
private stdoutBuffer;
|
|
131
178
|
private pending;
|
|
132
179
|
private nextRequestId;
|
|
@@ -143,7 +190,7 @@ export declare class BambuNetworkBridge {
|
|
|
143
190
|
* so LAN sessions run one at a time, as Bambu Studio connects one printer.
|
|
144
191
|
*/
|
|
145
192
|
private localSessionTail;
|
|
146
|
-
resolveBridgeCommand(override?: string): string;
|
|
193
|
+
resolveBridgeCommand(override?: string, configDir?: string): string;
|
|
147
194
|
resolveConfigDir(override?: string): string;
|
|
148
195
|
resolveCountryCode(override?: string): string;
|
|
149
196
|
getStatus(options?: BambuNetworkBridgeOptions): BambuNetworkBridgeStatus;
|
|
@@ -214,7 +261,10 @@ export declare class BambuNetworkBridge {
|
|
|
214
261
|
private controlTrace;
|
|
215
262
|
callWithAgent(method: string, payload?: JsonObject, options?: BambuNetworkBridgeOptions): Promise<unknown>;
|
|
216
263
|
stop(): Promise<void>;
|
|
264
|
+
/** A start in progress: concurrent callers wait for it, so a cold Docker host is started (and named) once. */
|
|
265
|
+
private starting?;
|
|
217
266
|
private ensureStarted;
|
|
267
|
+
private startBridge;
|
|
218
268
|
private handleStdout;
|
|
219
269
|
private resolvePendingJson;
|
|
220
270
|
private rememberLog;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
1
|
+
import { execFile, spawn } from "node:child_process";
|
|
2
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import os from "node:os";
|
|
@@ -65,7 +65,8 @@ const nextControlSequence = () => String(controlSequence = controlSequence >= 29
|
|
|
65
65
|
* which the host must already be able to read.
|
|
66
66
|
*/
|
|
67
67
|
export function bambuNetworkCertDir(configDir, env = process.env) {
|
|
68
|
-
|
|
68
|
+
// Absolute, as every folder given to the host is: a containerized host runs from /plugins, not this server's folder.
|
|
69
|
+
return path.resolve(trimEnv(env.BAMBU_NETWORK_CERT_DIR) || path.join(configDir, "cert"));
|
|
69
70
|
}
|
|
70
71
|
export function prepareBambuNetworkCertDir(configDir, env = process.env) {
|
|
71
72
|
const certDir = bambuNetworkCertDir(configDir, env);
|
|
@@ -88,6 +89,176 @@ export function defaultBambuNetworkConfigDir() {
|
|
|
88
89
|
function shellQuote(value) {
|
|
89
90
|
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
90
91
|
}
|
|
92
|
+
export function bridgeContainer(env = process.env) {
|
|
93
|
+
const image = trimEnv(env.BAMBU_NETWORK_BRIDGE_IMAGE);
|
|
94
|
+
if (!image)
|
|
95
|
+
return undefined;
|
|
96
|
+
const dockerHost = trimEnv(env.BAMBU_NETWORK_BRIDGE_DOCKER_HOST);
|
|
97
|
+
const profile = trimEnv(env.BAMBU_NETWORK_BRIDGE_COLIMA_PROFILE);
|
|
98
|
+
const home = trimEnv(env.BAMBU_NETWORK_BRIDGE_COLIMA_HOME);
|
|
99
|
+
// A Colima profile started with --activate=false leaves Docker's default context alone, so without an explicit
|
|
100
|
+
// host the server talks to that profile's own socket.
|
|
101
|
+
const colimaHome = home || path.join(os.homedir(), ".colima");
|
|
102
|
+
const host = dockerHost || (profile ? `unix://${path.join(colimaHome, profile, "docker.sock")}` : undefined);
|
|
103
|
+
return {
|
|
104
|
+
image,
|
|
105
|
+
docker: trimEnv(env.BAMBU_NETWORK_BRIDGE_DOCKER) || "docker",
|
|
106
|
+
...(host ? { dockerHost: host } : {}),
|
|
107
|
+
...(profile ? { colima: { executable: trimEnv(env.BAMBU_NETWORK_BRIDGE_COLIMA) || "colima", profile, ...(home ? { home } : {}) } } : {}),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** `--host <socket>` for every docker call, when a host is set. */
|
|
111
|
+
function dockerHostArgs(container) {
|
|
112
|
+
return container.dockerHost ? ["--host", container.dockerHost] : [];
|
|
113
|
+
}
|
|
114
|
+
/** The image's fixed layout: FULU's runtime and the networking plug-in, with the CA bundle cloud calls need. */
|
|
115
|
+
const CONTAINER_ENV = [
|
|
116
|
+
"LD_LIBRARY_PATH=/plugins:/fulu",
|
|
117
|
+
"SSL_CERT_FILE=/fulu/ca-certificates.crt",
|
|
118
|
+
"CURL_CA_BUNDLE=/fulu/ca-certificates.crt",
|
|
119
|
+
"SSL_CERT_DIR=/etc/ssl/certs",
|
|
120
|
+
"PJARCZAK_BAMBU_PLUGIN_DIR=/plugins",
|
|
121
|
+
"PJARCZAK_BAMBU_NETWORK_SO=/plugins/libbambu_networking.so",
|
|
122
|
+
"PJARCZAK_BAMBU_SOURCE_SO=/plugins/libBambuSource.so",
|
|
123
|
+
];
|
|
124
|
+
/** Set by the server for the host (country, expected network version): passed into the container from its env. */
|
|
125
|
+
const CONTAINER_PASSED_ENV = ["PJARCZAK_BAMBU_COUNTRY_CODE", "PJARCZAK_EXPECTED_BAMBU_NETWORK_VERSION"];
|
|
126
|
+
/** The explicit host command, when one is set: it wins over the Docker image. */
|
|
127
|
+
function explicitBridgeCommand(env = process.env) {
|
|
128
|
+
return trimEnv(env.BAMBU_NETWORK_BRIDGE_COMMAND) || trimEnv(env.FULU_BAMBU_NETWORK_BRIDGE_COMMAND) || trimEnv(env.PJARCZAK_BAMBU_BRIDGE_COMMAND);
|
|
129
|
+
}
|
|
130
|
+
function configuredBridgeConfigDir(env = process.env) {
|
|
131
|
+
return path.resolve(trimEnv(env.BAMBU_NETWORK_CONFIG_DIR) || trimEnv(env.PJARCZAK_BAMBU_PROBE_LOG_DIR) || defaultBambuNetworkConfigDir());
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Where a print's checked snapshot is written when the host runs in the Docker image: inside the agent's config
|
|
135
|
+
* folder, which the container mounts. The system temporary folder is no good there: Colima shares the home
|
|
136
|
+
* folder but not /tmp or /var/folders, so the host would see an empty folder. Undefined without the image.
|
|
137
|
+
*/
|
|
138
|
+
export function bridgeSnapshotRoot(env = process.env) {
|
|
139
|
+
if (explicitBridgeCommand(env) || !bridgeContainer(env))
|
|
140
|
+
return undefined;
|
|
141
|
+
const root = path.join(configuredBridgeConfigDir(env), "print-snapshots");
|
|
142
|
+
fs.mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
143
|
+
clearStaleSnapshots(root);
|
|
144
|
+
return root;
|
|
145
|
+
}
|
|
146
|
+
const STALE_SNAPSHOT_MS = 24 * 60 * 60 * 1000;
|
|
147
|
+
const clearedSnapshotRoots = new Set();
|
|
148
|
+
/**
|
|
149
|
+
* A snapshot kept for an upload still running is removed when the server exits; one a killed server left stays
|
|
150
|
+
* here, where no system cleanup reaches it. Once per server, snapshots older than a day are removed.
|
|
151
|
+
*/
|
|
152
|
+
function clearStaleSnapshots(root, now = Date.now()) {
|
|
153
|
+
if (clearedSnapshotRoots.has(root))
|
|
154
|
+
return;
|
|
155
|
+
clearedSnapshotRoots.add(root);
|
|
156
|
+
for (const name of fs.readdirSync(root)) {
|
|
157
|
+
if (!name.startsWith("bambu-print-"))
|
|
158
|
+
continue;
|
|
159
|
+
const dir = path.join(root, name);
|
|
160
|
+
try {
|
|
161
|
+
if (now - fs.statSync(dir).mtimeMs > STALE_SNAPSHOT_MS)
|
|
162
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
163
|
+
}
|
|
164
|
+
catch { /* gone already */ }
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The folders the host must see at the same absolute paths: the agent's config folder (the plug-in writes its
|
|
169
|
+
* logs and session there; a host given a log_dir it can't open aborts, FULU #54), the folder print snapshots are
|
|
170
|
+
* written to, and the certificate folder.
|
|
171
|
+
*/
|
|
172
|
+
export function bridgeContainerMounts(configDir, env = process.env) {
|
|
173
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
174
|
+
const folders = [path.resolve(configDir)];
|
|
175
|
+
const snapshots = bridgeSnapshotRoot(env);
|
|
176
|
+
if (snapshots)
|
|
177
|
+
folders.push(path.resolve(snapshots));
|
|
178
|
+
const certDir = trimEnv(env.BAMBU_NETWORK_CERT_DIR);
|
|
179
|
+
if (certDir) {
|
|
180
|
+
// Made here, so Docker doesn't create it (as root, inside the VM) for the mount.
|
|
181
|
+
fs.mkdirSync(certDir, { recursive: true });
|
|
182
|
+
folders.push(path.resolve(certDir));
|
|
183
|
+
}
|
|
184
|
+
const unique = [...new Set(folders)].filter((dir, _i, all) => !all.some(other => other !== dir && dir.startsWith(other + path.sep)));
|
|
185
|
+
// The host is given these paths as written, so each is mounted there; the VM reads the folder it really is
|
|
186
|
+
// (a symlinked folder's link target need not be shared with the VM).
|
|
187
|
+
return unique.map(dir => {
|
|
188
|
+
let real = dir;
|
|
189
|
+
try {
|
|
190
|
+
real = fs.realpathSync(dir);
|
|
191
|
+
}
|
|
192
|
+
catch { /* created later by the host */ }
|
|
193
|
+
if (dir.includes(":") || real.includes(":"))
|
|
194
|
+
throw new Error(`The FULU container can't mount ${dir}: Docker volume paths can't contain ':'. Move that folder.`);
|
|
195
|
+
return `${real}:${dir}`;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* docker run for the host: stdin/stdout are the bridge's framed protocol; the host is piped through cat (FULU #50).
|
|
200
|
+
* `--init` puts an init process first, so the SIGTERM docker forwards on stop reaches the host: a shell as the
|
|
201
|
+
* container's first process ignores it, and the container kept running after the server stopped. `name` lets stop
|
|
202
|
+
* remove the container even when the docker client was killed.
|
|
203
|
+
*/
|
|
204
|
+
export function bridgeContainerArgs(container, mounts, name) {
|
|
205
|
+
return [
|
|
206
|
+
...dockerHostArgs(container),
|
|
207
|
+
"run", "--rm", "-i", "--init", ...(name ? ["--name", name] : []),
|
|
208
|
+
"--platform", "linux/amd64", "--network", "host", "--log-driver=none", "--workdir", "/plugins",
|
|
209
|
+
...mounts.flatMap(mount => ["-v", `${mount}:rw`]),
|
|
210
|
+
...CONTAINER_ENV.flatMap(value => ["-e", value]),
|
|
211
|
+
...CONTAINER_PASSED_ENV.flatMap(name => ["-e", name]),
|
|
212
|
+
container.image,
|
|
213
|
+
"/bin/sh", "-c", "/fulu/pjarczak_bambu_linux_host | cat",
|
|
214
|
+
];
|
|
215
|
+
}
|
|
216
|
+
const runQuietly = (file, args, options) => new Promise((resolve, reject) => {
|
|
217
|
+
execFile(file, args, { env: options.env ?? process.env, timeout: options.timeout, maxBuffer: 1024 * 1024 }, (error, _stdout, stderr) => {
|
|
218
|
+
if (error)
|
|
219
|
+
reject(Object.assign(error, { stderr: String(stderr ?? "") }));
|
|
220
|
+
else
|
|
221
|
+
resolve();
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
/**
|
|
225
|
+
* Docker must answer before the host starts. When it doesn't and a Colima profile is configured, that profile is
|
|
226
|
+
* started without changing Docker's global context; a running profile is never stopped or restarted.
|
|
227
|
+
*/
|
|
228
|
+
export async function ensureBridgeContainerRuntime(container, timeouts = { infoMs: 20000, startMs: 600000 }) {
|
|
229
|
+
const info = () => runQuietly(container.docker, [...dockerHostArgs(container), "info"], { timeout: timeouts.infoMs });
|
|
230
|
+
try {
|
|
231
|
+
await info();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
if (!container.colima) {
|
|
236
|
+
throw new Error(`Docker didn't answer (${container.docker}${container.dockerHost ? ` --host ${container.dockerHost}` : ""} info), so the FULU container can't start. Start Docker, or set BAMBU_NETWORK_BRIDGE_COLIMA_PROFILE.`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const { executable, profile, home } = container.colima;
|
|
240
|
+
try {
|
|
241
|
+
await runQuietly(executable, ["start", "--profile", profile, "--activate=false"], { env: { ...process.env, ...(home ? { COLIMA_HOME: home } : {}) }, timeout: timeouts.startMs });
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
const detail = String(error.stderr ?? "").trim().split("\n").slice(-3).join(" ");
|
|
245
|
+
throw new Error(`Colima profile ${profile} didn't start for the FULU container${detail ? `: ${detail}` : "."}`);
|
|
246
|
+
}
|
|
247
|
+
try {
|
|
248
|
+
await info();
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
throw new Error(`Colima profile ${profile} started, but Docker still doesn't answer at ${container.dockerHost ?? "its default host"}.`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Stops the bridge's own named container (SIGTERM to the host through --init, two seconds to exit), then removes
|
|
256
|
+
* it. A container that is already gone is fine.
|
|
257
|
+
*/
|
|
258
|
+
async function removeBridgeContainer(container, name) {
|
|
259
|
+
await runQuietly(container.docker, [...dockerHostArgs(container), "stop", "--time", "2", name], { timeout: 20000 }).catch(() => undefined);
|
|
260
|
+
await runQuietly(container.docker, [...dockerHostArgs(container), "rm", "-f", name], { timeout: 20000 }).catch(() => undefined);
|
|
261
|
+
}
|
|
91
262
|
function trimEnv(value) {
|
|
92
263
|
const trimmed = value?.trim();
|
|
93
264
|
return trimmed ? trimmed : undefined;
|
|
@@ -246,6 +417,8 @@ function assertBridgeOk(value, method) {
|
|
|
246
417
|
}
|
|
247
418
|
export class BambuNetworkBridge {
|
|
248
419
|
constructor() {
|
|
420
|
+
/** This bridge's own container, when the host runs in the Docker image: unique, so two servers never remove each other's. */
|
|
421
|
+
this.containerName = `bambu-fulu-host-${process.pid}-${randomUUID().slice(0, 8)}`;
|
|
249
422
|
this.stdoutBuffer = Buffer.alloc(0);
|
|
250
423
|
this.pending = new Map();
|
|
251
424
|
this.nextRequestId = 1;
|
|
@@ -259,18 +432,19 @@ export class BambuNetworkBridge {
|
|
|
259
432
|
*/
|
|
260
433
|
this.localSessionTail = Promise.resolve();
|
|
261
434
|
}
|
|
262
|
-
resolveBridgeCommand(override) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
435
|
+
resolveBridgeCommand(override, configDir) {
|
|
436
|
+
const explicit = trimEnv(override) || explicitBridgeCommand();
|
|
437
|
+
if (explicit)
|
|
438
|
+
return explicit;
|
|
439
|
+
const container = bridgeContainer();
|
|
440
|
+
if (!container)
|
|
441
|
+
return "";
|
|
442
|
+
const mounts = bridgeContainerMounts(this.resolveConfigDir(configDir));
|
|
443
|
+
return [container.docker, ...bridgeContainerArgs(container, mounts, this.containerName)].map(shellQuote).join(" ");
|
|
268
444
|
}
|
|
269
445
|
resolveConfigDir(override) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
trimEnv(process.env.PJARCZAK_BAMBU_PROBE_LOG_DIR) ||
|
|
273
|
-
defaultBambuNetworkConfigDir());
|
|
446
|
+
const dir = trimEnv(override);
|
|
447
|
+
return dir ? path.resolve(dir) : configuredBridgeConfigDir();
|
|
274
448
|
}
|
|
275
449
|
resolveCountryCode(override) {
|
|
276
450
|
return (trimEnv(override) ||
|
|
@@ -279,7 +453,7 @@ export class BambuNetworkBridge {
|
|
|
279
453
|
"US");
|
|
280
454
|
}
|
|
281
455
|
getStatus(options = {}) {
|
|
282
|
-
const command = this.resolveBridgeCommand(options.bridgeCommand);
|
|
456
|
+
const command = this.resolveBridgeCommand(options.bridgeCommand, options.configDir);
|
|
283
457
|
const configDir = this.resolveConfigDir(options.configDir);
|
|
284
458
|
const countryCode = this.resolveCountryCode(options.countryCode);
|
|
285
459
|
const runtime = { certDir: bambuNetworkCertDir(configDir) };
|
|
@@ -310,14 +484,14 @@ export class BambuNetworkBridge {
|
|
|
310
484
|
runtime,
|
|
311
485
|
note: command
|
|
312
486
|
? undefined
|
|
313
|
-
: "Set BAMBU_NETWORK_BRIDGE_COMMAND to the FULU OrcaSlicer-bambulab Linux host or macOS/WSL wrapper command.",
|
|
487
|
+
: "Set BAMBU_NETWORK_BRIDGE_COMMAND to the FULU OrcaSlicer-bambulab Linux host or macOS/WSL wrapper command, or BAMBU_NETWORK_BRIDGE_IMAGE to a Docker image holding FULU's Linux host.",
|
|
314
488
|
};
|
|
315
489
|
}
|
|
316
490
|
async request(method, payload = {}, options = {}) {
|
|
317
491
|
if (!method.trim()) {
|
|
318
492
|
throw new Error("BambuNetwork bridge method is required.");
|
|
319
493
|
}
|
|
320
|
-
await this.ensureStarted(options.bridgeCommand);
|
|
494
|
+
await this.ensureStarted(options.bridgeCommand, options.configDir);
|
|
321
495
|
await options.beforeDispatch?.(method);
|
|
322
496
|
const id = this.nextRequestId++;
|
|
323
497
|
const requestPayload = Buffer.from(JSON.stringify({ method, payload }), "utf8");
|
|
@@ -355,7 +529,7 @@ export class BambuNetworkBridge {
|
|
|
355
529
|
});
|
|
356
530
|
}
|
|
357
531
|
async ensureAgent(options = {}) {
|
|
358
|
-
const command = this.resolveBridgeCommand(options.bridgeCommand);
|
|
532
|
+
const command = this.resolveBridgeCommand(options.bridgeCommand, options.configDir);
|
|
359
533
|
const configDir = this.resolveConfigDir(options.configDir);
|
|
360
534
|
const countryCode = this.resolveCountryCode(options.countryCode);
|
|
361
535
|
const userInfo = trimEnv(options.userInfo) || trimEnv(process.env.BAMBU_NETWORK_USER_INFO) || "";
|
|
@@ -787,6 +961,8 @@ export class BambuNetworkBridge {
|
|
|
787
961
|
}
|
|
788
962
|
async stop() {
|
|
789
963
|
const child = this.child;
|
|
964
|
+
const running = this.runningContainer;
|
|
965
|
+
this.runningContainer = undefined;
|
|
790
966
|
this.child = undefined;
|
|
791
967
|
this.commandLine = undefined;
|
|
792
968
|
this.agentId = undefined;
|
|
@@ -798,26 +974,53 @@ export class BambuNetworkBridge {
|
|
|
798
974
|
pending.reject(new Error(`FULU BambuNetwork bridge stopped before ${pending.method} completed.`));
|
|
799
975
|
this.pending.delete(id);
|
|
800
976
|
}
|
|
977
|
+
// The container goes first: a shell that keeps the docker client as its own child holds the pipes open until
|
|
978
|
+
// the client exits, so waiting for the shell before removing the container could wait for ever.
|
|
979
|
+
if (running)
|
|
980
|
+
await removeBridgeContainer(running, this.containerName);
|
|
801
981
|
if (child && child.exitCode === null) {
|
|
802
982
|
await new Promise((resolve) => {
|
|
983
|
+
let settleTimer;
|
|
803
984
|
const forceTimer = setTimeout(() => {
|
|
804
985
|
if (child.exitCode === null) {
|
|
805
986
|
child.kill("SIGKILL");
|
|
806
987
|
}
|
|
988
|
+
// A descendant can still hold the pipes after the shell is killed: stop waiting for it, and let go of
|
|
989
|
+
// those pipes so nothing it writes reaches a bridge started after this one.
|
|
990
|
+
settleTimer = setTimeout(() => {
|
|
991
|
+
for (const stream of [child.stdin, child.stdout, child.stderr])
|
|
992
|
+
stream.destroy();
|
|
993
|
+
resolve();
|
|
994
|
+
}, 2000);
|
|
807
995
|
}, 2000);
|
|
808
996
|
child.once("close", () => {
|
|
809
997
|
clearTimeout(forceTimer);
|
|
998
|
+
if (settleTimer)
|
|
999
|
+
clearTimeout(settleTimer);
|
|
810
1000
|
resolve();
|
|
811
1001
|
});
|
|
812
1002
|
child.kill("SIGTERM");
|
|
813
1003
|
});
|
|
814
1004
|
}
|
|
815
1005
|
}
|
|
816
|
-
async ensureStarted(commandOverride) {
|
|
817
|
-
|
|
1006
|
+
async ensureStarted(commandOverride, configDir) {
|
|
1007
|
+
while (this.starting)
|
|
1008
|
+
await this.starting.catch(() => undefined);
|
|
1009
|
+
const start = this.startBridge(commandOverride, configDir);
|
|
1010
|
+
this.starting = start;
|
|
1011
|
+
try {
|
|
1012
|
+
await start;
|
|
1013
|
+
}
|
|
1014
|
+
finally {
|
|
1015
|
+
if (this.starting === start)
|
|
1016
|
+
this.starting = undefined;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
async startBridge(commandOverride, configDir) {
|
|
1020
|
+
const command = this.resolveBridgeCommand(commandOverride, configDir);
|
|
818
1021
|
if (!command) {
|
|
819
|
-
throw new Error("BAMBU_NETWORK_BRIDGE_COMMAND is required for FULU BambuNetwork support. " +
|
|
820
|
-
"Point
|
|
1022
|
+
throw new Error("BAMBU_NETWORK_BRIDGE_COMMAND or BAMBU_NETWORK_BRIDGE_IMAGE is required for FULU BambuNetwork support. " +
|
|
1023
|
+
"Point the command at pjarczak_bambu_linux_host or the OrcaSlicer-bambulab macOS/WSL wrapper, or name a Docker image holding FULU's Linux host.");
|
|
821
1024
|
}
|
|
822
1025
|
if (this.child && this.child.exitCode === null && this.commandLine === command) {
|
|
823
1026
|
return;
|
|
@@ -825,6 +1028,13 @@ export class BambuNetworkBridge {
|
|
|
825
1028
|
if (this.child && this.commandLine !== command) {
|
|
826
1029
|
await this.stop();
|
|
827
1030
|
}
|
|
1031
|
+
const container = trimEnv(commandOverride) || explicitBridgeCommand() ? undefined : bridgeContainer();
|
|
1032
|
+
if (container) {
|
|
1033
|
+
await ensureBridgeContainerRuntime(container);
|
|
1034
|
+
// The docker client can exit (a dropped socket) while its container keeps running under this bridge's name.
|
|
1035
|
+
await removeBridgeContainer(container, this.containerName);
|
|
1036
|
+
this.runningContainer = container;
|
|
1037
|
+
}
|
|
828
1038
|
const shell = process.platform === "win32" ? process.env.ComSpec || "cmd.exe" : "/bin/sh";
|
|
829
1039
|
const shellArgs = process.platform === "win32"
|
|
830
1040
|
? ["/d", "/s", "/c", command]
|
|
@@ -18,6 +18,8 @@ export const REMOTE_SCOPES = {
|
|
|
18
18
|
counterpart_printer_info: "read",
|
|
19
19
|
counterpart_print_progress: "read",
|
|
20
20
|
fusion_mcp_status: "read",
|
|
21
|
+
blender_mcp_setup: "read", // checks only; update raises it
|
|
22
|
+
fusion_mcp_setup: "read", // checks only; install raises it
|
|
21
23
|
// design
|
|
22
24
|
slice_stl: "design",
|
|
23
25
|
lay_flat: "design",
|
|
@@ -69,6 +71,8 @@ export const REMOTE_SCOPES = {
|
|
|
69
71
|
const RAISED_BY = {
|
|
70
72
|
fusion_mcp_status: { launch: "design" }, // starts Fusion on this computer
|
|
71
73
|
blender_mcp_status: { connect: "design" }, // connects to Blender
|
|
74
|
+
blender_mcp_setup: { update: "raw" }, // replaces the add-on in the person's Blender
|
|
75
|
+
fusion_mcp_setup: { install: "raw" }, // installs into the person's Fusion, a login item and this server's .env
|
|
72
76
|
};
|
|
73
77
|
/**
|
|
74
78
|
* Overrides of a server's own configuration (both printer MCPs use the same names): the printer it targets, its
|
|
@@ -126,7 +126,7 @@ export declare const SETUP_FIELDS_OUTPUT_SCHEMA: {
|
|
|
126
126
|
properties: {
|
|
127
127
|
name: {
|
|
128
128
|
type: string;
|
|
129
|
-
enum: ("model" | "
|
|
129
|
+
enum: ("model" | "host" | "slicer" | "port" | "profiles" | "serial" | "secret" | "slicer-path")[];
|
|
130
130
|
};
|
|
131
131
|
env: {
|
|
132
132
|
type: string;
|
|
@@ -221,7 +221,7 @@ export declare const SETUP_FIELDS_OUTPUT_SCHEMA: {
|
|
|
221
221
|
properties: {
|
|
222
222
|
name: {
|
|
223
223
|
type: string;
|
|
224
|
-
enum: ("model" | "
|
|
224
|
+
enum: ("model" | "host" | "slicer" | "port" | "profiles" | "serial" | "secret" | "slicer-path")[];
|
|
225
225
|
};
|
|
226
226
|
env: {
|
|
227
227
|
type: string;
|