@frockbot/computer-host-runtime 0.2.1 → 0.2.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/runtime.ts +35 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frockbot/computer-host-runtime",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
package/src/runtime.ts CHANGED
@@ -174,6 +174,39 @@ export const NO_SLOTS_EXIT = 75;
174
174
  /** The same refusal, on stdout, for a transport that swallows the exit code. */
175
175
  export const NO_SLOTS_MARKER = "__FROCKBOT_NO_SLOTS__";
176
176
 
177
+ /** The loopback VNC port of slot 0; a slot's port is this plus its number. */
178
+ export const VNC_PORT_BASE = 5900;
179
+
180
+ /**
181
+ * The prefix of a tenant's own desktop service.
182
+ *
183
+ * One service per tenant rather than one for the Computer: a slot *is* an
184
+ * Xvfb, VNC, and CDP triple, so the process group that owns a display belongs
185
+ * to the tenant holding that slot and dies with it. The prefix is declared
186
+ * because two call sites need the same answer — the host starts these, and the
187
+ * `service` op reattaches them after a cold pause, which it may only do for a
188
+ * Computer-provider-declared name.
189
+ */
190
+ export const DESKTOP_TENANT_SERVICE_PREFIX = "frockbot-desktop-";
191
+
192
+ /** The tenant desktop service that `start-desktop.sh` runs under. */
193
+ export function desktopServiceNameV1(botKey: string): string {
194
+ return `${DESKTOP_TENANT_SERVICE_PREFIX}${botKey}`;
195
+ }
196
+
197
+ /**
198
+ * Printed by the attach probe when the tenant's VNC port already answers.
199
+ *
200
+ * The probe is the whole reason attaching a tenant does not restart its
201
+ * desktop on every Turn: `createService` is a create-*or-update*, so calling it
202
+ * unconditionally would tear down a running Xvfb — and with it the browser and
203
+ * every page the Bot had open — each time the Computer was opened. A listening
204
+ * VNC port is the one piece of evidence that the display behind it is real,
205
+ * which is more than the slot file can say: the slot is an allocation, not a
206
+ * running process.
207
+ */
208
+ export const DESKTOP_LIVE_MARKER = "__FROCKBOT_DESKTOP_LIVE__";
209
+
177
210
  /**
178
211
  * The one variable that separates a sanctioned GUI call from a shell-driven
179
212
  * one.
@@ -316,7 +349,7 @@ ROOT=${RUNTIME_ROOT}
316
349
  BOT="$ROOT/bots/$KEY"
317
350
  SLOT=$(cat "$BOT/slot")
318
351
  DISPLAY_NUMBER=$((100 + SLOT))
319
- VNC_PORT=$((5900 + SLOT))
352
+ VNC_PORT=$((${VNC_PORT_BASE} + SLOT))
320
353
  export DISPLAY=:$DISPLAY_NUMBER
321
354
  # The desktop stack *is* the sanctioned surface, so the shims step aside for
322
355
  # it. Everything a Bot's own shell runs arrives without this set.
@@ -444,7 +477,7 @@ fi
444
477
  TOKEN=$(cat "$BOT/viewer-token")
445
478
  TMP=$(mktemp "$ROOT/tokens.XXXXXX")
446
479
  grep -v "^$TOKEN:" "$ROOT/tokens" > "$TMP" || true
447
- printf '%s: 127.0.0.1:%s\n' "$TOKEN" "$((5900 + SLOT))" >> "$TMP"
480
+ printf '%s: 127.0.0.1:%s\n' "$TOKEN" "$((${VNC_PORT_BASE} + SLOT))" >> "$TMP"
448
481
  chmod 600 "$TMP"
449
482
  mv "$TMP" "$ROOT/tokens"
450
483
  `;