@gemies/sdk 3.1.0 → 3.3.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/CHANGELOG.md +28 -0
- package/package.json +2 -1
- package/src/components/GemieAccounts.tsx +111 -23
- package/src/components/connectors/ConnectorLogo.tsx +61 -0
- package/src/components/connectors/GemieConnectedConnectors.tsx +309 -0
- package/src/components/connectors/GemieConnectorsStore.tsx +444 -0
- package/src/components/thought/ThoughtPanel.tsx +17 -4
- package/src/connectors.ts +34 -0
- package/src/lib/copy-en.ts +91 -2
- package/src/lib/copy-es.ts +96 -2
- package/src/runtime/connectors.ts +324 -0
- package/src/runtime/gemie-accounts.ts +11 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @gemies/sdk
|
|
2
2
|
|
|
3
|
+
## 3.3.0
|
|
4
|
+
|
|
5
|
+
- **New: `@gemies/sdk/connectors`**, the connectors a person connects — providers' own remote MCP
|
|
6
|
+
servers (Notion, Linear, Slack…) and their own MCP servers by URL — drawn the same in the Gemies
|
|
7
|
+
and the Alia apps:
|
|
8
|
+
- `GemieConnectorsStore`: the store, with search, categories, each connector's real logo, Connect
|
|
9
|
+
(or Add account, for a further account of the same connector) and Add a custom MCP server.
|
|
10
|
+
- `GemieConnectedConnectors`: Settings › Connected, only what the person connected, each account
|
|
11
|
+
with its state, the gemies that may use it, Reconnect, Rename and Disconnect.
|
|
12
|
+
- `ConnectorLogo`: the one logo every screen draws for a connector, loaded only from the API's
|
|
13
|
+
origin, with a monogram when there is none.
|
|
14
|
+
- `useConnectorCatalogue`, `useConnections`, `useConnectorActions`, `useWebSignInReturn`,
|
|
15
|
+
`connectionOfTool`. A web sign-in returns to `/connectors`; a native one finishes in the auth
|
|
16
|
+
session on the app's scheme (`nativeScheme`).
|
|
17
|
+
- **A connector's tool step in the thought panel shows that connector's logo**
|
|
18
|
+
(`mcp_<account>__<tool>`); the connections are read only for a turn that used one.
|
|
19
|
+
|
|
20
|
+
## 3.2.0
|
|
21
|
+
|
|
22
|
+
- **Telegram is Telegram Business (Gemies ADR 0037).** `GemieAccounts` links a person's Telegram
|
|
23
|
+
through the shared Gemies bot: a button and a code that open the bot, and the step in Telegram ›
|
|
24
|
+
Settings › Telegram Business › Chatbots. It says Telegram Premium is needed and that only private
|
|
25
|
+
chats are covered, offers no group setting for it, and shows a connection the person turned off
|
|
26
|
+
in Telegram as paused (it resumes by itself) and one moved to another gemie as revoked; nothing
|
|
27
|
+
asks to sign in again. `GEMIE_ACCOUNT_STATUSES` gains `paused`, and `GemieAccount` carries
|
|
28
|
+
`canReply` (whether Telegram lets the gemie write); the panel says when it does not. New copy
|
|
29
|
+
under `gemie.accounts.telegram.*`; `gemie.accounts.scan.telegram` is gone.
|
|
30
|
+
|
|
3
31
|
## 3.1.0
|
|
4
32
|
|
|
5
33
|
- **New: `AGENT_ROUTES` and `threadKey` from `@gemies/sdk/runtime`**, the routes and cache key of a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gemies/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "The Gemies SDK: the conversation runtime, chat UI, voice calls and dictation for Oxy apps that talk to a gemie",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"./ask/text": "./src/ask-text.ts",
|
|
15
15
|
"./avatar": "./src/avatar.ts",
|
|
16
16
|
"./character": "./src/character.ts",
|
|
17
|
+
"./connectors": "./src/connectors.ts",
|
|
17
18
|
"./content": "./src/lib/content-utils.ts",
|
|
18
19
|
"./csp": "./src/csp.ts",
|
|
19
20
|
"./dictation": "./src/dictation.ts",
|
|
@@ -14,7 +14,7 @@ import { Switch } from '@oxy.so/bloom/switch';
|
|
|
14
14
|
import { toast } from '@oxy.so/bloom/toast';
|
|
15
15
|
import { Text } from '@oxy.so/bloom/typography';
|
|
16
16
|
import { useCallback, useEffect, useState } from 'react';
|
|
17
|
-
import { View } from 'react-native';
|
|
17
|
+
import { Linking, View } from 'react-native';
|
|
18
18
|
import QRCode from 'react-native-qrcode-svg';
|
|
19
19
|
import { englishCopy, type Translate } from '../lib/copy';
|
|
20
20
|
import { errorMessage } from '../runtime/error-utils';
|
|
@@ -93,7 +93,52 @@ function Choice<T extends string>({
|
|
|
93
93
|
);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
/**
|
|
96
|
+
/** A code to scan, drawn with its own white quiet zone so it scans on a dark theme too. */
|
|
97
|
+
function Code({ value }: { value: string | null | undefined }) {
|
|
98
|
+
return value ? (
|
|
99
|
+
<QRCode value={value} size={200} quietZone={12} backgroundColor="white" color="black" />
|
|
100
|
+
) : (
|
|
101
|
+
// The code's own shape while the provider makes it: the same square, the quiet zone in.
|
|
102
|
+
<Skeleton.Region>
|
|
103
|
+
<Skeleton.Box width={224} height={224} />
|
|
104
|
+
</Skeleton.Region>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Telegram's two steps (ADR 0037): open the shared Gemies bot from this link, so Telegram says who
|
|
110
|
+
* the person is, and add it in Telegram › Settings › Telegram Business › Chatbots. The link opens
|
|
111
|
+
* Telegram here, and its code opens it on a phone. Once Telegram knows who the person is, only the
|
|
112
|
+
* second step is left.
|
|
113
|
+
*/
|
|
114
|
+
function TelegramSteps({ link, t }: { link: string | null; t: Translate }) {
|
|
115
|
+
return (
|
|
116
|
+
<View className="gap-2">
|
|
117
|
+
<Text variant="body-2-regular" className="text-text-secondary">
|
|
118
|
+
{t(`${K}.telegram.note`)}
|
|
119
|
+
</Text>
|
|
120
|
+
{link ? (
|
|
121
|
+
<>
|
|
122
|
+
<Text variant="body-2-regular">{t(`${K}.telegram.step1`)}</Text>
|
|
123
|
+
<Text variant="body-2-regular">{t(`${K}.telegram.step2`)}</Text>
|
|
124
|
+
<View className="flex-row">
|
|
125
|
+
<Button size="sm" onPress={() => void Linking.openURL(link)}>
|
|
126
|
+
{t(`${K}.telegram.open`)}
|
|
127
|
+
</Button>
|
|
128
|
+
</View>
|
|
129
|
+
<Code value={link} />
|
|
130
|
+
</>
|
|
131
|
+
) : (
|
|
132
|
+
<Text variant="body-2-regular">{t(`${K}.telegram.waitingBusiness`)}</Text>
|
|
133
|
+
)}
|
|
134
|
+
</View>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The account being linked, until the person finishes on their phone: WhatsApp's code to scan, or
|
|
140
|
+
* Telegram's steps.
|
|
141
|
+
*/
|
|
97
142
|
function LinkingAccount({
|
|
98
143
|
gemieId,
|
|
99
144
|
name,
|
|
@@ -117,25 +162,28 @@ function LinkingAccount({
|
|
|
117
162
|
|
|
118
163
|
useEffect(() => {
|
|
119
164
|
if (status === 'qr-pending') return;
|
|
120
|
-
|
|
121
|
-
|
|
165
|
+
// Telegram reports a connection its person turned off as paused: linked all the same.
|
|
166
|
+
if (status === 'connected' || status === 'paused') {
|
|
167
|
+
toast.success(t(`${K}.linked`, { platform: label, name }));
|
|
168
|
+
} else toast.error(t(`${K}.linkExpired`, { platform: label }));
|
|
122
169
|
onDone();
|
|
123
170
|
}, [label, name, onDone, status, t]);
|
|
124
171
|
|
|
125
172
|
return (
|
|
126
173
|
<Row>
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// The code carries its own white quiet zone, so it scans on a dark theme too.
|
|
133
|
-
<QRCode value={data.qr} size={200} quietZone={12} backgroundColor="white" color="black" />
|
|
174
|
+
{platform === 'telegram' ? (
|
|
175
|
+
<>
|
|
176
|
+
<Text variant="body-2-semibold">{t(`${K}.telegram.linkTitle`)}</Text>
|
|
177
|
+
<TelegramSteps link={data?.qr ?? null} t={t} />
|
|
178
|
+
</>
|
|
134
179
|
) : (
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
<
|
|
138
|
-
|
|
180
|
+
<>
|
|
181
|
+
<Text variant="body-2-semibold">{t(`${K}.scanTitle`, { platform: label })}</Text>
|
|
182
|
+
<Text variant="body-2-regular" className="text-text-secondary">
|
|
183
|
+
{t(`${K}.scan.${platform}`)}
|
|
184
|
+
</Text>
|
|
185
|
+
<Code value={data?.qr} />
|
|
186
|
+
</>
|
|
139
187
|
)}
|
|
140
188
|
<View className="flex-row">
|
|
141
189
|
<Button size="sm" appearance="outline" tone="neutral" onPress={onCancel}>
|
|
@@ -146,6 +194,20 @@ function LinkingAccount({
|
|
|
146
194
|
);
|
|
147
195
|
}
|
|
148
196
|
|
|
197
|
+
/** A Telegram account the person left before finishing: its steps, kept until it is linked. */
|
|
198
|
+
function PendingTelegram({
|
|
199
|
+
gemieId,
|
|
200
|
+
account,
|
|
201
|
+
t,
|
|
202
|
+
}: {
|
|
203
|
+
gemieId: string;
|
|
204
|
+
account: GemieAccount;
|
|
205
|
+
t: Translate;
|
|
206
|
+
}) {
|
|
207
|
+
const { data } = useGemieAccountQr(gemieId, { accountId: account._id, qr: null });
|
|
208
|
+
return <TelegramSteps link={data?.qr ?? null} t={t} />;
|
|
209
|
+
}
|
|
210
|
+
|
|
149
211
|
/** The chats a `chosen` account answers, picked from its recent ones. */
|
|
150
212
|
function ChosenChats({
|
|
151
213
|
gemieId,
|
|
@@ -223,11 +285,19 @@ function AccountRow({
|
|
|
223
285
|
}) {
|
|
224
286
|
const { setReplies, remove } = useGemieAccountMutations(gemieId);
|
|
225
287
|
const platform = PLATFORM_LABELS[account.platform] ?? account.platform;
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
288
|
+
const telegram = account.platform === 'telegram';
|
|
289
|
+
// Telegram's statuses mean something of their own: a link waiting in Telegram, an account the
|
|
290
|
+
// person paused there, one that moved to another gemie. None asks them to sign in again.
|
|
291
|
+
const status = !GEMIE_ACCOUNT_STATUSES.includes(account.status)
|
|
292
|
+
? account.status
|
|
293
|
+
: telegram && account.status !== 'connected'
|
|
294
|
+
? t(`${K}.telegram.status.${account.status}`)
|
|
295
|
+
: t(`${K}.status.${account.status}`);
|
|
229
296
|
const identifier = account.phoneNumber || account.displayName;
|
|
230
|
-
const live =
|
|
297
|
+
const live =
|
|
298
|
+
account.status === 'connected' ||
|
|
299
|
+
account.status === 'disconnected' ||
|
|
300
|
+
account.status === 'paused';
|
|
231
301
|
|
|
232
302
|
const save = async (patch: {
|
|
233
303
|
replies?: GemieAccountReplies;
|
|
@@ -243,7 +313,9 @@ function AccountRow({
|
|
|
243
313
|
const handleRemove = async () => {
|
|
244
314
|
const ok = await confirm({
|
|
245
315
|
title: t(`${K}.removeTitle`, { platform }),
|
|
246
|
-
description:
|
|
316
|
+
description: telegram
|
|
317
|
+
? t(`${K}.telegram.removeDescription`, { name })
|
|
318
|
+
: t(`${K}.removeDescription`, { platform, name }),
|
|
247
319
|
confirmLabel: t(`${K}.remove`),
|
|
248
320
|
cancelLabel: t(`${K}.cancel`),
|
|
249
321
|
destructive: true,
|
|
@@ -280,6 +352,14 @@ function AccountRow({
|
|
|
280
352
|
{t(`${K}.remove`)}
|
|
281
353
|
</Button>
|
|
282
354
|
</View>
|
|
355
|
+
{telegram && account.status === 'qr-pending' ? (
|
|
356
|
+
<PendingTelegram gemieId={gemieId} account={account} t={t} />
|
|
357
|
+
) : null}
|
|
358
|
+
{telegram && account.status === 'connected' && account.canReply === false ? (
|
|
359
|
+
<Text variant="body-2-regular" className="text-text-secondary">
|
|
360
|
+
{t(`${K}.telegram.cannotReply`, { name })}
|
|
361
|
+
</Text>
|
|
362
|
+
) : null}
|
|
283
363
|
{live ? (
|
|
284
364
|
<>
|
|
285
365
|
<Choice
|
|
@@ -296,7 +376,8 @@ function AccountRow({
|
|
|
296
376
|
{account.replies === 'chosen' ? (
|
|
297
377
|
<ChosenChats gemieId={gemieId} account={account} t={t} />
|
|
298
378
|
) : null}
|
|
299
|
-
{
|
|
379
|
+
{/* Telegram Business covers private chats only: it has no groups to choose for. */}
|
|
380
|
+
{account.replies !== 'nobody' && !telegram ? (
|
|
300
381
|
<Choice
|
|
301
382
|
label={t(`${K}.groupRepliesLabel`)}
|
|
302
383
|
value={account.groupReplies}
|
|
@@ -324,7 +405,8 @@ export interface GemieAccountsProps {
|
|
|
324
405
|
}
|
|
325
406
|
|
|
326
407
|
/**
|
|
327
|
-
* The WhatsApp and Telegram accounts the person linked to a gemie (ADR 0035
|
|
408
|
+
* The WhatsApp and Telegram accounts the person linked to a gemie (ADR 0035; Telegram through
|
|
409
|
+
* Telegram Business, ADR 0037), drawn without a
|
|
328
410
|
* frame of its own so each app puts it in its own: the Gemies app in a gemie's editor card, the
|
|
329
411
|
* Alia app in its settings. The gemie answers what arrives on them as the person chooses, and only
|
|
330
412
|
* its own turns can read or send through them. Only what this deployment can link is offered.
|
|
@@ -437,7 +519,13 @@ export function GemieAccounts({ gemieId, name, t = englishCopy }: GemieAccountsP
|
|
|
437
519
|
<Text variant="body-2-regular" className="text-text-secondary">
|
|
438
520
|
{t(`${K}.unavailable`)}
|
|
439
521
|
</Text>
|
|
440
|
-
) :
|
|
522
|
+
) : null}
|
|
523
|
+
{platforms.includes('telegram') ? (
|
|
524
|
+
<Text variant="body-2-regular" className="text-text-secondary">
|
|
525
|
+
{t(`${K}.telegram.note`)}
|
|
526
|
+
</Text>
|
|
527
|
+
) : null}
|
|
528
|
+
{platforms.length === 0 ? null : (
|
|
441
529
|
<View className="flex-row flex-wrap gap-2">
|
|
442
530
|
{platforms.map((platform) => (
|
|
443
531
|
<Button
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Text } from '@oxy.so/bloom/typography';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import { useConnectorLogoUrl } from '../../runtime/connectors';
|
|
5
|
+
import { Image } from '../Image';
|
|
6
|
+
|
|
7
|
+
export interface ConnectorLogoProps {
|
|
8
|
+
/** The connector's name, for the monogram and for screen readers. */
|
|
9
|
+
name: string;
|
|
10
|
+
/** The logo path the API answered (`/mcp/logos/<id>`), or `null`. */
|
|
11
|
+
logoUrl: string | null | undefined;
|
|
12
|
+
/** Its side, in points. */
|
|
13
|
+
size?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A connector's logo, wherever a connector appears: the store, Settings, a gemie's editor and a
|
|
18
|
+
* tool call in the chat. The image is always one the API stores and serves from its own origin
|
|
19
|
+
* (`lib/connector-logos.ts`): the server's own MCP icon, its MCP Registry icon or its provider's
|
|
20
|
+
* brand mark. Without one, or when it does not load, a monogram — never a broken image.
|
|
21
|
+
*/
|
|
22
|
+
export function ConnectorLogo({ name, logoUrl, size = 40 }: ConnectorLogoProps) {
|
|
23
|
+
const src = useConnectorLogoUrl(logoUrl);
|
|
24
|
+
const [failed, setFailed] = useState(false);
|
|
25
|
+
const radius = Math.round(size * 0.22);
|
|
26
|
+
|
|
27
|
+
if (!src || failed) {
|
|
28
|
+
const letter = name.trim().charAt(0).toUpperCase() || '·';
|
|
29
|
+
return (
|
|
30
|
+
<View
|
|
31
|
+
accessibilityRole="image"
|
|
32
|
+
accessibilityLabel={name}
|
|
33
|
+
className="items-center justify-center bg-background-tertiary-default"
|
|
34
|
+
style={{ width: size, height: size, borderRadius: radius }}
|
|
35
|
+
>
|
|
36
|
+
<Text
|
|
37
|
+
variant="body-medium"
|
|
38
|
+
className="text-text-secondary"
|
|
39
|
+
style={{ fontSize: Math.round(size * 0.45), lineHeight: Math.round(size * 0.6) }}
|
|
40
|
+
>
|
|
41
|
+
{letter}
|
|
42
|
+
</Text>
|
|
43
|
+
</View>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<View
|
|
49
|
+
className="overflow-hidden border border-border bg-white"
|
|
50
|
+
style={{ width: size, height: size, borderRadius: radius }}
|
|
51
|
+
>
|
|
52
|
+
<Image
|
|
53
|
+
source={{ uri: src }}
|
|
54
|
+
accessibilityLabel={name}
|
|
55
|
+
contentFit="contain"
|
|
56
|
+
style={{ width: size, height: size }}
|
|
57
|
+
onError={() => setFailed(true)}
|
|
58
|
+
/>
|
|
59
|
+
</View>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { Badge } from '@oxy.so/bloom/badge';
|
|
2
|
+
import { Button } from '@oxy.so/bloom/button';
|
|
3
|
+
import { Dialog } from '@oxy.so/bloom/dialog';
|
|
4
|
+
import { EmptyState } from '@oxy.so/bloom/empty-state';
|
|
5
|
+
import { RiPlugLine } from '@oxy.so/bloom/icons/RiPlugLine';
|
|
6
|
+
import * as Skeleton from '@oxy.so/bloom/skeleton';
|
|
7
|
+
import { confirm } from '@oxy.so/bloom/surfaces';
|
|
8
|
+
import { TextFieldInput, TextFieldLabel } from '@oxy.so/bloom/text-field';
|
|
9
|
+
import { toast } from '@oxy.so/bloom/toast';
|
|
10
|
+
import { Text } from '@oxy.so/bloom/typography';
|
|
11
|
+
import { useState } from 'react';
|
|
12
|
+
import { View } from 'react-native';
|
|
13
|
+
import { englishCopy, type Translate } from '../../lib/copy';
|
|
14
|
+
import {
|
|
15
|
+
type Connection,
|
|
16
|
+
connectorReturnTo,
|
|
17
|
+
useConnections,
|
|
18
|
+
useConnectorActions,
|
|
19
|
+
} from '../../runtime/connectors';
|
|
20
|
+
import { ConnectorLogo } from './ConnectorLogo';
|
|
21
|
+
|
|
22
|
+
/** This component's own strings. */
|
|
23
|
+
const K = 'gemie.connectors';
|
|
24
|
+
|
|
25
|
+
export interface GemieConnectedConnectorsProps {
|
|
26
|
+
/**
|
|
27
|
+
* The native app's URL scheme (`gemies`, `alia`): a provider's sign-in returns to the store at
|
|
28
|
+
* `<scheme>://connectors`, and on the web to the store's page (`connectorReturnTo`).
|
|
29
|
+
*/
|
|
30
|
+
nativeScheme: string;
|
|
31
|
+
/** Opens the store, from the header and from the empty list. */
|
|
32
|
+
onBrowse: () => void;
|
|
33
|
+
/** The host's translator; English without one. */
|
|
34
|
+
t?: Translate;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const STATUS_COLOR = { running: 'success', error: 'error', installed: 'warning' } as const;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* What the person connected, for Settings: every account on its own, with its logo, which account
|
|
41
|
+
* of the provider it is, its state, which gemies may use it, and how to reconnect, rename or
|
|
42
|
+
* disconnect it. Nothing they have not connected is listed here; the store is a tap away.
|
|
43
|
+
*/
|
|
44
|
+
export function GemieConnectedConnectors({
|
|
45
|
+
nativeScheme,
|
|
46
|
+
onBrowse,
|
|
47
|
+
t = englishCopy,
|
|
48
|
+
}: GemieConnectedConnectorsProps) {
|
|
49
|
+
const connections = useConnections();
|
|
50
|
+
const actions = useConnectorActions({ returnTo: connectorReturnTo(nativeScheme) });
|
|
51
|
+
const [pending, setPending] = useState<string | null>(null);
|
|
52
|
+
const [renaming, setRenaming] = useState<Connection | null>(null);
|
|
53
|
+
|
|
54
|
+
const reconnect = async (connection: Connection) => {
|
|
55
|
+
setPending(connection._id);
|
|
56
|
+
try {
|
|
57
|
+
const done = await actions.reconnect.mutateAsync(connection._id);
|
|
58
|
+
if (done?.status === 'running') {
|
|
59
|
+
toast.success(t(`${K}.reconnected`, { name: connection.displayName }));
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
toast.error(t(`${K}.reconnectFailed`, { name: connection.displayName }));
|
|
63
|
+
} finally {
|
|
64
|
+
setPending(null);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const disconnect = async (connection: Connection) => {
|
|
69
|
+
const name = label(connection);
|
|
70
|
+
const ok = await confirm({
|
|
71
|
+
title: t(`${K}.disconnectTitle`, { name }),
|
|
72
|
+
description: t(`${K}.disconnectDescription`, { name: connection.displayName }),
|
|
73
|
+
confirmLabel: t(`${K}.disconnect`),
|
|
74
|
+
cancelLabel: t(`${K}.cancel`),
|
|
75
|
+
destructive: true,
|
|
76
|
+
});
|
|
77
|
+
if (!ok) return;
|
|
78
|
+
setPending(connection._id);
|
|
79
|
+
try {
|
|
80
|
+
await actions.disconnect.mutateAsync(connection._id);
|
|
81
|
+
toast.success(t(`${K}.disconnected`, { name }));
|
|
82
|
+
} catch {
|
|
83
|
+
toast.error(t(`${K}.disconnectFailed`));
|
|
84
|
+
} finally {
|
|
85
|
+
setPending(null);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
if (connections.isPending) return <ConnectedSkeleton />;
|
|
90
|
+
|
|
91
|
+
if (connections.isError) {
|
|
92
|
+
return (
|
|
93
|
+
<View className="items-start gap-2 py-2.5">
|
|
94
|
+
<Text variant="body-2-regular" className="text-text-secondary">
|
|
95
|
+
{t(`${K}.connected.loadFailed`)}
|
|
96
|
+
</Text>
|
|
97
|
+
<Button size="sm" appearance="outline" tone="neutral" onPress={() => connections.refetch()}>
|
|
98
|
+
{t(`${K}.store.retry`)}
|
|
99
|
+
</Button>
|
|
100
|
+
</View>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const rows = connections.data ?? [];
|
|
105
|
+
if (rows.length === 0) {
|
|
106
|
+
return (
|
|
107
|
+
<EmptyState
|
|
108
|
+
icon={RiPlugLine}
|
|
109
|
+
title={t(`${K}.connected.emptyTitle`)}
|
|
110
|
+
description={t(`${K}.connected.emptyDescription`)}
|
|
111
|
+
action={{ label: t(`${K}.connected.browse`), onPress: onBrowse }}
|
|
112
|
+
/>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<View className="gap-1">
|
|
118
|
+
<View className="flex-row items-center justify-between gap-3 pb-1">
|
|
119
|
+
<Text variant="body-2-regular" className="flex-1 text-text-secondary">
|
|
120
|
+
{t(`${K}.connected.description`)}
|
|
121
|
+
</Text>
|
|
122
|
+
<Button size="sm" appearance="outline" tone="neutral" onPress={onBrowse}>
|
|
123
|
+
{t(`${K}.connected.browse`)}
|
|
124
|
+
</Button>
|
|
125
|
+
</View>
|
|
126
|
+
{rows.map((connection, index) => (
|
|
127
|
+
<View
|
|
128
|
+
key={connection._id}
|
|
129
|
+
className={`gap-2 py-3 ${index === 0 ? '' : 'border-t border-border'}`}
|
|
130
|
+
>
|
|
131
|
+
<View className="flex-row items-center gap-3">
|
|
132
|
+
<ConnectorLogo name={connection.displayName} logoUrl={connection.logoUrl} size={36} />
|
|
133
|
+
<View className="flex-1 gap-0.5">
|
|
134
|
+
<Text variant="body-2-semibold" numberOfLines={1}>
|
|
135
|
+
{connection.displayName}
|
|
136
|
+
</Text>
|
|
137
|
+
<Text variant="body-2-regular" className="text-text-secondary" numberOfLines={1}>
|
|
138
|
+
{[
|
|
139
|
+
connection.accountLabel ??
|
|
140
|
+
(connection.source === 'custom' ? connection.config.url : null),
|
|
141
|
+
t(`${K}.toolCount`, { count: connection.tools.length }),
|
|
142
|
+
]
|
|
143
|
+
.filter(Boolean)
|
|
144
|
+
.join(' · ')}
|
|
145
|
+
</Text>
|
|
146
|
+
</View>
|
|
147
|
+
<Badge
|
|
148
|
+
size="label-small"
|
|
149
|
+
variant="subtle"
|
|
150
|
+
color={STATUS_COLOR[connection.status]}
|
|
151
|
+
content={t(`${K}.status.${connection.status}`)}
|
|
152
|
+
/>
|
|
153
|
+
</View>
|
|
154
|
+
{connection.status !== 'running' && connection.statusMessage ? (
|
|
155
|
+
<Text variant="body-2-regular" className="text-text-secondary">
|
|
156
|
+
{connection.statusMessage}
|
|
157
|
+
</Text>
|
|
158
|
+
) : null}
|
|
159
|
+
{connection.usedBy.length > 0 ? (
|
|
160
|
+
<Text variant="body-2-regular" className="text-text-secondary">
|
|
161
|
+
{t(`${K}.usedBy`, { names: connection.usedBy.map((gemie) => gemie.name).join(', ') })}
|
|
162
|
+
</Text>
|
|
163
|
+
) : null}
|
|
164
|
+
<View className="flex-row flex-wrap gap-2">
|
|
165
|
+
{connection.status !== 'running' ? (
|
|
166
|
+
<Button
|
|
167
|
+
size="sm"
|
|
168
|
+
appearance="solid"
|
|
169
|
+
tone="accent"
|
|
170
|
+
loading={pending === connection._id}
|
|
171
|
+
onPress={() => void reconnect(connection)}
|
|
172
|
+
>
|
|
173
|
+
{t(`${K}.reconnect`)}
|
|
174
|
+
</Button>
|
|
175
|
+
) : null}
|
|
176
|
+
<Button
|
|
177
|
+
size="sm"
|
|
178
|
+
appearance="outline"
|
|
179
|
+
tone="neutral"
|
|
180
|
+
disabled={pending === connection._id}
|
|
181
|
+
onPress={() => setRenaming(connection)}
|
|
182
|
+
>
|
|
183
|
+
{t(`${K}.rename`)}
|
|
184
|
+
</Button>
|
|
185
|
+
{connection.status === 'running' ? (
|
|
186
|
+
<Button
|
|
187
|
+
size="sm"
|
|
188
|
+
appearance="outline"
|
|
189
|
+
tone="neutral"
|
|
190
|
+
disabled={pending === connection._id}
|
|
191
|
+
onPress={() => void reconnect(connection)}
|
|
192
|
+
>
|
|
193
|
+
{t(`${K}.reconnect`)}
|
|
194
|
+
</Button>
|
|
195
|
+
) : null}
|
|
196
|
+
<Button
|
|
197
|
+
size="sm"
|
|
198
|
+
appearance="outline"
|
|
199
|
+
tone="neutral"
|
|
200
|
+
disabled={pending === connection._id}
|
|
201
|
+
onPress={() => void disconnect(connection)}
|
|
202
|
+
>
|
|
203
|
+
{t(`${K}.disconnect`)}
|
|
204
|
+
</Button>
|
|
205
|
+
</View>
|
|
206
|
+
</View>
|
|
207
|
+
))}
|
|
208
|
+
<RenameDialog
|
|
209
|
+
connection={renaming}
|
|
210
|
+
onClose={() => setRenaming(null)}
|
|
211
|
+
onSave={async (accountLabel) => {
|
|
212
|
+
if (!renaming) return;
|
|
213
|
+
await actions.rename.mutateAsync({ id: renaming._id, accountLabel });
|
|
214
|
+
}}
|
|
215
|
+
t={t}
|
|
216
|
+
/>
|
|
217
|
+
</View>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** `Notion · ana@acme.com`: the connector, and which of the person's accounts. */
|
|
222
|
+
function label(connection: Connection): string {
|
|
223
|
+
return connection.accountLabel
|
|
224
|
+
? `${connection.displayName} · ${connection.accountLabel}`
|
|
225
|
+
: connection.displayName;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function RenameDialog({
|
|
229
|
+
connection,
|
|
230
|
+
onClose,
|
|
231
|
+
onSave,
|
|
232
|
+
t,
|
|
233
|
+
}: {
|
|
234
|
+
connection: Connection | null;
|
|
235
|
+
onClose: () => void;
|
|
236
|
+
onSave: (accountLabel: string | null) => Promise<void>;
|
|
237
|
+
t: Translate;
|
|
238
|
+
}) {
|
|
239
|
+
const [value, setValue] = useState<string | null>(null);
|
|
240
|
+
const [saving, setSaving] = useState(false);
|
|
241
|
+
const current = value ?? connection?.accountLabel ?? '';
|
|
242
|
+
|
|
243
|
+
const close = () => {
|
|
244
|
+
setValue(null);
|
|
245
|
+
onClose();
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const save = async () => {
|
|
249
|
+
setSaving(true);
|
|
250
|
+
try {
|
|
251
|
+
await onSave(current.trim() || null);
|
|
252
|
+
close();
|
|
253
|
+
} catch {
|
|
254
|
+
toast.error(t(`${K}.renameFailed`));
|
|
255
|
+
} finally {
|
|
256
|
+
setSaving(false);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
return (
|
|
261
|
+
<Dialog
|
|
262
|
+
open={connection !== null}
|
|
263
|
+
onClose={close}
|
|
264
|
+
placement={{ base: 'bottom', md: 'center' }}
|
|
265
|
+
maxWidth={384}
|
|
266
|
+
title={t(`${K}.renameTitle`)}
|
|
267
|
+
description={t(`${K}.renameDescription`, { name: connection?.displayName ?? '' })}
|
|
268
|
+
actions={[
|
|
269
|
+
{ label: t(`${K}.cancel`), color: 'cancel', disabled: saving },
|
|
270
|
+
{
|
|
271
|
+
label: t(`${K}.renameSave`),
|
|
272
|
+
onPress: save,
|
|
273
|
+
disabled: saving,
|
|
274
|
+
shouldCloseOnPress: false,
|
|
275
|
+
},
|
|
276
|
+
]}
|
|
277
|
+
>
|
|
278
|
+
<View>
|
|
279
|
+
<TextFieldLabel>{t(`${K}.renameLabel`)}</TextFieldLabel>
|
|
280
|
+
<TextFieldInput
|
|
281
|
+
label={t(`${K}.renameLabel`)}
|
|
282
|
+
placeholder="ana@acme.com"
|
|
283
|
+
value={current}
|
|
284
|
+
onChangeText={setValue}
|
|
285
|
+
autoCapitalize="none"
|
|
286
|
+
/>
|
|
287
|
+
</View>
|
|
288
|
+
</Dialog>
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** The list's shape while it is read: rows, never a spinner. */
|
|
293
|
+
function ConnectedSkeleton() {
|
|
294
|
+
return (
|
|
295
|
+
<Skeleton.Region>
|
|
296
|
+
<View className="gap-4 py-2.5">
|
|
297
|
+
{[0, 1].map((index) => (
|
|
298
|
+
<View key={index} className="flex-row items-center gap-3">
|
|
299
|
+
<Skeleton.Box width={36} height={36} borderRadius={8} />
|
|
300
|
+
<View className="flex-1 gap-1.5">
|
|
301
|
+
<Skeleton.Box width={140} height={14} />
|
|
302
|
+
<Skeleton.Box width={200} height={12} />
|
|
303
|
+
</View>
|
|
304
|
+
</View>
|
|
305
|
+
))}
|
|
306
|
+
</View>
|
|
307
|
+
</Skeleton.Region>
|
|
308
|
+
);
|
|
309
|
+
}
|