@gemies/sdk 0.0.0-stage → 1.1.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.
Files changed (246) hide show
  1. package/CHANGELOG.md +1678 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +15 -0
  4. package/README.md +516 -2
  5. package/package.json +105 -4
  6. package/src/accounts.ts +29 -0
  7. package/src/animations.ts +5 -0
  8. package/src/ask-eager.ts +8 -0
  9. package/src/ask-text.ts +11 -0
  10. package/src/ask.ts +12 -0
  11. package/src/avatar.ts +13 -0
  12. package/src/character.ts +1 -0
  13. package/src/components/AmbientField.tsx +580 -0
  14. package/src/components/ComposerDropZone.tsx +235 -0
  15. package/src/components/ComposerSuggestions.tsx +45 -0
  16. package/src/components/GemieAccounts.tsx +433 -0
  17. package/src/components/GemieAskCore.tsx +184 -0
  18. package/src/components/GemieAskProvider.tsx +18 -0
  19. package/src/components/GemieAskProviderLazy.tsx +27 -0
  20. package/src/components/GemieAskProviderText.tsx +25 -0
  21. package/src/components/GemieAskSheet.tsx +51 -0
  22. package/src/components/GemieAskSheetWithVoice.tsx +10 -0
  23. package/src/components/GemieAvatar.tsx +57 -0
  24. package/src/components/GemieAvatarIcon.tsx +35 -0
  25. package/src/components/GemieChatContent.tsx +900 -0
  26. package/src/components/GemieChatHeader.tsx +123 -0
  27. package/src/components/GemieChatScreen.tsx +170 -0
  28. package/src/components/GemieChatSheet.tsx +368 -0
  29. package/src/components/GemieChatWithVoice.tsx +13 -0
  30. package/src/components/GemieComposer.tsx +388 -0
  31. package/src/components/GemieGroupWelcome.tsx +37 -0
  32. package/src/components/GemieParticipants.tsx +133 -0
  33. package/src/components/GemieParticipantsHeader.tsx +27 -0
  34. package/src/components/GemieRecentConversations.tsx +65 -0
  35. package/src/components/GemieSharedConversation.tsx +87 -0
  36. package/src/components/GemieWelcomeMessage.tsx +58 -0
  37. package/src/components/IdentityMark.tsx +225 -0
  38. package/src/components/Image.tsx +12 -0
  39. package/src/components/InertWhen.tsx +48 -0
  40. package/src/components/PlanPreviewCard.tsx +53 -0
  41. package/src/components/QuestionCard.tsx +64 -0
  42. package/src/components/ReplyMarkdown.tsx +373 -0
  43. package/src/components/RichBlocks.tsx +195 -0
  44. package/src/components/VoiceModeIcon.tsx +18 -0
  45. package/src/components/canvas/CanvasComponent.tsx +65 -0
  46. package/src/components/canvas/ChartRenderer.tsx +73 -0
  47. package/src/components/canvas/CodeRenderer.tsx +20 -0
  48. package/src/components/canvas/DashboardRenderer.tsx +70 -0
  49. package/src/components/canvas/DeckRenderer.tsx +43 -0
  50. package/src/components/canvas/FormRenderer.tsx +101 -0
  51. package/src/components/canvas/MarkdownRenderer.tsx +14 -0
  52. package/src/components/canvas/TableRenderer.tsx +47 -0
  53. package/src/components/icons/RiEmojiPicker.tsx +39 -0
  54. package/src/components/icons/RiMoreDots.tsx +32 -0
  55. package/src/components/icons/RiReplyLine.tsx +25 -0
  56. package/src/components/thought/FilesAndSources.tsx +120 -0
  57. package/src/components/thought/ThoughtPanel.tsx +426 -0
  58. package/src/components/thought/ToolStep.tsx +134 -0
  59. package/src/components/thread/AgentExchangeView.tsx +112 -0
  60. package/src/components/thread/AgentResultCard.tsx +125 -0
  61. package/src/components/thread/AgentTaskCard.tsx +127 -0
  62. package/src/components/thread/ChatBubble.tsx +256 -0
  63. package/src/components/thread/GemieThread.tsx +455 -0
  64. package/src/components/thread/MessageBlockBoundary.tsx +78 -0
  65. package/src/components/thread/NewConversationOffer.tsx +54 -0
  66. package/src/components/thread/ThreadRow.tsx +598 -0
  67. package/src/components/thread/ThreadSearch.tsx +130 -0
  68. package/src/components/thread/ThreadSkeleton.tsx +30 -0
  69. package/src/components/thread/ToolResultCard.tsx +254 -0
  70. package/src/components/thread/TurnMenu.tsx +54 -0
  71. package/src/components/thread/TurnStatusLine.tsx +34 -0
  72. package/src/components/voice/GemieVoiceCall.tsx +21 -0
  73. package/src/components/voice/GemieVoiceCall.web.tsx +17 -0
  74. package/src/components/voice/VoiceCallContext.ts +13 -0
  75. package/src/components/voice/VoiceControls.tsx +106 -0
  76. package/src/components/voice/VoiceSession.tsx +120 -0
  77. package/src/components/voice/withVoiceCall.tsx +25 -0
  78. package/src/csp.ts +50 -0
  79. package/src/dictation.ts +40 -0
  80. package/src/hooks/useAmbientWave.ts +184 -0
  81. package/src/hooks/useAtBottom.ts +51 -0
  82. package/src/hooks/useAttachMenu.ts +93 -0
  83. package/src/hooks/useAttachmentIntake.ts +401 -0
  84. package/src/hooks/useAudioLevelMonitor.ts +46 -0
  85. package/src/hooks/useAudioLevels.ts +51 -0
  86. package/src/hooks/useChatComposer.ts +309 -0
  87. package/src/hooks/useChatVoice.ts +129 -0
  88. package/src/hooks/useComposerSuggestions.ts +84 -0
  89. package/src/hooks/useDictation.ts +292 -0
  90. package/src/hooks/useDocumentPicker.ts +11 -0
  91. package/src/hooks/useFailedTurnToast.ts +43 -0
  92. package/src/hooks/useFocusWhenPresented.ts +41 -0
  93. package/src/hooks/useGemieActivity.ts +31 -0
  94. package/src/hooks/useImagePicker.ts +38 -0
  95. package/src/hooks/useMessageReactions.ts +119 -0
  96. package/src/hooks/useMessageVote.ts +50 -0
  97. package/src/hooks/useOpenThought.ts +79 -0
  98. package/src/hooks/usePendingQuestions.ts +19 -0
  99. package/src/hooks/useReadAloud.ts +92 -0
  100. package/src/hooks/useShareHandler.ts +24 -0
  101. package/src/hooks/useSoundEffects.ts +137 -0
  102. package/src/hooks/useTTS.ts +303 -0
  103. package/src/hooks/useThoughtScope.ts +59 -0
  104. package/src/hooks/useThreadRows.ts +157 -0
  105. package/src/hooks/useThreadView.ts +67 -0
  106. package/src/hooks/useTimelineWindow.ts +256 -0
  107. package/src/hooks/useVoiceLauncher.ts +180 -0
  108. package/src/hooks/useVoiceRoom.ts +212 -0
  109. package/src/index.ts +141 -0
  110. package/src/lib/activity-socket.ts +102 -0
  111. package/src/lib/activity-store.ts +53 -0
  112. package/src/lib/add-menu.ts +7 -0
  113. package/src/lib/agent-character.ts +28 -0
  114. package/src/lib/alia-character.ts +14 -0
  115. package/src/lib/alia-gemie.ts +6 -0
  116. package/src/lib/attachment-intake.ts +154 -0
  117. package/src/lib/attachment-tiles.ts +74 -0
  118. package/src/lib/audio-level.ts +130 -0
  119. package/src/lib/audio-request-auth.ts +4 -0
  120. package/src/lib/audio-session-binding.ts +27 -0
  121. package/src/lib/bubbles.tsx +16 -0
  122. package/src/lib/call-thread.ts +33 -0
  123. package/src/lib/canvas-result.ts +21 -0
  124. package/src/lib/catalogue-tool.ts +22 -0
  125. package/src/lib/citations.ts +192 -0
  126. package/src/lib/clipboard.ts +23 -0
  127. package/src/lib/content-utils.ts +46 -0
  128. package/src/lib/copy-en.ts +333 -0
  129. package/src/lib/copy-es.ts +330 -0
  130. package/src/lib/copy.ts +38 -0
  131. package/src/lib/deferred/document-picker.ts +2 -0
  132. package/src/lib/deferred/document-picker.web.ts +12 -0
  133. package/src/lib/deferred/expo-audio.ts +2 -0
  134. package/src/lib/deferred/expo-audio.web.ts +12 -0
  135. package/src/lib/deferred/image-data-url.ts +5 -0
  136. package/src/lib/deferred/image-data-url.web.ts +12 -0
  137. package/src/lib/dictation-protocol.ts +142 -0
  138. package/src/lib/dictation-recorder-types.ts +37 -0
  139. package/src/lib/dictation-recorder.native.ts +90 -0
  140. package/src/lib/dictation-recorder.ts +131 -0
  141. package/src/lib/dictation-stream.ts +238 -0
  142. package/src/lib/dictation.ts +216 -0
  143. package/src/lib/document-picker.ts +31 -0
  144. package/src/lib/domain.ts +12 -0
  145. package/src/lib/flights.ts +33 -0
  146. package/src/lib/focus-return.ts +66 -0
  147. package/src/lib/greeting.ts +15 -0
  148. package/src/lib/image-data-url.ts +35 -0
  149. package/src/lib/keyboard.native.tsx +25 -0
  150. package/src/lib/keyboard.tsx +55 -0
  151. package/src/lib/labels-es.ts +113 -0
  152. package/src/lib/labels.tsx +207 -0
  153. package/src/lib/origins.ts +28 -0
  154. package/src/lib/participants.ts +97 -0
  155. package/src/lib/pcm.ts +57 -0
  156. package/src/lib/power-level-options.ts +66 -0
  157. package/src/lib/questions.ts +92 -0
  158. package/src/lib/speech-language.ts +20 -0
  159. package/src/lib/speech-messages.ts +54 -0
  160. package/src/lib/speech-synthesis.ts +156 -0
  161. package/src/lib/suggestions.ts +53 -0
  162. package/src/lib/task-labels.ts +35 -0
  163. package/src/lib/text-input.ts +10 -0
  164. package/src/lib/tool-call-status.ts +28 -0
  165. package/src/lib/tool-icons.ts +36 -0
  166. package/src/lib/tool-registry.ts +71 -0
  167. package/src/lib/tool-renderers.tsx +32 -0
  168. package/src/lib/turn-state.ts +15 -0
  169. package/src/lib/utils.ts +35 -0
  170. package/src/lib/voice-audio-engine-types.ts +59 -0
  171. package/src/lib/voice-audio-engine.native.ts +232 -0
  172. package/src/lib/voice-audio-engine.ts +206 -0
  173. package/src/lib/voice-call-request.ts +49 -0
  174. package/src/lib/voice-call.ts +627 -0
  175. package/src/lib/voice-controls-labels.ts +31 -0
  176. package/src/lib/voice-levels.ts +64 -0
  177. package/src/lib/voice-protocol.ts +328 -0
  178. package/src/lib/voice-worklets.ts +19 -0
  179. package/src/lib/work-log.ts +370 -0
  180. package/src/metro/chart-importers.json +18 -0
  181. package/src/metro/granular-charts.js +3 -0
  182. package/src/metro/index.cjs +227 -0
  183. package/src/metro/index.d.cts +5 -0
  184. package/src/runtime/agents.ts +151 -0
  185. package/src/runtime/api.ts +144 -0
  186. package/src/runtime/app-assertion.ts +51 -0
  187. package/src/runtime/attachment-utils.ts +97 -0
  188. package/src/runtime/chat-turn-control.ts +74 -0
  189. package/src/runtime/composer-draft-store.ts +270 -0
  190. package/src/runtime/config.tsx +222 -0
  191. package/src/runtime/conversation-dates.ts +31 -0
  192. package/src/runtime/conversation-store.ts +49 -0
  193. package/src/runtime/conversations.ts +633 -0
  194. package/src/runtime/error-utils.ts +144 -0
  195. package/src/runtime/gemie-accounts.ts +182 -0
  196. package/src/runtime/host-tools.ts +290 -0
  197. package/src/runtime/index.ts +137 -0
  198. package/src/runtime/message-history.ts +124 -0
  199. package/src/runtime/message-reactions.ts +214 -0
  200. package/src/runtime/model.ts +39 -0
  201. package/src/runtime/oxy-files.ts +37 -0
  202. package/src/runtime/power-levels.ts +66 -0
  203. package/src/runtime/query-keys.ts +60 -0
  204. package/src/runtime/random-uuid.ts +25 -0
  205. package/src/runtime/reaction-cache.ts +45 -0
  206. package/src/runtime/room-events.ts +333 -0
  207. package/src/runtime/routes.ts +85 -0
  208. package/src/runtime/sharing.ts +217 -0
  209. package/src/runtime/sse-frame-reader.ts +88 -0
  210. package/src/runtime/stream-events.ts +154 -0
  211. package/src/runtime/stream-outcome.ts +21 -0
  212. package/src/runtime/thought-store.ts +103 -0
  213. package/src/runtime/thread/agent-activity.ts +261 -0
  214. package/src/runtime/thread/agent-exchange.ts +94 -0
  215. package/src/runtime/thread/automation-labels.ts +79 -0
  216. package/src/runtime/thread/conversation-export.ts +135 -0
  217. package/src/runtime/thread/message-days.ts +120 -0
  218. package/src/runtime/thread/message-processor.ts +93 -0
  219. package/src/runtime/thread/speaker-changes.ts +66 -0
  220. package/src/runtime/thread/task-utils.ts +11 -0
  221. package/src/runtime/thread/thought-utils.ts +750 -0
  222. package/src/runtime/thread/thread-history.ts +139 -0
  223. package/src/runtime/thread/timeline.ts +202 -0
  224. package/src/runtime/thread/title-tags.ts +8 -0
  225. package/src/runtime/thread/tool-cards.ts +387 -0
  226. package/src/runtime/turn-failure.ts +108 -0
  227. package/src/runtime/turn-preparation.ts +21 -0
  228. package/src/runtime/types.ts +172 -0
  229. package/src/runtime/usage-limit-error.ts +44 -0
  230. package/src/runtime/use-agent-activity.ts +80 -0
  231. package/src/runtime/use-conversation-stream.ts +1669 -0
  232. package/src/runtime/use-conversation-thread.ts +590 -0
  233. package/src/runtime/use-gemie-thread.ts +54 -0
  234. package/src/runtime/use-room-events.ts +75 -0
  235. package/src/runtime/use-start-conversation.ts +107 -0
  236. package/src/runtime/use-thread-history.ts +73 -0
  237. package/src/runtime/use-thread-search.ts +100 -0
  238. package/src/runtime/use-turn-edit.ts +99 -0
  239. package/src/text.ts +19 -0
  240. package/src/theme.ts +16 -0
  241. package/src/tools.ts +27 -0
  242. package/src/types.ts +161 -0
  243. package/src/voice-messages.ts +2 -0
  244. package/src/voice.ts +67 -0
  245. package/tsconfig.json +17 -0
  246. package/worklets/voice-processors.js +152 -0
