@fungi.computer/tourtois 0.19.0 → 0.20.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.
@@ -21,6 +21,13 @@ export type OysterComputersPort = Readonly<{
21
21
  */
22
22
  sizePrices?: Readonly<Record<ComputerSize, string>>;
23
23
  start(computerId: string): Promise<void>;
24
+ /**
25
+ * Hosts whose owner may stop a running Computer supply this. Durable
26
+ * workspace files are kept; the next start brings them back.
27
+ */
28
+ stop?(computerId: string): Promise<void>;
29
+ /** Hosts that can stop a Computer also read whether it is running. */
30
+ state?(computerId: string): Promise<ComputerRunState>;
24
31
  internetAccess(computerId: string): Promise<boolean>;
25
32
  setInternetAccess(computerId: string, enabled: boolean): Promise<boolean>;
26
33
  keepAwake(computerId: string): Promise<boolean>;
@@ -35,6 +42,8 @@ export type OysterComputersPort = Readonly<{
35
42
  /** Operator policy readback, when the host exposes it. Unknown locks writes. */
36
43
  egressPolicy?(): Promise<"enabled" | "globally-disabled" | "team-disabled">;
37
44
  }>;
45
+ /** Whether a Computer's runtime is up, as the host reads it without waking it. */
46
+ export type ComputerRunState = "running" | "sleeping" | "starting" | "queued" | "start_failed";
38
47
  /** The durable per-Computer switches an owner manages. */
39
48
  export type ComputerSwitchSetting = "internet-access" | "keep-awake";
40
49
  /** Bind owner-admitted fleet controls to this trusted shell's host origin. */
@@ -6,7 +6,10 @@ import { Button } from "@fungi.computer/caps/components/button";
6
6
  import { DataList, DataRow } from "@fungi.computer/caps/components/data-list";
7
7
  import { Field, FormFooter } from "@fungi.computer/caps/components/field";
8
8
  import { KeycapButton } from "@fungi.computer/caps/components/keycap";
9
+ import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@fungi.computer/caps/components/dialog";
9
10
  import { Status } from "@fungi.computer/caps/components/status";
11
+ import { toast } from "@fungi.computer/caps/components/toaster";
12
+ import { WORKBENCH_NOTICES } from "./app-toast.js";
10
13
  import { Switch } from "@fungi.computer/caps/components/switch";
11
14
  import { SchemaForm, field, useSchemaForm, } from "@fungi.computer/caps/form";
12
15
  import { Sigil } from "@fungi.computer/sigils";
@@ -28,6 +31,9 @@ const computerSizeOrder = ["small", "default", "large"];
28
31
  const sizeDetail = (size, prices) => [computerSizes[size].resources, prices?.[size]]
29
32
  .filter((part) => part !== undefined)
30
33
  .join(", ");
34
+ const computerRunStateSchema = z.looseObject({
35
+ state: z.enum(["running", "sleeping", "starting", "queued", "start_failed"]),
36
+ });
31
37
  const missingRuntime = z.strictObject({ error: z.literal("no_runtime") });
32
38
  const computerSwitchSchema = z.strictObject({ enabled: z.boolean() });
33
39
  async function request(url, init) {
@@ -84,6 +90,14 @@ export function createOysterComputersPort(origin) {
84
90
  });
85
91
  await response.json();
86
92
  },
