@gemies/sdk 10.7.0 → 10.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # @gemies/sdk
2
2
 
3
+ ## 10.9.0
4
+
5
+ ### Find, jump to a turn, and where a follow-up is
6
+
7
+ - **Find in the conversation.** `GemieChatState.openFind` (⌘F on a Mac, Ctrl+F elsewhere on web)
8
+ opens a bar that searches the words the loaded messages show, whatever their case or accents,
9
+ starting on the newest match. Enter goes to the one above, Shift+Enter below, Escape closes. The
10
+ current match is outlined and scrolled to, above the mounted window too. History not paged in yet
11
+ is not searched, and the bar says so; `openSearch` still searches a whole thread on the server.
12
+ While a chat on screen offers find, the browser's own does not open (it cannot see unmounted rows).
13
+ - **Jump to a turn.** `GemieChatState.openTurns` lists the questions, newest first, and a thread of
14
+ six turns or more has a button for it at its edge.
15
+ - **Where a follow-up is.** A line over the composer says when a new conversation's first message is
16
+ waiting to be sent, and when a reply to a waiting agent is on its way. `GemieComposer` takes it as
17
+ `followUp`, and `ApprovalActions` gained `steering`.
18
+ - A shared (`readOnly`) conversation's replies can be copied.
19
+ - The thread's search and the new panels open under the floating header rather than behind it.
20
+ - New words: `chat.find.*`, `chat.followUp.*`, `chat.turns.*` (en, es). A host with its own `t`
21
+ adds them.
22
+
23
+ ## 10.8.0
24
+
25
+ ### A plan to keep, and a question answered by keyboard
26
+
27
+ The plan card (`PlanPreviewCard`) folds away and back (remembered while the card is mounted), copies
28
+ its plan as Markdown, and downloads it as a `.md` file (the share sheet on a phone). New words:
29
+ `planCard.*` (en, es). `deliverMarkdownFile` is now exported from `@gemies/sdk/runtime`, for a host
30
+ that hands a Markdown document of its own to the person.
31
+
32
+ On web the question card (`QuestionCard`) is a full keyboard flow:
33
+
34
+ - It takes the focus when it appears and nothing else holds it. From an empty composer, ↑ moves into
35
+ it.
36
+ - ↑ and ↓ (and Home, End) move between the answers. Enter, Space and the digits pick, as before.
37
+ - ⌘/Ctrl+Enter is Next, or Done on the last question.
38
+ - Escape dismisses it, as its corner button does. In a free-text field with something typed, the
39
+ first Escape only leaves the field.
40
+ - A held key counts once. After a keyboard answer or dismissal the focus returns to the composer;
41
+ after a tap or a click it is left alone.
42
+
43
+ Touch and pointer behave as before. `QuestionCard` takes `autoFocus`, `onReturnFocus` and a `ref`
44
+ (`QuestionCardHandle`), and `GemieComposerQuestions` takes `autoFocus`; `GemieChatContent` sets it
45
+ while its chat is on screen.
46
+
3
47
  ## 10.7.0
4
48
 
5
49
  ### A turn is sent once
