@fungi.computer/tourtois 0.6.0 → 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.
- package/dist/AgentMcpServers.js +1 -1
- package/dist/ModelKeys.d.ts +68 -0
- package/dist/ModelKeys.js +200 -0
- package/dist/SystemSettings.js +2 -1
- package/dist/oyster-platform-controls.js +64 -0
- package/dist/settings-sections.d.ts +3 -0
- package/dist/settings-sections.js +1 -1
- package/package.json +11 -11
package/dist/AgentMcpServers.js
CHANGED
|
@@ -41,7 +41,7 @@ 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
|
|
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
45
|
remove.mutate({
|
|
46
46
|
agentId: agent.agentId,
|
|
47
47
|
serverId: server.serverId,
|
|
@@ -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 {};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { SectionHeading } from "@fungi.computer/caps/blocks/section-heading";
|
|
3
|
+
import { Button } from "@fungi.computer/caps/components/button";
|
|
4
|
+
import { DataList, DataListHeading, DataRow, FactRow, } from "@fungi.computer/caps/components/data-list";
|
|
5
|
+
import { FormFooter } from "@fungi.computer/caps/components/field";
|
|
6
|
+
import { KeycapButton } from "@fungi.computer/caps/components/keycap";
|
|
7
|
+
import { SchemaForm, field, useSchemaForm } from "@fungi.computer/caps/form";
|
|
8
|
+
import { Sigil } from "@fungi.computer/sigils";
|
|
9
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
10
|
+
import { useMemo, useState } from "react";
|
|
11
|
+
import * as z from "zod";
|
|
12
|
+
import { SettingsItem } from "./settings-item.js";
|
|
13
|
+
const providers = {
|
|
14
|
+
anthropic: "Anthropic",
|
|
15
|
+
openai: "OpenAI",
|
|
16
|
+
openrouter: "OpenRouter",
|
|
17
|
+
};
|
|
18
|
+
const providerSchema = z.enum(["anthropic", "openai", "openrouter"]);
|
|
19
|
+
/** One stored key as the host lists it; the secret never comes back. */
|
|
20
|
+
const modelKeySchema = z.strictObject({
|
|
21
|
+
keyId: z.string().min(1),
|
|
22
|
+
provider: providerSchema,
|
|
23
|
+
label: z.string().min(1),
|
|
24
|
+
createdAt: z.number(),
|
|
25
|
+
validatedAt: z.number(),
|
|
26
|
+
});
|
|
27
|
+
const agentChoiceSchema = z.strictObject({
|
|
28
|
+
keySource: z.enum(["workers-ai", "ai-gateway", "byok"]),
|
|
29
|
+
keyId: z.string().min(1).optional(),
|
|
30
|
+
model: z.strictObject({
|
|
31
|
+
providerId: z.string().min(1),
|
|
32
|
+
modelId: z.string().min(1),
|
|
33
|
+
reasoning: z.string().optional(),
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
/** Every stored key and every Agent with its persisted model choice. */
|
|
37
|
+
export const modelKeysViewSchema = z.strictObject({
|
|
38
|
+
keys: z.array(modelKeySchema),
|
|
39
|
+
agents: z.array(z.strictObject({
|
|
40
|
+
agentId: z.string().min(1),
|
|
41
|
+
name: z.string(),
|
|
42
|
+
choice: agentChoiceSchema.nullable(),
|
|
43
|
+
})),
|
|
44
|
+
});
|
|
45
|
+
const queryKey = ["tourtois", "model-keys"];
|
|
46
|
+
const defaultSource = "default";
|
|
47
|
+
/**
|
|
48
|
+
* Model keys on a standalone host: store a provider API key once, then pick
|
|
49
|
+
* which model and key each Agent runs on. A key is never shown again.
|
|
50
|
+
*/
|
|
51
|
+
export function ModelKeys({ port }) {
|
|
52
|
+
const client = useQueryClient();
|
|
53
|
+
const view = useQuery({ queryKey, queryFn: () => port.read() });
|
|
54
|
+
const refresh = () => client.invalidateQueries({ queryKey });
|
|
55
|
+
const remove = useMutation({
|
|
56
|
+
mutationFn: (keyId) => port.removeKey(keyId),
|
|
57
|
+
onSuccess: refresh,
|
|
58
|
+
});
|
|
59
|
+
const keys = view.data?.keys ?? [];
|
|
60
|
+
const agents = view.data?.agents ?? [];
|
|
61
|
+
// A fresh form after each stored key, so the key field empties.
|
|
62
|
+
const [formKey, setFormKey] = useState(0);
|
|
63
|
+
return (_jsxs("section", { className: "tourtois-settings-content 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
|
+
remove.mutate(key.keyId);
|
|
65
|
+
} }) }) }, key.keyId)))] }), remove.isError ? (_jsx("p", { role: "alert", children: "The model key could not be removed." })) : null, _jsx(AddModelKey, { onAdd: async (draft) => {
|
|
66
|
+
await port.addKey(draft);
|
|
67
|
+
await refresh();
|
|
68
|
+
setFormKey((current) => current + 1);
|
|
69
|
+
} }, formKey), _jsx(SectionHeading, { children: "Agent models" }), _jsxs(DataList, { density: "compact", "aria-label": "Agent models", children: [_jsx(DataListHeading, { children: "Current choice" }), agents.length === 0 ? (_jsx(DataRow, { className: "tourtois-settings-empty", children: "Create an Agent first." })) : null, agents.map((agent) => {
|
|
70
|
+
const keyLabel = agent.choice?.keyId === undefined
|
|
71
|
+
? null
|
|
72
|
+
: (keys.find((key) => key.keyId === agent.choice?.keyId)
|
|
73
|
+
?.label ?? "Removed key");
|
|
74
|
+
return (_jsxs(FactRow, { icon: _jsx(Sigil, { name: "agent" }), label: agent.name, children: [agent.choice?.model.modelId ?? "Unavailable", keyLabel === null ? "" : ` · ${keyLabel}`] }, agent.agentId));
|
|
75
|
+
})] }), agents.length > 0 ? (_jsx(ChooseAgentModel, { agents: agents, keys: keys, onChoose: async (agentId, draft) => {
|
|
76
|
+
await port.chooseModel(agentId, draft);
|
|
77
|
+
await refresh();
|
|
78
|
+
} })) : null] })) : null] }));
|
|
79
|
+
}
|
|
80
|
+
function AddModelKey({ onAdd, }) {
|
|
81
|
+
const schema = useMemo(() => z.object({
|
|
82
|
+
provider: providerSchema.meta(field({
|
|
83
|
+
label: "Provider",
|
|
84
|
+
icon: _jsx(Sigil, { name: "internet" }),
|
|
85
|
+
kind: "select",
|
|
86
|
+
options: providers,
|
|
87
|
+
})),
|
|
88
|
+
label: z
|
|
89
|
+
.string()
|
|
90
|
+
.min(1, "Name this key")
|
|
91
|
+
.max(64)
|
|
92
|
+
.meta(field({
|
|
93
|
+
label: "Name",
|
|
94
|
+
icon: _jsx(Sigil, { name: "write" }),
|
|
95
|
+
maxLength: 64,
|
|
96
|
+
placeholder: "Work key",
|
|
97
|
+
})),
|
|
98
|
+
apiKey: z
|
|
99
|
+
.string()
|
|
100
|
+
.min(1, "Paste the key")
|
|
101
|
+
.max(16_384)
|
|
102
|
+
.meta(field({
|
|
103
|
+
label: "API key",
|
|
104
|
+
icon: _jsx(Sigil, { name: "restricted" }),
|
|
105
|
+
help: "Sealed on this instance and never shown again.",
|
|
106
|
+
kind: "secret",
|
|
107
|
+
})),
|
|
108
|
+
}), []);
|
|
109
|
+
const add = useMutation({ mutationFn: onAdd });
|
|
110
|
+
const model = useSchemaForm({
|
|
111
|
+
schema,
|
|
112
|
+
defaultValues: { provider: "anthropic", label: "", apiKey: "" },
|
|
113
|
+
onSubmit: async (value) => {
|
|
114
|
+
try {
|
|
115
|
+
await add.mutateAsync(value);
|
|
116
|
+
return { kind: "saved" };
|
|
117
|
+
}
|
|
118
|
+
catch (cause) {
|
|
119
|
+
return {
|
|
120
|
+
kind: "refused",
|
|
121
|
+
error: cause instanceof Error
|
|
122
|
+
? cause.message
|
|
123
|
+
: "The model key could not be stored.",
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
return (_jsx(SchemaForm, { model: model, layout: "columns", "aria-label": "Add model key", disabled: add.isPending, footer: _jsx(FormFooter, { divider: false, error: model.error, children: _jsx(Button, { type: "submit", children: add.isPending ? "Checking…" : "Add model key" }) }) }));
|
|
129
|
+
}
|
|
130
|
+
function ChooseAgentModel({ agents, keys, onChoose, }) {
|
|
131
|
+
const schema = useMemo(() => z.object({
|
|
132
|
+
agentId: z.string().meta(field({
|
|
133
|
+
label: "Agent",
|
|
134
|
+
icon: _jsx(Sigil, { name: "agent" }),
|
|
135
|
+
kind: "select",
|
|
136
|
+
options: Object.fromEntries(agents.map((agent) => [agent.agentId, agent.name])),
|
|
137
|
+
})),
|
|
138
|
+
source: z.string().meta(field({
|
|
139
|
+
label: "Runs on",
|
|
140
|
+
icon: _jsx(Sigil, { name: "restricted" }),
|
|
141
|
+
kind: "select",
|
|
142
|
+
options: {
|
|
143
|
+
[defaultSource]: "Instance default model",
|
|
144
|
+
...Object.fromEntries(keys.map((key) => [
|
|
145
|
+
key.keyId,
|
|
146
|
+
`${key.label} (${providers[key.provider]})`,
|
|
147
|
+
])),
|
|
148
|
+
},
|
|
149
|
+
})),
|
|
150
|
+
modelId: z
|
|
151
|
+
.string()
|
|
152
|
+
.max(256)
|
|
153
|
+
.meta(field({
|
|
154
|
+
label: "Model",
|
|
155
|
+
icon: _jsx(Sigil, { name: "write" }),
|
|
156
|
+
help: "For a key: the provider's model id, such as gpt-6-luna.",
|
|
157
|
+
maxLength: 256,
|
|
158
|
+
})),
|
|
159
|
+
}), [agents, keys]);
|
|
160
|
+
const choose = useMutation({
|
|
161
|
+
mutationFn: (input) => onChoose(input.agentId, input.draft),
|
|
162
|
+
});
|
|
163
|
+
const model = useSchemaForm({
|
|
164
|
+
schema,
|
|
165
|
+
defaultValues: {
|
|
166
|
+
agentId: agents[0]?.agentId ?? "",
|
|
167
|
+
source: defaultSource,
|
|
168
|
+
modelId: "",
|
|
169
|
+
},
|
|
170
|
+
onSubmit: async (value) => {
|
|
171
|
+
const key = keys.find((item) => item.keyId === value.source);
|
|
172
|
+
if (value.source !== defaultSource && key === undefined)
|
|
173
|
+
return { kind: "refused", error: "Choose a stored key." };
|
|
174
|
+
if (key !== undefined && value.modelId.length === 0)
|
|
175
|
+
return { kind: "refused", error: "Name the model this key runs." };
|
|
176
|
+
try {
|
|
177
|
+
await choose.mutateAsync({
|
|
178
|
+
agentId: value.agentId,
|
|
179
|
+
draft: key === undefined
|
|
180
|
+
? { keyId: null }
|
|
181
|
+
: {
|
|
182
|
+
keyId: key.keyId,
|
|
183
|
+
provider: key.provider,
|
|
184
|
+
modelId: value.modelId,
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
return { kind: "saved" };
|
|
188
|
+
}
|
|
189
|
+
catch (cause) {
|
|
190
|
+
return {
|
|
191
|
+
kind: "refused",
|
|
192
|
+
error: cause instanceof Error
|
|
193
|
+
? cause.message
|
|
194
|
+
: "The model could not be saved.",
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
return (_jsx(SchemaForm, { model: model, layout: "columns", "aria-label": "Choose Agent model", disabled: choose.isPending, footer: _jsx(FormFooter, { divider: false, error: model.error, children: _jsx(Button, { type: "submit", children: choose.isPending ? "Saving…" : "Save model" }) }) }));
|
|
200
|
+
}
|
package/dist/SystemSettings.js
CHANGED
|
@@ -6,6 +6,7 @@ import { addressKey, } from "@fungi.computer/nacre/app-directory";
|
|
|
6
6
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
7
7
|
import { AgentMcpServers } from "./AgentMcpServers.js";
|
|
8
8
|
import { Keys } from "./Keys.js";
|
|
9
|
+
import { ModelKeys } from "./ModelKeys.js";
|
|
9
10
|
import { AppIcon } from "./app-icon.js";
|
|
10
11
|
import { AvatarSettings } from "./member-avatar.js";
|
|
11
12
|
import { SettingsNavigation } from "./SettingsNavigation.js";
|
|
@@ -134,7 +135,7 @@ export function SystemSettings({ location: requestedLocation, sections: ceiling,
|
|
|
134
135
|
computerCount: ports.summary?.computerCount ?? null,
|
|
135
136
|
}, onNavigate: onNavigate })) : null, avatar && ports.avatar !== undefined ? (_jsx("div", { className: "tourtois-settings-content", children: _jsx(AvatarSettings, { save: ports.avatar.save }) })) : null, connectors && agentMcpServers !== undefined ? (_jsx(AgentMcpServers, { port: agentMcpServers })) : null, connectors &&
|
|
136
137
|
agentMcpServers === undefined &&
|
|
137
|
-
ports.connectors !== undefined ? (_jsx(ports.connectors, { target: location.target, onNavigate: onNavigate })) : 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 && keys !== undefined ? (_jsx(Keys, { port: keys, apps: keyableApps })) : null, location?.category === "channels" &&
|
|
138
|
+
ports.connectors !== undefined ? (_jsx(ports.connectors, { target: location.target, onNavigate: onNavigate })) : 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 && keys !== undefined ? (_jsx(Keys, { port: keys, apps: keyableApps })) : null, keysSection && ports.modelKeys !== undefined ? (_jsx(ModelKeys, { port: ports.modelKeys })) : null, location?.category === "channels" &&
|
|
138
139
|
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: () => {
|
|
139
140
|
onNavigate({
|
|
140
141
|
category: "apps",
|
|
@@ -14,6 +14,7 @@ import { z } from "zod";
|
|
|
14
14
|
import { useEffect, useRef, useState } from "react";
|
|
15
15
|
import { createRoot } from "react-dom/client";
|
|
16
16
|
import { agentMcpServersViewSchema, createPlatformControls, PlatformControlsView, } from "./platform-controls.js";
|
|
17
|
+
import { modelKeysViewSchema } from "./ModelKeys.js";
|
|
17
18
|
import { settingsLocationSchema } from "./settings-routes.js";
|
|
18
19
|
import { OysterComputers, createOysterComputersPort, } from "./OysterComputers.js";
|
|
19
20
|
import { useSettingsLeaveGuard, } from "./settings-leave-guard.js";
|
|
@@ -64,6 +65,68 @@ const agentMcpServers = {
|
|
|
64
65
|
await ownerRequest(`/api/agent-mcp-servers/${encodeURIComponent(agentId)}/${encodeURIComponent(serverId)}`, { method: "DELETE" }, "The MCP server change was refused");
|
|
65
66
|
},
|
|
66
67
|
};
|
|
68
|
+
const modelKeyMessages = {
|
|
69
|
+
key_rejected: "The provider rejected this key",
|
|
70
|
+
provider_unavailable: "The provider could not be reached. Try again",
|
|
71
|
+
custody_unavailable: "This instance has no credential key. Set OYSTER_CREDENTIAL_KEY and redeploy",
|
|
72
|
+
limit: "Remove a model key before adding another",
|
|
73
|
+
invalid_key: "Choose a provider, name the key and paste it",
|
|
74
|
+
key_removed: "That key was removed",
|
|
75
|
+
key_source_mismatch: "That model does not belong to the key's provider",
|
|
76
|
+
model_unavailable: "That provider has no such model",
|
|
77
|
+
invalid_model_choice: "That model choice is not valid",
|
|
78
|
+
};
|
|
79
|
+
const modelKeyMessage = (code) => new Map(Object.entries(modelKeyMessages)).get(code) ?? code;
|
|
80
|
+
/** A model-key request whose host refusal code reads as a sentence. */
|
|
81
|
+
async function modelKeyRequest(path, init, refused) {
|
|
82
|
+
try {
|
|
83
|
+
return await ownerRequest(path, init, refused);
|
|
84
|
+
}
|
|
85
|
+
catch (cause) {
|
|
86
|
+
if (cause instanceof AppError)
|
|
87
|
+
throw new Error(modelKeyMessage(cause.message), { cause });
|
|
88
|
+
throw cause;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const jsonInit = (method, body) => ({
|
|
92
|
+
method,
|
|
93
|
+
headers: { "Content-Type": "application/json" },
|
|
94
|
+
body,
|
|
95
|
+
});
|
|
96
|
+
/** Owner-direct model-key custody: a key goes in once and never comes back. */
|
|
97
|
+
const modelKeys = {
|
|
98
|
+
read: async () => {
|
|
99
|
+
const [keys, agents] = await Promise.all([
|
|
100
|
+
json("/api/model-keys"),
|
|
101
|
+
json("/api/agent-models"),
|
|
102
|
+
]);
|
|
103
|
+
return modelKeysViewSchema.parse({
|
|
104
|
+
keys: z.object({ keys: z.unknown() }).parse(keys).keys,
|
|
105
|
+
agents: z.object({ agents: z.unknown() }).parse(agents).agents,
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
addKey: async (draft) => {
|
|
109
|
+
await modelKeyRequest("/api/model-keys", jsonInit("POST", JSON.stringify(draft)), "The model key was refused");
|
|
110
|
+
},
|
|
111
|
+
removeKey: async (keyId) => {
|
|
112
|
+
await modelKeyRequest(`/api/model-keys/${encodeURIComponent(keyId)}`, { method: "DELETE" }, "The model key could not be removed");
|
|
113
|
+
},
|
|
114
|
+
chooseModel: async (agentId, draft) => {
|
|
115
|
+
await modelKeyRequest(`/api/agent-models/${encodeURIComponent(agentId)}`, jsonInit("PUT", JSON.stringify(draft.keyId === null
|
|
116
|
+
? {
|
|
117
|
+
keySource: "workers-ai",
|
|
118
|
+
model: {
|
|
119
|
+
providerId: "cloudflare-workers-ai",
|
|
120
|
+
modelId: "@cf/moonshotai/kimi-k2.6",
|
|
121
|
+
},
|
|
122
|
+
}
|
|
123
|
+
: {
|
|
124
|
+
keySource: "byok",
|
|
125
|
+
keyId: draft.keyId,
|
|
126
|
+
model: { providerId: draft.provider, modelId: draft.modelId },
|
|
127
|
+
})), "The model could not be saved");
|
|
128
|
+
},
|
|
129
|
+
};
|
|
67
130
|
/** Owner-direct Keys custody; a plaintext secret comes back only once, on issue. */
|
|
68
131
|
function createOysterKeysPort(oysterKeysWire) {
|
|
69
132
|
const oysterKeysView = z.strictObject({
|
|
@@ -207,6 +270,7 @@ export const mountPlatformControls = (root, input) => {
|
|
|
207
270
|
agentMcpServers,
|
|
208
271
|
computers,
|
|
209
272
|
keys,
|
|
273
|
+
modelKeys,
|
|
210
274
|
requestAppAccess,
|
|
211
275
|
appPermissions: OysterAppPermissions,
|
|
212
276
|
} }) }));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ComponentType } from "react";
|
|
2
2
|
import type { AgentMcpServersPort } from "./AgentMcpServers.js";
|
|
3
3
|
import type { KeysPort } from "./Keys.js";
|
|
4
|
+
import type { ModelKeysPort } from "./ModelKeys.js";
|
|
4
5
|
import type { MemberAvatarReader, MemberAvatarSave } from "./member-avatar.js";
|
|
5
6
|
import { type SettingsLocation } from "./settings-routes.js";
|
|
6
7
|
export type SettingsCategory = SettingsLocation["category"];
|
|
@@ -40,6 +41,8 @@ export type SettingsSectionPorts = Readonly<{
|
|
|
40
41
|
computers?: ComponentType;
|
|
41
42
|
/** Keys settings: the host's owner-direct Keys custody. */
|
|
42
43
|
keys?: KeysPort;
|
|
44
|
+
/** Model keys beside Keys: the host's sealed provider keys and per-Agent models. */
|
|
45
|
+
modelKeys?: ModelKeysPort;
|
|
43
46
|
/** The Team's role defaults. */
|
|
44
47
|
defaults?: ComponentType<{
|
|
45
48
|
onAccepted: Accepted;
|
|
@@ -8,7 +8,7 @@ export function offeredSettings(ceiling, ports) {
|
|
|
8
8
|
avatar: ports.avatar !== undefined,
|
|
9
9
|
connectors: ports.agentMcpServers !== undefined || ports.connectors !== undefined,
|
|
10
10
|
computers: ports.computers !== undefined,
|
|
11
|
-
keys: ports.keys !== undefined,
|
|
11
|
+
keys: ports.keys !== undefined || ports.modelKeys !== undefined,
|
|
12
12
|
defaults: ports.defaults !== undefined,
|
|
13
13
|
channels: ports.channels !== undefined,
|
|
14
14
|
selling: ports.selling !== undefined,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/tourtois",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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",
|
|
@@ -73,15 +73,15 @@
|
|
|
73
73
|
"LICENSE"
|
|
74
74
|
],
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@fungi.computer/agar": "0.7.
|
|
76
|
+
"@fungi.computer/agar": "0.7.1",
|
|
77
77
|
"@fungi.computer/cairn": "0.1.0",
|
|
78
|
-
"@fungi.computer/caps": "0.7.
|
|
78
|
+
"@fungi.computer/caps": "0.7.1",
|
|
79
79
|
"@fungi.computer/ear-tag": "0.1.0",
|
|
80
|
-
"@fungi.computer/gills": "0.2.
|
|
80
|
+
"@fungi.computer/gills": "0.2.1",
|
|
81
81
|
"@fungi.computer/maosaico": "0.1.0",
|
|
82
|
-
"@fungi.computer/parakeet": "0.7.
|
|
83
|
-
"@fungi.computer/puffball": "0.5.
|
|
84
|
-
"@fungi.computer/shiitake": "0.9.
|
|
82
|
+
"@fungi.computer/parakeet": "0.7.2",
|
|
83
|
+
"@fungi.computer/puffball": "0.5.1",
|
|
84
|
+
"@fungi.computer/shiitake": "0.9.2",
|
|
85
85
|
"@fungi.computer/sigils": "0.3.0",
|
|
86
86
|
"@fungi.computer/sprite": "0.2.0",
|
|
87
87
|
"@fungi.computer/sprite-zdog": "0.3.0",
|
|
@@ -96,16 +96,16 @@
|
|
|
96
96
|
"lucide-react": "0.460.0",
|
|
97
97
|
"react-dom": "18.3.1",
|
|
98
98
|
"zod": "4.4.3",
|
|
99
|
-
"@fungi.computer/nacre": "0.1.
|
|
99
|
+
"@fungi.computer/nacre": "0.1.4"
|
|
100
100
|
},
|
|
101
101
|
"peerDependencies": {
|
|
102
102
|
"react": "^18.3.1 || ^19.2.0"
|
|
103
103
|
},
|
|
104
104
|
"devDependencies": {
|
|
105
|
-
"@fungi.computer/oyster": "0.
|
|
105
|
+
"@fungi.computer/oyster": "0.10.0",
|
|
106
106
|
"@cloudflare/workers-types": "5.20260828.1",
|
|
107
|
-
"@fungi.computer/forage": "0.3.
|
|
108
|
-
"@fungi.computer/mycelium": "0.3.
|
|
107
|
+
"@fungi.computer/forage": "0.3.1",
|
|
108
|
+
"@fungi.computer/mycelium": "0.3.4",
|
|
109
109
|
"@ladle/react": "5.1.1",
|
|
110
110
|
"@types/react": "18.3.3",
|
|
111
111
|
"@vitejs/plugin-react": "6.1.1",
|