crewaid-selfhost 0.1.13 → 0.1.14

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 CHANGED
@@ -13,8 +13,21 @@ npx crewaid-selfhost reset-password you@example.com
13
13
  local network, or a domain with HTTPS — generates every secret, writes
14
14
  `compose.yml` and `.env` to `~/crewaid` (`--dir` to change), starts the server
15
15
  and tells you what to type into the **Crewaid Lite** app
16
- ([macOS](https://downloads.crewaid.io/desktop/selfhosted/mac),
17
- [Windows](https://downloads.crewaid.io/desktop/selfhosted/windows)).
16
+ ([Apple silicon](https://downloads.crewaid.io/desktop/selfhosted/mac-arm64),
17
+ [Intel Mac](https://downloads.crewaid.io/desktop/selfhosted/mac-intel),
18
+ [Windows](https://downloads.crewaid.io/desktop/selfhosted/windows),
19
+ [Linux x64 .deb](https://downloads.crewaid.io/desktop/selfhosted/linux)).
20
+
21
+ On a Docker host without Node.js, pass the subcommand to the same script:
22
+
23
+ ```sh
24
+ curl -fsSL https://downloads.crewaid.io/install.sh | sh -s -- status
25
+ curl -fsSL https://downloads.crewaid.io/install.sh | sh -s -- update
26
+ curl -fsSL https://downloads.crewaid.io/install.sh | sh -s -- reset-password you@example.com
27
+ ```
28
+
29
+ Use `--mode lan --advertise-url` with the exact HTTP origin the app will
30
+ use when the client sees an address different from the server’s local address.
18
31
 
19
32
  Needs Docker Desktop (macOS, Windows) or Docker Engine with Compose v2 (Linux).
20
33
  `crewaid-selfhost --help` lists every option.
@@ -94,6 +94,7 @@ services:
94
94
  SANDBOX_SUPERVISOR_PORT: '7300'
95
95
  SANDBOX_IMAGE: ghcr.io/natanael-exe/crewaid-sandbox:${CREWAID_VERSION}
96
96
  SANDBOX_NETWORK: crewaid-sandboxes
97
+ SANDBOX_CPUS: ${SANDBOX_CPUS:-2}
97
98
  # Nothing is published: the orchestrator reaches a computer's screen,
98
99
  # DevTools and bridge at the computer's own address on the sandbox
99
100
  # network, which it joins below — the one address the fence lets in.
@@ -154,6 +155,7 @@ services:
154
155
  # Must match the supervisor's: it refuses any other image or network.
155
156
  SANDBOX_IMAGE: ghcr.io/natanael-exe/crewaid-sandbox:${CREWAID_VERSION}
156
157
  SANDBOX_NETWORK: crewaid-sandboxes
158
+ SANDBOX_CPUS: ${SANDBOX_CPUS:-2}
157
159
  # No Docker socket here (D-200): computers are started by the supervisor.
158
160
  SANDBOX_SUPERVISOR_URL: http://sandbox-supervisor:7300
159
161
  SANDBOX_SUPERVISOR_SECRET: ${SANDBOX_SUPERVISOR_SECRET:?Set SANDBOX_SUPERVISOR_SECRET (openssl rand -hex 32)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crewaid-selfhost",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "Install, update and look after a self-hosted Crewaid server (Docker).",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",
package/src/cli.mjs CHANGED
@@ -6,7 +6,14 @@ import { fileURLToPath } from 'node:url';
6
6
  import { generateSecrets, supervisorSecret } from './secrets.mjs';
7
7
  import { parseEnv, renderEnv, setEnvValue } from './env.mjs';
8
8
  import { lanAddress, pickSandboxSubnet, portIsFree } from './network.mjs';
9
- import { capture, compose, dockerSubnets, existingProject, preflight } from './docker.mjs';
9
+ import {
10
+ capture,
11
+ captureCompose,
12
+ compose,
13
+ dockerSubnets,
14
+ existingProject,
15
+ preflight,
16
+ } from './docker.mjs';
10
17
 
11
18
  const HERE = path.dirname(fileURLToPath(import.meta.url));
12
19
  const DOWNLOADS = 'https://downloads.crewaid.io/desktop/selfhosted';
@@ -28,6 +35,8 @@ const HELP = `crewaid-selfhost — run Crewaid on your own machine or server (Do
28
35
  local: this computer only (http://localhost:<port>)
29
36
  lan: your local network (http://<lan-ip>:<port>, unencrypted)
30
37
  domain: a domain name pointed here, HTTPS via Let's Encrypt
38
+ --advertise-url <url> exact HTTP address the app uses with --mode lan
39
+ --sandbox-cpus <n> CPU quota per computer (default: up to 2)
31
40
  --domain <name> for --mode domain
32
41
  --port <n> default 3000
33
42
  --version <x.y.z> release to run (default: this installer's)
@@ -86,7 +95,10 @@ async function exists(file) {
86
95
  * The address the desktop app will use and how the server listens, for a mode.
87
96
  * Pure, so the three shapes are tested without a terminal or Docker.
88
97
  */
89
- export function addressPlan({ mode, port, domain, lan }) {
98
+ export function addressPlan({ mode, port, domain, lan, advertised }) {
99
+ if (advertised !== undefined && mode !== 'lan') {
100
+ throw new Error('--advertise-url is used with --mode lan.');
101
+ }
90
102
  if (mode === 'domain') {
91
103
  if (!domain) throw new Error('--mode domain needs --domain <name>');
92
104
  return {
@@ -98,12 +110,24 @@ export function addressPlan({ mode, port, domain, lan }) {
98
110
  };
99
111
  }
100
112
  if (mode === 'lan') {
101
- if (!lan)
113
+ if (!advertised && !lan) {
114
+ throw new Error('Could not detect a local network address. Supply --advertise-url.');
115
+ }
116
+ const url = parseAdvertisedUrl(advertised || `http://${lan}:${port}`);
117
+ if (
118
+ url?.protocol !== 'http:' ||
119
+ url.username ||
120
+ url.password ||
121
+ url.pathname !== '/' ||
122
+ url.search ||
123
+ url.hash
124
+ ) {
102
125
  throw new Error(
103
- 'Could not find this machine’s local network address; use --mode local or --mode domain.',
126
+ '--advertise-url needs an HTTP origin, for example http://192.168.1.20:3000.',
104
127
  );
128
+ }
105
129
  return {
106
- BETTER_AUTH_URL: `http://${lan}:${port}`,
130
+ BETTER_AUTH_URL: url.origin,
107
131
  CREWAID_BIND: '0.0.0.0',
108
132
  CREWAID_PORT: String(port),
109
133
  };
@@ -115,6 +139,27 @@ export function addressPlan({ mode, port, domain, lan }) {
115
139
  };
116
140
  }
117
141
 
142
+ function parseAdvertisedUrl(value) {
143
+ try {
144
+ return new URL(value);
145
+ } catch {
146
+ return null;
147
+ }
148
+ }
149
+
150
+ /** Docker's CPU quota cannot exceed the daemon's available vCPUs. */
151
+ export function sandboxCpus(available, requested) {
152
+ const max = Math.min(4, Number(available));
153
+ if (!Number.isSafeInteger(Number(available)) || max < 1) {
154
+ throw new Error('Could not determine the Docker daemon’s CPU count (docker info).');
155
+ }
156
+ const cpus = requested === undefined ? Math.min(2, max) : Number(requested);
157
+ if (!Number.isFinite(cpus) || cpus < 1 || cpus > max) {
158
+ throw new Error(`--sandbox-cpus must be between 1 and ${max} on this Docker host.`);
159
+ }
160
+ return String(cpus);
161
+ }
162
+
118
163
  async function ask(rl, question, fallback) {
119
164
  if (!rl) return fallback;
120
165
  const answer = (await rl.question(`${question} [${fallback}] `)).trim();
@@ -175,12 +220,28 @@ export function readiness(health) {
175
220
  }
176
221
 
177
222
  /** Wait until the server is ready; the last answer either way. */
178
- async function waitForReady(dir, port, timeoutMs = 300_000) {
179
- const deadline = Date.now() + timeoutMs;
223
+ async function waitForReady(dir, port, started) {
224
+ const deadline = Date.now() + 300_000;
180
225
  let health = null;
226
+ let nextEgressCheck = Date.now();
181
227
  while (Date.now() < deadline) {
182
228
  health = await readHealth(dir, port);
183
229
  if (readiness(health).ready) return health;
230
+ if (Date.now() >= nextEgressCheck) {
231
+ nextEgressCheck = Date.now() + 8000;
232
+ const logs = captureCompose(dir, ['logs', '--no-color', '--since', started, 'egress']);
233
+ if (
234
+ /Sandbox egress is blocked: br_netfilter is unavailable|modprobe exited .*br_netfilter/.test(
235
+ logs.stdout,
236
+ )
237
+ ) {
238
+ throw new Error(
239
+ 'The sandbox firewall needs br_netfilter on the Linux Docker host. ' +
240
+ 'Run sudo modprobe br_netfilter, then docker compose restart egress from the install folder. ' +
241
+ 'For reboot persistence, add br_netfilter to /etc/modules-load.d/crewaid.conf.',
242
+ );
243
+ }
244
+ }
184
245
  await new Promise((resolve) => setTimeout(resolve, 2000));
185
246
  }
186
247
  return health;
@@ -236,6 +297,12 @@ async function init(options) {
236
297
  console.log(' domain the internet, through a domain name pointed here (HTTPS)');
237
298
  mode = await ask(rl, 'Choose', 'local');
238
299
  }
300
+ if (
301
+ ('advertise-url' in options && !options['advertise-url']) ||
302
+ ('sandbox-cpus' in options && !options['sandbox-cpus'])
303
+ ) {
304
+ return fail('--advertise-url and --sandbox-cpus require a value.');
305
+ }
239
306
  if (!['local', 'lan', 'domain'].includes(mode))
240
307
  return fail(`Unknown mode "${mode}": use local, lan or domain.`);
241
308
  const domain =
@@ -247,7 +314,18 @@ async function init(options) {
247
314
  return fail(`Port ${port} is already in use on this machine. Choose another with --port.`);
248
315
  }
249
316
  const lan = process.env.CREWAID_HOST_LAN_IP || lanAddress();
250
- const plan = addressPlan({ mode, port, domain, lan });
317
+ const advertised =
318
+ options['advertise-url'] ??
319
+ (mode === 'lan'
320
+ ? await ask(
321
+ rl,
322
+ 'HTTP address the app will use (use the client-facing address through NAT)',
323
+ lan ? `http://${lan}:${port}` : '',
324
+ )
325
+ : undefined);
326
+ const plan = addressPlan({ mode, port, domain, lan, advertised });
327
+ const cpuInfo = capture('docker', ['info', '--format', '{{.NCPU}}']);
328
+ const cpus = sandboxCpus(cpuInfo.stdout, options['sandbox-cpus']);
251
329
  const version = options.version ?? (await ownVersion());
252
330
  const { subnet, orchestrator } = pickSandboxSubnet(dockerSubnets());
253
331
 
@@ -261,6 +339,7 @@ async function init(options) {
261
339
  ...plan,
262
340
  CREWAID_SANDBOX_SUBNET: subnet,
263
341
  CREWAID_ORCHESTRATOR_ADDRESS: orchestrator,
342
+ SANDBOX_CPUS: cpus,
264
343
  SANDBOX_MAX_RUNNING: '2',
265
344
  ...generateSecrets(),
266
345
  }),
@@ -281,12 +360,13 @@ async function init(options) {
281
360
  }
282
361
 
283
362
  console.log(`\nStarting Crewaid ${version} (the first start downloads about 2 GB)…`);
363
+ const started = new Date().toISOString();
284
364
  const code = await compose(dir, ['up', '-d']);
285
365
  if (code !== 0)
286
366
  return fail(
287
367
  `docker compose up failed (exit ${code}). Logs: cd ${dir} && docker compose logs`,
288
368
  );
289
- const health = await waitForReady(dir, port);
369
+ const health = await waitForReady(dir, port, started);
290
370
  const state = readiness(health);
291
371
  if (!state.ready) {
292
372
  return fail(
@@ -298,14 +378,19 @@ async function init(options) {
298
378
  Crewaid ${health.version} is running.
299
379
 
300
380
  1. Download Crewaid Lite:
301
- macOS ${DOWNLOADS}/mac
302
- Windows ${DOWNLOADS}/windows
381
+ Mac (Apple silicon) ${DOWNLOADS}/mac-arm64
382
+ Mac (Intel) ${DOWNLOADS}/mac-intel
383
+ Windows ${DOWNLOADS}/windows
384
+ Linux (.deb, x64) ${DOWNLOADS}/linux
303
385
  2. Open it and enter this address: ${plan.BETTER_AUTH_URL}
304
386
  3. Create your account — the first one is yours; anyone who can reach the
305
387
  address can create their own.
306
388
 
307
- Later: \`npx crewaid-selfhost update\` for new releases, \`npx crewaid-selfhost reset-password <email>\`
308
- if someone forgets theirs. Everything lives in ${dir}.`);
389
+ 4. Open Settings → Models and add a provider and model.
390
+
391
+ To check health, update, or reset a password without Node.js, use:
392
+ curl -fsSL https://downloads.crewaid.io/install.sh | sh -s -- status --dir "${dir}"
393
+ Replace status with update or reset-password <email> as needed.`);
309
394
  return 0;
310
395
  } finally {
311
396
  rl?.close();
@@ -320,13 +405,17 @@ async function update(options) {
320
405
  if (!(await exists(envFile)))
321
406
  return fail(`No Crewaid server in ${dir}. Install one with \`crewaid-selfhost init\`.`);
322
407
  const text = await readFile(envFile, 'utf8');
323
- const current = parseEnv(text).CREWAID_VERSION;
408
+ const env = parseEnv(text);
409
+ const current = env.CREWAID_VERSION;
410
+ const cpus = env.SANDBOX_CPUS?.trim()
411
+ ? undefined
412
+ : sandboxCpus(capture('docker', ['info', '--format', '{{.NCPU}}']).stdout);
324
413
  const version = options.version ?? (await ownVersion());
325
414
  console.log(`Updating ${dir} from ${current} to ${version}.`);
326
415
  // The compose file belongs to the release; .env belongs to the operator and
327
- // only its version line changes (and a secret a newer release needs is added).
416
+ // upgrade fills in missing defaults and retains operator settings.
328
417
  await writeFile(path.join(dir, 'compose.yml'), await composeTemplate());
329
- await writeFile(envFile, updateEnvironment(text, version), { mode: 0o600 });
418
+ await writeFile(envFile, updateEnvironment(text, version, cpus), { mode: 0o600 });
330
419
  await returnOwnership(dir, ['compose.yml', '.env']);
331
420
  let code = await compose(dir, ['pull']);
332
421
  if (code !== 0) {
@@ -335,10 +424,11 @@ async function update(options) {
335
424
  '(https://github.com/natanael-exe — crewaid-orchestrator) and that this machine is online.',
336
425
  );
337
426
  }
427
+ const started = new Date().toISOString();
338
428
  code = await compose(dir, ['up', '-d']);
339
429
  if (code !== 0)
340
430
  return fail(`docker compose up failed (exit ${code}). Logs: cd ${dir} && docker compose logs`);
341
- const health = await waitForReady(dir, Number(parseEnv(text).CREWAID_PORT ?? 3000));
431
+ const health = await waitForReady(dir, Number(env.CREWAID_PORT ?? 3000), started);
342
432
  const state = readiness(health);
343
433
  if (!state.ready) {
344
434
  return fail(
@@ -349,9 +439,13 @@ async function update(options) {
349
439
  return 0;
350
440
  }
351
441
 
352
- /** Add the supervisor key once when upgrading an older install; retain every existing key. */
353
- export function updateEnvironment(text, version) {
354
- if (!parseEnv(text).SANDBOX_SUPERVISOR_SECRET) {
442
+ /** Fill in missing values when upgrading an older install. */
443
+ export function updateEnvironment(text, version, cpus) {
444
+ const env = parseEnv(text);
445
+ if (cpus !== undefined && !env.SANDBOX_CPUS?.trim()) {
446
+ text = setEnvValue(text, 'SANDBOX_CPUS', cpus);
447
+ }
448
+ if (!env.SANDBOX_SUPERVISOR_SECRET) {
355
449
  text = setEnvValue(text, 'SANDBOX_SUPERVISOR_SECRET', supervisorSecret());
356
450
  }
357
451
  return setEnvValue(text, 'CREWAID_VERSION', version);
package/src/docker.mjs CHANGED
@@ -26,14 +26,15 @@ export function attached(command, args, options = {}) {
26
26
  * so `docker compose up -d` run by hand there does exactly what this does.
27
27
  */
28
28
  export function compose(dir, args) {
29
- return attached('docker', [
30
- 'compose',
31
- '--project-directory',
32
- dir,
33
- '-f',
34
- `${dir}/compose.yml`,
35
- ...args,
36
- ]);
29
+ return attached('docker', composeArgs(dir, args));
30
+ }
31
+
32
+ export function captureCompose(dir, args) {
33
+ return capture('docker', composeArgs(dir, args));
34
+ }
35
+
36
+ function composeArgs(dir, args) {
37
+ return ['compose', '--project-directory', dir, '-f', `${dir}/compose.yml`, ...args];
37
38
  }
38
39
 
39
40
  /** What Docker and Compose report, or why there is nothing to talk to. */