93
+ stop: async (computerId) => {
94
+ const response = await read(`/api/computers/${encodeURIComponent(computerId)}/stop`, { method: "POST" });
95
+ await response.json();
96
+ },
97
+ state: async (computerId) => {
98
+ const response = await read(`/api/computers/${encodeURIComponent(computerId)}/state`);
99
+ return computerRunStateSchema.parse(await response.json()).state;
100
+ },
87
101
  selection: {
88
102
  selected: async () => {
89
103
  const response = await read("/api/workbench/directory");
@@ -150,7 +164,7 @@ function KeepAwake({ teamId, computer, port, }) {
150
164
  /** Keep awake's help; hosts that bill idle time say so. */
151
165
  export const keepAwakeHelp = (idleMetered) => `${idleMetered
152
166
  ? "Stays on when idle, and idle time is charged."
153
- : "Stays on when idle."} Off, it sleeps after 15 idle minutes.`;
167
+ : "Stays on when idle."} Off, it sleeps after an idle hour.`;
154
168
  const createComputerSchema = (prices) => z.object({
155
169
  name: z
156
170
  .string()
@@ -173,6 +187,61 @@ const createComputerSchema = (prices) => z.object({
173
187
  help: "Fixed when the Computer is created.",
174
188
  })),
175
189
  });
190
+ const stateDisplay = {
191
+ running: { label: "Running", tone: "success" },
192
+ sleeping: { label: "Sleeping", tone: "neutral" },
193
+ starting: { label: "Starting", tone: "info" },
194
+ queued: { label: "Queued", tone: "info" },
195
+ start_failed: { label: "Start failed", tone: "error" },
196
+ };
197
+ /** The runtime state of one Computer; polled while it is changing. */
198
+ function useComputerRunState(teamId, computer, port) {
199
+ const read = port.state;
200
+ return useQuery({
201
+ queryKey: tourtoisQueryKeys.oysterComputerState(teamId, computer.computerId),
202
+ enabled: read !== undefined,
203
+ queryFn: () => read === undefined
204
+ ? Promise.reject(new Error("This host cannot read Computer state"))
205
+ : read(computer.computerId),
206
+ refetchInterval: (query) => query.state.data === "starting" || query.state.data === "queued"
207
+ ? 2000
208
+ : false,
209
+ });
210
+ }
211
+ /** The state beside a Computer's name: a dot and one word. */
212
+ function ComputerRunStatus({ teamId, computer, port, }) {
213
+ const run = useComputerRunState(teamId, computer, port);
214
+ if (run.data === undefined)
215
+ return null;
216
+ const { label, tone } = stateDisplay[run.data];
217
+ return (_jsx(Status, { size: "compact", tone: tone, label: label, motion: run.data === "starting" || run.data === "queued" ? "pulse" : "none" }));
218
+ }
219
+ /**
220
+ * Start when the Computer sleeps, Stop when it runs; neither while it is
221
+ * changing. Hosts that cannot read state keep the one Start key.
222
+ */
223
+ function ComputerLifecycleKeys({ teamId, computer, port, disabled, busy, onStart, onStop, }) {
224
+ const run = useComputerRunState(teamId, computer, port);
225
+ const [confirming, setConfirming] = useState(false);
226
+ const canStop = port.stop !== undefined && port.state !== undefined;
227
+ if (canStop && run.data === "running")
228
+ return (_jsxs(_Fragment, { children: [_jsx(KeycapButton, { density: "compact", label: "Stop", icon: _jsx(Sigil, { name: "stop" }), "aria-label": `Stop ${computer.name}`, disabled: disabled || busy, onClick: () => {
229
+ setConfirming(true);
230
+ } }), _jsx(Dialog, { open: confirming, onOpenChange: (next, details) => {
231
+ if (busy) {
232
+ details.cancel();
233
+ return;
234
+ }
235
+ setConfirming(next);
236
+ }, children: _jsxs(DialogContent, { forceBackdrop: true, children: [_jsxs(DialogHeader, { children: [_jsxs(DialogTitle, { children: ["Stop ", computer.name, "?"] }), _jsx(DialogDescription, { children: "Running commands end; files are kept." })] }), _jsxs(DialogFooter, { children: [_jsx(DialogClose, { render: _jsx(Button, { variant: "ghost" }), disabled: busy, children: "Cancel" }), _jsx(Button, { variant: "destructive", loading: busy, onClick: () => {
237
+ void onStop().then(() => {
238
+ setConfirming(false);
239
+ },
240
+ // The mutation's onError already shows the toast.
241
+ () => undefined);
242
+ }, children: "Stop" })] })] }) })] }));
243
+ return (_jsx(KeycapButton, { density: "compact", label: "Start", icon: _jsx(Sigil, { name: "run" }), "aria-label": `Start ${computer.name}`, disabled: disabled || busy || run.data === "starting" || run.data === "queued", onClick: onStart }));
244
+ }
176
245
  /** Owner Settings over the host's existing inventory and optional default. */
177
246
  export function OysterComputers({ teamId, port, onChanged, }) {
178
247
  const client = useQueryClient();
@@ -208,17 +277,37 @@ export function OysterComputers({ teamId, port, onChanged, }) {
208
277
  case "start":
209
278
  await port.start(input.computerId);
210
279
  return;
280
+ case "stop":
281
+ if (port.stop === undefined)
282
+ throw new Error("This host cannot stop a Computer");
283
+ await port.stop(input.computerId);
284
+ return;
211
285
  case "select":
212
286
  if (selection === undefined)
213
287
  throw new Error("This host has no default Computer");
214
288
  await selection.select(input.computerId);
215
289
  }
216
290
  },
291
+ onError: (cause, input) => {
292
+ if (input.kind !== "create")
293
+ toast.error(cause.message, { toasterId: WORKBENCH_NOTICES });
294
+ },
217
295
  onSuccess: async (_result, input) => {
218
296
  if (input.kind === "create") {
219
297
  intent.current = null;
220
298
  setOffset(0);
221
299
  }
300
+ if (input.kind !== "create") {
301
+ const name = inventory.data?.computers.find((row) => row.computerId === input.computerId)?.name ?? "The Computer";
302
+ toast.success(input.kind === "start"
303
+ ? `${name} started.`
304
+ : input.kind === "stop"
305
+ ? `${name} stopped. Your files are kept.`
306
+ : `${name} is now the default for new Apps.`, { toasterId: WORKBENCH_NOTICES });
307
+ await client.invalidateQueries({
308
+ queryKey: tourtoisQueryKeys.oysterComputerStates(teamId),
309
+ });
310
+ }
222
311
  await Promise.all([
223
312
  client.invalidateQueries({ queryKey: inventoryKey }),
224
313
  ...(selection === undefined
@@ -276,12 +365,17 @@ export function OysterComputers({ teamId, port, onChanged, }) {
276
365
  const isDefault = selection !== undefined &&
277
366
  selected.isSuccess &&
278
367
  selected.data === computer.computerId;
279
- return (_jsxs("section", { className: "tourtois-computer", "aria-label": computer.name, children: [_jsx(SettingsItem, { icon: _jsx(Sigil, { name: "computer" }), title: computer.name, detail: `${computerSizes[computer.size].label}: ${sizeDetail(computer.size, port.sizePrices)}`, actions: _jsxs(_Fragment, { children: [_jsx(KeycapButton, { density: "compact", label: "Start", icon: _jsx(Sigil, { name: "run" }), "aria-label": `Start ${computer.name}`, disabled: unavailable, onClick: () => {
368
+ return (_jsxs("section", { className: "tourtois-computer", "aria-label": computer.name, children: [_jsx(SettingsItem, { icon: _jsx(Sigil, { name: "computer" }), title: _jsxs(_Fragment, { children: [computer.name, " ", _jsx(ComputerRunStatus, { teamId: teamId, computer: computer, port: port })] }), detail: `${computerSizes[computer.size].label}: ${sizeDetail(computer.size, port.sizePrices)}`, actions: _jsxs(_Fragment, { children: [_jsx(ComputerLifecycleKeys, { teamId: teamId, computer: computer, port: port, disabled: unavailable, busy: action.isPending &&
369
+ action.variables.kind !== "create" &&
370
+ action.variables.computerId === computer.computerId, onStart: () => {
280
371
  action.mutate({
281
372
  kind: "start",
282
373
  computerId: computer.computerId,
283
374
  });
284
- } }), isDefault ? (_jsx(Status, { size: "compact", tone: "success", label: "Default for new Apps" })) : selection !== undefined ? (_jsx(KeycapButton, { density: "compact", label: "Use for new Apps", icon: _jsx(Sigil, { name: "allApps" }), "aria-label": `Use ${computer.name} for new Apps`, disabled: unavailable, onClick: () => {
375
+ }, onStop: () => action.mutateAsync({
376
+ kind: "stop",
377
+ computerId: computer.computerId,
378
+ }) }), isDefault ? (_jsx(Status, { size: "compact", tone: "success", label: "Default for new Apps" })) : selection !== undefined ? (_jsx(KeycapButton, { density: "compact", label: "Use for new Apps", icon: _jsx(Sigil, { name: "allApps" }), "aria-label": `Use ${computer.name} for new Apps`, disabled: unavailable, onClick: () => {
285
379
  action.mutate({
286
380
  kind: "select",
287
381
  computerId: computer.computerId,
@@ -293,5 +387,5 @@ export function OysterComputers({ teamId, port, onChanged, }) {
293
387
  const next = inventory.data?.nextOffset;
294
388
  if (next != null)
295
389
  setOffset(next);
296
- }, children: "Next" })] })) : null, _jsx(SchemaForm, { model: create, layout: "columns", "aria-label": "Create Computer", disabled: unavailable, footer: _jsx(FormFooter, { divider: false, error: create.error, children: _jsx(Button, { type: "submit", disabled: unavailable, children: "Create Computer" }) }) }), action.isError && action.variables.kind !== "create" ? (_jsx("p", { role: "alert", children: action.error.message })) : null, action.isSuccess ? (_jsx("p", { role: "status", children: "Computer request completed." })) : null] }));
390
+ }, children: "Next" })] })) : null, _jsx(SchemaForm, { model: create, layout: "columns", "aria-label": "Create Computer", disabled: unavailable, footer: _jsx(FormFooter, { divider: false, error: create.error, children: _jsx(Button, { type: "submit", disabled: unavailable, children: "Create Computer" }) }) })] }));
297
391
  }
@@ -2,6 +2,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
2
2
  import { AppError } from "@fungi.computer/agar";
3
3
  import { Button } from "@fungi.computer/caps/components/button";
4
4
  import { toast } from "@fungi.computer/caps/components/toaster";
5
+ import { OverlayRoot, } from "@fungi.computer/caps/components/overlay-root";
5
6
  import { desktopGillAdditionSchema, desktopGillSelectionSchema, } from "@fungi.computer/nacre/workbench";
6
7
  import { addressKey } from "@fungi.computer/nacre/app-directory";
7
8
  import { tourtoisQueryKeys } from "./queries.js";
@@ -14,6 +15,41 @@ export { parseSettingsLocation } from "./settings-routes.js";
14
15
  import { MemberAvatarSource } from "./member-avatar.js";
15
16
  export { connectionAddedSchema, connectionToolsSchema, connectionsViewSchema, } from "./Connections.js";
16
17
  export {} from "./Keys.js";
18
+ const overlayLayers = ["popover", "dialog", "toast", "tooltip"];
19
+ /** The shell's own layer roots, or the body where no shell is mounted. */
20
+ function shellOverlays() {
21
+ const find = (name) => document.querySelector(`[data-maosaico-layer="${name}"]`) ??
22
+ document.body;
23
+ return {
24
+ popover: find("popover"),
25
+ dialog: find("dialog"),
26
+ toast: find("toast"),
27
+ tooltip: find("tooltip"),
28
+ };
29
+ }
30
+ /**
31
+ * Settings mount in their own React root, outside the shell's layers. Give
32
+ * their dialogs the shell's dialog layer so toasts and other overlays paint in
33
+ * the shell's order instead of under a window in the body.
34
+ */
35
+ function ShellOverlays({ children }) {
36
+ const [containers, setContainers] = useState(shellOverlays);
37
+ useEffect(() => {
38
+ const sync = () => {
39
+ const next = shellOverlays();
40
+ setContainers((current) => overlayLayers.every((name) => current[name] === next[name])
41
+ ? current
42
+ : next);
43
+ };
44
+ sync();
45
+ const observer = new MutationObserver(sync);
46
+ observer.observe(document.body, { childList: true, subtree: true });
47
+ return () => {
48
+ observer.disconnect();
49
+ };
50
+ }, []);
51
+ return _jsx(OverlayRoot, { containers: containers, children: children });
52
+ }
17
53
  /** One host's platform controls; render them with `PlatformControlsView`. */
18
54
  export function createPlatformControls(options) {
19
55
  const sections = options?.sections.slice();
@@ -271,5 +307,5 @@ export function PlatformControlsView({ teamId, controls, data, }) {
271
307
  await directory.refetch({ throwOnError: true });
272
308
  controls.changed();
273
309
  }, desktopSettings: controls.desktopSettings, desktopConsentReadyAt: controls.desktopConsentReadyAt(), onClosed: controls.settingsClosed, restoreFocus: restoreFocus, ports: data })] }));
274
- return data.avatar === undefined ? (settings) : (_jsx(MemberAvatarSource, { read: data.avatar.read, children: settings }));
310
+ return (_jsx(ShellOverlays, { children: data.avatar === undefined ? (settings) : (_jsx(MemberAvatarSource, { read: data.avatar.read, children: settings })) }));
275
311
  }
package/dist/queries.d.ts CHANGED
@@ -4,6 +4,8 @@ export declare const tourtoisQueryKeys: {
4
4
  oysterComputerPage: (teamId: string, offset: number) => readonly ["tourtois", "oyster-computers", string, number];
5
5
  oysterSelectedComputer: (teamId: string) => readonly ["tourtois", "oyster-selected-computer", string];
6
6
  oysterInternetAccess: (teamId: string, computerId: string) => readonly ["tourtois", "oyster-internet-access", string, string];
7
+ oysterComputerStates: (teamId: string) => readonly ["tourtois", "oyster-computer-state", string];
8
+ oysterComputerState: (teamId: string, computerId: string) => readonly ["tourtois", "oyster-computer-state", string, string];
7
9
  oysterKeepAwake: (teamId: string, computerId: string) => readonly ["tourtois", "oyster-keep-awake", string, string];
8
10
  oysterEgressPolicy: (teamId: string) => readonly ["tourtois", "oyster-egress-policy", string];
9
11
  discordChannels: (scope: string) => readonly ["tourtois", "discord-channels", string];
package/dist/queries.js CHANGED
@@ -4,6 +4,8 @@ export const tourtoisQueryKeys = {
4
4
  oysterComputerPage: (teamId, offset) => [...tourtoisQueryKeys.oysterComputers(teamId), offset],
5
5
  oysterSelectedComputer: (teamId) => ["tourtois", "oyster-selected-computer", teamId],
6
6
  oysterInternetAccess: (teamId, computerId) => ["tourtois", "oyster-internet-access", teamId, computerId],
7
+ oysterComputerStates: (teamId) => ["tourtois", "oyster-computer-state", teamId],
8
+ oysterComputerState: (teamId, computerId) => [...tourtoisQueryKeys.oysterComputerStates(teamId), computerId],
7
9
  oysterKeepAwake: (teamId, computerId) => ["tourtois", "oyster-keep-awake", teamId, computerId],
8
10
  oysterEgressPolicy: (teamId) => ["tourtois", "oyster-egress-policy", teamId],
9
11
  discordChannels: (scope) => ["tourtois", "discord-channels", scope],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/tourtois",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Tourtois: the trusted desktop shell for Oyster and Fungi, with host-supplied Settings sections",
6
6
  "type": "module",
@@ -77,16 +77,16 @@
77
77
  "LICENSE"
78
78
  ],
79
79
  "dependencies": {
80
- "@fungi.computer/agar": "0.12.1",
80
+ "@fungi.computer/agar": "0.13.0",
81
81
  "@fungi.computer/cairn": "0.1.0",
82
- "@fungi.computer/caps": "0.11.3",
82
+ "@fungi.computer/caps": "0.11.4",
83
83
  "@fungi.computer/ear-tag": "0.1.0",
84
84
  "@fungi.computer/gills": "0.3.0",
85
85
  "@fungi.computer/maosaico": "0.1.2",
86
- "@fungi.computer/parakeet": "0.11.25",
87
- "@fungi.computer/puffball": "0.7.0",
88
- "@fungi.computer/shiitake": "0.15.0",
89
- "@fungi.computer/sigils": "0.3.1",
86
+ "@fungi.computer/parakeet": "0.11.26",
87
+ "@fungi.computer/puffball": "0.8.0",
88
+ "@fungi.computer/shiitake": "0.16.0",
89
+ "@fungi.computer/sigils": "0.3.2",
90
90
  "@fungi.computer/sprite": "0.2.2",
91
91
  "@fungi.computer/sprite-zdog": "0.3.2",
92
92
  "@fungi.computer/whistle": "0.3.0",
@@ -100,16 +100,16 @@
100
100
  "lucide-react": "0.460.0",
101
101
  "react-dom": "18.3.1",
102
102
  "zod": "4.4.3",
103
- "@fungi.computer/nacre": "0.6.0"
103
+ "@fungi.computer/nacre": "0.6.1"
104
104
  },
105
105
  "peerDependencies": {
106
106
  "react": "^18.3.1 || ^19.2.0"
107
107
  },
108
108
  "devDependencies": {
109
- "@fungi.computer/oyster": "0.26.0",
109
+ "@fungi.computer/oyster": "0.27.0",
110
110
  "@cloudflare/workers-types": "5.20260828.1",
111
- "@fungi.computer/forage": "0.3.7",
112
- "@fungi.computer/mycelium": "0.3.10",
111
+ "@fungi.computer/forage": "0.3.8",
112
+ "@fungi.computer/mycelium": "0.3.11",
113
113
  "@ladle/react": "5.1.1",
114
114
  "@types/react": "18.3.3",
115
115
  "@vitejs/plugin-react": "6.1.1",