bambu-printer-mcp 1.1.65 → 1.1.67
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 -6
- package/dist/3mf_parser.d.ts +12 -1
- package/dist/3mf_parser.js +47 -17
- package/dist/counterpart/remote.js +4 -0
- package/dist/design-app-setup.d.ts +384 -0
- package/dist/design-app-setup.js +654 -0
- package/dist/fusion-mcp-bridge.d.ts +11 -2
- package/dist/fusion-mcp-bridge.js +9 -4
- package/dist/index.js +57 -8
- package/dist/tool-annotations.js +4 -0
- package/package.json +1 -1
- package/src/3mf_parser.ts +51 -17
- package/src/counterpart/remote.ts +4 -0
- package/src/design-app-setup.ts +640 -0
- package/src/fusion-mcp-bridge.ts +9 -4
- package/src/index.ts +56 -8
- package/src/tool-annotations.ts +4 -0
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The server and add-in commit fusion_mcp_setup installs (FUSION_ADDIN_COMMIT): David Montgomery's fork of
|
|
4
|
+
* faust-machines/fusion360-mcp-server with document binding, which fusion_mcp_new_design's bind_document needs, while
|
|
5
|
+
* that change is reviewed upstream. Move it only after the Counterpart PRD §8.9 acceptance check passes.
|
|
6
|
+
*/
|
|
7
|
+
export declare const FUSION_MCP_PIN: string;
|
|
4
8
|
/** PRD §8.9: Blender's MCP add-on holds the add-in's own default, 9876, so Counterpart's Fusion uses 9877. */
|
|
5
9
|
export declare const FUSION_ADDIN_DEFAULT_PORT = 9877;
|
|
6
10
|
export declare const FUSION_MCP_DEFAULT_ARGS: readonly string[];
|
|
@@ -25,6 +29,11 @@ export type FusionSystem = {
|
|
|
25
29
|
*/
|
|
26
30
|
export declare function fusionLaunchArguments(port: number): string[];
|
|
27
31
|
export declare const defaultFusionSystem: FusionSystem;
|
|
32
|
+
/** Where the add-in listens: faust reads FUSION_MCP_HOST and FUSION_MCP_PORT too. */
|
|
33
|
+
export declare function addinAddress(): {
|
|
34
|
+
host: string;
|
|
35
|
+
port: number;
|
|
36
|
+
};
|
|
28
37
|
export declare const FUSION_STATUS_OUTPUT_SCHEMA: {
|
|
29
38
|
type: "object";
|
|
30
39
|
properties: {
|
|
@@ -20,13 +20,18 @@ import net from "node:net";
|
|
|
20
20
|
import path from "node:path";
|
|
21
21
|
import { promisify } from "node:util";
|
|
22
22
|
import { stlMetadata } from "./blender-mcp-bridge.js";
|
|
23
|
+
import { FUSION_ADDIN_COMMIT, FUSION_ADDIN_REPOSITORY } from "./design-app-setup.js";
|
|
23
24
|
const execFileAsync = promisify(execFile);
|
|
24
|
-
/**
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* The server and add-in commit fusion_mcp_setup installs (FUSION_ADDIN_COMMIT): David Montgomery's fork of
|
|
27
|
+
* faust-machines/fusion360-mcp-server with document binding, which fusion_mcp_new_design's bind_document needs, while
|
|
28
|
+
* that change is reviewed upstream. Move it only after the Counterpart PRD §8.9 acceptance check passes.
|
|
29
|
+
*/
|
|
30
|
+
export const FUSION_MCP_PIN = FUSION_ADDIN_COMMIT.slice(0, 12);
|
|
26
31
|
/** PRD §8.9: Blender's MCP add-on holds the add-in's own default, 9876, so Counterpart's Fusion uses 9877. */
|
|
27
32
|
export const FUSION_ADDIN_DEFAULT_PORT = 9877;
|
|
28
33
|
export const FUSION_MCP_DEFAULT_ARGS = Object.freeze([
|
|
29
|
-
"--from", `git+https://github.com
|
|
34
|
+
"--from", `git+https://github.com/${FUSION_ADDIN_REPOSITORY}@${FUSION_MCP_PIN}`,
|
|
30
35
|
"fusion360-mcp-server", "--mode", "socket",
|
|
31
36
|
]);
|
|
32
37
|
const DEFAULT_TIMEOUT_MS = 180000;
|
|
@@ -149,7 +154,7 @@ function configuration() {
|
|
|
149
154
|
return { command, args };
|
|
150
155
|
}
|
|
151
156
|
/** Where the add-in listens: faust reads FUSION_MCP_HOST and FUSION_MCP_PORT too. */
|
|
152
|
-
function addinAddress() {
|
|
157
|
+
export function addinAddress() {
|
|
153
158
|
const host = process.env.FUSION_MCP_HOST?.trim() || "localhost";
|
|
154
159
|
const port = Number(process.env.FUSION_MCP_PORT?.trim() || FUSION_ADDIN_DEFAULT_PORT);
|
|
155
160
|
return { host, port: Number.isInteger(port) && port > 0 && port < 65536 ? port : FUSION_ADDIN_DEFAULT_PORT };
|
package/dist/index.js
CHANGED
|
@@ -27,9 +27,10 @@ import { BambuNetworkBridge, describeBambuNetworkPrintError } from "./bambu-netw
|
|
|
27
27
|
import { assertBambuNativeAvailable, bambuNativeControlsAvailable, bambuNativeUnavailableReason, interruptNativeOperations, validateBambuNativeMetadata, buildBambuNativeFanCommand, buildBambuNativeTemperatureCommand, printWithBambuNative, sendCommandWithBambuNative, uploadWithBambuNative, } from "./bambu-native.js";
|
|
28
28
|
import { importFileViaBambuConnect } from "./bambu-connect.js";
|
|
29
29
|
import { BlenderMcpBridge } from "./blender-mcp-bridge.js";
|
|
30
|
-
import { FUSION_EXPORT_OUTPUT_SCHEMA, FUSION_MCP_DEFAULT_ARGS, FUSION_NEW_DESIGN_OUTPUT_SCHEMA, FUSION_STATUS_OUTPUT_SCHEMA, FusionMcpBridge } from "./fusion-mcp-bridge.js";
|
|
30
|
+
import { FUSION_EXPORT_OUTPUT_SCHEMA, FUSION_MCP_DEFAULT_ARGS, FUSION_MCP_PIN, FUSION_NEW_DESIGN_OUTPUT_SCHEMA, FUSION_STATUS_OUTPUT_SCHEMA, FusionMcpBridge, addinAddress } from "./fusion-mcp-bridge.js";
|
|
31
|
+
import { BLENDER_SETUP_OUTPUT_SCHEMA, BlenderAddonSetup, FUSION_ADDIN_REPOSITORY, FUSION_SETUP_OUTPUT_SCHEMA, FusionAddinSetup, defaultSetupSystem, parseAddonHandshake } from "./design-app-setup.js";
|
|
31
32
|
import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, hasAmsMappingInput, normalizeAmsMappingObject, normalizeBridgeAmsTrayValue, studioAmsMappingInfo, trayColour } from "./ams-mapping.js";
|
|
32
|
-
import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, hasBambuProjectSettings, parse3MF } from './3mf_parser.js';
|
|
33
|
+
import { analyze3MFAmsRequirements, analyze3MFPlateObjects, analyzeCollarCharm3MF, extractBambuTemplateSettings, getCollarCharmRolePolicy, hasBambuProjectSettings, hasSlicerSettingsFile, parse3MF, withExtractedSettingsCleanup } from './3mf_parser.js';
|
|
33
34
|
import { BambuImplementation, assertDirectPrintSupported, checkedFile, defaultResumeStateDir } from "./printers/bambu.js";
|
|
34
35
|
import { resolveStudioPrintOptions, usedNozzleCount } from "./studio-print-options.js";
|
|
35
36
|
import { inspectPrintFile } from "./safety/print-file.js";
|
|
@@ -1108,6 +1109,9 @@ class BambuPrinterMCPServer {
|
|
|
1108
1109
|
constructor() {
|
|
1109
1110
|
this.blender = new BlenderMcpBridge();
|
|
1110
1111
|
this.fusion = new FusionMcpBridge();
|
|
1112
|
+
// Downloads and installer output are staged in this server's own temporary folder.
|
|
1113
|
+
this.blenderSetup = new BlenderAddonSetup(() => this.blenderAddonHandshake(), { ...defaultSetupSystem, tmp: TEMP_DIR });
|
|
1114
|
+
this.fusionSetup = new FusionAddinSetup(() => addinAddress().port, FUSION_MCP_DEFAULT_ARGS, { ...defaultSetupSystem, tmp: TEMP_DIR });
|
|
1111
1115
|
this.shuttingDown = false;
|
|
1112
1116
|
this.confirmationTimeoutMs = parseConfirmationTimeout(process.env.BAMBU_CONFIRMATION_TIMEOUT_MS);
|
|
1113
1117
|
this.runtimeConfig = readRuntimeConfig();
|
|
@@ -1160,6 +1164,14 @@ class BambuPrinterMCPServer {
|
|
|
1160
1164
|
this.setupPromptHandlers();
|
|
1161
1165
|
this.setupToolHandlers();
|
|
1162
1166
|
}
|
|
1167
|
+
/** The running Blender add-on's get_addon_status, read through this server's Blender bridge (undefined when it has none). */
|
|
1168
|
+
async blenderAddonHandshake() {
|
|
1169
|
+
const signal = AbortSignal.timeout(20000);
|
|
1170
|
+
const status = await this.blender.status({ connect: true, timeout_ms: 15000 }, signal);
|
|
1171
|
+
if (status?.connected !== true || !status.tools?.some(tool => tool.name === "get_addon_status"))
|
|
1172
|
+
return undefined;
|
|
1173
|
+
return parseAddonHandshake(await this.blender.call({ tool_name: "get_addon_status", arguments: {}, timeout_ms: 15000 }, signal));
|
|
1174
|
+
}
|
|
1163
1175
|
/**
|
|
1164
1176
|
* The model for display-only counterpart tools: the argument, then the
|
|
1165
1177
|
* configured model, then the serial prefix. Never a safety decision and
|
|
@@ -1708,12 +1720,18 @@ class BambuPrinterMCPServer {
|
|
|
1708
1720
|
fs.mkdirSync(tempDir, { recursive: true });
|
|
1709
1721
|
if (extension === ".3mf") {
|
|
1710
1722
|
const parsed = await parse3MF(sourcePath);
|
|
1711
|
-
const extractedSettingsPath = await extractBambuTemplateSettings(sourcePath, tempDir);
|
|
1712
1723
|
const config = (parsed.slicerConfig || {});
|
|
1724
|
+
// A 3MF with no settings file says so (raw_key_count 0) rather than failing, so a client can tell a file with
|
|
1725
|
+
// none to keep from one whose settings couldn't be read, which stays an error.
|
|
1726
|
+
const hasSettingsFile = await hasSlicerSettingsFile(sourcePath);
|
|
1727
|
+
if (hasSettingsFile && !Object.keys(config).length)
|
|
1728
|
+
throw new Error(`The slicer settings in ${sourcePath} couldn't be read.`);
|
|
1729
|
+
// Returned to the caller, so it stays.
|
|
1730
|
+
const extractedSettingsPath = hasSettingsFile ? await extractBambuTemplateSettings(sourcePath, tempDir, { keep: true }) : undefined;
|
|
1713
1731
|
return {
|
|
1714
1732
|
source_path: sourcePath,
|
|
1715
1733
|
source_type: "3mf",
|
|
1716
|
-
extracted_settings_path: extractedSettingsPath,
|
|
1734
|
+
...(extractedSettingsPath ? { extracted_settings_path: extractedSettingsPath } : {}),
|
|
1717
1735
|
object_count: parsed.objects.length,
|
|
1718
1736
|
build_item_count: parsed.build.items.length,
|
|
1719
1737
|
metadata_keys: Object.keys(parsed.metadata),
|
|
@@ -2134,7 +2152,7 @@ class BambuPrinterMCPServer {
|
|
|
2134
2152
|
},
|
|
2135
2153
|
{
|
|
2136
2154
|
name: "get_slice_settings",
|
|
2137
|
-
description: "Inspect slicer settings from a saved 3MF template or a JSON/config slicer profile without slicing anything. For a 3MF given as source_path, own_process is true when slice_stl, given this call's other arguments as it would take them (slicer_profile, template_name, template_3mf_path, layer_height, wall_loops, sparse_infill_density, quality, strength), prints the process the file carries (a designer's Bambu Studio or Orca project) unchanged.",
|
|
2155
|
+
description: "Inspect slicer settings from a saved 3MF template or a JSON/config slicer profile without slicing anything. For a 3MF given as source_path, own_process is true when slice_stl, given this call's other arguments as it would take them (slicer_profile, template_name, template_3mf_path, layer_height, wall_loops, sparse_infill_density, quality, strength), prints the process the file carries (a designer's Bambu Studio or Orca project) unchanged. A 3MF with no slicer settings reports raw_key_count 0; a file that can't be read is an error.",
|
|
2138
2156
|
inputSchema: {
|
|
2139
2157
|
type: "object",
|
|
2140
2158
|
properties: {
|
|
@@ -3079,9 +3097,29 @@ class BambuPrinterMCPServer {
|
|
|
3079
3097
|
},
|
|
3080
3098
|
outputSchema: MAKE_3MF_OUTPUT_SCHEMA
|
|
3081
3099
|
},
|
|
3100
|
+
{
|
|
3101
|
+
name: "blender_mcp_setup",
|
|
3102
|
+
description: "Check or update the MCP for Blender add-on that the configured Blender bridge (BLENDER_MCP_COMMAND uvx, BLENDER_MCP_ARGS naming mcp-for-blender or blender-mcp) needs. Without update: which add-on file Blender loads, its protocol and the protocol the package expects, whether Blender is listening and the running add-on's own handshake. Changes nothing. With update: true, stages the add-on with the package's own installer (mcp-for-blender install-addon) at the inspected version, checks it, keeps the old file as a backup next to it and renames the new one into place. Never starts, stops or edits Blender; a running Blender uses the new add-on once it is re-enabled or restarted. A custom bridge returns supported false.",
|
|
3103
|
+
inputSchema: {
|
|
3104
|
+
type: "object",
|
|
3105
|
+
properties: { update: { type: "boolean", description: "Replace the installed add-on with the package's own (default false: check only)." } },
|
|
3106
|
+
additionalProperties: false
|
|
3107
|
+
},
|
|
3108
|
+
outputSchema: BLENDER_SETUP_OUTPUT_SCHEMA
|
|
3109
|
+
},
|
|
3110
|
+
{
|
|
3111
|
+
name: "fusion_mcp_setup",
|
|
3112
|
+
description: `Check or install what the Fusion bridge needs on macOS: Autodesk Fusion itself (found, never installed), the Fusion360MCP add-in from ${FUSION_ADDIN_REPOSITORY} at ${FUSION_MCP_PIN} (every file checked against its pinned SHA-256) set to run on startup, a login item that sets FUSION_MCP_PORT for Fusion however it is opened, and this server's FUSION_MCP_* settings. Without install: reports them and changes nothing. With install: true, installs what is missing and adds the missing settings to this server's own .env (after a copy of it), keeping a configured FUSION_MCP_COMMAND and its arguments. Never starts or quits Fusion; check the connection with fusion_mcp_status.`,
|
|
3113
|
+
inputSchema: {
|
|
3114
|
+
type: "object",
|
|
3115
|
+
properties: { install: { type: "boolean", description: "Install what is missing (default false: check only)." } },
|
|
3116
|
+
additionalProperties: false
|
|
3117
|
+
},
|
|
3118
|
+
outputSchema: FUSION_SETUP_OUTPUT_SCHEMA
|
|
3119
|
+
},
|
|
3082
3120
|
{
|
|
3083
3121
|
name: "fusion_mcp_status",
|
|
3084
|
-
description: `Check Autodesk Fusion through the configured Fusion MCP server (
|
|
3122
|
+
description: `Check Autodesk Fusion through the configured Fusion MCP server (fusion360-mcp-server, faust-machines or the pinned fork with document binding): whether it is configured, Fusion is running, the Fusion360MCP add-in answers on its port, and the server's tools and schemas. connected is true only when the add-in answers. With launch: true, starts Fusion on macOS when it is not running and waits up to 90 s for the add-in. Configure FUSION_MCP_COMMAND (uvx) and FUSION_MCP_ARGS (${JSON.stringify(FUSION_MCP_DEFAULT_ARGS)}), or run fusion_mcp_setup.`,
|
|
3085
3123
|
inputSchema: {
|
|
3086
3124
|
type: "object",
|
|
3087
3125
|
properties: {
|
|
@@ -3141,7 +3179,8 @@ class BambuPrinterMCPServer {
|
|
|
3141
3179
|
].map(withAnnotations).map(withRemote)
|
|
3142
3180
|
};
|
|
3143
3181
|
});
|
|
3144
|
-
this
|
|
3182
|
+
// A designer's settings extracted for this call are removed when it settles.
|
|
3183
|
+
this.server.setRequestHandler(CallToolRequestSchema, (request, extra) => withExtractedSettingsCleanup(async () => {
|
|
3145
3184
|
const { name, arguments: args } = request.params;
|
|
3146
3185
|
const sendNativeCommand = (options, execution = {}) => sendCommandWithBambuNative(options, { signal: extra.signal, ...execution });
|
|
3147
3186
|
const progressToken = extra._meta?.progressToken;
|
|
@@ -4292,6 +4331,16 @@ class BambuPrinterMCPServer {
|
|
|
4292
4331
|
case "counterpart_make_3mf":
|
|
4293
4332
|
result = await makeCounterpart3mf(args ?? {});
|
|
4294
4333
|
break;
|
|
4334
|
+
case "blender_mcp_setup":
|
|
4335
|
+
if (args?.update !== undefined && typeof args.update !== "boolean")
|
|
4336
|
+
throw new Error("update must be a boolean.");
|
|
4337
|
+
result = args?.update === true ? await this.blenderSetup.update(extra.signal) : await this.blenderSetup.check();
|
|
4338
|
+
break;
|
|
4339
|
+
case "fusion_mcp_setup":
|
|
4340
|
+
if (args?.install !== undefined && typeof args.install !== "boolean")
|
|
4341
|
+
throw new Error("install must be a boolean.");
|
|
4342
|
+
result = args?.install === true ? await this.fusionSetup.install(extra.signal) : await this.fusionSetup.check();
|
|
4343
|
+
break;
|
|
4295
4344
|
case "fusion_mcp_status":
|
|
4296
4345
|
result = await this.fusion.status(args ?? {}, extra.signal);
|
|
4297
4346
|
break;
|
|
@@ -4349,7 +4398,7 @@ class BambuPrinterMCPServer {
|
|
|
4349
4398
|
isError: true,
|
|
4350
4399
|
};
|
|
4351
4400
|
}
|
|
4352
|
-
});
|
|
4401
|
+
}));
|
|
4353
4402
|
}
|
|
4354
4403
|
async startStdio() {
|
|
4355
4404
|
const transport = new StdioServerTransport();
|
package/dist/tool-annotations.js
CHANGED
|
@@ -87,6 +87,10 @@ export const TOOL_ANNOTATIONS = {
|
|
|
87
87
|
// The standard route preserves scene objects and needs a new output path; a configured legacy bridge promises neither.
|
|
88
88
|
blender_mcp_edit_model: hints(false, true, false, true),
|
|
89
89
|
fusion_mcp_status: hints(false, false, true, true), // launch: true starts Fusion on this computer
|
|
90
|
+
// Install add-ons into the person's own Blender or Fusion: the add-on file is replaced (kept as a backup), and
|
|
91
|
+
// the Fusion add-in folder, a login item and this server's .env are written. Repeating finds them current.
|
|
92
|
+
blender_mcp_setup: hints(false, true, true, true),
|
|
93
|
+
fusion_mcp_setup: hints(false, true, true, true),
|
|
90
94
|
fusion_mcp_call: hints(false, true, false, true), // any Fusion tool, including execute_code
|
|
91
95
|
fusion_mcp_new_design: hints(false, false, false, true), // opens another new document
|
|
92
96
|
fusion_mcp_export: hints(false, false, true, true), // never overwrites; a repeat fails and changes nothing
|
package/package.json
CHANGED
package/src/3mf_parser.ts
CHANGED
|
@@ -2,7 +2,9 @@ import JSZip from 'jszip';
|
|
|
2
2
|
import { parseStringPromise } from 'xml2js';
|
|
3
3
|
import { ThreeMFData, BambuSlicerConfig, ThreeMFMetadata, ThreeMFObject, ThreeMFBuildItem, AMSFilamentMapping, CollarCharmAnalysis, CollarCharmRole, ThreeMFAmsRequirements, ThreeMFPlateObjects } from './types.js';
|
|
4
4
|
import * as fs from 'fs/promises';
|
|
5
|
-
import {
|
|
5
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
6
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
7
|
+
import * as path from 'node:path';
|
|
6
8
|
|
|
7
9
|
// Parses Bambu Studio's JSON config data
|
|
8
10
|
function parseBambuJSONConfig(jsonData: any): Partial<BambuSlicerConfig> {
|
|
@@ -71,14 +73,23 @@ function parseBambuJSONConfig(jsonData: any): Partial<BambuSlicerConfig> {
|
|
|
71
73
|
return config;
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
/** The files a 3MF's slicer settings are read from, first found wins. */
|
|
77
|
+
const SLICER_SETTINGS_FILES = [
|
|
78
|
+
'Metadata/project_settings.config',
|
|
79
|
+
'Metadata/Slic3r_PE.config',
|
|
80
|
+
'Metadata/model_settings.config',
|
|
81
|
+
'Metadata/slice_info.config'
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
/** Whether a 3MF carries a slicer settings file at all (readable or not). */
|
|
85
|
+
export async function hasSlicerSettingsFile(filePath: string): Promise<boolean> {
|
|
86
|
+
const zip = await JSZip.loadAsync(await fs.readFile(filePath));
|
|
87
|
+
return SLICER_SETTINGS_FILES.some(name => zip.file(name));
|
|
88
|
+
}
|
|
89
|
+
|
|
74
90
|
async function parseBambuConfig(zip: JSZip): Promise<Partial<BambuSlicerConfig>> {
|
|
75
91
|
// Look for common Bambu config file names
|
|
76
|
-
const potentialFiles =
|
|
77
|
-
'Metadata/project_settings.config',
|
|
78
|
-
'Metadata/Slic3r_PE.config',
|
|
79
|
-
'Metadata/model_settings.config',
|
|
80
|
-
'Metadata/slice_info.config'
|
|
81
|
-
];
|
|
92
|
+
const potentialFiles = SLICER_SETTINGS_FILES;
|
|
82
93
|
let configFile = null;
|
|
83
94
|
let configContent = '';
|
|
84
95
|
|
|
@@ -241,27 +252,50 @@ export async function hasBambuProjectSettings(filePath: string): Promise<boolean
|
|
|
241
252
|
}
|
|
242
253
|
}
|
|
243
254
|
|
|
255
|
+
const extractionScope = new AsyncLocalStorage<string[]>();
|
|
256
|
+
|
|
257
|
+
/** Runs one operation; the directory of every settings file extracted during it is removed when it settles. */
|
|
258
|
+
export async function withExtractedSettingsCleanup<T>(operation: () => Promise<T>): Promise<T> {
|
|
259
|
+
const dirs: string[] = [];
|
|
260
|
+
try {
|
|
261
|
+
return await extractionScope.run(dirs, operation);
|
|
262
|
+
} finally {
|
|
263
|
+
await Promise.all(dirs.map(dir => fs.rm(dir, { recursive: true, force: true }).catch(() => undefined)));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Writes a 3MF's slicer settings to a file of their own and returns its path. Each extraction gets its own directory,
|
|
269
|
+
* removed when the surrounding withExtractedSettingsCleanup operation settles. `keep` is for a path handed back to the
|
|
270
|
+
* caller: it is named by content, so repeat calls reuse one file, and written whole before it is renamed into place.
|
|
271
|
+
*/
|
|
244
272
|
export async function extractBambuTemplateSettings(
|
|
245
273
|
filePath: string,
|
|
246
|
-
outputDir: string
|
|
274
|
+
outputDir: string,
|
|
275
|
+
options: { keep?: boolean } = {}
|
|
247
276
|
): Promise<string> {
|
|
248
277
|
const data = await fs.readFile(filePath);
|
|
249
278
|
const zip = await JSZip.loadAsync(data);
|
|
250
|
-
const potentialFiles =
|
|
251
|
-
'Metadata/project_settings.config',
|
|
252
|
-
'Metadata/Slic3r_PE.config',
|
|
253
|
-
'Metadata/model_settings.config',
|
|
254
|
-
'Metadata/slice_info.config'
|
|
255
|
-
];
|
|
279
|
+
const potentialFiles = SLICER_SETTINGS_FILES;
|
|
256
280
|
|
|
257
281
|
for (const name of potentialFiles) {
|
|
258
282
|
const file = zip.file(name);
|
|
259
283
|
if (!file) continue;
|
|
260
284
|
|
|
261
285
|
const content = await file.async('string');
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
286
|
+
if (options.keep) {
|
|
287
|
+
const digest = createHash('sha256').update(content).digest('hex').slice(0, 16);
|
|
288
|
+
const outputPath = path.join(outputDir, `${digest}_${name.replace(/\//g, '_')}`);
|
|
289
|
+
const partial = `${outputPath}.${randomUUID()}.partial`;
|
|
290
|
+
await fs.writeFile(partial, content, 'utf8');
|
|
291
|
+
await fs.rename(partial, outputPath);
|
|
292
|
+
return outputPath;
|
|
293
|
+
}
|
|
294
|
+
// Its own directory for every extraction, so two slices at once (of different projects or the same one)
|
|
295
|
+
// never share, overwrite or half-read one settings file.
|
|
296
|
+
const dir = await fs.mkdtemp(path.join(outputDir, 'slicer-settings-'));
|
|
297
|
+
extractionScope.getStore()?.push(dir);
|
|
298
|
+
const outputPath = path.join(dir, name.replace(/\//g, '_'));
|
|
265
299
|
await fs.writeFile(outputPath, content, 'utf8');
|
|
266
300
|
return outputPath;
|
|
267
301
|
}
|
|
@@ -41,6 +41,8 @@ export const REMOTE_SCOPES: Readonly<Record<string, RemoteScope>> = {
|
|
|
41
41
|
counterpart_printer_info: "read",
|
|
42
42
|
counterpart_print_progress: "read",
|
|
43
43
|
fusion_mcp_status: "read",
|
|
44
|
+
blender_mcp_setup: "read", // checks only; update raises it
|
|
45
|
+
fusion_mcp_setup: "read", // checks only; install raises it
|
|
44
46
|
// design
|
|
45
47
|
slice_stl: "design",
|
|
46
48
|
lay_flat: "design",
|
|
@@ -93,6 +95,8 @@ export const REMOTE_SCOPES: Readonly<Record<string, RemoteScope>> = {
|
|
|
93
95
|
const RAISED_BY: Readonly<Record<string, Record<string, RemoteScope>>> = {
|
|
94
96
|
fusion_mcp_status: { launch: "design" }, // starts Fusion on this computer
|
|
95
97
|
blender_mcp_status: { connect: "design" }, // connects to Blender
|
|
98
|
+
blender_mcp_setup: { update: "raw" }, // replaces the add-on in the person's Blender
|
|
99
|
+
fusion_mcp_setup: { install: "raw" }, // installs into the person's Fusion, a login item and this server's .env
|
|
96
100
|
};
|
|
97
101
|
|
|
98
102
|
/**
|