@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,373 @@
1
+ import { CodeBlock } from '@oxy.so/bloom/code';
2
+ import { Markdown } from '@oxy.so/bloom/markdown';
3
+ import { Text } from '@oxy.so/bloom/typography';
4
+ import * as WebBrowser from 'expo-web-browser';
5
+ import { useMemo } from 'react';
6
+ import { Platform, Pressable, View } from 'react-native';
7
+ import {
8
+ type CitationSource,
9
+ extractCitationSources,
10
+ linkifyCitations,
11
+ type ReferenceEntry,
12
+ splitReferences,
13
+ } from '../lib/citations';
14
+ import { useLabels } from '../lib/labels';
15
+ import type { ToolInvocation } from '../runtime/types';
16
+ import { Banner, CompactList, Comparison, Credibility, RichImage, Timeline } from './RichBlocks';
17
+
18
+ // Cheap pre-check: plain markdown (the overwhelmingly common case) skips the
19
+ // six per-pattern regex scans below with a single pass.
20
+ const SPECIAL_BLOCK_HINT_RE =
21
+ /\[(?:ALIA_)?(?:COMPACTLIST|BANNER|COMPARISON|TIMELINE|IMAGE|CREDIBILITY)/;
22
+
23
+ // Parse special blocks from content
24
+ function parseSpecialBlocks(
25
+ content: string,
26
+ ): Array<{ type: 'text' | 'block'; content: string; blockType?: string; data?: any }> {
27
+ if (!SPECIAL_BLOCK_HINT_RE.test(content)) {
28
+ return [{ type: 'text', content }];
29
+ }
30
+
31
+ const blocks: Array<{ type: 'text' | 'block'; content: string; blockType?: string; data?: any }> =
32
+ [];
33
+
34
+ const patterns = [
35
+ {
36
+ name: 'COMPACTLIST',
37
+ regex: /\[(?:ALIA_)?COMPACTLIST title="([^"]+)"\]([\s\S]*?)\[\/(?:ALIA_)?COMPACTLIST\]/g,
38
+ },
39
+ {
40
+ name: 'BANNER',
41
+ regex: /\[(?:ALIA_)?BANNER type="([^"]+)" title="([^"]+)"\]([\s\S]*?)\[\/(?:ALIA_)?BANNER\]/g,
42
+ },
43
+ {
44
+ name: 'COMPARISON',
45
+ regex: /\[(?:ALIA_)?COMPARISON title="([^"]+)"\]([\s\S]*?)\[\/(?:ALIA_)?COMPARISON\]/g,
46
+ },
47
+ {
48
+ name: 'TIMELINE',
49
+ regex: /\[(?:ALIA_)?TIMELINE title="([^"]+)"\]([\s\S]*?)\[\/(?:ALIA_)?TIMELINE\]/g,
50
+ },
51
+ {
52
+ name: 'IMAGE',
53
+ regex:
54
+ /\[(?:ALIA_)?IMAGE url="([^"]+)"(?:\s+title="([^"]*)")?\s*(?:caption="([^"]*)")?\s*\/\]/g,
55
+ },
56
+ {
57
+ name: 'CREDIBILITY',
58
+ regex: /\[(?:ALIA_)?CREDIBILITY level="(\d+)" source="([^"]+)"\s*\/\]/g,
59
+ },
60
+ ];
61
+
62
+ let lastIndex = 0;
63
+ const matches: Array<{ index: number; length: number; block: any }> = [];
64
+
65
+ // Find all matches
66
+ patterns.forEach(({ name, regex }) => {
67
+ let match;
68
+ const regexCopy = new RegExp(regex.source, regex.flags);
69
+ while ((match = regexCopy.exec(content)) !== null) {
70
+ matches.push({
71
+ index: match.index,
72
+ length: match[0].length,
73
+ block: { type: name, match, fullMatch: match[0] },
74
+ });
75
+ }
76
+ });
77
+
78
+ // Sort matches by index
79
+ matches.sort((a, b) => a.index - b.index);
80
+
81
+ // Build blocks array
82
+ matches.forEach((m) => {
83
+ // Add text before block
84
+ if (lastIndex < m.index) {
85
+ const textContent = content.substring(lastIndex, m.index).trim();
86
+ if (textContent) {
87
+ blocks.push({ type: 'text', content: textContent });
88
+ }
89
+ }
90
+
91
+ // Add block
92
+ blocks.push({
93
+ type: 'block',
94
+ content: m.block.fullMatch,
95
+ blockType: m.block.type,
96
+ data: parseBlockData(m.block.type, m.block.match),
97
+ });
98
+
99
+ lastIndex = m.index + m.length;
100
+ });
101
+
102
+ // Add remaining text
103
+ if (lastIndex < content.length) {
104
+ const textContent = content.substring(lastIndex).trim();
105
+ if (textContent) {
106
+ blocks.push({ type: 'text', content: textContent });
107
+ }
108
+ }
109
+
110
+ // If no blocks found, return all as text
111
+ if (blocks.length === 0) {
112
+ blocks.push({ type: 'text', content });
113
+ }
114
+
115
+ return blocks;
116
+ }
117
+
118
+ function parseBlockData(type: string, match: RegExpExecArray): any {
119
+ try {
120
+ switch (type) {
121
+ case 'COMPACTLIST': {
122
+ const title = match[1];
123
+ const itemsText = match[2] ?? '';
124
+ const items = itemsText
125
+ .split('\n')
126
+ .filter((line) => line.trim().startsWith('-'))
127
+ .map((line) => {
128
+ try {
129
+ const jsonStr = line.trim().substring(1).trim();
130
+ return JSON.parse(jsonStr);
131
+ } catch {
132
+ return null;
133
+ }
134
+ })
135
+ .filter(Boolean);
136
+ return { title, items };
137
+ }
138
+ case 'BANNER': {
139
+ return {
140
+ type: match[1],
141
+ title: match[2],
142
+ content: (match[3] ?? '').trim(),
143
+ };
144
+ }
145
+ case 'COMPARISON': {
146
+ const title = match[1];
147
+ const content = match[2] ?? '';
148
+ const leftMatch = content.match(/LEFT:\s*({.*?})/s);
149
+ const rightMatch = content.match(/RIGHT:\s*({.*?})/s);
150
+ const conclusionMatch = content.match(/CONCLUSION:\s*(.*?)$/s);
151
+
152
+ return {
153
+ title,
154
+ left: leftMatch ? JSON.parse(leftMatch[1] ?? '') : {},
155
+ right: rightMatch ? JSON.parse(rightMatch[1] ?? '') : {},
156
+ conclusion: conclusionMatch ? (conclusionMatch[1] ?? '').trim() : undefined,
157
+ };
158
+ }
159
+ case 'TIMELINE': {
160
+ const title = match[1];
161
+ const itemsText = match[2] ?? '';
162
+ const items = itemsText
163
+ .split('\n')
164
+ .filter((line) => line.trim().startsWith('-'))
165
+ .map((line) => {
166
+ try {
167
+ const jsonStr = line.trim().substring(1).trim();
168
+ return JSON.parse(jsonStr);
169
+ } catch {
170
+ return null;
171
+ }
172
+ })
173
+ .filter(Boolean);
174
+ return { title, items };
175
+ }
176
+ case 'IMAGE': {
177
+ return {
178
+ url: match[1],
179
+ title: match[2] || undefined,
180
+ caption: match[3] || undefined,
181
+ };
182
+ }
183
+ case 'CREDIBILITY': {
184
+ return {
185
+ level: parseInt(match[1] ?? '', 10),
186
+ source: match[2],
187
+ };
188
+ }
189
+ default:
190
+ return {};
191
+ }
192
+ } catch (e) {
193
+ console.error('Error parsing block data:', e);
194
+ return {};
195
+ }
196
+ }
197
+
198
+ function renderBlock(blockType: string, data: any, key: number) {
199
+ switch (blockType) {
200
+ case 'COMPACTLIST':
201
+ return <CompactList key={key} {...data} />;
202
+ case 'BANNER':
203
+ return <Banner key={key} {...data} />;
204
+ case 'COMPARISON':
205
+ return <Comparison key={key} {...data} />;
206
+ case 'TIMELINE':
207
+ return <Timeline key={key} {...data} />;
208
+ case 'IMAGE':
209
+ return <RichImage key={key} {...data} />;
210
+ case 'CREDIBILITY':
211
+ return <Credibility key={key} {...data} />;
212
+ default:
213
+ return null;
214
+ }
215
+ }
216
+
217
+ /** Open a source the way the Sources tab does: a new tab on web, the in-app browser on native. */
218
+ function openSource(url: string): void {
219
+ if (Platform.OS === 'web') {
220
+ window.open(url, '_blank', 'noopener,noreferrer');
221
+ } else {
222
+ void WebBrowser.openBrowserAsync(url);
223
+ }
224
+ }
225
+
226
+ /**
227
+ * The references section of a research answer, as links.
228
+ *
229
+ * The API writes each entry as a Markdown link. The section is cut off the
230
+ * Markdown and drawn here as a list of sources rather than running text: one
231
+ * `accessibilityRole="link"` per entry — an `<a href>` on web, so Tab reaches
232
+ * it and Enter opens it — named "Source n: title", with its domain. Older
233
+ * answers, whose entries were a title over a bare URL, split the same way.
234
+ */
235
+ function ReferenceList({
236
+ entries,
237
+ onCitationPress,
238
+ }: {
239
+ entries: ReferenceEntry[];
240
+ onCitationPress?: (source: CitationSource) => void;
241
+ }) {
242
+ const { t } = useLabels();
243
+ return (
244
+ <View className="mt-3 gap-1 border-t border-border pt-3" accessibilityRole="list">
245
+ <Text className="text-xs font-medium text-muted-foreground">{t('thought.references')}</Text>
246
+ {entries.map((entry) => {
247
+ const press = () => {
248
+ if (onCitationPress) onCitationPress(entry);
249
+ else openSource(entry.url);
250
+ };
251
+ // On web the anchor itself navigates (new tab, no opener); `onPress`
252
+ // is wired only when the caller wants the press instead of the
253
+ // navigation, and the default is then prevented.
254
+ const webAnchor =
255
+ Platform.OS === 'web'
256
+ ? ({
257
+ href: entry.url,
258
+ hrefAttrs: { target: '_blank', rel: 'noopener noreferrer' },
259
+ } as object)
260
+ : {};
261
+ const onPress =
262
+ Platform.OS === 'web'
263
+ ? onCitationPress
264
+ ? (e: { preventDefault?: () => void }) => {
265
+ e.preventDefault?.();
266
+ press();
267
+ }
268
+ : undefined
269
+ : press;
270
+ return (
271
+ <Pressable
272
+ key={entry.id}
273
+ accessibilityRole="link"
274
+ accessibilityLabel={t('thought.sourceLabel', { n: entry.id, title: entry.title })}
275
+ className="flex-row items-start gap-2 rounded-md py-0.5 active:opacity-70"
276
+ onPress={onPress}
277
+ {...webAnchor}
278
+ >
279
+ <Text className="text-sm text-muted-foreground">[{entry.id}]</Text>
280
+ <Text className="flex-1 text-sm text-primary underline" numberOfLines={2}>
281
+ {entry.title}
282
+ </Text>
283
+ <Text className="text-xs text-muted-foreground" numberOfLines={1}>
284
+ {entry.domain}
285
+ </Text>
286
+ </Pressable>
287
+ );
288
+ })}
289
+ </View>
290
+ );
291
+ }
292
+
293
+ /**
294
+ * Fenced code as Bloom's code card: the language chip, a copy button and
295
+ * numbered lines. Module-level so its identity is stable, as Bloom's
296
+ * `Markdown` asks of `renderCodeBlock`.
297
+ */
298
+ const renderCodeBlock = (code: string, language?: string) => (
299
+ <CodeBlock code={code} language={language} />
300
+ );
301
+
302
+ /**
303
+ * The chat's Markdown, plus what a research answer needs on top of it.
304
+ *
305
+ * `toolInvocations` (the message's persisted record) and `researchSources`
306
+ * (the live progress event, before persistence) are where the `[n]` markers
307
+ * resolve: a marker naming a known source becomes a link to it, titled
308
+ * "Source n: title", and the References section becomes the accessible list
309
+ * above. Markers the model spelled as `【n†…】` or `[n, m]` in an older answer
310
+ * are normalised first. A message with neither prop renders exactly as
311
+ * before.
312
+ *
313
+ * `onCitationPress` replaces opening a source's URL, for the references list
314
+ * and for an inline marker alike; any other link opens as Bloom's `Markdown`
315
+ * opens it. `streaming` is the reply still arriving: Bloom's `Markdown` closes
316
+ * an unfinished trailing construct instead of showing its raw markers.
317
+ */
318
+ export function ReplyMarkdown({
319
+ content,
320
+ toolInvocations,
321
+ researchSources,
322
+ onCitationPress,
323
+ streaming = false,
324
+ size = 'lg',
325
+ }: {
326
+ content: string;
327
+ toolInvocations?: ToolInvocation[];
328
+ researchSources?: Array<{ id: number; url: string; title: string }> | null;
329
+ onCitationPress?: (source: CitationSource) => void;
330
+ streaming?: boolean;
331
+ /** Bloom Markdown's size: `lg` is the roomy reading size; a chat bubble is `md`, as compact as the person's own. */
332
+ size?: 'sm' | 'md' | 'lg';
333
+ }) {
334
+ const sources = useMemo(
335
+ () => extractCitationSources(toolInvocations, researchSources),
336
+ [toolInvocations, researchSources],
337
+ );
338
+ const { body, references } = useMemo(() => splitReferences(content, sources), [content, sources]);
339
+ const linked = useMemo(() => linkifyCitations(body, sources), [body, sources]);
340
+ const blocks = useMemo(() => parseSpecialBlocks(linked), [linked]);
341
+ const onLinkPress = useMemo(() => {
342
+ if (!onCitationPress) return undefined;
343
+ return (url: string) => {
344
+ const source = sources.find((entry) => entry.url === url);
345
+ if (source) onCitationPress(source);
346
+ else openSource(url);
347
+ };
348
+ }, [onCitationPress, sources]);
349
+
350
+ return (
351
+ <View>
352
+ {blocks.map((block, idx) => {
353
+ if (block.type === 'text') {
354
+ return (
355
+ <Markdown
356
+ key={idx}
357
+ size={size}
358
+ streaming={streaming && idx === blocks.length - 1}
359
+ renderCodeBlock={renderCodeBlock}
360
+ onLinkPress={onLinkPress}
361
+ >
362
+ {block.content}
363
+ </Markdown>
364
+ );
365
+ } else if (block.type === 'block' && block.blockType) {
366
+ return renderBlock(block.blockType, block.data, idx);
367
+ }
368
+ return null;
369
+ })}
370
+ {references ? <ReferenceList entries={references} onCitationPress={onCitationPress} /> : null}
371
+ </View>
372
+ );
373
+ }
@@ -0,0 +1,195 @@
1
+ import { useLabels } from '../lib/labels';
2
+ import {
3
+ Admonition,
4
+ AdmonitionContent,
5
+ AdmonitionIcon,
6
+ AdmonitionRoot,
7
+ AdmonitionRow,
8
+ AdmonitionText,
9
+ } from '@oxy.so/bloom/admonition';
10
+ import { Card, CardBody, CardHeader, CardTitle } from '@oxy.so/bloom/card';
11
+ import { RiExternalLinkLine } from '@oxy.so/bloom/icons/RiExternalLinkLine';
12
+ import { Item } from '@oxy.so/bloom/item';
13
+ import { Rating } from '@oxy.so/bloom/rating';
14
+ import { Muted, Text } from '@oxy.so/bloom/typography';
15
+ import { Image } from './Image';
16
+ import { Linking, View } from 'react-native';
17
+
18
+ /**
19
+ * The rich blocks a reply can carry (```compactlist, ```banner, …), drawn with
20
+ * Bloom: a card per block, `Item` rows, `Admonition` for a banner and `Rating`
21
+ * for a source's credibility. `ReplyMarkdown.tsx` parses the fences.
22
+ */
23
+
24
+ type CompactListItem = {
25
+ title: string;
26
+ href?: string;
27
+ meta?: string;
28
+ image?: string;
29
+ };
30
+
31
+ export function CompactList({ title, items }: { title: string; items: CompactListItem[] }) {
32
+ return (
33
+ <Card appearance="outline" className="my-2">
34
+ <CardHeader>
35
+ <CardTitle>{title}</CardTitle>
36
+ </CardHeader>
37
+ <CardBody>
38
+ <View role="list">
39
+ {items.map((item, index) => (
40
+ <Item
41
+ key={index}
42
+ role="listitem"
43
+ title={item.title}
44
+ subtitle={item.meta}
45
+ leading={
46
+ item.image ? (
47
+ <Image
48
+ source={{ uri: item.image }}
49
+ className="h-10 w-10 rounded"
50
+ contentFit="cover"
51
+ />
52
+ ) : undefined
53
+ }
54
+ trailing={item.href ? <RiExternalLinkLine size="sm" /> : undefined}
55
+ onPress={item.href ? () => void Linking.openURL(item.href!) : undefined}
56
+ />
57
+ ))}
58
+ </View>
59
+ </CardBody>
60
+ </Card>
61
+ );
62
+ }
63
+
64
+ type BannerType = 'info' | 'success' | 'warning' | 'danger';
65
+
66
+ /** A block's tone, in Bloom's admonition vocabulary. */
67
+ const ADMONITION = { info: 'info', success: 'tip', warning: 'warning', danger: 'error' } as const;
68
+
69
+ export function Banner({
70
+ type = 'info',
71
+ title,
72
+ content,
73
+ }: {
74
+ type?: BannerType;
75
+ title: string;
76
+ content: string;
77
+ }) {
78
+ return (
79
+ <View className="my-2">
80
+ <AdmonitionRoot type={Object.hasOwn(ADMONITION, type) ? ADMONITION[type] : 'info'}>
81
+ <AdmonitionRow>
82
+ <AdmonitionIcon />
83
+ <AdmonitionContent>
84
+ <Text variant="body-medium">{title}</Text>
85
+ <AdmonitionText>{content}</AdmonitionText>
86
+ </AdmonitionContent>
87
+ </AdmonitionRow>
88
+ </AdmonitionRoot>
89
+ </View>
90
+ );
91
+ }
92
+
93
+ type ComparisonSide = {
94
+ title: string;
95
+ content: string;
96
+ source?: string;
97
+ };
98
+
99
+ function ComparisonSideCard({ side }: { side: ComparisonSide }) {
100
+ const { t } = useLabels();
101
+ return (
102
+ <Card appearance="outline">
103
+ <CardBody>
104
+ <Text variant="body-medium">{side.title}</Text>
105
+ <Muted>{side.content}</Muted>
106
+ {side.source ? <Muted>{t('chat.richBlocks.source', { source: side.source })}</Muted> : null}
107
+ </CardBody>
108
+ </Card>
109
+ );
110
+ }
111
+
112
+ export function Comparison({
113
+ title,
114
+ left,
115
+ right,
116
+ conclusion,
117
+ }: {
118
+ title: string;
119
+ left: ComparisonSide;
120
+ right: ComparisonSide;
121
+ conclusion?: string;
122
+ }) {
123
+ return (
124
+ <Card appearance="outline" className="my-2">
125
+ <CardHeader>
126
+ <CardTitle>{title}</CardTitle>
127
+ </CardHeader>
128
+ <CardBody>
129
+ <View className="gap-2">
130
+ <ComparisonSideCard side={left} />
131
+ <ComparisonSideCard side={right} />
132
+ {conclusion ? <Admonition type="tip">{conclusion}</Admonition> : null}
133
+ </View>
134
+ </CardBody>
135
+ </Card>
136
+ );
137
+ }
138
+
139
+ type TimelineItem = {
140
+ date: string;
141
+ title: string;
142
+ description?: string;
143
+ };
144
+
145
+ export function Timeline({ title, items }: { title: string; items: TimelineItem[] }) {
146
+ return (
147
+ <Card appearance="outline" className="my-2">
148
+ <CardHeader>
149
+ <CardTitle>{title}</CardTitle>
150
+ </CardHeader>
151
+ <CardBody>
152
+ <View role="list">
153
+ {items.map((item, index) => (
154
+ <Item
155
+ key={index}
156
+ role="listitem"
157
+ leading={<Muted>{item.date}</Muted>}
158
+ title={item.title}
159
+ subtitle={item.description}
160
+ />
161
+ ))}
162
+ </View>
163
+ </CardBody>
164
+ </Card>
165
+ );
166
+ }
167
+
168
+ export function RichImage({
169
+ url,
170
+ title,
171
+ caption,
172
+ }: {
173
+ url: string;
174
+ title?: string;
175
+ caption?: string;
176
+ }) {
177
+ return (
178
+ <View className="my-2 gap-1">
179
+ <Image source={{ uri: url }} className="aspect-video w-full rounded-lg" contentFit="cover" />
180
+ {title ? <Text variant="body-medium">{title}</Text> : null}
181
+ {caption ? <Muted>{caption}</Muted> : null}
182
+ </View>
183
+ );
184
+ }
185
+
186
+ /** How far a source can be trusted, on a five-point scale. */
187
+ export function Credibility({ level, source }: { level: number; source: string }) {
188
+ const { t } = useLabels();
189
+ return (
190
+ <View className="my-2 flex-row items-center gap-2">
191
+ <Rating value={Math.max(0, Math.min(5, level))} size="sm" />
192
+ <Muted>{t('chat.richBlocks.source', { source })}</Muted>
193
+ </View>
194
+ );
195
+ }
@@ -0,0 +1,18 @@
1
+ import Svg, { Path } from 'react-native-svg';
2
+
3
+ /** The glyph's outline: a speaker cone with three rays, drawn on a 512 grid (y down). */
4
+ const GLYPH =
5
+ 'M136 117Q158 95 212.5 119.5Q267 144 323 200Q379 256 403.5 311Q428 366 406 387Q396 398 373 414Q350 430 313.5 447Q277 464 240 472.5Q203 481 162 472.5Q121 464 90.5 433.5Q60 403 51 361.5Q42 320 50.5 283Q59 246 76.5 209.5Q94 173 109.5 150.5Q125 128 136 117ZM348.5 361.5Q348.5 361.5 358.25 364.25Q368 367 373 362.5Q378 358 372.5 338Q367 318 347 286Q327 254 298 225Q269 196 237 176.5Q205 157 185.5 151Q166 145 161 150Q156 155 162 174.5Q168 194 187.5 226Q207 258 236 287.5Q265 317 297 336.5Q329 356 348.5 361.5ZM395 153Q388 161 377 161Q366 161 358.5 153.5Q351 146 351 135Q351 124 359 117L408 68Q415 61 425.5 61Q436 61 443.5 68.5Q451 76 451 86.5Q451 97 444 104ZM285 97Q272 90 272 75Q272 68 275 62L303 13Q310 0 325 0Q336 0 343.5 7.5Q351 15 351 26Q351 32 347 38L320 87Q312 101 297 101Q291 101 285 97ZM509 174Q512 180 512 187Q512 202 499 209L449 236Q443 240 437 240Q426 240 418.5 232.5Q411 225 411 214Q411 199 424 192L474 165Q480 161 486 161Q501 161 509 174Z';
6
+
7
+ /**
8
+ * The glyph of Alia's voice button: the speaker with rays the button has always worn. Bloom has no
9
+ * equivalent, so it is drawn here against Bloom's icon contract (`width` / `fill`) for a Bloom
10
+ * `Button` to size and colour.
11
+ */
12
+ export function VoiceModeIcon({ width = 18, fill }: { width?: number; fill?: string }) {
13
+ return (
14
+ <Svg width={width} height={width} viewBox="23 -17 512 512">
15
+ <Path d={GLYPH} fill={fill} />
16
+ </Svg>
17
+ );
18
+ }
@@ -0,0 +1,65 @@
1
+ import { useLabels } from '../../lib/labels';
2
+ import { Muted, Text } from '@oxy.so/bloom/typography';
3
+ import { View } from 'react-native';
4
+ import { ChartRenderer } from './ChartRenderer';
5
+ import { CodeRenderer } from './CodeRenderer';
6
+ import { DashboardRenderer } from './DashboardRenderer';
7
+ import { DeckRenderer } from './DeckRenderer';
8
+ import { FormRenderer } from './FormRenderer';
9
+ import { MarkdownRenderer } from './MarkdownRenderer';
10
+ import { TableRenderer } from './TableRenderer';
11
+
12
+ interface CanvasComponentProps {
13
+ component: {
14
+ id: string;
15
+ type: string;
16
+ title: string;
17
+ data: any;
18
+ };
19
+ onFormSubmit?: (formData: Record<string, any>) => void;
20
+ }
21
+
22
+ export function CanvasComponent({ component, onFormSubmit }: CanvasComponentProps) {
23
+ const { t } = useLabels();
24
+
25
+ // Code carries its own header (the file name), and a chart card its own title.
26
+ if (component.type === 'code')
27
+ return <CodeRenderer data={component.data} filename={component.title} />;
28
+ if (component.type === 'artifact' && component.data.language)
29
+ return (
30
+ <CodeRenderer
31
+ data={{ language: component.data.language, code: component.data.content }}
32
+ filename={component.title}
33
+ />
34
+ );
35
+ if (component.type === 'chart')
36
+ return <ChartRenderer data={component.data} title={component.title} />;
37
+
38
+ const content = (() => {
39
+ switch (component.type) {
40
+ case 'table':
41
+ return <TableRenderer data={component.data} title={component.title} />;
42
+ case 'form':
43
+ return <FormRenderer data={component.data} onSubmit={onFormSubmit} />;
44
+ case 'image':
45
+ return <Muted>{component.data.alt || t('panels.canvas.image')}</Muted>;
46
+ case 'markdown':
47
+ return <MarkdownRenderer data={component.data} />;
48
+ case 'artifact':
49
+ return <MarkdownRenderer data={{ content: component.data.content }} />;
50
+ case 'deck':
51
+ return <DeckRenderer data={component.data} />;
52
+ case 'dashboard':
53
+ return <DashboardRenderer data={component.data} />;
54
+ default:
55
+ return <Muted>{t('panels.canvas.unsupported', { type: component.type })}</Muted>;
56
+ }
57
+ })();
58
+
59
+ return (
60
+ <View className="gap-3">
61
+ <Text variant="body-semibold">{component.title}</Text>
62
+ {content}
63
+ </View>
64
+ );
65
+ }