@gemies/sdk 10.8.0 → 10.10.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 +47 -0
- package/README.md +4 -0
- package/package.json +1 -1
- package/src/components/GemieChatContent.tsx +117 -27
- package/src/components/GemieComposer.tsx +25 -4
- package/src/components/diff/AnnotatedPatch.tsx +125 -0
- package/src/components/diff/DiffCommentCards.tsx +132 -0
- package/src/components/diff/DiffCommentChips.tsx +57 -0
- package/src/components/diff/FileChangeSection.tsx +12 -5
- package/src/components/diff/FileChangesViewer.tsx +21 -5
- package/src/components/diff/PatchLines.tsx +124 -13
- package/src/components/diff/diff-comments-context.ts +29 -0
- package/src/components/diff/diff-renderer.ts +17 -1
- package/src/components/thread/FollowUpStatus.tsx +35 -0
- package/src/components/thread/GemieThread.tsx +25 -1
- package/src/components/thread/ThreadFindBar.tsx +121 -0
- package/src/components/thread/ThreadPanel.tsx +34 -0
- package/src/components/thread/ThreadRow.tsx +52 -12
- package/src/components/thread/ThreadSearch.tsx +61 -78
- package/src/components/thread/ThreadTurns.tsx +94 -0
- package/src/components/thread/TurnDiffComments.tsx +52 -0
- package/src/hooks/useChatComposer.ts +20 -3
- package/src/hooks/useFindShortcut.ts +57 -0
- package/src/hooks/useRowJump.ts +79 -0
- package/src/hooks/useThreadNavigation.ts +134 -0
- package/src/hooks/useTimelineWindow.ts +18 -1
- package/src/index.ts +8 -0
- package/src/lib/content-utils.ts +10 -0
- package/src/lib/copy-en.ts +26 -0
- package/src/lib/copy-es.ts +26 -0
- package/src/runtime/composer-draft-store.ts +43 -16
- package/src/runtime/model.ts +1 -0
- package/src/runtime/thread/diff-comments.ts +227 -0
- package/src/runtime/thread/message-processor.ts +58 -37
- package/src/runtime/thread/thread-find.ts +102 -0
- package/src/runtime/use-approval-actions.ts +7 -1
- package/src/runtime/use-conversation-thread.ts +10 -4
- package/src/runtime/use-start-conversation.ts +2 -1
- package/src/runtime/use-turn-edit.ts +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# @gemies/sdk
|
|
2
2
|
|
|
3
|
+
## 10.10.0
|
|
4
|
+
|
|
5
|
+
### Comments on diff lines go with the next message
|
|
6
|
+
|
|
7
|
+
In the diff viewer, a line number picks its line (a second one, or a drag on the highlighted view,
|
|
8
|
+
covers a run) and takes a comment. The comment shows under its last line and as a chip over the
|
|
9
|
+
composer, and the next message sent carries it: file, lines, the excerpt of the diff and the words.
|
|
10
|
+
Removing the chip (or the note under the line) takes it out. A message may be only comments.
|
|
11
|
+
|
|
12
|
+
- **How it travels.** No new API: each comment is a `<diff_comment …>` block after the person's
|
|
13
|
+
words in the message text (`composeTurnText` / `splitTurnText`, exported from
|
|
14
|
+
`@gemies/sdk/model`). The thread draws a sent comment as a card, not as the block; editing a turn,
|
|
15
|
+
or a send that fails, gives the comments back as chips. Surfaces that read the raw text of a
|
|
16
|
+
message see the block.
|
|
17
|
+
- **Draft.** Comments live in the composer draft (`ComposerDraft.diffComments`), per account and
|
|
18
|
+
conversation, in memory like the rest of it. `EditedTurn` now needs `diffComments`.
|
|
19
|
+
- **Renderers.** `GemiePatchViewProps` gains `annotations` (what to draw under which line),
|
|
20
|
+
`selection` and `onSelectLines`. A host renderer that ignores them draws as before and takes no
|
|
21
|
+
comments.
|
|
22
|
+
- **Composer.** `GemieComposer` takes `diffComments` and `onRemoveDiffComment`.
|
|
23
|
+
- Read-only threads (a shared conversation, one between gemies) take no comments.
|
|
24
|
+
- Find in the conversation and the list of turns read a sent comment as its card does (file name and
|
|
25
|
+
words), not as the block.
|
|
26
|
+
- `processMessage` reads a message once: text full of unclosed `[TAG` markers no longer takes
|
|
27
|
+
quadratic time. A tag whose attributes hold a `[` is now left as written.
|
|
28
|
+
- New words: `chat.diffComments.*` (en, es).
|
|
29
|
+
|
|
30
|
+
## 10.9.0
|
|
31
|
+
|
|
32
|
+
### Find, jump to a turn, and where a follow-up is
|
|
33
|
+
|
|
34
|
+
- **Find in the conversation.** `GemieChatState.openFind` (⌘F on a Mac, Ctrl+F elsewhere on web)
|
|
35
|
+
opens a bar that searches the words the loaded messages show, whatever their case or accents,
|
|
36
|
+
starting on the newest match. Enter goes to the one above, Shift+Enter below, Escape closes. The
|
|
37
|
+
current match is outlined and scrolled to, above the mounted window too. History not paged in yet
|
|
38
|
+
is not searched, and the bar says so; `openSearch` still searches a whole thread on the server.
|
|
39
|
+
While a chat on screen offers find, the browser's own does not open (it cannot see unmounted rows).
|
|
40
|
+
- **Jump to a turn.** `GemieChatState.openTurns` lists the questions, newest first, and a thread of
|
|
41
|
+
six turns or more has a button for it at its edge.
|
|
42
|
+
- **Where a follow-up is.** A line over the composer says when a new conversation's first message is
|
|
43
|
+
waiting to be sent, and when a reply to a waiting agent is on its way. `GemieComposer` takes it as
|
|
44
|
+
`followUp`, and `ApprovalActions` gained `steering`.
|
|
45
|
+
- A shared (`readOnly`) conversation's replies can be copied.
|
|
46
|
+
- The thread's search and the new panels open under the floating header rather than behind it.
|
|
47
|
+
- New words: `chat.find.*`, `chat.followUp.*`, `chat.turns.*` (en, es). A host with its own `t`
|
|
48
|
+
adds them.
|
|
49
|
+
|
|
3
50
|
## 10.8.0
|
|
4
51
|
|
|
5
52
|
### A plan to keep, and a question answered by keyboard
|
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
|
@@ -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';
|
|
@@ -65,6 +67,7 @@ import {
|
|
|
65
67
|
} from '../lib/participants';
|
|
66
68
|
import { type GemieToolRenderers, GemieToolRenderersProvider } from '../lib/tool-renderers';
|
|
67
69
|
import { type GemieChartCards, GemieChartCardsProvider } from './charts/chart-cards';
|
|
70
|
+
import { DiffCommentsProvider, type DiffCommentsDraft } from './diff/diff-comments-context';
|
|
68
71
|
import { type GemieFileDiffRenderer, GemieFileDiffRendererProvider } from './diff/diff-renderer';
|
|
69
72
|
import { KeyboardSafeAreaFloor } from '../lib/keyboard';
|
|
70
73
|
import { type GemieChatLabels, GemieChatLabelsProvider, useLabels } from '../lib/labels';
|
|
@@ -72,6 +75,7 @@ import { type DeviceModel, buildPowerLevelOptions } from '../lib/power-level-opt
|
|
|
72
75
|
import { GEMIE_FEATURES, featureOffer, useAgentFeatures, useAgentProfile } from '../runtime/agents';
|
|
73
76
|
import { type GemieRuntimeHost, GemieRuntimeProvider, useGemieRuntime } from '../runtime/config';
|
|
74
77
|
import { type GemieHostTools, APP_SLUG } from '../runtime/host-tools';
|
|
78
|
+
import { useConversationStore } from '../runtime/conversation-store';
|
|
75
79
|
import { useCreateConversation } from '../runtime/conversations';
|
|
76
80
|
import { useRefreshGemieThread } from '../runtime/use-gemie-thread';
|
|
77
81
|
import type { GemieThreadAddress } from '../runtime/routes';
|
|
@@ -87,8 +91,11 @@ import { GemieWelcomeMessage } from './GemieWelcomeMessage';
|
|
|
87
91
|
import { AmbientField } from './AmbientField';
|
|
88
92
|
import { InertWhen } from './InertWhen';
|
|
89
93
|
import { GemieBetweenGemies } from './GemieBetweenGemies';
|
|
94
|
+
import { FollowUpStatus } from './thread/FollowUpStatus';
|
|
90
95
|
import { GemieThread } from './thread/GemieThread';
|
|
96
|
+
import { ThreadFindBar } from './thread/ThreadFindBar';
|
|
91
97
|
import { ThreadSearch } from './thread/ThreadSearch';
|
|
98
|
+
import { LONG_THREAD_TURNS, ThreadTurnList, ThreadTurnsButton } from './thread/ThreadTurns';
|
|
92
99
|
import { VoiceModeIcon } from './VoiceModeIcon';
|
|
93
100
|
import { VoiceCallContext } from './voice/VoiceCallContext';
|
|
94
101
|
import { createTokenStyles } from '@oxy.so/bloom/theme';
|
|
@@ -116,6 +123,10 @@ export interface GemieChatState {
|
|
|
116
123
|
participants: GemieChatParticipants;
|
|
117
124
|
/** Search what was said in the agent's thread. Present only on a thread (`threadHandle`, `gemieThread`). */
|
|
118
125
|
openSearch: (() => void) | undefined;
|
|
126
|
+
/** Find words in the conversation on screen (⌘F / Ctrl+F on web). Present once there is something to find. */
|
|
127
|
+
openFind: (() => void) | undefined;
|
|
128
|
+
/** The list of the conversation's turns, each a jump to it. Present once there is a turn. */
|
|
129
|
+
openTurns: (() => void) | undefined;
|
|
119
130
|
/** The conversation as it stands now, for an export. Read when called, not when rendered. */
|
|
120
131
|
getMessages: () => readonly Message[];
|
|
121
132
|
}
|
|
@@ -519,6 +530,12 @@ function GemieConversationView({
|
|
|
519
530
|
},
|
|
520
531
|
[composer],
|
|
521
532
|
);
|
|
533
|
+
// The diff viewers in the thread write their comments into this chat's draft.
|
|
534
|
+
const { diffComments, addDiffComment, removeDiffComment } = composer;
|
|
535
|
+
const diffCommentsDraft = useMemo<DiffCommentsDraft>(
|
|
536
|
+
() => ({ comments: diffComments, add: addDiffComment, remove: removeDiffComment }),
|
|
537
|
+
[diffComments, addDiffComment, removeDiffComment],
|
|
538
|
+
);
|
|
522
539
|
// Without a call handed down (a text-only entry), the chat is text-only whatever `voice` says. A
|
|
523
540
|
// group is too: a call has one gemie, and a group's turns are its members' (the server refuses it).
|
|
524
541
|
const VoiceCall = useContext(VoiceCallContext);
|
|
@@ -705,6 +722,49 @@ function GemieConversationView({
|
|
|
705
722
|
if (sent) composer.setText('');
|
|
706
723
|
}, [approvals, composer, decliningOption]);
|
|
707
724
|
|
|
725
|
+
// ── Moving around a long thread: find, and the list of turns ──
|
|
726
|
+
const showsPast = view.jumped;
|
|
727
|
+
const pastMessages = view.history?.messages;
|
|
728
|
+
/** What the thread draws, oldest first: the history behind it, then the conversation. */
|
|
729
|
+
const threadRows = useMemo<Message[]>(
|
|
730
|
+
() => [
|
|
731
|
+
...(pastMessages ?? []),
|
|
732
|
+
// Nothing live under a window: it is a view of the past.
|
|
733
|
+
...(showsPast ? [] : messages.filter((m) => m.role === 'user' || m.role === 'assistant')),
|
|
734
|
+
],
|
|
735
|
+
[pastMessages, showsPast, messages],
|
|
736
|
+
);
|
|
737
|
+
const navigation = useThreadNavigation(threadRows, conversationId);
|
|
738
|
+
const { openFind, openTurns, close: closeNavigation } = navigation;
|
|
739
|
+
const { closeSearch, openSearch: openThreadSearch } = view;
|
|
740
|
+
// One thing over the thread at a time.
|
|
741
|
+
const findInThread = useCallback(() => {
|
|
742
|
+
closeSearch();
|
|
743
|
+
openFind();
|
|
744
|
+
}, [closeSearch, openFind]);
|
|
745
|
+
const listTurns = useCallback(() => {
|
|
746
|
+
closeSearch();
|
|
747
|
+
openTurns();
|
|
748
|
+
}, [closeSearch, openTurns]);
|
|
749
|
+
const searchThread = useCallback(() => {
|
|
750
|
+
closeNavigation();
|
|
751
|
+
openThreadSearch();
|
|
752
|
+
}, [closeNavigation, openThreadSearch]);
|
|
753
|
+
const turnCount = useMemo(
|
|
754
|
+
() => threadRows.reduce((count, m) => (m.role === 'user' ? count + 1 : count), 0),
|
|
755
|
+
[threadRows],
|
|
756
|
+
);
|
|
757
|
+
const canFind = threadRows.length > 0;
|
|
758
|
+
const canList = turnCount > 0;
|
|
759
|
+
useFindShortcut(canFind && isFocused && betweenGemies === null ? findInThread : undefined);
|
|
760
|
+
|
|
761
|
+
// A message not yet in a turn being answered: said above the composer while that is so.
|
|
762
|
+
const queued = useConversationStore(
|
|
763
|
+
(s) =>
|
|
764
|
+
conversationId !== undefined && s.pendingInitialMessage?.conversationId === conversationId,
|
|
765
|
+
);
|
|
766
|
+
const followUp = approvals.steering.size > 0 ? 'steering' : queued ? 'queued' : undefined;
|
|
767
|
+
|
|
708
768
|
// ── The chrome ──
|
|
709
769
|
const latestMessages = useRef(messages);
|
|
710
770
|
latestMessages.current = messages;
|
|
@@ -717,7 +777,9 @@ function GemieConversationView({
|
|
|
717
777
|
clearMessages: clearConversation,
|
|
718
778
|
markState: voice.markState,
|
|
719
779
|
participants,
|
|
720
|
-
openSearch: threadAddress === undefined ? undefined :
|
|
780
|
+
openSearch: threadAddress === undefined ? undefined : searchThread,
|
|
781
|
+
openFind: canFind ? findInThread : undefined,
|
|
782
|
+
openTurns: canList ? listTurns : undefined,
|
|
721
783
|
getMessages: () => latestMessages.current,
|
|
722
784
|
}),
|
|
723
785
|
[
|
|
@@ -728,7 +790,11 @@ function GemieConversationView({
|
|
|
728
790
|
voice.markState,
|
|
729
791
|
participants,
|
|
730
792
|
threadAddress,
|
|
731
|
-
|
|
793
|
+
searchThread,
|
|
794
|
+
canFind,
|
|
795
|
+
findInThread,
|
|
796
|
+
canList,
|
|
797
|
+
listTurns,
|
|
732
798
|
],
|
|
733
799
|
);
|
|
734
800
|
const frame = useMemo(() => chrome?.(state) ?? {}, [chrome, state]);
|
|
@@ -790,6 +856,11 @@ function GemieConversationView({
|
|
|
790
856
|
onSubmit={() => void (replyDeclines ? submitReply() : composer.submit(composer.text))}
|
|
791
857
|
// Stop gives way to send while a reply would decline the question the agent waits on.
|
|
792
858
|
busy={isLoading && !replyDeclines}
|
|
859
|
+
followUp={
|
|
860
|
+
followUp === undefined ? undefined : (
|
|
861
|
+
<FollowUpStatus state={followUp} agent={lead.name} />
|
|
862
|
+
)
|
|
863
|
+
}
|
|
793
864
|
approval={
|
|
794
865
|
approvals.pending === undefined ? undefined : (
|
|
795
866
|
<ApprovalBar approvals={approvals} isFocused={isFocused} />
|
|
@@ -824,6 +895,8 @@ function GemieConversationView({
|
|
|
824
895
|
: { modes, mode: model ?? 'auto', onModeChange: onModelChange })}
|
|
825
896
|
addMenu={menu.groups}
|
|
826
897
|
onAddMenuSelect={menu.onSelect}
|
|
898
|
+
diffComments={diffComments}
|
|
899
|
+
onRemoveDiffComment={removeDiffComment}
|
|
827
900
|
attachments={composer.photos}
|
|
828
901
|
onAddAttachment={composer.addAttachment}
|
|
829
902
|
onRemoveAttachment={composer.removeAttachment}
|
|
@@ -835,7 +908,6 @@ function GemieConversationView({
|
|
|
835
908
|
</>
|
|
836
909
|
);
|
|
837
910
|
|
|
838
|
-
const showsPast = view.jumped;
|
|
839
911
|
return (
|
|
840
912
|
<GemieFlightsProvider value={flights}>
|
|
841
913
|
<InertWhen inert={betweenGemies !== null}>
|
|
@@ -856,30 +928,34 @@ function GemieConversationView({
|
|
|
856
928
|
>
|
|
857
929
|
<BubblesProvider value={bubbles || group !== undefined}>
|
|
858
930
|
<GemieConversationOpenerProvider value={setBetweenGemies}>
|
|
859
|
-
<
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
931
|
+
<DiffCommentsProvider value={diffCommentsDraft}>
|
|
932
|
+
<GemieThread
|
|
933
|
+
// Nothing live under a window: it is a view of the past, and the conversation being
|
|
934
|
+
// streamed into is not below it in the thread.
|
|
935
|
+
messages={showsPast ? NO_MESSAGES : messages}
|
|
936
|
+
conversationId={conversationId}
|
|
937
|
+
isLoading={isLoading}
|
|
938
|
+
conversationLoading={conversationLoading || loading}
|
|
939
|
+
history={view.history}
|
|
940
|
+
focusCursor={view.focusCursor}
|
|
941
|
+
jumpTo={navigation.jump}
|
|
942
|
+
highlightedId={navigation.highlightedId}
|
|
943
|
+
failedTurn={failedTurn}
|
|
944
|
+
onRetryTurn={retryFailedTurn}
|
|
945
|
+
onRegenerate={composer.regenerate}
|
|
946
|
+
onStartEdit={edit.start}
|
|
947
|
+
newConversationOffer={newConversationOffer}
|
|
948
|
+
approvals={approvals}
|
|
949
|
+
actionApprovals={showsPast ? undefined : actionApprovals}
|
|
950
|
+
agentActivity={agentRun === null ? null : agentActivity}
|
|
951
|
+
call={voice.isActive ? { agentState: voice.agentState } : undefined}
|
|
952
|
+
empty={welcome}
|
|
953
|
+
threadRef={threadRef}
|
|
954
|
+
onScroll={onScroll}
|
|
955
|
+
onReply={quoteIntoComposer}
|
|
956
|
+
onReactionChange={thread.applyReaction}
|
|
957
|
+
/>
|
|
958
|
+
</DiffCommentsProvider>
|
|
883
959
|
</GemieConversationOpenerProvider>
|
|
884
960
|
</BubblesProvider>
|
|
885
961
|
{!showsPast ? null : (
|
|
@@ -892,6 +968,20 @@ function GemieConversationView({
|
|
|
892
968
|
{!view.searchOpen || threadAddress === undefined ? null : (
|
|
893
969
|
<ThreadSearch thread={threadAddress} onJump={view.jump} onClose={view.closeSearch} />
|
|
894
970
|
)}
|
|
971
|
+
{navigation.panel === 'find' ? (
|
|
972
|
+
<ThreadFindBar find={navigation} partial={view.history?.loadMore !== undefined} />
|
|
973
|
+
) : null}
|
|
974
|
+
{navigation.panel === 'turns' ? (
|
|
975
|
+
<ThreadTurnList
|
|
976
|
+
turns={navigation.turns}
|
|
977
|
+
onJump={navigation.jumpToTurn}
|
|
978
|
+
onLoadEarlier={view.history?.loadMore}
|
|
979
|
+
onClose={navigation.close}
|
|
980
|
+
/>
|
|
981
|
+
) : null}
|
|
982
|
+
{navigation.panel === null && !view.searchOpen && turnCount >= LONG_THREAD_TURNS ? (
|
|
983
|
+
<ThreadTurnsButton onPress={listTurns} />
|
|
984
|
+
) : null}
|
|
895
985
|
</AiChatContainer>
|
|
896
986
|
</InertWhen>
|
|
897
987
|
{betweenGemies === null ? null : (
|
|
@@ -28,12 +28,14 @@ import type { TextInputHandle } from '../lib/text-input';
|
|
|
28
28
|
import { type GemieChatLabels, GemieChatLabelsProvider, useLabels } from '../lib/labels';
|
|
29
29
|
import type { AskedQuestion } from '../lib/questions';
|
|
30
30
|
import type { VoiceErrorCode } from '../lib/speech-messages';
|
|
31
|
+
import type { DiffComment } from '../runtime/thread/diff-comments';
|
|
31
32
|
import type { GemieAttachment, GemieSuggestion } from '../types';
|
|
32
33
|
import {
|
|
33
34
|
ComposerDropOverlay,
|
|
34
35
|
useComposerDropTarget,
|
|
35
36
|
useComposerPasteTarget,
|
|
36
37
|
} from './ComposerDropZone';
|
|
38
|
+
import { DiffCommentChips } from './diff/DiffCommentChips';
|
|
37
39
|
import { ComposerSuggestions } from './ComposerSuggestions';
|
|
38
40
|
import { QuestionCard } from './QuestionCard';
|
|
39
41
|
import type { ShortcutKeyEvent } from '../hooks/useApprovalShortcuts';
|
|
@@ -48,8 +50,8 @@ import { createTokenStyles } from '@oxy.so/bloom/theme';
|
|
|
48
50
|
* pill's permission picker, which is the host's power-level selector), the mic, send / stop, the
|
|
49
51
|
* attachment tiles and the status tab. What this adds is what every Alia surface needs the same
|
|
50
52
|
* way: files arriving by paste and drop (read with real progress, retried, refused with a
|
|
51
|
-
* sentence), dictation, the suggestions over the field,
|
|
52
|
-
* above it. What differs per surface is a prop: the add menu and the modes are the host's,
|
|
53
|
+
* sentence), dictation, the suggestions over the field, the questions Alia asked docked
|
|
54
|
+
* above it, and the diff comments the next message carries. What differs per surface is a prop: the add menu and the modes are the host's,
|
|
53
55
|
* and a host that offers no way to attach files gets no paste or drop either.
|
|
54
56
|
*
|
|
55
57
|
* A running turn is the stop control and the container's thinking line; the panel takes no
|
|
@@ -59,6 +61,7 @@ const EMPTY_ADD_MENU: readonly ComposerPanelAddMenuGroup[] = [];
|
|
|
59
61
|
/** `[]` hides the selector; Bloom's own four modes are not Alia's. */
|
|
60
62
|
const NO_MODES: readonly ComposerPanelPermissionOption[] = [];
|
|
61
63
|
const NO_ATTACHMENTS: readonly GemieAttachment[] = [];
|
|
64
|
+
const NO_DIFF_COMMENTS: readonly DiffComment[] = [];
|
|
62
65
|
|
|
63
66
|
/** The rows over the field, as `useComposerSuggestions` hands them back. */
|
|
64
67
|
export interface GemieComposerSuggestions<T extends GemieSuggestion = GemieSuggestion> {
|
|
@@ -109,6 +112,12 @@ export interface GemieComposerProps<T extends GemieSuggestion = GemieSuggestion>
|
|
|
109
112
|
onRemoveAttachment?: (id: string) => void;
|
|
110
113
|
/** The kinds of file the host's send carries; others are refused with a sentence. Default both. */
|
|
111
114
|
attachmentKinds?: readonly IntakeKind[];
|
|
115
|
+
/**
|
|
116
|
+
* The comments on diff lines the draft holds, drawn as chips over the field. A draft with one has
|
|
117
|
+
* something to send, with or without words.
|
|
118
|
+
*/
|
|
119
|
+
diffComments?: readonly DiffComment[];
|
|
120
|
+
onRemoveDiffComment?: (id: string) => void;
|
|
112
121
|
/** The suggestions drawn over the field. Their keys are the host's `onKeyPress`. */
|
|
113
122
|
suggestions?: GemieComposerSuggestions<T>;
|
|
114
123
|
/** What Alia is waiting on, docked above the composer. */
|
|
@@ -118,6 +127,8 @@ export interface GemieComposerProps<T extends GemieSuggestion = GemieSuggestion>
|
|
|
118
127
|
* questions: where the person is about to type the reply that declines it.
|
|
119
128
|
*/
|
|
120
129
|
approval?: ReactNode;
|
|
130
|
+
/** Where a message that is not in a running turn yet is (`FollowUpStatus`), over the field. */
|
|
131
|
+
followUp?: ReactNode;
|
|
121
132
|
/** The tab on the card's top edge (`ComposerPanelStatusTab`). */
|
|
122
133
|
status?: ReactNode;
|
|
123
134
|
/** Drawn where send would be while there is nothing to send (voice mode). */
|
|
@@ -161,9 +172,12 @@ function GemieComposerBody<T extends GemieSuggestion>({
|
|
|
161
172
|
onAddAttachment,
|
|
162
173
|
onRemoveAttachment,
|
|
163
174
|
attachmentKinds,
|
|
175
|
+
diffComments = NO_DIFF_COMMENTS,
|
|
176
|
+
onRemoveDiffComment,
|
|
164
177
|
suggestions,
|
|
165
178
|
questions,
|
|
166
179
|
approval,
|
|
180
|
+
followUp,
|
|
167
181
|
status,
|
|
168
182
|
emptyAction,
|
|
169
183
|
accessory,
|
|
@@ -303,7 +317,11 @@ function GemieComposerBody<T extends GemieSuggestion>({
|
|
|
303
317
|
const remainingSeconds =
|
|
304
318
|
dictation.remainingMs === null ? null : Math.ceil(dictation.remainingMs / 1000);
|
|
305
319
|
|
|
306
|
-
const hasContent = value.trim() !== '' || attachments.length > 0;
|
|
320
|
+
const hasContent = value.trim() !== '' || attachments.length > 0 || diffComments.length > 0;
|
|
321
|
+
const removeComment = useCallback(
|
|
322
|
+
(id: string) => onRemoveDiffComment?.(id),
|
|
323
|
+
[onRemoveDiffComment],
|
|
324
|
+
);
|
|
307
325
|
const panelLabels = useMemo(
|
|
308
326
|
() => ({
|
|
309
327
|
message: labels.composerMessage,
|
|
@@ -342,6 +360,8 @@ function GemieComposerBody<T extends GemieSuggestion>({
|
|
|
342
360
|
onReturnFocus={returnToField}
|
|
343
361
|
/>
|
|
344
362
|
) : null}
|
|
363
|
+
{followUp}
|
|
364
|
+
<DiffCommentChips comments={diffComments} onRemove={removeComment} />
|
|
345
365
|
<ComposerLoader phase={loaderPhase ?? (busy ? 'streaming' : 'idle')}>
|
|
346
366
|
<ComposerPill
|
|
347
367
|
value={value}
|
|
@@ -371,7 +391,8 @@ function GemieComposerBody<T extends GemieSuggestion>({
|
|
|
371
391
|
// puts the item back to `reading` over the same `File`.
|
|
372
392
|
onAttachmentRetry={intake.retry}
|
|
373
393
|
status={status}
|
|
374
|
-
|
|
394
|
+
// The pill counts words and files; comments alone are something to send too.
|
|
395
|
+
emptyAction={diffComments.length === 0 ? emptyAction : undefined}
|
|
375
396
|
onKeyPress={handleKeyPress}
|
|
376
397
|
labels={panelLabels}
|
|
377
398
|
// The loader paints the pill's surface behind its light; the controls go frosted over it.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { createTokenStyles } from '@oxy.so/bloom/theme';
|
|
2
|
+
import { type ReactNode, useCallback, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import {
|
|
5
|
+
createDiffComment,
|
|
6
|
+
type DiffLinePoint,
|
|
7
|
+
type DiffLineRange,
|
|
8
|
+
type DiffSelection,
|
|
9
|
+
diffCommentsOn,
|
|
10
|
+
selectDiffLines,
|
|
11
|
+
} from '../../runtime/thread/diff-comments';
|
|
12
|
+
import { DiffCommentEditor, DiffCommentNote } from './DiffCommentCards';
|
|
13
|
+
import type { DiffCommentsDraft } from './diff-comments-context';
|
|
14
|
+
import type {
|
|
15
|
+
DiffLayout,
|
|
16
|
+
GemieDiffAnnotation,
|
|
17
|
+
GemieFileDiffRenderer,
|
|
18
|
+
GemiePatchViewProps,
|
|
19
|
+
} from './diff-renderer';
|
|
20
|
+
import { PatchLines } from './PatchLines';
|
|
21
|
+
|
|
22
|
+
export interface AnnotatedPatchProps
|
|
23
|
+
extends Pick<GemiePatchViewProps, 'patch' | 'path' | 'wrap' | 'appearance'> {
|
|
24
|
+
layout: DiffLayout;
|
|
25
|
+
/** The host's drawing of a patch; the SDK's plain lines when it brought none. */
|
|
26
|
+
renderer: GemieFileDiffRenderer | null;
|
|
27
|
+
draft: DiffCommentsDraft | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const pointKey = ({ side, line }: DiffLinePoint) => `${side}:${line}`;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* One file's patch with its comments: under each commented line the comments the message being
|
|
34
|
+
* written holds on it, and, under the last of the lines just picked, the editor for a new one.
|
|
35
|
+
* Whichever draws the patch gets the same annotations.
|
|
36
|
+
*/
|
|
37
|
+
export function AnnotatedPatch({
|
|
38
|
+
patch,
|
|
39
|
+
path,
|
|
40
|
+
layout,
|
|
41
|
+
wrap,
|
|
42
|
+
appearance,
|
|
43
|
+
renderer,
|
|
44
|
+
draft,
|
|
45
|
+
}: AnnotatedPatchProps) {
|
|
46
|
+
const styles = useStyles();
|
|
47
|
+
const [selection, setSelection] = useState<DiffSelection | null>(null);
|
|
48
|
+
// The words being typed outlive the editor, which moves when the run of lines grows; they are
|
|
49
|
+
// kept in a ref so a keystroke does not draw the patch again.
|
|
50
|
+
const words = useRef('');
|
|
51
|
+
|
|
52
|
+
const select = useCallback(
|
|
53
|
+
(range: DiffLineRange) => {
|
|
54
|
+
const picked = selectDiffLines(patch, range);
|
|
55
|
+
if (picked !== null) setSelection(picked);
|
|
56
|
+
},
|
|
57
|
+
[patch],
|
|
58
|
+
);
|
|
59
|
+
const close = useCallback(() => {
|
|
60
|
+
words.current = '';
|
|
61
|
+
setSelection(null);
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
const comments = draft?.comments;
|
|
65
|
+
const add = draft?.add;
|
|
66
|
+
const remove = draft?.remove;
|
|
67
|
+
const annotations = useMemo<GemieDiffAnnotation[]>(() => {
|
|
68
|
+
if (comments === undefined || add === undefined || remove === undefined) return [];
|
|
69
|
+
const lines = new Map<string, { at: DiffLinePoint; notes: ReactNode[] }>();
|
|
70
|
+
const under = (at: DiffLinePoint) => {
|
|
71
|
+
const key = pointKey(at);
|
|
72
|
+
const line = lines.get(key) ?? { at, notes: [] };
|
|
73
|
+
lines.set(key, line);
|
|
74
|
+
return line.notes;
|
|
75
|
+
};
|
|
76
|
+
for (const comment of diffCommentsOn(comments, path, patch)) {
|
|
77
|
+
under(comment.range.to).push(
|
|
78
|
+
<DiffCommentNote key={comment.id} comment={comment} onRemove={() => remove(comment.id)} />,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
if (selection !== null) {
|
|
82
|
+
under(selection.range.to).push(
|
|
83
|
+
<DiffCommentEditor
|
|
84
|
+
key="editor"
|
|
85
|
+
lines={selection.lines}
|
|
86
|
+
initialText={() => words.current}
|
|
87
|
+
onTextChange={(text) => {
|
|
88
|
+
words.current = text;
|
|
89
|
+
}}
|
|
90
|
+
onCancel={close}
|
|
91
|
+
onSubmit={(text) => {
|
|
92
|
+
add(createDiffComment(path, selection, text));
|
|
93
|
+
close();
|
|
94
|
+
}}
|
|
95
|
+
/>,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return [...lines.values()].map(({ at, notes }) => ({
|
|
99
|
+
at,
|
|
100
|
+
content: <View style={styles.notes}>{notes}</View>,
|
|
101
|
+
}));
|
|
102
|
+
}, [comments, add, remove, path, patch, selection, close, styles]);
|
|
103
|
+
|
|
104
|
+
const view = {
|
|
105
|
+
patch,
|
|
106
|
+
wrap,
|
|
107
|
+
annotations,
|
|
108
|
+
selection: selection?.range ?? null,
|
|
109
|
+
...(draft === null ? {} : { onSelectLines: select }),
|
|
110
|
+
};
|
|
111
|
+
if (renderer === null) return <PatchLines {...view} />;
|
|
112
|
+
const { PatchView } = renderer;
|
|
113
|
+
return (
|
|
114
|
+
<PatchView
|
|
115
|
+
{...view}
|
|
116
|
+
path={path}
|
|
117
|
+
layout={renderer.layouts.includes(layout) ? layout : 'unified'}
|
|
118
|
+
appearance={appearance}
|
|
119
|
+
/>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const useStyles = createTokenStyles(() => ({
|
|
124
|
+
notes: { gap: 6, paddingHorizontal: 12, paddingVertical: 8 },
|
|
125
|
+
}));
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Button } from '@oxy.so/bloom/button';
|
|
2
|
+
import { RiCloseLine } from '@oxy.so/bloom/icons/RiCloseLine';
|
|
3
|
+
import { Textarea } from '@oxy.so/bloom/textarea';
|
|
4
|
+
import { createTokenStyles } from '@oxy.so/bloom/theme';
|
|
5
|
+
import { Muted, Text } from '@oxy.so/bloom/typography';
|
|
6
|
+
import { useState } from 'react';
|
|
7
|
+
import { type TextInputKeyPressEvent, View } from 'react-native';
|
|
8
|
+
import { useLabels } from '../../lib/labels';
|
|
9
|
+
import {
|
|
10
|
+
DIFF_COMMENT_MAX_CHARS,
|
|
11
|
+
type DiffComment,
|
|
12
|
+
type DiffLineSpan,
|
|
13
|
+
} from '../../runtime/thread/diff-comments';
|
|
14
|
+
import { diffLinesLabel } from './diff-comments-context';
|
|
15
|
+
|
|
16
|
+
/** A comment of the message being written, under the lines it is about. */
|
|
17
|
+
export function DiffCommentNote({
|
|
18
|
+
comment,
|
|
19
|
+
onRemove,
|
|
20
|
+
}: {
|
|
21
|
+
comment: DiffComment;
|
|
22
|
+
onRemove: () => void;
|
|
23
|
+
}) {
|
|
24
|
+
const { t } = useLabels();
|
|
25
|
+
const styles = useStyles();
|
|
26
|
+
const lines = diffLinesLabel(t, comment.lines);
|
|
27
|
+
return (
|
|
28
|
+
<View style={styles.card}>
|
|
29
|
+
<View style={styles.header}>
|
|
30
|
+
<Muted style={styles.lines}>{lines}</Muted>
|
|
31
|
+
<Button
|
|
32
|
+
iconOnly
|
|
33
|
+
size="xs"
|
|
34
|
+
appearance="plain"
|
|
35
|
+
tone="neutral"
|
|
36
|
+
leadingIcon={RiCloseLine}
|
|
37
|
+
accessibilityLabel={t('chat.diffComments.remove', { lines })}
|
|
38
|
+
onPress={onRemove}
|
|
39
|
+
/>
|
|
40
|
+
</View>
|
|
41
|
+
<Text style={styles.text} selectable>
|
|
42
|
+
{comment.text}
|
|
43
|
+
</Text>
|
|
44
|
+
</View>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Where a comment is written. Adding it puts it in the message; Cmd or Ctrl and Enter add it,
|
|
50
|
+
* Escape gives it up.
|
|
51
|
+
*/
|
|
52
|
+
export function DiffCommentEditor({
|
|
53
|
+
lines,
|
|
54
|
+
initialText,
|
|
55
|
+
onTextChange,
|
|
56
|
+
onCancel,
|
|
57
|
+
onSubmit,
|
|
58
|
+
}: {
|
|
59
|
+
lines: DiffLineSpan;
|
|
60
|
+
/** What was typed so far: the editor is made afresh when the patch is drawn anew around it. */
|
|
61
|
+
initialText: () => string;
|
|
62
|
+
onTextChange: (text: string) => void;
|
|
63
|
+
onCancel: () => void;
|
|
64
|
+
onSubmit: (text: string) => void;
|
|
65
|
+
}) {
|
|
66
|
+
const { t } = useLabels();
|
|
67
|
+
const styles = useStyles();
|
|
68
|
+
const [text, setText] = useState(initialText);
|
|
69
|
+
const label = diffLinesLabel(t, lines);
|
|
70
|
+
const ready = text.trim() !== '';
|
|
71
|
+
|
|
72
|
+
const change = (next: string) => {
|
|
73
|
+
setText(next);
|
|
74
|
+
onTextChange(next);
|
|
75
|
+
};
|
|
76
|
+
const submit = () => {
|
|
77
|
+
if (ready) onSubmit(text);
|
|
78
|
+
};
|
|
79
|
+
const onKeyPress = (event: TextInputKeyPressEvent) => {
|
|
80
|
+
const key = event.nativeEvent as { key: string; metaKey?: boolean; ctrlKey?: boolean };
|
|
81
|
+
if (key.key === 'Escape') {
|
|
82
|
+
// Claimed, so the viewer around the editor does not close with it.
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
onCancel();
|
|
85
|
+
} else if (key.key === 'Enter' && (key.metaKey || key.ctrlKey)) {
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
submit();
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<View style={styles.card}>
|
|
93
|
+
<Muted style={styles.lines}>{label}</Muted>
|
|
94
|
+
<Textarea
|
|
95
|
+
size="sm"
|
|
96
|
+
rows={2}
|
|
97
|
+
autoResize
|
|
98
|
+
maxRows={8}
|
|
99
|
+
autoFocus
|
|
100
|
+
maxLength={DIFF_COMMENT_MAX_CHARS}
|
|
101
|
+
value={text}
|
|
102
|
+
onValueChange={change}
|
|
103
|
+
onKeyPress={onKeyPress}
|
|
104
|
+
placeholder={t('chat.diffComments.placeholder')}
|
|
105
|
+
accessibilityLabel={t('chat.diffComments.field', { lines: label })}
|
|
106
|
+
/>
|
|
107
|
+
<View style={styles.actions}>
|
|
108
|
+
<Button size="xs" appearance="plain" tone="neutral" onPress={onCancel}>
|
|
109
|
+
{t('chat.diffComments.cancel')}
|
|
110
|
+
</Button>
|
|
111
|
+
<Button size="xs" tone="action" disabled={!ready} onPress={submit}>
|
|
112
|
+
{t('chat.diffComments.add')}
|
|
113
|
+
</Button>
|
|
114
|
+
</View>
|
|
115
|
+
</View>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const useStyles = createTokenStyles((t) => ({
|
|
120
|
+
card: {
|
|
121
|
+
gap: 6,
|
|
122
|
+
padding: 8,
|
|
123
|
+
borderWidth: 1,
|
|
124
|
+
borderColor: t.border,
|
|
125
|
+
borderRadius: 8,
|
|
126
|
+
backgroundColor: t.card,
|
|
127
|
+
},
|
|
128
|
+
header: { flexDirection: 'row', alignItems: 'center', gap: 8 },
|
|
129
|
+
lines: { flexGrow: 1, fontSize: 12 },
|
|
130
|
+
text: { fontSize: 13, lineHeight: 18 },
|
|
131
|
+
actions: { flexDirection: 'row', justifyContent: 'flex-end', gap: 8 },
|
|
132
|
+
}));
|