@slatesvideo/shared 0.7.14 → 0.7.15
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/auth.d.ts +2 -1
- package/dist/auth.js +73 -5
- package/dist/clients/blender.d.ts +9 -1
- package/dist/clients/blender.js +160 -27
- package/dist/clients/cloud.d.ts +1 -0
- package/dist/clients/cloud.js +10 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/manual/content.d.ts +1 -1
- package/dist/manual/content.js +1 -1
- package/dist/operations/index.d.ts +4 -2
- package/dist/operations/index.js +140 -39
- package/dist/operations/surface.d.ts +1 -1
- package/dist/operations/surface.js +16 -8
- package/dist/skills/my-brain.js +2 -2
- package/dist/skills/served.js +6 -4
- package/dist/update-check.js +8 -1
- package/package.json +2 -2
package/dist/auth.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export interface McpLauncher {
|
|
|
51
51
|
env: Record<string, string>;
|
|
52
52
|
}
|
|
53
53
|
/** The desktop's bundled server, or null when there is none on this computer (no app, an old app,
|
|
54
|
-
* an uninstalled one whose file was left behind,
|
|
54
|
+
* an uninstalled one whose file was left behind, a file this version cannot read, or a launch that
|
|
55
|
+
* is not the app's). */
|
|
55
56
|
export declare function readMcpLauncher(file?: string): McpLauncher | null;
|
|
56
57
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/auth.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
1
2
|
import { createHash } from 'node:crypto';
|
|
2
3
|
import { homedir } from 'node:os';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync, } from 'node:fs';
|
|
4
|
+
import { basename, dirname, join, resolve, sep } from 'node:path';
|
|
5
|
+
import { chmodSync, existsSync, readFileSync, writeFileSync, mkdirSync, } from 'node:fs';
|
|
5
6
|
// Reads/writes ~/.slates/agent-connection.json — the single file the
|
|
6
7
|
// Slates desktop app produces and the MCP/CLI consume.
|
|
7
8
|
//
|
|
@@ -42,9 +43,38 @@ export function setDefaultProjectId(projectId) {
|
|
|
42
43
|
export function readDefaultProjectId() {
|
|
43
44
|
return readConnection().defaultProjectId ?? null;
|
|
44
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Windows: strip what `path` inherits and leave the current user the only entry. The profile folder's
|
|
48
|
+
* ACL is no wall: Codex's sandbox group can read it. Full paths, because Git for Windows puts its own
|
|
49
|
+
* `whoami` first on PATH. A failure warns and carries on, so a locked-down machine can still sign in.
|
|
50
|
+
*/
|
|
51
|
+
function restrictToCurrentUser(path) {
|
|
52
|
+
const system32 = join(process.env.SystemRoot ?? 'C:\\Windows', 'System32');
|
|
53
|
+
try {
|
|
54
|
+
const whoami = execFileSync(join(system32, 'whoami.exe'), ['/user', '/fo', 'csv', '/nh'], { encoding: 'utf8', windowsHide: true });
|
|
55
|
+
const sid = /"(S-1-[\d-]+)"/.exec(whoami)?.[1];
|
|
56
|
+
if (!sid)
|
|
57
|
+
throw new Error(`no SID in ${whoami}`);
|
|
58
|
+
execFileSync(join(system32, 'icacls.exe'), [path, '/inheritance:r', '/grant:r', `*${sid}:F`], { stdio: 'ignore', windowsHide: true });
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
console.error(`[slates] could not limit ${path} to this user: ${error instanceof Error ? error.message : error}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
45
64
|
export function writeConnection(data) {
|
|
46
|
-
|
|
47
|
-
|
|
65
|
+
mkdirSync(AGENT_DIR, { recursive: true, mode: 0o700 });
|
|
66
|
+
// Owner-only, because this file holds both tokens. `mode` applies only when a file or folder is
|
|
67
|
+
// created, and the desktop may have made them first, so the modes are set before the tokens land.
|
|
68
|
+
if (process.platform === 'win32') {
|
|
69
|
+
if (!existsSync(CONNECTION_FILE))
|
|
70
|
+
writeFileSync(CONNECTION_FILE, '');
|
|
71
|
+
restrictToCurrentUser(CONNECTION_FILE);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
chmodSync(AGENT_DIR, 0o700);
|
|
75
|
+
if (existsSync(CONNECTION_FILE))
|
|
76
|
+
chmodSync(CONNECTION_FILE, 0o600);
|
|
77
|
+
}
|
|
48
78
|
writeFileSync(CONNECTION_FILE, JSON.stringify(data, null, 2), { mode: 0o600 });
|
|
49
79
|
}
|
|
50
80
|
export function setCloudToken(token) {
|
|
@@ -95,8 +125,44 @@ export function requireDesktop() {
|
|
|
95
125
|
// the transition tools while his app had them. A server started from this file is the app's own
|
|
96
126
|
// copy, so it is always the version that matches the app, and updates when the app does.
|
|
97
127
|
export const MCP_LAUNCHER_FILE = join(AGENT_DIR, 'mcp-server.json');
|
|
128
|
+
/** What `slate/src/main/agent/mcpLauncher.ts` `appMcpLaunch()` writes, and all it writes. */
|
|
129
|
+
const LAUNCHER_ENV = { ELECTRON_RUN_AS_NODE: '1', SLATES_MCP_BUNDLED: '1' };
|
|
130
|
+
/**
|
|
131
|
+
* Where the app installs: `electron-builder.yml`'s one-click per-user NSIS, and a Mac app dragged to
|
|
132
|
+
* either Applications folder. Slates ships no Linux build. An app run from anywhere else, or a
|
|
133
|
+
* lookalike folder, reads as no launcher, and the copy that was started simply runs as itself.
|
|
134
|
+
*/
|
|
135
|
+
function appInstallRoots() {
|
|
136
|
+
const home = homedir();
|
|
137
|
+
return [
|
|
138
|
+
join(process.env.LOCALAPPDATA || join(home, 'AppData', 'Local'), 'Programs', 'slates'),
|
|
139
|
+
resolve('/Applications/Slates.app'),
|
|
140
|
+
join(home, 'Applications', 'Slates.app'),
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
function isInstalled(command) {
|
|
144
|
+
const fold = (path) => (process.platform === 'win32' ? resolve(path).toLowerCase() : resolve(path));
|
|
145
|
+
return appInstallRoots().some((root) => fold(command).startsWith(fold(root) + sep));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Whether a launch is the app's own binary starting the server packaged beside it. The file is
|
|
149
|
+
* plain JSON a write tool could reach, and this process would run what it names at every start, so
|
|
150
|
+
* `cmd.exe /c ...`, an env carrying NODE_OPTIONS or a copy planted elsewhere must read as no launcher
|
|
151
|
+
* at all.
|
|
152
|
+
*/
|
|
153
|
+
function isAppLaunch(command, args, env) {
|
|
154
|
+
if (!/^slates(\.exe)?$/i.test(basename(command)) || args.length !== 1 || !isInstalled(command))
|
|
155
|
+
return false;
|
|
156
|
+
const appDir = dirname(command);
|
|
157
|
+
const serverPath = join('mcp-server', 'dist', 'server.mjs');
|
|
158
|
+
const packaged = [join(appDir, 'resources', serverPath), join(dirname(appDir), 'Resources', serverPath)];
|
|
159
|
+
const sameEnv = Object.keys(env).length === Object.keys(LAUNCHER_ENV).length &&
|
|
160
|
+
Object.entries(LAUNCHER_ENV).every(([key, value]) => env[key] === value);
|
|
161
|
+
return sameEnv && packaged.includes(resolve(args[0]));
|
|
162
|
+
}
|
|
98
163
|
/** The desktop's bundled server, or null when there is none on this computer (no app, an old app,
|
|
99
|
-
* an uninstalled one whose file was left behind,
|
|
164
|
+
* an uninstalled one whose file was left behind, a file this version cannot read, or a launch that
|
|
165
|
+
* is not the app's). */
|
|
100
166
|
export function readMcpLauncher(file = MCP_LAUNCHER_FILE) {
|
|
101
167
|
try {
|
|
102
168
|
const raw = JSON.parse(readFileSync(file, 'utf-8'));
|
|
@@ -111,6 +177,8 @@ export function readMcpLauncher(file = MCP_LAUNCHER_FILE) {
|
|
|
111
177
|
// The app was moved or uninstalled since it wrote the file: nothing to start.
|
|
112
178
|
if (!existsSync(raw.command) || (raw.args[0] && !existsSync(raw.args[0])))
|
|
113
179
|
return null;
|
|
180
|
+
if (!isAppLaunch(raw.command, raw.args, env))
|
|
181
|
+
return null;
|
|
114
182
|
return { version: raw.version, command: raw.command, args: raw.args, env };
|
|
115
183
|
}
|
|
116
184
|
catch {
|
|
@@ -16,6 +16,10 @@ export declare const BLENDER_SETUP_HINT: string;
|
|
|
16
16
|
export declare class BlenderNotRunningError extends Error {
|
|
17
17
|
constructor();
|
|
18
18
|
}
|
|
19
|
+
/** Something answered on the bridge ports, and it is not a Blender this client may drive. */
|
|
20
|
+
export declare class BlenderPeerError extends Error {
|
|
21
|
+
constructor(message: string);
|
|
22
|
+
}
|
|
19
23
|
/** Raised when Blender executed the code and Python threw. Carries the traceback. */
|
|
20
24
|
export declare class BlenderExecError extends Error {
|
|
21
25
|
readonly stdout: string;
|
|
@@ -44,7 +48,11 @@ export declare class BlenderBridgeClient {
|
|
|
44
48
|
call(body: string, opts?: {
|
|
45
49
|
timeoutMs?: number;
|
|
46
50
|
}): Promise<unknown>;
|
|
47
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* True when a Blender this client may drive answers, false when nothing listens. Throws
|
|
53
|
+
* when a listener cannot be used: the reason is what the user needs (update the add-on,
|
|
54
|
+
* restart the bridge), and "no Blender found" would send them the wrong way.
|
|
55
|
+
*/
|
|
48
56
|
isReachable(): Promise<boolean>;
|
|
49
57
|
}
|
|
50
58
|
//# sourceMappingURL=blender.d.ts.map
|
package/dist/clients/blender.js
CHANGED
|
@@ -1,16 +1,42 @@
|
|
|
1
|
+
import { createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
1
3
|
import net from 'node:net';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { AGENT_DIR } from '../auth.js';
|
|
2
6
|
// Thin client for the Slates Blender add-on's localhost execution bridge.
|
|
3
7
|
//
|
|
4
|
-
// Wire protocol (matches the add-on's `bridge/server.py`,
|
|
5
|
-
// Lab's `blender_mcp` protocol)
|
|
8
|
+
// Wire protocol (matches the add-on's `bridge_auth.py`, in front of `bridge/server.py`,
|
|
9
|
+
// which is Blender Lab's `blender_mcp` protocol). Requests and responses are
|
|
10
|
+
// NUL-delimited JSON over plain TCP, one request per connection:
|
|
6
11
|
//
|
|
7
|
-
// -> {"type":"
|
|
8
|
-
// <- {"status":"ok","
|
|
9
|
-
//
|
|
12
|
+
// -> {"type":"hello","nonce":"<client nonce>"}\0
|
|
13
|
+
// <- {"status":"ok","nonce":"<server nonce>","proof":"<mac>"}\0
|
|
14
|
+
// -> {"type":"execute_sealed","nonce":"<server nonce>","payload":"<json>","mac":"<mac>"}\0
|
|
15
|
+
// <- {"status":"ok","result":{"sealed":"<json>","mac":"<mac>"}}\0
|
|
10
16
|
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
17
|
+
// `payload` is the upstream request `{"type":"execute","code":"...","strict_json":false}`
|
|
18
|
+
// and `sealed` the upstream reply `{"status":"ok","result":{...},"stdout":"...","stderr":"..."}`
|
|
19
|
+
// or `{"status":"error","message":"<traceback>"}`, each as a string so both sides MAC the
|
|
20
|
+
// same bytes. A mac is HMAC-SHA256 of `<label>\0<nonce>\0<body>` under the token the add-on
|
|
21
|
+
// writes to ~/.slates/blender-bridge-<port>.token each time it binds:
|
|
22
|
+
//
|
|
23
|
+
// hello label "hello", the client nonce, body the server nonce
|
|
24
|
+
// request label "request", the server nonce, body the payload
|
|
25
|
+
// reply label "reply", the server nonce, body the sealed string
|
|
26
|
+
//
|
|
27
|
+
// 🚨 THE TOKEN NEVER CROSSES THE SOCKET, AND NO CODE IS SENT BEFORE THE PROOF. Anything
|
|
28
|
+
// local can bind a port in this range, and on Windows it can share a port the add-on holds
|
|
29
|
+
// (`__init__.py` `_port_is_free`). A listener without the token cannot answer the hello, so
|
|
30
|
+
// it is sent no code, and it cannot seal a reply, so a forged `filePath` cannot reach the
|
|
31
|
+
// desktop's upload route. A process sharing the add-on's port is the one exception: the hello
|
|
32
|
+
// can land on the add-on and the signed request on that process, which can then read the
|
|
33
|
+
// code. It still cannot change it, forge it or seal a reply. Each nonce is good for one
|
|
34
|
+
// request, so a captured one replays nothing. A later incompatible change takes a new request
|
|
35
|
+
// type: the older side answers "Unknown request type", which is how an old add-on is told
|
|
36
|
+
// apart here.
|
|
37
|
+
//
|
|
38
|
+
// The add-on executes on Blender's main thread via a timer, so a request is
|
|
39
|
+
// serviced within a tick rather than immediately: the socket stays open until
|
|
14
40
|
// the reply lands, and long jobs (renders) hold it open for as long as they
|
|
15
41
|
// take. That is why the timeout here is generous and configurable per call
|
|
16
42
|
// rather than a single global value.
|
|
@@ -24,6 +50,9 @@ const DEFAULT_TIMEOUT_MS = 60_000;
|
|
|
24
50
|
// Renders are the one call that legitimately runs for minutes.
|
|
25
51
|
export const RENDER_TIMEOUT_MS = 15 * 60_000;
|
|
26
52
|
const CONNECT_TIMEOUT_MS = 1_500;
|
|
53
|
+
// Bounds a listener that accepts and never answers, on each port walked. Blender answers a
|
|
54
|
+
// hello on its next timer tick unless its main thread is busy.
|
|
55
|
+
const HELLO_TIMEOUT_MS = 15_000;
|
|
27
56
|
/**
|
|
28
57
|
* Where the add-on comes from, and how to switch it on. ONE string.
|
|
29
58
|
*
|
|
@@ -48,6 +77,26 @@ export class BlenderNotRunningError extends Error {
|
|
|
48
77
|
this.name = 'BlenderNotRunningError';
|
|
49
78
|
}
|
|
50
79
|
}
|
|
80
|
+
/** Something answered on the bridge ports, and it is not a Blender this client may drive. */
|
|
81
|
+
export class BlenderPeerError extends Error {
|
|
82
|
+
constructor(message) {
|
|
83
|
+
super(message);
|
|
84
|
+
this.name = 'BlenderPeerError';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const ADDON_OUTDATED_MESSAGE = 'The Slates add-on in this Blender is too old for this version of Slates, which only ' +
|
|
88
|
+
'drives an add-on that proves itself. Update it: in Blender open Edit > Preferences > ' +
|
|
89
|
+
'Get Extensions, choose Refresh Remote, then Update on Slates, or reinstall from ' +
|
|
90
|
+
'https://slates.video/blender. Then restart Blender.';
|
|
91
|
+
const UNVERIFIED_MESSAGE = `Something is listening on ${HOST}:${BASE_PORT}-${BASE_PORT + PORT_FALLBACKS} but could not ` +
|
|
92
|
+
'prove it is the Slates add-on, so nothing was sent to it. In Blender, stop and start the ' +
|
|
93
|
+
'bridge from the Slates tab, which writes a new token to ~/.slates. If that does not clear ' +
|
|
94
|
+
'it, Blender is running as another user or another program holds the port.';
|
|
95
|
+
const UNSIGNED_REPLY_MESSAGE = 'Blender did not return a signed reply, so the result was thrown away. Check the Blender ' +
|
|
96
|
+
'window and retry. If it repeats, stop and start the bridge from the Slates tab.';
|
|
97
|
+
/** A listener took the connection and said nothing in time. */
|
|
98
|
+
class BlenderSilentError extends Error {
|
|
99
|
+
}
|
|
51
100
|
/** Raised when Blender executed the code and Python threw. Carries the traceback. */
|
|
52
101
|
export class BlenderExecError extends Error {
|
|
53
102
|
stdout;
|
|
@@ -59,6 +108,26 @@ export class BlenderExecError extends Error {
|
|
|
59
108
|
this.stderr = stderr;
|
|
60
109
|
}
|
|
61
110
|
}
|
|
111
|
+
function bridgeMac(token, label, nonce, body) {
|
|
112
|
+
return createHmac('sha256', token).update(`${label}\0${nonce}\0${body}`, 'utf8').digest('hex');
|
|
113
|
+
}
|
|
114
|
+
function macMatches(expected, received) {
|
|
115
|
+
if (typeof received !== 'string')
|
|
116
|
+
return false;
|
|
117
|
+
const a = Buffer.from(expected);
|
|
118
|
+
const b = Buffer.from(received);
|
|
119
|
+
return a.length === b.length && timingSafeEqual(a, b);
|
|
120
|
+
}
|
|
121
|
+
/** The add-on rewrites this file on every bind, so it is read fresh for each handshake. */
|
|
122
|
+
function readBridgeToken(port) {
|
|
123
|
+
try {
|
|
124
|
+
const token = readFileSync(join(AGENT_DIR, `blender-bridge-${port}.token`), 'utf8').trim();
|
|
125
|
+
return /^[0-9a-f]{64}$/.test(token) ? token : null;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
62
131
|
/**
|
|
63
132
|
* Resolve the installed add-on package regardless of what Blender named it.
|
|
64
133
|
*
|
|
@@ -107,17 +176,6 @@ function connect(port) {
|
|
|
107
176
|
});
|
|
108
177
|
});
|
|
109
178
|
}
|
|
110
|
-
async function connectAny() {
|
|
111
|
-
for (let port = BASE_PORT; port <= BASE_PORT + PORT_FALLBACKS; port++) {
|
|
112
|
-
try {
|
|
113
|
-
return await connect(port);
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
// Try the next port in the range.
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
throw new BlenderNotRunningError();
|
|
120
|
-
}
|
|
121
179
|
function request(socket, payload, timeoutMs) {
|
|
122
180
|
return new Promise((resolve, reject) => {
|
|
123
181
|
let buffer = '';
|
|
@@ -130,7 +188,7 @@ function request(socket, payload, timeoutMs) {
|
|
|
130
188
|
socket.destroy();
|
|
131
189
|
fn();
|
|
132
190
|
};
|
|
133
|
-
const timer = setTimeout(() => finish(() => reject(new
|
|
191
|
+
const timer = setTimeout(() => finish(() => reject(new BlenderSilentError(`Blender did not respond within ${Math.round(timeoutMs / 1000)}s. ` +
|
|
134
192
|
'It may be busy with a modal operator — check the Blender window.'))), timeoutMs);
|
|
135
193
|
socket.setEncoding('utf8');
|
|
136
194
|
socket.on('data', (chunk) => {
|
|
@@ -153,6 +211,69 @@ function request(socket, payload, timeoutMs) {
|
|
|
153
211
|
socket.write(payload + '\0');
|
|
154
212
|
});
|
|
155
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* The session on `port`, null with no listener there, or why the listener cannot be used. Throws
|
|
216
|
+
* when the listener is silent and this port has a token: that is the add-on with its main thread
|
|
217
|
+
* busy, and walking on would run the work in whichever other .blend is open.
|
|
218
|
+
*/
|
|
219
|
+
async function helloOn(port) {
|
|
220
|
+
let socket;
|
|
221
|
+
try {
|
|
222
|
+
socket = await connect(port);
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
const clientNonce = randomBytes(16).toString('hex');
|
|
228
|
+
let reply;
|
|
229
|
+
try {
|
|
230
|
+
reply = await request(socket, JSON.stringify({ type: 'hello', nonce: clientNonce }), HELLO_TIMEOUT_MS);
|
|
231
|
+
}
|
|
232
|
+
catch (err) {
|
|
233
|
+
if (err instanceof BlenderSilentError && readBridgeToken(port))
|
|
234
|
+
throw err;
|
|
235
|
+
return err;
|
|
236
|
+
}
|
|
237
|
+
if (typeof reply !== 'object' || reply === null)
|
|
238
|
+
return new BlenderPeerError(UNVERIFIED_MESSAGE);
|
|
239
|
+
if (reply.status === 'error' && typeof reply.message === 'string' && reply.message.startsWith('Unknown request type')) {
|
|
240
|
+
return new BlenderPeerError(ADDON_OUTDATED_MESSAGE);
|
|
241
|
+
}
|
|
242
|
+
const token = readBridgeToken(port);
|
|
243
|
+
if (!token || typeof reply.nonce !== 'string' || !macMatches(bridgeMac(token, 'hello', clientNonce, reply.nonce), reply.proof)) {
|
|
244
|
+
return new BlenderPeerError(UNVERIFIED_MESSAGE);
|
|
245
|
+
}
|
|
246
|
+
return { port, token, nonce: reply.nonce };
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* The first port whose listener proves it is the add-on. A listener that cannot does not stop
|
|
250
|
+
* the walk, because the add-on steps past a held port. When none proves itself, the failure
|
|
251
|
+
* that tells the user the most wins: an old add-on, then a silent listener, then a stranger.
|
|
252
|
+
*/
|
|
253
|
+
async function authenticate() {
|
|
254
|
+
const failures = [];
|
|
255
|
+
for (let port = BASE_PORT; port <= BASE_PORT + PORT_FALLBACKS; port++) {
|
|
256
|
+
const outcome = await helloOn(port);
|
|
257
|
+
if (outcome === null)
|
|
258
|
+
continue;
|
|
259
|
+
if (!(outcome instanceof Error))
|
|
260
|
+
return outcome;
|
|
261
|
+
failures.push(outcome);
|
|
262
|
+
}
|
|
263
|
+
const outdated = failures.find((f) => f.message === ADDON_OUTDATED_MESSAGE);
|
|
264
|
+
const silent = failures.find((f) => !(f instanceof BlenderPeerError));
|
|
265
|
+
throw outdated ?? silent ?? failures[0] ?? new BlenderNotRunningError();
|
|
266
|
+
}
|
|
267
|
+
/** Open what the add-on sealed. An unsealed reply, error or not, is untrusted text and is dropped. */
|
|
268
|
+
function unseal(res, session) {
|
|
269
|
+
const seal = res?.result;
|
|
270
|
+
if (res?.status !== 'ok' || typeof seal?.sealed !== 'string')
|
|
271
|
+
throw new BlenderPeerError(UNSIGNED_REPLY_MESSAGE);
|
|
272
|
+
if (!macMatches(bridgeMac(session.token, 'reply', session.nonce, seal.sealed), seal.mac)) {
|
|
273
|
+
throw new BlenderPeerError(UNSIGNED_REPLY_MESSAGE);
|
|
274
|
+
}
|
|
275
|
+
return JSON.parse(seal.sealed);
|
|
276
|
+
}
|
|
156
277
|
export class BlenderBridgeClient {
|
|
157
278
|
/**
|
|
158
279
|
* Execute Python in Blender and return whatever the code assigned to
|
|
@@ -161,9 +282,16 @@ export class BlenderBridgeClient {
|
|
|
161
282
|
* itself, which it cannot do if the error is about serialization.
|
|
162
283
|
*/
|
|
163
284
|
async execute(code, opts) {
|
|
164
|
-
const
|
|
285
|
+
const session = await authenticate();
|
|
286
|
+
const socket = await connect(session.port);
|
|
165
287
|
const payload = JSON.stringify({ type: 'execute', code, strict_json: false });
|
|
166
|
-
const
|
|
288
|
+
const sealed = JSON.stringify({
|
|
289
|
+
type: 'execute_sealed',
|
|
290
|
+
nonce: session.nonce,
|
|
291
|
+
payload,
|
|
292
|
+
mac: bridgeMac(session.token, 'request', session.nonce, payload),
|
|
293
|
+
});
|
|
294
|
+
const res = unseal(await request(socket, sealed, opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS), session);
|
|
167
295
|
const stdout = res.stdout ?? '';
|
|
168
296
|
const stderr = res.stderr ?? '';
|
|
169
297
|
if (res.status !== 'ok') {
|
|
@@ -180,15 +308,20 @@ export class BlenderBridgeClient {
|
|
|
180
308
|
const { result } = await this.execute(`${PRELUDE}\n${body}`, opts);
|
|
181
309
|
return result;
|
|
182
310
|
}
|
|
183
|
-
/**
|
|
311
|
+
/**
|
|
312
|
+
* True when a Blender this client may drive answers, false when nothing listens. Throws
|
|
313
|
+
* when a listener cannot be used: the reason is what the user needs (update the add-on,
|
|
314
|
+
* restart the bridge), and "no Blender found" would send them the wrong way.
|
|
315
|
+
*/
|
|
184
316
|
async isReachable() {
|
|
185
317
|
try {
|
|
186
|
-
|
|
187
|
-
socket.destroy();
|
|
318
|
+
await authenticate();
|
|
188
319
|
return true;
|
|
189
320
|
}
|
|
190
|
-
catch {
|
|
191
|
-
|
|
321
|
+
catch (err) {
|
|
322
|
+
if (err instanceof BlenderNotRunningError)
|
|
323
|
+
return false;
|
|
324
|
+
throw err;
|
|
192
325
|
}
|
|
193
326
|
}
|
|
194
327
|
}
|
package/dist/clients/cloud.d.ts
CHANGED
package/dist/clients/cloud.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { requireCloudToken, tokenHash } from '../auth.js';
|
|
2
2
|
import { SLATES_API_URL } from '../api-url.js';
|
|
3
3
|
const FALLBACK_CLOUD_BASE_URL = SLATES_API_URL;
|
|
4
|
-
// The slates_sk_ bearer is attached to every cloud request
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// or
|
|
8
|
-
//
|
|
9
|
-
function resolveCloudBaseUrl() {
|
|
10
|
-
const override = process.env.SLATES_CLOUD_BASE_URL;
|
|
4
|
+
// The slates_sk_ bearer is attached to every cloud request, and an env block in a
|
|
5
|
+
// plugin or project config can reach this process. So SLATES_CLOUD_BASE_URL may
|
|
6
|
+
// point only at this machine (a local slates-api) or the production host; any
|
|
7
|
+
// other host, https or not, is ignored in favour of production. It is not a way
|
|
8
|
+
// to reach a staging host: add one here by name if one ever exists.
|
|
9
|
+
export function resolveCloudBaseUrl(override = process.env.SLATES_CLOUD_BASE_URL) {
|
|
11
10
|
if (!override)
|
|
12
11
|
return FALLBACK_CLOUD_BASE_URL;
|
|
13
12
|
try {
|
|
14
13
|
const u = new URL(override);
|
|
15
|
-
const isLoopback = u.hostname === 'localhost' || u.hostname === '127.0.0.1';
|
|
16
|
-
|
|
14
|
+
const isLoopback = u.hostname === 'localhost' || u.hostname === '127.0.0.1' || u.hostname === '[::1]';
|
|
15
|
+
const isProduction = u.protocol === 'https:' && u.hostname === new URL(FALLBACK_CLOUD_BASE_URL).hostname;
|
|
16
|
+
if (isProduction || (isLoopback && (u.protocol === 'http:' || u.protocol === 'https:'))) {
|
|
17
17
|
return override.replace(/\/+$/, '');
|
|
18
18
|
}
|
|
19
|
-
console.error(`[slates] Ignoring SLATES_CLOUD_BASE_URL="${override}": must be
|
|
19
|
+
console.error(`[slates] Ignoring SLATES_CLOUD_BASE_URL="${override}": it must be this machine or ${FALLBACK_CLOUD_BASE_URL}. ` +
|
|
20
20
|
`Falling back to ${FALLBACK_CLOUD_BASE_URL} so the auth token is not exposed.`);
|
|
21
21
|
}
|
|
22
22
|
catch {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './auth.js';
|
|
2
|
-
export { SlatesCloudClient, type SlatesUserInfo, type CreditsBalance, type ModelRegistryResponse } from './clients/cloud.js';
|
|
2
|
+
export { SlatesCloudClient, DEFAULT_CLOUD_BASE_URL, resolveCloudBaseUrl, type SlatesUserInfo, type CreditsBalance, type ModelRegistryResponse } from './clients/cloud.js';
|
|
3
3
|
export { SlatesDesktopClient, setDesktopClientIdentity, type DesktopHealth } from './clients/desktop.js';
|
|
4
4
|
export { BRAIN_SHAPE, SKILLS } from './skills/content.js';
|
|
5
5
|
export { BRAIN_CACHE, brainFiles, clearServedBrain, refreshServedBrain, servedBrain, useBrainSource, type LockedGuide, type ServedBrain } from './skills/served.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './auth.js';
|
|
2
|
-
export { SlatesCloudClient } from './clients/cloud.js';
|
|
2
|
+
export { SlatesCloudClient, DEFAULT_CLOUD_BASE_URL, resolveCloudBaseUrl } from './clients/cloud.js';
|
|
3
3
|
export { SlatesDesktopClient, setDesktopClientIdentity } from './clients/desktop.js';
|
|
4
4
|
export { BRAIN_SHAPE, SKILLS } from './skills/content.js';
|
|
5
5
|
export { BRAIN_CACHE, brainFiles, clearServedBrain, refreshServedBrain, servedBrain, useBrainSource } from './skills/served.js';
|