@gemies/sdk 3.0.1 → 3.2.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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @gemies/sdk
2
2
 
3
+ ## 3.2.0
4
+
5
+ - **Telegram is Telegram Business (Gemies ADR 0037).** `GemieAccounts` links a person's Telegram
6
+ through the shared Gemies bot: a button and a code that open the bot, and the step in Telegram ›
7
+ Settings › Telegram Business › Chatbots. It says Telegram Premium is needed and that only private
8
+ chats are covered, offers no group setting for it, and shows a connection the person turned off
9
+ in Telegram as paused (it resumes by itself) and one moved to another gemie as revoked; nothing
10
+ asks to sign in again. `GEMIE_ACCOUNT_STATUSES` gains `paused`, and `GemieAccount` carries
11
+ `canReply` (whether Telegram lets the gemie write); the panel says when it does not. New copy
12
+ under `gemie.accounts.telegram.*`; `gemie.accounts.scan.telegram` is gone.
13
+
14
+ ## 3.1.0
15
+
16
+ - **New: `AGENT_ROUTES` and `threadKey` from `@gemies/sdk/runtime`**, the routes and cache key of a
17
+ gemie's thread by its address (`{ handle }` or `{ gemieId }`), so a host opening a thread by id
18
+ reads the same path and invalidates the same key as `GemieChatContent`. A gemie with no Oxy
19
+ account (an external agent, Gemies ADR 0036) has no handle: its thread is addressed by its id.
20
+
3
21
  ## 3.0.1
4
22
 
5
23
  - **A gemie's account colour may be any hex, not only a Bloom preset key.** `readAgentCharacter`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gemies/sdk",
