@gemies/sdk 0.0.0-stage → 1.0.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 (242) hide show
  1. package/CHANGELOG.md +1662 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +15 -0
  4. package/README.md +516 -2
  5. package/package.json +102 -4
  6. package/src/animations.ts +5 -0
  7. package/src/ask-eager.ts +8 -0
  8. package/src/ask-text.ts +11 -0
  9. package/src/ask.ts +12 -0
  10. package/src/avatar.ts +13 -0
  11. package/src/character.ts +1 -0
  12. package/src/components/AmbientField.tsx +580 -0
  13. package/src/components/ComposerDropZone.tsx +235 -0
  14. package/src/components/ComposerSuggestions.tsx +45 -0
  15. package/src/components/GemieAskCore.tsx +184 -0
  16. package/src/components/GemieAskProvider.tsx +18 -0
  17. package/src/components/GemieAskProviderLazy.tsx +27 -0
  18. package/src/components/GemieAskProviderText.tsx +25 -0
  19. package/src/components/GemieAskSheet.tsx +51 -0
  20. package/src/components/GemieAskSheetWithVoice.tsx +10 -0
  21. package/src/components/GemieAvatar.tsx +57 -0
  22. package/src/components/GemieAvatarIcon.tsx +35 -0
  23. package/src/components/GemieChatContent.tsx +900 -0
  24. package/src/components/GemieChatHeader.tsx +123 -0
  25. package/src/components/GemieChatScreen.tsx +170 -0
  26. package/src/components/GemieChatSheet.tsx +368 -0
  27. package/src/components/GemieChatWithVoice.tsx +13 -0
  28. package/src/components/GemieComposer.tsx +388 -0
  29. package/src/components/GemieGroupWelcome.tsx +37 -0
  30. package/src/components/GemieParticipants.tsx +133 -0
  31. package/src/components/GemieParticipantsHeader.tsx +27 -0
  32. package/src/components/GemieRecentConversations.tsx +65 -0
  33. package/src/components/GemieSharedConversation.tsx +87 -0
  34. package/src/components/GemieWelcomeMessage.tsx +58 -0
  35. package/src/components/IdentityMark.tsx +225 -0
  36. package/src/components/Image.tsx +12 -0
  37. package/src/components/InertWhen.tsx +48 -0
  38. package/src/components/PlanPreviewCard.tsx +53 -0
  39. package/src/components/QuestionCard.tsx +64 -0
  40. package/src/components/ReplyMarkdown.tsx +373 -0
  41. package/src/components/RichBlocks.tsx +195 -0
  42. package/src/components/VoiceModeIcon.tsx +18 -0
  43. package/src/components/canvas/CanvasComponent.tsx +65 -0
  44. package/src/components/canvas/ChartRenderer.tsx +73 -0
  45. package/src/components/canvas/CodeRenderer.tsx +20 -0
  46. package/src/components/canvas/DashboardRenderer.tsx +70 -0
  47. package/src/components/canvas/DeckRenderer.tsx +43 -0
  48. package/src/components/canvas/FormRenderer.tsx +101 -0
  49. package/src/components/canvas/MarkdownRenderer.tsx +14 -0
  50. package/src/components/canvas/TableRenderer.tsx +47 -0
  51. package/src/components/icons/RiEmojiPicker.tsx +39 -0
  52. package/src/components/icons/RiMoreDots.tsx +32 -0
  53. package/src/components/icons/RiReplyLine.tsx +25 -0
  54. package/src/components/thought/FilesAndSources.tsx +120 -0
  55. package/src/components/thought/ThoughtPanel.tsx +426 -0
  56. package/src/components/thought/ToolStep.tsx +134 -0
  57. package/src/components/thread/AgentExchangeView.tsx +112 -0
  58. package/src/components/thread/AgentResultCard.tsx +125 -0
  59. package/src/components/thread/AgentTaskCard.tsx +127 -0
  60. package/src/components/thread/ChatBubble.tsx +256 -0
  61. package/src/components/thread/GemieThread.tsx +455 -0
  62. package/src/components/thread/MessageBlockBoundary.tsx +78 -0
  63. package/src/components/thread/NewConversationOffer.tsx +54 -0
  64. package/src/components/thread/ThreadRow.tsx +598 -0
  65. package/src/components/thread/ThreadSearch.tsx +130 -0
  66. package/src/components/thread/ThreadSkeleton.tsx +30 -0
  67. package/src/components/thread/ToolResultCard.tsx +254 -0
  68. package/src/components/thread/TurnMenu.tsx +54 -0
  69. package/src/components/thread/TurnStatusLine.tsx +34 -0
  70. package/src/components/voice/GemieVoiceCall.tsx +21 -0
  71. package/src/components/voice/GemieVoiceCall.web.tsx +17 -0
  72. package/src/components/voice/VoiceCallContext.ts +13 -0
  73. package/src/components/voice/VoiceControls.tsx +106 -0
  74. package/src/components/voice/VoiceSession.tsx +120 -0
  75. package/src/components/voice/withVoiceCall.tsx +25 -0
  76. package/src/csp.ts +50 -0
  77. package/src/dictation.ts +40 -0
  78. package/src/hooks/useAmbientWave.ts +184 -0
  79. package/src/hooks/useAtBottom.ts +51 -0
  80. package/src/hooks/useAttachMenu.ts +93 -0
  81. package/src/hooks/useAttachmentIntake.ts +401 -0
  82. package/src/hooks/useAudioLevelMonitor.ts +46 -0
  83. package/src/hooks/useAudioLevels.ts +51 -0
  84. package/src/hooks/useChatComposer.ts +309 -0
  85. package/src/hooks/useChatVoice.ts +129 -0
  86. package/src/hooks/useComposerSuggestions.ts +84 -0
  87. package/src/hooks/useDictation.ts +292 -0
  88. package/src/hooks/useDocumentPicker.ts +11 -0
  89. package/src/hooks/useFailedTurnToast.ts +43 -0
  90. package/src/hooks/useFocusWhenPresented.ts +41 -0
  91. package/src/hooks/useGemieActivity.ts +31 -0
  92. package/src/hooks/useImagePicker.ts +38 -0
  93. package/src/hooks/useMessageReactions.ts +119 -0
  94. package/src/hooks/useMessageVote.ts +50 -0
  95. package/src/hooks/useOpenThought.ts +79 -0
  96. package/src/hooks/usePendingQuestions.ts +19 -0
  97. package/src/hooks/useReadAloud.ts +92 -0
  98. package/src/hooks/useShareHandler.ts +24 -0
  99. package/src/hooks/useSoundEffects.ts +137 -0
  100. package/src/hooks/useTTS.ts +303 -0
  101. package/src/hooks/useThoughtScope.ts +59 -0
  102. package/src/hooks/useThreadRows.ts +157 -0
  103. package/src/hooks/useThreadView.ts +67 -0
  104. package/src/hooks/useTimelineWindow.ts +256 -0
  105. package/src/hooks/useVoiceLauncher.ts +180 -0
  106. package/src/hooks/useVoiceRoom.ts +212 -0
  107. package/src/index.ts +140 -0
  108. package/src/lib/activity-socket.ts +102 -0
  109. package/src/lib/activity-store.ts +53 -0
  110. package/src/lib/add-menu.ts +7 -0
  111. package/src/lib/agent-character.ts +28 -0
  112. package/src/lib/alia-character.ts +14 -0
  113. package/src/lib/attachment-intake.ts +154 -0
  114. package/src/lib/attachment-tiles.ts +74 -0
  115. package/src/lib/audio-level.ts +130 -0
  116. package/src/lib/audio-request-auth.ts +4 -0
  117. package/src/lib/audio-session-binding.ts +27 -0
  118. package/src/lib/bubbles.tsx +16 -0
  119. package/src/lib/call-thread.ts +33 -0
  120. package/src/lib/canvas-result.ts +21 -0
  121. package/src/lib/catalogue-tool.ts +22 -0
  122. package/src/lib/citations.ts +192 -0
  123. package/src/lib/clipboard.ts +23 -0
  124. package/src/lib/content-utils.ts +46 -0
  125. package/src/lib/copy-en.ts +291 -0
  126. package/src/lib/copy-es.ts +287 -0
  127. package/src/lib/copy.ts +38 -0
  128. package/src/lib/deferred/document-picker.ts +2 -0
  129. package/src/lib/deferred/document-picker.web.ts +12 -0
  130. package/src/lib/deferred/expo-audio.ts +2 -0
  131. package/src/lib/deferred/expo-audio.web.ts +12 -0
  132. package/src/lib/deferred/image-data-url.ts +5 -0
  133. package/src/lib/deferred/image-data-url.web.ts +12 -0
  134. package/src/lib/dictation-protocol.ts +142 -0
  135. package/src/lib/dictation-recorder-types.ts +37 -0
  136. package/src/lib/dictation-recorder.native.ts +90 -0
  137. package/src/lib/dictation-recorder.ts +131 -0
  138. package/src/lib/dictation-stream.ts +238 -0
  139. package/src/lib/dictation.ts +216 -0
  140. package/src/lib/document-picker.ts +31 -0
  141. package/src/lib/domain.ts +12 -0
  142. package/src/lib/flights.ts +33 -0
  143. package/src/lib/focus-return.ts +66 -0
  144. package/src/lib/greeting.ts +15 -0
  145. package/src/lib/image-data-url.ts +35 -0
  146. package/src/lib/keyboard.native.tsx +25 -0
  147. package/src/lib/keyboard.tsx +55 -0
  148. package/src/lib/labels-es.ts +113 -0
  149. package/src/lib/labels.tsx +207 -0
  150. package/src/lib/origins.ts +28 -0
  151. package/src/lib/participants.ts +97 -0
  152. package/src/lib/pcm.ts +57 -0
  153. package/src/lib/power-level-options.ts +66 -0
  154. package/src/lib/questions.ts +92 -0
  155. package/src/lib/speech-language.ts +20 -0
  156. package/src/lib/speech-messages.ts +54 -0
  157. package/src/lib/speech-synthesis.ts +156 -0
  158. package/src/lib/suggestions.ts +53 -0
  159. package/src/lib/task-labels.ts +35 -0
  160. package/src/lib/text-input.ts +10 -0
  161. package/src/lib/tool-call-status.ts +28 -0
  162. package/src/lib/tool-icons.ts +36 -0
  163. package/src/lib/tool-registry.ts +71 -0
  164. package/src/lib/tool-renderers.tsx +32 -0
  165. package/src/lib/turn-state.ts +15 -0
  166. package/src/lib/utils.ts +35 -0
  167. package/src/lib/voice-audio-engine-types.ts +59 -0
  168. package/src/lib/voice-audio-engine.native.ts +232 -0
  169. package/src/lib/voice-audio-engine.ts +206 -0
  170. package/src/lib/voice-call-request.ts +49 -0
  171. package/src/lib/voice-call.ts +627 -0
  172. package/src/lib/voice-controls-labels.ts +31 -0
  173. package/src/lib/voice-levels.ts +64 -0
  174. package/src/lib/voice-protocol.ts +328 -0
  175. package/src/lib/voice-worklets.ts +19 -0
  176. package/src/lib/work-log.ts +370 -0
  177. package/src/metro/chart-importers.json +18 -0
  178. package/src/metro/granular-charts.js +3 -0
  179. package/src/metro/index.cjs +227 -0
  180. package/src/metro/index.d.cts +5 -0
  181. package/src/runtime/agents.ts +151 -0
  182. package/src/runtime/api.ts +144 -0
  183. package/src/runtime/app-assertion.ts +51 -0
  184. package/src/runtime/attachment-utils.ts +97 -0
  185. package/src/runtime/chat-turn-control.ts +74 -0
  186. package/src/runtime/composer-draft-store.ts +270 -0
  187. package/src/runtime/config.tsx +222 -0
  188. package/src/runtime/conversation-dates.ts +31 -0
  189. package/src/runtime/conversation-store.ts +49 -0
  190. package/src/runtime/conversations.ts +633 -0
  191. package/src/runtime/error-utils.ts +144 -0
  192. package/src/runtime/host-tools.ts +290 -0
  193. package/src/runtime/index.ts +137 -0
  194. package/src/runtime/message-history.ts +124 -0
  195. package/src/runtime/message-reactions.ts +214 -0
  196. package/src/runtime/model.ts +39 -0
  197. package/src/runtime/oxy-files.ts +37 -0
  198. package/src/runtime/power-levels.ts +66 -0
  199. package/src/runtime/query-keys.ts +49 -0
  200. package/src/runtime/random-uuid.ts +25 -0
  201. package/src/runtime/reaction-cache.ts +45 -0
  202. package/src/runtime/room-events.ts +333 -0
  203. package/src/runtime/routes.ts +81 -0
  204. package/src/runtime/sharing.ts +217 -0
  205. package/src/runtime/sse-frame-reader.ts +88 -0
  206. package/src/runtime/stream-events.ts +154 -0
  207. package/src/runtime/stream-outcome.ts +21 -0
  208. package/src/runtime/thought-store.ts +103 -0
  209. package/src/runtime/thread/agent-activity.ts +261 -0
  210. package/src/runtime/thread/agent-exchange.ts +94 -0
  211. package/src/runtime/thread/automation-labels.ts +79 -0
  212. package/src/runtime/thread/conversation-export.ts +135 -0
  213. package/src/runtime/thread/message-days.ts +120 -0
  214. package/src/runtime/thread/message-processor.ts +93 -0
  215. package/src/runtime/thread/speaker-changes.ts +66 -0
  216. package/src/runtime/thread/task-utils.ts +11 -0
  217. package/src/runtime/thread/thought-utils.ts +750 -0
  218. package/src/runtime/thread/thread-history.ts +139 -0
  219. package/src/runtime/thread/timeline.ts +202 -0
  220. package/src/runtime/thread/title-tags.ts +8 -0
  221. package/src/runtime/thread/tool-cards.ts +387 -0
  222. package/src/runtime/turn-failure.ts +108 -0
  223. package/src/runtime/turn-preparation.ts +21 -0
  224. package/src/runtime/types.ts +172 -0
  225. package/src/runtime/usage-limit-error.ts +44 -0
  226. package/src/runtime/use-agent-activity.ts +80 -0
  227. package/src/runtime/use-conversation-stream.ts +1669 -0
  228. package/src/runtime/use-conversation-thread.ts +590 -0
  229. package/src/runtime/use-gemie-thread.ts +54 -0
  230. package/src/runtime/use-room-events.ts +75 -0
  231. package/src/runtime/use-start-conversation.ts +107 -0
  232. package/src/runtime/use-thread-history.ts +73 -0
  233. package/src/runtime/use-thread-search.ts +100 -0
  234. package/src/runtime/use-turn-edit.ts +99 -0
  235. package/src/text.ts +19 -0
  236. package/src/theme.ts +16 -0
  237. package/src/tools.ts +27 -0
  238. package/src/types.ts +161 -0
  239. package/src/voice-messages.ts +2 -0
  240. package/src/voice.ts +67 -0
  241. package/tsconfig.json +17 -0
  242. package/worklets/voice-processors.js +152 -0
