@fungi.computer/tourtois 0.15.3 → 0.16.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/ModelKeys.d.ts +8 -20
- package/dist/ModelKeys.js +23 -24
- package/package.json +2 -2
package/dist/ModelKeys.d.ts
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
|
-
|
|
3
|
-
readonly "cloudflare-workers-ai": "Cloudflare Workers AI";
|
|
4
|
-
readonly anthropic: "Anthropic";
|
|
5
|
-
readonly openai: "OpenAI";
|
|
6
|
-
readonly openrouter: "OpenRouter";
|
|
7
|
-
};
|
|
8
|
-
export type Provider = keyof typeof providers;
|
|
2
|
+
export type Provider = string;
|
|
9
3
|
/** Every stored key and every Agent with its persisted model choice. */
|
|
10
4
|
export declare const modelKeysViewSchema: z.ZodObject<{
|
|
11
5
|
keys: z.ZodArray<z.ZodObject<{
|
|
12
6
|
keyId: z.ZodString;
|
|
13
|
-
provider: z.
|
|
14
|
-
"cloudflare-workers-ai": "cloudflare-workers-ai";
|
|
15
|
-
anthropic: "anthropic";
|
|
16
|
-
openai: "openai";
|
|
17
|
-
openrouter: "openrouter";
|
|
18
|
-
}>;
|
|
7
|
+
provider: z.ZodString;
|
|
19
8
|
label: z.ZodString;
|
|
20
9
|
createdAt: z.ZodNumber;
|
|
21
10
|
validatedAt: z.ZodNumber;
|
|
@@ -25,12 +14,12 @@ export declare const modelKeysViewSchema: z.ZodObject<{
|
|
|
25
14
|
unknown: "unknown";
|
|
26
15
|
missing: "missing";
|
|
27
16
|
}>;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
17
|
+
providers: z.ZodArray<z.ZodObject<{
|
|
18
|
+
id: z.ZodString;
|
|
19
|
+
label: z.ZodString;
|
|
20
|
+
accountId: z.ZodBoolean;
|
|
21
|
+
}, z.core.$strict>>;
|
|
22
|
+
catalogs: z.ZodRecord<z.ZodString & z.core.$partial, z.ZodArray<z.ZodObject<{
|
|
34
23
|
id: z.ZodString;
|
|
35
24
|
name: z.ZodString;
|
|
36
25
|
input: z.ZodNumber;
|
|
@@ -86,4 +75,3 @@ export declare function ModelKeys({ port, focus, }: {
|
|
|
86
75
|
port: ModelKeysPort;
|
|
87
76
|
focus?: boolean;
|
|
88
77
|
}): import("react/jsx-runtime").JSX.Element;
|
|
89
|
-
export {};
|
package/dist/ModelKeys.js
CHANGED
|
@@ -11,18 +11,13 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
|
11
11
|
import { useCallback, useMemo, useState } from "react";
|
|
12
12
|
import * as z from "zod";
|
|
13
13
|
import { SettingsItem } from "./settings-item.js";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
const providerSchema = z.
|
|
21
|
-
"cloudflare-workers-ai",
|
|
22
|
-
"anthropic",
|
|
23
|
-
"openai",
|
|
24
|
-
"openrouter",
|
|
25
|
-
]);
|
|
14
|
+
/** A provider the host offers; the host owns the list and the client only shows it. */
|
|
15
|
+
const providerChoiceSchema = z.strictObject({
|
|
16
|
+
id: z.string().min(1),
|
|
17
|
+
label: z.string().min(1),
|
|
18
|
+
accountId: z.boolean(),
|
|
19
|
+
});
|
|
20
|
+
const providerSchema = z.string().min(1);
|
|
26
21
|
/** One stored key as the host lists it; the secret never comes back. */
|
|
27
22
|
const modelKeySchema = z.strictObject({
|
|
28
23
|
keyId: z.string().min(1),
|
|
@@ -44,6 +39,7 @@ const agentChoiceSchema = z.strictObject({
|
|
|
44
39
|
export const modelKeysViewSchema = z.strictObject({
|
|
45
40
|
keys: z.array(modelKeySchema),
|
|
46
41
|
models: z.enum(["ready", "missing", "unknown"]),
|
|
42
|
+
providers: z.array(providerChoiceSchema).min(1),
|
|
47
43
|
catalogs: z.partialRecord(providerSchema, z.array(z.strictObject({
|
|
48
44
|
id: z.string().min(1),
|
|
49
45
|
name: z.string().min(1),
|
|
@@ -57,6 +53,8 @@ export const modelKeysViewSchema = z.strictObject({
|
|
|
57
53
|
choice: agentChoiceSchema.nullable(),
|
|
58
54
|
})),
|
|
59
55
|
});
|
|
56
|
+
/** Provider label from the host's list; an unlisted provider shows its id. */
|
|
57
|
+
const providerLabel = (providers, id) => providers.find((choice) => choice.id === id)?.label ?? id;
|
|
60
58
|
const queryKey = ["tourtois", "model-keys"];
|
|
61
59
|
const defaultSource = "default";
|
|
62
60
|
/**
|
|
@@ -83,9 +81,9 @@ export function ModelKeys({ port, focus = false, }) {
|
|
|
83
81
|
const agents = view.data?.agents ?? [];
|
|
84
82
|
// A fresh form after each stored key, so the key field empties.
|
|
85
83
|
const [formKey, setFormKey] = useState(0);
|
|
86
|
-
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
|
|
84
|
+
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: providerLabel(view.data.providers, key.provider) }), actions: _jsx(KeycapButton, { density: "compact", tone: "destructive", label: "Remove", "aria-label": `Remove ${key.label}`, disabled: remove.isPending, onClick: () => {
|
|
87
85
|
remove.mutate(key.keyId);
|
|
88
|
-
} }) }) }, key.keyId)))] }), remove.isError ? (_jsx("p", { role: "alert", children: "The model key could not be removed." })) : null, _jsx(AddModelKey, { onAdd: async (draft) => {
|
|
86
|
+
} }) }) }, key.keyId)))] }), remove.isError ? (_jsx("p", { role: "alert", children: "The model key could not be removed." })) : null, _jsx(AddModelKey, { providers: view.data.providers, onAdd: async (draft) => {
|
|
89
87
|
await port.addKey(draft);
|
|
90
88
|
await refresh();
|
|
91
89
|
setFormKey((current) => current + 1);
|
|
@@ -106,18 +104,19 @@ export function ModelKeys({ port, focus = false, }) {
|
|
|
106
104
|
: "Model unavailable for tools")), disconnected || selectedKey === undefined
|
|
107
105
|
? ""
|
|
108
106
|
: ` · ${selectedKey.label}`] }, agent.agentId));
|
|
109
|
-
})] }), agents.length > 0 ? (_jsx(ChooseAgentModel, { agents: agents, keys: keys, catalogs: view.data.catalogs, models: view.data.models, onChoose: async (agentId, draft) => {
|
|
107
|
+
})] }), agents.length > 0 ? (_jsx(ChooseAgentModel, { agents: agents, keys: keys, providers: view.data.providers, catalogs: view.data.catalogs, models: view.data.models, onChoose: async (agentId, draft) => {
|
|
110
108
|
await port.chooseModel(agentId, draft);
|
|
111
109
|
await refresh();
|
|
112
110
|
} }, keys.map((key) => key.keyId).join(":"))) : null] })) : null] }));
|
|
113
111
|
}
|
|
114
|
-
function AddModelKey({ onAdd, }) {
|
|
112
|
+
function AddModelKey({ providers, onAdd, }) {
|
|
113
|
+
const needsAccountId = (provider) => providers.find((choice) => choice.id === provider)?.accountId === true;
|
|
115
114
|
const schema = useMemo(() => z.object({
|
|
116
115
|
provider: providerSchema.meta(field({
|
|
117
116
|
label: "Provider",
|
|
118
117
|
icon: _jsx(Sigil, { name: "internet" }),
|
|
119
118
|
kind: "select",
|
|
120
|
-
options: providers,
|
|
119
|
+
options: Object.fromEntries(providers.map((choice) => [choice.id, choice.label])),
|
|
121
120
|
})),
|
|
122
121
|
label: z
|
|
123
122
|
.string()
|
|
@@ -148,19 +147,19 @@ function AddModelKey({ onAdd, }) {
|
|
|
148
147
|
help: "Sealed on this instance and never shown again.",
|
|
149
148
|
kind: "secret",
|
|
150
149
|
})),
|
|
151
|
-
}), []);
|
|
150
|
+
}), [providers]);
|
|
152
151
|
const add = useMutation({ mutationFn: onAdd });
|
|
153
152
|
const model = useSchemaForm({
|
|
154
153
|
schema,
|
|
155
154
|
defaultValues: {
|
|
156
|
-
provider: "
|
|
155
|
+
provider: providers[0]?.id ?? "",
|
|
157
156
|
label: "",
|
|
158
157
|
apiKey: "",
|
|
159
158
|
accountId: "",
|
|
160
159
|
},
|
|
161
160
|
onSubmit: async (value) => {
|
|
162
161
|
try {
|
|
163
|
-
if (value.provider
|
|
162
|
+
if (needsAccountId(value.provider) &&
|
|
164
163
|
!/^[a-f0-9]{32}$/u.test(value.accountId))
|
|
165
164
|
return {
|
|
166
165
|
kind: "refused",
|
|
@@ -173,7 +172,7 @@ function AddModelKey({ onAdd, }) {
|
|
|
173
172
|
label: value.label,
|
|
174
173
|
apiKey: value.apiKey,
|
|
175
174
|
};
|
|
176
|
-
await add.mutateAsync(value.provider
|
|
175
|
+
await add.mutateAsync(needsAccountId(value.provider)
|
|
177
176
|
? { ...draft, accountId: value.accountId }
|
|
178
177
|
: draft);
|
|
179
178
|
return { kind: "saved" };
|
|
@@ -188,11 +187,11 @@ function AddModelKey({ onAdd, }) {
|
|
|
188
187
|
}
|
|
189
188
|
},
|
|
190
189
|
});
|
|
191
|
-
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" }) }), children: _jsx(model.form.Subscribe, { selector: (state) => state.values.provider, children: (provider) => (_jsx(FormFields, { model: model, names: provider
|
|
190
|
+
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" }) }), children: _jsx(model.form.Subscribe, { selector: (state) => state.values.provider, children: (provider) => (_jsx(FormFields, { model: model, names: needsAccountId(provider)
|
|
192
191
|
? ["provider", "label", "accountId", "apiKey"]
|
|
193
192
|
: ["provider", "label", "apiKey"], layout: "columns" })) }) }));
|
|
194
193
|
}
|
|
195
|
-
function ChooseAgentModel({ agents, keys, catalogs, models, onChoose, }) {
|
|
194
|
+
function ChooseAgentModel({ agents, keys, providers, catalogs, models, onChoose, }) {
|
|
196
195
|
const schema = useMemo(() => z.object({
|
|
197
196
|
agentId: z.string().meta(field({
|
|
198
197
|
label: "Agent",
|
|
@@ -252,7 +251,7 @@ function ChooseAgentModel({ agents, keys, catalogs, models, onChoose, }) {
|
|
|
252
251
|
model.form.setFieldValue("modelId", "");
|
|
253
252
|
}, children: [_jsx("option", { value: defaultSource, children: models === "missing"
|
|
254
253
|
? "Instance default — not connected"
|
|
255
|
-
: "Instance default model" }), keys.map((key) => (_jsxs("option", { value: key.keyId, children: [key.label, " (", providers
|
|
254
|
+
: "Instance default model" }), keys.map((key) => (_jsxs("option", { value: key.keyId, children: [key.label, " (", providerLabel(providers, key.provider), ")"] }, key.keyId)))] })) }), _jsx(model.form.Subscribe, { selector: (state) => state.values.source, children: (source) => {
|
|
256
255
|
const key = keys.find((item) => item.keyId === source);
|
|
257
256
|
if (key === undefined)
|
|
258
257
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/tourtois",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"react": "^18.3.1 || ^19.2.0"
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
|
-
"@fungi.computer/oyster": "0.
|
|
109
|
+
"@fungi.computer/oyster": "0.22.0",
|
|
110
110
|
"@cloudflare/workers-types": "5.20260828.1",
|
|
111
111
|
"@fungi.computer/forage": "0.3.5",
|
|
112
112
|
"@fungi.computer/mycelium": "0.3.8",
|