@fungi.computer/tourtois 0.5.3 → 0.7.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.
@@ -1,15 +1,15 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { SectionHeading } from "@fungi.computer/caps/blocks/section-heading";
3
- import { ActionRow } from "@fungi.computer/caps/components/action-row";
4
- import { Badge } from "@fungi.computer/caps/components/badge";
5
3
  import { Button } from "@fungi.computer/caps/components/button";
6
4
  import { DataList, DataListHeading, DataRow, } from "@fungi.computer/caps/components/data-list";
7
5
  import { FormFooter } from "@fungi.computer/caps/components/field";
6
+ import { KeycapButton } from "@fungi.computer/caps/components/keycap";
8
7
  import { SchemaForm, field, useSchemaForm } from "@fungi.computer/caps/form";
9
8
  import { Sigil } from "@fungi.computer/sigils";
10
9
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
11
10
  import { Fragment, useMemo, useState } from "react";
12
11
  import * as z from "zod";
12
+ import { SettingsItem } from "./settings-item.js";
13
13
  /** One connected MCP server as the host lists it; the token never comes back. */
14
14
  const agentMcpServerSchema = z.strictObject({
15
15
  serverId: z.string().min(1),
@@ -41,12 +41,12 @@ export function AgentMcpServers({ port }) {
41
41
  const agents = view.data?.agents ?? [];
42
42
  // A fresh form after each connected server, so the token field empties.
43
43
  const [formKey, setFormKey] = useState(0);
44
- return (_jsxs("section", { className: "tourtois-settings-content tourtois-connectors", "aria-label": "Connectors", children: [_jsx(SectionHeading, { children: "Connectors" }), _jsxs("p", { className: "tourtois-settings-lede", children: ["Connect a remote MCP server to an Agent. Its tools become", " ", _jsx("code", { children: "env.mcp.<name>" }), " in that Agent's code. A token stays with the Agent and is never shown again."] }), view.isPending ? _jsx("p", { children: "Loading MCP servers\u2026" }) : null, view.isError ? (_jsxs("div", { role: "status", children: [_jsx("p", { children: "MCP servers could not be loaded." }), _jsx(Button, { size: "sm", onClick: () => void view.refetch(), children: "Retry" })] })) : null, view.isSuccess && agents.length === 0 ? (_jsx("p", { children: "Create an Agent first, then connect MCP servers to it." })) : null, agents.length > 0 ? (_jsxs(_Fragment, { children: [_jsx(DataList, { "aria-label": "Agent MCP servers", children: agents.map((agent) => (_jsxs(Fragment, { children: [_jsx(DataListHeading, { children: agent.name }), agent.servers.length === 0 ? (_jsx(DataRow, { children: "No MCP servers." })) : null, agent.servers.map((server) => (_jsx(DataRow, { className: "p-0", children: _jsx(ActionRow, { icon: _jsx(Sigil, { name: "connected" }), label: _jsxs(_Fragment, { children: [server.name, " ", _jsx(Badge, { size: "sm", variant: "quiet", children: "MCP" })] }), description: server.url, trailing: _jsxs(_Fragment, { children: [server.hasBearer ? (_jsx(Badge, { size: "sm", variant: "quiet", children: "Token saved" })) : null, _jsx(Button, { size: "sm", variant: "ghost", "aria-label": `Remove ${server.name} from ${agent.name}`, disabled: remove.isPending, onClick: () => {
45
- remove.mutate({
46
- agentId: agent.agentId,
47
- serverId: server.serverId,
48
- });
49
- }, children: "Remove" })] }) }) }, server.serverId)))] }, agent.agentId))) }), remove.isError ? (_jsx("p", { role: "alert", children: "The MCP server could not be removed." })) : null, _jsx(AddMcpServer, { agents: agents, onAdd: async (agentId, draft) => {
44
+ return (_jsxs("section", { className: "tourtois-settings-content tourtois-connectors", "aria-label": "Connectors", children: [_jsx(SectionHeading, { children: "Connectors" }), _jsxs("p", { className: "tourtois-settings-lede", children: ["Connect a remote MCP server to an Agent. Its tools become", " ", _jsx("code", { children: "env.mcp.<name>" }), " in that Agent's code. A token is sealed by this Oyster, never given to the Agent, and never shown again."] }), view.isPending ? _jsx("p", { children: "Loading MCP servers\u2026" }) : null, view.isError ? (_jsxs("div", { role: "status", className: "tourtois-settings-notice", children: [_jsx("p", { children: "MCP servers could not be loaded." }), _jsx(Button, { size: "sm", variant: "outline", onClick: () => void view.refetch(), children: "Retry" })] })) : null, view.isSuccess && agents.length === 0 ? (_jsx("p", { children: "Create an Agent first, then connect MCP servers to it." })) : null, agents.length > 0 ? (_jsxs(_Fragment, { children: [_jsx(DataList, { "aria-label": "Agent MCP servers", children: agents.map((agent) => (_jsxs(Fragment, { children: [_jsx(DataListHeading, { children: agent.name }), agent.servers.length === 0 ? (_jsx(DataRow, { className: "tourtois-settings-empty", children: "No MCP servers." })) : null, agent.servers.map((server) => (_jsx(DataRow, { children: _jsx(SettingsItem, { icon: _jsx(Sigil, { name: "connected" }), title: server.name, detail: _jsxs("p", { children: [server.url, server.hasBearer ? " · Token saved" : ""] }), actions: _jsx(KeycapButton, { density: "compact", tone: "destructive", label: "Remove", "aria-label": `Remove ${server.name} from ${agent.name}`, disabled: remove.isPending, onClick: () => {
45
+ remove.mutate({
46
+ agentId: agent.agentId,
47
+ serverId: server.serverId,
48
+ });
49
+ } }) }) }, server.serverId)))] }, agent.agentId))) }), remove.isError ? (_jsx("p", { role: "alert", children: "The MCP server could not be removed." })) : null, _jsx(AddMcpServer, { agents: agents, onAdd: async (agentId, draft) => {
50
50
  await port.add(agentId, draft);
51
51
  await refresh();
52
52
  setFormKey((current) => current + 1);
@@ -56,6 +56,7 @@ function AddMcpServer({ agents, onAdd, }) {
56
56
  const schema = useMemo(() => z.object({
57
57
  agentId: z.string().meta(field({
58
58
  label: "Agent",
59
+ icon: _jsx(Sigil, { name: "agent" }),
59
60
  kind: "select",
60
61
  options: Object.fromEntries(agents.map((agent) => [agent.agentId, agent.name])),
61
62
  })),
@@ -64,6 +65,7 @@ function AddMcpServer({ agents, onAdd, }) {
64
65
  .regex(/^[a-z][a-z0-9_]{0,31}$/u, "Lowercase letters, digits and _, starting with a letter")
65
66
  .meta(field({
66
67
  label: "Name",
68
+ icon: _jsx(Sigil, { name: "write" }),
67
69
  help: "The Agent calls its tools as env.mcp.<name>.",
68
70
  maxLength: 32,
69
71
  placeholder: "linear",
@@ -74,6 +76,7 @@ function AddMcpServer({ agents, onAdd, }) {
74
76
  .refine((value) => URL.canParse(value) && new URL(value).protocol === "https:", "Use the server's https:// address")
75
77
  .meta(field({
76
78
  label: "Server URL",
79
+ icon: _jsx(Sigil, { name: "internet" }),
77
80
  kind: "url",
78
81
  placeholder: "https://mcp.example.com/mcp",
79
82
  })),
@@ -82,8 +85,8 @@ function AddMcpServer({ agents, onAdd, }) {
82
85
  .max(4_096)
83
86
  .meta(field({
84
87
  label: "Bearer token",
85
- help: "Only if the server asks for one.",
86
- optional: true,
88
+ icon: _jsx(Sigil, { name: "restricted" }),
89
+ help: "Optional: only if the server asks for one.",
87
90
  kind: "secret",
88
91
  })),
89
92
  }), [agents]);
@@ -120,5 +123,5 @@ function AddMcpServer({ agents, onAdd, }) {
120
123
  }
121
124
  },
122
125
  });
123
- return (_jsx(SchemaForm, { model: model, "aria-label": "Add MCP server", disabled: add.isPending, footer: _jsx(FormFooter, { error: model.error, children: _jsx(Button, { type: "submit", children: add.isPending ? "Connecting…" : "Add MCP server" }) }) }));
126
+ return (_jsx(SchemaForm, { model: model, layout: "columns", "aria-label": "Add MCP server", disabled: add.isPending, footer: _jsx(FormFooter, { divider: false, error: model.error, children: _jsx(Button, { type: "submit", children: add.isPending ? "Connecting…" : "Add MCP server" }) }) }));
124
127
  }
@@ -1,14 +1,15 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Card } from "@fungi.computer/caps/components/card";
3
- import { DataListHeading } from "@fungi.computer/caps/components/data-list";
4
- import { RadioGroup, RadioGroupItem, RadioGroupCard, } from "@fungi.computer/caps/components/radio-group";
3
+ import { Field, FieldSet } from "@fungi.computer/caps/components/field";
4
+ import { IconRadio, SwatchRadio, } from "@fungi.computer/caps/components/icon-radio";
5
+ import { RadioGroup } from "@fungi.computer/caps/components/radio-group";
5
6
  import { Switch } from "@fungi.computer/caps/components/switch";
6
7
  import { Input } from "@fungi.computer/caps/components/input";
7
- import { Field } from "@fungi.computer/caps/components/field";
8
8
  import { renderStyles, renderStyleLabels, renderStyleSchema, resolveAppearance, } from "@fungi.computer/sprite";
9
9
  import { avatarCharacters, avatarEnvelopeSchema, } from "@fungi.computer/sprite/avatar";
10
10
  import { avatarCatalog } from "@fungi.computer/sprite-zdog/catalog";
11
11
  import { memberAvatarSchema, deriveAgentAvatar, } from "@fungi.computer/sprite-zdog/avatar";
12
+ import { Sigil } from "@fungi.computer/sigils";
12
13
  import { AvatarPreview } from "./AvatarPreview.js";
13
14
  const names = { mushroom: "Shiitake", cat: "Cat", burger: "Burger" };
14
15
  const swatches = [
@@ -33,46 +34,54 @@ export function AvatarPicker({ value, disabled, onChange, }) {
33
34
  onChange(memberAvatarSchema.parse({ ...value, avatar: { ...avatar, ...next } }));
34
35
  };
35
36
  const primarySlot = catalog.identitySlots[0];
37
+ const colourLabel = avatar.character === "mushroom" ? "Cap colour" : "Colour";
36
38
  const selectedSwatch = swatches.find(([, primary, secondary]) => catalog.identitySlots.every((slot, index) => resolved[slot] === (index === 0 ? primary : secondary)))?.[0] ?? "";
37
- return (_jsxs("div", { className: "tourtois-avatar-picker", children: [_jsxs(Card, { className: "tourtois-avatar-preview", children: [_jsx(AvatarPreview, { avatar: avatar, className: "tourtois-avatar-large" }), _jsx("strong", { children: "Your avatar" }), _jsx("p", { children: "One look for your account, across Teams." })] }), _jsxs("fieldset", { disabled: disabled, className: "tourtois-avatar-controls", children: [_jsx("legend", { className: "sr-only", children: "Customize your avatar" }), _jsxs("section", { "aria-labelledby": "avatar-character", children: [_jsx(DataListHeading, { level: 3, id: "avatar-character", children: "Character" }), _jsx(RadioGroup, { "aria-labelledby": "avatar-character", className: "tourtois-avatar-characters", orientation: "horizontal", value: avatar.character, onValueChange: (raw) => {
38
- const character = avatarEnvelopeSchema.shape.character.parse(raw);
39
- change({ character, appearance: {}, expression: "normal" });
40
- }, children: avatarCharacters.map((character) => (_jsx(RadioGroupCard, { value: character, title: names[character], description: _jsx(AvatarPreview, { avatar: {
41
- ...avatar,
42
- character,
43
- appearance: character === avatar.character ? avatar.appearance : {},
44
- expression: "normal",
45
- }, className: "tourtois-avatar-character-preview" }) }, character))) })] }), _jsxs("section", { "aria-labelledby": "avatar-colours", children: [_jsx(DataListHeading, { level: 3, id: "avatar-colours", children: avatar.character === "mushroom" ? "Cap colour" : "Colour" }), _jsx(RadioGroup, { "aria-labelledby": "avatar-colours", className: "tourtois-avatar-swatches", orientation: "horizontal", value: selectedSwatch, onValueChange: (name) => {
46
- const swatch = swatches.find(([label]) => label === name);
47
- if (!swatch)
48
- return;
49
- change({
50
- appearance: {
51
- ...avatar.appearance,
52
- ...Object.fromEntries(catalog.identitySlots.map((slot, index) => [
53
- slot,
54
- swatch[index === 0 ? 1 : 2],
55
- ])),
56
- },
57
- });
58
- }, children: swatches.map(([name, color]) => (_jsx("label", { title: name, className: "tourtois-avatar-swatch", style: { backgroundColor: color }, children: _jsx(RadioGroupItem, { value: name, "aria-label": name }) }, name))) }), _jsx("div", { className: "tourtois-avatar-custom-colours", children: catalog.identitySlots.map((slot) => {
59
- const control = catalog.controls[slot];
60
- if (control?.type !== "color")
61
- return null;
62
- return (_jsx(Field, { label: slot === primarySlot ? "Custom colour" : "Accent colour", children: _jsx(Input, { type: "color", defaultValue: String(resolved[slot]), onBlur: (event) => {
63
- if (event.currentTarget.value !== resolved[slot])
64
- change({
65
- appearance: {
66
- ...avatar.appearance,
67
- [slot]: event.currentTarget.value,
68
- },
69
- });
70
- } }) }, `${avatar.character}:${slot}:${String(resolved[slot])}`));
71
- }) })] }), _jsxs("section", { "aria-labelledby": "avatar-expression", children: [_jsx(DataListHeading, { level: 3, id: "avatar-expression", children: "Resting face" }), _jsx(RadioGroup, { "aria-labelledby": "avatar-expression", className: "tourtois-avatar-faces", orientation: "horizontal", value: avatar.expression, onValueChange: (expression) => {
72
- change({ expression });
73
- }, children: catalog.expressions.map((expression) => (_jsx(RadioGroupCard, { value: expression, title: expression.charAt(0).toUpperCase() + expression.slice(1) }, expression))) })] }), _jsxs("section", { "aria-labelledby": "avatar-style", children: [_jsx(DataListHeading, { level: 3, id: "avatar-style", children: "Drawing style" }), _jsx(RadioGroup, { "aria-labelledby": "avatar-style", className: "tourtois-sprite-styles", orientation: "horizontal", value: avatar.renderStyle, onValueChange: (raw) => {
74
- change({ renderStyle: renderStyleSchema.parse(raw) });
75
- }, children: renderStyles.map((renderStyle) => (_jsx(RadioGroupCard, { value: renderStyle, title: renderStyleLabels[renderStyle], description: _jsx(AvatarPreview, { avatar: { ...avatar, renderStyle }, className: "tourtois-sprite-style-preview" }) }, renderStyle))) })] }), _jsxs("section", { "aria-labelledby": "avatar-agents", children: [_jsx(DataListHeading, { level: 3, id: "avatar-agents", children: "Your new Agents" }), _jsx(Field, { label: "Give each Agent its own colour", children: _jsx(Switch, { checked: agentColors === "shift", onCheckedChange: (checked) => {
76
- onChange({ ...value, agentColors: checked ? "shift" : "keep" });
77
- } }) }), _jsx("p", { className: "tourtois-settings-lede", children: "A preview of your preference for new Agents. Existing Agents keep their look." }), _jsx("div", { className: "tourtois-avatar-agents", children: exampleNames.map((name) => (_jsxs("div", { children: [_jsx(AvatarPreview, { avatar: deriveAgentAvatar(avatar, agentColors, name), className: "tourtois-avatar-agent-preview" }), _jsx("span", { children: name })] }, name))) })] })] })] }));
39
+ return (_jsxs("div", { className: "tourtois-avatar-picker", children: [_jsxs(Card, { className: "tourtois-avatar-preview", children: [_jsx(AvatarPreview, { avatar: avatar, className: "tourtois-avatar-large" }), _jsx("strong", { children: "Your avatar" }), _jsx("p", { children: "One look for your account, across Teams." })] }), _jsxs("fieldset", { disabled: disabled, className: "tourtois-avatar-controls", children: [_jsx("legend", { className: "sr-only", children: "Customize your avatar" }), _jsx(FieldSet, { legend: "Character", icon: _jsx(Sigil, { name: "agent" }), layout: "columns", children: _jsx(RadioGroup, { "aria-label": "Character", className: "caps-field-icon-choices", orientation: "horizontal", value: avatar.character, onValueChange: (raw) => {
40
+ const character = avatarEnvelopeSchema.shape.character.parse(raw);
41
+ change({ character, appearance: {}, expression: "normal" });
42
+ }, children: avatarCharacters.map((character) => (_jsx(IconRadio, { value: character, label: names[character], caption: names[character], art: "color", icon: _jsx(AvatarPreview, { avatar: {
43
+ ...avatar,
44
+ character,
45
+ appearance: character === avatar.character ? avatar.appearance : {},
46
+ expression: "normal",
47
+ }, className: "tourtois-avatar-key-art" }) }, character))) }) }), _jsx(FieldSet, { legend: colourLabel, icon: _jsx(Sigil, { name: "prints" }), layout: "columns", children: _jsx(RadioGroup, { "aria-label": colourLabel, className: "caps-field-icon-choices", orientation: "horizontal", value: selectedSwatch, onValueChange: (name) => {
48
+ const swatch = swatches.find(([label]) => label === name);
49
+ if (!swatch)
50
+ return;
51
+ change({
52
+ appearance: {
53
+ ...avatar.appearance,
54
+ ...Object.fromEntries(catalog.identitySlots.map((slot, index) => [
55
+ slot,
56
+ swatch[index === 0 ? 1 : 2],
57
+ ])),
58
+ },
59
+ });
60
+ }, children: swatches.map(([name, color]) => (_jsx(SwatchRadio, { value: name, label: name, color: color }, name))) }) }), _jsx(FieldSet, { legend: "Custom", icon: _jsx(Sigil, { name: "write" }), layout: "columns", children: _jsx("div", { className: "tourtois-avatar-custom-colours", children: catalog.identitySlots.map((slot) => {
61
+ const control = catalog.controls[slot];
62
+ if (control?.type !== "color")
63
+ return null;
64
+ const label = slot === primarySlot ? "Custom colour" : "Accent colour";
65
+ return (_jsx(Input, { type: "color", "aria-label": label, title: label, defaultValue: String(resolved[slot]), onBlur: (event) => {
66
+ if (event.currentTarget.value !== resolved[slot])
67
+ change({
68
+ appearance: {
69
+ ...avatar.appearance,
70
+ [slot]: event.currentTarget.value,
71
+ },
72
+ });
73
+ } }, `${avatar.character}:${slot}:${String(resolved[slot])}`));
74
+ }) }) }), _jsx(FieldSet, { legend: "Resting face", icon: _jsx(Sigil, { name: "chat" }), layout: "columns", children: _jsx(RadioGroup, { "aria-label": "Resting face", className: "caps-field-icon-choices", orientation: "horizontal", value: avatar.expression, onValueChange: (expression) => {
75
+ change({ expression });
76
+ }, children: catalog.expressions.map((expression) => {
77
+ const label = expression.charAt(0).toUpperCase() + expression.slice(1);
78
+ return (_jsx(IconRadio, { value: expression, label: label, caption: label, art: "color", icon: _jsx(AvatarPreview, { avatar: { ...avatar, expression }, className: "tourtois-avatar-key-art" }) }, expression));
79
+ }) }) }), _jsx(FieldSet, { legend: "Drawing style", icon: _jsx(Sigil, { name: "generateMedia" }), layout: "columns", children: _jsx(RadioGroup, { "aria-label": "Drawing style", className: "caps-field-icon-choices", orientation: "horizontal", value: avatar.renderStyle, onValueChange: (raw) => {
80
+ change({ renderStyle: renderStyleSchema.parse(raw) });
81
+ }, children: renderStyles.map((renderStyle) => (_jsx(IconRadio, { value: renderStyle, label: renderStyleLabels[renderStyle], caption: renderStyleLabels[renderStyle], art: "color", icon: _jsx(AvatarPreview, { avatar: { ...avatar, renderStyle }, className: "tourtois-avatar-key-art" }) }, renderStyle))) }) }), _jsx(FieldSet, { legend: "New Agents", icon: _jsx(Sigil, { name: "members" }), layout: "columns", description: "A preview of your preference for new Agents. Existing Agents keep their look.", children: _jsxs("div", { className: "tourtois-avatar-agents-panel", children: [_jsx(Field, { label: "Give each Agent its own colour", orientation: "inline", children: _jsx(Switch, { checked: agentColors === "shift", onCheckedChange: (checked) => {
82
+ onChange({
83
+ ...value,
84
+ agentColors: checked ? "shift" : "keep",
85
+ });
86
+ } }) }), _jsx("div", { className: "tourtois-avatar-agents", children: exampleNames.map((name) => (_jsxs("div", { children: [_jsx(AvatarPreview, { avatar: deriveAgentAvatar(avatar, agentColors, name), className: "tourtois-avatar-agent-preview" }), _jsx("span", { children: name })] }, name))) })] }) })] })] }));
78
87
  }
package/dist/Keys.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Grant } from "@fungi.computer/ear-tag/grants";
2
2
  import type { IssueKeyInput, KeySummary, UpdateGrantsInput } from "@fungi.computer/ear-tag/keys";
3
3
  import { type ComponentType } from "react";
4
+ import { type SigilName } from "@fungi.computer/sigils";
4
5
  export type KeyAppOption = Readonly<{
5
6
  installationId: string;
6
7
  displayName: string;
@@ -13,6 +14,10 @@ export type KeyTargetOption = Readonly<{
13
14
  export type KeyGrantOption = Readonly<{
14
15
  capability: string;
15
16
  label: string;
17
+ /** The grant's Sigil on its check key; a lock when absent. */
18
+ icon?: SigilName;
19
+ /** One quiet line under the label, such as "Owner only". */
20
+ hint?: string;
16
21
  /** Omit for capabilities which have no selected-target form. */
17
22
  targets?: readonly KeyTargetOption[];
18
23
  }>;
package/dist/Keys.js CHANGED
@@ -1,15 +1,18 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { SectionHeading } from "@fungi.computer/caps/blocks/section-heading";
3
3
  import { Button } from "@fungi.computer/caps/components/button";
4
- import { Checkbox } from "@fungi.computer/caps/components/checkbox";
4
+ import { CheckKey, CheckKeys, } from "@fungi.computer/caps/components/icon-checkbox";
5
5
  import { DataList, DataRow } from "@fungi.computer/caps/components/data-list";
6
- import { Field, FormFooter } from "@fungi.computer/caps/components/field";
6
+ import { FieldSet, FormFooter } from "@fungi.computer/caps/components/field";
7
+ import { KeycapButton } from "@fungi.computer/caps/components/keycap";
7
8
  import { Input } from "@fungi.computer/caps/components/input";
8
- import { FormFields, SchemaForm, field, useSchemaForm, useSchemaFormStatus, } from "@fungi.computer/caps/form";
9
+ import { SchemaForm, field, useSchemaForm, useSchemaFormStatus, } from "@fungi.computer/caps/form";
9
10
  import { defineIdFamily } from "@fungi.computer/cairn/id";
10
11
  import { useQuery, useQueryClient } from "@tanstack/react-query";
11
12
  import { useState } from "react";
12
13
  import * as z from "zod";
14
+ import { Sigil } from "@fungi.computer/sigils";
15
+ import { SettingsItem } from "./settings-item.js";
13
16
  const mutationIds = defineIdFamily({
14
17
  family: "tourtois-keys-mutation",
15
18
  version: 1,
@@ -68,21 +71,22 @@ function KeysContent({ port, apps, }) {
68
71
  }
69
72
  };
70
73
  const labels = new Map(options.data?.map((option) => [option.capability, option.label]));
71
- return (_jsxs("section", { className: "tourtois-settings-content tourtois-keys", "aria-label": "Keys", children: [_jsx(SectionHeading, { children: "Keys" }), _jsx("p", { className: "tourtois-settings-lede", children: "Anyone holding a key can act with your current access, limited to its grants and expiry, without asking again. Read grants cannot make changes. Grants which run Workflows can also run them with your access, within the key's targets." }), view.isPending ? _jsx("p", { children: "Loading keys\u2026" }) : null, view.isError ? (_jsxs("p", { role: "alert", children: ["Keys could not be loaded.", " ", _jsx(Button, { onClick: () => void view.refetch(), children: "Retry" })] })) : null, options.isError ? (_jsxs("p", { role: "alert", children: ["Capability targets could not be loaded.", " ", _jsx(Button, { onClick: () => void options.refetch(), children: "Retry targets" })] })) : null, view.isSuccess && view.data.keys.length === 0 ? (_jsx("p", { children: "No keys yet." })) : null, _jsx(DataList, { "aria-label": "Keys", children: (view.data?.keys ?? []).map((key) => (_jsx(DataRow, { style: { gridTemplateColumns: "minmax(0, 1fr)" }, children: _jsxs("div", { className: "grid min-w-0 gap-sm", children: [_jsxs("div", { className: "grid min-w-0 gap-xs break-words", children: [_jsxs("strong", { children: [key.name, key.revokedAt !== null ? " · Revoked" : ""] }), _jsx("p", { children: key.grants.length === 0
72
- ? "Authority unavailable; revoke and issue a new key."
73
- : key.grants
74
- .map((grant) => `${labels.get(grant.capability) ?? grant.capability}: ${grant.targets.kind === "all" ? "all current and future targets" : grant.targets.ids.join(", ")}`)
75
- .join(" · ") }), _jsxs("p", { children: [key.expiresAt === null
76
- ? "Never expires"
77
- : `${key.expiresAt <= Date.now() ? "Expired" : "Expires"} ${new Date(key.expiresAt).toLocaleString()}`, " ", "\u00B7", " ", key.lastUsedAt === null
78
- ? "Use not recorded"
79
- : `Last used ${new Date(key.lastUsedAt).toLocaleString()}`] })] }), key.revokedAt === null ? (_jsxs("div", { className: "flex flex-wrap gap-sm", children: [port.updateGrants !== undefined && key.grants.length > 0 ? (_jsx(Button, { "aria-label": `Edit ${key.name}`, disabled: busy || command !== null, onClick: () => {
80
- setEditing(key);
81
- }, children: "Edit" })) : null, _jsx(Button, { "aria-label": `Revoke ${key.name}`, disabled: busy || command !== null, onClick: () => void mutate({
82
- kind: "revoke",
83
- keyId: key.keyId,
84
- requestId: mutationIds.request.generate(),
85
- }), children: "Revoke" })] })) : null] }) }, key.keyId))) }), notice ? _jsx("p", { role: "status", children: notice }) : null, error ? _jsx("p", { role: "alert", children: error }) : null, command !== null ? (_jsxs("div", { className: "flex gap-sm", children: [_jsx(Button, { disabled: busy, onClick: () => void mutate(command), children: "Retry key change" }), _jsx(Button, { disabled: busy, onClick: () => {
74
+ return (_jsxs("section", { className: "tourtois-settings-content tourtois-settings-stack tourtois-keys", "aria-label": "Keys", children: [_jsx(SectionHeading, { children: "Keys" }), _jsx("p", { className: "tourtois-settings-lede", children: "Anyone holding a key can act with your current access, limited to its grants and expiry, without asking again. Read grants cannot make changes. Grants which run Workflows can also run them with your access, within the key's targets." }), view.isPending ? _jsx("p", { children: "Loading keys\u2026" }) : null, view.isError ? (_jsxs("div", { role: "alert", className: "tourtois-settings-notice", children: [_jsx("p", { children: "Keys could not be loaded." }), _jsx(Button, { size: "sm", variant: "outline", onClick: () => void view.refetch(), children: "Retry" })] })) : null, options.isError ? (_jsxs("div", { role: "alert", className: "tourtois-settings-notice", children: [_jsx("p", { children: "Capability targets could not be loaded." }), _jsx(Button, { size: "sm", variant: "outline", onClick: () => void options.refetch(), children: "Retry targets" })] })) : null, view.isSuccess && view.data.keys.length === 0 ? (_jsx("p", { className: "tourtois-settings-empty", children: "No keys yet." })) : null, _jsx(DataList, { "aria-label": "Keys", children: (view.data?.keys ?? []).map((key) => (_jsx(DataRow, { children: _jsx(SettingsItem, { icon: _jsx(Sigil, { name: "restricted" }), title: `${key.name}${key.revokedAt !== null ? " · Revoked" : ""}`, detail: _jsxs(_Fragment, { children: [_jsx("p", { children: key.grants.length === 0
75
+ ? "Authority unavailable; revoke and issue a new key."
76
+ : key.grants
77
+ .map((grant) => `${labels.get(grant.capability) ?? grant.capability}: ${grant.targets.kind === "all" ? "all current and future targets" : grant.targets.ids.join(", ")}`)
78
+ .join(" · ") }), _jsxs("p", { children: [key.expiresAt === null
79
+ ? "Never expires"
80
+ : `${key.expiresAt <= Date.now() ? "Expired" : "Expires"} ${new Date(key.expiresAt).toLocaleString()}`, " ", "\u00B7", " ", key.lastUsedAt === null
81
+ ? "Use not recorded"
82
+ : `Last used ${new Date(key.lastUsedAt).toLocaleString()}`] })] }), actions: key.revokedAt === null ? (_jsxs(_Fragment, { children: [port.updateGrants !== undefined &&
83
+ key.grants.length > 0 ? (_jsx(KeycapButton, { density: "compact", label: "Edit", icon: _jsx(Sigil, { name: "write" }), "aria-label": `Edit ${key.name}`, disabled: busy || command !== null, onClick: () => {
84
+ setEditing(key);
85
+ } })) : null, _jsx(KeycapButton, { density: "compact", tone: "destructive", label: "Revoke", "aria-label": `Revoke ${key.name}`, disabled: busy || command !== null, onClick: () => void mutate({
86
+ kind: "revoke",
87
+ keyId: key.keyId,
88
+ requestId: mutationIds.request.generate(),
89
+ }) })] })) : undefined }) }, key.keyId))) }), notice ? _jsx("p", { role: "status", children: notice }) : null, error ? _jsx("p", { role: "alert", children: error }) : null, command !== null ? (_jsxs("div", { className: "tourtois-settings-notice", children: [_jsx(Button, { size: "sm", variant: "outline", disabled: busy, onClick: () => void mutate(command), children: "Retry key change" }), _jsx(Button, { size: "sm", variant: "outline", disabled: busy, onClick: () => {
86
90
  setCommand(null);
87
91
  setEditing(null);
88
92
  void refresh();
@@ -96,53 +100,60 @@ function KeysContent({ port, apps, }) {
96
100
  expectedGrantVersion: editing.grantVersion,
97
101
  grants,
98
102
  },
99
- }) }, editing.keyId + ":" + String(editing.grantVersion))) : null, _jsx(SectionHeading, { children: "New key" }), issued === null ? (options.data === undefined ? (_jsx("p", { children: "Loading capability targets\u2026" })) : (_jsx(IssueKey, { port: port, options: options.data, onIssue: async (draft) => {
103
+ }) }, editing.keyId + ":" + String(editing.grantVersion))) : null, _jsx(SectionHeading, { children: "New key" }), issued === null ? (options.data === undefined ? (_jsx("p", { className: "tourtois-settings-empty", children: "Loading capability targets\u2026" })) : (_jsx(IssueKey, { port: port, options: options.data, onIssue: async (draft) => {
100
104
  const result = await port.issue(draft);
101
105
  setIssued(result);
102
106
  await refresh();
103
- } }))) : (_jsxs("div", { className: "grid gap-sm", role: "status", children: [_jsx("p", { children: "Copy this key now. It is shown once and cannot be retrieved later." }), _jsx("code", { className: "break-all", children: issued.plaintext }), _jsx(Button, { onClick: () => {
104
- setIssued(null);
105
- }, children: "I copied the key" })] }))] }));
107
+ } }))) : (_jsxs("div", { className: "tourtois-settings-stack", role: "status", children: [_jsx("p", { className: "tourtois-settings-lede", children: "Copy this key now. It is shown once and cannot be retrieved later." }), _jsx("code", { className: "break-all", children: issued.plaintext }), _jsx("div", { className: "tourtois-settings-notice", children: _jsx(Button, { size: "sm", onClick: () => {
108
+ setIssued(null);
109
+ }, children: "I copied the key" }) })] }))] }));
106
110
  }
107
111
  function GrantEditor({ grants, onChange, options, disabled, }) {
108
- return (_jsxs("fieldset", { className: "grid gap-sm", disabled: disabled, children: [_jsx("legend", { children: "Capability grants" }), options.map((option) => {
112
+ return (_jsxs(FieldSet, { legend: "Grants", icon: _jsx(Sigil, { name: "restricted" }), layout: "columns", disabled: disabled, className: "tourtois-key-grants", children: [_jsx(CheckKeys, { children: options.map((option) => (_jsx(CheckKey, { name: "cap:" + option.capability, label: option.label, icon: _jsx(Sigil, { name: option.icon ?? "restricted" }), hint: option.hint, checked: grants.some((current) => current.capability === option.capability), onChange: (event) => {
113
+ onChange(event.currentTarget.checked
114
+ ? [
115
+ ...grants,
116
+ {
117
+ capability: option.capability,
118
+ targets: { kind: "all" },
119
+ },
120
+ ]
121
+ : grants.filter((current) => current.capability !== option.capability));
122
+ } }, option.capability))) }), options.map((option) => {
109
123
  const grant = grants.find((current) => current.capability === option.capability);
124
+ if (grant === undefined || option.targets === undefined)
125
+ return null;
110
126
  const replace = (targets) => {
111
127
  onChange(grants.map((current) => current.capability === option.capability
112
128
  ? { ...current, targets }
113
129
  : current));
114
130
  };
115
- return (_jsxs("div", { className: "grid gap-xs", children: [_jsx(Field, { label: option.label, orientation: "inline", children: _jsx(Checkbox, { name: "cap:" + option.capability, checked: grant !== undefined, onChange: (event) => {
116
- onChange(event.currentTarget.checked
117
- ? [
118
- ...grants,
119
- {
120
- capability: option.capability,
121
- targets: { kind: "all" },
122
- },
123
- ]
124
- : grants.filter((current) => current.capability !== option.capability));
125
- } }) }), grant !== undefined && option.targets !== undefined ? (_jsxs("div", { className: "grid gap-xs pl-md", children: [_jsx(Field, { label: "All current and future targets", orientation: "inline", children: _jsx(Checkbox, { name: "all:" + option.capability, checked: grant.targets.kind === "all", onChange: (event) => {
126
- replace(event.currentTarget.checked
127
- ? { kind: "all" }
128
- : { kind: "selected", ids: [] });
129
- } }) }), grant.targets.kind === "selected" ? (_jsxs(_Fragment, { children: [option.targets.length === 0 ? (_jsx("p", { children: "No targets available." })) : null, option.targets.map((target) => (_jsx(Field, { label: target.name, orientation: "inline", children: _jsx(Checkbox, { name: option.capability + ":" + target.id, checked: grant.targets.kind === "selected" &&
130
- grant.targets.ids.includes(target.id), onChange: (event) => {
131
- const ids = grant.targets.kind === "selected"
132
- ? grant.targets.ids
133
- : [];
134
- replace({
135
- kind: "selected",
136
- ids: event.currentTarget.checked
137
- ? [...ids, target.id]
138
- : ids.filter((id) => id !== target.id),
139
- });
140
- } }) }, target.id))), grant.targets.ids
141
- .filter((id) => !option.targets?.some((target) => target.id === id))
142
- .map((id) => (_jsxs("p", { children: ["Unavailable target: ", id] }, id)))] })) : null] })) : null] }, option.capability));
131
+ return (_jsxs("div", { role: "group", "aria-label": `${option.label} targets`, className: "tourtois-key-targets", children: [_jsx("p", { className: "tourtois-key-targets-label", children: option.label }), _jsxs(CheckKeys, { children: [_jsx(CheckKey, { name: "all:" + option.capability, label: "All targets", hint: "Current and future", checked: grant.targets.kind === "all", onChange: (event) => {
132
+ replace(event.currentTarget.checked
133
+ ? { kind: "all" }
134
+ : { kind: "selected", ids: [] });
135
+ } }), grant.targets.kind === "selected"
136
+ ? option.targets.map((target) => (_jsx(CheckKey, { name: option.capability + ":" + target.id, label: target.name, checked: grant.targets.kind === "selected" &&
137
+ grant.targets.ids.includes(target.id), onChange: (event) => {
138
+ const ids = grant.targets.kind === "selected"
139
+ ? grant.targets.ids
140
+ : [];
141
+ replace({
142
+ kind: "selected",
143
+ ids: event.currentTarget.checked
144
+ ? [...ids, target.id]
145
+ : ids.filter((id) => id !== target.id),
146
+ });
147
+ } }, target.id)))
148
+ : null] }), grant.targets.kind === "selected" &&
149
+ option.targets.length === 0 ? (_jsx("p", { className: "tourtois-settings-empty", children: "No targets available." })) : null, grant.targets.kind === "selected"
150
+ ? grant.targets.ids
151
+ .filter((id) => !option.targets?.some((target) => target.id === id))
152
+ .map((id) => (_jsxs("p", { className: "tourtois-settings-empty", children: ["Unavailable target: ", id] }, id)))
153
+ : null] }, option.capability));
143
154
  }), grants
144
155
  .filter((grant) => !options.some((option) => option.capability === grant.capability))
145
- .map((grant) => (_jsxs("div", { children: [_jsxs("p", { children: [grant.capability, " is no longer offered by this host."] }), _jsxs(Button, { type: "button", onClick: () => {
156
+ .map((grant) => (_jsxs("div", { children: [_jsxs("p", { children: [grant.capability, " is no longer offered by this host."] }), _jsxs(Button, { type: "button", size: "sm", variant: "outline", onClick: () => {
146
157
  onChange(grants.filter((current) => current !== grant));
147
158
  }, children: ["Remove ", grant.capability] })] }, grant.capability)))] }));
148
159
  }
@@ -174,7 +185,6 @@ function IssueKey({ port, options, onIssue, }) {
174
185
  } })) }));
175
186
  }
176
187
  function IssueForm({ port, grants, ready, onIssue, }) {
177
- const [custom, setCustom] = useState("");
178
188
  const expiryValues = port.expiry === "required"
179
189
  ? ["30", "90", "365", "custom"]
180
190
  : ["30", "90", "365", "custom", "never"];
@@ -191,19 +201,35 @@ function IssueForm({ port, grants, ready, onIssue, }) {
191
201
  .trim()
192
202
  .min(1, "Give this key a name.")
193
203
  .max(128)
194
- .meta(field({ label: "Name", required: true, maxLength: 128 })),
204
+ .meta(field({
205
+ label: "Name",
206
+ icon: _jsx(Sigil, { name: "write" }),
207
+ required: true,
208
+ maxLength: 128,
209
+ })),
195
210
  expiry: expiry.meta(field({
196
211
  label: "Expires after",
212
+ icon: _jsx(Sigil, { name: "schedule" }),
197
213
  options: port.expiry === "optional"
198
214
  ? { ...finiteExpiryOptions, never: "Never" }
199
215
  : finiteExpiryOptions,
200
216
  })),
217
+ // Only a custom expiry asks for its date.
218
+ customExpiry: z.string().meta(field({
219
+ label: "Custom expiry",
220
+ icon: _jsx(Sigil, { name: "schedule" }),
221
+ when: (values) => values.expiry === "custom",
222
+ render: (control) => (_jsx(Input, { type: "datetime-local", id: control.id, name: control.name, "aria-describedby": control["aria-describedby"], "aria-invalid": control["aria-invalid"], disabled: control.disabled, value: control.value, onBlur: control.onBlur, onChange: (event) => {
223
+ control.onChange(event.currentTarget.value);
224
+ } })),
225
+ })),
201
226
  });
202
227
  const model = useSchemaForm({
203
228
  schema,
204
229
  defaultValues: {
205
230
  name: "",
206
231
  expiry: port.expiry === "required" ? "30" : "never",
232
+ customExpiry: "",
207
233
  },
208
234
  onSubmit: async (value) => {
209
235
  if (!ready)
@@ -214,7 +240,7 @@ function IssueForm({ port, grants, ready, onIssue, }) {
214
240
  const expiresAt = value.expiry === "never"
215
241
  ? undefined
216
242
  : value.expiry === "custom"
217
- ? new Date(custom).getTime()
243
+ ? new Date(value.customExpiry).getTime()
218
244
  : Date.now() + Number(value.expiry) * 86_400_000;
219
245
  if (expiresAt !== undefined &&
220
246
  (!Number.isSafeInteger(expiresAt) || expiresAt <= Date.now()))
@@ -235,10 +261,8 @@ function IssueForm({ port, grants, ready, onIssue, }) {
235
261
  },
236
262
  });
237
263
  const { submitting } = useSchemaFormStatus(model);
238
- return (_jsxs(SchemaForm, { model: model, "aria-label": "Issue a key", footer: _jsx(FormFooter, { error: model.error, children: _jsx(Button, { type: "submit", disabled: !ready || submitting, children: "Issue key" }) }), children: [_jsx(FormFields, { model: model }), _jsx(Field, { label: "Custom expiry", children: _jsx(Input, { type: "datetime-local", name: "customExpiry", value: custom, disabled: submitting, onChange: (event) => {
239
- setCustom(event.currentTarget.value);
240
- } }) })] }));
264
+ return (_jsx(SchemaForm, { model: model, layout: "columns", "aria-label": "Issue a key", footer: _jsx(FormFooter, { divider: false, error: model.error, children: _jsx(Button, { type: "submit", disabled: !ready || submitting, children: "Issue key" }) }) }));
241
265
  }
242
266
  function EditKey({ record, port, options, disabled, onSave, onCancel, }) {
243
- return (_jsxs("section", { "aria-label": "Edit " + record.name, className: "grid gap-sm", children: [_jsxs(SectionHeading, { children: ["Edit ", record.name] }), _jsx(GrantDraft, { port: port, options: options, initial: record.grants, disabled: disabled, children: (grants, ready) => (_jsxs("div", { className: "flex gap-sm", children: [_jsx(Button, { disabled: disabled || !ready, onClick: () => void onSave(grants), children: "Save grants" }), _jsx(Button, { disabled: disabled, onClick: onCancel, children: "Cancel" })] })) })] }));
267
+ return (_jsxs("section", { "aria-label": "Edit " + record.name, className: "tourtois-settings-stack", children: [_jsxs(SectionHeading, { children: ["Edit ", record.name] }), _jsx(GrantDraft, { port: port, options: options, initial: record.grants, disabled: disabled, children: (grants, ready) => (_jsxs(FormFooter, { divider: false, children: [_jsx(Button, { type: "button", variant: "ghost", disabled: disabled, onClick: onCancel, children: "Cancel" }), _jsx(Button, { type: "button", disabled: disabled || !ready, onClick: () => void onSave(grants), children: "Save grants" })] })) })] }));
244
268
  }
@@ -0,0 +1,68 @@
1
+ import * as z from "zod";
2
+ declare const providers: {
3
+ readonly anthropic: "Anthropic";
4
+ readonly openai: "OpenAI";
5
+ readonly openrouter: "OpenRouter";
6
+ };
7
+ export type Provider = keyof typeof providers;
8
+ /** Every stored key and every Agent with its persisted model choice. */
9
+ export declare const modelKeysViewSchema: z.ZodObject<{
10
+ keys: z.ZodArray<z.ZodObject<{
11
+ keyId: z.ZodString;
12
+ provider: z.ZodEnum<{
13
+ anthropic: "anthropic";
14
+ openai: "openai";
15
+ openrouter: "openrouter";
16
+ }>;
17
+ label: z.ZodString;
18
+ createdAt: z.ZodNumber;
19
+ validatedAt: z.ZodNumber;
20
+ }, z.core.$strict>>;
21
+ agents: z.ZodArray<z.ZodObject<{
22
+ agentId: z.ZodString;
23
+ name: z.ZodString;
24
+ choice: z.ZodNullable<z.ZodObject<{
25
+ keySource: z.ZodEnum<{
26
+ "workers-ai": "workers-ai";
27
+ "ai-gateway": "ai-gateway";
28
+ byok: "byok";
29
+ }>;
30
+ keyId: z.ZodOptional<z.ZodString>;
31
+ model: z.ZodObject<{
32
+ providerId: z.ZodString;
33
+ modelId: z.ZodString;
34
+ reasoning: z.ZodOptional<z.ZodString>;
35
+ }, z.core.$strict>;
36
+ }, z.core.$strict>>;
37
+ }, z.core.$strict>>;
38
+ }, z.core.$strict>;
39
+ export type ModelKeysView = z.output<typeof modelKeysViewSchema>;
40
+ /** What the owner submits to store one key. */
41
+ export type ModelKeyDraft = Readonly<{
42
+ provider: Provider;
43
+ label: string;
44
+ apiKey: string;
45
+ }>;
46
+ /** The Agent's next model: the instance default, or a stored key's provider. */
47
+ export type AgentModelChoiceDraft = Readonly<{
48
+ keyId: null;
49
+ }> | Readonly<{
50
+ keyId: string;
51
+ provider: Provider;
52
+ modelId: string;
53
+ }>;
54
+ /** The host's owner-direct model-key custody and per-Agent model choice. */
55
+ export type ModelKeysPort = Readonly<{
56
+ read(): Promise<ModelKeysView>;
57
+ addKey(draft: ModelKeyDraft): Promise<void>;
58
+ removeKey(keyId: string): Promise<void>;
59
+ chooseModel(agentId: string, draft: AgentModelChoiceDraft): Promise<void>;
60
+ }>;
61
+ /**
62
+ * Model keys on a standalone host: store a provider API key once, then pick
63
+ * which model and key each Agent runs on. A key is never shown again.
64
+ */
65
+ export declare function ModelKeys({ port }: {
66
+ port: ModelKeysPort;
67
+ }): import("react/jsx-runtime").JSX.Element;
68
+ export {};