@fungi.computer/tourtois 0.16.0 → 0.17.1
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/ChannelConversations.d.ts +34 -0
- package/dist/ChannelConversations.js +44 -0
- package/dist/DiscordChannels.d.ts +84 -0
- package/dist/DiscordChannels.js +388 -0
- package/dist/WebsiteChannels.js +5 -29
- package/dist/channel-time.d.ts +6 -0
- package/dist/channel-time.js +33 -0
- package/dist/oyster-platform-controls.js +3 -1
- package/dist/queries.d.ts +4 -0
- package/dist/queries.js +11 -0
- package/dist/settings-navigation.css +44 -0
- package/package.json +6 -6
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { WebsiteConversation, WebsiteTranscript } from "@fungi.computer/nacre/website-channels";
|
|
2
|
+
/** One reply that never reached its member, as the owner is told. */
|
|
3
|
+
export type ChannelProblem = Readonly<{
|
|
4
|
+
id: string;
|
|
5
|
+
/** Who was waiting. */
|
|
6
|
+
label: string;
|
|
7
|
+
at: number;
|
|
8
|
+
/** Why it did not arrive, in a sentence. */
|
|
9
|
+
reason: string;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* What one channel's owner reads: the conversations its Agent had, and any
|
|
13
|
+
* one transcript on request. Website and Discord share it; each host port
|
|
14
|
+
* brings its own cache keys, reads and words for the other party.
|
|
15
|
+
*/
|
|
16
|
+
export declare function ChannelConversations({ keys, load, read, speaker, empty, label, problems, }: {
|
|
17
|
+
keys: Readonly<{
|
|
18
|
+
list: readonly unknown[];
|
|
19
|
+
transcript: (sessionId: string) => readonly unknown[];
|
|
20
|
+
}>;
|
|
21
|
+
load: () => Promise<readonly WebsiteConversation[]>;
|
|
22
|
+
read: (sessionId: string) => Promise<WebsiteTranscript>;
|
|
23
|
+
/** What the party on the other side is called in a transcript. */
|
|
24
|
+
speaker: string;
|
|
25
|
+
/** What to say when nobody has written yet. */
|
|
26
|
+
empty: string;
|
|
27
|
+
/** Names the list for assistive technology. */
|
|
28
|
+
label: string;
|
|
29
|
+
/** Replies the channel owed and could not deliver; absent where there are none to report. */
|
|
30
|
+
problems?: Readonly<{
|
|
31
|
+
key: readonly unknown[];
|
|
32
|
+
load: () => Promise<readonly ChannelProblem[]>;
|
|
33
|
+
}>;
|
|
34
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { DataList, DataListHeading, DataRow, } from "@fungi.computer/caps/components/data-list";
|
|
3
|
+
import { channelWhen } from "./channel-time.js";
|
|
4
|
+
import { KeycapButton } from "@fungi.computer/caps/components/keycap";
|
|
5
|
+
import { useQuery } from "@tanstack/react-query";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
/**
|
|
8
|
+
* What one channel's owner reads: the conversations its Agent had, and any
|
|
9
|
+
* one transcript on request. Website and Discord share it; each host port
|
|
10
|
+
* brings its own cache keys, reads and words for the other party.
|
|
11
|
+
*/
|
|
12
|
+
export function ChannelConversations({ keys, load, read, speaker, empty, label, problems, }) {
|
|
13
|
+
const [shown, setShown] = useState(false);
|
|
14
|
+
const [reading, setReading] = useState(null);
|
|
15
|
+
const list = useQuery({
|
|
16
|
+
queryKey: keys.list,
|
|
17
|
+
enabled: shown,
|
|
18
|
+
retry: false,
|
|
19
|
+
queryFn: load,
|
|
20
|
+
});
|
|
21
|
+
const undelivered = useQuery({
|
|
22
|
+
queryKey: problems?.key ?? [],
|
|
23
|
+
enabled: shown && problems !== undefined,
|
|
24
|
+
retry: false,
|
|
25
|
+
queryFn: () => problems?.load() ?? Promise.resolve([]),
|
|
26
|
+
});
|
|
27
|
+
const transcript = useQuery({
|
|
28
|
+
queryKey: keys.transcript(reading ?? ""),
|
|
29
|
+
enabled: reading !== null,
|
|
30
|
+
retry: false,
|
|
31
|
+
queryFn: () => reading === null
|
|
32
|
+
? Promise.reject(new Error("No conversation is open"))
|
|
33
|
+
: read(reading),
|
|
34
|
+
});
|
|
35
|
+
return (_jsxs("section", { className: "grid gap-sm", "aria-label": "Conversations", children: [_jsx(DataListHeading, { level: 3, className: "tourtois-conversations-heading", children: "Conversations" }), shown ? null : (_jsx(KeycapButton, { density: "compact", label: "Show conversations", onClick: () => {
|
|
36
|
+
setShown(true);
|
|
37
|
+
} })), list.isPending && shown ? _jsx("p", { role: "status", children: "Loading\u2026" }) : null, list.isError ? (_jsx("p", { role: "alert", children: "Conversations could not be loaded." })) : null, list.data?.length === 0 ? _jsx("p", { className: "text-sm", children: empty }) : null, list.data !== undefined && list.data.length > 0 ? (_jsx(DataList, { density: "compact", "aria-label": label, children: list.data.map((conversation) => (_jsx(DataRow, { children: _jsxs("div", { className: "tourtois-conversation", children: [_jsxs("div", { className: "tourtois-conversation-row", children: [_jsx("span", { className: "tourtois-conversation-name text-sm", children: conversation.label }), _jsxs("span", { className: "flex flex-wrap items-center gap-sm", children: [_jsx("span", { className: "text-sm", children: channelWhen(conversation.lastEventAt, Date.now()) }), _jsx(KeycapButton, { density: "compact", label: reading === conversation.sessionId
|
|
38
|
+
? "Close transcript"
|
|
39
|
+
: "Read transcript", "aria-label": `${reading === conversation.sessionId ? "Close" : "Read"} transcript of ${conversation.label}`, onClick: () => {
|
|
40
|
+
setReading(reading === conversation.sessionId
|
|
41
|
+
? null
|
|
42
|
+
: conversation.sessionId);
|
|
43
|
+
} })] })] }), reading === conversation.sessionId ? (_jsxs("div", { className: "tourtois-conversation-transcript", children: [transcript.isPending ? (_jsx("p", { role: "status", children: "Loading\u2026" })) : null, transcript.isError ? (_jsx("p", { role: "alert", children: "This conversation could not be read." })) : null, transcript.data ? (_jsx("ol", { "aria-label": "Transcript", className: "grid gap-xs", children: transcript.data.lines.map((line, index) => (_jsxs("li", { className: "text-sm", children: [_jsxs("strong", { children: [line.role === "visitor" ? speaker : "Agent", ":"] }), " ", line.text] }, `${String(index)}-${line.role}`))) })) : null] })) : null] }) }, conversation.sessionId))) })) : null, undelivered.data !== undefined && undelivered.data.length > 0 ? (_jsxs("section", { className: "grid gap-xs", "aria-label": "Replies not delivered", children: [_jsx(DataListHeading, { level: 3, className: "tourtois-conversations-heading", children: "Not delivered" }), _jsx(DataList, { density: "compact", "aria-label": "Replies not delivered", children: undelivered.data.map((problem) => (_jsx(DataRow, { children: _jsxs("div", { className: "tourtois-conversation", children: [_jsxs("div", { className: "tourtois-conversation-row", children: [_jsx("span", { className: "tourtois-conversation-name text-sm", children: problem.label }), _jsx("span", { className: "text-sm", children: channelWhen(problem.at, Date.now()) })] }), _jsx("p", { className: "text-sm", children: problem.reason })] }) }, problem.id))) })] })) : null] }));
|
|
44
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { type WebsiteConversation, type WebsiteTranscript } from "@fungi.computer/nacre/website-channels";
|
|
3
|
+
/** An Agent a Discord application can be bound to. */
|
|
4
|
+
export type DiscordAgent = Readonly<{
|
|
5
|
+
agentId: string;
|
|
6
|
+
name: string;
|
|
7
|
+
}>;
|
|
8
|
+
declare const discordBindingWire: z.ZodObject<{
|
|
9
|
+
bindingId: z.ZodString;
|
|
10
|
+
agentId: z.ZodString;
|
|
11
|
+
selector: z.ZodObject<{
|
|
12
|
+
provider: z.ZodLiteral<"discord">;
|
|
13
|
+
applicationId: z.ZodString;
|
|
14
|
+
publicKey: z.ZodString;
|
|
15
|
+
guildIds: z.ZodArray<z.ZodString>;
|
|
16
|
+
channelIds: z.ZodArray<z.ZodString>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
lifecycle: z.ZodEnum<{
|
|
19
|
+
active: "active";
|
|
20
|
+
suspended: "suspended";
|
|
21
|
+
}>;
|
|
22
|
+
authorityVersion: z.ZodNumber;
|
|
23
|
+
persona: z.ZodString;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
/** One Discord application bound to an Agent; the bot token never comes back. */
|
|
26
|
+
export type DiscordBinding = z.infer<typeof discordBindingWire>;
|
|
27
|
+
/** Everything one host knows about its Discord applications. */
|
|
28
|
+
export type DiscordDirectory = Readonly<{
|
|
29
|
+
/** The host's own address, where Discord posts its interactions. */
|
|
30
|
+
interactionsOrigin: string;
|
|
31
|
+
agents: readonly DiscordAgent[];
|
|
32
|
+
bindings: readonly DiscordBinding[];
|
|
33
|
+
}>;
|
|
34
|
+
/** A new Discord application: its Agent, identity, token, places and brief. */
|
|
35
|
+
export type NewDiscord = Readonly<{
|
|
36
|
+
agentId: string;
|
|
37
|
+
applicationId: string;
|
|
38
|
+
publicKey: string;
|
|
39
|
+
botToken: string;
|
|
40
|
+
guildIds: readonly string[];
|
|
41
|
+
channelIds: readonly string[];
|
|
42
|
+
persona: string;
|
|
43
|
+
}>;
|
|
44
|
+
/** What an owner may change about one Discord application. */
|
|
45
|
+
export type DiscordChange = Readonly<{
|
|
46
|
+
lifecycle?: "active" | "suspended";
|
|
47
|
+
botToken?: string;
|
|
48
|
+
}>;
|
|
49
|
+
/** Which guilds took `/ask` and which Discord refused. */
|
|
50
|
+
export type DiscordCommandResult = Readonly<{
|
|
51
|
+
registered: readonly string[];
|
|
52
|
+
failed: readonly string[];
|
|
53
|
+
}>;
|
|
54
|
+
/** Host-supplied owner controls over its Discord applications. */
|
|
55
|
+
export type DiscordChannelsPort = Readonly<{
|
|
56
|
+
/** Names this host's data; two hosts never share a cache entry. */
|
|
57
|
+
scope: string;
|
|
58
|
+
read(): Promise<DiscordDirectory>;
|
|
59
|
+
create(input: NewDiscord, requestId: string): Promise<DiscordBinding>;
|
|
60
|
+
update(bindingId: string, expectedVersion: number, change: DiscordChange): Promise<DiscordBinding>;
|
|
61
|
+
registerCommands(bindingId: string): Promise<DiscordCommandResult>;
|
|
62
|
+
conversations(binding: DiscordBinding): Promise<readonly WebsiteConversation[]>;
|
|
63
|
+
transcript(binding: DiscordBinding, sessionId: string): Promise<WebsiteTranscript>;
|
|
64
|
+
/** Replies the Agent owed this application's members and could not deliver. */
|
|
65
|
+
undelivered(binding: DiscordBinding): Promise<readonly DiscordUndelivered[]>;
|
|
66
|
+
}>;
|
|
67
|
+
/** One reply that never reached Discord; the member is named, never numbered. */
|
|
68
|
+
export type DiscordUndelivered = Readonly<{
|
|
69
|
+
interactionId: string;
|
|
70
|
+
label: string;
|
|
71
|
+
state: "expired" | "failed";
|
|
72
|
+
closedAt: number;
|
|
73
|
+
}>;
|
|
74
|
+
/** Bind owner Discord controls to this trusted shell's own host. */
|
|
75
|
+
export declare function createOysterDiscordChannelsPort(origin: URL): DiscordChannelsPort;
|
|
76
|
+
/**
|
|
77
|
+
* Owner Settings for Discord: bring your own Discord application, choose the
|
|
78
|
+
* Agent members talk to, add `/ask` to your servers and pause it. Sits under
|
|
79
|
+
* the Website section of Channels, in the same shape.
|
|
80
|
+
*/
|
|
81
|
+
export declare function DiscordChannels({ port }: {
|
|
82
|
+
port: DiscordChannelsPort;
|
|
83
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { AppError } from "@fungi.computer/agar";
|
|
3
|
+
import { DataList, DataListHeading, DataRow, FactRow, } from "@fungi.computer/caps/components/data-list";
|
|
4
|
+
import { Button } from "@fungi.computer/caps/components/button";
|
|
5
|
+
import { CopyField } from "@fungi.computer/caps/components/copy-field";
|
|
6
|
+
import { FormFooter } from "@fungi.computer/caps/components/field";
|
|
7
|
+
import { InlineCode } from "@fungi.computer/caps/components/inline-code";
|
|
8
|
+
import { KeycapButton } from "@fungi.computer/caps/components/keycap";
|
|
9
|
+
import { Prose } from "@fungi.computer/caps/components/prose";
|
|
10
|
+
import { Status } from "@fungi.computer/caps/components/status";
|
|
11
|
+
import { SchemaForm, field, sections, useSchemaForm, } from "@fungi.computer/caps/form";
|
|
12
|
+
import { Sigil } from "@fungi.computer/sigils";
|
|
13
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
14
|
+
import { useId, useMemo, useState } from "react";
|
|
15
|
+
import * as Option from "effect/Option";
|
|
16
|
+
import * as Schema from "effect/Schema";
|
|
17
|
+
import * as z from "zod";
|
|
18
|
+
import { websiteConversationSchema, websiteTranscriptSchema, } from "@fungi.computer/nacre/website-channels";
|
|
19
|
+
import { ChannelConversations } from "./ChannelConversations.js";
|
|
20
|
+
import { tourtoisQueryKeys } from "./queries.js";
|
|
21
|
+
import { requestIds } from "./team-directory.js";
|
|
22
|
+
const snowflake = z.string().regex(/^\d{17,20}$/u);
|
|
23
|
+
const discordBindingWire = z.object({
|
|
24
|
+
bindingId: z.string(),
|
|
25
|
+
agentId: z.string(),
|
|
26
|
+
selector: z.object({
|
|
27
|
+
provider: z.literal("discord"),
|
|
28
|
+
applicationId: snowflake,
|
|
29
|
+
publicKey: z.string(),
|
|
30
|
+
guildIds: z.array(snowflake),
|
|
31
|
+
channelIds: z.array(snowflake),
|
|
32
|
+
}),
|
|
33
|
+
lifecycle: z.enum(["active", "suspended"]),
|
|
34
|
+
authorityVersion: z.number().int().positive(),
|
|
35
|
+
persona: z.string(),
|
|
36
|
+
});
|
|
37
|
+
function parseIds(text, what, least) {
|
|
38
|
+
const entries = text.split(/[\s,]+/u).filter(Boolean);
|
|
39
|
+
if (entries.length < least)
|
|
40
|
+
return { kind: "invalid", message: `Enter at least one ${what} ID.` };
|
|
41
|
+
const ids = [];
|
|
42
|
+
for (const entry of entries) {
|
|
43
|
+
if (!snowflake.safeParse(entry).success)
|
|
44
|
+
return {
|
|
45
|
+
kind: "invalid",
|
|
46
|
+
message: `“${entry}” is not a Discord ID. It is 17 to 20 digits.`,
|
|
47
|
+
};
|
|
48
|
+
if (!ids.includes(entry))
|
|
49
|
+
ids.push(entry);
|
|
50
|
+
}
|
|
51
|
+
return { kind: "parsed", ids };
|
|
52
|
+
}
|
|
53
|
+
const directoryWire = z.object({
|
|
54
|
+
interactionsOrigin: z.url(),
|
|
55
|
+
agents: z.array(z.object({ agentId: z.string(), name: z.string() })),
|
|
56
|
+
discords: z.array(discordBindingWire),
|
|
57
|
+
});
|
|
58
|
+
const bindingChange = z.object({ binding: discordBindingWire });
|
|
59
|
+
const commandResult = z.object({
|
|
60
|
+
registered: z.array(snowflake),
|
|
61
|
+
failed: z.array(snowflake),
|
|
62
|
+
});
|
|
63
|
+
const decodeRefusal = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Struct({ error: Schema.String })));
|
|
64
|
+
const undeliveredList = z.object({
|
|
65
|
+
undelivered: z.array(z.object({
|
|
66
|
+
interactionId: z.string(),
|
|
67
|
+
label: z.string(),
|
|
68
|
+
state: z.enum(["expired", "failed"]),
|
|
69
|
+
closedAt: z.number(),
|
|
70
|
+
})),
|
|
71
|
+
});
|
|
72
|
+
const conversationList = z.object({
|
|
73
|
+
conversations: z.array(websiteConversationSchema),
|
|
74
|
+
});
|
|
75
|
+
const refusalText = new Map([
|
|
76
|
+
["application_taken", "That Discord application is already bound."],
|
|
77
|
+
["not_found", "That Agent or Discord application was not found."],
|
|
78
|
+
["version_conflict", "It changed elsewhere. Reload, then try again."],
|
|
79
|
+
["invalid_input", "Check the IDs, key and bot token, then try again."],
|
|
80
|
+
[
|
|
81
|
+
"custody_unavailable",
|
|
82
|
+
"This Oyster has no credential key, so it cannot store a bot token.",
|
|
83
|
+
],
|
|
84
|
+
["limit", "This Oyster holds as many sealed credentials as it can."],
|
|
85
|
+
]);
|
|
86
|
+
/** The owner-readable reason a refusal body names, if it names one we know. */
|
|
87
|
+
async function refusalOf(response) {
|
|
88
|
+
const decoded = decodeRefusal(await response.text());
|
|
89
|
+
return Option.isSome(decoded)
|
|
90
|
+
? refusalText.get(decoded.value.error)
|
|
91
|
+
: undefined;
|
|
92
|
+
}
|
|
93
|
+
async function request(url, init) {
|
|
94
|
+
const response = await fetch(url, {
|
|
95
|
+
...init,
|
|
96
|
+
headers: {
|
|
97
|
+
Accept: "application/json",
|
|
98
|
+
"Content-Type": "application/json",
|
|
99
|
+
...Object.fromEntries(new Headers(init?.headers)),
|
|
100
|
+
},
|
|
101
|
+
credentials: "same-origin",
|
|
102
|
+
cache: "no-store",
|
|
103
|
+
redirect: "error",
|
|
104
|
+
});
|
|
105
|
+
if (!response.ok) {
|
|
106
|
+
throw new AppError((await refusalOf(response)) ??
|
|
107
|
+
`Discord request refused (${String(response.status)}).`, {
|
|
108
|
+
code: response.status === 401 || response.status === 403
|
|
109
|
+
? "CAPABILITY_DENIED"
|
|
110
|
+
: "HOST_FAILURE",
|
|
111
|
+
retryable: response.status >= 500,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return response;
|
|
115
|
+
}
|
|
116
|
+
/** Bind owner Discord controls to this trusted shell's own host. */
|
|
117
|
+
export function createOysterDiscordChannelsPort(origin) {
|
|
118
|
+
const send = (path, init) => request(new URL(path, origin), init);
|
|
119
|
+
const binding = (bindingId) => `/api/discord/${encodeURIComponent(bindingId)}`;
|
|
120
|
+
return {
|
|
121
|
+
scope: origin.origin,
|
|
122
|
+
read: async () => {
|
|
123
|
+
const wire = directoryWire.parse(await (await send("/api/discord")).json());
|
|
124
|
+
return {
|
|
125
|
+
interactionsOrigin: wire.interactionsOrigin,
|
|
126
|
+
agents: wire.agents,
|
|
127
|
+
bindings: wire.discords,
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
create: async (input, requestId) => {
|
|
131
|
+
const response = await send("/api/discord", {
|
|
132
|
+
method: "POST",
|
|
133
|
+
headers: { "x-request-id": requestId },
|
|
134
|
+
body: JSON.stringify(input),
|
|
135
|
+
});
|
|
136
|
+
return bindingChange.parse(await response.json()).binding;
|
|
137
|
+
},
|
|
138
|
+
update: async (bindingId, expectedVersion, change) => {
|
|
139
|
+
const response = await send(binding(bindingId), {
|
|
140
|
+
method: "PUT",
|
|
141
|
+
body: JSON.stringify({ expectedVersion, ...change }),
|
|
142
|
+
});
|
|
143
|
+
return bindingChange.parse(await response.json()).binding;
|
|
144
|
+
},
|
|
145
|
+
registerCommands: async (bindingId) => commandResult.parse(await (await send(`${binding(bindingId)}/commands`, { method: "POST" })).json()),
|
|
146
|
+
conversations: async ({ bindingId }) => conversationList.parse(await (await send(`${binding(bindingId)}/conversations`)).json()).conversations,
|
|
147
|
+
undelivered: async ({ bindingId }) => undeliveredList.parse(await (await send(`${binding(bindingId)}/undelivered`)).json()).undelivered,
|
|
148
|
+
transcript: async ({ bindingId }, sessionId) => websiteTranscriptSchema.parse(await (await send(`${binding(bindingId)}/conversations/${encodeURIComponent(sessionId)}`)).json()),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const portalUrl = "https://discord.com/developers/applications";
|
|
152
|
+
/**
|
|
153
|
+
* Owner Settings for Discord: bring your own Discord application, choose the
|
|
154
|
+
* Agent members talk to, add `/ask` to your servers and pause it. Sits under
|
|
155
|
+
* the Website section of Channels, in the same shape.
|
|
156
|
+
*/
|
|
157
|
+
export function DiscordChannels({ port }) {
|
|
158
|
+
const directory = useQuery({
|
|
159
|
+
queryKey: tourtoisQueryKeys.discordChannels(port.scope),
|
|
160
|
+
retry: false,
|
|
161
|
+
queryFn: () => port.read(),
|
|
162
|
+
});
|
|
163
|
+
const [adding, setAdding] = useState(false);
|
|
164
|
+
const [createdBinding, setCreatedBinding] = useState(null);
|
|
165
|
+
const [openBinding, setOpenBinding] = useState(null);
|
|
166
|
+
const agents = directory.data?.agents ?? [];
|
|
167
|
+
return (_jsxs("section", { className: "tourtois-websites grid gap-md", "aria-label": "Discord", children: [_jsxs("header", { className: "grid gap-xs", children: [_jsx(DataListHeading, { level: 3, children: "Discord" }), _jsxs("p", { className: "text-sm", children: ["Let people in your Discord server talk to one of your Agents. You bring your own Discord application; Fungi holds no Discord account. Members type ", _jsx(InlineCode, { children: "/ask" }), ", and the Agent answers in the channel."] })] }), directory.isPending ? _jsx("p", { role: "status", children: "Loading Discord\u2026" }) : null, directory.isError ? (_jsxs("div", { role: "alert", children: [_jsx("p", { children: "Discord could not be loaded. Your saved settings have not changed." }), _jsx(Button, { onClick: () => {
|
|
168
|
+
void directory.refetch();
|
|
169
|
+
}, children: "Retry Discord" })] })) : null, directory.data ? (_jsxs(_Fragment, { children: [directory.data.bindings.length > 0 ? (_jsx(DataList, { "aria-label": "Saved Discord applications", children: directory.data.bindings.map((binding) => (_jsx(DiscordRow, { port: port, binding: binding, interactionsOrigin: directory.data.interactionsOrigin, open: openBinding === binding.bindingId, justCreated: createdBinding === binding.bindingId, onOpenChange: (open) => {
|
|
170
|
+
setOpenBinding(open ? binding.bindingId : null);
|
|
171
|
+
}, agentName: agents.find((agent) => agent.agentId === binding.agentId)
|
|
172
|
+
?.name ?? "Unavailable Agent" }, binding.bindingId))) })) : adding ? null : (_jsx("p", { className: "text-sm", children: "No Discord applications yet." })), adding ? (_jsx(AddDiscord, { port: port, agents: agents, onDone: (bindingId) => {
|
|
173
|
+
setAdding(false);
|
|
174
|
+
if (bindingId) {
|
|
175
|
+
setOpenBinding(bindingId);
|
|
176
|
+
setCreatedBinding(bindingId);
|
|
177
|
+
}
|
|
178
|
+
} })) : agents.length === 0 ? (_jsx("p", { className: "text-sm", children: "Create an Agent first; Discord needs one to answer members." })) : (_jsx("div", { className: "flex justify-end", children: _jsx(Button, { variant: directory.data.bindings.length === 0 ? "primary" : "outline", onClick: () => {
|
|
179
|
+
setAdding(true);
|
|
180
|
+
}, children: directory.data.bindings.length === 0
|
|
181
|
+
? "Add Discord"
|
|
182
|
+
: "Add another application" }) }))] })) : null] }));
|
|
183
|
+
}
|
|
184
|
+
function AddDiscord({ port, agents, onDone, }) {
|
|
185
|
+
const cache = useQueryClient();
|
|
186
|
+
const schema = useMemo(() => z
|
|
187
|
+
.object({
|
|
188
|
+
agentId: z.string().meta(field({
|
|
189
|
+
label: "Agent",
|
|
190
|
+
help: "Members talk to this Agent.",
|
|
191
|
+
kind: "select",
|
|
192
|
+
section: "discord",
|
|
193
|
+
options: Object.fromEntries(agents.map((agent) => [agent.agentId, agent.name])),
|
|
194
|
+
})),
|
|
195
|
+
applicationId: snowflake.meta(field({
|
|
196
|
+
label: "Application ID",
|
|
197
|
+
help: "From General Information in the Discord developer portal.",
|
|
198
|
+
placeholder: "1234567890123456789",
|
|
199
|
+
required: true,
|
|
200
|
+
section: "discord",
|
|
201
|
+
})),
|
|
202
|
+
publicKey: z
|
|
203
|
+
.string()
|
|
204
|
+
.regex(/^[0-9a-fA-F]{64}$/u, "Paste the 64-character public key")
|
|
205
|
+
.meta(field({
|
|
206
|
+
label: "Public key",
|
|
207
|
+
help: "Also on General Information. Discord signs every request with it.",
|
|
208
|
+
required: true,
|
|
209
|
+
section: "discord",
|
|
210
|
+
})),
|
|
211
|
+
botToken: z
|
|
212
|
+
.string()
|
|
213
|
+
.min(1, "Paste the bot token")
|
|
214
|
+
.max(256)
|
|
215
|
+
.meta(field({
|
|
216
|
+
label: "Bot token",
|
|
217
|
+
icon: _jsx(Sigil, { name: "restricted" }),
|
|
218
|
+
help: "From Bot in the developer portal. Sealed on this instance and never shown again.",
|
|
219
|
+
kind: "secret",
|
|
220
|
+
required: true,
|
|
221
|
+
section: "discord",
|
|
222
|
+
})),
|
|
223
|
+
guilds: z
|
|
224
|
+
.string()
|
|
225
|
+
.transform((text, context) => {
|
|
226
|
+
const parsed = parseIds(text, "server", 1);
|
|
227
|
+
if (parsed.kind === "parsed")
|
|
228
|
+
return parsed.ids;
|
|
229
|
+
context.addIssue({ code: "custom", message: parsed.message });
|
|
230
|
+
return z.NEVER;
|
|
231
|
+
})
|
|
232
|
+
.meta(field({
|
|
233
|
+
label: "Server IDs",
|
|
234
|
+
help: "Turn on Developer Mode in Discord, then right-click your server and Copy Server ID. Separate more than one with commas.",
|
|
235
|
+
placeholder: "2345678901234567890",
|
|
236
|
+
required: true,
|
|
237
|
+
section: "discord",
|
|
238
|
+
})),
|
|
239
|
+
channels: z
|
|
240
|
+
.string()
|
|
241
|
+
.transform((text, context) => {
|
|
242
|
+
const parsed = parseIds(text, "channel", 0);
|
|
243
|
+
if (parsed.kind === "parsed")
|
|
244
|
+
return parsed.ids;
|
|
245
|
+
context.addIssue({ code: "custom", message: parsed.message });
|
|
246
|
+
return z.NEVER;
|
|
247
|
+
})
|
|
248
|
+
.meta(field({
|
|
249
|
+
label: "Channel IDs",
|
|
250
|
+
help: "Leave empty to answer in every channel of those servers.",
|
|
251
|
+
optional: true,
|
|
252
|
+
section: "discord",
|
|
253
|
+
})),
|
|
254
|
+
persona: z
|
|
255
|
+
.string()
|
|
256
|
+
.max(4_000)
|
|
257
|
+
.meta(field({
|
|
258
|
+
label: "What should the Agent do here?",
|
|
259
|
+
help: "Its brief for Discord. Members don't see it.",
|
|
260
|
+
kind: "textarea",
|
|
261
|
+
optional: true,
|
|
262
|
+
rows: 3,
|
|
263
|
+
maxLength: 4_000,
|
|
264
|
+
placeholder: "Answer questions about our community.",
|
|
265
|
+
section: "discord",
|
|
266
|
+
})),
|
|
267
|
+
})
|
|
268
|
+
.meta(sections({
|
|
269
|
+
discord: {
|
|
270
|
+
title: "Add a Discord application",
|
|
271
|
+
description: "Create an application in the Discord developer portal, add its bot to your server, then paste its details here. You get the address to give Discord next.",
|
|
272
|
+
},
|
|
273
|
+
})), [agents]);
|
|
274
|
+
const create = useMutation({
|
|
275
|
+
mutationFn: (input) => port.create({
|
|
276
|
+
agentId: input.agentId,
|
|
277
|
+
applicationId: input.applicationId,
|
|
278
|
+
publicKey: input.publicKey,
|
|
279
|
+
botToken: input.botToken,
|
|
280
|
+
guildIds: input.guildIds,
|
|
281
|
+
channelIds: input.channelIds,
|
|
282
|
+
persona: input.persona,
|
|
283
|
+
}, input.requestId),
|
|
284
|
+
onSuccess: async (binding) => {
|
|
285
|
+
await cache.invalidateQueries({
|
|
286
|
+
queryKey: tourtoisQueryKeys.discordChannels(port.scope),
|
|
287
|
+
});
|
|
288
|
+
onDone(binding.bindingId);
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
const model = useSchemaForm({
|
|
292
|
+
schema,
|
|
293
|
+
defaultValues: {
|
|
294
|
+
agentId: agents[0]?.agentId ?? "",
|
|
295
|
+
applicationId: "",
|
|
296
|
+
publicKey: "",
|
|
297
|
+
botToken: "",
|
|
298
|
+
guilds: "",
|
|
299
|
+
channels: "",
|
|
300
|
+
persona: "",
|
|
301
|
+
},
|
|
302
|
+
onSubmit: async (value) => {
|
|
303
|
+
try {
|
|
304
|
+
await create.mutateAsync({
|
|
305
|
+
requestId: requestIds.request.generate(),
|
|
306
|
+
agentId: value.agentId,
|
|
307
|
+
applicationId: value.applicationId,
|
|
308
|
+
publicKey: value.publicKey,
|
|
309
|
+
botToken: value.botToken,
|
|
310
|
+
guildIds: value.guilds,
|
|
311
|
+
channelIds: value.channels,
|
|
312
|
+
persona: value.persona,
|
|
313
|
+
});
|
|
314
|
+
return { kind: "saved" };
|
|
315
|
+
}
|
|
316
|
+
catch (cause) {
|
|
317
|
+
return {
|
|
318
|
+
kind: "refused",
|
|
319
|
+
error: cause instanceof Error
|
|
320
|
+
? cause.message
|
|
321
|
+
: "Discord could not be added. Try the saved request again.",
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
return (_jsx(SchemaForm, { model: model, layout: "columns", "aria-label": "Add a Discord application", disabled: create.isPending, footer: _jsxs(FormFooter, { error: create.error?.message ?? model.error, children: [_jsx(Button, { type: "button", variant: "ghost", onClick: () => {
|
|
327
|
+
onDone(null);
|
|
328
|
+
}, children: "Cancel" }), create.isError ? (_jsx(Button, { type: "button", variant: "outline", onClick: () => {
|
|
329
|
+
create.mutate(create.variables);
|
|
330
|
+
}, children: "Retry saved request" })) : null, _jsx(Button, { type: "submit", children: create.isPending ? "Adding Discord…" : "Add Discord" })] }) }));
|
|
331
|
+
}
|
|
332
|
+
function DiscordRow({ port, binding, interactionsOrigin, agentName, open, justCreated, onOpenChange, }) {
|
|
333
|
+
const cache = useQueryClient();
|
|
334
|
+
const guideId = useId();
|
|
335
|
+
const key = tourtoisQueryKeys.discordChannels(port.scope);
|
|
336
|
+
const patch = useMutation({
|
|
337
|
+
// Edits queue per application; each sends the last version the host acknowledged.
|
|
338
|
+
scope: { id: JSON.stringify([port.scope, binding.bindingId]) },
|
|
339
|
+
mutationFn: (change) => {
|
|
340
|
+
const current = cache
|
|
341
|
+
.getQueryData(key)
|
|
342
|
+
?.bindings.find((item) => item.bindingId === binding.bindingId);
|
|
343
|
+
if (!current)
|
|
344
|
+
throw new Error("Discord unavailable. Reload before changing it.");
|
|
345
|
+
return port.update(binding.bindingId, current.authorityVersion, change);
|
|
346
|
+
},
|
|
347
|
+
onSettled: () => cache.invalidateQueries({ queryKey: key }),
|
|
348
|
+
});
|
|
349
|
+
const register = useMutation({
|
|
350
|
+
mutationFn: () => port.registerCommands(binding.bindingId),
|
|
351
|
+
});
|
|
352
|
+
const { applicationId, guildIds, channelIds } = binding.selector;
|
|
353
|
+
const endpoint = `${interactionsOrigin}/api/discord/interactions/${binding.bindingId}`;
|
|
354
|
+
const active = binding.lifecycle === "active";
|
|
355
|
+
const places = channelIds.length === 0
|
|
356
|
+
? `all channels in ${String(guildIds.length)} ${guildIds.length === 1 ? "server" : "servers"}`
|
|
357
|
+
: `${String(channelIds.length)} ${channelIds.length === 1 ? "channel" : "channels"}`;
|
|
358
|
+
return (_jsx(DataRow, { children: _jsxs("div", { className: "tourtois-connector-row grid gap-md", children: [_jsxs("div", { className: "tourtois-website-summary", children: [_jsx(Sigil, { name: "agent", size: 28 }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx(DataListHeading, { level: 3, children: agentName }), _jsx("p", { className: "tourtois-website-hosts text-sm", children: places })] }), _jsx(Status, { appearance: "chip", label: active ? "Active" : "Paused", size: "compact", tone: active ? "success" : "neutral" }), _jsx(Button, { variant: "outline", size: "sm", "aria-controls": guideId, "aria-expanded": open, "aria-label": `${open ? "Close" : "Set up"} ${agentName} on Discord`, onClick: () => {
|
|
359
|
+
onOpenChange(!open);
|
|
360
|
+
}, children: open ? "Close" : "Set up" })] }), open ? (_jsxs("div", { className: "tourtois-connector-row-details tourtois-website-guide", id: guideId, children: [_jsxs(Prose, { className: "tourtois-website-doc", children: [_jsx("h4", { children: justCreated ? "Finish setting up Discord" : "Connect Discord" }), _jsxs("ol", { children: [_jsxs("li", { children: [_jsxs("p", { children: [_jsx("strong", { children: "Copy this address." }), " In the", " ", _jsx("a", { href: portalUrl, children: "Discord developer portal" }), ", open your application, paste it into Interactions Endpoint URL on General Information and save. Discord checks it at once."] }), _jsx(CopyField, { layout: "block", title: "URL", label: "Copy address", tokens: [{ kind: "string", text: endpoint }], "aria-label": `Interactions endpoint for ${agentName}` })] }), _jsx("li", { children: _jsxs("p", { children: [_jsx("strong", { children: "Add the bot to your server" }), " from OAuth2 in the portal, with the ", _jsx(InlineCode, { children: "bot" }), " and", " ", _jsx(InlineCode, { children: "applications.commands" }), " scopes. It needs no other permission."] }) }), _jsxs("li", { children: [_jsxs("p", { children: [_jsx("strong", { children: "Add the command." }), " This puts", " ", _jsx(InlineCode, { children: "/ask" }), " in your server."] }), _jsxs("span", { className: "tourtois-website-fact", children: [_jsx(KeycapButton, { density: "compact", label: register.isPending
|
|
361
|
+
? "Adding /ask…"
|
|
362
|
+
: "Add /ask to Discord", disabled: register.isPending, onClick: () => {
|
|
363
|
+
register.mutate();
|
|
364
|
+
} }), register.data ? (_jsx(Status, { glyph: "dot", tone: register.data.failed.length === 0
|
|
365
|
+
? "success"
|
|
366
|
+
: "warning", label: register.data.failed.length === 0
|
|
367
|
+
? `Added to ${String(register.data.registered.length)} ${register.data.registered.length === 1 ? "server" : "servers"}`
|
|
368
|
+
: `Discord refused ${String(register.data.failed.length)} of ${String(register.data.failed.length + register.data.registered.length)}. Check the bot is in that server.` })) : null] })] }), _jsx("li", { children: _jsxs("p", { children: [_jsx("strong", { children: "Try it." }), " Type ", _jsx(InlineCode, { children: "/ask" }), " ", "in a channel. ", agentName, " answers there, with a Reply button to carry on."] }) })] }), _jsx("h4", { children: "What members can trigger" }), _jsxs("p", { children: ["Members talk to ", agentName, " itself, with ", agentName, "\u2019s own tools and permissions. They cannot sign in to this Oyster or reach your account. The server and channel list limits where it answers, not who can use it there."] })] }), _jsxs(DataList, { density: "compact", "aria-label": `Discord status for ${agentName}`, children: [_jsx(FactRow, { icon: _jsx(Sigil, { name: "agent" }), label: "Agent", children: agentName }), _jsx(FactRow, { icon: _jsx(Sigil, { name: "internet" }), label: "Application ID", children: _jsx(InlineCode, { children: applicationId }) }), _jsx(FactRow, { icon: _jsx(Sigil, { name: "chat" }), label: active ? "Discord is live" : "Discord is paused", children: _jsxs("span", { className: "tourtois-website-fact", children: [_jsx("span", { className: "text-sm", children: active
|
|
369
|
+
? "Pause to stop answering without removing the setup."
|
|
370
|
+
: "Members get a notice until you resume it." }), _jsx(KeycapButton, { density: "compact", label: active ? "Pause Discord" : "Resume Discord", disabled: patch.isPending, onClick: () => {
|
|
371
|
+
patch.mutate({
|
|
372
|
+
lifecycle: active ? "suspended" : "active",
|
|
373
|
+
});
|
|
374
|
+
} })] }) })] }), patch.isError ? _jsx("p", { role: "alert", children: patch.error.message }) : null, register.isError ? (_jsx("p", { role: "alert", children: register.error.message })) : null, _jsx(ChannelConversations, { keys: {
|
|
375
|
+
list: tourtoisQueryKeys.discordConversations(port.scope, binding.bindingId),
|
|
376
|
+
transcript: (sessionId) => tourtoisQueryKeys.discordTranscript(port.scope, binding.bindingId, sessionId),
|
|
377
|
+
}, load: () => port.conversations(binding), read: (sessionId) => port.transcript(binding, sessionId), problems: {
|
|
378
|
+
key: tourtoisQueryKeys.discordUndelivered(port.scope, binding.bindingId),
|
|
379
|
+
load: async () => (await port.undelivered(binding)).map((reply) => ({
|
|
380
|
+
id: reply.interactionId,
|
|
381
|
+
label: reply.label,
|
|
382
|
+
at: reply.closedAt,
|
|
383
|
+
reason: reply.state === "failed"
|
|
384
|
+
? "Discord kept refusing the answer, so it never arrived."
|
|
385
|
+
: "The answer was not ready before Discord's reply window closed.",
|
|
386
|
+
})),
|
|
387
|
+
}, speaker: "Member", empty: "No one has asked yet.", label: "Discord conversations" })] })) : null] }) }));
|
|
388
|
+
}
|
package/dist/WebsiteChannels.js
CHANGED
|
@@ -16,6 +16,7 @@ import { Sigil } from "@fungi.computer/sigils";
|
|
|
16
16
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
17
17
|
import { useId, useMemo, useState } from "react";
|
|
18
18
|
import * as z from "zod";
|
|
19
|
+
import { ChannelConversations } from "./ChannelConversations.js";
|
|
19
20
|
import { tourtoisQueryKeys } from "./queries.js";
|
|
20
21
|
import { requestIds } from "./team-directory.js";
|
|
21
22
|
const exampleAddress = "https://example.com";
|
|
@@ -340,33 +341,8 @@ function WebsiteRow({ port, copy, site, notice, embedOrigin, agentName, open, ju
|
|
|
340
341
|
setConfirmingKey(false);
|
|
341
342
|
} })] })) : (_jsx(KeycapButton, { density: "compact", label: "New site key", disabled: patch.isPending, onClick: () => {
|
|
342
343
|
setConfirmingKey(true);
|
|
343
|
-
} }))] }) })] }), notice, patch.isError ? _jsx("p", { role: "alert", children: patch.error.message }) : null, _jsx(
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const [shown, setShown] = useState(false);
|
|
348
|
-
const [reading, setReading] = useState(null);
|
|
349
|
-
const list = useQuery({
|
|
350
|
-
queryKey: tourtoisQueryKeys.websiteConversations(port.scope, bindingId),
|
|
351
|
-
enabled: shown,
|
|
352
|
-
retry: false,
|
|
353
|
-
queryFn: () => port.conversations(site),
|
|
354
|
-
});
|
|
355
|
-
const transcript = useQuery({
|
|
356
|
-
queryKey: tourtoisQueryKeys.websiteTranscript(port.scope, bindingId, reading ?? ""),
|
|
357
|
-
enabled: reading !== null,
|
|
358
|
-
retry: false,
|
|
359
|
-
queryFn: () => reading === null
|
|
360
|
-
? Promise.reject(new Error("No conversation is open"))
|
|
361
|
-
: port.transcript(site, reading),
|
|
362
|
-
});
|
|
363
|
-
return (_jsxs("section", { className: "grid gap-sm", "aria-label": "Conversations", children: [_jsx(DataListHeading, { level: 3, children: "Conversations" }), shown ? null : (_jsx(KeycapButton, { density: "compact", label: "Show conversations", onClick: () => {
|
|
364
|
-
setShown(true);
|
|
365
|
-
} })), list.isPending && shown ? _jsx("p", { role: "status", children: "Loading\u2026" }) : null, list.isError ? (_jsx("p", { role: "alert", children: "Conversations could not be loaded." })) : null, list.data?.length === 0 ? (_jsx("p", { className: "text-sm", children: "No visitor has written yet." })) : null, list.data !== undefined && list.data.length > 0 ? (_jsx(DataList, { density: "compact", "aria-label": "Website conversations", children: list.data.map((conversation) => (_jsx(FactRow, { label: conversation.label, children: _jsxs("span", { className: "flex flex-wrap items-center gap-sm", children: [_jsx("span", { className: "text-sm", children: new Date(conversation.lastEventAt).toLocaleString() }), _jsx(KeycapButton, { density: "compact", label: reading === conversation.sessionId
|
|
366
|
-
? "Close transcript"
|
|
367
|
-
: "Read transcript", "aria-label": `${reading === conversation.sessionId ? "Close" : "Read"} transcript of ${conversation.label}`, onClick: () => {
|
|
368
|
-
setReading(reading === conversation.sessionId
|
|
369
|
-
? null
|
|
370
|
-
: conversation.sessionId);
|
|
371
|
-
} })] }) }, conversation.sessionId))) })) : null, reading !== null && transcript.isPending ? (_jsx("p", { role: "status", children: "Loading\u2026" })) : null, transcript.isError ? (_jsx("p", { role: "alert", children: "This conversation could not be read." })) : null, reading !== null && transcript.data ? (_jsx("ol", { "aria-label": "Transcript", className: "grid gap-xs", children: transcript.data.lines.map((line, index) => (_jsxs("li", { className: "text-sm", children: [_jsxs("strong", { children: [line.role === "visitor" ? "Visitor" : "Agent", ":"] }), " ", line.text] }, `${String(index)}-${line.role}`))) })) : null] }));
|
|
344
|
+
} }))] }) })] }), notice, patch.isError ? _jsx("p", { role: "alert", children: patch.error.message }) : null, _jsx(ChannelConversations, { keys: {
|
|
345
|
+
list: tourtoisQueryKeys.websiteConversations(port.scope, site.bindingId),
|
|
346
|
+
transcript: (sessionId) => tourtoisQueryKeys.websiteTranscript(port.scope, site.bindingId, sessionId),
|
|
347
|
+
}, load: () => port.conversations(site), read: (sessionId) => port.transcript(site, sessionId), speaker: "Visitor", empty: "No visitor has written yet.", label: "Website conversations" })] })) : null] }) }));
|
|
372
348
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When a channel conversation last moved, for the owner: `Today, 7:30 PM`,
|
|
3
|
+
* `Yesterday, 10:05 AM`, `Nov 9, 10:05 AM`, and with the year only when it is
|
|
4
|
+
* not this one. No seconds; the time of day follows the owner's locale.
|
|
5
|
+
*/
|
|
6
|
+
export declare function channelWhen(epochMillis: number, now: number): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const dayStart = (date) => new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
|
|
2
|
+
const clock = new Intl.DateTimeFormat(undefined, {
|
|
3
|
+
hour: "numeric",
|
|
4
|
+
minute: "2-digit",
|
|
5
|
+
});
|
|
6
|
+
const monthDay = new Intl.DateTimeFormat(undefined, {
|
|
7
|
+
month: "short",
|
|
8
|
+
day: "numeric",
|
|
9
|
+
});
|
|
10
|
+
const monthDayYear = new Intl.DateTimeFormat(undefined, {
|
|
11
|
+
month: "short",
|
|
12
|
+
day: "numeric",
|
|
13
|
+
year: "numeric",
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* When a channel conversation last moved, for the owner: `Today, 7:30 PM`,
|
|
17
|
+
* `Yesterday, 10:05 AM`, `Nov 9, 10:05 AM`, and with the year only when it is
|
|
18
|
+
* not this one. No seconds; the time of day follows the owner's locale.
|
|
19
|
+
*/
|
|
20
|
+
export function channelWhen(epochMillis, now) {
|
|
21
|
+
const at = new Date(epochMillis);
|
|
22
|
+
const today = new Date(now);
|
|
23
|
+
const days = Math.round((dayStart(today) - dayStart(at)) / 86_400_000);
|
|
24
|
+
const time = clock.format(at);
|
|
25
|
+
if (days === 0)
|
|
26
|
+
return `Today, ${time}`;
|
|
27
|
+
if (days === 1)
|
|
28
|
+
return `Yesterday, ${time}`;
|
|
29
|
+
const date = at.getFullYear() === today.getFullYear()
|
|
30
|
+
? monthDay.format(at)
|
|
31
|
+
: monthDayYear.format(at);
|
|
32
|
+
return `${date}, ${time}`;
|
|
33
|
+
}
|
|
@@ -18,6 +18,7 @@ import { createOysterSetupPort, oysterSetupSchema } from "./oyster-setup.js";
|
|
|
18
18
|
import { modelKeysViewSchema } from "./ModelKeys.js";
|
|
19
19
|
import { settingsLocationSchema } from "./settings-routes.js";
|
|
20
20
|
import { OysterComputers, createOysterComputersPort, } from "./OysterComputers.js";
|
|
21
|
+
import { DiscordChannels, createOysterDiscordChannelsPort, } from "./DiscordChannels.js";
|
|
21
22
|
import { WebsiteChannels, createOysterWebsiteChannelsPort, } from "./WebsiteChannels.js";
|
|
22
23
|
import { useSettingsLeaveGuard, } from "./settings-leave-guard.js";
|
|
23
24
|
async function json(path) {
|
|
@@ -287,7 +288,8 @@ export const mountPlatformControls = (root, input) => {
|
|
|
287
288
|
const computersPort = createOysterComputersPort(new URL(window.location.origin));
|
|
288
289
|
const computers = () => (_jsx(OysterComputers, { teamId: input.teamId, port: computersPort, onChanged: controls.changed }));
|
|
289
290
|
const websitesPort = createOysterWebsiteChannelsPort(new URL(window.location.origin));
|
|
290
|
-
const
|
|
291
|
+
const discordPort = createOysterDiscordChannelsPort(new URL(window.location.origin));
|
|
292
|
+
const channels = () => (_jsx(WebsiteChannels, { port: websitesPort, copy: oysterWebsiteCopy, children: _jsx(DiscordChannels, { port: discordPort }) }));
|
|
291
293
|
const setup = createOysterSetupPort({
|
|
292
294
|
readFacts: async () => oysterSetupSchema.parse(await json("/api/setup")),
|
|
293
295
|
openSettings: (location) => {
|
package/dist/queries.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ export declare const tourtoisQueryKeys: {
|
|
|
6
6
|
oysterInternetAccess: (teamId: string, computerId: string) => readonly ["tourtois", "oyster-internet-access", string, string];
|
|
7
7
|
oysterKeepAwake: (teamId: string, computerId: string) => readonly ["tourtois", "oyster-keep-awake", string, string];
|
|
8
8
|
oysterEgressPolicy: (teamId: string) => readonly ["tourtois", "oyster-egress-policy", string];
|
|
9
|
+
discordChannels: (scope: string) => readonly ["tourtois", "discord-channels", string];
|
|
10
|
+
discordConversations: (scope: string, bindingId: string) => readonly ["tourtois", "discord-channels", string, string];
|
|
11
|
+
discordUndelivered: (scope: string, bindingId: string) => readonly ["tourtois", "discord-channels", string, "undelivered", string];
|
|
12
|
+
discordTranscript: (scope: string, bindingId: string, sessionId: string) => readonly ["tourtois", "discord-channels", string, string, string];
|
|
9
13
|
websiteChannels: (scope: string) => readonly ["tourtois", "website-channels", string];
|
|
10
14
|
websiteConversations: (scope: string, bindingId: string) => readonly ["tourtois", "website-channels", string, string];
|
|
11
15
|
websiteTranscript: (scope: string, bindingId: string, sessionId: string) => readonly ["tourtois", "website-channels", string, string, string];
|
package/dist/queries.js
CHANGED
|
@@ -6,6 +6,17 @@ export const tourtoisQueryKeys = {
|
|
|
6
6
|
oysterInternetAccess: (teamId, computerId) => ["tourtois", "oyster-internet-access", teamId, computerId],
|
|
7
7
|
oysterKeepAwake: (teamId, computerId) => ["tourtois", "oyster-keep-awake", teamId, computerId],
|
|
8
8
|
oysterEgressPolicy: (teamId) => ["tourtois", "oyster-egress-policy", teamId],
|
|
9
|
+
discordChannels: (scope) => ["tourtois", "discord-channels", scope],
|
|
10
|
+
discordConversations: (scope, bindingId) => [...tourtoisQueryKeys.discordChannels(scope), bindingId],
|
|
11
|
+
discordUndelivered: (scope, bindingId) => [
|
|
12
|
+
...tourtoisQueryKeys.discordChannels(scope),
|
|
13
|
+
"undelivered",
|
|
14
|
+
bindingId,
|
|
15
|
+
],
|
|
16
|
+
discordTranscript: (scope, bindingId, sessionId) => [
|
|
17
|
+
...tourtoisQueryKeys.discordConversations(scope, bindingId),
|
|
18
|
+
sessionId,
|
|
19
|
+
],
|
|
9
20
|
websiteChannels: (scope) => ["tourtois", "website-channels", scope],
|
|
10
21
|
websiteConversations: (scope, bindingId) => [...tourtoisQueryKeys.websiteChannels(scope), bindingId],
|
|
11
22
|
websiteTranscript: (scope, bindingId, sessionId) => [
|
|
@@ -129,6 +129,50 @@
|
|
|
129
129
|
min-width: 0;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
/* A conversation is one column: its line, then its transcript when open. */
|
|
133
|
+
.tourtois-conversation {
|
|
134
|
+
display: grid;
|
|
135
|
+
flex: 1;
|
|
136
|
+
grid-column: 1 / -1;
|
|
137
|
+
width: 100%;
|
|
138
|
+
min-width: 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* The Conversations and Not delivered labels sit on their rows' left edge. */
|
|
142
|
+
.tourtois-conversations-heading {
|
|
143
|
+
padding-inline: 0;
|
|
144
|
+
}
|
|
145
|
+
/* On a phone the control that reads a transcript is a full touch target. */
|
|
146
|
+
@media (max-width: 40rem) {
|
|
147
|
+
.tourtois-conversation-row button {
|
|
148
|
+
min-height: 44px;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* A conversation line: its name gets the room, its date and button wrap below
|
|
153
|
+
when the line is narrow. */
|
|
154
|
+
.tourtois-conversation-row {
|
|
155
|
+
display: flex;
|
|
156
|
+
flex-wrap: wrap;
|
|
157
|
+
align-items: center;
|
|
158
|
+
justify-content: space-between;
|
|
159
|
+
gap: var(--spacing-xs) var(--spacing-md);
|
|
160
|
+
min-width: 0;
|
|
161
|
+
}
|
|
162
|
+
/* An open transcript sits inside its own row, under the name it belongs to. */
|
|
163
|
+
.tourtois-conversation-transcript {
|
|
164
|
+
display: grid;
|
|
165
|
+
gap: var(--spacing-xs);
|
|
166
|
+
margin-top: var(--spacing-sm);
|
|
167
|
+
min-width: 0;
|
|
168
|
+
}
|
|
169
|
+
.tourtois-conversation-name {
|
|
170
|
+
flex: 1 1 12rem;
|
|
171
|
+
min-width: 0;
|
|
172
|
+
overflow-wrap: anywhere;
|
|
173
|
+
font-weight: 500;
|
|
174
|
+
}
|
|
175
|
+
|
|
132
176
|
/* The Settings panel owns scrolling; its GitHub contents retain their natural
|
|
133
177
|
height rather than shrinking the form and feedback inside the flex column. */
|
|
134
178
|
.tourtois-github-settings > * {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/tourtois",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.1",
|
|
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",
|
|
@@ -77,15 +77,15 @@
|
|
|
77
77
|
"LICENSE"
|
|
78
78
|
],
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@fungi.computer/agar": "0.
|
|
80
|
+
"@fungi.computer/agar": "0.11.0",
|
|
81
81
|
"@fungi.computer/cairn": "0.1.0",
|
|
82
82
|
"@fungi.computer/caps": "0.11.3",
|
|
83
83
|
"@fungi.computer/ear-tag": "0.1.0",
|
|
84
84
|
"@fungi.computer/gills": "0.3.0",
|
|
85
85
|
"@fungi.computer/maosaico": "0.1.2",
|
|
86
|
-
"@fungi.computer/parakeet": "0.11.
|
|
86
|
+
"@fungi.computer/parakeet": "0.11.23",
|
|
87
87
|
"@fungi.computer/puffball": "0.5.5",
|
|
88
|
-
"@fungi.computer/shiitake": "0.
|
|
88
|
+
"@fungi.computer/shiitake": "0.14.1",
|
|
89
89
|
"@fungi.computer/sigils": "0.3.1",
|
|
90
90
|
"@fungi.computer/sprite": "0.2.2",
|
|
91
91
|
"@fungi.computer/sprite-zdog": "0.3.2",
|
|
@@ -100,13 +100,13 @@
|
|
|
100
100
|
"lucide-react": "0.460.0",
|
|
101
101
|
"react-dom": "18.3.1",
|
|
102
102
|
"zod": "4.4.3",
|
|
103
|
-
"@fungi.computer/nacre": "0.5.
|
|
103
|
+
"@fungi.computer/nacre": "0.5.4"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
106
|
"react": "^18.3.1 || ^19.2.0"
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
|
-
"@fungi.computer/oyster": "0.
|
|
109
|
+
"@fungi.computer/oyster": "0.24.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",
|