@gemies/sdk 10.9.0 → 10.11.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 +37 -0
- package/package.json +1 -1
- package/src/components/GemieChatContent.tsx +37 -26
- package/src/components/GemieComposer.tsx +21 -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/ThreadRow.tsx +8 -3
- package/src/components/thread/TurnDiffComments.tsx +52 -0
- package/src/hooks/useChatComposer.ts +20 -3
- package/src/index.ts +8 -0
- package/src/lib/content-utils.ts +10 -0
- package/src/lib/copy-en.ts +15 -0
- package/src/lib/copy-es.ts +15 -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 +14 -7
- package/src/runtime/turn-failure.ts +26 -9
- package/src/runtime/use-conversation-stream.ts +22 -11
- 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,42 @@
|
|
|
1
1
|
# @gemies/sdk
|
|
2
2
|
|
|
3
|
+
## 10.11.0
|
|
4
|
+
|
|
5
|
+
### Error rows name the request
|
|
6
|
+
|
|
7
|
+
Every error body and stream error frame of the API now carries `traceId`, the id its logs are
|
|
8
|
+
written under (for a chat turn, the same value as the run `reference`). The line under a failed
|
|
9
|
+
turn ends in `Ref <id>` for a refused request too, after the server's message, and for a request
|
|
10
|
+
that failed outside the turn (`Something went wrong! · Ref req_…`). A turn that failed still reads
|
|
11
|
+
`CODE · Ref <reference>`. `failureDetail` (`@gemies/sdk/model`) takes `message` and `traceId`.
|
|
12
|
+
|
|
13
|
+
## 10.10.0
|
|
14
|
+
|
|
15
|
+
### Comments on diff lines go with the next message
|
|
16
|
+
|
|
17
|
+
In the diff viewer, a line number picks its line (a second one, or a drag on the highlighted view,
|
|
18
|
+
covers a run) and takes a comment. The comment shows under its last line and as a chip over the
|
|
19
|
+
composer, and the next message sent carries it: file, lines, the excerpt of the diff and the words.
|
|
20
|
+
Removing the chip (or the note under the line) takes it out. A message may be only comments.
|
|
21
|
+
|
|
22
|
+
- **How it travels.** No new API: each comment is a `<diff_comment …>` block after the person's
|
|
23
|
+
words in the message text (`composeTurnText` / `splitTurnText`, exported from
|
|
24
|
+
`@gemies/sdk/model`). The thread draws a sent comment as a card, not as the block; editing a turn,
|
|
25
|
+
or a send that fails, gives the comments back as chips. Surfaces that read the raw text of a
|
|
26
|
+
message see the block.
|
|
27
|
+
- **Draft.** Comments live in the composer draft (`ComposerDraft.diffComments`), per account and
|
|
28
|
+
conversation, in memory like the rest of it. `EditedTurn` now needs `diffComments`.
|
|
29
|
+
- **Renderers.** `GemiePatchViewProps` gains `annotations` (what to draw under which line),
|
|
30
|
+
`selection` and `onSelectLines`. A host renderer that ignores them draws as before and takes no
|
|
31
|
+
comments.
|
|
32
|
+
- **Composer.** `GemieComposer` takes `diffComments` and `onRemoveDiffComment`.
|
|
33
|
+
- Read-only threads (a shared conversation, one between gemies) take no comments.
|
|
34
|
+
- Find in the conversation and the list of turns read a sent comment as its card does (file name and
|
|
35
|
+
words), not as the block.
|
|
36
|
+
- `processMessage` reads a message once: text full of unclosed `[TAG` markers no longer takes
|
|
37
|
+
quadratic time. A tag whose attributes hold a `[` is now left as written.
|
|
38
|
+
- New words: `chat.diffComments.*` (en, es).
|
|
39
|
+
|
|
3
40
|
## 10.9.0
|
|
4
41
|
|
|
5
42
|
### Find, jump to a turn, and where a follow-up is
|
package/package.json
CHANGED
|
@@ -67,6 +67,7 @@ import {
|
|
|
67
67
|
} from '../lib/participants';
|
|
68
68
|
import { type GemieToolRenderers, GemieToolRenderersProvider } from '../lib/tool-renderers';
|
|
69
69
|
import { type GemieChartCards, GemieChartCardsProvider } from './charts/chart-cards';
|
|
70
|
+
import { DiffCommentsProvider, type DiffCommentsDraft } from './diff/diff-comments-context';
|
|
70
71
|
import { type GemieFileDiffRenderer, GemieFileDiffRendererProvider } from './diff/diff-renderer';
|
|
71
72
|
import { KeyboardSafeAreaFloor } from '../lib/keyboard';
|
|
72
73
|
import { type GemieChatLabels, GemieChatLabelsProvider, useLabels } from '../lib/labels';
|
|
@@ -529,6 +530,12 @@ function GemieConversationView({
|
|
|
529
530
|
},
|
|
530
531
|
[composer],
|
|
531
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
|
+
);
|
|
532
539
|
// Without a call handed down (a text-only entry), the chat is text-only whatever `voice` says. A
|
|
533
540
|
// group is too: a call has one gemie, and a group's turns are its members' (the server refuses it).
|
|
534
541
|
const VoiceCall = useContext(VoiceCallContext);
|
|
@@ -888,6 +895,8 @@ function GemieConversationView({
|
|
|
888
895
|
: { modes, mode: model ?? 'auto', onModeChange: onModelChange })}
|
|
889
896
|
addMenu={menu.groups}
|
|
890
897
|
onAddMenuSelect={menu.onSelect}
|
|
898
|
+
diffComments={diffComments}
|
|
899
|
+
onRemoveDiffComment={removeDiffComment}
|
|
891
900
|
attachments={composer.photos}
|
|
892
901
|
onAddAttachment={composer.addAttachment}
|
|
893
902
|
onRemoveAttachment={composer.removeAttachment}
|
|
@@ -919,32 +928,34 @@ function GemieConversationView({
|
|
|
919
928
|
>
|
|
920
929
|
<BubblesProvider value={bubbles || group !== undefined}>
|
|
921
930
|
<GemieConversationOpenerProvider value={setBetweenGemies}>
|
|
922
|
-
<
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
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>
|
|
948
959
|
</GemieConversationOpenerProvider>
|
|
949
960
|
</BubblesProvider>
|
|
950
961
|
{!showsPast ? 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. */
|
|
@@ -163,6 +172,8 @@ function GemieComposerBody<T extends GemieSuggestion>({
|
|
|
163
172
|
onAddAttachment,
|
|
164
173
|
onRemoveAttachment,
|
|
165
174
|
attachmentKinds,
|
|
175
|
+
diffComments = NO_DIFF_COMMENTS,
|
|
176
|
+
onRemoveDiffComment,
|
|
166
177
|
suggestions,
|
|
167
178
|
questions,
|
|
168
179
|
approval,
|
|
@@ -306,7 +317,11 @@ function GemieComposerBody<T extends GemieSuggestion>({
|
|
|
306
317
|
const remainingSeconds =
|
|
307
318
|
dictation.remainingMs === null ? null : Math.ceil(dictation.remainingMs / 1000);
|
|
308
319
|
|
|
309
|
-
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
|
+
);
|
|
310
325
|
const panelLabels = useMemo(
|
|
311
326
|
() => ({
|
|
312
327
|
message: labels.composerMessage,
|
|
@@ -346,6 +361,7 @@ function GemieComposerBody<T extends GemieSuggestion>({
|
|
|
346
361
|
/>
|
|
347
362
|
) : null}
|
|
348
363
|
{followUp}
|
|
364
|
+
<DiffCommentChips comments={diffComments} onRemove={removeComment} />
|
|
349
365
|
<ComposerLoader phase={loaderPhase ?? (busy ? 'streaming' : 'idle')}>
|
|
350
366
|
<ComposerPill
|
|
351
367
|
value={value}
|
|
@@ -375,7 +391,8 @@ function GemieComposerBody<T extends GemieSuggestion>({
|
|
|
375
391
|
// puts the item back to `reading` over the same `File`.
|
|
376
392
|
onAttachmentRetry={intake.retry}
|
|
377
393
|
status={status}
|
|
378
|
-
|
|
394
|
+
// The pill counts words and files; comments alone are something to send too.
|
|
395
|
+
emptyAction={diffComments.length === 0 ? emptyAction : undefined}
|
|
379
396
|
onKeyPress={handleKeyPress}
|
|
380
397
|
labels={panelLabels}
|
|
381
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
|
+
}));
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Chip } from '@oxy.so/bloom/chip';
|
|
2
|
+
import { RiChat3Line } from '@oxy.so/bloom/icons/RiChat3Line';
|
|
3
|
+
import { createTokenStyles } from '@oxy.so/bloom/theme';
|
|
4
|
+
import { View } from 'react-native';
|
|
5
|
+
import { useLabels } from '../../lib/labels';
|
|
6
|
+
import type { DiffComment } from '../../runtime/thread/diff-comments';
|
|
7
|
+
import { fileChangeName } from '../../runtime/thread/file-changes';
|
|
8
|
+
import { diffLinesLabel } from './diff-comments-context';
|
|
9
|
+
|
|
10
|
+
/** How much of a comment its chip shows. */
|
|
11
|
+
const PREVIEW_CHARS = 40;
|
|
12
|
+
|
|
13
|
+
const preview = (text: string) => {
|
|
14
|
+
const line = text.replace(/\s+/g, ' ').trim();
|
|
15
|
+
return line.length > PREVIEW_CHARS ? `${line.slice(0, PREVIEW_CHARS - 1)}…` : line;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The diff comments the next message carries, over the composer: the file and lines each is on and
|
|
20
|
+
* the start of what it says, with a way to take it out.
|
|
21
|
+
*/
|
|
22
|
+
export function DiffCommentChips({
|
|
23
|
+
comments,
|
|
24
|
+
onRemove,
|
|
25
|
+
}: {
|
|
26
|
+
comments: readonly DiffComment[];
|
|
27
|
+
onRemove: (id: string) => void;
|
|
28
|
+
}) {
|
|
29
|
+
const { t } = useLabels();
|
|
30
|
+
const styles = useStyles();
|
|
31
|
+
if (comments.length === 0) return null;
|
|
32
|
+
return (
|
|
33
|
+
<View style={styles.chips}>
|
|
34
|
+
{comments.map((comment) => {
|
|
35
|
+
const where = {
|
|
36
|
+
file: fileChangeName(comment.path),
|
|
37
|
+
lines: diffLinesLabel(t, comment.lines),
|
|
38
|
+
};
|
|
39
|
+
return (
|
|
40
|
+
<Chip
|
|
41
|
+
key={comment.id}
|
|
42
|
+
size="sm"
|
|
43
|
+
leadingIcon={RiChat3Line}
|
|
44
|
+
onClose={() => onRemove(comment.id)}
|
|
45
|
+
closeLabel={t('chat.diffComments.removeFrom', where)}
|
|
46
|
+
>
|
|
47
|
+
{`${t('chat.diffComments.chip', where)} · ${preview(comment.text)}`}
|
|
48
|
+
</Chip>
|
|
49
|
+
);
|
|
50
|
+
})}
|
|
51
|
+
</View>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const useStyles = createTokenStyles(() => ({
|
|
56
|
+
chips: { flexDirection: 'row', flexWrap: 'wrap', gap: 6, paddingHorizontal: 8, paddingBottom: 8 },
|
|
57
|
+
}));
|
|
@@ -9,8 +9,9 @@ import { View } from 'react-native';
|
|
|
9
9
|
import { copyText } from '../../lib/clipboard';
|
|
10
10
|
import { useLabels } from '../../lib/labels';
|
|
11
11
|
import { type CallFileChange, patchLines } from '../../runtime/thread/file-changes';
|
|
12
|
+
import { AnnotatedPatch } from './AnnotatedPatch';
|
|
13
|
+
import type { DiffCommentsDraft } from './diff-comments-context';
|
|
12
14
|
import type { DiffLayout, GemieFileDiffRenderer } from './diff-renderer';
|
|
13
|
-
import { PatchLines } from './PatchLines';
|
|
14
15
|
|
|
15
16
|
const MARK = { add: 'A', update: 'M', delete: 'D', rename: 'R' } as const;
|
|
16
17
|
|
|
@@ -40,6 +41,8 @@ export interface FileChangeSectionProps {
|
|
|
40
41
|
wrap: boolean;
|
|
41
42
|
/** The host's drawing of a patch; the SDK's plain lines when it brought none. */
|
|
42
43
|
renderer: GemieFileDiffRenderer | null;
|
|
44
|
+
/** The comments of the message being written; `null` where nothing takes them. */
|
|
45
|
+
draft: DiffCommentsDraft | null;
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
/**
|
|
@@ -54,6 +57,7 @@ export function FileChangeSection({
|
|
|
54
57
|
layout,
|
|
55
58
|
wrap,
|
|
56
59
|
renderer,
|
|
60
|
+
draft,
|
|
57
61
|
}: FileChangeSectionProps) {
|
|
58
62
|
const { t } = useLabels();
|
|
59
63
|
const { isDark, colors } = useTheme();
|
|
@@ -110,6 +114,7 @@ export function FileChangeSection({
|
|
|
110
114
|
layout={layout}
|
|
111
115
|
wrap={wrap}
|
|
112
116
|
renderer={renderer}
|
|
117
|
+
draft={draft}
|
|
113
118
|
appearance={isDark ? 'dark' : 'light'}
|
|
114
119
|
/>
|
|
115
120
|
</View>
|
|
@@ -124,12 +129,14 @@ function ChangeBody({
|
|
|
124
129
|
layout,
|
|
125
130
|
wrap,
|
|
126
131
|
renderer,
|
|
132
|
+
draft,
|
|
127
133
|
appearance,
|
|
128
134
|
}: {
|
|
129
135
|
change: CallFileChange;
|
|
130
136
|
layout: DiffLayout;
|
|
131
137
|
wrap: boolean;
|
|
132
138
|
renderer: GemieFileDiffRenderer | null;
|
|
139
|
+
draft: DiffCommentsDraft | null;
|
|
133
140
|
appearance: 'light' | 'dark';
|
|
134
141
|
}) {
|
|
135
142
|
const { t } = useLabels();
|
|
@@ -147,15 +154,15 @@ function ChangeBody({
|
|
|
147
154
|
if (change.additions === 0 && change.deletions === 0 && patchLines(change.patch).length === 0) {
|
|
148
155
|
return say('chat.fileChanges.noContent');
|
|
149
156
|
}
|
|
150
|
-
if (renderer === null) return <PatchLines patch={change.patch} wrap={wrap} />;
|
|
151
|
-
const { PatchView } = renderer;
|
|
152
157
|
return (
|
|
153
|
-
<
|
|
158
|
+
<AnnotatedPatch
|
|
154
159
|
patch={change.patch}
|
|
155
160
|
path={change.path}
|
|
156
|
-
layout={
|
|
161
|
+
layout={layout}
|
|
157
162
|
wrap={wrap}
|
|
158
163
|
appearance={appearance}
|
|
164
|
+
renderer={renderer}
|
|
165
|
+
draft={draft}
|
|
159
166
|
/>
|
|
160
167
|
);
|
|
161
168
|
}
|