bambu-studio-mcp 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +105 -2
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +6 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.js +132 -0
- package/dist/cli.js.map +1 -0
- package/dist/confirm.d.ts +7 -0
- package/dist/confirm.js +24 -0
- package/dist/confirm.js.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +38 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +10 -0
- package/dist/mcp.js +98 -0
- package/dist/mcp.js.map +1 -0
- package/dist/osa.d.ts +15 -0
- package/dist/osa.js +40 -0
- package/dist/osa.js.map +1 -0
- package/dist/parse.d.ts +15 -0
- package/dist/parse.js +241 -0
- package/dist/parse.js.map +1 -0
- package/dist/runner.d.ts +31 -0
- package/dist/runner.js +50 -0
- package/dist/runner.js.map +1 -0
- package/dist/screen.d.ts +26 -0
- package/dist/screen.js +61 -0
- package/dist/screen.js.map +1 -0
- package/dist/studio.d.ts +131 -0
- package/dist/studio.js +329 -0
- package/dist/studio.js.map +1 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/jxa/click.js +21 -0
- package/jxa/close-window.js +9 -0
- package/jxa/colour.js +27 -0
- package/jxa/instances.js +9 -0
- package/jxa/keystroke.js +14 -0
- package/jxa/ocr.js +25 -0
- package/jxa/permissions.js +11 -0
- package/jxa/prelude.js +114 -0
- package/jxa/wait-window.js +15 -0
- package/package.json +69 -4
package/dist/studio.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { askToSend } from "./confirm.js";
|
|
3
|
+
import { BsmError } from "./errors.js";
|
|
4
|
+
import { Osa } from "./osa.js";
|
|
5
|
+
import { clean, diffDialogs, parseDevice, parseSendDialog, unmet } from "./parse.js";
|
|
6
|
+
import { defaultStateDir, nodeRunner } from "./runner.js";
|
|
7
|
+
import { isGreen, Screen } from "./screen.js";
|
|
8
|
+
export const SEND_DIALOG = "Send print job";
|
|
9
|
+
/** Windows that are dialogs over a project window, never the project window itself. */
|
|
10
|
+
const DIALOGS = new Set([SEND_DIALOG, "Keyboard Shortcuts"]);
|
|
11
|
+
/** Height of the strip under the title bar that holds the tabs and the Slice and Print buttons, in points. */
|
|
12
|
+
const TOP_STRIP = 80;
|
|
13
|
+
/** The versions this was written and tested against. Others may work; `doctor` says so. */
|
|
14
|
+
export const TESTED = { studio: ["02.09.02.62"], macos: ["27.2.1"], printers: ["Bambu Lab X2D"] };
|
|
15
|
+
export const DEFAULTS = {
|
|
16
|
+
sliceTimeoutMs: 600_000,
|
|
17
|
+
pollMs: 2_000,
|
|
18
|
+
previewTtlMs: 600_000,
|
|
19
|
+
allowUnconfirmed: false,
|
|
20
|
+
stateDir: defaultStateDir(),
|
|
21
|
+
studioApp: "/Applications/BambuStudio.app",
|
|
22
|
+
};
|
|
23
|
+
function centre(rect, box) {
|
|
24
|
+
return { x: rect.x + (box.x + box.w / 2) * rect.w, y: rect.y + (box.y + box.h / 2) * rect.h };
|
|
25
|
+
}
|
|
26
|
+
function sameRect(a, b) {
|
|
27
|
+
return a.x === b.x && a.y === b.y && a.w === b.w && a.h === b.h;
|
|
28
|
+
}
|
|
29
|
+
export class Studio {
|
|
30
|
+
runner;
|
|
31
|
+
osa;
|
|
32
|
+
screen;
|
|
33
|
+
opts;
|
|
34
|
+
constructor(runner, osa, screen, options = {}) {
|
|
35
|
+
this.runner = runner;
|
|
36
|
+
this.osa = osa;
|
|
37
|
+
this.screen = screen;
|
|
38
|
+
this.opts = { ...DEFAULTS, ...options };
|
|
39
|
+
}
|
|
40
|
+
static create(options = {}, runner = nodeRunner()) {
|
|
41
|
+
const osa = new Osa(runner);
|
|
42
|
+
return new Studio(runner, osa, new Screen(runner, osa), options);
|
|
43
|
+
}
|
|
44
|
+
base64(path) {
|
|
45
|
+
return this.screen.base64(path);
|
|
46
|
+
}
|
|
47
|
+
instances() {
|
|
48
|
+
return this.osa.call("instances");
|
|
49
|
+
}
|
|
50
|
+
/** The one instance meant, and its project window. */
|
|
51
|
+
async locate(target = {}) {
|
|
52
|
+
const all = await this.instances();
|
|
53
|
+
const { pid, project } = target;
|
|
54
|
+
const matches = all.filter((i) => (pid === undefined || i.pid === pid) &&
|
|
55
|
+
(project === undefined || i.windows.some((w) => w.name === project)));
|
|
56
|
+
const [only] = matches;
|
|
57
|
+
if (only === undefined) {
|
|
58
|
+
throw new BsmError("NO_INSTANCE", all.length === 0 ? "Bambu Studio is not running" : "no Bambu Studio instance matches", "Open a project first (open), or pass the pid or project from instances.");
|
|
59
|
+
}
|
|
60
|
+
if (matches.length > 1) {
|
|
61
|
+
const list = matches.map((i) => `${i.pid} (${i.windows.map((w) => w.name).join(", ")})`).join("; ");
|
|
62
|
+
throw new BsmError("AMBIGUOUS", `several Bambu Studio instances are open: ${list}`, "Pass pid or project.");
|
|
63
|
+
}
|
|
64
|
+
const window = only.windows.find((w) => (project === undefined ? !DIALOGS.has(w.name) : w.name === project)) ?? null;
|
|
65
|
+
if (window === null)
|
|
66
|
+
throw new BsmError("NOT_FOUND", `instance ${only.pid} shows no project window`);
|
|
67
|
+
return { pid: only.pid, window };
|
|
68
|
+
}
|
|
69
|
+
async open(file, timeoutMs = 120_000) {
|
|
70
|
+
if (!this.runner.exists(file))
|
|
71
|
+
throw new BsmError("NOT_FOUND", `no such file: ${file}`);
|
|
72
|
+
const project = file.split("/").pop().replace(/\.3mf$/i, "");
|
|
73
|
+
await this.runner.exec("open", ["-a", this.opts.studioApp, file]);
|
|
74
|
+
const deadline = this.runner.now() + timeoutMs;
|
|
75
|
+
for (;;) {
|
|
76
|
+
const found = (await this.instances()).find((i) => i.windows.some((w) => w.name === project));
|
|
77
|
+
if (found !== undefined)
|
|
78
|
+
return this.locate({ pid: found.pid, project });
|
|
79
|
+
if (this.runner.now() >= deadline) {
|
|
80
|
+
throw new BsmError("TIMEOUT", `no window named "${project}" appeared`, "Bambu Studio may be showing a question about the file; look at it.");
|
|
81
|
+
}
|
|
82
|
+
await this.runner.sleep(this.opts.pollMs);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async topStrip(at) {
|
|
86
|
+
const { window } = at;
|
|
87
|
+
const path = await this.screen.capture({ x: window.x, y: window.y, w: window.w, h: TOP_STRIP });
|
|
88
|
+
return { path, items: await this.screen.ocr(path) };
|
|
89
|
+
}
|
|
90
|
+
/** Whether the Print plate button is enabled, which it is once the plate is sliced. */
|
|
91
|
+
/**
|
|
92
|
+
* Whether the Print plate button is enabled, which it is once the plate is sliced. Its colour is read
|
|
93
|
+
* just right of the label, inside the button: over the label itself the white letters wash it out.
|
|
94
|
+
* A disabled button's grey label isn't recognized at all.
|
|
95
|
+
*/
|
|
96
|
+
async sliced(at) {
|
|
97
|
+
const strip = await this.topStrip(at);
|
|
98
|
+
const label = strip.items.find((i) => clean(i.t) === "Print plate");
|
|
99
|
+
if (label === undefined)
|
|
100
|
+
return false;
|
|
101
|
+
const beside = { x: label.x + label.w + 0.002, y: label.y, w: 0.005, h: label.h };
|
|
102
|
+
return isGreen(await this.screen.colour(strip.path, beside));
|
|
103
|
+
}
|
|
104
|
+
async slice(target = {}) {
|
|
105
|
+
const at = await this.locate(target);
|
|
106
|
+
await this.osa.call("keystroke", [at.pid, at.window.name, "r", "command"]);
|
|
107
|
+
const deadline = this.runner.now() + this.opts.sliceTimeoutMs;
|
|
108
|
+
for (;;) {
|
|
109
|
+
await this.runner.sleep(this.opts.pollMs);
|
|
110
|
+
if (await this.sliced(at))
|
|
111
|
+
break;
|
|
112
|
+
if (this.runner.now() >= deadline) {
|
|
113
|
+
throw new BsmError("TIMEOUT", "the plate did not finish slicing", "Look at the window: slicing may have failed.");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return { pid: at.pid, window: at.window.name, image: await this.screen.capture(at.window) };
|
|
117
|
+
}
|
|
118
|
+
/** The Device tab, shown if it isn't already: by its label in the tab strip, so nothing else is clicked. */
|
|
119
|
+
async deviceView(at) {
|
|
120
|
+
const look = async () => {
|
|
121
|
+
const path = await this.screen.capture(at.window);
|
|
122
|
+
return { path, items: await this.screen.ocr(path) };
|
|
123
|
+
};
|
|
124
|
+
const first = await look();
|
|
125
|
+
if (first.items.some((i) => clean(i.t) === "Printing Progress" || clean(i.t) === "Camera"))
|
|
126
|
+
return first;
|
|
127
|
+
const strip = await this.topStrip(at);
|
|
128
|
+
const tab = strip.items.find((i) => clean(i.t).endsWith("Device"));
|
|
129
|
+
if (tab === undefined) {
|
|
130
|
+
throw new BsmError("NOT_FOUND", "cannot find the Device tab", "Bambu Studio must be in English; see doctor.");
|
|
131
|
+
}
|
|
132
|
+
const { window } = at;
|
|
133
|
+
const point = centre({ x: window.x, y: window.y, w: window.w, h: TOP_STRIP }, tab);
|
|
134
|
+
await this.osa.call("click", [
|
|
135
|
+
at.pid,
|
|
136
|
+
window.name,
|
|
137
|
+
window.x,
|
|
138
|
+
window.y,
|
|
139
|
+
window.w,
|
|
140
|
+
window.h,
|
|
141
|
+
point.x,
|
|
142
|
+
point.y,
|
|
143
|
+
]);
|
|
144
|
+
await this.runner.sleep(1_500);
|
|
145
|
+
return look();
|
|
146
|
+
}
|
|
147
|
+
async status(target = {}) {
|
|
148
|
+
const at = await this.locate(target);
|
|
149
|
+
const view = await this.deviceView(at);
|
|
150
|
+
return { pid: at.pid, status: parseDevice(view.items), image: view.path };
|
|
151
|
+
}
|
|
152
|
+
/** The camera view's box on the Device tab: between its label, the Control panel and the progress panel. */
|
|
153
|
+
cameraBox(items) {
|
|
154
|
+
const camera = items.find((i) => clean(i.t) === "Camera");
|
|
155
|
+
if (camera === undefined)
|
|
156
|
+
throw new BsmError("NOT_FOUND", "cannot find the camera view on the Device tab");
|
|
157
|
+
const control = items.find((i) => clean(i.t) === "Control");
|
|
158
|
+
const progress = items.find((i) => clean(i.t) === "Printing Progress");
|
|
159
|
+
const top = camera.y + camera.h + 0.005;
|
|
160
|
+
return {
|
|
161
|
+
x: camera.x,
|
|
162
|
+
y: top,
|
|
163
|
+
w: (control?.x ?? 0.66) - camera.x - 0.01,
|
|
164
|
+
h: (progress?.y ?? 0.56) - top - 0.02,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
async snapshot(target = {}) {
|
|
168
|
+
const at = await this.locate(target);
|
|
169
|
+
let view = await this.deviceView(at);
|
|
170
|
+
let box = this.cameraBox(view.items);
|
|
171
|
+
// Bambu Studio closes the live view after a while, and otherwise shows an old still: press its play
|
|
172
|
+
// button, in the middle of the camera view, and give the stream a moment.
|
|
173
|
+
if (view.items.some((i) => /Temporarily closed|Non-live image/i.test(i.t))) {
|
|
174
|
+
const { window } = at;
|
|
175
|
+
const point = centre(window, box);
|
|
176
|
+
await this.osa.call("click", [
|
|
177
|
+
at.pid,
|
|
178
|
+
window.name,
|
|
179
|
+
window.x,
|
|
180
|
+
window.y,
|
|
181
|
+
window.w,
|
|
182
|
+
window.h,
|
|
183
|
+
point.x,
|
|
184
|
+
point.y,
|
|
185
|
+
]);
|
|
186
|
+
await this.runner.sleep(6_000);
|
|
187
|
+
view = await this.deviceView(at);
|
|
188
|
+
box = this.cameraBox(view.items);
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
pid: at.pid,
|
|
192
|
+
capturedAt: parseDevice(view.items).cameraCapturedAt,
|
|
193
|
+
image: await this.screen.crop(view.path, box),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
statePath(token) {
|
|
197
|
+
return join(this.opts.stateDir, `preview-${token}.json`);
|
|
198
|
+
}
|
|
199
|
+
async preview(target = {}) {
|
|
200
|
+
const at = await this.locate(target);
|
|
201
|
+
const open = (await this.instances())
|
|
202
|
+
.find((i) => i.pid === at.pid)
|
|
203
|
+
?.windows.some((w) => w.name === SEND_DIALOG);
|
|
204
|
+
if (open !== true)
|
|
205
|
+
await this.osa.call("keystroke", [at.pid, at.window.name, "g", "command,shift"]);
|
|
206
|
+
const waited = await this.osa.call("wait-window", [
|
|
207
|
+
at.pid,
|
|
208
|
+
SEND_DIALOG,
|
|
209
|
+
"appear",
|
|
210
|
+
15,
|
|
211
|
+
]);
|
|
212
|
+
if (!waited.done || waited.window === null) {
|
|
213
|
+
throw new BsmError("TIMEOUT", "the Send print job dialog did not open", "Slice the plate first (slice).");
|
|
214
|
+
}
|
|
215
|
+
const rect = { x: waited.window.x, y: waited.window.y, w: waited.window.w, h: waited.window.h };
|
|
216
|
+
const image = await this.screen.capture(rect);
|
|
217
|
+
const dialog = parseSendDialog(await this.screen.ocr(image));
|
|
218
|
+
const token = `${at.pid}-${this.runner.now().toString(36)}`;
|
|
219
|
+
const stored = { token, pid: at.pid, rect, dialog, at: this.runner.now() };
|
|
220
|
+
await this.runner.writeText(this.statePath(token), JSON.stringify(stored));
|
|
221
|
+
return { token, pid: at.pid, dialog, image };
|
|
222
|
+
}
|
|
223
|
+
async cancel(target = {}) {
|
|
224
|
+
const at = await this.locate(target);
|
|
225
|
+
return this.osa.call("close-window", [at.pid, SEND_DIALOG]);
|
|
226
|
+
}
|
|
227
|
+
async loadPreview(token) {
|
|
228
|
+
const path = this.statePath(token);
|
|
229
|
+
if (!/^[\w-]+$/.test(token) || !this.runner.exists(path)) {
|
|
230
|
+
throw new BsmError("STALE", "unknown or used preview token", "Run preview again.");
|
|
231
|
+
}
|
|
232
|
+
const stored = JSON.parse(await this.runner.readText(path));
|
|
233
|
+
if (this.runner.now() - stored.at > this.opts.previewTtlMs) {
|
|
234
|
+
await this.runner.remove(path);
|
|
235
|
+
throw new BsmError("STALE", "the preview is too old", "Run preview again.");
|
|
236
|
+
}
|
|
237
|
+
return stored;
|
|
238
|
+
}
|
|
239
|
+
async send(request) {
|
|
240
|
+
const stored = await this.loadPreview(request.token);
|
|
241
|
+
const pid = stored.pid;
|
|
242
|
+
const dialogWindow = (await this.instances())
|
|
243
|
+
.find((i) => i.pid === pid)
|
|
244
|
+
?.windows.find((w) => w.name === SEND_DIALOG);
|
|
245
|
+
if (dialogWindow === undefined || !sameRect(dialogWindow, stored.rect)) {
|
|
246
|
+
throw new BsmError("STALE", "the Send print job dialog closed or moved since the preview", "Run preview again.");
|
|
247
|
+
}
|
|
248
|
+
// Read the dialog again, now, and send only what was previewed and expected.
|
|
249
|
+
const image = await this.screen.capture(stored.rect);
|
|
250
|
+
const dialog = parseSendDialog(await this.screen.ocr(image));
|
|
251
|
+
const changed = diffDialogs(stored.dialog, dialog);
|
|
252
|
+
if (changed.length > 0)
|
|
253
|
+
throw new BsmError("MISMATCH", `the dialog changed since the preview: ${changed.join("; ")}`);
|
|
254
|
+
const failed = unmet(dialog, request.expect ?? {});
|
|
255
|
+
if (failed.length > 0)
|
|
256
|
+
throw new BsmError("MISMATCH", `the dialog is not what was expected: ${failed.join("; ")}`);
|
|
257
|
+
if (dialog.notices.length > 0) {
|
|
258
|
+
throw new BsmError("NOT_READY", `the dialog shows a problem: ${dialog.notices.join(" / ")}`);
|
|
259
|
+
}
|
|
260
|
+
if (dialog.send === null)
|
|
261
|
+
throw new BsmError("NOT_FOUND", "cannot find the Send button");
|
|
262
|
+
if (!isGreen(await this.screen.colour(image, dialog.send))) {
|
|
263
|
+
throw new BsmError("NOT_READY", "the Send button is disabled", "Bambu Studio says the printer can't take this job now.");
|
|
264
|
+
}
|
|
265
|
+
if (request.confirm === false) {
|
|
266
|
+
if (!this.opts.allowUnconfirmed) {
|
|
267
|
+
throw new BsmError("USAGE", "sending without the confirmation dialog is turned off", "A person can allow it: the CLI's --yes, or BAMBU_STUDIO_MCP_ALLOW_UNCONFIRMED=1 in the server's environment.");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
const fil = dialog.filaments.map((f) => `${f.material} from ${f.slot}`).join(", ");
|
|
272
|
+
const question = `Send "${dialog.job}" to ${dialog.printer}?\n\n${dialog.duration}, ${dialog.grams} g, ${fil}, ${dialog.plate}.\n\nOnly if the bed is clear.`;
|
|
273
|
+
if (!(await askToSend(this.runner, question)))
|
|
274
|
+
throw new BsmError("DECLINED", "not sent: the person at the Mac said no");
|
|
275
|
+
}
|
|
276
|
+
// One click, never retried: a second click could send a second job.
|
|
277
|
+
await this.runner.remove(this.statePath(request.token));
|
|
278
|
+
const point = centre(stored.rect, dialog.send);
|
|
279
|
+
const r = stored.rect;
|
|
280
|
+
await this.osa.call("click", [pid, SEND_DIALOG, r.x, r.y, r.w, r.h, point.x, point.y]);
|
|
281
|
+
const closed = await this.osa.call("wait-window", [pid, SEND_DIALOG, "vanish", 90]);
|
|
282
|
+
if (!closed.done) {
|
|
283
|
+
const after = await this.screen.capture(stored.rect);
|
|
284
|
+
const notices = (await this.screen.ocr(after)).map((i) => clean(i.t)).filter((t) => t !== "");
|
|
285
|
+
return { result: "not-sent", job: dialog.job, notices, status: null, image: after };
|
|
286
|
+
}
|
|
287
|
+
await this.runner.sleep(3_000);
|
|
288
|
+
const { status, image: shot } = await this.status({ pid });
|
|
289
|
+
const started = status.job === dialog.job && (status.state === "printing" || status.state === "preparing");
|
|
290
|
+
return { result: started ? "started" : "unconfirmed", job: dialog.job, notices: [], status, image: shot };
|
|
291
|
+
}
|
|
292
|
+
async doctor() {
|
|
293
|
+
const warnings = [];
|
|
294
|
+
const macos = (await this.runner.exec("sw_vers", ["-productVersion"])).trim();
|
|
295
|
+
const installed = this.runner.exists(this.opts.studioApp);
|
|
296
|
+
const version = installed
|
|
297
|
+
? (await this.runner.exec("defaults", [
|
|
298
|
+
"read",
|
|
299
|
+
`${this.opts.studioApp}/Contents/Info.plist`,
|
|
300
|
+
"CFBundleShortVersionString",
|
|
301
|
+
])).trim()
|
|
302
|
+
: null;
|
|
303
|
+
if (!installed)
|
|
304
|
+
warnings.push(`Bambu Studio is not at ${this.opts.studioApp}.`);
|
|
305
|
+
else if (!TESTED.studio.includes(version)) {
|
|
306
|
+
warnings.push(`Bambu Studio ${version} is untested (tested: ${TESTED.studio.join(", ")}).`);
|
|
307
|
+
}
|
|
308
|
+
if (!TESTED.macos.includes(macos)) {
|
|
309
|
+
warnings.push(`macOS ${macos} is untested (tested: ${TESTED.macos.join(", ")}).`);
|
|
310
|
+
}
|
|
311
|
+
const permissions = await this.osa.call("permissions");
|
|
312
|
+
if (!permissions.accessibility)
|
|
313
|
+
warnings.push("Accessibility is not allowed for this app: it cannot drive Bambu Studio.");
|
|
314
|
+
if (!permissions.screenRecording)
|
|
315
|
+
warnings.push("Screen Recording is not allowed for this app: it cannot read Bambu Studio.");
|
|
316
|
+
const instances = permissions.accessibility ? await this.instances() : [];
|
|
317
|
+
if (instances.length > 1)
|
|
318
|
+
warnings.push("Several instances are open: pass pid or project to each command.");
|
|
319
|
+
return {
|
|
320
|
+
macos,
|
|
321
|
+
studio: { installed, version },
|
|
322
|
+
permissions,
|
|
323
|
+
instances: instances.map((i) => ({ pid: i.pid, windows: i.windows.map((w) => w.name) })),
|
|
324
|
+
tested: TESTED,
|
|
325
|
+
warnings,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=studio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studio.js","sourceRoot":"","sources":["../src/studio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,GAAG,EAAgB,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,E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0E,CAAC,CAAC;QAC5F,IAAI,CAAC,WAAW,CAAC,eAAe;YAC9B,QAAQ,CAAC,IAAI,CAAC,4EAA4E,CAAC,CAAC;QAC9F,MAAM,SAAS,GAAG,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1E,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC;YACtB,QAAQ,CAAC,IAAI,CAAC,kEAAkE,CAAC,CAAC;QACpF,OAAO;YACL,KAAK;YACL,MAAM,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE;YAC9B,WAAW;YACX,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACxF,MAAM,EAAE,MAAM;YACd,QAAQ;SACT,CAAC;IACJ,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** A rectangle on screen, in points, origin at the top-left of the main display (macOS's global space). */
|
|
2
|
+
export interface Rect {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
w: number;
|
|
6
|
+
h: number;
|
|
7
|
+
}
|
|
8
|
+
/** A box inside an image, normalized to 0..1, origin top-left. */
|
|
9
|
+
export type Box = Rect;
|
|
10
|
+
/** One line of recognized text and its box in the image. */
|
|
11
|
+
export interface OcrItem extends Box {
|
|
12
|
+
t: string;
|
|
13
|
+
}
|
|
14
|
+
export interface WindowInfo extends Rect {
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
17
|
+
/** One Bambu Studio process. Bambu Studio runs one per open project. */
|
|
18
|
+
export interface Instance {
|
|
19
|
+
pid: number;
|
|
20
|
+
frontmost: boolean;
|
|
21
|
+
windows: WindowInfo[];
|
|
22
|
+
}
|
|
23
|
+
/** Which instance to act on: by pid, or by its project's window title. Neither, when only one is running. */
|
|
24
|
+
export interface Target {
|
|
25
|
+
pid?: number | undefined;
|
|
26
|
+
project?: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
export interface Filament {
|
|
29
|
+
nozzle: "main" | "auxiliary";
|
|
30
|
+
material: string;
|
|
31
|
+
slot: string;
|
|
32
|
+
}
|
|
33
|
+
/** What the "Send print job" dialog says, read from a screenshot of it. */
|
|
34
|
+
export interface SendDialog {
|
|
35
|
+
job: string | null;
|
|
36
|
+
duration: string | null;
|
|
37
|
+
seconds: number | null;
|
|
38
|
+
grams: number | null;
|
|
39
|
+
printer: string | null;
|
|
40
|
+
model: string | null;
|
|
41
|
+
plate: string | null;
|
|
42
|
+
filaments: Filament[];
|
|
43
|
+
notices: string[];
|
|
44
|
+
/** Where its Send button is, in the dialog's own normalized box; null when it can't be seen. */
|
|
45
|
+
send: Box | null;
|
|
46
|
+
}
|
|
47
|
+
export type PrinterState = "printing" | "preparing" | "paused" | "finished" | "canceled" | "failed" | "idle" | "unknown";
|
|
48
|
+
/** What the Device tab says, read from a screenshot of it. */
|
|
49
|
+
export interface DeviceStatus {
|
|
50
|
+
printer: string | null;
|
|
51
|
+
state: PrinterState;
|
|
52
|
+
job: string | null;
|
|
53
|
+
stage: string | null;
|
|
54
|
+
percent: number | null;
|
|
55
|
+
layer: {
|
|
56
|
+
current: number;
|
|
57
|
+
total: number;
|
|
58
|
+
} | null;
|
|
59
|
+
remaining: string | null;
|
|
60
|
+
finish: string | null;
|
|
61
|
+
cameraCapturedAt: string | null;
|
|
62
|
+
}
|
|
63
|
+
/** What a send must find in the dialog. Strings match case-insensitively as substrings; lists exactly. */
|
|
64
|
+
export interface Expect {
|
|
65
|
+
job?: string | undefined;
|
|
66
|
+
printer?: string | undefined;
|
|
67
|
+
plate?: string | undefined;
|
|
68
|
+
slots?: string[] | undefined;
|
|
69
|
+
materials?: string[] | undefined;
|
|
70
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,4EAA4E;AAC5E,MAAM,CAAC,MAAM,OAAO,GAAY,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,iBAAiB,CAAyB;KACtG,OAAO,CAAC"}
|
package/jxa/click.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// argv: pid, window name, its expected x, y, w, h, then the point px, py (global, in points).
|
|
2
|
+
// One mouse click inside a window, and only if the window is still exactly where the caller saw it,
|
|
3
|
+
// so a moved or resized window cannot turn the click into a click on something else.
|
|
4
|
+
function run(argv) {
|
|
5
|
+
let proc = studioProcess(parseInt(argv[0], 10));
|
|
6
|
+
let w = findWindow(proc, argv[1]);
|
|
7
|
+
if (!w) throw new Error(`BSM_WINDOWS: the window '${argv[1]}' is not open`);
|
|
8
|
+
let info = windowInfo(w);
|
|
9
|
+
let want = [argv[2], argv[3], argv[4], argv[5]].map(parseFloat);
|
|
10
|
+
if (info.x !== want[0] || info.y !== want[1] || info.w !== want[2] || info.h !== want[3]) {
|
|
11
|
+
throw new Error("BSM_MOVED: the window moved since it was read; read it again");
|
|
12
|
+
}
|
|
13
|
+
let px = parseFloat(argv[6]);
|
|
14
|
+
let py = parseFloat(argv[7]);
|
|
15
|
+
if (px < info.x || px > info.x + info.w || py < info.y || py > info.y + info.h) {
|
|
16
|
+
throw new Error("BSM_OUTSIDE: the point is outside the window");
|
|
17
|
+
}
|
|
18
|
+
bringToFront(proc);
|
|
19
|
+
postClick(px, py);
|
|
20
|
+
return emit({ clicked: true });
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// argv: pid, window name. Closes that window with its own close button, which in a dialog means
|
|
2
|
+
// "dismiss without acting".
|
|
3
|
+
function run(argv) {
|
|
4
|
+
let proc = studioProcess(parseInt(argv[0], 10));
|
|
5
|
+
let w = findWindow(proc, argv[1]);
|
|
6
|
+
if (!w) return emit({ closed: false, reason: "not open" });
|
|
7
|
+
w.buttons.whose({ subrole: "AXCloseButton" })[0].click();
|
|
8
|
+
return emit({ closed: true });
|
|
9
|
+
}
|
package/jxa/colour.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// argv: path to a PNG, then a box normalized to the image: x, y, w, h (origin top-left).
|
|
2
|
+
// The average colour of that box, 0..255 per channel, sampled on a grid. Read-only.
|
|
3
|
+
function run(argv) {
|
|
4
|
+
let data = $.NSData.dataWithContentsOfFile(argv[0]);
|
|
5
|
+
let rep = $.NSBitmapImageRep.imageRepWithData(data);
|
|
6
|
+
if (!rep || rep.isNil()) throw new Error(`BSM_IMAGE: cannot read ${argv[0]}`);
|
|
7
|
+
let W = rep.pixelsWide;
|
|
8
|
+
let H = rep.pixelsHigh;
|
|
9
|
+
let bx = parseFloat(argv[1]) * W;
|
|
10
|
+
let by = parseFloat(argv[2]) * H;
|
|
11
|
+
let bw = parseFloat(argv[3]) * W;
|
|
12
|
+
let bh = parseFloat(argv[4]) * H;
|
|
13
|
+
let sum = [0, 0, 0];
|
|
14
|
+
let n = 0;
|
|
15
|
+
for (let i = 0; i < 12; i++) {
|
|
16
|
+
for (let j = 0; j < 6; j++) {
|
|
17
|
+
let px = Math.min(W - 1, Math.max(0, Math.round(bx + ((i + 0.5) * bw) / 12)));
|
|
18
|
+
let py = Math.min(H - 1, Math.max(0, Math.round(by + ((j + 0.5) * bh) / 6)));
|
|
19
|
+
let c = rep.colorAtXY(px, py).colorUsingColorSpace($.NSColorSpace.sRGBColorSpace);
|
|
20
|
+
sum[0] += c.redComponent * 255;
|
|
21
|
+
sum[1] += c.greenComponent * 255;
|
|
22
|
+
sum[2] += c.blueComponent * 255;
|
|
23
|
+
n++;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return emit(sum.map((s) => Math.round(s / n)));
|
|
27
|
+
}
|
package/jxa/instances.js
ADDED
package/jxa/keystroke.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// argv: pid, window, key, modifiers (comma-separated: command,shift,option,control).
|
|
2
|
+
// Types one shortcut into Bambu Studio, and only when the process shows exactly the expected window
|
|
3
|
+
// and is frontmost.
|
|
4
|
+
function run(argv) {
|
|
5
|
+
let proc = studioProcess(parseInt(argv[0], 10));
|
|
6
|
+
expectOnly(proc, argv[1]);
|
|
7
|
+
bringToFront(proc);
|
|
8
|
+
let mods = (argv[3] || "")
|
|
9
|
+
.split(",")
|
|
10
|
+
.filter((m) => m)
|
|
11
|
+
.map((m) => `${m} down`);
|
|
12
|
+
SE.keystroke(argv[2], { using: mods });
|
|
13
|
+
return emit({ ok: true });
|
|
14
|
+
}
|
package/jxa/ocr.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// argv: path to a PNG. Text in the image by macOS's own Vision framework: one item per line, with its
|
|
2
|
+
// box normalized to the image (0..1, origin top-left). Read-only.
|
|
3
|
+
function run(argv) {
|
|
4
|
+
let url = $.NSURL.fileURLWithPath(argv[0]);
|
|
5
|
+
let req = $.VNRecognizeTextRequest.alloc.init;
|
|
6
|
+
req.recognitionLevel = $.VNRequestTextRecognitionLevelAccurate;
|
|
7
|
+
req.usesLanguageCorrection = false;
|
|
8
|
+
let handler = $.VNImageRequestHandler.alloc.initWithURLOptions(url, $());
|
|
9
|
+
if (!handler.performRequestsError($([req]), null)) throw new Error("BSM_OCR: text recognition failed");
|
|
10
|
+
let res = req.results;
|
|
11
|
+
let out = [];
|
|
12
|
+
for (let i = 0; i < res.count; i++) {
|
|
13
|
+
let o = res.objectAtIndex(i);
|
|
14
|
+
let c = o.topCandidates(1).objectAtIndex(0);
|
|
15
|
+
let b = o.boundingBox;
|
|
16
|
+
out.push({
|
|
17
|
+
t: c.string.js,
|
|
18
|
+
x: b.origin.x,
|
|
19
|
+
y: 1 - b.origin.y - b.size.height,
|
|
20
|
+
w: b.size.width,
|
|
21
|
+
h: b.size.height,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return emit(out);
|
|
25
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// What this host app (the terminal, or the MCP client) is allowed: Accessibility, to read and drive
|
|
2
|
+
// windows, and Screen Recording, to read the custom-drawn parts of Bambu Studio. Read-only.
|
|
3
|
+
function run() {
|
|
4
|
+
let accessibility = true;
|
|
5
|
+
try {
|
|
6
|
+
SE.processes.name();
|
|
7
|
+
} catch (e) {
|
|
8
|
+
accessibility = false;
|
|
9
|
+
}
|
|
10
|
+
return emit({ accessibility: accessibility, screenRecording: $.CGPreflightScreenCaptureAccess() === true });
|
|
11
|
+
}
|