@fungi.computer/tourtois 0.12.4 → 0.12.6

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.
@@ -62,7 +62,8 @@ export type ModelKeysPort = Readonly<{
62
62
  * Model keys on a standalone host: store a provider API key once, then pick
63
63
  * which model and key each Agent runs on. A key is never shown again.
64
64
  */
65
- export declare function ModelKeys({ port }: {
65
+ export declare function ModelKeys({ port, focus, }: {
66
66
  port: ModelKeysPort;
67
+ focus?: boolean;
67
68
  }): import("react/jsx-runtime").JSX.Element;
68
69
  export {};
package/dist/ModelKeys.js CHANGED
@@ -7,7 +7,7 @@ import { KeycapButton } from "@fungi.computer/caps/components/keycap";
7
7
  import { SchemaForm, field, useSchemaForm } from "@fungi.computer/caps/form";
8
8
  import { Sigil } from "@fungi.computer/sigils";
9
9
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
10
- import { useMemo, useState } from "react";
10
+ import { useCallback, useMemo, useState } from "react";
11
11
  import * as z from "zod";
12
12
  import { SettingsItem } from "./settings-item.js";
13
13
  const providers = {
@@ -48,9 +48,17 @@ const defaultSource = "default";
48
48
  * Model keys on a standalone host: store a provider API key once, then pick
49
49
  * which model and key each Agent runs on. A key is never shown again.
50
50
  */
51
- export function ModelKeys({ port }) {
51
+ export function ModelKeys({ port, focus = false, }) {
52
52
  const client = useQueryClient();
53
53
  const view = useQuery({ queryKey, queryFn: () => port.read() });
54
+ const status = view.status;
55
+ const focusSetup = useCallback((section) => {
56
+ if (!focus || status === "pending")
57
+ return;
58
+ const target = section?.querySelector("select") ??
59
+ section?.querySelector("button");
60
+ target?.focus();
61
+ }, [focus, status]);
54
62
  const refresh = () => client.invalidateQueries({ queryKey });
55
63
  const remove = useMutation({
56
64
  mutationFn: (keyId) => port.removeKey(keyId),
@@ -60,7 +68,7 @@ export function ModelKeys({ port }) {
60
68
  const agents = view.data?.agents ?? [];
61
69
  // A fresh form after each stored key, so the key field empties.
62
70
  const [formKey, setFormKey] = useState(0);
63
- return (_jsxs("section", { className: "tourtois-settings-stack tourtois-model-keys", "aria-label": "Model keys", children: [_jsx(SectionHeading, { children: "Model keys" }), _jsx("p", { className: "tourtois-settings-lede", children: "Bring your own provider API key. It is checked with the provider, sealed on this instance and never shown again. Each Agent can run on any key." }), view.isPending ? _jsx("p", { children: "Loading model keys\u2026" }) : null, view.isError ? (_jsxs("div", { role: "status", className: "tourtois-settings-notice", children: [_jsx("p", { children: "Model keys could not be loaded." }), _jsx(Button, { size: "sm", variant: "outline", onClick: () => void view.refetch(), children: "Retry" })] })) : null, view.isSuccess ? (_jsxs(_Fragment, { children: [_jsxs(DataList, { "aria-label": "Model keys", children: [keys.length === 0 ? (_jsx(DataRow, { className: "tourtois-settings-empty", children: "No model keys yet." })) : null, keys.map((key) => (_jsx(DataRow, { children: _jsx(SettingsItem, { icon: _jsx(Sigil, { name: "restricted" }), title: key.label, detail: _jsx("p", { children: providers[key.provider] }), actions: _jsx(KeycapButton, { density: "compact", tone: "destructive", label: "Remove", "aria-label": `Remove ${key.label}`, disabled: remove.isPending, onClick: () => {
71
+ return (_jsxs("section", { ref: focusSetup, className: "tourtois-settings-stack tourtois-model-keys", "aria-label": "Model keys", children: [_jsx(SectionHeading, { children: "Model keys" }), _jsx("p", { className: "tourtois-settings-lede", children: "Bring your own provider API key. It is checked with the provider, sealed on this instance and never shown again. Each Agent can run on any key." }), view.isPending ? _jsx("p", { children: "Loading model keys\u2026" }) : null, view.isError ? (_jsxs("div", { role: "status", className: "tourtois-settings-notice", children: [_jsx("p", { children: "Model keys could not be loaded." }), _jsx(Button, { size: "sm", variant: "outline", onClick: () => void view.refetch(), children: "Retry" })] })) : null, view.isSuccess ? (_jsxs(_Fragment, { children: [_jsxs(DataList, { "aria-label": "Model keys", children: [keys.length === 0 ? (_jsx(DataRow, { className: "tourtois-settings-empty", children: "No model keys yet." })) : null, keys.map((key) => (_jsx(DataRow, { children: _jsx(SettingsItem, { icon: _jsx(Sigil, { name: "restricted" }), title: key.label, detail: _jsx("p", { children: providers[key.provider] }), actions: _jsx(KeycapButton, { density: "compact", tone: "destructive", label: "Remove", "aria-label": `Remove ${key.label}`, disabled: remove.isPending, onClick: () => {
64
72
  remove.mutate(key.keyId);
65
73
  } }) }) }, key.keyId)))] }), remove.isError ? (_jsx("p", { role: "alert", children: "The model key could not be removed." })) : null, _jsx(AddModelKey, { onAdd: async (draft) => {
66
74
  await port.addKey(draft);
@@ -30,7 +30,7 @@ export function SettingsHome({ team, summary, sections, desktopOnly = false, onN
30
30
  category: "connectors",
31
31
  target: { kind: "list" },
32
32
  });
33
- } }) })) : null, offers("computers") ? (_jsx(DataRow, { className: "p-0", children: _jsx(ActionRow, { "aria-label": "Internet access", icon: _jsx(Sigil, { name: "internet" }), label: "Internet access", description: "Each Computer\u2019s outside access.", trailing: summary.computerCount === null ? null : (_jsx(OverviewValue, { children: String(summary.computerCount) +
33
+ } }) })) : null, offers("computers") ? (_jsx(DataRow, { className: "p-0", children: _jsx(ActionRow, { "aria-label": "Computers", icon: _jsx(Sigil, { name: "internet" }), label: "Computers", description: "Each Computer\u2019s outside access.", trailing: summary.computerCount === null ? null : (_jsx(OverviewValue, { children: String(summary.computerCount) +
34
34
  (summary.computerCount === 1
35
35
  ? " Computer"
36
36
  : " Computers") })), onClick: () => {
@@ -102,13 +102,13 @@ function navigationGroups(apps, sections, desktopOnly) {
102
102
  },
103
103
  {
104
104
  value: "computers",
105
- label: "Internet access",
105
+ label: "Computers",
106
106
  location: { category: "computers" },
107
107
  },
108
108
  {
109
109
  value: "keys",
110
110
  label: "Keys",
111
- location: { category: "keys" },
111
+ location: { category: "keys", target: "all" },
112
112
  },
113
113
  ],
114
114
  },
@@ -1,6 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { AppCallPermissions } from "./AppCallPermissions.js";
3
3
  import { SectionHeading } from "@fungi.computer/caps/blocks/section-heading";
4
+ import { FormFooter } from "@fungi.computer/caps/components/field";
5
+ import { Prose } from "@fungi.computer/caps/components/prose";
4
6
  import { AppDesktopSettings, } from "./AppDesktopSettings.js";
5
7
  import { addressKey, } from "@fungi.computer/nacre/app-directory";
6
8
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@@ -30,6 +32,15 @@ export function SystemSettings({ location: requestedLocation, sections: ceiling,
30
32
  const connectors = location?.category === "connectors";
31
33
  const computersSection = location?.category === "computers";
32
34
  const keysSection = location?.category === "keys";
35
+ const keysTarget = location?.category === "keys" ? location.target : "all";
36
+ const keyContent = useRef(null);
37
+ useEffect(() => {
38
+ const content = keyContent.current;
39
+ if (keysTarget !== "media" || content === null)
40
+ return;
41
+ content.scrollTop = 0;
42
+ content.querySelector("a")?.focus();
43
+ }, [keysTarget]);
33
44
  const keyableApps = useMemo(() => apps.flatMap((app) => app.installationId === null
34
45
  ? []
35
46
  : [
@@ -122,7 +133,9 @@ export function SystemSettings({ location: requestedLocation, sections: ceiling,
122
133
  }, onOpenChange: (next) => {
123
134
  if (!next)
124
135
  close();
125
- }, children: _jsxs(DialogContent, { finalFocus: restoreFocus, render: _jsx(WindowFrame, { floating: true }), keepMounted: false, className: "tourtois-system-settings", children: [_jsx(DialogTitle, { className: "sr-only", children: "System Settings" }), _jsx(DialogDescription, { className: "sr-only", children: desktopOnly
136
+ }, children: _jsxs(DialogContent, { finalFocus: restoreFocus, initialFocus: keysTarget === "all"
137
+ ? true
138
+ : () => keyContent.current?.querySelector(keysTarget === "model" ? "select" : "a") ?? true, render: _jsx(WindowFrame, { floating: true }), keepMounted: false, className: "tourtois-system-settings", children: [_jsx(DialogTitle, { className: "sr-only", children: "System Settings" }), _jsx(DialogDescription, { className: "sr-only", children: desktopOnly
126
139
  ? "Your desktop and App settings."
127
140
  : "Your avatar, Channels, Connectors, App access and App settings." }), _jsx(WindowHeader, { ...headerProps }), _jsx(SettingsLeaveContext.Provider, { value: register, children: _jsxs("div", { className: "tourtois-settings-layout", children: [_jsx(SettingsNavigation, { sections: sections, desktopOnly: desktopOnly, location: location, apps: apps, onNavigate: (next) => {
128
141
  if (location?.category === "selling" && location.appId !== null)
@@ -133,7 +146,11 @@ export function SystemSettings({ location: requestedLocation, sections: ceiling,
133
146
  appCount,
134
147
  defaultAppCount: ports.summary?.defaultAppCount ?? null,
135
148
  computerCount: ports.summary?.computerCount ?? null,
136
- }, onNavigate: onNavigate })) : null, avatar && ports.avatar !== undefined ? (_jsx("div", { className: "tourtois-settings-content", children: _jsx(AvatarSettings, { save: ports.avatar.save }) })) : null, connectors && connections !== undefined ? (location.target.kind === "list" ? (_jsx(Connections, { port: connections, target: location.target, onNavigate: onNavigate })) : connections.hostSections ? (_jsx(connections.hostSections, { target: location.target, onNavigate: onNavigate })) : null) : null, location?.category === "selling" && ports.selling !== undefined ? (_jsx(ports.selling, { appId: location.appId, onNavigate: onNavigate })) : null, computersSection && ports.computers !== undefined ? (_jsx("div", { className: "tourtois-settings-content", children: _jsx(ports.computers, {}) })) : null, keysSection ? (_jsxs("div", { className: "tourtois-settings-content tourtois-settings-stack", children: [keys !== undefined ? (_jsx(Keys, { port: keys, apps: keyableApps })) : null, ports.modelKeys !== undefined ? (_jsx(ModelKeys, { port: ports.modelKeys })) : null] })) : null, location?.category === "channels" &&
149
+ }, onNavigate: onNavigate })) : null, avatar && ports.avatar !== undefined ? (_jsx("div", { className: "tourtois-settings-content", children: _jsx(AvatarSettings, { save: ports.avatar.save }) })) : null, connectors && connections !== undefined ? (location.target.kind === "list" ? (_jsx(Connections, { port: connections, target: location.target, onNavigate: onNavigate })) : connections.hostSections ? (_jsx(connections.hostSections, { target: location.target, onNavigate: onNavigate })) : null) : null, location?.category === "selling" && ports.selling !== undefined ? (_jsx(ports.selling, { appId: location.appId, onNavigate: onNavigate })) : null, computersSection && ports.computers !== undefined ? (_jsx("div", { className: "tourtois-settings-content", children: _jsx(ports.computers, {}) })) : null, keysSection ? (_jsxs("div", { ref: keyContent, "aria-label": keysTarget === "model"
150
+ ? "Model setup"
151
+ : keysTarget === "media"
152
+ ? "Image setup"
153
+ : "Keys settings", className: "tourtois-settings-content tourtois-settings-stack", children: [keysTarget === "all" && keys !== undefined ? (_jsx(Keys, { port: keys, apps: keyableApps })) : null, keysTarget !== "media" && ports.modelKeys !== undefined ? (_jsx(ModelKeys, { port: ports.modelKeys, focus: keysTarget === "model" })) : null, keysTarget !== "model" && ports.modelKeys !== undefined ? (_jsxs("section", { className: "tourtois-settings-stack", "aria-label": "Image models", children: [_jsx(SectionHeading, { children: "Image models" }), _jsx("p", { className: "tourtois-settings-lede", children: "Flux images use Cloudflare Workers AI." }), _jsxs(Prose, { children: [_jsx("p", { children: "Local trials can upload images. To generate:" }), _jsxs("ol", { children: [_jsx("li", { children: "Enable Workers AI in your Cloudflare account." }), _jsx("li", { children: "Deploy this Oyster using the setup guide." }), _jsx("li", { children: "Open Prints at the deployed Oyster address." })] })] }), _jsx(FormFooter, { divider: false, children: _jsx(Button, { asChild: true, children: _jsx("a", { href: "https://docs.fungi.computer/guides/run-your-own-oyster/#image-models", target: "_blank", rel: "noreferrer", children: "Set up Cloudflare Workers AI" }) }) })] })) : null] })) : null, location?.category === "channels" &&
137
154
  ports.channels !== undefined ? (_jsx(ports.channels, {})) : null, defaults && ports.defaults !== undefined ? (_jsx("div", { className: "tourtois-settings-content", children: _jsx(ports.defaults, { onAccepted: onAccepted }) })) : null, appSection && appKey === null ? (_jsxs("section", { className: "tourtois-settings-content", "aria-label": "Choose an App", children: [_jsx(SectionHeading, { className: "tourtois-settings-app-heading", children: desktopOnly ? "App desktop" : "App permissions" }), _jsx(DataList, { density: "compact", "aria-label": "Apps to review", children: apps.map((app) => (_jsx(DataRow, { className: "p-0", children: _jsx(ActionRow, { label: app.displayName ?? app.appId, icon: _jsx(AppIcon, { roles: app.roles, icon: app.icon }), onClick: () => {
138
155
  onNavigate({
139
156
  category: "apps",
@@ -315,7 +315,11 @@ export const mountPlatformControls = (root, input) => {
315
315
  } }) }));
316
316
  return Promise.resolve({
317
317
  controls: {
318
- ...controls,
318
+ sections: controls.sections,
319
+ subscribeSettingsClosed: controls.subscribeSettingsClosed,
320
+ subscribeChanges: controls.subscribeChanges,
321
+ attachDesktopSettings: controls.attachDesktopSettings,
322
+ requestAppAccess: controls.requestAppAccess,
319
323
  setup,
320
324
  parseSettings: (value) => S.decodeUnknownSync(S.Json)(settingsLocationSchema.parse(value)),
321
325
  retryInstall: async (installationId) => {
@@ -9,9 +9,9 @@ export const oysterSetupSchema = z.strictObject({
9
9
  });
10
10
  /** Where each need is fixed in this host's Settings. */
11
11
  export function settingsForNeed(need) {
12
- // Models and media both come from a key; git and a runtime from Computers.
12
+ // Model keys and image setup have separate destinations; runtimes live in Computers.
13
13
  return need === "model" || need === "media"
14
- ? { category: "keys" }
14
+ ? { category: "keys", target: need }
15
15
  : { category: "computers" };
16
16
  }
17
17
  /** The setup port: facts read live, plus the Settings page for each need. */
@@ -31,6 +31,11 @@ export declare const settingsLocationSchema: z.ZodDiscriminatedUnion<[z.ZodObjec
31
31
  category: z.ZodLiteral<"computers">;
32
32
  }, z.core.$strict>, z.ZodObject<{
33
33
  category: z.ZodLiteral<"keys">;
34
+ target: z.ZodEnum<{
35
+ media: "media";
36
+ all: "all";
37
+ model: "model";
38
+ }>;
34
39
  }, z.core.$strict>, z.ZodObject<{
35
40
  category: z.ZodLiteral<"defaults">;
36
41
  }, z.core.$strict>, z.ZodObject<{
@@ -112,6 +117,14 @@ export declare function createSettingsRouter(): RouterCore<import("@tanstack/rou
112
117
  category: "computers";
113
118
  }, unknown, unknown, unknown, unknown, undefined>, import("@tanstack/react-router").Route<unknown, import("@tanstack/react-router").RootRoute<import("@tanstack/react-router").Register, undefined, {}, import("@tanstack/react-router").AnyContext, import("@tanstack/react-router").AnyContext, {}, undefined, unknown, unknown, unknown, unknown, undefined>, "/keys", "/keys", string, "/keys", undefined, import("@tanstack/react-router").ResolveParams<"/keys">, import("@tanstack/react-router").AnyContext, import("@tanstack/react-router").AnyContext, import("@tanstack/react-router").AnyContext, {}, () => {
114
119
  category: "keys";
120
+ target: "all";
121
+ }, unknown, unknown, unknown, unknown, undefined>, import("@tanstack/react-router").Route<unknown, import("@tanstack/react-router").RootRoute<import("@tanstack/react-router").Register, undefined, {}, import("@tanstack/react-router").AnyContext, import("@tanstack/react-router").AnyContext, {}, undefined, unknown, unknown, unknown, unknown, undefined>, "/keys/$target", "/keys/$target", string, "/keys/$target", undefined, {
122
+ target: "media" | "model";
123
+ }, import("@tanstack/react-router").AnyContext, import("@tanstack/react-router").AnyContext, import("@tanstack/react-router").AnyContext, {}, ({ params }: import("@tanstack/react-router").LoaderFnContext<unknown, import("@tanstack/react-router").RootRoute<import("@tanstack/react-router").Register, undefined, {}, import("@tanstack/react-router").AnyContext, import("@tanstack/react-router").AnyContext, {}, undefined, unknown, unknown, unknown, unknown, undefined>, "/keys/$target", {
124
+ target: "media" | "model";
125
+ }, {}, import("@tanstack/react-router").AnyContext, import("@tanstack/react-router").AnyContext, import("@tanstack/react-router").AnyContext, unknown, undefined>) => {
126
+ category: "keys";
127
+ target: "media" | "model";
115
128
  }, unknown, unknown, unknown, unknown, undefined>, import("@tanstack/react-router").Route<unknown, import("@tanstack/react-router").RootRoute<import("@tanstack/react-router").Register, undefined, {}, import("@tanstack/react-router").AnyContext, import("@tanstack/react-router").AnyContext, {}, undefined, unknown, unknown, unknown, unknown, undefined>, "/channels", "/channels", string, "/channels", undefined, import("@tanstack/react-router").ResolveParams<"/channels">, import("@tanstack/react-router").AnyContext, import("@tanstack/react-router").AnyContext, import("@tanstack/react-router").AnyContext, {}, () => {
116
129
  category: "channels";
117
130
  }, unknown, unknown, unknown, unknown, undefined>], unknown, unknown, unknown, undefined>, "never", false, import("@tanstack/history").RouterHistory, Record<string, any>>;
@@ -23,7 +23,10 @@ export const settingsLocationSchema = z.discriminatedUnion("category", [
23
23
  ]),
24
24
  }),
25
25
  z.strictObject({ category: z.literal("computers") }),
26
- z.strictObject({ category: z.literal("keys") }),
26
+ z.strictObject({
27
+ category: z.literal("keys"),
28
+ target: z.enum(["all", "model", "media"]),
29
+ }),
27
30
  z.strictObject({ category: z.literal("defaults") }),
28
31
  z.strictObject({ category: z.literal("channels") }),
29
32
  z.strictObject({ category: z.literal("selling"), appId: appKey.nullable() }),
@@ -120,7 +123,15 @@ export function createSettingsRouter() {
120
123
  const keys = createRoute({
121
124
  getParentRoute: () => root,
122
125
  path: "/keys",
123
- loader: () => ({ category: "keys" }),
126
+ loader: () => ({ category: "keys", target: "all" }),
127
+ });
128
+ const keySetup = createRoute({
129
+ getParentRoute: () => root,
130
+ path: "/keys/$target",
131
+ params: {
132
+ parse: (params) => z.object({ target: z.enum(["model", "media"]) }).parse(params),
133
+ },
134
+ loader: ({ params }) => ({ category: "keys", target: params.target }),
124
135
  });
125
136
  const channels = createRoute({
126
137
  getParentRoute: () => root,
@@ -154,6 +165,7 @@ export function createSettingsRouter() {
154
165
  connectorAgent,
155
166
  computers,
156
167
  keys,
168
+ keySetup,
157
169
  channels,
158
170
  ]);
159
171
  const router = createRouter({
@@ -204,7 +216,12 @@ export function navigateSettings(router, location) {
204
216
  case "computers":
205
217
  return router.navigate({ to: "/computers" });
206
218
  case "keys":
207
- return router.navigate({ to: "/keys" });
219
+ return location.target === "all"
220
+ ? router.navigate({ to: "/keys" })
221
+ : router.navigate({
222
+ to: "/keys/$target",
223
+ params: { target: location.target },
224
+ });
208
225
  case "apps":
209
226
  return location.appKey === null
210
227
  ? router.navigate({ to: "/apps" })
@@ -259,6 +259,7 @@ export function createTourtoisShell(workbench) {
259
259
  const changeListeners = new Set();
260
260
  let watching;
261
261
  const platform = {
262
+ retryInstall: workbench.retryInstall?.bind(workbench),
262
263
  registerDesktopSettings: (handler) => workbench.registerDesktopSettings(handler),
263
264
  openSettings: (location) => {
264
265
  // The host renders Settings itself. Restore our own invoker only after
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/tourtois",
3
- "version": "0.12.4",
3
+ "version": "0.12.6",
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",
@@ -82,7 +82,7 @@
82
82
  "@fungi.computer/caps": "0.10.1",
83
83
  "@fungi.computer/ear-tag": "0.1.0",
84
84
  "@fungi.computer/gills": "0.3.0",
85
- "@fungi.computer/maosaico": "0.1.1",
85
+ "@fungi.computer/maosaico": "0.1.2",
86
86
  "@fungi.computer/parakeet": "0.11.3",
87
87
  "@fungi.computer/puffball": "0.5.5",
88
88
  "@fungi.computer/shiitake": "0.12.3",
@@ -100,13 +100,13 @@
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.4.2"
103
+ "@fungi.computer/nacre": "0.4.3"
104
104
  },
105
105
  "peerDependencies": {
106
106
  "react": "^18.3.1 || ^19.2.0"
107
107
  },
108
108
  "devDependencies": {
109
- "@fungi.computer/oyster": "0.19.4",
109
+ "@fungi.computer/oyster": "0.19.6",
110
110
  "@cloudflare/workers-types": "5.20260828.1",
111
111
  "@fungi.computer/forage": "0.3.5",
112
112
  "@fungi.computer/mycelium": "0.3.8",