@fungi.computer/tourtois 0.27.2 → 0.28.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/SettingsHome.js +2 -0
- package/dist/SettingsNavigation.js +7 -0
- package/dist/SystemSettings.js +5 -11
- package/dist/Vault.d.ts +341 -0
- package/dist/Vault.js +930 -0
- package/dist/oyster-platform-controls.d.ts +2 -0
- package/dist/oyster-platform-controls.js +210 -49
- package/dist/oyster-setup.js +6 -4
- package/dist/platform-controls.d.ts +1 -0
- package/dist/platform-controls.js +1 -0
- package/dist/settings-item.d.ts +1 -1
- package/dist/settings-item.js +1 -1
- package/dist/settings-routes.d.ts +13 -6
- package/dist/settings-routes.js +29 -14
- package/dist/settings-sections.d.ts +5 -3
- package/dist/settings-sections.js +2 -1
- package/dist/shell.css +155 -0
- package/package.json +9 -4
- package/dist/ModelKeys.d.ts +0 -77
- package/dist/ModelKeys.js +0 -275
package/dist/shell.css
CHANGED
|
@@ -300,6 +300,10 @@
|
|
|
300
300
|
color: var(--stipe-fg-muted);
|
|
301
301
|
overflow-wrap: anywhere;
|
|
302
302
|
}
|
|
303
|
+
/* With no icon, the detail sits under the title at the same edge. */
|
|
304
|
+
.tourtois-settings-item[data-plain] .tourtois-settings-item-detail {
|
|
305
|
+
padding-inline-start: 0;
|
|
306
|
+
}
|
|
303
307
|
.tourtois-settings-item-detail > p {
|
|
304
308
|
margin: 0;
|
|
305
309
|
}
|
|
@@ -315,6 +319,157 @@
|
|
|
315
319
|
word-break: break-all;
|
|
316
320
|
}
|
|
317
321
|
|
|
322
|
+
/* Vault: each section is a small heading over its list; rows open one
|
|
323
|
+
inline panel (rotate, scope, usage or revoke) under their line. */
|
|
324
|
+
/* Every section starts at one left edge: its heading, then its explanation
|
|
325
|
+
at the secondary size, then its list and add form. */
|
|
326
|
+
.tourtois-vault > .tourtois-settings-stack {
|
|
327
|
+
padding-top: var(--spacing-lg);
|
|
328
|
+
border-top: 1px solid var(--stipe-hairline);
|
|
329
|
+
}
|
|
330
|
+
.tourtois-vault-section-head {
|
|
331
|
+
display: grid;
|
|
332
|
+
gap: var(--spacing-2xs);
|
|
333
|
+
}
|
|
334
|
+
.tourtois-vault-section-title {
|
|
335
|
+
margin: 0;
|
|
336
|
+
font-size: var(--text-base);
|
|
337
|
+
font-weight: 650;
|
|
338
|
+
}
|
|
339
|
+
.tourtois-vault-add {
|
|
340
|
+
display: flex;
|
|
341
|
+
}
|
|
342
|
+
.tourtois-vault-add-form {
|
|
343
|
+
padding-top: var(--spacing-md);
|
|
344
|
+
border-top: 1px solid var(--stipe-hairline);
|
|
345
|
+
}
|
|
346
|
+
/* A short multi-select: checkboxes that wrap like words, selection by fill. */
|
|
347
|
+
.tourtois-vault-choices {
|
|
348
|
+
display: flex;
|
|
349
|
+
flex-wrap: wrap;
|
|
350
|
+
gap: var(--spacing-xs) var(--spacing-md);
|
|
351
|
+
}
|
|
352
|
+
.tourtois-vault-choice {
|
|
353
|
+
display: inline-flex;
|
|
354
|
+
align-items: center;
|
|
355
|
+
gap: var(--spacing-xs);
|
|
356
|
+
font-size: var(--text-sm);
|
|
357
|
+
}
|
|
358
|
+
.tourtois-vault-note {
|
|
359
|
+
max-width: 60ch;
|
|
360
|
+
margin: 0;
|
|
361
|
+
color: var(--stipe-fg-muted);
|
|
362
|
+
font-size: var(--text-sm);
|
|
363
|
+
}
|
|
364
|
+
.tourtois-vault-item {
|
|
365
|
+
display: grid;
|
|
366
|
+
gap: var(--spacing-sm);
|
|
367
|
+
min-width: 0;
|
|
368
|
+
}
|
|
369
|
+
.list-row > .tourtois-vault-item {
|
|
370
|
+
grid-column: 1 / -1;
|
|
371
|
+
}
|
|
372
|
+
.tourtois-vault-mono {
|
|
373
|
+
font-family: var(--font-mono);
|
|
374
|
+
font-size: var(--text-xs);
|
|
375
|
+
overflow-wrap: anywhere;
|
|
376
|
+
}
|
|
377
|
+
.tourtois-vault-coverage {
|
|
378
|
+
display: flex;
|
|
379
|
+
align-items: center;
|
|
380
|
+
gap: var(--spacing-xs);
|
|
381
|
+
font-size: var(--text-sm);
|
|
382
|
+
}
|
|
383
|
+
.tourtois-vault-coverage > p {
|
|
384
|
+
margin: 0;
|
|
385
|
+
}
|
|
386
|
+
.tourtois-vault-panel {
|
|
387
|
+
display: grid;
|
|
388
|
+
gap: var(--spacing-sm);
|
|
389
|
+
min-width: 0;
|
|
390
|
+
padding: var(--spacing-sm) var(--spacing-md);
|
|
391
|
+
border-radius: var(--radius-field);
|
|
392
|
+
border: 1px solid var(--stipe-hairline);
|
|
393
|
+
background: var(--color-base-200);
|
|
394
|
+
}
|
|
395
|
+
.tourtois-vault-panel-copy {
|
|
396
|
+
max-width: 60ch;
|
|
397
|
+
margin: 0;
|
|
398
|
+
font-size: var(--text-xs);
|
|
399
|
+
color: var(--stipe-fg-muted);
|
|
400
|
+
}
|
|
401
|
+
.tourtois-vault-panel-copy > strong {
|
|
402
|
+
color: var(--color-base-content);
|
|
403
|
+
}
|
|
404
|
+
.tourtois-vault-scope,
|
|
405
|
+
.tourtois-vault-destinations,
|
|
406
|
+
.tourtois-vault-sites {
|
|
407
|
+
display: grid;
|
|
408
|
+
gap: var(--spacing-sm);
|
|
409
|
+
min-width: 0;
|
|
410
|
+
}
|
|
411
|
+
.tourtois-vault-destination > .caps-fieldset-fields {
|
|
412
|
+
flex-direction: column;
|
|
413
|
+
flex-wrap: nowrap;
|
|
414
|
+
gap: var(--spacing-xs);
|
|
415
|
+
}
|
|
416
|
+
.tourtois-vault-methods {
|
|
417
|
+
font-family: var(--font-mono);
|
|
418
|
+
}
|
|
419
|
+
.tourtois-vault-usage {
|
|
420
|
+
display: grid;
|
|
421
|
+
gap: var(--spacing-2xs);
|
|
422
|
+
margin: 0;
|
|
423
|
+
padding: 0;
|
|
424
|
+
list-style: none;
|
|
425
|
+
}
|
|
426
|
+
.tourtois-vault-use {
|
|
427
|
+
display: grid;
|
|
428
|
+
grid-template-columns: minmax(9rem, auto) minmax(0, 1fr) minmax(0, 1fr) auto;
|
|
429
|
+
align-items: center;
|
|
430
|
+
gap: var(--spacing-xs) var(--spacing-sm);
|
|
431
|
+
min-width: 0;
|
|
432
|
+
padding-block: var(--spacing-2xs);
|
|
433
|
+
border-bottom: 1px solid var(--stipe-hairline);
|
|
434
|
+
font-size: var(--text-xs);
|
|
435
|
+
}
|
|
436
|
+
.tourtois-vault-use:last-child {
|
|
437
|
+
border-bottom: 0;
|
|
438
|
+
}
|
|
439
|
+
.tourtois-vault-use-who {
|
|
440
|
+
min-width: 0;
|
|
441
|
+
overflow: hidden;
|
|
442
|
+
text-overflow: ellipsis;
|
|
443
|
+
white-space: nowrap;
|
|
444
|
+
font-weight: 600;
|
|
445
|
+
}
|
|
446
|
+
.tourtois-vault-use-where,
|
|
447
|
+
.tourtois-vault-use-when {
|
|
448
|
+
min-width: 0;
|
|
449
|
+
color: var(--stipe-fg-muted);
|
|
450
|
+
}
|
|
451
|
+
.tourtois-vault-use-when {
|
|
452
|
+
white-space: nowrap;
|
|
453
|
+
text-align: end;
|
|
454
|
+
}
|
|
455
|
+
@container (max-width: 34rem) {
|
|
456
|
+
.tourtois-vault-use {
|
|
457
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
458
|
+
}
|
|
459
|
+
.tourtois-vault-use-who {
|
|
460
|
+
grid-column: 1;
|
|
461
|
+
grid-row: 2;
|
|
462
|
+
}
|
|
463
|
+
.tourtois-vault-use-where {
|
|
464
|
+
grid-column: 1 / -1;
|
|
465
|
+
grid-row: 3;
|
|
466
|
+
}
|
|
467
|
+
.tourtois-vault-use-when {
|
|
468
|
+
grid-column: 2;
|
|
469
|
+
grid-row: 1 / span 2;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
318
473
|
.tourtois-settings-tabs-end {
|
|
319
474
|
margin-left: auto;
|
|
320
475
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/tourtois",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.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",
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"types": "./dist/OysterComputers.d.ts",
|
|
39
39
|
"import": "./dist/OysterComputers.js"
|
|
40
40
|
},
|
|
41
|
+
"./vault": {
|
|
42
|
+
"types": "./dist/Vault.d.ts",
|
|
43
|
+
"import": "./dist/Vault.js"
|
|
44
|
+
},
|
|
41
45
|
"./website-channels": {
|
|
42
46
|
"types": "./dist/WebsiteChannels.d.ts",
|
|
43
47
|
"import": "./dist/WebsiteChannels.js"
|
|
@@ -79,7 +83,7 @@
|
|
|
79
83
|
"@fungi.computer/ear-tag": "0.1.0",
|
|
80
84
|
"@fungi.computer/gills": "0.4.0",
|
|
81
85
|
"@fungi.computer/maosaico": "0.1.2",
|
|
82
|
-
"@fungi.computer/parakeet": "0.14.
|
|
86
|
+
"@fungi.computer/parakeet": "0.14.5",
|
|
83
87
|
"@fungi.computer/puffball": "0.12.0",
|
|
84
88
|
"@fungi.computer/shiitake": "0.21.4",
|
|
85
89
|
"@fungi.computer/sigils": "0.3.2",
|
|
@@ -102,7 +106,7 @@
|
|
|
102
106
|
"react": "^18.3.1 || ^19.2.0"
|
|
103
107
|
},
|
|
104
108
|
"devDependencies": {
|
|
105
|
-
"@fungi.computer/oyster": "0.
|
|
109
|
+
"@fungi.computer/oyster": "0.46.0",
|
|
106
110
|
"@cloudflare/workers-types": "5.20260828.1",
|
|
107
111
|
"@fungi.computer/forage": "0.3.13",
|
|
108
112
|
"@fungi.computer/mycelium": "0.4.7",
|
|
@@ -256,10 +260,11 @@
|
|
|
256
260
|
"format:check": "node ../../tooling/repository/scripts/format-package-check.mjs",
|
|
257
261
|
"lint:anti-slop": "node ../../tooling/repository/scripts/lint-package-anti-slop.mjs",
|
|
258
262
|
"build:workbench": "pnpm run workbench:build",
|
|
259
|
-
"test:nightly": "node test/permission-matrix.browser.mjs && node --import tsx ../../tooling/repository/scripts/workbench-proofs.mjs --output ../../.botanical/tourtois-ladle --origin-env TOURTOIS_WORKBENCH_URL test/member-avatar.browser.mjs test/settings-icons.browser.mjs && node test/overlay-layering.browser.mjs",
|
|
263
|
+
"test:nightly": "node test/permission-matrix.browser.mjs && node --import tsx ../../tooling/repository/scripts/workbench-proofs.mjs --output ../../.botanical/tourtois-ladle --origin-env TOURTOIS_WORKBENCH_URL test/member-avatar.browser.mjs test/settings-icons.browser.mjs test/vault.browser.mjs && node test/overlay-layering.browser.mjs",
|
|
260
264
|
"test:unit": "vitest run",
|
|
261
265
|
"test:merge": "node test/layout-backend.native.mjs && node --import tsx test/desktop-refresh.native.mjs",
|
|
262
266
|
"test:app-call-permissions": "node --import tsx ../../tooling/repository/scripts/workbench-proofs.mjs --output ../../.botanical/tourtois-ladle --origin-env TOURTOIS_WORKBENCH_URL test/app-call-permissions.browser.mjs",
|
|
267
|
+
"test:vault": "node --import tsx ../../tooling/repository/scripts/workbench-proofs.mjs --output ../../.botanical/tourtois-ladle --origin-env TOURTOIS_WORKBENCH_URL test/vault.browser.mjs",
|
|
263
268
|
"test:window-resize": "node --import tsx ../../tooling/repository/scripts/workbench-proofs.mjs --output ../../.botanical/tourtois-ladle --origin-env TOURTOIS_WORKBENCH_URL test/window-resize.browser.mjs"
|
|
264
269
|
}
|
|
265
270
|
}
|
package/dist/ModelKeys.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import * as z from "zod";
|
|
2
|
-
export type Provider = string;
|
|
3
|
-
/** Every stored key and every Agent with its persisted model choice. */
|
|
4
|
-
export declare const modelKeysViewSchema: z.ZodObject<{
|
|
5
|
-
keys: z.ZodArray<z.ZodObject<{
|
|
6
|
-
keyId: z.ZodString;
|
|
7
|
-
provider: z.ZodString;
|
|
8
|
-
label: z.ZodString;
|
|
9
|
-
createdAt: z.ZodNumber;
|
|
10
|
-
validatedAt: z.ZodNumber;
|
|
11
|
-
}, z.core.$strict>>;
|
|
12
|
-
models: z.ZodEnum<{
|
|
13
|
-
ready: "ready";
|
|
14
|
-
unknown: "unknown";
|
|
15
|
-
missing: "missing";
|
|
16
|
-
}>;
|
|
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<{
|
|
23
|
-
id: z.ZodString;
|
|
24
|
-
name: z.ZodString;
|
|
25
|
-
input: z.ZodNumber;
|
|
26
|
-
output: z.ZodNumber;
|
|
27
|
-
tools: z.ZodBoolean;
|
|
28
|
-
}, z.core.$strict>>>;
|
|
29
|
-
agents: z.ZodArray<z.ZodObject<{
|
|
30
|
-
agentId: z.ZodString;
|
|
31
|
-
name: z.ZodString;
|
|
32
|
-
choice: z.ZodNullable<z.ZodObject<{
|
|
33
|
-
keySource: z.ZodEnum<{
|
|
34
|
-
"workers-ai": "workers-ai";
|
|
35
|
-
"ai-gateway": "ai-gateway";
|
|
36
|
-
byok: "byok";
|
|
37
|
-
}>;
|
|
38
|
-
keyId: z.ZodOptional<z.ZodString>;
|
|
39
|
-
model: z.ZodObject<{
|
|
40
|
-
providerId: z.ZodString;
|
|
41
|
-
modelId: z.ZodString;
|
|
42
|
-
reasoning: z.ZodOptional<z.ZodString>;
|
|
43
|
-
}, z.core.$strict>;
|
|
44
|
-
}, z.core.$strict>>;
|
|
45
|
-
}, z.core.$strict>>;
|
|
46
|
-
}, z.core.$strict>;
|
|
47
|
-
export type ModelKeysView = z.output<typeof modelKeysViewSchema>;
|
|
48
|
-
/** What the owner submits to store one key. */
|
|
49
|
-
export type ModelKeyDraft = Readonly<{
|
|
50
|
-
provider: Provider;
|
|
51
|
-
label: string;
|
|
52
|
-
apiKey: string;
|
|
53
|
-
accountId?: string;
|
|
54
|
-
}>;
|
|
55
|
-
/** The Agent's next model: the instance default, or a stored key's provider. */
|
|
56
|
-
export type AgentModelChoiceDraft = Readonly<{
|
|
57
|
-
keyId: null;
|
|
58
|
-
}> | Readonly<{
|
|
59
|
-
keyId: string;
|
|
60
|
-
provider: Provider;
|
|
61
|
-
modelId: string;
|
|
62
|
-
}>;
|
|
63
|
-
/** The host's owner-direct model-key custody and per-Agent model choice. */
|
|
64
|
-
export type ModelKeysPort = Readonly<{
|
|
65
|
-
read(): Promise<ModelKeysView>;
|
|
66
|
-
addKey(draft: ModelKeyDraft): Promise<void>;
|
|
67
|
-
removeKey(keyId: string): Promise<void>;
|
|
68
|
-
chooseModel(agentId: string, draft: AgentModelChoiceDraft): Promise<void>;
|
|
69
|
-
}>;
|
|
70
|
-
/**
|
|
71
|
-
* Model keys on a standalone host: store a provider API key once, then pick
|
|
72
|
-
* which model and key each Agent runs on. A key is never shown again.
|
|
73
|
-
*/
|
|
74
|
-
export declare function ModelKeys({ port, focus, }: {
|
|
75
|
-
port: ModelKeysPort;
|
|
76
|
-
focus?: boolean;
|
|
77
|
-
}): import("react/jsx-runtime").JSX.Element;
|
package/dist/ModelKeys.js
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
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 { Select } from "@fungi.computer/caps/components/select";
|
|
6
|
-
import { FormFooter } from "@fungi.computer/caps/components/field";
|
|
7
|
-
import { KeycapButton } from "@fungi.computer/caps/components/keycap";
|
|
8
|
-
import { FormField, FormFields, SchemaForm, field, useSchemaForm, } from "@fungi.computer/caps/form";
|
|
9
|
-
import { Sigil } from "@fungi.computer/sigils";
|
|
10
|
-
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
11
|
-
import { useCallback, useMemo, useState } from "react";
|
|
12
|
-
import * as z from "zod";
|
|
13
|
-
import { SettingsItem } from "./settings-item.js";
|
|
14
|
-
import { toast } from "@fungi.computer/caps/components/toaster";
|
|
15
|
-
import { WORKBENCH_NOTICES } from "./app-toast.js";
|
|
16
|
-
/** A provider the host offers; the host owns the list and the client only shows it. */
|
|
17
|
-
const providerChoiceSchema = z.strictObject({
|
|
18
|
-
id: z.string().min(1),
|
|
19
|
-
label: z.string().min(1),
|
|
20
|
-
accountId: z.boolean(),
|
|
21
|
-
});
|
|
22
|
-
const providerSchema = z.string().min(1);
|
|
23
|
-
/** One stored key as the host lists it; the secret never comes back. */
|
|
24
|
-
const modelKeySchema = z.strictObject({
|
|
25
|
-
keyId: z.string().min(1),
|
|
26
|
-
provider: providerSchema,
|
|
27
|
-
label: z.string().min(1),
|
|
28
|
-
createdAt: z.number(),
|
|
29
|
-
validatedAt: z.number(),
|
|
30
|
-
});
|
|
31
|
-
const agentChoiceSchema = z.strictObject({
|
|
32
|
-
keySource: z.enum(["workers-ai", "ai-gateway", "byok"]),
|
|
33
|
-
keyId: z.string().min(1).optional(),
|
|
34
|
-
model: z.strictObject({
|
|
35
|
-
providerId: z.string().min(1),
|
|
36
|
-
modelId: z.string().min(1),
|
|
37
|
-
reasoning: z.string().optional(),
|
|
38
|
-
}),
|
|
39
|
-
});
|
|
40
|
-
/** Every stored key and every Agent with its persisted model choice. */
|
|
41
|
-
export const modelKeysViewSchema = z.strictObject({
|
|
42
|
-
keys: z.array(modelKeySchema),
|
|
43
|
-
models: z.enum(["ready", "missing", "unknown"]),
|
|
44
|
-
providers: z.array(providerChoiceSchema).min(1),
|
|
45
|
-
catalogs: z.partialRecord(providerSchema, z.array(z.strictObject({
|
|
46
|
-
id: z.string().min(1),
|
|
47
|
-
name: z.string().min(1),
|
|
48
|
-
input: z.number().nonnegative(),
|
|
49
|
-
output: z.number().nonnegative(),
|
|
50
|
-
tools: z.boolean(),
|
|
51
|
-
}))),
|
|
52
|
-
agents: z.array(z.strictObject({
|
|
53
|
-
agentId: z.string().min(1),
|
|
54
|
-
name: z.string(),
|
|
55
|
-
choice: agentChoiceSchema.nullable(),
|
|
56
|
-
})),
|
|
57
|
-
});
|
|
58
|
-
/** Provider label from the host's list; an unlisted provider shows its id. */
|
|
59
|
-
const providerLabel = (providers, id) => providers.find((choice) => choice.id === id)?.label ?? id;
|
|
60
|
-
const queryKey = ["tourtois", "model-keys"];
|
|
61
|
-
const defaultSource = "default";
|
|
62
|
-
/**
|
|
63
|
-
* Model keys on a standalone host: store a provider API key once, then pick
|
|
64
|
-
* which model and key each Agent runs on. A key is never shown again.
|
|
65
|
-
*/
|
|
66
|
-
export function ModelKeys({ port, focus = false, }) {
|
|
67
|
-
const client = useQueryClient();
|
|
68
|
-
const view = useQuery({ queryKey, queryFn: () => port.read() });
|
|
69
|
-
const status = view.status;
|
|
70
|
-
const focusSetup = useCallback((section) => {
|
|
71
|
-
if (!focus || status === "pending")
|
|
72
|
-
return;
|
|
73
|
-
const target = section?.querySelector("select") ??
|
|
74
|
-
section?.querySelector("button");
|
|
75
|
-
target?.focus();
|
|
76
|
-
}, [focus, status]);
|
|
77
|
-
const refresh = () => client.invalidateQueries({ queryKey });
|
|
78
|
-
const remove = useMutation({
|
|
79
|
-
mutationFn: (keyId) => port.removeKey(keyId),
|
|
80
|
-
onSuccess: refresh,
|
|
81
|
-
onError: () => {
|
|
82
|
-
toast.error("The model key could not be removed.", {
|
|
83
|
-
toasterId: WORKBENCH_NOTICES,
|
|
84
|
-
});
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
const keys = view.data?.keys ?? [];
|
|
88
|
-
const agents = view.data?.agents ?? [];
|
|
89
|
-
// A fresh form after each stored key, so the key field empties.
|
|
90
|
-
const [formKey, setFormKey] = useState(0);
|
|
91
|
-
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: () => {
|
|
92
|
-
remove.mutate(key.keyId);
|
|
93
|
-
} }) }) }, key.keyId)))] }), _jsx(AddModelKey, { providers: view.data.providers, onAdd: async (draft) => {
|
|
94
|
-
await port.addKey(draft);
|
|
95
|
-
await refresh();
|
|
96
|
-
setFormKey((current) => current + 1);
|
|
97
|
-
} }, formKey), _jsx(SectionHeading, { children: "Agent models" }), view.data.models === "missing" ? (_jsx("p", { role: "status", className: "tourtois-settings-note", children: "No model is connected yet. The instance default cannot reply until you add a model key." })) : null, _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) => {
|
|
98
|
-
const selectedKey = keys.find((key) => key.keyId === agent.choice?.keyId);
|
|
99
|
-
const catalog = Object.entries(view.data.catalogs).find(([provider]) => provider === agent.choice?.model.providerId)?.[1];
|
|
100
|
-
const name = catalog?.find((model) => model.id === agent.choice?.model.modelId)?.name;
|
|
101
|
-
const disconnected = view.data.models === "missing" ||
|
|
102
|
-
(agent.choice?.keySource === "byok" &&
|
|
103
|
-
selectedKey === undefined);
|
|
104
|
-
return (_jsxs(FactRow, { icon: _jsx(Sigil, { name: "agent" }), label: agent.name, children: [disconnected
|
|
105
|
-
? "Not connected"
|
|
106
|
-
: agent.choice === null
|
|
107
|
-
? "Unavailable"
|
|
108
|
-
: (name ??
|
|
109
|
-
(catalog === undefined
|
|
110
|
-
? "Instance default"
|
|
111
|
-
: "Model unavailable for tools")), disconnected || selectedKey === undefined
|
|
112
|
-
? ""
|
|
113
|
-
: ` · ${selectedKey.label}`] }, agent.agentId));
|
|
114
|
-
})] }), 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) => {
|
|
115
|
-
await port.chooseModel(agentId, draft);
|
|
116
|
-
await refresh();
|
|
117
|
-
} }, keys.map((key) => key.keyId).join(":"))) : null] })) : null] }));
|
|
118
|
-
}
|
|
119
|
-
function AddModelKey({ providers, onAdd, }) {
|
|
120
|
-
const needsAccountId = (provider) => providers.find((choice) => choice.id === provider)?.accountId === true;
|
|
121
|
-
const schema = useMemo(() => z.object({
|
|
122
|
-
provider: providerSchema.meta(field({
|
|
123
|
-
label: "Provider",
|
|
124
|
-
icon: _jsx(Sigil, { name: "internet" }),
|
|
125
|
-
kind: "select",
|
|
126
|
-
options: Object.fromEntries(providers.map((choice) => [choice.id, choice.label])),
|
|
127
|
-
})),
|
|
128
|
-
label: z
|
|
129
|
-
.string()
|
|
130
|
-
.min(1, "Name this key")
|
|
131
|
-
.max(64)
|
|
132
|
-
.meta(field({
|
|
133
|
-
label: "Name",
|
|
134
|
-
icon: _jsx(Sigil, { name: "write" }),
|
|
135
|
-
maxLength: 64,
|
|
136
|
-
placeholder: "Work key",
|
|
137
|
-
})),
|
|
138
|
-
accountId: z
|
|
139
|
-
.string()
|
|
140
|
-
.max(32)
|
|
141
|
-
.meta(field({
|
|
142
|
-
label: "Account ID",
|
|
143
|
-
icon: _jsx(Sigil, { name: "internet" }),
|
|
144
|
-
help: "Find this in your Cloudflare dashboard. The token needs Workers AI access for this account.",
|
|
145
|
-
maxLength: 32,
|
|
146
|
-
})),
|
|
147
|
-
apiKey: z
|
|
148
|
-
.string()
|
|
149
|
-
.min(1, "Paste the key")
|
|
150
|
-
.max(16_384)
|
|
151
|
-
.meta(field({
|
|
152
|
-
label: "API key",
|
|
153
|
-
icon: _jsx(Sigil, { name: "restricted" }),
|
|
154
|
-
help: "Sealed on this instance and never shown again.",
|
|
155
|
-
kind: "secret",
|
|
156
|
-
})),
|
|
157
|
-
}), [providers]);
|
|
158
|
-
const add = useMutation({ mutationFn: onAdd });
|
|
159
|
-
const model = useSchemaForm({
|
|
160
|
-
schema,
|
|
161
|
-
defaultValues: {
|
|
162
|
-
provider: providers[0]?.id ?? "",
|
|
163
|
-
label: "",
|
|
164
|
-
apiKey: "",
|
|
165
|
-
accountId: "",
|
|
166
|
-
},
|
|
167
|
-
onSubmit: async (value) => {
|
|
168
|
-
try {
|
|
169
|
-
if (needsAccountId(value.provider) &&
|
|
170
|
-
!/^[a-f0-9]{32}$/u.test(value.accountId))
|
|
171
|
-
return {
|
|
172
|
-
kind: "refused",
|
|
173
|
-
fields: {
|
|
174
|
-
accountId: "Enter your 32-character Cloudflare account ID.",
|
|
175
|
-
},
|
|
176
|
-
};
|
|
177
|
-
const draft = {
|
|
178
|
-
provider: value.provider,
|
|
179
|
-
label: value.label,
|
|
180
|
-
apiKey: value.apiKey,
|
|
181
|
-
};
|
|
182
|
-
await add.mutateAsync(needsAccountId(value.provider)
|
|
183
|
-
? { ...draft, accountId: value.accountId }
|
|
184
|
-
: draft);
|
|
185
|
-
return { kind: "saved" };
|
|
186
|
-
}
|
|
187
|
-
catch (cause) {
|
|
188
|
-
return {
|
|
189
|
-
kind: "refused",
|
|
190
|
-
error: cause instanceof Error
|
|
191
|
-
? cause.message
|
|
192
|
-
: "The model key could not be stored.",
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
});
|
|
197
|
-
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)
|
|
198
|
-
? ["provider", "label", "accountId", "apiKey"]
|
|
199
|
-
: ["provider", "label", "apiKey"], layout: "columns" })) }) }));
|
|
200
|
-
}
|
|
201
|
-
function ChooseAgentModel({ agents, keys, providers, catalogs, models, onChoose, }) {
|
|
202
|
-
const schema = useMemo(() => z.object({
|
|
203
|
-
agentId: z.string().meta(field({
|
|
204
|
-
label: "Agent",
|
|
205
|
-
icon: _jsx(Sigil, { name: "agent" }),
|
|
206
|
-
kind: "select",
|
|
207
|
-
options: Object.fromEntries(agents.map((agent) => [agent.agentId, agent.name])),
|
|
208
|
-
})),
|
|
209
|
-
source: z.string(),
|
|
210
|
-
modelId: z.string(),
|
|
211
|
-
}), [agents]);
|
|
212
|
-
const choose = useMutation({
|
|
213
|
-
mutationFn: (input) => onChoose(input.agentId, input.draft),
|
|
214
|
-
});
|
|
215
|
-
const model = useSchemaForm({
|
|
216
|
-
schema,
|
|
217
|
-
defaultValues: {
|
|
218
|
-
agentId: agents[0]?.agentId ?? "",
|
|
219
|
-
source: keys[0]?.keyId ?? defaultSource,
|
|
220
|
-
modelId: "",
|
|
221
|
-
},
|
|
222
|
-
onSubmit: async (value) => {
|
|
223
|
-
const key = keys.find((item) => item.keyId === value.source);
|
|
224
|
-
if (value.source !== defaultSource && key === undefined)
|
|
225
|
-
return { kind: "refused", error: "Choose a stored key." };
|
|
226
|
-
const available = key === undefined ? [] : (catalogs[key.provider] ?? []);
|
|
227
|
-
const modelId = value.modelId || available.find((item) => item.tools)?.id;
|
|
228
|
-
if (key !== undefined && !available.some((item) => item.id === modelId))
|
|
229
|
-
return {
|
|
230
|
-
kind: "refused",
|
|
231
|
-
error: "Choose a supported model for this key.",
|
|
232
|
-
};
|
|
233
|
-
try {
|
|
234
|
-
await choose.mutateAsync({
|
|
235
|
-
agentId: value.agentId,
|
|
236
|
-
draft: key === undefined
|
|
237
|
-
? { keyId: null }
|
|
238
|
-
: {
|
|
239
|
-
keyId: key.keyId,
|
|
240
|
-
provider: key.provider,
|
|
241
|
-
modelId: modelId ?? "",
|
|
242
|
-
},
|
|
243
|
-
});
|
|
244
|
-
return { kind: "saved" };
|
|
245
|
-
}
|
|
246
|
-
catch (cause) {
|
|
247
|
-
return {
|
|
248
|
-
kind: "refused",
|
|
249
|
-
error: cause instanceof Error
|
|
250
|
-
? cause.message
|
|
251
|
-
: "The model could not be saved.",
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
},
|
|
255
|
-
});
|
|
256
|
-
return (_jsxs(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" }) }), children: [_jsx(FormFields, { model: model, names: ["agentId"] }), _jsx(FormField, { form: model.form, name: "source", label: "Runs on", children: (source) => (_jsxs(Select, { name: "source", value: source.state.value, onChange: (event) => {
|
|
257
|
-
source.handleChange(event.target.value);
|
|
258
|
-
model.form.setFieldValue("modelId", "");
|
|
259
|
-
}, children: [_jsx("option", { value: defaultSource, children: models === "missing"
|
|
260
|
-
? "Instance default — not connected"
|
|
261
|
-
: "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) => {
|
|
262
|
-
const key = keys.find((item) => item.keyId === source);
|
|
263
|
-
if (key === undefined)
|
|
264
|
-
return null;
|
|
265
|
-
const available = catalogs[key.provider] ?? [];
|
|
266
|
-
return (_jsx(FormField, { form: model.form, name: "modelId", label: "Model", description: "Choose tools for work in Apps. Other models may not use tools. USD per million tokens: input / output; lowest rate first in each group.", children: (choice) => (_jsxs(Select, { name: "modelId", value: choice.state.value ||
|
|
267
|
-
(available.find((item) => item.tools)?.id ?? ""), onChange: (event) => {
|
|
268
|
-
choice.handleChange(event.target.value);
|
|
269
|
-
}, children: [available.length === 0 ? (_jsx("option", { value: "", children: "No supported models available" })) : null, available.length > 0 &&
|
|
270
|
-
!available.some((item) => item.tools) ? (_jsx("option", { value: "", children: "Choose a model" })) : null, [true, false].map((tools) => {
|
|
271
|
-
const group = available.filter((item) => item.tools === tools);
|
|
272
|
-
return group.length === 0 ? null : (_jsx("optgroup", { label: tools ? "Tools" : "Other models (may not use tools)", children: group.map((item) => (_jsxs("option", { value: item.id, children: [item.name, " \u00B7 ", tools ? "tools" : "chat only", " \u00B7 $", item.input, " / $", item.output] }, item.id))) }, String(tools)));
|
|
273
|
-
})] })) }));
|
|
274
|
-
} })] }));
|
|
275
|
-
}
|