3
- "version": "3.0.1",
3
+ "version": "3.2.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,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
- /** The account being linked: its QR code until the person scans it with the platform's app. */
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
- if (status === 'connected') toast.success(t(`${K}.linked`, { platform: label, name }));
121
- else toast.error(t(`${K}.linkExpired`, { platform: label }));
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
- <Text variant="body-2-semibold">{t(`${K}.scanTitle`, { platform: label })}</Text>
128
- <Text variant="body-2-regular" className="text-text-secondary">
129
- {t(`${K}.scan.${platform}`)}
130
- </Text>
131
- {data?.qr ? (
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
- // The code's own shape while the provider makes it: the same square, the quiet zone in.
136
- <Skeleton.Region>
137
- <Skeleton.Box width={224} height={224} />
138
- </Skeleton.Region>
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 status = GEMIE_ACCOUNT_STATUSES.includes(account.status)
227
- ? t(`${K}.status.${account.status}`)
228
- : account.status;
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 = account.status === 'connected' || account.status === 'disconnected';
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: t(`${K}.removeDescription`, { platform, name }),
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
- {account.replies !== 'nobody' ? (
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), drawn without a
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
@@ -181,16 +181,36 @@ export const COPY_EN: Readonly<Record<string, CopyEntry>> = {
181
181
  'gemie.accounts.repliesLabel': 'Who {{name}} answers',
182
182
  'gemie.accounts.retry': 'Retry',
183
183
  'gemie.accounts.saveFailed': 'Could not save. Try again.',
184
- 'gemie.accounts.scan.telegram':
185
- 'Open Telegram on your phone, go to Settings > Devices > Link Desktop Device, and scan this code.',
186
184
  'gemie.accounts.scan.whatsapp':
187
185
  'Open WhatsApp on your phone, go to Settings > Linked devices > Link a device, and scan this code.',
188
186
  'gemie.accounts.scanTitle': 'Scan with {{platform}}',
189
187
  'gemie.accounts.status.connected': 'Connected',
190
188
  'gemie.accounts.status.disconnected': 'Reconnecting',
191
189
  'gemie.accounts.status.failed': 'Could not reconnect. Remove it and link it again.',
190
+ 'gemie.accounts.status.paused': 'Paused',
192
191
  'gemie.accounts.status.logged-out': 'Unlinked from the phone. Remove it and link it again.',
193
192
  'gemie.accounts.status.qr-pending': 'Waiting for the scan',
193
+ 'gemie.accounts.telegram.cannotReply':
194
+ 'Telegram does not let {{name}} reply yet: allow "Reply to messages" for the bot in Telegram › Settings › Telegram Business › Chatbots.',
195
+ 'gemie.accounts.telegram.linkTitle': 'Connect Telegram',
196
+ 'gemie.accounts.telegram.note':
197
+ 'Telegram Business needs Telegram Premium, and covers your private chats only (not groups or channels). It stays connected until you remove it in Telegram.',
198
+ 'gemie.accounts.telegram.open': 'Open Telegram',
199
+ 'gemie.accounts.telegram.removeDescription':
200
+ '{{name}} stops answering on your Telegram and what it read there is deleted. To disconnect it in Telegram too, remove the bot in Telegram › Settings › Telegram Business › Chatbots.',
201
+ 'gemie.accounts.telegram.status.disconnected': 'Reconnecting',
202
+ 'gemie.accounts.telegram.status.failed': 'Telegram could not be reached. It retries on its own.',
203
+ 'gemie.accounts.telegram.status.logged-out':
204
+ 'Revoked: this Telegram now answers through another gemie. Remove it, or link it again.',
205
+ 'gemie.accounts.telegram.status.paused':
206
+ 'Paused in Telegram. It resumes on its own when you turn the bot back on there.',
207
+ 'gemie.accounts.telegram.status.qr-pending': 'Waiting for you in Telegram',
208
+ 'gemie.accounts.telegram.step1':
209
+ '1. Open the Gemies bot in Telegram and press Start (or scan this code with your phone).',
210
+ 'gemie.accounts.telegram.step2':
211
+ '2. In Telegram, go to Settings › Telegram Business › Chatbots, add the bot and choose which chats it may answer.',
212
+ 'gemie.accounts.telegram.waitingBusiness':
213
+ 'Telegram knows it is you. Now go to Telegram › Settings › Telegram Business › Chatbots and add the bot you just opened.',
194
214
  'gemie.accounts.title': 'Connected accounts',
195
215
  'gemie.accounts.tryAgain': 'try again in a moment.',
196
216
  'gemie.accounts.unavailable': 'Linking WhatsApp or Telegram is not available right now.',
@@ -177,17 +177,38 @@ export const COPY_ES: Readonly<Record<string, CopyEntry>> = {
177
177
  'gemie.accounts.repliesLabel': 'A quién responde {{name}}',
178
178
  'gemie.accounts.retry': 'Reintentar',
179
179
  'gemie.accounts.saveFailed': 'No se ha podido guardar. Inténtalo de nuevo.',
180
- 'gemie.accounts.scan.telegram':
181
- 'Abre Telegram en tu teléfono, ve a Ajustes > Dispositivos > Vincular dispositivo de escritorio y escanea este código.',
182
180
  'gemie.accounts.scan.whatsapp':
183
181
  'Abre WhatsApp en tu teléfono, ve a Ajustes > Dispositivos vinculados > Vincular un dispositivo y escanea este código.',
184
182
  'gemie.accounts.scanTitle': 'Escanea con {{platform}}',
185
183
  'gemie.accounts.status.connected': 'Conectada',
186
184
  'gemie.accounts.status.disconnected': 'Reconectando',
187
185
  'gemie.accounts.status.failed': 'No se ha podido reconectar. Quítala y vuelve a vincularla.',
186
+ 'gemie.accounts.status.paused': 'En pausa',
188
187
  'gemie.accounts.status.logged-out':
189
188
  'Desvinculada desde el teléfono. Quítala y vuelve a vincularla.',
190
189
  'gemie.accounts.status.qr-pending': 'Esperando el escaneo',
190
+ 'gemie.accounts.telegram.cannotReply':
191
+ 'Telegram aún no deja responder a {{name}}: permite «Responder a mensajes» al bot en Telegram › Ajustes › Telegram Business › Chatbots.',
192
+ 'gemie.accounts.telegram.linkTitle': 'Conectar Telegram',
193
+ 'gemie.accounts.telegram.note':
194
+ 'Telegram Business necesita Telegram Premium y solo cubre tus chats privados (no grupos ni canales). Sigue conectado hasta que lo quites en Telegram.',
195
+ 'gemie.accounts.telegram.open': 'Abrir Telegram',
196
+ 'gemie.accounts.telegram.removeDescription':
197
+ '{{name}} deja de responder en tu Telegram y se borra lo que leyó allí. Para desconectarlo también en Telegram, quita el bot en Telegram › Ajustes › Telegram Business › Chatbots.',
198
+ 'gemie.accounts.telegram.status.disconnected': 'Reconectando',
199
+ 'gemie.accounts.telegram.status.failed':
200
+ 'No se ha podido contactar con Telegram. Lo reintenta solo.',
201
+ 'gemie.accounts.telegram.status.logged-out':
202
+ 'Revocado: este Telegram ahora responde a través de otro gemie. Quítalo o vuelve a vincularlo.',
203
+ 'gemie.accounts.telegram.status.paused':
204
+ 'En pausa en Telegram. Se reanuda solo cuando vuelvas a activar el bot allí.',
205
+ 'gemie.accounts.telegram.status.qr-pending': 'Esperándote en Telegram',
206
+ 'gemie.accounts.telegram.step1':
207
+ '1. Abre el bot de Gemies en Telegram y pulsa Iniciar (o escanea este código con el teléfono).',
208
+ 'gemie.accounts.telegram.step2':
209
+ '2. En Telegram, ve a Ajustes › Telegram Business › Chatbots, añade el bot y elige qué chats puede responder.',
210
+ 'gemie.accounts.telegram.waitingBusiness':
211
+ 'Telegram ya sabe que eres tú. Ahora ve a Telegram › Ajustes › Telegram Business › Chatbots y añade el bot que acabas de abrir.',
191
212
  'gemie.accounts.title': 'Cuentas conectadas',
192
213
  'gemie.accounts.tryAgain': 'inténtalo de nuevo en un momento.',
193
214
  'gemie.accounts.unavailable': 'Ahora mismo no se puede vincular WhatsApp ni Telegram.',
@@ -6,8 +6,8 @@ import { gemieQueryKeys } from './query-keys';
6
6
  import { AGENT_ROUTES } from './routes';
7
7
 
8
8
  /**
9
- * A gemie's connected accounts (ADR 0035): the WhatsApp and Telegram accounts the person linked to
10
- * a gemie, which answers what arrives on them as their replies say. Each is the caller's own; the
9
+ * A gemie's connected accounts (ADR 0035): the WhatsApp and Telegram (Business, ADR 0037) accounts
10
+ * the person linked to a gemie, which answers what arrives on them as their replies say. Each is the caller's own; the
11
11
  * API never lists another person's. The Gemies app (in a gemie's editor) and the Alia app (for
12
12
  * Alia's gemie) both manage them through these hooks and `GemieAccounts` (`@gemies/sdk/accounts`).
13
13
  */
@@ -20,6 +20,7 @@ export const GEMIE_ACCOUNT_STATUSES = [
20
20
  'qr-pending',
21
21
  'connected',
22
22
  'disconnected',
23
+ 'paused',
23
24
  'logged-out',
24
25
  'failed',
25
26
  ] as const;
@@ -39,6 +40,8 @@ export interface GemieAccount {
39
40
  displayName: string | null;
40
41
  phoneNumber: string | null;
41
42
  status: GemieAccountStatus;
43
+ /** Whether the platform lets the gemie write from it (Telegram Business); `null` elsewhere. */
44
+ canReply: boolean | null;
42
45
  oxyTaskState: 'active' | 'reauth_required';
43
46
  replies: GemieAccountReplies;
44
47
  replyChatIds: string[];
@@ -53,7 +56,10 @@ export interface GemieAccountChat {
53
56
  kind: 'direct' | 'group';
54
57
  }
55
58
 
56
- /** A link waiting for its scan. */
59
+ /**
60
+ * A link waiting to be finished: WhatsApp's code to scan, or Telegram's t.me link to
61
+ * open (or scan from another device).
62
+ */
57
63
  export interface GemieAccountLink {
58
64
  accountId: string;
59
65
  qr: string | null;
@@ -97,7 +103,8 @@ export function useGemieAccounts(gemieId: string) {
97
103
 
98
104
  /**
99
105
  * The code of an account being linked, refreshed while it waits (WhatsApp rotates its code every
100
- * few seconds). It stops once the session leaves `qr-pending`, and the list is re-read then, so the
106
+ * few seconds; Telegram's link is renewed when it expires, and is gone once Telegram knows who the
107
+ * person is). It stops once the session leaves `qr-pending`, and the list is re-read then, so the
101
108
  * account shows as it is.
102
109
  */
103
110
  export function useGemieAccountQr(gemieId: string, link: GemieAccountLink | null) {
@@ -124,6 +124,7 @@ export { useThreadHistory } from './use-thread-history';
124
124
  export { useThreadSearch, useThreadWindow } from './use-thread-search';
125
125
  export { useGemieThread } from './use-gemie-thread';
126
126
  export type { GemieThreadInfo } from './use-gemie-thread';
127
+ export { AGENT_ROUTES, threadKey } from './routes';
127
128
  export type { GemieThreadAddress } from './routes';
128
129
  export { useStartConversation } from './use-start-conversation';
129
130
  export type { StartConversationOptions } from './use-start-conversation';