package/README.md CHANGED
@@ -304,6 +304,10 @@ history with the scroll that goes with it; and the card of an agent's run. What
304
304
  around it, never in it (`tests/components/thread/one-thread.test.tsx` mounts it both ways and
305
305
  holds the rows equal, and fails if anything else imports Bloom's thread).
306
306
 
307
+ Every chat can be moved around in: `state.openFind` finds words in the loaded messages (⌘F or
308
+ Ctrl+F on web, taken only while a chat offers it) and `state.openTurns` lists the turns to jump to.
309
+ A host draws the two where it draws its other chat actions.
310
+
307
311
  An agent's permanent thread is `threadHandle`: the conversations behind the open one are paged in
308
312
  above it, the thread can be searched (`state.openSearch`), and a hit opens the stretch around it.
309
313
  Those routes (`/agents/thread/:handle/…`) answer Alia's own origins only, as `/conversations` did
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gemies/sdk",
3
- "version": "10.7.0",
3
+ "version": "10.9.0",
4
4
  "description": "The Gemies SDK: the conversation runtime, chat UI, voice calls and dictation for Oxy apps that talk to a gemie",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -48,9 +48,11 @@ import type { SharedValue } from 'react-native-reanimated';
48
48
  import { useAmbientWave } from '../hooks/useAmbientWave';
49
49
  import { useAtBottom } from '../hooks/useAtBottom';
50
50
  import { type GemieTurn, useChatComposer } from '../hooks/useChatComposer';
51
+ import { useFindShortcut } from '../hooks/useFindShortcut';
51
52
  import { type GemieVoiceOptions, useChatVoice } from '../hooks/useChatVoice';
52
53
  import { useAttachMenu } from '../hooks/useAttachMenu';
53
54
  import { usePendingQuestions } from '../hooks/usePendingQuestions';
55
+ import { useThreadNavigation } from '../hooks/useThreadNavigation';
54
56
  import { useThreadView } from '../hooks/useThreadView';
55
57
  import { useTTS } from '../hooks/useTTS';
56
58
  import { BubblesProvider } from '../lib/bubbles';
@@ -72,6 +74,7 @@ import { type DeviceModel, buildPowerLevelOptions } from '../lib/power-level-opt
72
74
  import { GEMIE_FEATURES, featureOffer, useAgentFeatures, useAgentProfile } from '../runtime/agents';
73
75
  import { type GemieRuntimeHost, GemieRuntimeProvider, useGemieRuntime } from '../runtime/config';
74
76
  import { type GemieHostTools, APP_SLUG } from '../runtime/host-tools';
77
+ import { useConversationStore } from '../runtime/conversation-store';
75
78
  import { useCreateConversation } from '../runtime/conversations';
76
79
  import { useRefreshGemieThread } from '../runtime/use-gemie-thread';
77
80
  import type { GemieThreadAddress } from '../runtime/routes';
@@ -87,8 +90,11 @@ import { GemieWelcomeMessage } from './GemieWelcomeMessage';
87
90
  import { AmbientField } from './AmbientField';
88
91
  import { InertWhen } from './InertWhen';
89
92
  import { GemieBetweenGemies } from './GemieBetweenGemies';
93
+ import { FollowUpStatus } from './thread/FollowUpStatus';
90
94
  import { GemieThread } from './thread/GemieThread';
95
+ import { ThreadFindBar } from './thread/ThreadFindBar';
91
96
  import { ThreadSearch } from './thread/ThreadSearch';
97
+ import { LONG_THREAD_TURNS, ThreadTurnList, ThreadTurnsButton } from './thread/ThreadTurns';
92
98
  import { VoiceModeIcon } from './VoiceModeIcon';
93
99
  import { VoiceCallContext } from './voice/VoiceCallContext';
94
100
  import { createTokenStyles } from '@oxy.so/bloom/theme';
@@ -116,6 +122,10 @@ export interface GemieChatState {
116
122
  participants: GemieChatParticipants;
117
123
  /** Search what was said in the agent's thread. Present only on a thread (`threadHandle`, `gemieThread`). */
118
124
  openSearch: (() => void) | undefined;
125
+ /** Find words in the conversation on screen (⌘F / Ctrl+F on web). Present once there is something to find. */
126
+ openFind: (() => void) | undefined;
127
+ /** The list of the conversation's turns, each a jump to it. Present once there is a turn. */
128
+ openTurns: (() => void) | undefined;
119
129
  /** The conversation as it stands now, for an export. Read when called, not when rendered. */
120
130
  getMessages: () => readonly Message[];
121
131
  }
@@ -705,6 +715,49 @@ function GemieConversationView({
705
715
  if (sent) composer.setText('');
706
716
  }, [approvals, composer, decliningOption]);
707
717
 
718
+ // ── Moving around a long thread: find, and the list of turns ──
719
+ const showsPast = view.jumped;
720
+ const pastMessages = view.history?.messages;
721
+ /** What the thread draws, oldest first: the history behind it, then the conversation. */
722
+ const threadRows = useMemo<Message[]>(
723
+ () => [
724
+ ...(pastMessages ?? []),
725
+ // Nothing live under a window: it is a view of the past.
726
+ ...(showsPast ? [] : messages.filter((m) => m.role === 'user' || m.role === 'assistant')),
727
+ ],
728
+ [pastMessages, showsPast, messages],
729
+ );
730
+ const navigation = useThreadNavigation(threadRows, conversationId);
731
+ const { openFind, openTurns, close: closeNavigation } = navigation;
732
+ const { closeSearch, openSearch: openThreadSearch } = view;
733
+ // One thing over the thread at a time.
734
+ const findInThread = useCallback(() => {
735
+ closeSearch();
736
+ openFind();
737
+ }, [closeSearch, openFind]);
738
+ const listTurns = useCallback(() => {
739
+ closeSearch();
740
+ openTurns();
741
+ }, [closeSearch, openTurns]);
742
+ const searchThread = useCallback(() => {
743
+ closeNavigation();
744
+ openThreadSearch();
745
+ }, [closeNavigation, openThreadSearch]);
746
+ const turnCount = useMemo(
747
+ () => threadRows.reduce((count, m) => (m.role === 'user' ? count + 1 : count), 0),
748
+ [threadRows],
749
+ );
750
+ const canFind = threadRows.length > 0;
751
+ const canList = turnCount > 0;
752
+ useFindShortcut(canFind && isFocused && betweenGemies === null ? findInThread : undefined);
753
+
754
+ // A message not yet in a turn being answered: said above the composer while that is so.
755
+ const queued = useConversationStore(
756
+ (s) =>
757
+ conversationId !== undefined && s.pendingInitialMessage?.conversationId === conversationId,
758
+ );
759
+ const followUp = approvals.steering.size > 0 ? 'steering' : queued ? 'queued' : undefined;
760
+
708
761
  // ── The chrome ──
709
762
  const latestMessages = useRef(messages);
710
763
  latestMessages.current = messages;
@@ -717,7 +770,9 @@ function GemieConversationView({
717
770
  clearMessages: clearConversation,
718
771
  markState: voice.markState,
719
772
  participants,
720
- openSearch: threadAddress === undefined ? undefined : view.openSearch,
773
+ openSearch: threadAddress === undefined ? undefined : searchThread,
774
+ openFind: canFind ? findInThread : undefined,
775
+ openTurns: canList ? listTurns : undefined,
721
776
  getMessages: () => latestMessages.current,
722
777
  }),
723
778
  [
@@ -728,7 +783,11 @@ function GemieConversationView({
728
783
  voice.markState,
729
784
  participants,
730
785
  threadAddress,
731
- view.openSearch,
786
+ searchThread,
787
+ canFind,
788
+ findInThread,
789
+ canList,
790
+ listTurns,
732
791
  ],
733
792
  );
734
793
  const frame = useMemo(() => chrome?.(state) ?? {}, [chrome, state]);
@@ -783,12 +842,18 @@ function GemieConversationView({
783
842
  items: asked.questions,
784
843
  onSubmit: (message) => void composer.sendTurn(message, undefined, composer.turnOptions),
785
844
  onDismiss: asked.dismiss,
845
+ autoFocus: isFocused,
786
846
  }}
787
847
  value={composer.text}
788
848
  onValueChange={composer.setText}
789
849
  onSubmit={() => void (replyDeclines ? submitReply() : composer.submit(composer.text))}
790
850
  // Stop gives way to send while a reply would decline the question the agent waits on.
791
851
  busy={isLoading && !replyDeclines}
852
+ followUp={
853
+ followUp === undefined ? undefined : (
854
+ <FollowUpStatus state={followUp} agent={lead.name} />
855
+ )
856
+ }
792
857
  approval={
793
858
  approvals.pending === undefined ? undefined : (
794
859
  <ApprovalBar approvals={approvals} isFocused={isFocused} />
@@ -834,7 +899,6 @@ function GemieConversationView({
834
899
  </>
835
900
  );
836
901
 
837
- const showsPast = view.jumped;
838
902
  return (
839
903
  <GemieFlightsProvider value={flights}>
840
904
  <InertWhen inert={betweenGemies !== null}>
@@ -864,6 +928,8 @@ function GemieConversationView({
864
928
  conversationLoading={conversationLoading || loading}
865
929
  history={view.history}
866
930
  focusCursor={view.focusCursor}
931
+ jumpTo={navigation.jump}
932
+ highlightedId={navigation.highlightedId}
867
933
  failedTurn={failedTurn}
868
934
  onRetryTurn={retryFailedTurn}
869
935
  onRegenerate={composer.regenerate}
@@ -891,6 +957,20 @@ function GemieConversationView({
891
957
  {!view.searchOpen || threadAddress === undefined ? null : (
892
958
  <ThreadSearch thread={threadAddress} onJump={view.jump} onClose={view.closeSearch} />
893
959
  )}
960
+ {navigation.panel === 'find' ? (
961
+ <ThreadFindBar find={navigation} partial={view.history?.loadMore !== undefined} />
962
+ ) : null}
963
+ {navigation.panel === 'turns' ? (
964
+ <ThreadTurnList
965
+ turns={navigation.turns}
966
+ onJump={navigation.jumpToTurn}
967
+ onLoadEarlier={view.history?.loadMore}
968
+ onClose={navigation.close}
969
+ />
970
+ ) : null}
971
+ {navigation.panel === null && !view.searchOpen && turnCount >= LONG_THREAD_TURNS ? (
972
+ <ThreadTurnsButton onPress={listTurns} />
973
+ ) : null}
894
974
  </AiChatContainer>
895
975
  </InertWhen>
896
976
  {betweenGemies === null ? null : (
@@ -36,6 +36,8 @@ import {
36
36
  } from './ComposerDropZone';
37
37
  import { ComposerSuggestions } from './ComposerSuggestions';
38
38
  import { QuestionCard } from './QuestionCard';
39
+ import type { ShortcutKeyEvent } from '../hooks/useApprovalShortcuts';
40
+ import type { QuestionCardHandle } from '../hooks/useQuestionKeyboard';
39
41
  import { createTokenStyles } from '@oxy.so/bloom/theme';
40
42
 
41
43
  /**
@@ -72,6 +74,11 @@ export interface GemieComposerQuestions {
72
74
  /** Sends the answers as the next message. */
73
75
  onSubmit: (message: string) => void;
74
76
  onDismiss: () => void;
77
+ /**
78
+ * The composer's chat is on screen, so the card may take the focus when nothing else holds it.
79
+ * Default `false`: on web, ↑ in an empty composer moves into the card either way.
80
+ */
81
+ autoFocus?: boolean;
75
82
  }
76
83
 
77
84
  export interface GemieComposerProps<T extends GemieSuggestion = GemieSuggestion> {
@@ -111,6 +118,8 @@ export interface GemieComposerProps<T extends GemieSuggestion = GemieSuggestion>
111
118
  * questions: where the person is about to type the reply that declines it.
112
119
  */
113
120
  approval?: ReactNode;
121
+ /** Where a message that is not in a running turn yet is (`FollowUpStatus`), over the field. */
122
+ followUp?: ReactNode;
114
123
  /** The tab on the card's top edge (`ComposerPanelStatusTab`). */
115
124
  status?: ReactNode;
116
125
  /** Drawn where send would be while there is nothing to send (voice mode). */
@@ -157,6 +166,7 @@ function GemieComposerBody<T extends GemieSuggestion>({
157
166
  suggestions,
158
167
  questions,
159
168
  approval,
169
+ followUp,
160
170
  status,
161
171
  emptyAction,
162
172
  accessory,
@@ -173,6 +183,21 @@ function GemieComposerBody<T extends GemieSuggestion>({
173
183
  (message: string) => (onError ? onError(message) : toast.error(message)),
174
184
  [onError],
175
185
  );
186
+ const ownFieldRef = useRef<TextInputHandle | null>(null);
187
+ const fieldRef = inputRef ?? ownFieldRef;
188
+ const questionRef = useRef<QuestionCardHandle>(null);
189
+ const returnToField = useCallback(() => fieldRef.current?.focus(), [fieldRef]);
190
+ // ↑ in an empty field moves into the question above it, once the host has had the key.
191
+ const handleKeyPress = useCallback(
192
+ (event: TextInputKeyPressEvent) => {
193
+ onKeyPress?.(event);
194
+ if (event.defaultPrevented || value !== '') return;
195
+ const { key, shiftKey, altKey, ctrlKey, metaKey } = event.nativeEvent as ShortcutKeyEvent;
196
+ if (key !== 'ArrowUp' || shiftKey || altKey || ctrlKey || metaKey) return;
197
+ if (questionRef.current?.focus()) event.preventDefault();
198
+ },
199
+ [onKeyPress, value],
200
+ );
176
201
  // Paste is a DOM gesture on a DOM node; the panel publishes no ref to one.
177
202
  const hostId = `composer-${useId().replace(/[^a-zA-Z0-9]/g, '')}`;
178
203
 
@@ -312,17 +337,21 @@ function GemieComposerBody<T extends GemieSuggestion>({
312
337
  // Beside the loader, not through the pill's `question` slot: the light traces the box it
313
338
  // wraps, so a question inside it would be ringed too.
314
339
  <QuestionCard
340
+ ref={questionRef}
315
341
  questions={questions.items}
316
342
  onSubmit={questions.onSubmit}
317
343
  onDismiss={questions.onDismiss}
344
+ autoFocus={questions.autoFocus}
345
+ onReturnFocus={returnToField}
318
346
  />
319
347
  ) : null}
348
+ {followUp}
320
349
  <ComposerLoader phase={loaderPhase ?? (busy ? 'streaming' : 'idle')}>
321
350
  <ComposerPill
322
351
  value={value}
323
352
  onValueChange={onValueChange}
324
353
  onSubmit={() => onSubmit()}
325
- inputRef={inputRef}
354
+ inputRef={fieldRef}
326
355
  busy={busy}
327
356
  onStop={onStop}
328
357
  disabled={disabled || intake.isBusy || !hasContent}
@@ -347,7 +376,7 @@ function GemieComposerBody<T extends GemieSuggestion>({
347
376
  onAttachmentRetry={intake.retry}
348
377
  status={status}
349
378
  emptyAction={emptyAction}
350
- onKeyPress={onKeyPress}
379
+ onKeyPress={handleKeyPress}
351
380
  labels={panelLabels}
352
381
  // The loader paints the pill's surface behind its light; the controls go frosted over it.
353
382
  surface={false}
@@ -1,14 +1,25 @@
1
+ import { Button } from '@oxy.so/bloom/button';
1
2
  import { Card, CardBody, CardHeader, CardTitle } from '@oxy.so/bloom/card';
3
+ import { Collapsible } from '@oxy.so/bloom/collapsible';
4
+ import { RiArrowDownSLine } from '@oxy.so/bloom/icons/RiArrowDownSLine';
5
+ import { RiArrowUpSLine } from '@oxy.so/bloom/icons/RiArrowUpSLine';
6
+ import { RiDownload2Line } from '@oxy.so/bloom/icons/RiDownload2Line';
7
+ import { RiFileCopyLine } from '@oxy.so/bloom/icons/RiFileCopyLine';
2
8
  import { RiListCheck3 } from '@oxy.so/bloom/icons/RiListCheck3';
3
9
  import { Item } from '@oxy.so/bloom/item';
4
- import { useTheme } from '@oxy.so/bloom/theme';
10
+ import { createTokenStyles, useTheme } from '@oxy.so/bloom/theme';
11
+ import { toast } from '@oxy.so/bloom/toast';
5
12
  import { Text } from '@oxy.so/bloom/typography';
13
+ import { useState } from 'react';
6
14
  import { View } from 'react-native';
7
15
  import Animated from 'react-native-reanimated';
8
16
  import { planPreviewEnter } from '../animations';
17
+ import { copyText } from '../lib/clipboard';
9
18
  import { useLabels } from '../lib/labels';
19
+ import { planMarkdown } from '../lib/plan-markdown';
20
+ import { deliverMarkdownFile } from '../runtime/markdown-file';
21
+ import { exportFilename } from '../runtime/thread/conversation-export';
10
22
  import type { PlanStep } from '../types';
11
- import { createTokenStyles } from '@oxy.so/bloom/theme';
12
23
 
13
24
  interface PlanPreviewCardProps {
14
25
  steps: PlanStep[];
@@ -16,12 +27,23 @@ interface PlanPreviewCardProps {
16
27
 
17
28
  /**
18
29
  * The plan the agent shows before it works. It is only shown: the agent does not wait on it, and
19
- * nobody is asked to approve it.
30
+ * nobody is asked to approve it. The person can fold it away (remembered for as long as this card
31
+ * is mounted), copy it, or take it as a Markdown file.
20
32
  */
21
33
  export function PlanPreviewCard({ steps }: PlanPreviewCardProps) {
22
34
  const styles = useStyles();
23
- const labels = useLabels();
35
+ const { planTitle, t } = useLabels();
24
36
  const { colors } = useTheme();
37
+ const [open, setOpen] = useState(true);
38
+
39
+ const copy = () => void copyText(planMarkdown(planTitle, steps), t);
40
+ const download = () => {
41
+ deliverMarkdownFile(
42
+ exportFilename('plan', new Date()),
43
+ planMarkdown(planTitle, steps),
44
+ planTitle,
45
+ ).catch(() => toast.error(t('planCard.downloadFailed')));
46
+ };
25
47
 
26
48
  return (
27
49
  <Animated.View entering={planPreviewEnter} style={styles.card}>
@@ -29,22 +51,52 @@ export function PlanPreviewCard({ steps }: PlanPreviewCardProps) {
29
51
  <CardHeader>
30
52
  <View style={styles.titleRow}>
31
53
  <RiListCheck3 width={16} height={16} fill={colors.icon} />
32
- <CardTitle>{labels.planTitle}</CardTitle>
54
+ <CardTitle style={styles.title}>{planTitle}</CardTitle>
55
+ <Button
56
+ size="xs"
57
+ appearance="plain"
58
+ tone="neutral"
59
+ iconOnly
60
+ icon={RiFileCopyLine}
61
+ accessibilityLabel={t('planCard.copy')}
62
+ onPress={copy}
63
+ />
64
+ <Button
65
+ size="xs"
66
+ appearance="plain"
67
+ tone="neutral"
68
+ iconOnly
69
+ icon={RiDownload2Line}
70
+ accessibilityLabel={t('planCard.download')}
71
+ onPress={download}
72
+ />
73
+ <Button
74
+ size="xs"
75
+ appearance="plain"
76
+ tone="neutral"
77
+ iconOnly
78
+ icon={open ? RiArrowUpSLine : RiArrowDownSLine}
79
+ accessibilityLabel={t(open ? 'planCard.collapse' : 'planCard.expand')}
80
+ aria-expanded={open}
81
+ onPress={() => setOpen((current) => !current)}
82
+ />
33
83
  </View>
34
84
  </CardHeader>
35
- <CardBody>
36
- {steps.map((step, index) => (
37
- <Item
38
- // A plan has no ids and its steps never reorder: the position is the identity.
39
- // biome-ignore lint/suspicious/noArrayIndexKey: see above
40
- key={index}
41
- density="compact"
42
- leading={<Text style={styles.stepNumber}>{index + 1}</Text>}
43
- title={step.action}
44
- subtitle={step.description || undefined}
45
- />
46
- ))}
47
- </CardBody>
85
+ <Collapsible open={open}>
86
+ <CardBody>
87
+ {steps.map((step, index) => (
88
+ <Item
89
+ // A plan has no ids and its steps never reorder: the position is the identity.
90
+ // biome-ignore lint/suspicious/noArrayIndexKey: see above
91
+ key={index}
92
+ density="compact"
93
+ leading={<Text style={styles.stepNumber}>{index + 1}</Text>}
94
+ title={step.action}
95
+ subtitle={step.description || undefined}
96
+ />
97
+ ))}
98
+ </CardBody>
99
+ </Collapsible>
48
100
  </Card>
49
101
  </Animated.View>
50
102
  );
@@ -53,6 +105,7 @@ export function PlanPreviewCard({ steps }: PlanPreviewCardProps) {
53
105
  const useStyles = createTokenStyles((t) => ({
54
106
  card: { marginVertical: 8 },
55
107
  titleRow: { flexDirection: 'row', alignItems: 'center', gap: 8 },
108
+ title: { flex: 1 },
56
109
  stepNumber: {
57
110
  width: 20,
58
111
  textAlign: 'center',
@@ -1,6 +1,8 @@
1
1
  import { Questionnaire, type QuestionnaireAnswers } from '@oxy.so/bloom/questionnaire';
2
2
  import { Muted } from '@oxy.so/bloom/typography';
3
+ import { type Ref, useId } from 'react';
3
4
  import { View, StyleSheet } from 'react-native';
5
+ import { type QuestionCardHandle, useQuestionKeyboard } from '../hooks/useQuestionKeyboard';
4
6
  import { type AskedQuestion, formatAnswers } from '../lib/questions';
5
7
 
6
8
  interface QuestionCardProps {
@@ -9,6 +11,12 @@ interface QuestionCardProps {
9
11
  onSubmit: (message: string) => void;
10
12
  /** Shows the corner dismiss; typing a reply in the composer answers just as well. */
11
13
  onDismiss?: () => void;
14
+ /** Take the focus when the card appears and nothing else holds it. Default `false`. */
15
+ autoFocus?: boolean;
16
+ /** The keyboard answered or dismissed the card: move the focus on, to the composer. */
17
+ onReturnFocus?: () => void;
18
+ /** Lets a host move the keyboard into the card. */
19
+ ref?: Ref<QuestionCardHandle>;
12
20
  }
13
21
 
14
22
  /** Ids are positions: the questions are the model's, and carry none. */
@@ -17,10 +25,27 @@ const idOf = (index: number) => `q${index}`;
17
25
  /**
18
26
  * The questions Alia asked, as Bloom's `Questionnaire`. Give it to the composer's `question`
19
27
  * slot while the person can still answer: it docks above the composer, where they are about
20
- * to type, rather than sitting in the thread.
28
+ * to type, rather than sitting in the thread. On web it is answered by keyboard too
29
+ * (`useQuestionKeyboard`).
21
30
  */
22
- export function QuestionCard({ questions, onSubmit, onDismiss }: QuestionCardProps) {
23
- const complete = (answers: QuestionnaireAnswers) =>
31
+ export function QuestionCard({
32
+ questions,
33
+ onSubmit,
34
+ onDismiss,
35
+ autoFocus = false,
36
+ onReturnFocus,
37
+ ref,
38
+ }: QuestionCardProps) {
39
+ const testID = `question-card-${useId().replace(/[^a-zA-Z0-9]/g, '')}`;
40
+ const { rootRef, leave, dismiss } = useQuestionKeyboard({
41
+ testID,
42
+ autoFocus,
43
+ onDismiss,
44
+ onReturnFocus,
45
+ ref,
46
+ });
47
+ const complete = (answers: QuestionnaireAnswers) => {
48
+ leave();
24
49
  onSubmit(
25
50
  formatAnswers(
26
51
  questions,
@@ -30,23 +55,27 @@ export function QuestionCard({ questions, onSubmit, onDismiss }: QuestionCardPro
30
55
  })),
31
56
  ),
32
57
  );
58
+ };
33
59
 
34
60
  return (
35
- <Questionnaire
36
- questions={questions.map((q, i) => ({
37
- id: idOf(i),
38
- question: q.question,
39
- select: q.multiSelect ? 'multiple' : 'single',
40
- other: true,
41
- options: q.options.map((option, index) => ({
42
- value: String(index),
43
- label: option.label,
44
- description: option.description,
45
- })),
46
- }))}
47
- onComplete={complete}
48
- onDismiss={onDismiss}
49
- />
61
+ <View ref={rootRef}>
62
+ <Questionnaire
63
+ testID={testID}
64
+ questions={questions.map((q, i) => ({
65
+ id: idOf(i),
66
+ question: q.question,
67
+ select: q.multiSelect ? 'multiple' : 'single',
68
+ other: true,
69
+ options: q.options.map((option, index) => ({
70
+ value: String(index),
71
+ label: option.label,
72
+ description: option.description,
73
+ })),
74
+ }))}
75
+ onComplete={complete}
76
+ onDismiss={onDismiss ? dismiss : undefined}
77
+ />
78
+ </View>
50
79
  );
51
80
  }
52
81
 
@@ -0,0 +1,35 @@
1
+ import { RiTimeLine } from '@oxy.so/bloom/icons/RiTimeLine';
2
+ import { Muted } from '@oxy.so/bloom/typography';
3
+ import { StyleSheet, View } from 'react-native';
4
+ import { useLabels } from '../../lib/labels';
5
+
6
+ /**
7
+ * Where something the person wrote is, when it is not in the thread being answered yet:
8
+ *
9
+ * - `queued`: the first message of a conversation just created, waiting for the thread to send it;
10
+ * - `steering`: a reply to the waiting agent on its way into the turn that is running.
11
+ */
12
+ export type FollowUpState = 'queued' | 'steering';
13
+
14
+ /** One line above the composer, said while it is true and gone with it. */
15
+ export function FollowUpStatus({ state, agent }: { state: FollowUpState; agent: string }) {
16
+ const { t } = useLabels();
17
+ return (
18
+ <View style={styles.row} accessibilityLiveRegion="polite" aria-live="polite">
19
+ <RiTimeLine size="sm" />
20
+ <Muted>
21
+ {state === 'queued' ? t('chat.followUp.queued') : t('chat.followUp.steering', { agent })}
22
+ </Muted>
23
+ </View>
24
+ );
25
+ }
26
+
27
+ const styles = StyleSheet.create({
28
+ row: {
29
+ flexDirection: 'row',
30
+ alignItems: 'center',
31
+ gap: 8,
32
+ paddingHorizontal: 16,
33
+ paddingBottom: 8,
34
+ },
35
+ });
@@ -19,7 +19,9 @@ import { useMessageVote } from '../../hooks/useMessageVote';
19
19
  import { useMessageReactions } from '../../hooks/useMessageReactions';
20
20
  import { useOpenThought } from '../../hooks/useOpenThought';
21
21
  import { useReadAloud } from '../../hooks/useReadAloud';
22
+ import { FIND_BAR_CLEARANCE, useRowJump } from '../../hooks/useRowJump';
22
23
  import { useThoughtScope } from '../../hooks/useThoughtScope';
24
+ import type { ThreadJumpTarget } from '../../hooks/useThreadNavigation';
23
25
  import { useThreadRows } from '../../hooks/useThreadRows';
24
26
  import { useTimelineWindow } from '../../hooks/useTimelineWindow';
25
27
  import { useAgentRunFailureToast } from '../../hooks/useAgentRunFailureToast';
@@ -73,6 +75,10 @@ export interface GemieThreadProps {
73
75
  * any list — leaves the reader twenty messages past the thing they searched for.
74
76
  */
75
77
  focusCursor?: string | null;
78
+ /** A row to bring into view: a match of the find bar, or a turn picked from the list. */
79
+ jumpTo?: ThreadJumpTarget | null;
80
+ /** The message marked as the find bar's current match. */
81
+ highlightedId?: string | null;
76
82
  /**
77
83
  * The turn that got no answer. It is told with a toast and a Retry, and the person's message
78
84
  * stays in the thread.
@@ -143,6 +149,8 @@ export const GemieThread = memo(function GemieThread({
143
149
  conversationLoading = false,
144
150
  history: historyProps,
145
151
  focusCursor,
152
+ jumpTo,
153
+ highlightedId,
146
154
  failedTurn = null,
147
155
  onRetryTurn,
148
156
  onRegenerate,
@@ -282,6 +290,16 @@ export const GemieThread = memo(function GemieThread({
282
290
  onLoadHistory: loadMore,
283
291
  onScroll,
284
292
  });
293
+ // While a match is marked the find bar floats over the top: the list holds that room open, so
294
+ // even the first row can be brought out from under it.
295
+ const clearance = highlightedId == null ? 0 : FIND_BAR_CLEARANCE;
296
+ const { listRef, registerRow } = useRowJump({
297
+ clearance,
298
+ target: jumpTo,
299
+ ids,
300
+ reveal: timeline.reveal,
301
+ threadRef,
302
+ });
285
303
 
286
304
  const nothingToShow =
287
305
  rows.length === 0 && !conversationLoading && !isLoading && !loadingHistory && !voiceThinking;
@@ -323,6 +341,8 @@ export const GemieThread = memo(function GemieThread({
323
341
  isLoading={isLastReply ? isLoading : false}
324
342
  conversationId={conversationOf(index)}
325
343
  onLayout={index === focusIndex ? handleFocusLayout : undefined}
344
+ registerRow={registerRow}
345
+ highlighted={message.id === highlightedId}
326
346
  actions={actions}
327
347
  readAloudState={readAloud.stateOf(message.id)}
328
348
  readAloudBlocked={readAloud.blocked}
@@ -373,7 +393,11 @@ export const GemieThread = memo(function GemieThread({
373
393
  <View style={styles.column}>
374
394
  {rows.length === 0 && conversationLoading ? <ThreadSkeleton /> : null}
375
395
 
376
- <View style={styles.list} onLayout={timeline.onListLayout}>
396
+ <View
397
+ ref={listRef}
398
+ style={clearance === 0 ? styles.list : [styles.list, { paddingTop: clearance }]}
399
+ onLayout={timeline.onListLayout}
400
+ >
377
401
  {/* The slot the history loader shows in, held open for as long as there is history to
378
402
  load. The thread anchors ONE growth per request — the first after
379
403
  `onStartReached` — so a loader that appeared on request would spend that anchor on