@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,125 @@
1
+ import type { AgentActivityState, PlanItem } from '../../runtime/thread/agent-activity';
2
+ import { useLabels } from '../../lib/labels';
3
+ import {
4
+ Accordion,
5
+ AccordionContent,
6
+ AccordionItem,
7
+ AccordionTrigger,
8
+ } from '@oxy.so/bloom/accordion';
9
+ import { Admonition } from '@oxy.so/bloom/admonition';
10
+ import { Badge } from '@oxy.so/bloom/badge';
11
+ import { Card, CardBody, CardHeader } from '@oxy.so/bloom/card';
12
+ import { RiAlertLine } from '@oxy.so/bloom/icons/RiAlertLine';
13
+ import { RiCheckboxCircleLine } from '@oxy.so/bloom/icons/RiCheckboxCircleLine';
14
+ import { RiCloseCircleLine } from '@oxy.so/bloom/icons/RiCloseCircleLine';
15
+ import { Item } from '@oxy.so/bloom/item';
16
+ import { Muted, Text } from '@oxy.so/bloom/typography';
17
+ import React, { useState } from 'react';
18
+ import { View } from 'react-native';
19
+
20
+ /**
21
+ * AgentResultCard — the summary an agent run leaves in the chat when it ends.
22
+ *
23
+ * A Bloom `Card`: the outcome as a `Badge` beside the heading, the run's
24
+ * numbers in one secondary line, an error as an `Admonition`, and the plan as
25
+ * an `Accordion` section.
26
+ */
27
+
28
+ interface AgentResultCardProps {
29
+ activity: AgentActivityState;
30
+ agentName?: string;
31
+ }
32
+
33
+ /** `42s`, `3m 5s`, `1h 2m` — how long the run took. */
34
+ export function formatRunDuration(startedAt: number | null, now: number): string {
35
+ if (!startedAt) return '--';
36
+ const seconds = Math.max(0, Math.floor((now - startedAt) / 1000));
37
+ if (seconds < 60) return `${seconds}s`;
38
+ const minutes = Math.floor(seconds / 60);
39
+ if (minutes < 60) return `${minutes}m ${seconds % 60}s`;
40
+ return `${Math.floor(minutes / 60)}h ${minutes % 60}m`;
41
+ }
42
+
43
+ const PLAN_ICON = {
44
+ completed: RiCheckboxCircleLine,
45
+ blocked: RiAlertLine,
46
+ } as const;
47
+
48
+ function PlanItemRow({ item }: { item: PlanItem }) {
49
+ const Icon = PLAN_ICON[item.status as keyof typeof PLAN_ICON] ?? RiCloseCircleLine;
50
+ return <Item density="compact" role="listitem" leading={<Icon size="sm" />} title={item.text} />;
51
+ }
52
+
53
+ export const AgentResultCard = React.memo(function AgentResultCard({
54
+ activity,
55
+ agentName,
56
+ }: AgentResultCardProps) {
57
+ const { t } = useLabels();
58
+ const [open, setOpen] = useState<string[]>([]);
59
+ // Measured once, when the card first draws the finished run.
60
+ const [now] = useState(() => Date.now());
61
+
62
+ const { plan, isComplete, hasError, lastError, eventCount, startedAt } = activity;
63
+ const isSuccess = isComplete && !hasError;
64
+
65
+ const stats = [
66
+ formatRunDuration(startedAt, now),
67
+ t('chat.agentRun.steps', { count: String(eventCount) }),
68
+ plan
69
+ ? t('chat.agentRun.planItems', { done: String(plan.completed), total: String(plan.total) })
70
+ : null,
71
+ activity.creditsCharged != null
72
+ ? t('chat.agentRun.credits', { count: String(activity.creditsCharged) })
73
+ : null,
74
+ ].filter((part): part is string => part !== null);
75
+
76
+ return (
77
+ <Card>
78
+ <CardHeader>
79
+ <View className="flex-row items-center gap-2">
80
+ <Badge
81
+ variant="subtle"
82
+ color={isSuccess ? 'success' : hasError ? 'error' : 'default'}
83
+ content={t(
84
+ isSuccess
85
+ ? 'chat.agentRun.completed'
86
+ : hasError
87
+ ? 'chat.agentRun.failed'
88
+ : 'chat.agentRun.unknown',
89
+ )}
90
+ />
91
+ <View className="min-w-0 flex-1">
92
+ <Text variant="headline-semibold">
93
+ {t(isSuccess ? 'chat.agentRun.taskComplete' : 'chat.agentRun.taskFailed')}
94
+ </Text>
95
+ {agentName ? <Muted>{t('chat.agentRun.by', { name: agentName })}</Muted> : null}
96
+ </View>
97
+ </View>
98
+ </CardHeader>
99
+ <CardBody>
100
+ <View className="gap-3">
101
+ <Muted>{stats.join(' · ')}</Muted>
102
+
103
+ {hasError && lastError ? <Admonition type="error">{lastError}</Admonition> : null}
104
+
105
+ {plan && plan.items.length > 0 ? (
106
+ <Accordion
107
+ type="multiple"
108
+ value={open}
109
+ onValueChange={(next) => setOpen(Array.isArray(next) ? next : next ? [next] : [])}
110
+ >
111
+ <AccordionItem value="plan">
112
+ <AccordionTrigger>{t('chat.agentRun.planSummary')}</AccordionTrigger>
113
+ <AccordionContent>
114
+ {plan.items.map((item) => (
115
+ <PlanItemRow key={item.id} item={item} />
116
+ ))}
117
+ </AccordionContent>
118
+ </AccordionItem>
119
+ </Accordion>
120
+ ) : null}
121
+ </View>
122
+ </CardBody>
123
+ </Card>
124
+ );
125
+ });
@@ -0,0 +1,127 @@
1
+ import type { AgentActivityState } from '../../runtime/thread/agent-activity';
2
+ import { useLabels } from '../../lib/labels';
3
+ import { getToolPillLabel } from '../../runtime/model';
4
+ import { Admonition } from '@oxy.so/bloom/admonition';
5
+ import { AgentProgress } from '@oxy.so/bloom/agent-progress';
6
+ import { AgentThinking } from '@oxy.so/bloom/agent-thinking';
7
+ import { Badge } from '@oxy.so/bloom/badge';
8
+ import { Card, CardBody, CardHeader } from '@oxy.so/bloom/card';
9
+ import { Muted } from '@oxy.so/bloom/typography';
10
+ import React, { useEffect, useState } from 'react';
11
+ import { View } from 'react-native';
12
+
13
+ /**
14
+ * AgentTaskCard — an agent run in progress, inline in the chat.
15
+ *
16
+ * Bloom all the way down: a `Card` whose header carries the run's status as a
17
+ * `Badge` with the elapsed time, the plan as `AgentProgress` (its rings are the
18
+ * checklist), what the agent is doing right now as `AgentThinking`, and an
19
+ * error as an `Admonition`. The tool is named by its product label, never by
20
+ * its internal name.
21
+ */
22
+
23
+ interface AgentTaskCardProps {
24
+ activity: AgentActivityState;
25
+ }
26
+
27
+ /** `42s`, `3m 5s` — how long the run has been going. */
28
+ export function formatRunElapsed(startedAt: number | null, now: number): string {
29
+ if (!startedAt) return '';
30
+ const seconds = Math.max(0, Math.floor((now - startedAt) / 1000));
31
+ if (seconds < 60) return `${seconds}s`;
32
+ return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
33
+ }
34
+
35
+ /**
36
+ * The plan's lines as `AgentProgress` steps. The steps are also its React keys,
37
+ * and a plan can repeat a line ("Run the tests" twice), so a repeat is told
38
+ * apart by its position rather than dropped.
39
+ */
40
+ export function uniqueStepLabels(texts: readonly string[]): string[] {
41
+ const seen = new Map<string, number>();
42
+ return texts.map((text) => {
43
+ const count = (seen.get(text) ?? 0) + 1;
44
+ seen.set(text, count);
45
+ return count === 1 ? text : `${text} (${count})`;
46
+ });
47
+ }
48
+
49
+ export const AgentTaskCard = React.memo(function AgentTaskCard({ activity }: AgentTaskCardProps) {
50
+ const { t } = useLabels();
51
+ const {
52
+ plan,
53
+ currentAction,
54
+ isComplete,
55
+ hasError,
56
+ lastError,
57
+ eventCount,
58
+ startedAt,
59
+ latestResponse,
60
+ } = activity;
61
+ const [now, setNow] = useState(() => Date.now());
62
+
63
+ // The clock runs while the agent does; a finished run keeps its last reading.
64
+ useEffect(() => {
65
+ if (!startedAt || isComplete) return;
66
+ const interval = setInterval(() => setNow(Date.now()), 1000);
67
+ return () => clearInterval(interval);
68
+ }, [startedAt, isComplete]);
69
+
70
+ // Nothing to show yet
71
+ if (!plan && !currentAction && eventCount === 0) return null;
72
+
73
+ const elapsed = formatRunElapsed(startedAt, now);
74
+ const status = isComplete
75
+ ? { color: 'success' as const, label: t('chat.agentRun.complete') }
76
+ : hasError
77
+ ? { color: 'error' as const, label: t('chat.agentRun.error') }
78
+ : { color: 'info' as const, label: t('chat.agentRun.working') };
79
+
80
+ return (
81
+ <Card>
82
+ <CardHeader>
83
+ <View className="flex-row items-center justify-between gap-2">
84
+ <Badge variant="subtle" color={status.color} content={status.label} />
85
+ <Muted>
86
+ {[elapsed, plan && plan.total > 0 ? `${plan.completed}/${plan.total}` : '']
87
+ .filter((part) => part !== '')
88
+ .join(' · ')}
89
+ </Muted>
90
+ </View>
91
+ </CardHeader>
92
+ <CardBody>
93
+ <View className="gap-3">
94
+ {plan && plan.items.length > 0 ? (
95
+ <AgentProgress
96
+ steps={uniqueStepLabels(plan.items.map((item) => item.text))}
97
+ completedCount={plan.completed}
98
+ />
99
+ ) : null}
100
+
101
+ {currentAction && !isComplete ? (
102
+ <AgentThinking
103
+ variant="wave"
104
+ label={
105
+ currentAction.content
106
+ ? `${getToolPillLabel(currentAction.toolName, t)} · ${
107
+ currentAction.content.length > 80
108
+ ? `${currentAction.content.slice(0, 80)}…`
109
+ : currentAction.content
110
+ }`
111
+ : getToolPillLabel(currentAction.toolName, t)
112
+ }
113
+ />
114
+ ) : null}
115
+
116
+ {latestResponse && !isComplete ? (
117
+ <Muted numberOfLines={4}>
118
+ {latestResponse.length > 200 ? `${latestResponse.slice(0, 200)}…` : latestResponse}
119
+ </Muted>
120
+ ) : null}
121
+
122
+ {hasError && lastError ? <Admonition type="error">{lastError}</Admonition> : null}
123
+ </View>
124
+ </CardBody>
125
+ </Card>
126
+ );
127
+ });
@@ -0,0 +1,256 @@
1
+ import type { AiChatTurnAction } from '@oxy.so/bloom/ai-chat';
2
+ import { ReactionPicker } from '@oxy.so/bloom/chat-composer';
3
+ import {
4
+ DropdownMenu,
5
+ DropdownMenuContent,
6
+ DropdownMenuItem,
7
+ DropdownMenuTrigger,
8
+ } from '@oxy.so/bloom/dropdown-menu';
9
+ import { useInteractionState } from '@oxy.so/bloom/hooks';
10
+ import { useTheme, withAlpha } from '@oxy.so/bloom/theme';
11
+ import { type ComponentProps, type ReactNode, useState } from 'react';
12
+ import { Platform, Pressable, Text, View } from 'react-native';
13
+ import { useLabels } from '../../lib/labels';
14
+ import { RiEmojiPicker } from '../icons/RiEmojiPicker';
15
+ import { RiMoreDots } from '../icons/RiMoreDots';
16
+ import { RiReplyLine } from '../icons/RiReplyLine';
17
+
18
+ type Glyph = (props: { width?: number; height?: number; fill?: string }) => ReactNode;
19
+
20
+ /**
21
+ * One turn as a chat bubble, built after the bubbles of the agent chat this thread is modelled on.
22
+ *
23
+ * The row is a line with an 8px gap: the person's bubble hugs the end with its icons on the side
24
+ * facing the thread, a reply hugs the start with its icons after it. A bubble is 24px round, up to
25
+ * 80% of the column and 16px in from its sides; the person's is 12px tall at both ends and in the
26
+ * theme's primary (the agent's colour: the app is themed by it), a reply's is 8px and neutral. The icons are the three of that chat, 24px round
27
+ * buttons holding a 16px glyph: react (a reply's only: it is a vote), reply (quotes the turn into
28
+ * the composer) and more (the rest of the turn's actions). They show while the row is hovered or a
29
+ * menu of theirs is open, and always on a touch screen, which has no hover to reveal them.
30
+ */
31
+ export function ChatBubble({
32
+ side,
33
+ reactions = [],
34
+ onReact,
35
+ menu = [],
36
+ onReply,
37
+ children,
38
+ }: {
39
+ side: 'user' | 'reply';
40
+ /** The emoji left on this turn: drawn as pills under the bubble. */
41
+ reactions?: readonly string[];
42
+ /** Leave an emoji on this turn, or take it back (a pill pressed, or a pick of the picker). Absent: no react button. */
43
+ onReact?: (emoji: string) => void;
44
+ /** What "more" offers: every other action of the turn. */
45
+ menu?: ReadonlyArray<AiChatTurnAction>;
46
+ /** Quote this turn into the composer. */
47
+ onReply?: () => void;
48
+ /** The words. A function is handed the colour text takes on the person's bubble (the theme's). */
49
+ children: ReactNode | ((foreground: string | undefined) => ReactNode);
50
+ }) {
51
+ const { t } = useLabels();
52
+ const theme = useTheme();
53
+ const { state: hovered, onIn, onOut } = useInteractionState();
54
+ const [pinned, setPinned] = useState(false);
55
+ const mine = side === 'user';
56
+ // The person's bubble is the theme's primary: Bloom's theme is seeded from the agent's colour, and
57
+ // Bloom picks the text that reads on it.
58
+ const mineColors = mine
59
+ ? { background: theme.colors.primary, foreground: theme.colors.primaryForeground }
60
+ : null;
61
+ const shown = Platform.OS !== 'web' || hovered || pinned;
62
+ const hasIcons = onReact !== undefined || onReply !== undefined || menu.length > 0;
63
+ const icons = !hasIcons ? null : (
64
+ <View
65
+ className="shrink-0 flex-row items-center gap-0.5"
66
+ style={{ opacity: shown ? 1 : 0 }}
67
+ pointerEvents={shown ? 'auto' : 'none'}
68
+ >
69
+ {onReact === undefined ? null : (
70
+ <ReactMenu
71
+ label={t('chat.reactToMessage')}
72
+ held={reactions}
73
+ onReact={onReact}
74
+ onOpenChange={setPinned}
75
+ />
76
+ )}
77
+ {onReply === undefined ? null : (
78
+ <IconButton label={t('chat.replyToMessage')} icon={RiReplyLine} onPress={onReply} />
79
+ )}
80
+ {menu.length === 0 ? null : (
81
+ <ActionMenu
82
+ label={t('chat.moreActions')}
83
+ icon={RiMoreDots}
84
+ actions={menu}
85
+ onOpenChange={setPinned}
86
+ />
87
+ )}
88
+ </View>
89
+ );
90
+ return (
91
+ <View
92
+ className="w-full py-2"
93
+ {...(Platform.OS === 'web' ? { onPointerEnter: onIn, onPointerLeave: onOut } : {})}
94
+ >
95
+ <View
96
+ className={`w-full flex-row items-center gap-2 ${mine ? 'justify-end' : 'justify-start'}`}
97
+ >
98
+ {mine ? icons : null}
99
+ <View
100
+ className={`min-w-0 max-w-[80%] rounded-3xl px-4 ${
101
+ mine ? 'py-3' : 'bg-background-tertiary-default py-2'
102
+ }`}
103
+ style={mineColors ? { backgroundColor: mineColors.background } : undefined}
104
+ >
105
+ {typeof children === 'function' ? children(mineColors?.foreground) : children}
106
+ </View>
107
+ {mine ? null : icons}
108
+ </View>
109
+ {reactions.length === 0 ? null : (
110
+ // The reactions sit on the bubble's lower edge, as the chat this is modelled on draws them.
111
+ <View
112
+ className={`-mt-2.5 flex-row flex-wrap items-center gap-1 ${
113
+ mine ? 'justify-end me-2.5' : 'justify-start ms-2.5'
114
+ }`}
115
+ >
116
+ {reactions.map((emoji) => (
117
+ <ReactionPill
118
+ key={emoji}
119
+ emoji={emoji}
120
+ onPress={onReact === undefined ? undefined : () => onReact(emoji)}
121
+ />
122
+ ))}
123
+ </View>
124
+ )}
125
+ </View>
126
+ );
127
+ }
128
+
129
+ /** One reaction under a bubble: the emoji on a wash of the theme's primary, ringed in the surface. */
130
+ function ReactionPill({ emoji, onPress }: { emoji: string; onPress?: () => void }) {
131
+ const theme = useTheme();
132
+ const { t } = useLabels();
133
+ const { state: hovered, onIn, onOut } = useInteractionState();
134
+ return (
135
+ <Pressable
136
+ onHoverIn={onIn}
137
+ onHoverOut={onOut}
138
+ accessibilityRole="button"
139
+ accessibilityLabel={t('chat.reaction', { emoji })}
140
+ accessibilityState={{ selected: true }}
141
+ disabled={onPress === undefined}
142
+ onPress={onPress}
143
+ className="h-[22px] flex-row items-center rounded-full px-2"
144
+ style={{
145
+ backgroundColor: withAlpha(theme.colors.primary, hovered ? 0.16 : 0.12),
146
+ borderWidth: 2,
147
+ borderColor: theme.colors.background,
148
+ }}
149
+ >
150
+ <Text className="text-sm leading-none">{emoji}</Text>
151
+ </Pressable>
152
+ );
153
+ }
154
+
155
+ /** The react button: it opens Bloom's emoji bar, and a pick leaves the emoji (or takes it back). */
156
+ function ReactMenu({
157
+ label,
158
+ held,
159
+ onReact,
160
+ onOpenChange,
161
+ }: {
162
+ label: string;
163
+ held: readonly string[];
164
+ onReact: (emoji: string) => void;
165
+ onOpenChange: (open: boolean) => void;
166
+ }) {
167
+ const [open, setOpen] = useState(false);
168
+ const change = (next: boolean) => {
169
+ setOpen(next);
170
+ onOpenChange(next);
171
+ };
172
+ return (
173
+ <DropdownMenu open={open} onOpenChange={change}>
174
+ <DropdownMenuTrigger asChild label={label}>
175
+ <IconButton label={label} icon={RiEmojiPicker} />
176
+ </DropdownMenuTrigger>
177
+ <DropdownMenuContent>
178
+ <ReactionPicker
179
+ surface={false}
180
+ size="sm"
181
+ selected={held.length === 1 ? held[0] : undefined}
182
+ onSelectEmoji={(emoji) => {
183
+ onReact(emoji);
184
+ change(false);
185
+ }}
186
+ />
187
+ </DropdownMenuContent>
188
+ </DropdownMenu>
189
+ );
190
+ }
191
+
192
+ /** A button of the icon group that opens a menu of the turn's actions. */
193
+ function ActionMenu({
194
+ label,
195
+ icon,
196
+ actions,
197
+ onOpenChange,
198
+ }: {
199
+ label: string;
200
+ icon: Glyph;
201
+ actions: ReadonlyArray<AiChatTurnAction>;
202
+ onOpenChange: (open: boolean) => void;
203
+ }) {
204
+ const theme = useTheme();
205
+ return (
206
+ <DropdownMenu onOpenChange={onOpenChange}>
207
+ <DropdownMenuTrigger asChild label={label}>
208
+ <IconButton label={label} icon={icon} />
209
+ </DropdownMenuTrigger>
210
+ <DropdownMenuContent>
211
+ {actions.map((action) => {
212
+ const Item = action.icon;
213
+ return (
214
+ <DropdownMenuItem
215
+ key={action.key}
216
+ disabled={action.disabled}
217
+ onPress={action.onPress}
218
+ leading={<Item width={16} height={16} fill={theme.colors.textSecondary} />}
219
+ >
220
+ {action.label}
221
+ </DropdownMenuItem>
222
+ );
223
+ })}
224
+ </DropdownMenuContent>
225
+ </DropdownMenu>
226
+ );
227
+ }
228
+
229
+ /** A 24px round button holding a 16px glyph, washed on hover. It forwards what a trigger hands it. */
230
+ function IconButton({
231
+ label,
232
+ icon: Icon,
233
+ onPress,
234
+ ...rest
235
+ }: { label: string; icon: Glyph } & Omit<ComponentProps<typeof Pressable>, 'children'>) {
236
+ const theme = useTheme();
237
+ const { state: hovered, onIn, onOut } = useInteractionState();
238
+ return (
239
+ <Pressable
240
+ {...rest}
241
+ accessibilityRole="button"
242
+ accessibilityLabel={label}
243
+ onPress={onPress}
244
+ onHoverIn={onIn}
245
+ onHoverOut={onOut}
246
+ className="size-6 items-center justify-center rounded-full"
247
+ style={{ backgroundColor: hovered ? theme.colors.backgroundSecondary : undefined }}
248
+ >
249
+ <Icon
250
+ width={16}
251
+ height={16}
252
+ fill={hovered ? theme.colors.text : theme.colors.textSecondary}
253
+ />
254
+ </Pressable>
255
+ );
256
+ }