@@ -0,0 +1,388 @@
1
+ import {
2
+ useCallback,
3
+ useEffect,
4
+ useId,
5
+ useMemo,
6
+ useRef,
7
+ type ReactNode,
8
+ type RefObject,
9
+ } from 'react';
10
+ import { View, type TextInputKeyPressEvent } from 'react-native';
11
+ import type { ComposerLoaderPhase } from '@oxy.so/bloom/composer-loader';
12
+ import {
13
+ ComposerPill,
14
+ type ComposerPanelAddMenuGroup,
15
+ type ComposerPanelAttachment,
16
+ type ComposerPanelPermissionOption,
17
+ } from '@oxy.so/bloom/composer-panel';
18
+ import { ComposerLoader } from '@oxy.so/bloom/composer-loader';
19
+ import { toast } from '@oxy.so/bloom/toast';
20
+ import { Text } from '@oxy.so/bloom/typography';
21
+ import { useAttachmentIntake } from '../hooks/useAttachmentIntake';
22
+ import { useDictation } from '../hooks/useDictation';
23
+ import type { Completion } from '../lib/suggestions';
24
+ import { composerTiles, intakeError } from '../lib/attachment-tiles';
25
+ import type { IntakeKind } from '../lib/attachment-intake';
26
+ import { KeyboardAvoidingView } from '../lib/keyboard';
27
+ import type { TextInputHandle } from '../lib/text-input';
28
+ import { type GemieChatLabels, GemieChatLabelsProvider, useLabels } from '../lib/labels';
29
+ import type { AskedQuestion } from '../lib/questions';
30
+ import type { VoiceErrorCode } from '../lib/speech-messages';
31
+ import type { GemieAttachment, GemieSuggestion } from '../types';
32
+ import {
33
+ ComposerDropOverlay,
34
+ useComposerDropTarget,
35
+ useComposerPasteTarget,
36
+ } from './ComposerDropZone';
37
+ import { ComposerSuggestions } from './ComposerSuggestions';
38
+ import { QuestionCard } from './QuestionCard';
39
+
40
+ /**
41
+ * Alia's composer: the ONE composer of the sheet, the screen and the Alia app, Bloom's
42
+ * `ComposerPill` plus everything Alia puts around it.
43
+ *
44
+ * Everything the pill draws is Bloom's: the prompt, the add menu, the mode selector (the
45
+ * pill's permission picker, which is the host's power-level selector), the mic, send / stop, the
46
+ * attachment tiles and the status tab. What this adds is what every Alia surface needs the same
47
+ * way: files arriving by paste and drop (read with real progress, retried, refused with a
48
+ * sentence), dictation, the suggestions over the field, and the questions Alia asked docked
49
+ * above it. What differs per surface is a prop: the add menu and the modes are the host's,
50
+ * and a host that offers no way to attach files gets no paste or drop either.
51
+ *
52
+ * A running turn is the stop control and the container's thinking line; the panel takes no
53
+ * loader (Bloom's loader traces the pill, and would light the status tab too).
54
+ */
55
+ const EMPTY_ADD_MENU: readonly ComposerPanelAddMenuGroup[] = [];
56
+ /** `[]` hides the selector; Bloom's own four modes are not Alia's. */
57
+ const NO_MODES: readonly ComposerPanelPermissionOption[] = [];
58
+ const NO_ATTACHMENTS: readonly GemieAttachment[] = [];
59
+
60
+ /** The rows over the field, as `useComposerSuggestions` hands them back. */
61
+ export interface GemieComposerSuggestions<T extends GemieSuggestion = GemieSuggestion> {
62
+ completions: readonly Completion<T>[];
63
+ /** The row the keyboard is on, or -1. */
64
+ selected: number;
65
+ onPick: (suggestion: T) => void;
66
+ }
67
+
68
+ /** The questions Alia asked and the person has not answered (`usePendingQuestions`). */
69
+ export interface GemieComposerQuestions {
70
+ items: AskedQuestion[];
71
+ /** Sends the answers as the next message. */
72
+ onSubmit: (message: string) => void;
73
+ onDismiss: () => void;
74
+ }
75
+
76
+ export interface GemieComposerProps<T extends GemieSuggestion = GemieSuggestion> {
77
+ value: string;
78
+ onValueChange: (value: string) => void;
79
+ /** Sends the draft. */
80
+ onSubmit: () => void;
81
+ /** A turn is streaming: send becomes stop. */
82
+ busy?: boolean;
83
+ /** Request lifecycle sent to Bloom's decorative loader; request behavior remains controlled by `busy`. */
84
+ loaderPhase?: ComposerLoaderPhase;
85
+ /** The composer is closed (usage limit). Never reaches stop. */
86
+ disabled?: boolean;
87
+ onStop?: () => void;
88
+ placeholder?: string;
89
+ /** The mode selector (the power levels). Omit to hide it. */
90
+ modes?: readonly ComposerPanelPermissionOption[];
91
+ mode?: string;
92
+ onModeChange?: (mode: string) => void;
93
+ addMenu?: readonly ComposerPanelAddMenuGroup[];
94
+ onAddMenuSelect?: (rowId: string) => void;
95
+ /**
96
+ * The draft's files. A composer given no `onAddAttachment` takes none: its surface sends
97
+ * nothing but the text, so no paste, drop or tile may say otherwise.
98
+ */
99
+ attachments?: readonly GemieAttachment[];
100
+ onAddAttachment?: (attachment: GemieAttachment) => void;
101
+ onRemoveAttachment?: (id: string) => void;
102
+ /** The kinds of file the host's send carries; others are refused with a sentence. Default both. */
103
+ attachmentKinds?: readonly IntakeKind[];
104
+ /** The suggestions drawn over the field. Their keys are the host's `onKeyPress`. */
105
+ suggestions?: GemieComposerSuggestions<T>;
106
+ /** What Alia is waiting on, docked above the composer. */
107
+ questions?: GemieComposerQuestions;
108
+ /** The tab on the card's top edge (`ComposerPanelStatusTab`). */
109
+ status?: ReactNode;
110
+ /** Drawn where send would be while there is nothing to send (voice mode). */
111
+ emptyAction?: ReactNode;
112
+ /**
113
+ * Drawn over the conversation at the composer's top-right corner, and so pinned with it —
114
+ * the jump to the newest turn.
115
+ */
116
+ accessory?: ReactNode;
117
+ /** The field's keys, before the panel's own Enter rule (suggestions over it). */
118
+ onKeyPress?: (event: TextInputKeyPressEvent) => void;
119
+ /** The host already avoids the keyboard. */
120
+ disableKeyboardAvoidance?: boolean;
121
+ /** The field itself, for a host that moves focus into it. */
122
+ inputRef?: RefObject<TextInputHandle | null>;
123
+ /** Dictation's language, a BCP-47 tag; omitted, the platform's own. */
124
+ speechLanguage?: string;
125
+ /** The Gemies API, which transcribes dictation; omitted, `EXPO_PUBLIC_GEMIES_API_URL` or production. */
126
+ apiUrl?: string;
127
+ /** Where a refused file or a failed dictation is said; omitted, Bloom's toast. */
128
+ onError?: (message: string) => void;
129
+ /** The composer's copy, over whatever labels are already in reach. */
130
+ labels?: Partial<GemieChatLabels>;
131
+ }
132
+
133
+ function GemieComposerBody<T extends GemieSuggestion>({
134
+ value,
135
+ onValueChange,
136
+ onSubmit,
137
+ busy = false,
138
+ loaderPhase,
139
+ disabled = false,
140
+ onStop,
141
+ placeholder,
142
+ modes,
143
+ mode,
144
+ onModeChange,
145
+ addMenu,
146
+ onAddMenuSelect,
147
+ attachments = NO_ATTACHMENTS,
148
+ onAddAttachment,
149
+ onRemoveAttachment,
150
+ attachmentKinds,
151
+ suggestions,
152
+ questions,
153
+ status,
154
+ emptyAction,
155
+ accessory,
156
+ onKeyPress,
157
+ disableKeyboardAvoidance = false,
158
+ inputRef,
159
+ speechLanguage,
160
+ apiUrl,
161
+ onError,
162
+ }: Omit<GemieComposerProps<T>, 'labels'>) {
163
+ const labels = useLabels();
164
+ const report = useCallback(
165
+ (message: string) => (onError ? onError(message) : toast.error(message)),
166
+ [onError],
167
+ );
168
+ // Paste is a DOM gesture on a DOM node; the panel publishes no ref to one.
169
+ const hostId = `composer-${useId().replace(/[^a-zA-Z0-9]/g, '')}`;
170
+
171
+ // The list's owner releases what a removed tile held (the draft store does).
172
+ const takesFiles = onAddAttachment !== undefined;
173
+ const addAttachment = useCallback(
174
+ (attachment: GemieAttachment) => onAddAttachment?.(attachment),
175
+ [onAddAttachment],
176
+ );
177
+ const removeAttachment = useCallback(
178
+ (id: string) => onRemoveAttachment?.(id),
179
+ [onRemoveAttachment],
180
+ );
181
+ const intake = useAttachmentIntake({ addAttachment, kinds: attachmentKinds });
182
+ // A surface that takes no files still catches a drop or a pasted file, so
183
+ // the browser does not open it in place of the page — and then does nothing.
184
+ const acceptsFiles = takesFiles && !disabled && !busy;
185
+ useComposerPasteTarget({ elementId: hostId, enabled: acceptsFiles, onFiles: intake.accept });
186
+ // Web only; on native there is no drag, and the hook attaches nothing.
187
+ const isDragOver = useComposerDropTarget({
188
+ elementId: hostId,
189
+ enabled: acceptsFiles,
190
+ onFiles: intake.accept,
191
+ });
192
+
193
+ /**
194
+ * A refused file — too large, or empty — is said once, in a toast, and
195
+ * leaves the queue.
196
+ *
197
+ * It is not a tile because Bloom's retry is the PANEL's: with
198
+ * `onAttachmentRetry` set, every error tile draws a retry button, and a
199
+ * refusal has nothing to retry — the same file reaches the same verdict.
200
+ * A tile whose button does nothing is worse than a sentence.
201
+ * A failed READ stays, as an error tile whose retry re-reads its file.
202
+ */
203
+ useEffect(() => {
204
+ for (const item of intake.items) {
205
+ if (item.status !== 'refused') continue;
206
+ const error = intakeError(item, labels);
207
+ if (error !== undefined) report(error);
208
+ intake.dismiss(item.id);
209
+ }
210
+ }, [intake, labels, report]);
211
+
212
+ // Landed files, then the ones being read with their real progress, then the
213
+ // ones whose read failed, with why.
214
+ const tiles = useMemo<ComposerPanelAttachment[]>(
215
+ () =>
216
+ composerTiles(attachments, intake.items, labels)
217
+ .filter((tile) => tile.error === undefined || tile.retryable === true)
218
+ .map(({ retryable: _retryable, ...tile }) => tile),
219
+ [attachments, intake.items, labels],
220
+ );
221
+ const removeTile = useCallback(
222
+ (id: string) => {
223
+ if (intake.items.some((item) => item.id === id)) intake.cancel(id);
224
+ else removeAttachment(id);
225
+ },
226
+ [intake, removeAttachment],
227
+ );
228
+
229
+ // The draft at the moment the transcription lands, not when the mic was pressed.
230
+ const draftRef = useRef(value);
231
+ draftRef.current = value;
232
+ const insertDictation = useCallback(
233
+ (text: string) => {
234
+ const draft = draftRef.current;
235
+ onValueChange(draft === '' ? text : `${draft} ${text}`);
236
+ },
237
+ [onValueChange],
238
+ );
239
+ const dictation = useDictation({
240
+ lang: speechLanguage,
241
+ ...(apiUrl === undefined ? {} : { apiUrl }),
242
+ onText: insertDictation,
243
+ });
244
+ // Said once per failure: a host re-rendering with new labels is not a new failure.
245
+ const sayVoiceError = useRef<(code: VoiceErrorCode, retry: (() => void) | null) => void>(
246
+ () => undefined,
247
+ );
248
+ sayVoiceError.current = (code, retry) => {
249
+ const message = labels.voiceError(code);
250
+ if (onError || retry === null) report(message);
251
+ else toast.error(message, { action: { label: labels.composerRetry, onClick: retry } });
252
+ };
253
+ const {
254
+ errorCode: dictationError,
255
+ canRetry: dictationCanRetry,
256
+ retry: retryDictation,
257
+ } = dictation;
258
+ useEffect(() => {
259
+ if (dictationError !== null)
260
+ sayVoiceError.current(dictationError, dictationCanRetry ? () => void retryDictation() : null);
261
+ }, [dictationError, dictationCanRetry, retryDictation]);
262
+
263
+ const handleListeningChange = useCallback(
264
+ async (next: boolean) => {
265
+ if (next) {
266
+ if (!disabled && !busy && !dictation.isTranscribing) void dictation.start();
267
+ return;
268
+ }
269
+ await dictation.stop();
270
+ },
271
+ [disabled, busy, dictation],
272
+ );
273
+ const remainingSeconds =
274
+ dictation.remainingMs === null ? null : Math.ceil(dictation.remainingMs / 1000);
275
+
276
+ const hasContent = value.trim() !== '' || attachments.length > 0;
277
+ const panelLabels = useMemo(
278
+ () => ({
279
+ message: labels.composerMessage,
280
+ addMenu: labels.composerAddMenu,
281
+ permissions: labels.composerModes,
282
+ permissionMode: labels.composerModes,
283
+ voice: labels.composerVoice,
284
+ send: labels.composerSend,
285
+ stop: labels.composerStop,
286
+ remove: labels.composerRemove,
287
+ // Bloom names the button "<retry> <file name>".
288
+ retry: labels.composerRetry,
289
+ }),
290
+ [labels],
291
+ );
292
+
293
+ const host = (
294
+ // The transcript's column (Bloom's `AgentChat`: 768 at most, centred), so
295
+ // the composer and the conversation share one edge.
296
+ <View id={hostId} className="w-full max-w-[768px] self-center">
297
+ {remainingSeconds !== null ? (
298
+ <Text
299
+ className="mb-1 self-center text-sm text-text-secondary"
300
+ accessibilityLiveRegion="polite"
301
+ aria-live="polite"
302
+ >
303
+ {labels.dictationRemaining(remainingSeconds)}
304
+ </Text>
305
+ ) : null}
306
+ {questions && questions.items.length > 0 ? (
307
+ // Beside the loader, not through the pill's `question` slot: the light traces the box it
308
+ // wraps, so a question inside it would be ringed too.
309
+ <QuestionCard
310
+ questions={questions.items}
311
+ onSubmit={questions.onSubmit}
312
+ onDismiss={questions.onDismiss}
313
+ />
314
+ ) : null}
315
+ <ComposerLoader phase={loaderPhase ?? (busy ? 'streaming' : 'idle')}>
316
+ <ComposerPill
317
+ value={value}
318
+ onValueChange={onValueChange}
319
+ onSubmit={() => onSubmit()}
320
+ inputRef={inputRef}
321
+ busy={busy}
322
+ onStop={onStop}
323
+ disabled={disabled || intake.isBusy || !hasContent}
324
+ placeholder={placeholder ?? labels.placeholder('Alia')}
325
+ addMenu={addMenu ?? EMPTY_ADD_MENU}
326
+ onAddMenuSelect={onAddMenuSelect}
327
+ permissions={modes ?? NO_MODES}
328
+ permission={mode}
329
+ onPermissionChange={onModeChange}
330
+ voiceState={
331
+ dictation.isTranscribing
332
+ ? 'transcribing'
333
+ : dictation.isRecording || dictation.state === 'requesting-permission'
334
+ ? 'recording'
335
+ : 'idle'
336
+ }
337
+ onVoiceStateChange={(next) => void handleListeningChange(next === 'recording')}
338
+ attachments={tiles}
339
+ onRemoveAttachment={removeTile}
340
+ // Clears the tile's error and starts its progress again: `intake.retry`
341
+ // puts the item back to `reading` over the same `File`.
342
+ onAttachmentRetry={intake.retry}
343
+ status={status}
344
+ emptyAction={emptyAction}
345
+ onKeyPress={onKeyPress}
346
+ labels={panelLabels}
347
+ // The loader paints the pill's surface behind its light; the controls go frosted over it.
348
+ surface={false}
349
+ frosted={busy}
350
+ />
351
+ </ComposerLoader>
352
+ <ComposerDropOverlay visible={takesFiles && isDragOver} enabled={acceptsFiles} />
353
+ {accessory ? (
354
+ <View pointerEvents="box-none" className="absolute bottom-full right-0 mb-2">
355
+ {accessory}
356
+ </View>
357
+ ) : null}
358
+ </View>
359
+ );
360
+
361
+ return (
362
+ <>
363
+ {suggestions ? (
364
+ <ComposerSuggestions
365
+ completions={suggestions.completions}
366
+ selected={suggestions.selected}
367
+ onPick={suggestions.onPick}
368
+ />
369
+ ) : null}
370
+ {disableKeyboardAvoidance ? (
371
+ host
372
+ ) : (
373
+ <KeyboardAvoidingView behavior="padding">{host}</KeyboardAvoidingView>
374
+ )}
375
+ </>
376
+ );
377
+ }
378
+
379
+ export function GemieComposer<T extends GemieSuggestion = GemieSuggestion>({
380
+ labels,
381
+ ...props
382
+ }: GemieComposerProps<T>) {
383
+ return (
384
+ <GemieChatLabelsProvider labels={labels}>
385
+ <GemieComposerBody {...props} />
386
+ </GemieChatLabelsProvider>
387
+ );
388
+ }
@@ -0,0 +1,37 @@
1
+ import { useAvatarFlights } from '@oxy.so/bloom/avatar-flight';
2
+ import { SelectedAgentPreview } from '@oxy.so/bloom/multi-agent-chat';
3
+ import { Text, View } from 'react-native';
4
+ import { useMemo } from 'react';
5
+ import { useGemieFlights } from '../lib/flights';
6
+ import { useLabels } from '../lib/labels';
7
+ import type { GemieParticipant } from '../lib/participants';
8
+
9
+ /**
10
+ * The empty chat of a GROUP: its members together, as Bloom's multi-agent chat draws them (one
11
+ * large avatar, a trio, or a ring), above "A few minds, one conversation". Each avatar is named
12
+ * `empty:<agent id>` for the chat's flights, the anchor Bloom's own group chat flies from.
13
+ */
14
+ export function GemieGroupWelcome({ members }: { members: readonly GemieParticipant[] }) {
15
+ const { t } = useLabels();
16
+ const shared = useGemieFlights();
17
+ const own = useAvatarFlights();
18
+ const agents = useMemo(
19
+ () =>
20
+ members.map((member) => ({
21
+ id: member.id,
22
+ name: member.name,
23
+ label: '',
24
+ description: '',
25
+ avatar: member.character,
26
+ })),
27
+ [members],
28
+ );
29
+ return (
30
+ <View className="items-center gap-4">
31
+ <SelectedAgentPreview agents={agents} flights={shared ?? own} anchor="empty" />
32
+ <Text selectable={false} className="max-w-md shrink text-center text-4xl text-text-primary">
33
+ {t('chat.groupWelcome')}
34
+ </Text>
35
+ </View>
36
+ );
37
+ }
@@ -0,0 +1,133 @@
1
+ /**
2
+ * The conversation's participants: Bloom's `AgentProfile` with `[lead, ...joined]`, and the
3
+ * agents joining it (ADR 0020 §7).
4
+ *
5
+ * When the lead consults another agent (`alia.agent_start`), the agent's reply appears in the
6
+ * thread under its own identity (anchor `reply:<agentId>`), and that avatar flies into the header
7
+ * through Bloom's `useAvatarJoin`: one choreography for every multi-agent conversation, Bloom's
8
+ * own `MultiAgentChat` included. The header gains the agent only when its flight lands; with
9
+ * reduced motion, or when there is nothing to measure, it gains it at once. An agent already in
10
+ * the conversation when the chat opens is simply there.
11
+ *
12
+ * A GROUP's first message flies its members' avatars out of the empty chat the same way
13
+ * (`groupFirstSend`).
14
+ *
15
+ * This is the ONLY file that draws `AgentProfile` or joins agents to it (`one-thread.test.tsx`
16
+ * holds it), so the header of the sheet, the screen and the Alia app are one header.
17
+ */
18
+
19
+ import { AgentProfile } from '@oxy.so/bloom/agent-reply';
20
+ import {
21
+ type AvatarFlightSpec,
22
+ type AvatarFlights,
23
+ avatarJoinFlights,
24
+ useAvatarJoin,
25
+ } from '@oxy.so/bloom/avatar-flight';
26
+ import { memo, useMemo } from 'react';
27
+ import { ANCHORS, useGemieFlights } from '../lib/flights';
28
+ import {
29
+ type GemieChatParticipants,
30
+ type GemieLead,
31
+ type GemieParticipant,
32
+ consultedAgents,
33
+ } from '../lib/participants';
34
+ import type { Message } from '../runtime/types';
35
+
36
+ export interface UseParticipantsOptions {
37
+ lead: GemieLead;
38
+ messages: readonly Message[];
39
+ /** The chat's flights; `null` draws everybody in place without flying. */
40
+ flights: AvatarFlights | null;
41
+ }
42
+
43
+ /** How long the answering member's avatar takes to land on its reply. */
44
+ const REPLY_LANDING_MS = 800;
45
+
46
+ /**
47
+ * A group's first message, as Bloom's multi-agent chat flies it: the member that answers first
48
+ * lands on its reply (`reply:<id>`), the others merge into the header's participants. Each leaves
49
+ * the `empty:<id>` anchor the group's welcome draws.
50
+ */
51
+ export function groupFirstSend(members: readonly GemieParticipant[]): AvatarFlightSpec[] {
52
+ const [responder, ...waiting] = members;
53
+ if (responder === undefined) return [];
54
+ return [
55
+ {
56
+ key: responder.id,
57
+ character: responder.character,
58
+ from: `empty:${responder.id}`,
59
+ to: ANCHORS.reply(responder.id),
60
+ duration: REPLY_LANDING_MS,
61
+ },
62
+ ...avatarJoinFlights(waiting, {
63
+ from: (member) => `empty:${member.id}`,
64
+ to: ANCHORS.profile,
65
+ character: (member) => member.character,
66
+ }),
67
+ ];
68
+ }
69
+
70
+ const fromReply = (agent: GemieParticipant) => ANCHORS.reply(agent.id);
71
+ const characterOf = (agent: GemieParticipant) => agent.character;
72
+
73
+ /** Who the header shows: the lead, then the agents it consulted as each one's avatar lands. */
74
+ export function useParticipants({
75
+ lead,
76
+ messages,
77
+ flights,
78
+ }: UseParticipantsOptions): GemieChatParticipants {
79
+ const arrivals = useMemo(
80
+ () =>
81
+ consultedAgents(messages, lead.id).map(({ participant, live }) => ({
82
+ agent: participant,
83
+ live,
84
+ })),
85
+ [messages, lead.id],
86
+ );
87
+ const joined = useAvatarJoin({
88
+ arrivals,
89
+ flights,
90
+ from: fromReply,
91
+ to: ANCHORS.profile,
92
+ character: characterOf,
93
+ // A new lead is a new conversation: nobody has joined it.
94
+ resetKey: lead.id,
95
+ });
96
+ return useMemo(() => ({ lead, joined: [...joined] }), [lead, joined]);
97
+ }
98
+
99
+ export interface GemieParticipantsProps {
100
+ participants: GemieChatParticipants;
101
+ /** Pressing the profile. Omitted, every avatar in it waves. */
102
+ onPress?: () => void;
103
+ }
104
+
105
+ const noop = () => undefined;
106
+
107
+ /**
108
+ * The header's participants: the lead's avatar above its name, joined by the agents it consulted
109
+ * ("Alia + Sindi"). Place it in the chat's chrome; it is the conversation's title.
110
+ */
111
+ export const GemieParticipants = memo(function GemieParticipants({
112
+ participants,
113
+ onPress,
114
+ }: GemieParticipantsProps) {
115
+ const flights = useGemieFlights();
116
+ const agents = useMemo(
117
+ () =>
118
+ [participants.lead, ...participants.joined].map((agent) => ({
119
+ id: agent.id,
120
+ name: agent.name,
121
+ avatar: agent.character,
122
+ })),
123
+ [participants],
124
+ );
125
+ return (
126
+ <AgentProfile
127
+ agents={agents}
128
+ onPress={onPress ?? noop}
129
+ avatarRef={flights?.anchor(ANCHORS.profile)}
130
+ avatarHidden={flights?.isLanding(ANCHORS.profile)}
131
+ />
132
+ );
133
+ });
@@ -0,0 +1,27 @@
1
+ import { AiChatHeader } from '@oxy.so/bloom/ai-chat';
2
+ import { memo } from 'react';
3
+ import type { GemieChatParticipants } from '../lib/participants';
4
+ import { GemieParticipants } from './GemieParticipants';
5
+
6
+ export interface GemieParticipantsHeaderProps {
7
+ participants: GemieChatParticipants;
8
+ /** Pressing the participants. Omitted, every avatar in it waves. */
9
+ onPress?: () => void;
10
+ }
11
+
12
+ /**
13
+ * The conversation's header inside Bloom's AI chat shell: the participants as its title, in
14
+ * Bloom's `AiChatHeader`, between the shell's own navigation and panel buttons on a compact
15
+ * screen. A host puts this in `chrome.header` instead of drawing a title of its own. Outside a
16
+ * shell it is the participants alone.
17
+ */
18
+ export const GemieParticipantsHeader = memo(function GemieParticipantsHeader({
19
+ participants,
20
+ onPress,
21
+ }: GemieParticipantsHeaderProps) {
22
+ return (
23
+ <AiChatHeader>
24
+ <GemieParticipants participants={participants} onPress={onPress} />
25
+ </AiChatHeader>
26
+ );
27
+ });
@@ -0,0 +1,65 @@
1
+ import { Item } from '@oxy.so/bloom/item';
2
+ import { Text } from '@oxy.so/bloom/typography';
3
+ import { useMemo } from 'react';
4
+ import { View } from 'react-native';
5
+ import { useLabels } from '../lib/labels';
6
+ import { useGemieRuntime } from '../runtime/config';
7
+ import { useConversations } from '../runtime/conversations';
8
+
9
+ /** How many of the lead's conversations the sheet offers to pick up again. */
10
+ const RECENT_CONVERSATIONS_SHOWN = 3;
11
+
12
+ /**
13
+ * The person's latest conversations with the sheet's lead, under its greeting: "Ask Sindi" picks
14
+ * up where it left off instead of every opening being a blank page. Alia's own sheet lists the
15
+ * person's latest conversations of any kind. In an app's sheet (the chat's `app`) they are the ones
16
+ * started in that app: Mercaria's sheet offers Mercaria's, never a Homiio chat. Nothing while
17
+ * loading or when there are none.
18
+ */
19
+ export function GemieRecentConversations({
20
+ agentId,
21
+ onOpen,
22
+ }: {
23
+ /** The lead; omitted, Alia. */
24
+ agentId?: string;
25
+ onOpen: (conversationId: string) => void;
26
+ }) {
27
+ const labels = useLabels();
28
+ const { app } = useGemieRuntime();
29
+ const { data } = useConversations({
30
+ ...(agentId === undefined ? {} : { agentId }),
31
+ ...(app === undefined ? {} : { app }),
32
+ });
33
+ const recent = useMemo(
34
+ () => data?.pages[0]?.conversations.slice(0, RECENT_CONVERSATIONS_SHOWN) ?? [],
35
+ [data],
36
+ );
37
+ const when = useMemo(
38
+ () => new Intl.DateTimeFormat(labels.locale, { day: 'numeric', month: 'short' }),
39
+ [labels.locale],
40
+ );
41
+ if (recent.length === 0) return null;
42
+ return (
43
+ <View accessibilityRole="list" className="w-full max-w-[480px] self-center gap-1">
44
+ <Text className="px-3 text-sm text-text-secondary">{labels.recentConversations}</Text>
45
+ {recent.map((conversation) => {
46
+ const title = conversation.title || labels.newChat;
47
+ return (
48
+ <Item
49
+ key={conversation.id}
50
+ density="compact"
51
+ accessibilityRole="button"
52
+ accessibilityLabel={title}
53
+ onPress={() => onOpen(conversation.id)}
54
+ title={<Text numberOfLines={1}>{title}</Text>}
55
+ trailing={
56
+ <Text className="text-xs text-text-tertiary">
57
+ {when.format(new Date(conversation.updatedAt))}
58
+ </Text>
59
+ }
60
+ />
61
+ );
62
+ })}
63
+ </View>
64
+ );
65
+ }