@@ -0,0 +1,433 @@
1
+ import { Button } from '@oxy.so/bloom/button';
2
+ import {
3
+ Select,
4
+ SelectContent,
5
+ SelectIcon,
6
+ SelectItem,
7
+ SelectItemText,
8
+ SelectTrigger,
9
+ SelectValue,
10
+ } from '@oxy.so/bloom/select';
11
+ import * as Skeleton from '@oxy.so/bloom/skeleton';
12
+ import { confirm } from '@oxy.so/bloom/surfaces';
13
+ import { Switch } from '@oxy.so/bloom/switch';
14
+ import { toast } from '@oxy.so/bloom/toast';
15
+ import { Text } from '@oxy.so/bloom/typography';
16
+ import { useCallback, useEffect, useState } from 'react';
17
+ import { View } from 'react-native';
18
+ import QRCode from 'react-native-qrcode-svg';
19
+ import { englishCopy, type Translate } from '../lib/copy';
20
+ import { errorMessage } from '../runtime/error-utils';
21
+ import {
22
+ GEMIE_ACCOUNT_STATUSES,
23
+ useGemieAccountChats,
24
+ useGemieAccountMutations,
25
+ useGemieAccountQr,
26
+ useGemieAccounts,
27
+ type GemieAccount,
28
+ type GemieAccountGroupReplies,
29
+ type GemieAccountLink,
30
+ type GemieAccountPlatform,
31
+ type GemieAccountReplies,
32
+ } from '../runtime/gemie-accounts';
33
+
34
+ /** This component's own strings. */
35
+ const K = 'gemie.accounts';
36
+
37
+ /** Product names, the same in every language. */
38
+ const PLATFORM_LABELS: Record<GemieAccountPlatform, string> = {
39
+ whatsapp: 'WhatsApp',
40
+ telegram: 'Telegram',
41
+ };
42
+
43
+ /** One row of the list: the same rhythm as a settings row, a divider above all but the first. */
44
+ function Row({ children, first }: { children: React.ReactNode; first?: boolean }) {
45
+ return (
46
+ <View className={`gap-3 py-2.5 pe-2.5 ${first ? '' : 'border-t border-border'}`}>
47
+ {children}
48
+ </View>
49
+ );
50
+ }
51
+
52
+ function Choice<T extends string>({
53
+ label,
54
+ value,
55
+ items,
56
+ disabled,
57
+ onChange,
58
+ }: {
59
+ label: string;
60
+ value: T;
61
+ items: readonly { value: T; label: string }[];
62
+ disabled: boolean;
63
+ onChange: (value: T) => void;
64
+ }) {
65
+ return (
66
+ <View className="gap-1">
67
+ <Text variant="body-2-regular" className="text-text-secondary">
68
+ {label}
69
+ </Text>
70
+ <Select
71
+ size="sm"
72
+ value={value}
73
+ onValueChange={(next) => onChange(next as T)}
74
+ disabled={disabled}
75
+ >
76
+ <SelectTrigger label={label}>
77
+ <SelectValue placeholder={label} />
78
+ <SelectIcon />
79
+ </SelectTrigger>
80
+ <SelectContent
81
+ label={label}
82
+ items={items.map((item) => ({ ...item, id: item.value }))}
83
+ width={280}
84
+ valueExtractor={(item) => item.id}
85
+ renderItem={(item) => (
86
+ <SelectItem value={item.id} label={item.label}>
87
+ <SelectItemText>{item.label}</SelectItemText>
88
+ </SelectItem>
89
+ )}
90
+ />
91
+ </Select>
92
+ </View>
93
+ );
94
+ }
95
+
96
+ /** The account being linked: its QR code until the person scans it with the platform's app. */
97
+ function LinkingAccount({
98
+ gemieId,
99
+ name,
100
+ platform,
101
+ link,
102
+ t,
103
+ onDone,
104
+ onCancel,
105
+ }: {
106
+ gemieId: string;
107
+ name: string;
108
+ platform: GemieAccountPlatform;
109
+ link: GemieAccountLink;
110
+ t: Translate;
111
+ onDone: () => void;
112
+ onCancel: () => void;
113
+ }) {
114
+ const { data } = useGemieAccountQr(gemieId, link);
115
+ const status = data?.status ?? 'qr-pending';
116
+ const label = PLATFORM_LABELS[platform];
117
+
118
+ useEffect(() => {
119
+ 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 }));
122
+ onDone();
123
+ }, [label, name, onDone, status, t]);
124
+
125
+ return (
126
+ <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" />
134
+ ) : (
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>
139
+ )}
140
+ <View className="flex-row">
141
+ <Button size="sm" appearance="outline" tone="neutral" onPress={onCancel}>
142
+ {t(`${K}.cancel`)}
143
+ </Button>
144
+ </View>
145
+ </Row>
146
+ );
147
+ }
148
+
149
+ /** The chats a `chosen` account answers, picked from its recent ones. */
150
+ function ChosenChats({
151
+ gemieId,
152
+ account,
153
+ t,
154
+ }: {
155
+ gemieId: string;
156
+ account: GemieAccount;
157
+ t: Translate;
158
+ }) {
159
+ const { data: chats, isPending } = useGemieAccountChats(gemieId, account._id);
160
+ const { setReplies } = useGemieAccountMutations(gemieId);
161
+
162
+ const toggle = async (chatId: string, on: boolean) => {
163
+ const replyChatIds = on
164
+ ? [...account.replyChatIds, chatId]
165
+ : account.replyChatIds.filter((id) => id !== chatId);
166
+ try {
167
+ await setReplies.mutateAsync({ accountId: account._id, replyChatIds });
168
+ } catch {
169
+ toast.error(t(`${K}.saveFailed`));
170
+ }
171
+ };
172
+
173
+ if (isPending) {
174
+ return (
175
+ <Skeleton.Region>
176
+ <View className="gap-2">
177
+ {[0, 1, 2].map((row) => (
178
+ <Skeleton.Box key={row} width={180} height={14} />
179
+ ))}
180
+ </View>
181
+ </Skeleton.Region>
182
+ );
183
+ }
184
+ if (!chats?.length) {
185
+ return (
186
+ <Text variant="body-2-regular" className="text-text-secondary">
187
+ {t(`${K}.noChats`)}
188
+ </Text>
189
+ );
190
+ }
191
+ return (
192
+ <View className="gap-1">
193
+ {chats.map((chat) => (
194
+ <View key={chat.chatId} className="flex-row items-center justify-between gap-3 py-1">
195
+ <Text variant="body-2-regular" numberOfLines={1} className="flex-1">
196
+ {chat.kind === 'group' ? t(`${K}.groupChat`, { name: chat.name }) : chat.name}
197
+ </Text>
198
+ <Switch
199
+ accessibilityLabel={t(`${K}.answerChat`, { name: chat.name })}
200
+ checked={account.replyChatIds.includes(chat.chatId)}
201
+ disabled={setReplies.isPending}
202
+ onCheckedChange={(on) => toggle(chat.chatId, on)}
203
+ />
204
+ </View>
205
+ ))}
206
+ </View>
207
+ );
208
+ }
209
+
210
+ /** One linked account: its live status, who it answers, and removing it. */
211
+ function AccountRow({
212
+ gemieId,
213
+ name,
214
+ account,
215
+ first,
216
+ t,
217
+ }: {
218
+ gemieId: string;
219
+ name: string;
220
+ account: GemieAccount;
221
+ first: boolean;
222
+ t: Translate;
223
+ }) {
224
+ const { setReplies, remove } = useGemieAccountMutations(gemieId);
225
+ 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;
229
+ const identifier = account.phoneNumber || account.displayName;
230
+ const live = account.status === 'connected' || account.status === 'disconnected';
231
+
232
+ const save = async (patch: {
233
+ replies?: GemieAccountReplies;
234
+ groupReplies?: GemieAccountGroupReplies;
235
+ }) => {
236
+ try {
237
+ await setReplies.mutateAsync({ accountId: account._id, ...patch });
238
+ } catch {
239
+ toast.error(t(`${K}.saveFailed`));
240
+ }
241
+ };
242
+
243
+ const handleRemove = async () => {
244
+ const ok = await confirm({
245
+ title: t(`${K}.removeTitle`, { platform }),
246
+ description: t(`${K}.removeDescription`, { platform, name }),
247
+ confirmLabel: t(`${K}.remove`),
248
+ cancelLabel: t(`${K}.cancel`),
249
+ destructive: true,
250
+ });
251
+ if (!ok) return;
252
+ try {
253
+ await remove.mutateAsync(account._id);
254
+ toast.success(t(`${K}.removed`, { platform }));
255
+ } catch {
256
+ toast.error(t(`${K}.removeFailed`));
257
+ }
258
+ };
259
+
260
+ return (
261
+ <Row first={first}>
262
+ <View className="flex-row flex-wrap items-center justify-between gap-3">
263
+ <View className="flex-1 gap-0.5">
264
+ <Text variant="body-2-semibold">{platform}</Text>
265
+ <Text variant="body-2-regular">{[identifier, status].filter(Boolean).join(' · ')}</Text>
266
+ <Text variant="body-2-regular" className="text-text-secondary">
267
+ {account.lastActiveAt
268
+ ? t(`${K}.lastMessage`, { when: new Date(account.lastActiveAt).toLocaleString() })
269
+ : t(`${K}.noMessagesYet`)}
270
+ </Text>
271
+ </View>
272
+ <Button
273
+ size="sm"
274
+ appearance="outline"
275
+ tone="danger"
276
+ accessibilityLabel={t(`${K}.removeNamed`, { platform })}
277
+ disabled={remove.isPending}
278
+ onPress={handleRemove}
279
+ >
280
+ {t(`${K}.remove`)}
281
+ </Button>
282
+ </View>
283
+ {live ? (
284
+ <>
285
+ <Choice
286
+ label={t(`${K}.repliesLabel`, { name })}
287
+ value={account.replies}
288
+ disabled={setReplies.isPending}
289
+ items={[
290
+ { value: 'everyone', label: t(`${K}.replies.everyone`) },
291
+ { value: 'chosen', label: t(`${K}.replies.chosen`) },
292
+ { value: 'nobody', label: t(`${K}.replies.nobody`, { name }) },
293
+ ]}
294
+ onChange={(replies) => save({ replies })}
295
+ />
296
+ {account.replies === 'chosen' ? (
297
+ <ChosenChats gemieId={gemieId} account={account} t={t} />
298
+ ) : null}
299
+ {account.replies !== 'nobody' ? (
300
+ <Choice
301
+ label={t(`${K}.groupRepliesLabel`)}
302
+ value={account.groupReplies}
303
+ disabled={setReplies.isPending}
304
+ items={[
305
+ { value: 'mentions', label: t(`${K}.groupReplies.mentions`) },
306
+ { value: 'never', label: t(`${K}.groupReplies.never`) },
307
+ ]}
308
+ onChange={(groupReplies) => save({ groupReplies })}
309
+ />
310
+ ) : null}
311
+ </>
312
+ ) : null}
313
+ </Row>
314
+ );
315
+ }
316
+
317
+ export interface GemieAccountsProps {
318
+ /** The gemie the accounts are linked to (Alia's id, in the Alia app). */
319
+ gemieId: string;
320
+ /** The gemie's name, as the copy says it. */
321
+ name: string;
322
+ /** The host's translator, keyed as `gemie.accounts.*`; English when absent. */
323
+ t?: Translate;
324
+ }
325
+
326
+ /**
327
+ * The WhatsApp and Telegram accounts the person linked to a gemie (ADR 0035), drawn without a
328
+ * frame of its own so each app puts it in its own: the Gemies app in a gemie's editor card, the
329
+ * Alia app in its settings. The gemie answers what arrives on them as the person chooses, and only
330
+ * its own turns can read or send through them. Only what this deployment can link is offered.
331
+ */
332
+ export function GemieAccounts({ gemieId, name, t = englishCopy }: GemieAccountsProps) {
333
+ const { data, isPending, isError } = useGemieAccounts(gemieId);
334
+ const { link, remove } = useGemieAccountMutations(gemieId);
335
+ const [linking, setLinking] = useState<{
336
+ platform: GemieAccountPlatform;
337
+ link: GemieAccountLink;
338
+ } | null>(null);
339
+ const linked = useCallback(() => setLinking(null), []);
340
+
341
+ if (isPending) {
342
+ return (
343
+ <Skeleton.Region>
344
+ <View className="gap-3 py-2.5">
345
+ <Skeleton.Box width={260} height={14} />
346
+ <Skeleton.Box width={160} height={14} />
347
+ </View>
348
+ </Skeleton.Region>
349
+ );
350
+ }
351
+
352
+ const handleLink = async (platform: GemieAccountPlatform) => {
353
+ try {
354
+ setLinking({ platform, link: await link.mutateAsync(platform) });
355
+ } catch (error) {
356
+ toast.error(
357
+ t(`${K}.linkFailed`, {
358
+ platform: PLATFORM_LABELS[platform],
359
+ reason: errorMessage(error, t(`${K}.tryAgain`)),
360
+ }),
361
+ );
362
+ }
363
+ };
364
+
365
+ const handleCancel = async () => {
366
+ const pending = linking;
367
+ setLinking(null);
368
+ if (pending) await remove.mutateAsync(pending.link.accountId).catch(() => {});
369
+ };
370
+
371
+ // The account being linked shows as its QR code, not as a row beside it.
372
+ const accounts = (data?.accounts ?? []).filter(
373
+ (account) => account._id !== linking?.link.accountId,
374
+ );
375
+ const platforms = data?.platforms ?? [];
376
+
377
+ return (
378
+ <View>
379
+ <Row first>
380
+ <Text variant="body-2-regular" className="text-text-secondary">
381
+ {isError ? t(`${K}.loadFailed`) : t(`${K}.description`, { name })}
382
+ </Text>
383
+ </Row>
384
+ {accounts.map((account) => (
385
+ <AccountRow
386
+ key={account._id}
387
+ gemieId={gemieId}
388
+ name={name}
389
+ account={account}
390
+ first={false}
391
+ t={t}
392
+ />
393
+ ))}
394
+ {linking ? (
395
+ <LinkingAccount
396
+ gemieId={gemieId}
397
+ name={name}
398
+ platform={linking.platform}
399
+ link={linking.link}
400
+ t={t}
401
+ onDone={linked}
402
+ onCancel={handleCancel}
403
+ />
404
+ ) : isError ? null : (
405
+ <Row>
406
+ <Text variant="body-2-semibold">{t(`${K}.link`)}</Text>
407
+ {platforms.length === 0 ? (
408
+ <Text variant="body-2-regular" className="text-text-secondary">
409
+ {t(`${K}.unavailable`)}
410
+ </Text>
411
+ ) : (
412
+ <View className="flex-row gap-2">
413
+ {platforms.map((platform) => (
414
+ <Button
415
+ key={platform}
416
+ size="sm"
417
+ appearance="outline"
418
+ tone="neutral"
419
+ accessibilityLabel={t(`${K}.linkNamed`, { platform: PLATFORM_LABELS[platform] })}
420
+ loading={link.isPending && link.variables === platform}
421
+ disabled={link.isPending}
422
+ onPress={() => handleLink(platform)}
423
+ >
424
+ {PLATFORM_LABELS[platform]}
425
+ </Button>
426
+ ))}
427
+ </View>
428
+ )}
429
+ </Row>
430
+ )}
431
+ </View>
432
+ );
433
+ }
@@ -0,0 +1,184 @@
1
+ /**
2
+ * "Ask Alia", "Ask Sindi": one sheet an app mounts once, opened on any agent from anywhere in it.
3
+ *
4
+ * The app names the agents it offers (`agents`, by a key of its own) and configures the sheet
5
+ * once — its host tools, renderers, words, voice, context, upsell and share. A button calls
6
+ * `useAskGemie().ask(key, turn)`. Signed out, the sheet is not mounted (it could not call Alia):
7
+ * `ask` opens Oxy's sign-in instead, and the person asks again once signed in.
8
+ *
9
+ * This module is the provider without its sheet; each entry builds one with `createAskProvider`:
10
+ * - `@gemies/sdk/ask` (`GemieAskProviderLazy`) loads the sheet with the first `ask`, through
11
+ * the one `import()` that keeps the chat out of the app's entry bundle;
12
+ * - the root entry (`GemieAskProvider`) already holds the whole chat, so its sheet is a static
13
+ * import. A lazy one there would put an async chunk boundary INSIDE the SDK, and on web Metro
14
+ * hoists every module two async chunks share into `__common.js`, loaded at first paint: an app
15
+ * that lazy-loads the root entry would get the chat in its first paint instead of its own chunk.
16
+ * Both read and write the one context below, so `useAskGemie` works under either.
17
+ */
18
+
19
+ import { useAuth, useOxy } from '@oxy.so/services/ui/client';
20
+ import {
21
+ type ComponentType,
22
+ createContext,
23
+ forwardRef,
24
+ type ReactNode,
25
+ type RefAttributes,
26
+ useCallback,
27
+ useContext,
28
+ useEffect,
29
+ useImperativeHandle,
30
+ useMemo,
31
+ useRef,
32
+ useState,
33
+ } from 'react';
34
+ import type { GemieTurn } from '../hooks/useChatComposer';
35
+ import type { GemieChatSheetProps, GemieChatSheetRef } from './GemieChatSheet';
36
+ import type { GemieAskOpening, GemieAskSheetProps } from './GemieAskSheet';
37
+
38
+ /** The agents an app offers, by its own key. An entry without `id` is Alia. */
39
+ export type GemieAskAgents = Readonly<Record<string, { id?: string }>>;
40
+
41
+ export interface GemieAskProviderProps
42
+ extends Pick<
43
+ GemieChatSheetProps,
44
+ | 'app'
45
+ | 'hostTools'
46
+ | 'toolRenderers'
47
+ | 'labels'
48
+ | 'voice'
49
+ | 'clientContext'
50
+ | 'onFeatureLocked'
51
+ | 'onShare'
52
+ | 'model'
53
+ | 'apiUrl'
54
+ | 'headerMenu'
55
+ | 'recentConversations'
56
+ > {
57
+ /** The agents `ask` opens, by key. Omitted, the sheet only ever opens on Alia. */
58
+ agents?: GemieAskAgents;
59
+ /** The lines offered over Alia's empty composer; an agent offers its own starters. */
60
+ welcomeSuggestions?: GemieChatSheetProps['welcomeSuggestions'];
61
+ children: ReactNode;
62
+ }
63
+
64
+ export interface GemieAsk {
65
+ /**
66
+ * Open the sheet on the agent `agentKey` (omitted, Alia), with `turn` already sent when given
67
+ * ("ask Sindi about this listing"). Signed out, opens Oxy's sign-in instead.
68
+ */
69
+ ask: (agentKey?: string, turn?: GemieTurn) => void;
70
+ /** Open the sheet on the agent `agentKey` (omitted, Alia), on its stored conversation `conversationId`. */
71
+ resume: (agentKey: string | undefined, conversationId: string) => void;
72
+ /**
73
+ * Close the sheet — a host tool that changed the page under it shows the person the result, once
74
+ * the turn has been written.
75
+ */
76
+ dismiss: () => void;
77
+ }
78
+
79
+ const AskContext = createContext<GemieAsk | null>(null);
80
+
81
+ /** The app's way to open its one Alia sheet. Must be used under `GemieAskProvider`. */
82
+ export function useAskGemie(): GemieAsk {
83
+ const ask = useContext(AskContext);
84
+ if (ask === null) throw new Error('useAskGemie must be used within a GemieAskProvider');
85
+ return ask;
86
+ }
87
+
88
+ /** The opening that waits for the sheet of agent `key` to be the one mounted. */
89
+ interface Opening extends GemieAskOpening {
90
+ key: string | undefined;
91
+ }
92
+
93
+ /** The sheet a provider mounts: `GemieAskSheet`, imported statically or behind `lazy` + `Suspense`. */
94
+ export type AskSheetComponent = ComponentType<
95
+ GemieAskSheetProps & RefAttributes<GemieChatSheetRef>
96
+ >;
97
+
98
+ /**
99
+ * Builds the provider around `Sheet`. `preload`, when given, fetches the sheet's module in the
100
+ * background once signed in, so the first `ask` does not wait on the network.
101
+ */
102
+ export function createAskProvider(Sheet: AskSheetComponent, preload?: () => Promise<unknown>) {
103
+ /**
104
+ * Mounts the app's one sheet. Its ref is the same `GemieAsk` as `useAskGemie()`, for the code
105
+ * that configures the sheet and so sits above it — a host-tool executor that closes it.
106
+ */
107
+ return forwardRef<GemieAsk, GemieAskProviderProps>(function GemieAskProvider(
108
+ { agents, welcomeSuggestions, children, labels, ...sheet },
109
+ ref,
110
+ ) {
111
+ const { canUsePrivateApi, signIn } = useAuth();
112
+ const { currentLanguage } = useOxy();
113
+ const localizedLabels = useMemo(
114
+ () => ({ ...labels, locale: labels?.locale ?? currentLanguage }),
115
+ [labels, currentLanguage],
116
+ );
117
+ const sheetRef = useRef<GemieChatSheetRef>(null);
118
+ const [opening, setOpening] = useState<Opening | null>(null);
119
+ const [current, setCurrent] = useState<string | undefined>(undefined);
120
+ /** Nothing is mounted before the first `ask`. */
121
+ const [asked, setAsked] = useState(false);
122
+ const agentsRef = useRef(agents);
123
+ agentsRef.current = agents;
124
+
125
+ const open = useCallback(
126
+ (agentKey: string | undefined, turn?: GemieTurn, conversationId?: string) => {
127
+ if (agentKey !== undefined && agentsRef.current?.[agentKey] === undefined) {
128
+ throw new Error(`GemieAskProvider has no agent "${agentKey}"`);
129
+ }
130
+ if (!canUsePrivateApi) {
131
+ void signIn().catch(() => undefined);
132
+ return;
133
+ }
134
+ setAsked(true);
135
+ setCurrent(agentKey);
136
+ setOpening((previous) => ({
137
+ key: agentKey,
138
+ turn,
139
+ ...(conversationId === undefined ? {} : { conversationId }),
140
+ serial: (previous?.serial ?? 0) + 1,
141
+ }));
142
+ },
143
+ [canUsePrivateApi, signIn],
144
+ );
145
+ const ask = useCallback((agentKey?: string, turn?: GemieTurn) => open(agentKey, turn), [open]);
146
+ const resume = useCallback(
147
+ (agentKey: string | undefined, conversationId: string) =>
148
+ open(agentKey, undefined, conversationId),
149
+ [open],
150
+ );
151
+ const dismiss = useCallback(() => sheetRef.current?.dismiss(), []);
152
+
153
+ const opened = useCallback(() => setOpening(null), []);
154
+
155
+ // Signed in, the sheet's module comes down in the background, ahead of the first `ask`.
156
+ useEffect(() => {
157
+ if (canUsePrivateApi && preload !== undefined) void preload().catch(() => undefined);
158
+ }, [canUsePrivateApi]);
159
+
160
+ const agentId = current === undefined ? undefined : agents?.[current]?.id;
161
+ const agent = useMemo(() => (agentId === undefined ? undefined : { id: agentId }), [agentId]);
162
+ const value = useMemo<GemieAsk>(() => ({ ask, resume, dismiss }), [ask, resume, dismiss]);
163
+ useImperativeHandle(ref, () => value, [value]);
164
+
165
+ return (
166
+ <AskContext.Provider value={value}>
167
+ {children}
168
+ {canUsePrivateApi && asked ? (
169
+ <Sheet
170
+ key={agentId ?? 'alia'}
171
+ ref={sheetRef}
172
+ {...sheet}
173
+ labels={localizedLabels}
174
+ agent={agent}
175
+ welcomeSuggestions={agent === undefined ? welcomeSuggestions : undefined}
176
+ // A different agent is a new sheet: the opening waits for that one to mount.
177
+ opening={opening !== null && opening.key === current ? opening : null}
178
+ onOpened={opened}
179
+ />
180
+ ) : null}
181
+ </AskContext.Provider>
182
+ );
183
+ });
184
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The ask provider of the root entry (`@gemies/sdk`): its sheet is a static import.
3
+ *
4
+ * The root entry already holds the whole chat, so loading `GemieAskSheet` lazily here would save
5
+ * nothing and cost a lot on web: it is an async chunk boundary inside the SDK, and Metro hoists
6
+ * every module two async chunks share into `__common.js`, which loads at first paint. An app that
7
+ * lazy-loads its Alia sheet would then get the chat (and the Bloom it draws with) in its first
8
+ * paint. An app that wants the chat out of its entry bundle mounts the provider from
9
+ * `@gemies/sdk/ask` (`GemieAskProviderLazy`) instead. See `GemieAskCore` for the provider itself.
10
+ */
11
+
12
+ import { createAskProvider } from './GemieAskCore';
13
+ import { GemieAskSheet } from './GemieAskSheetWithVoice';
14
+
15
+ export type { GemieAsk, GemieAskAgents, GemieAskProviderProps } from './GemieAskCore';
16
+ export { useAskGemie } from './GemieAskCore';
17
+
18
+ export const GemieAskProvider = createAskProvider(GemieAskSheet);
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The ask provider of `@gemies/sdk/ask`: its sheet is loaded lazily and mounted on the first
3
+ * `ask`, so an app that mounts this provider at its root keeps the chat out of its entry bundle.
4
+ * Signed in, the sheet's module is fetched in the background so the first `ask` does not wait on
5
+ * the network.
6
+ *
7
+ * This `import()` is the ONE async boundary the SDK draws, and only for this entry (and
8
+ * `@gemies/sdk/ask/text`): everything behind it (`GemieAskSheetWithVoice` and the chat) imports statically on web, so Metro emits one chunk for
9
+ * the sheet and hoists nothing of it into `__common.js` (`scripts/check-entry-isolation.mjs`).
10
+ */
11
+
12
+ import { lazy, Suspense } from 'react';
13
+ import { type AskSheetComponent, createAskProvider } from './GemieAskCore';
14
+
15
+ const loadSheet = () => import('./GemieAskSheetWithVoice');
16
+ const LazyAskSheet = lazy(() => loadSheet().then((module) => ({ default: module.GemieAskSheet })));
17
+
18
+ const SuspendedAskSheet: AskSheetComponent = (props) => (
19
+ <Suspense fallback={null}>
20
+ <LazyAskSheet {...props} />
21
+ </Suspense>
22
+ );
23
+
24
+ export type { GemieAsk, GemieAskAgents, GemieAskProviderProps } from './GemieAskCore';
25
+ export { useAskGemie } from './GemieAskCore';
26
+
27
+ export const GemieAskProvider = createAskProvider(SuspendedAskSheet, loadSheet);
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The ask provider of `@gemies/sdk/ask/text`: `GemieAskProviderLazy` without the voice call. Its
3
+ * sheet is loaded lazily, with the first `ask`, and neither the provider nor the sheet reaches the
4
+ * call's modules, so a text-only app bundles none of them.
5
+ *
6
+ * Its `import()` is the one async boundary of this entry, as in `GemieAskProviderLazy`: behind it
7
+ * everything imports statically on web (`scripts/check-entry-isolation.mjs`).
8
+ */
9
+
10
+ import { lazy, Suspense } from 'react';
11
+ import { type AskSheetComponent, createAskProvider } from './GemieAskCore';
12
+
13
+ const loadSheet = () => import('./GemieAskSheet');
14
+ const LazyAskSheet = lazy(() => loadSheet().then((module) => ({ default: module.GemieAskSheet })));
15
+
16
+ const SuspendedAskSheet: AskSheetComponent = (props) => (
17
+ <Suspense fallback={null}>
18
+ <LazyAskSheet {...props} />
19
+ </Suspense>
20
+ );
21
+
22
+ export type { GemieAsk, GemieAskAgents, GemieAskProviderProps } from './GemieAskCore';
23
+ export { useAskGemie } from './GemieAskCore';
24
+
25
+ export const GemieAskProvider = createAskProvider(SuspendedAskSheet, loadSheet);