@fungi.computer/tourtois 0.7.0 → 0.8.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/Connections.d.ts +94 -0
- package/dist/Connections.js +303 -0
- package/dist/SystemSettings.js +3 -5
- package/dist/WebsiteChannels.d.ts +131 -0
- package/dist/WebsiteChannels.js +372 -0
- package/dist/oyster-platform-controls.js +33 -14
- package/dist/platform-controls.d.ts +1 -1
- package/dist/platform-controls.js +1 -1
- package/dist/queries.d.ts +3 -0
- package/dist/queries.js +6 -0
- package/dist/settings-navigation.css +7 -0
- package/dist/settings-sections.d.ts +3 -8
- package/dist/settings-sections.js +1 -1
- package/package.json +9 -5
- package/dist/AgentMcpServers.d.ts +0 -34
- package/dist/AgentMcpServers.js +0 -127
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type ComponentType } from "react";
|
|
2
|
+
import type { ConnectorsTarget, Navigate } from "./settings-sections.js";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
/** What an Agent may do with one connection: everything, only reads, or named tools. */
|
|
5
|
+
declare const connectionAccessSchema: z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodLiteral<"read">, z.ZodArray<z.ZodString>]>;
|
|
6
|
+
export type ConnectionAccess = z.output<typeof connectionAccessSchema>;
|
|
7
|
+
/** The connections an owner holds, with who may use each. No secret ever appears. */
|
|
8
|
+
export declare const connectionsViewSchema: z.ZodObject<{
|
|
9
|
+
callbackUrl: z.ZodNullable<z.ZodString>;
|
|
10
|
+
agents: z.ZodArray<z.ZodObject<{
|
|
11
|
+
agentId: z.ZodString;
|
|
12
|
+
name: z.ZodString;
|
|
13
|
+
}, z.core.$strict>>;
|
|
14
|
+
connections: z.ZodArray<z.ZodObject<{
|
|
15
|
+
connectionId: z.ZodString;
|
|
16
|
+
name: z.ZodString;
|
|
17
|
+
label: z.ZodString;
|
|
18
|
+
kind: z.ZodEnum<{
|
|
19
|
+
mcp: "mcp";
|
|
20
|
+
openapi: "openapi";
|
|
21
|
+
}>;
|
|
22
|
+
url: z.ZodString;
|
|
23
|
+
auth: z.ZodEnum<{
|
|
24
|
+
none: "none";
|
|
25
|
+
token: "token";
|
|
26
|
+
oauth: "oauth";
|
|
27
|
+
}>;
|
|
28
|
+
state: z.ZodEnum<{
|
|
29
|
+
pending: "pending";
|
|
30
|
+
connected: "connected";
|
|
31
|
+
reconnect_required: "reconnect_required";
|
|
32
|
+
}>;
|
|
33
|
+
grants: z.ZodArray<z.ZodObject<{
|
|
34
|
+
agentId: z.ZodString;
|
|
35
|
+
access: z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodLiteral<"read">, z.ZodArray<z.ZodString>]>;
|
|
36
|
+
}, z.core.$strict>>;
|
|
37
|
+
}, z.core.$strict>>;
|
|
38
|
+
}, z.core.$strict>;
|
|
39
|
+
export type ConnectionsView = z.output<typeof connectionsViewSchema>;
|
|
40
|
+
export type ConnectionRecord = ConnectionsView["connections"][number];
|
|
41
|
+
/** What the owner submits to connect one MCP server. */
|
|
42
|
+
export type ConnectionDraft = Readonly<{
|
|
43
|
+
name: string;
|
|
44
|
+
url: string;
|
|
45
|
+
bearer: string | null;
|
|
46
|
+
/** Sign in at the server instead of pasting a token; the client is optional. */
|
|
47
|
+
oauth?: Readonly<{
|
|
48
|
+
clientId?: string | undefined;
|
|
49
|
+
clientSecret?: string | undefined;
|
|
50
|
+
}>;
|
|
51
|
+
}>;
|
|
52
|
+
/** Where to send the owner to finish signing in, when the server asked for it. */
|
|
53
|
+
export declare const connectionAddedSchema: z.ZodObject<{
|
|
54
|
+
authorizeUrl: z.ZodNullable<z.ZodString>;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
export declare const connectionToolsSchema: z.ZodObject<{
|
|
57
|
+
tools: z.ZodArray<z.ZodString>;
|
|
58
|
+
}, z.core.$strict>;
|
|
59
|
+
/**
|
|
60
|
+
* The one Settings port for connections, on every host: who holds what, who
|
|
61
|
+
* may use it, and the owner's controls. A host with kinds of its own mounts
|
|
62
|
+
* them beside the shared list through `hostSections`.
|
|
63
|
+
*/
|
|
64
|
+
export type ConnectionsPort = Readonly<{
|
|
65
|
+
list(): Promise<ConnectionsView>;
|
|
66
|
+
add(draft: ConnectionDraft): Promise<z.output<typeof connectionAddedSchema>>;
|
|
67
|
+
/** Give one Agent access, or change what it has. */
|
|
68
|
+
grant(input: {
|
|
69
|
+
connectionId: string;
|
|
70
|
+
agentId: string;
|
|
71
|
+
access: ConnectionAccess;
|
|
72
|
+
}): Promise<void>;
|
|
73
|
+
ungrant(connectionId: string, agentId: string): Promise<void>;
|
|
74
|
+
remove(connectionId: string): Promise<void>;
|
|
75
|
+
/** The tool names an MCP server offers, for choosing a narrower grant. */
|
|
76
|
+
tools(connectionId: string): Promise<readonly string[]>;
|
|
77
|
+
/** Where the host edits a connection it has its own editor for, or null. */
|
|
78
|
+
editor?(connection: ConnectionRecord): ConnectorsTarget | null;
|
|
79
|
+
/** The host's own connector editors (Apps, Git, importing a spec), shown beside the list. */
|
|
80
|
+
hostSections?: ComponentType<{
|
|
81
|
+
target: ConnectorsTarget;
|
|
82
|
+
onNavigate: Navigate;
|
|
83
|
+
}>;
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* Connections settings: what this instance reaches outside, which Agents may
|
|
87
|
+
* use it, and how much. Secrets stay with the owner, never with an Agent.
|
|
88
|
+
*/
|
|
89
|
+
export declare function Connections({ port, target, onNavigate, }: {
|
|
90
|
+
port: ConnectionsPort;
|
|
91
|
+
target: ConnectorsTarget;
|
|
92
|
+
onNavigate: Navigate;
|
|
93
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
94
|
+
export {};
|
|
@@ -0,0 +1,303 @@
|
|
|
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, DataRow, FactRow, } from "@fungi.computer/caps/components/data-list";
|
|
5
|
+
import { FieldSet, FormFooter } from "@fungi.computer/caps/components/field";
|
|
6
|
+
import { CheckKey, CheckKeys, } from "@fungi.computer/caps/components/icon-checkbox";
|
|
7
|
+
import { KeycapButton } from "@fungi.computer/caps/components/keycap";
|
|
8
|
+
import { SchemaForm, field, useSchemaForm } from "@fungi.computer/caps/form";
|
|
9
|
+
import { Sigil } from "@fungi.computer/sigils";
|
|
10
|
+
import { queryOptions, useMutation, useQuery, useQueryClient, } from "@tanstack/react-query";
|
|
11
|
+
import { useState } from "react";
|
|
12
|
+
import * as z from "zod";
|
|
13
|
+
import { SettingsItem } from "./settings-item.js";
|
|
14
|
+
/** What an Agent may do with one connection: everything, only reads, or named tools. */
|
|
15
|
+
const connectionAccessSchema = z.union([
|
|
16
|
+
z.literal("all"),
|
|
17
|
+
z.literal("read"),
|
|
18
|
+
z.array(z.string().min(1).max(256)).max(256),
|
|
19
|
+
]);
|
|
20
|
+
/** The connections an owner holds, with who may use each. No secret ever appears. */
|
|
21
|
+
export const connectionsViewSchema = z.strictObject({
|
|
22
|
+
/** The redirect URL to register when bringing your own OAuth app; null when the host has no sign-in. */
|
|
23
|
+
callbackUrl: z.string().min(1).nullable(),
|
|
24
|
+
agents: z.array(z.strictObject({ agentId: z.string().min(1), name: z.string() })),
|
|
25
|
+
connections: z.array(z.strictObject({
|
|
26
|
+
connectionId: z.string().min(1),
|
|
27
|
+
name: z.string().min(1),
|
|
28
|
+
label: z.string().min(1),
|
|
29
|
+
kind: z.enum(["mcp", "openapi"]),
|
|
30
|
+
url: z.string().min(1),
|
|
31
|
+
auth: z.enum(["none", "token", "oauth"]),
|
|
32
|
+
state: z.enum(["connected", "pending", "reconnect_required"]),
|
|
33
|
+
grants: z.array(z.strictObject({
|
|
34
|
+
agentId: z.string().min(1),
|
|
35
|
+
access: connectionAccessSchema,
|
|
36
|
+
})),
|
|
37
|
+
})),
|
|
38
|
+
});
|
|
39
|
+
/** Where to send the owner to finish signing in, when the server asked for it. */
|
|
40
|
+
export const connectionAddedSchema = z.object({
|
|
41
|
+
authorizeUrl: z.string().nullable(),
|
|
42
|
+
});
|
|
43
|
+
export const connectionToolsSchema = z.strictObject({
|
|
44
|
+
tools: z.array(z.string().min(1)).max(1_024),
|
|
45
|
+
});
|
|
46
|
+
const queryKey = ["tourtois", "connections"];
|
|
47
|
+
const toolsQuery = (port, connectionId) => queryOptions({
|
|
48
|
+
queryKey: [...queryKey, "tools", connectionId],
|
|
49
|
+
queryFn: () => port.tools(connectionId),
|
|
50
|
+
});
|
|
51
|
+
const authText = {
|
|
52
|
+
none: "No token",
|
|
53
|
+
token: "Token sealed",
|
|
54
|
+
oauth: "Signed in",
|
|
55
|
+
};
|
|
56
|
+
const stateText = {
|
|
57
|
+
connected: "",
|
|
58
|
+
pending: " · Waiting for sign-in",
|
|
59
|
+
reconnect_required: " · Sign in again",
|
|
60
|
+
};
|
|
61
|
+
const accessText = (access) => access === "all"
|
|
62
|
+
? "All tools"
|
|
63
|
+
: access === "read"
|
|
64
|
+
? "Read only"
|
|
65
|
+
: `${String(access.length)} selected`;
|
|
66
|
+
/**
|
|
67
|
+
* Connections settings: what this instance reaches outside, which Agents may
|
|
68
|
+
* use it, and how much. Secrets stay with the owner, never with an Agent.
|
|
69
|
+
*/
|
|
70
|
+
export function Connections({ port, target, onNavigate, }) {
|
|
71
|
+
const client = useQueryClient();
|
|
72
|
+
const view = useQuery({ queryKey, queryFn: () => port.list() });
|
|
73
|
+
const refresh = () => client.invalidateQueries({ queryKey });
|
|
74
|
+
const remove = useMutation({
|
|
75
|
+
mutationFn: (connectionId) => port.remove(connectionId),
|
|
76
|
+
onSuccess: refresh,
|
|
77
|
+
});
|
|
78
|
+
const agents = view.data?.agents ?? [];
|
|
79
|
+
const connections = view.data?.connections ?? [];
|
|
80
|
+
// A fresh form after each connection, so the token field empties.
|
|
81
|
+
const [formKey, setFormKey] = useState(0);
|
|
82
|
+
const HostSections = port.hostSections;
|
|
83
|
+
return (_jsxs("section", { className: "tourtois-settings-content tourtois-connectors", "aria-label": "Connections", children: [_jsx(SectionHeading, { children: "Connections" }), _jsx("p", { className: "tourtois-settings-lede", children: "Connect a remote MCP server, then choose which Agents may use it. A token is sealed by this host, never given to an Agent, and never shown again." }), view.data?.callbackUrl ? (_jsx(DataList, { density: "compact", "aria-label": "Redirect URL", children: _jsx(FactRow, { icon: _jsx(Sigil, { name: "internet" }), label: "Redirect URL", children: _jsx("code", { className: "text-[length:inherit]", children: view.data.callbackUrl }) }) })) : null, view.isPending ? _jsx("p", { children: "Loading connections\u2026" }) : null, view.isError ? (_jsxs("div", { role: "status", className: "tourtois-settings-notice", children: [_jsx("p", { children: "Connections could not be loaded." }), _jsx(Button, { size: "sm", variant: "outline", onClick: () => void view.refetch(), children: "Retry" })] })) : null, view.isSuccess ? (_jsxs(_Fragment, { children: [connections.length === 0 ? (_jsx("p", { children: "No connections yet." })) : (_jsx(DataList, { "aria-label": "Connections", children: connections.map((connection) => (_jsx(DataRow, { children: _jsx(SettingsItem, { icon: _jsx(Sigil, { name: "connected" }), title: connection.label, detail: _jsxs(_Fragment, { children: [_jsxs("p", { children: [connection.url, " \u00B7 ", authText[connection.auth], stateText[connection.state]] }), _jsx(AgentAccess, { connection: connection, agents: agents, port: port, onChanged: refresh }), _jsxs("div", { className: "tourtois-settings-item-keys mt-2", children: [port.editor?.(connection) ? (_jsx(KeycapButton, { density: "compact", label: "Edit", "aria-label": `Edit ${connection.label}`, onClick: () => {
|
|
84
|
+
const target = port.editor?.(connection);
|
|
85
|
+
if (target)
|
|
86
|
+
onNavigate({
|
|
87
|
+
category: "connectors",
|
|
88
|
+
target,
|
|
89
|
+
});
|
|
90
|
+
} })) : null, _jsx(KeycapButton, { density: "compact", tone: "destructive", label: "Remove", "aria-label": `Remove ${connection.label}`, disabled: remove.isPending, onClick: () => {
|
|
91
|
+
remove.mutate(connection.connectionId);
|
|
92
|
+
} })] })] }) }) }, connection.connectionId))) })), remove.isError ? (_jsx("p", { role: "alert", children: "The connection could not be removed." })) : null, _jsx(AddConnection, { signIn: view.data.callbackUrl !== null, onAdd: async (draft) => {
|
|
93
|
+
const added = await port.add(draft);
|
|
94
|
+
// OAuth servers finish at the authorization server, then return here.
|
|
95
|
+
if (added.authorizeUrl !== null) {
|
|
96
|
+
window.location.assign(added.authorizeUrl);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
await refresh();
|
|
100
|
+
setFormKey((current) => current + 1);
|
|
101
|
+
} }, formKey)] })) : null, HostSections ? (_jsx(HostSections, { target: target, onNavigate: onNavigate })) : null] }));
|
|
102
|
+
}
|
|
103
|
+
/** Who may use one connection, and how much; each change takes effect on the Agent's next call. */
|
|
104
|
+
function AgentAccess({ connection, agents, port, onChanged, }) {
|
|
105
|
+
const change = useMutation({
|
|
106
|
+
mutationFn: async (next) => {
|
|
107
|
+
if (next.access === null)
|
|
108
|
+
await port.ungrant(connection.connectionId, next.agentId);
|
|
109
|
+
else
|
|
110
|
+
await port.grant({
|
|
111
|
+
connectionId: connection.connectionId,
|
|
112
|
+
agentId: next.agentId,
|
|
113
|
+
access: next.access,
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
onSuccess: onChanged,
|
|
117
|
+
});
|
|
118
|
+
if (agents.length === 0)
|
|
119
|
+
return _jsx("p", { children: "Create an Agent to share this." });
|
|
120
|
+
const grantFor = (agentId) => connection.grants.find((grant) => grant.agentId === agentId);
|
|
121
|
+
return (_jsxs(FieldSet, { legend: `Agents using ${connection.label}`, icon: _jsx(Sigil, { name: "agent" }), disabled: change.isPending || connection.state !== "connected", children: [_jsx(CheckKeys, { children: agents.map((agent) => (_jsx(CheckKey, { name: `${connection.connectionId}:${agent.agentId}`, label: agent.name, icon: _jsx(Sigil, { name: "agent" }), hint: grantFor(agent.agentId) === undefined
|
|
122
|
+
? "No access"
|
|
123
|
+
: accessText(grantFor(agent.agentId)?.access ?? "all"), checked: grantFor(agent.agentId) !== undefined, onChange: (event) => {
|
|
124
|
+
change.mutate({
|
|
125
|
+
agentId: agent.agentId,
|
|
126
|
+
access: event.currentTarget.checked ? "all" : null,
|
|
127
|
+
});
|
|
128
|
+
} }, agent.agentId))) }), agents.flatMap((agent) => {
|
|
129
|
+
const grant = grantFor(agent.agentId);
|
|
130
|
+
return grant === undefined
|
|
131
|
+
? []
|
|
132
|
+
: [
|
|
133
|
+
_jsx(ChooseAccess, { connection: connection, agentName: agent.name, access: grant.access, port: port, onChoose: (access) => {
|
|
134
|
+
change.mutate({ agentId: agent.agentId, access });
|
|
135
|
+
} }, agent.agentId),
|
|
136
|
+
];
|
|
137
|
+
}), change.isError ? (_jsx("p", { role: "alert", children: "The access could not be changed." })) : null] }));
|
|
138
|
+
}
|
|
139
|
+
/** Narrow one Agent's access: everything, reads only, or the tools you pick. */
|
|
140
|
+
function ChooseAccess({ connection, agentName, access, port, onChoose, }) {
|
|
141
|
+
const selecting = Array.isArray(access);
|
|
142
|
+
const tools = useQuery({
|
|
143
|
+
...toolsQuery(port, connection.connectionId),
|
|
144
|
+
enabled: selecting && connection.kind === "mcp",
|
|
145
|
+
});
|
|
146
|
+
const modes = connection.kind === "mcp"
|
|
147
|
+
? [
|
|
148
|
+
["all", "All tools"],
|
|
149
|
+
["pick", "Selected tools"],
|
|
150
|
+
]
|
|
151
|
+
: [
|
|
152
|
+
["all", "All operations"],
|
|
153
|
+
["read", "Read only"],
|
|
154
|
+
];
|
|
155
|
+
const mode = selecting ? "pick" : access;
|
|
156
|
+
return (_jsxs("div", { className: "tourtois-connection-access", children: [_jsx(FactRow, { icon: _jsx(Sigil, { name: "agent" }), label: agentName, children: _jsxs("label", { children: [_jsx("span", { className: "sr-only", children: `Access for ${agentName}` }), _jsx("select", { "aria-label": `Access for ${agentName}`, value: mode, onChange: (event) => {
|
|
157
|
+
const next = event.currentTarget.value;
|
|
158
|
+
onChoose(next === "pick" ? [] : next === "read" ? "read" : "all");
|
|
159
|
+
}, children: modes.map(([value, text]) => (_jsx("option", { value: value, children: text }, value))) })] }) }), selecting ? (tools.isPending ? (_jsx("p", { children: "Loading tools\u2026" })) : tools.isError ? (_jsx("p", { role: "alert", children: "The tools could not be listed." })) : (_jsx(CheckKeys, { children: tools.data.map((tool) => (_jsx(CheckKey, { name: `${connection.connectionId}:${agentName}:${tool}`, label: tool, icon: _jsx(Sigil, { name: "write" }), checked: access.includes(tool), onChange: (event) => {
|
|
160
|
+
onChoose(event.currentTarget.checked
|
|
161
|
+
? [...access, tool]
|
|
162
|
+
: access.filter((name) => name !== tool));
|
|
163
|
+
} }, tool))) }))) : null] }));
|
|
164
|
+
}
|
|
165
|
+
const nameField = z
|
|
166
|
+
.string()
|
|
167
|
+
.regex(/^[a-z][a-z0-9_]{0,31}$/u, "Lowercase letters, digits and _, starting with a letter")
|
|
168
|
+
.meta(field({
|
|
169
|
+
label: "Name",
|
|
170
|
+
icon: _jsx(Sigil, { name: "write" }),
|
|
171
|
+
help: "The Agent calls its tools as env.mcp.<name>.",
|
|
172
|
+
maxLength: 32,
|
|
173
|
+
placeholder: "linear",
|
|
174
|
+
}));
|
|
175
|
+
const urlField = z
|
|
176
|
+
.string()
|
|
177
|
+
.max(2_048)
|
|
178
|
+
.refine((value) => URL.canParse(value) && new URL(value).protocol === "https:", "Use the server's https:// address")
|
|
179
|
+
.meta(field({
|
|
180
|
+
label: "Server URL",
|
|
181
|
+
icon: _jsx(Sigil, { name: "internet" }),
|
|
182
|
+
kind: "url",
|
|
183
|
+
placeholder: "https://mcp.example.com/mcp",
|
|
184
|
+
}));
|
|
185
|
+
const bearerField = z
|
|
186
|
+
.string()
|
|
187
|
+
.max(4_096)
|
|
188
|
+
.meta(field({
|
|
189
|
+
label: "Bearer token",
|
|
190
|
+
icon: _jsx(Sigil, { name: "restricted" }),
|
|
191
|
+
help: "Optional: only if the server asks for one.",
|
|
192
|
+
kind: "secret",
|
|
193
|
+
}));
|
|
194
|
+
/** Add a connection; a host with no sign-in page offers a token or none. */
|
|
195
|
+
function AddConnection({ onAdd, signIn, }) {
|
|
196
|
+
return signIn ? (_jsx(AddWithSignIn, { onAdd: onAdd })) : (_jsx(AddWithToken, { onAdd: onAdd }));
|
|
197
|
+
}
|
|
198
|
+
function AddWithToken({ onAdd, }) {
|
|
199
|
+
const schema = z.object({
|
|
200
|
+
name: nameField,
|
|
201
|
+
url: urlField,
|
|
202
|
+
bearer: bearerField,
|
|
203
|
+
});
|
|
204
|
+
const add = useMutation({
|
|
205
|
+
mutationFn: (draft) => onAdd(draft),
|
|
206
|
+
});
|
|
207
|
+
const model = useSchemaForm({
|
|
208
|
+
schema,
|
|
209
|
+
defaultValues: { name: "", url: "", bearer: "" },
|
|
210
|
+
onSubmit: async (value) => {
|
|
211
|
+
try {
|
|
212
|
+
await add.mutateAsync({
|
|
213
|
+
name: value.name,
|
|
214
|
+
url: value.url,
|
|
215
|
+
bearer: value.bearer.length === 0 ? null : value.bearer,
|
|
216
|
+
});
|
|
217
|
+
return { kind: "saved" };
|
|
218
|
+
}
|
|
219
|
+
catch (cause) {
|
|
220
|
+
return {
|
|
221
|
+
kind: "refused",
|
|
222
|
+
error: cause instanceof Error
|
|
223
|
+
? cause.message
|
|
224
|
+
: "The connection could not be made.",
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
return (_jsx(SchemaForm, { model: model, layout: "columns", "aria-label": "Add connection", disabled: add.isPending, footer: _jsx(FormFooter, { divider: false, error: model.error, children: _jsx(Button, { type: "submit", children: add.isPending ? "Connecting…" : "Add connection" }) }) }));
|
|
230
|
+
}
|
|
231
|
+
function AddWithSignIn({ onAdd, }) {
|
|
232
|
+
const schema = z.object({
|
|
233
|
+
name: nameField,
|
|
234
|
+
url: urlField,
|
|
235
|
+
bearer: bearerField,
|
|
236
|
+
signIn: z.string().meta(field({
|
|
237
|
+
label: "Authorization",
|
|
238
|
+
icon: _jsx(Sigil, { name: "restricted" }),
|
|
239
|
+
kind: "select",
|
|
240
|
+
options: {
|
|
241
|
+
token: "Bearer token, or none",
|
|
242
|
+
oauth: "Sign in with OAuth",
|
|
243
|
+
},
|
|
244
|
+
})),
|
|
245
|
+
clientId: z
|
|
246
|
+
.string()
|
|
247
|
+
.max(512)
|
|
248
|
+
.meta(field({
|
|
249
|
+
label: "Client ID",
|
|
250
|
+
icon: _jsx(Sigil, { name: "write" }),
|
|
251
|
+
help: "Optional: your own OAuth app. Otherwise the server registers one.",
|
|
252
|
+
})),
|
|
253
|
+
clientSecret: z
|
|
254
|
+
.string()
|
|
255
|
+
.max(4_096)
|
|
256
|
+
.meta(field({
|
|
257
|
+
label: "Client secret",
|
|
258
|
+
icon: _jsx(Sigil, { name: "restricted" }),
|
|
259
|
+
help: "Optional: sealed by this host.",
|
|
260
|
+
kind: "secret",
|
|
261
|
+
})),
|
|
262
|
+
});
|
|
263
|
+
const add = useMutation({
|
|
264
|
+
mutationFn: (draft) => onAdd(draft),
|
|
265
|
+
});
|
|
266
|
+
const model = useSchemaForm({
|
|
267
|
+
schema,
|
|
268
|
+
defaultValues: {
|
|
269
|
+
name: "",
|
|
270
|
+
url: "",
|
|
271
|
+
bearer: "",
|
|
272
|
+
signIn: "token",
|
|
273
|
+
clientId: "",
|
|
274
|
+
clientSecret: "",
|
|
275
|
+
},
|
|
276
|
+
onSubmit: async (value) => {
|
|
277
|
+
try {
|
|
278
|
+
const oauth = {
|
|
279
|
+
clientId: value.clientId.length > 0 ? value.clientId : undefined,
|
|
280
|
+
clientSecret: value.clientSecret.length > 0 ? value.clientSecret : undefined,
|
|
281
|
+
};
|
|
282
|
+
const draft = value.signIn === "oauth"
|
|
283
|
+
? { name: value.name, url: value.url, bearer: null, oauth }
|
|
284
|
+
: {
|
|
285
|
+
name: value.name,
|
|
286
|
+
url: value.url,
|
|
287
|
+
bearer: value.bearer.length === 0 ? null : value.bearer,
|
|
288
|
+
};
|
|
289
|
+
await add.mutateAsync(draft);
|
|
290
|
+
return { kind: "saved" };
|
|
291
|
+
}
|
|
292
|
+
catch (cause) {
|
|
293
|
+
return {
|
|
294
|
+
kind: "refused",
|
|
295
|
+
error: cause instanceof Error
|
|
296
|
+
? cause.message
|
|
297
|
+
: "The connection could not be made.",
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
return (_jsx(SchemaForm, { model: model, layout: "columns", "aria-label": "Add connection", disabled: add.isPending, footer: _jsx(FormFooter, { divider: false, error: model.error, children: _jsx(Button, { type: "submit", children: add.isPending ? "Connecting…" : "Add connection" }) }) }));
|
|
303
|
+
}
|
package/dist/SystemSettings.js
CHANGED
|
@@ -4,7 +4,7 @@ import { SectionHeading } from "@fungi.computer/caps/blocks/section-heading";
|
|
|
4
4
|
import { AppDesktopSettings, } from "./AppDesktopSettings.js";
|
|
5
5
|
import { addressKey, } from "@fungi.computer/nacre/app-directory";
|
|
6
6
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
7
|
-
import {
|
|
7
|
+
import { Connections } from "./Connections.js";
|
|
8
8
|
import { Keys } from "./Keys.js";
|
|
9
9
|
import { ModelKeys } from "./ModelKeys.js";
|
|
10
10
|
import { AppIcon } from "./app-icon.js";
|
|
@@ -25,7 +25,7 @@ export function SystemSettings({ location: requestedLocation, sections: ceiling,
|
|
|
25
25
|
const location = requestedLocation !== null && sections.includes(requestedLocation.category)
|
|
26
26
|
? requestedLocation
|
|
27
27
|
: null;
|
|
28
|
-
const {
|
|
28
|
+
const { connections, keys, appPermissions: AppPermissions, appAdvanced: AppAdvanced, } = ports;
|
|
29
29
|
const avatar = location?.category === "avatar";
|
|
30
30
|
const connectors = location?.category === "connectors";
|
|
31
31
|
const computersSection = location?.category === "computers";
|
|
@@ -133,9 +133,7 @@ export function SystemSettings({ location: requestedLocation, sections: ceiling,
|
|
|
133
133
|
appCount,
|
|
134
134
|
defaultAppCount: ports.summary?.defaultAppCount ?? null,
|
|
135
135
|
computerCount: ports.summary?.computerCount ?? null,
|
|
136
|
-
}, onNavigate: onNavigate })) : null, avatar && ports.avatar !== undefined ? (_jsx("div", { className: "tourtois-settings-content", children: _jsx(AvatarSettings, { save: ports.avatar.save }) })) : null, connectors &&
|
|
137
|
-
agentMcpServers === undefined &&
|
|
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" &&
|
|
136
|
+
}, onNavigate: onNavigate })) : null, avatar && ports.avatar !== undefined ? (_jsx("div", { className: "tourtois-settings-content", children: _jsx(AvatarSettings, { save: ports.avatar.save }) })) : null, connectors && connections !== undefined ? (location.target.kind === "list" ? (_jsx(Connections, { port: connections, target: location.target, onNavigate: onNavigate })) : connections.hostSections ? (_jsx(connections.hostSections, { target: location.target, onNavigate: onNavigate })) : null) : null, location?.category === "selling" && ports.selling !== undefined ? (_jsx(ports.selling, { appId: location.appId, onNavigate: onNavigate })) : null, computersSection && ports.computers !== undefined ? (_jsx("div", { className: "tourtois-settings-content", children: _jsx(ports.computers, {}) })) : null, keysSection && keys !== undefined ? (_jsx(Keys, { port: keys, apps: keyableApps })) : null, keysSection && ports.modelKeys !== undefined ? (_jsx(ModelKeys, { port: ports.modelKeys })) : null, location?.category === "channels" &&
|
|
139
137
|
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: () => {
|
|
140
138
|
onNavigate({
|
|
141
139
|
category: "apps",
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { type WebsiteConversation, type WebsiteSite, type WebsiteTranscript } from "@fungi.computer/nacre/website-channels";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
export type { WebsiteConversation, WebsiteSite, WebsiteTranscript };
|
|
4
|
+
/** An Agent a website can be bound to. */
|
|
5
|
+
export type WebsiteAgent = Readonly<{
|
|
6
|
+
agentId: string;
|
|
7
|
+
name: string;
|
|
8
|
+
}>;
|
|
9
|
+
/** Everything one host knows about its websites. */
|
|
10
|
+
export type WebsiteDirectory = Readonly<{
|
|
11
|
+
/** The host's own address, where the launcher and visitor API are served. */
|
|
12
|
+
embedOrigin: string;
|
|
13
|
+
agents: readonly WebsiteAgent[];
|
|
14
|
+
sites: readonly WebsiteSite[];
|
|
15
|
+
}>;
|
|
16
|
+
/** What an owner may change about one website. */
|
|
17
|
+
export type WebsiteChange = Readonly<{
|
|
18
|
+
lifecycle?: "active" | "suspended";
|
|
19
|
+
turnstile?: boolean;
|
|
20
|
+
rotateSiteKey?: true;
|
|
21
|
+
}>;
|
|
22
|
+
/** A new website: the Agent visitors talk to, where it appears and its brief. */
|
|
23
|
+
export type NewWebsite = Readonly<{
|
|
24
|
+
agentId: string;
|
|
25
|
+
origins: readonly string[];
|
|
26
|
+
persona: string;
|
|
27
|
+
}>;
|
|
28
|
+
/** Host-supplied owner controls over its websites, not a second inventory. */
|
|
29
|
+
export type WebsiteChannelsPort = Readonly<{
|
|
30
|
+
/** Names this host's data; two hosts never share a cache entry. */
|
|
31
|
+
scope: string;
|
|
32
|
+
read(): Promise<WebsiteDirectory>;
|
|
33
|
+
create(input: NewWebsite, requestId: string): Promise<WebsiteSite>;
|
|
34
|
+
update(bindingId: string, expectedVersion: number, change: WebsiteChange): Promise<WebsiteSite>;
|
|
35
|
+
conversations(site: WebsiteSite): Promise<readonly WebsiteConversation[]>;
|
|
36
|
+
transcript(site: WebsiteSite, sessionId: string): Promise<WebsiteTranscript>;
|
|
37
|
+
}>;
|
|
38
|
+
/** What the owner typed in the address field, read the way the host will. */
|
|
39
|
+
export type WebsiteAddresses = {
|
|
40
|
+
kind: "parsed";
|
|
41
|
+
origins: string[];
|
|
42
|
+
} | {
|
|
43
|
+
kind: "invalid";
|
|
44
|
+
message: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Read the owner's typed addresses, then run the web origin schema on each.
|
|
48
|
+
* Settings only forgives typing: a bare host gains `https://` and a lone
|
|
49
|
+
* trailing `/` is dropped, so a pasted home-page link works. Anything the
|
|
50
|
+
* schema refuses is named on the field instead of sent.
|
|
51
|
+
*/
|
|
52
|
+
export declare function parseWebsiteAddresses(text: string): WebsiteAddresses;
|
|
53
|
+
/** The loader tag an owner pastes, as coloured runs; joined, they are the tag. */
|
|
54
|
+
export declare function websiteEmbedSnippet(embedOrigin: string, siteKey: string): readonly [{
|
|
55
|
+
readonly kind: "tag";
|
|
56
|
+
readonly text: "<script";
|
|
57
|
+
}, {
|
|
58
|
+
readonly kind: "text";
|
|
59
|
+
readonly text: "\n ";
|
|
60
|
+
}, {
|
|
61
|
+
readonly kind: "attribute";
|
|
62
|
+
readonly text: "src";
|
|
63
|
+
}, {
|
|
64
|
+
readonly kind: "tag";
|
|
65
|
+
readonly text: "=";
|
|
66
|
+
}, {
|
|
67
|
+
readonly kind: "string";
|
|
68
|
+
readonly text: `"${string}/embed/v1.js"`;
|
|
69
|
+
}, {
|
|
70
|
+
readonly kind: "text";
|
|
71
|
+
readonly text: "\n ";
|
|
72
|
+
}, {
|
|
73
|
+
readonly kind: "attribute";
|
|
74
|
+
readonly text: "data-site";
|
|
75
|
+
}, {
|
|
76
|
+
readonly kind: "tag";
|
|
77
|
+
readonly text: "=";
|
|
78
|
+
}, {
|
|
79
|
+
readonly kind: "string";
|
|
80
|
+
readonly text: `"${string}"`;
|
|
81
|
+
}, {
|
|
82
|
+
readonly kind: "text";
|
|
83
|
+
readonly text: "\n ";
|
|
84
|
+
}, {
|
|
85
|
+
readonly kind: "attribute";
|
|
86
|
+
readonly text: "data-theme";
|
|
87
|
+
}, {
|
|
88
|
+
readonly kind: "tag";
|
|
89
|
+
readonly text: "=";
|
|
90
|
+
}, {
|
|
91
|
+
readonly kind: "string";
|
|
92
|
+
readonly text: "\"auto\"";
|
|
93
|
+
}, {
|
|
94
|
+
readonly kind: "text";
|
|
95
|
+
readonly text: "\n ";
|
|
96
|
+
}, {
|
|
97
|
+
readonly kind: "attribute";
|
|
98
|
+
readonly text: "async";
|
|
99
|
+
}, {
|
|
100
|
+
readonly kind: "text";
|
|
101
|
+
readonly text: "\n";
|
|
102
|
+
}, {
|
|
103
|
+
readonly kind: "tag";
|
|
104
|
+
readonly text: "></script>";
|
|
105
|
+
}];
|
|
106
|
+
/** Bind owner website controls to this trusted shell's own host. */
|
|
107
|
+
export declare function createOysterWebsiteChannelsPort(origin: URL): WebsiteChannelsPort;
|
|
108
|
+
/** Host copy that differs by what a visitor can reach. */
|
|
109
|
+
export type WebsiteChannelsCopy = Readonly<{
|
|
110
|
+
/** Opening paragraphs under the heading. */
|
|
111
|
+
intro: ReactNode;
|
|
112
|
+
/** What a visitor sees and what limits apply, for one Agent. */
|
|
113
|
+
visitors: (agentName: string) => ReactNode;
|
|
114
|
+
/** What a visitor's chat can trigger, for one Agent. */
|
|
115
|
+
reach: (agentName: string) => ReactNode;
|
|
116
|
+
}>;
|
|
117
|
+
/**
|
|
118
|
+
* Owner Settings for website chat: bind an Agent to a website, copy the code
|
|
119
|
+
* to paste there, pause it, require a security check, change its site key and
|
|
120
|
+
* read what visitors said. Hosts supply the port and the copy that differs.
|
|
121
|
+
*/
|
|
122
|
+
export declare function WebsiteChannels({ port, copy, assistant, siteNotice, children, }: {
|
|
123
|
+
port: WebsiteChannelsPort;
|
|
124
|
+
copy: WebsiteChannelsCopy;
|
|
125
|
+
/** A host's own way to make the first Agent; absent means create one in Agents. */
|
|
126
|
+
assistant?: (done: () => void, cancel: () => void) => ReactNode;
|
|
127
|
+
/** A host's note under one website, such as an Agent delivery state. */
|
|
128
|
+
siteNotice?: (site: WebsiteSite) => ReactNode;
|
|
129
|
+
/** Further sections the host keeps under the websites. */
|
|
130
|
+
children?: ReactNode;
|
|
131
|
+
}): import("react/jsx-runtime").JSX.Element;
|