@gemies/sdk 10.9.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.
@@ -9,10 +9,13 @@ import {
9
9
  SegmentedControlItemText,
10
10
  } from '@oxy.so/bloom/segmented-control';
11
11
  import { createTokenStyles } from '@oxy.so/bloom/theme';
12
+ import { Muted } from '@oxy.so/bloom/typography';
12
13
  import { useMemo, useState } from 'react';
13
14
  import { View } from 'react-native';
14
15
  import { useLabels } from '../../lib/labels';
16
+ import { type DiffComment, diffCommentsOn } from '../../runtime/thread/diff-comments';
15
17
  import { type CallFileChange, fileChangeTotals } from '../../runtime/thread/file-changes';
18
+ import { useDiffCommentsDraft } from './diff-comments-context';
16
19
  import { type DiffLayout, useFileDiffRenderer } from './diff-renderer';
17
20
  import { FileChangeSection } from './FileChangeSection';
18
21
 
@@ -23,13 +26,21 @@ import { FileChangeSection } from './FileChangeSection';
23
26
  */
24
27
  export const OPEN_LINE_BUDGET = 600;
25
28
 
26
- /** The sections that start open: in order, until the budget of lines is spent. */
27
- export function initiallyOpen(changes: readonly CallFileChange[]): Set<string> {
29
+ /**
30
+ * The sections that start open: in order, until the budget of lines is spent, and any holding a
31
+ * comment of the message being written.
32
+ */
33
+ export function initiallyOpen(
34
+ changes: readonly CallFileChange[],
35
+ comments: readonly DiffComment[] = [],
36
+ ): Set<string> {
28
37
  const open = new Set<string>();
29
38
  let spent = 0;
30
39
  for (const change of changes) {
40
+ if (change.patch === undefined || change.binary) continue;
41
+ if (diffCommentsOn(comments, change.path, change.patch).length > 0) open.add(change.key);
31
42
  const size = change.additions + change.deletions;
32
- if (change.patch === undefined || change.binary || spent + size > OPEN_LINE_BUDGET) continue;
43
+ if (spent + size > OPEN_LINE_BUDGET) continue;
33
44
  spent += size;
34
45
  open.add(change.key);
35
46
  }
@@ -45,14 +56,16 @@ export interface FileChangesViewerProps {
45
56
  /**
46
57
  * The files an agent changed, as a sheet (a panel on a wide screen): each file a section that folds,
47
58
  * with a unified/split choice where the host's renderer has both, line wrapping, and fold or open
48
- * every file at once.
59
+ * every file at once. Where a composer is listening (`DiffCommentsProvider`), the lines take
60
+ * comments that go with the next message.
49
61
  */
50
62
  export function FileChangesViewer({ changes, open, onClose }: FileChangesViewerProps) {
51
63
  const { t } = useLabels();
52
64
  const styles = useStyles();
53
65
  const renderer = useFileDiffRenderer();
66
+ const draft = useDiffCommentsDraft();
54
67
  const totals = useMemo(() => fileChangeTotals(changes), [changes]);
55
- const [opened, setOpened] = useState(() => initiallyOpen(changes));
68
+ const [opened, setOpened] = useState(() => initiallyOpen(changes, draft?.comments));
56
69
  const [layout, setLayout] = useState<DiffLayout>('unified');
57
70
  const [wrap, setWrap] = useState(false);
58
71
  const allOpen = changes.every((change) => opened.has(change.key));
@@ -107,6 +120,7 @@ export function FileChangesViewer({ changes, open, onClose }: FileChangesViewerP
107
120
  {allOpen ? t('chat.fileChanges.collapseAll') : t('chat.fileChanges.expandAll')}
108
121
  </Button>
109
122
  </View>
123
+ {draft === null ? null : <Muted style={styles.hint}>{t('chat.diffComments.hint')}</Muted>}
110
124
  <View>
111
125
  {changes.map((change) => (
112
126
  <FileChangeSection
@@ -117,6 +131,7 @@ export function FileChangesViewer({ changes, open, onClose }: FileChangesViewerP
117
131
  layout={layout}
118
132
  wrap={wrap}
119
133
  renderer={renderer}
134
+ draft={draft}
120
135
  />
121
136
  ))}
122
137
  </View>
@@ -132,4 +147,5 @@ const useStyles = createTokenStyles(() => ({
132
147
  gap: 8,
133
148
  paddingBottom: 12,
134
149
  },
150
+ hint: { fontSize: 12, paddingBottom: 8 },
135
151
  }));
@@ -1,9 +1,14 @@
1
1
  import { Button } from '@oxy.so/bloom/button';
2
2
  import { createTokenStyles } from '@oxy.so/bloom/theme';
3
3
  import { Text } from '@oxy.so/bloom/typography';
4
- import { useMemo, useState } from 'react';
5
- import { Platform, ScrollView, View } from 'react-native';
4
+ import { type ReactNode, useMemo, useState } from 'react';
5
+ import { Platform, Pressable, ScrollView, View } from 'react-native';
6
6
  import { useLabels } from '../../lib/labels';
7
+ import {
8
+ type DiffLinePoint,
9
+ diffLinePoint,
10
+ selectDiffLines,
11
+ } from '../../runtime/thread/diff-comments';
7
12
  import { type PatchLine, patchLines } from '../../runtime/thread/file-changes';
8
13
  import type { GemiePatchViewProps } from './diff-renderer';
9
14
 
@@ -28,25 +33,88 @@ function digitsOf(lines: readonly PatchLine[]): number {
28
33
 
29
34
  const SIGN = { add: '+', delete: '−', context: ' ' } as const;
30
35
 
36
+ const pointKey = ({ side, line }: DiffLinePoint) => `${side}:${line}`;
37
+
38
+ type PatchLinesProps = Pick<GemiePatchViewProps, 'patch' | 'wrap'> &
39
+ Partial<Pick<GemiePatchViewProps, 'annotations' | 'selection' | 'onSelectLines'>>;
40
+
41
+ /** The rows `selection` covers, as places in `lines`; none when it is not of this patch. */
42
+ function selectedRows(
43
+ patch: string,
44
+ lines: readonly PatchLine[],
45
+ selection: PatchLinesProps['selection'],
46
+ ): { first: number; last: number } | null {
47
+ const picked = selection ? selectDiffLines(patch, selection) : null;
48
+ if (picked === null) return null;
49
+ const at = (point: DiffLinePoint) =>
50
+ lines.findIndex(
51
+ (line) =>
52
+ line.kind !== 'hunk' &&
53
+ line.kind !== 'note' &&
54
+ pointKey(diffLinePoint(line)) === pointKey(point),
55
+ );
56
+ return { first: at(picked.range.from), last: at(picked.range.to) };
57
+ }
58
+
31
59
  /**
32
60
  * One file's patch as monospace lines, with its line numbers and the added and removed lines
33
61
  * tinted: the SDK's own drawing of a patch, which draws on every platform and needs nothing
34
62
  * installed. Drawn a page at a time, so a large patch costs what the person has read.
63
+ *
64
+ * Where it takes comments, a line number picks its line, and a second one picked while the first
65
+ * is marked extends the run to it.
35
66
  */
36
- export function PatchLines({ patch, wrap }: Pick<GemiePatchViewProps, 'patch' | 'wrap'>) {
67
+ export function PatchLines({
68
+ patch,
69
+ wrap,
70
+ annotations,
71
+ selection,
72
+ onSelectLines,
73
+ }: PatchLinesProps) {
37
74
  const { t } = useLabels();
38
75
  const styles = useStyles();
39
76
  const lines = useMemo(() => patchLines(patch), [patch]);
40
77
  const [shown, setShown] = useState(PATCH_LINES_PAGE);
41
- const rows = lines.slice(0, shown);
78
+ const under = useMemo(
79
+ () => new Map(annotations?.map(({ at, content }) => [pointKey(at), content])),
80
+ [annotations],
81
+ );
82
+ // An annotated line is drawn however far down the patch it is.
83
+ const annotatedThrough = lines.reduce(
84
+ (through, line, index) =>
85
+ line.kind !== 'hunk' && line.kind !== 'note' && under.has(pointKey(diffLinePoint(line)))
86
+ ? index + 1
87
+ : through,
88
+ 0,
89
+ );
90
+ const visible = Math.max(shown, annotatedThrough);
91
+ const rows = lines.slice(0, visible);
42
92
  const gutter = digitsOf(lines);
93
+ const marked = useMemo(() => selectedRows(patch, lines, selection), [patch, lines, selection]);
94
+ const pick =
95
+ onSelectLines === undefined
96
+ ? undefined
97
+ : (point: DiffLinePoint) =>
98
+ onSelectLines({ from: selection ? selection.from : point, to: point });
43
99
 
44
100
  const body = (
45
101
  <View style={wrap ? styles.wrapped : undefined}>
46
102
  {rows.map((line, index) => (
47
- // A patch's lines never reorder: their place in it is their identity.
48
- // biome-ignore lint/suspicious/noArrayIndexKey: see above
49
- <Row key={`${index}:${line.kind}`} line={line} gutter={gutter} wrap={wrap} />
103
+ <Row
104
+ // A patch's lines never reorder: their place in it is their identity.
105
+ // biome-ignore lint/suspicious/noArrayIndexKey: see above
106
+ key={`${index}:${line.kind}`}
107
+ line={line}
108
+ gutter={gutter}
109
+ wrap={wrap}
110
+ selected={marked !== null && index >= marked.first && index <= marked.last}
111
+ onPick={pick}
112
+ annotation={
113
+ line.kind === 'hunk' || line.kind === 'note'
114
+ ? undefined
115
+ : under.get(pointKey(diffLinePoint(line)))
116
+ }
117
+ />
50
118
  ))}
51
119
  </View>
52
120
  );
@@ -54,15 +122,15 @@ export function PatchLines({ patch, wrap }: Pick<GemiePatchViewProps, 'patch' |
54
122
  return (
55
123
  <View>
56
124
  {wrap ? body : <ScrollView horizontal>{body}</ScrollView>}
57
- {lines.length > shown ? (
125
+ {lines.length > visible ? (
58
126
  <View style={styles.more}>
59
127
  <Button
60
128
  size="sm"
61
129
  appearance="outline"
62
130
  tone="neutral"
63
- onPress={() => setShown((count) => count + PATCH_LINES_PAGE)}
131
+ onPress={() => setShown(visible + PATCH_LINES_PAGE)}
64
132
  >
65
- {t('chat.fileChanges.showMore', { count: lines.length - shown })}
133
+ {t('chat.fileChanges.showMore', { count: lines.length - visible })}
66
134
  </Button>
67
135
  </View>
68
136
  ) : null}
@@ -70,7 +138,22 @@ export function PatchLines({ patch, wrap }: Pick<GemiePatchViewProps, 'patch' |
70
138
  );
71
139
  }
72
140
 
73
- function Row({ line, gutter, wrap }: { line: PatchLine; gutter: number; wrap: boolean }) {
141
+ function Row({
142
+ line,
143
+ gutter,
144
+ wrap,
145
+ selected,
146
+ onPick,
147
+ annotation,
148
+ }: {
149
+ line: PatchLine;
150
+ gutter: number;
151
+ wrap: boolean;
152
+ selected: boolean;
153
+ onPick: ((point: DiffLinePoint) => void) | undefined;
154
+ annotation: ReactNode;
155
+ }) {
156
+ const { t } = useLabels();
74
157
  const styles = useStyles();
75
158
  if (line.kind === 'hunk' || line.kind === 'note') {
76
159
  return (
@@ -80,21 +163,46 @@ function Row({ line, gutter, wrap }: { line: PatchLine; gutter: number; wrap: bo
80
163
  );
81
164
  }
82
165
  const number = line.kind === 'delete' ? line.oldLine : line.newLine;
83
- return (
166
+ const numberText = (
167
+ <Text style={[styles.number, { minWidth: gutter * 9 + 12 }]}>{number ?? ''}</Text>
168
+ );
169
+ const row = (
84
170
  <View
85
171
  style={[
86
172
  styles.row,
87
173
  line.kind === 'add' ? styles.added : null,
88
174
  line.kind === 'delete' ? styles.removed : null,
175
+ selected ? styles.selected : null,
89
176
  ]}
90
177
  >
91
- <Text style={[styles.number, { minWidth: gutter * 9 + 12 }]}>{number ?? ''}</Text>
178
+ {onPick === undefined ? (
179
+ numberText
180
+ ) : (
181
+ <Pressable
182
+ onPress={() => onPick(diffLinePoint(line))}
183
+ accessibilityRole="button"
184
+ accessibilityLabel={t(
185
+ `chat.diffComments.comment.${line.kind === 'delete' ? 'removed' : 'current'}`,
186
+ { line: number },
187
+ )}
188
+ accessibilityState={{ selected }}
189
+ >
190
+ {numberText}
191
+ </Pressable>
192
+ )}
92
193
  <Text style={styles.sign}>{SIGN[line.kind]}</Text>
93
194
  <Text style={[styles.code, wrap ? styles.codeWrapped : null]} selectable>
94
195
  {line.text === '' ? ' ' : line.text}
95
196
  </Text>
96
197
  </View>
97
198
  );
199
+ if (annotation === undefined) return row;
200
+ return (
201
+ <View>
202
+ {row}
203
+ <View style={styles.annotation}>{annotation}</View>
204
+ </View>
205
+ );
98
206
  }
99
207
 
100
208
  const useStyles = createTokenStyles((t) => ({
@@ -116,4 +224,7 @@ const useStyles = createTokenStyles((t) => ({
116
224
  code: { fontFamily: MONO, fontSize: 12, lineHeight: 18, color: t.foreground },
117
225
  codeWrapped: { flexShrink: 1, flexGrow: 1, flexBasis: '0%' },
118
226
  more: { alignItems: 'center', paddingVertical: 8 },
227
+ selected: { backgroundColor: t.accent },
228
+ // Beside a patch that scrolls sideways there is no width to fill, so the note keeps its own.
229
+ annotation: { width: '100%', minWidth: 280, maxWidth: 560 },
119
230
  }));
@@ -0,0 +1,29 @@
1
+ import { createContext, useContext } from 'react';
2
+ import type { Translate } from '../../lib/copy';
3
+ import type { DiffComment, DiffLineSpan } from '../../runtime/thread/diff-comments';
4
+
5
+ /** The comments of the message being written, and how the diff viewer changes them. */
6
+ export interface DiffCommentsDraft {
7
+ comments: readonly DiffComment[];
8
+ add: (comment: DiffComment) => void;
9
+ remove: (id: string) => void;
10
+ }
11
+
12
+ const DiffCommentsContext = createContext<DiffCommentsDraft | null>(null);
13
+
14
+ /**
15
+ * Makes the diff viewers under it take comments, into this draft. A thread with no composer (a
16
+ * shared conversation, one between gemies) has no provider, and its viewers only show the changes.
17
+ */
18
+ export const DiffCommentsProvider = DiffCommentsContext.Provider;
19
+
20
+ export function useDiffCommentsDraft(): DiffCommentsDraft | null {
21
+ return useContext(DiffCommentsContext);
22
+ }
23
+
24
+ /** "Line 4", "Lines 3–5", or the same of removed lines. */
25
+ export function diffLinesLabel(t: Translate, { side, start, end }: DiffLineSpan): string {
26
+ const span = start === end ? 'line' : 'lines';
27
+ const kind = side === 'old' ? 'removed' : 'current';
28
+ return t(`chat.diffComments.${kind}.${span}`, { line: start, start, end });
29
+ }
@@ -1,8 +1,15 @@
1
- import { type ComponentType, createContext, useContext } from 'react';
1
+ import { type ComponentType, createContext, type ReactNode, useContext } from 'react';
2
+ import type { DiffLinePoint, DiffLineRange } from '../../runtime/thread/diff-comments';
2
3
 
3
4
  /** How a file's changes are laid out: one column of lines, or the old and new side by side. */
4
5
  export type DiffLayout = 'unified' | 'split';
5
6
 
7
+ /** Something drawn under one line of a patch: its comments, or the one being written. */
8
+ export interface GemieDiffAnnotation {
9
+ at: DiffLinePoint;
10
+ content: ReactNode;
11
+ }
12
+
6
13
  export interface GemiePatchViewProps {
7
14
  /** One file's unified patch (`diff --git` headers, then its hunks). */
8
15
  patch: string;
@@ -13,6 +20,15 @@ export interface GemiePatchViewProps {
13
20
  wrap: boolean;
14
21
  /** The theme the person reads in. */
15
22
  appearance: 'light' | 'dark';
23
+ /** What to draw under its lines; one entry a line. */
24
+ annotations: readonly GemieDiffAnnotation[];
25
+ /** The lines being commented on, to mark them. */
26
+ selection: DiffLineRange | null;
27
+ /**
28
+ * The person picked lines to comment on, in either order. Absent where nothing takes comments:
29
+ * the lines are then not selectable.
30
+ */
31
+ onSelectLines?: (range: DiffLineRange) => void;
16
32
  }
17
33
 
18
34
  /**
@@ -26,8 +26,9 @@ import { agentCharacterOf } from '../../lib/participants';
26
26
  import { gemieConversationOf } from '../../runtime/gemie-conversations';
27
27
  import { GemieConversationCard } from './GemieConversationCard';
28
28
  import { useBubbles } from '../../lib/bubbles';
29
- import { messageText } from '../../lib/content-utils';
29
+ import { messageText, questionParts } from '../../lib/content-utils';
30
30
  import { hasAttachments, TurnAttachments } from './TurnAttachments';
31
+ import { TurnDiffComments } from './TurnDiffComments';
31
32
  import { ANCHORS, useGemieFlights } from '../../lib/flights';
32
33
  import { useLabels } from '../../lib/labels';
33
34
  import { canvasResultOf } from '../../lib/canvas-result';
@@ -149,8 +150,10 @@ export const ThreadRow = memo(function ThreadRow({
149
150
  }: ThreadRowProps) {
150
151
  const styles = useStyles();
151
152
  const { t } = useLabels();
152
- const text = messageText(message);
153
153
  const isReply = message.role === 'assistant';
154
+ const question = isReply ? null : questionParts(message);
155
+ const text = question === null ? messageText(message) : question.text;
156
+ const diffComments = question?.diffComments ?? [];
154
157
  const attached = !isReply && hasAttachments(message.content);
155
158
  const storedIn = message.unsaved === true ? undefined : conversationId;
156
159
  const hasText = text.length > 0;
@@ -189,7 +192,7 @@ export const ThreadRow = memo(function ThreadRow({
189
192
  const questionActions = [copyAction, editAction].filter(isPresent);
190
193
  return (
191
194
  <Animated.View ref={rowRef} onLayout={onLayout} style={rowStyle}>
192
- {text.length === 0 && !attached ? null : (
195
+ {text.length === 0 && !attached && diffComments.length === 0 ? null : (
193
196
  // Bloom's user turn, with the breathing room above it the thread has always had.
194
197
  <View style={styles.question}>
195
198
  <TurnMenu actions={questionActions} label={t('chat.turnActions')}>
@@ -204,6 +207,7 @@ export const ThreadRow = memo(function ThreadRow({
204
207
  tone="outgoing"
205
208
  onColor={foreground}
206
209
  />
210
+ <TurnDiffComments comments={diffComments} color={foreground} />
207
211
  {text.length > 0 ? (
208
212
  <Text variant="body-regular" selectable style={{ color: foreground }}>
209
213
  {text}
@@ -216,6 +220,7 @@ export const ThreadRow = memo(function ThreadRow({
216
220
  <AiChatUserMessage animate={isNew} actions={questionActions}>
217
221
  {/* Bloom's user turn sits on a neutral surface, not the accent. */}
218
222
  <TurnAttachments content={message.content} tone="incoming" />
223
+ {diffComments.length > 0 ? <TurnDiffComments comments={diffComments} /> : null}
219
224
  {text}
220
225
  </AiChatUserMessage>
221
226
  )}
@@ -0,0 +1,52 @@
1
+ import { createTokenStyles } from '@oxy.so/bloom/theme';
2
+ import { Muted, Text } from '@oxy.so/bloom/typography';
3
+ import { View } from 'react-native';
4
+ import { useLabels } from '../../lib/labels';
5
+ import type { DiffComment } from '../../runtime/thread/diff-comments';
6
+ import { fileChangeName } from '../../runtime/thread/file-changes';
7
+ import { diffLinesLabel } from '../diff/diff-comments-context';
8
+
9
+ /**
10
+ * The diff comments a sent turn carried, drawn with it: where each one is and what it says. The
11
+ * excerpt the gemie reads is not repeated here, the diff is in the conversation above.
12
+ */
13
+ export function TurnDiffComments({
14
+ comments,
15
+ color,
16
+ }: {
17
+ comments: readonly DiffComment[];
18
+ /** The bubble's own foreground, where the turn is a painted bubble. */
19
+ color?: string;
20
+ }) {
21
+ const { t } = useLabels();
22
+ const styles = useStyles();
23
+ if (comments.length === 0) return null;
24
+ const painted = color === undefined ? null : { color };
25
+ return (
26
+ <View style={styles.comments}>
27
+ {comments.map((comment) => (
28
+ <View
29
+ key={comment.id}
30
+ style={[styles.comment, color === undefined ? null : { borderColor: color }]}
31
+ >
32
+ <Muted style={[styles.where, painted]} numberOfLines={1}>
33
+ {t('chat.diffComments.chip', {
34
+ file: fileChangeName(comment.path),
35
+ lines: diffLinesLabel(t, comment.lines),
36
+ })}
37
+ </Muted>
38
+ <Text style={[styles.text, painted]} selectable>
39
+ {comment.text}
40
+ </Text>
41
+ </View>
42
+ ))}
43
+ </View>
44
+ );
45
+ }
46
+
47
+ const useStyles = createTokenStyles((t) => ({
48
+ comments: { gap: 8, paddingBottom: 4 },
49
+ comment: { borderLeftWidth: 2, borderColor: t.border, paddingLeft: 8, gap: 2 },
50
+ where: { fontSize: 12 },
51
+ text: { fontSize: 14, lineHeight: 20 },
52
+ }));
@@ -13,6 +13,7 @@ import {
13
13
  useComposerDraftStore,
14
14
  useDraftAddress,
15
15
  } from '../runtime/composer-draft-store';
16
+ import { composeTurnText, type DiffComment } from '../runtime/thread/diff-comments';
16
17
  import type { SendOptions } from '../runtime/types';
17
18
  import type { ConversationThread } from '../runtime/use-conversation-thread';
18
19
  import { useTurnEdit } from '../runtime/use-turn-edit';
@@ -76,7 +77,7 @@ function dataUrlAttachment(url: string, index: number): GemieAttachment {
76
77
 
77
78
  /**
78
79
  * Everything the person does with the composer: the draft they are writing (kept per conversation,
79
- * shared with every other surface), sending it, rewriting a question already sent, answering
80
+ * shared with every other surface) with its files and diff comments, sending it, rewriting a question already sent, answering
80
81
  * Alia's questions, picking a suggestion, asking for a reply again.
81
82
  *
82
83
  * Sending is the one path every turn takes. The draft is cleared at once and handed back if the
@@ -118,6 +119,7 @@ export function useChatComposer({
118
119
  const draft = useComposerDraft(target);
119
120
  const address = useDraftAddress(target);
120
121
  const photos = draft.attachments;
122
+ const diffComments = draft.diffComments;
121
123
  /** What a send carries beyond the text: the connector and skills chosen for this turn. */
122
124
  const turnOptions = useMemo<SendOptions>(
123
125
  () => ({ mcpServerId: draft.mcpServerId, skillNames: draft.skillNames }),
@@ -136,6 +138,14 @@ export function useChatComposer({
136
138
  (id: string) => useComposerDraftStore.getState().removeAttachment(address, id),
137
139
  [address],
138
140
  );
141
+ const addDiffComment = useCallback(
142
+ (comment: DiffComment) => useComposerDraftStore.getState().addDiffComment(address, comment),
143
+ [address],
144
+ );
145
+ const removeDiffComment = useCallback(
146
+ (id: string) => useComposerDraftStore.getState().removeDiffComment(address, id),
147
+ [address],
148
+ );
139
149
  const edit = useTurnEdit({ target, messages, turnOptionsOf, onEditMessage: editMessage });
140
150
  const { editing } = edit;
141
151
 
@@ -189,7 +199,8 @@ export function useChatComposer({
189
199
 
190
200
  const submit = useCallback(
191
201
  async (value: string) => {
192
- const text = value.trim();
202
+ // The diff comments go as part of the message's words, after what the person wrote.
203
+ const text = composeTurnText(value.trim(), diffComments);
193
204
  if ((!text && photos.length === 0) || isLoading || closed) return;
194
205
  // An edit rewrites the question's words; an attachment alone does not make a replacement.
195
206
  if (editing !== undefined && !text) return;
@@ -208,12 +219,15 @@ export function useChatComposer({
208
219
  else await submitTurn(text, attachments, turnOptions);
209
220
  } catch (err) {
210
221
  // Nothing was sent (the photos could not be read): keep the draft.
211
- useComposerDraftStore.getState().restore(address, { text: value, attachments: photos });
222
+ useComposerDraftStore
223
+ .getState()
224
+ .restore(address, { text: value, attachments: photos, diffComments });
212
225
  reportError(err instanceof Error ? err.message : 'Could not attach the photos');
213
226
  }
214
227
  },
215
228
  [
216
229
  photos,
230
+ diffComments,
217
231
  isLoading,
218
232
  closed,
219
233
  editing,
@@ -294,6 +308,9 @@ export function useChatComposer({
294
308
  photos,
295
309
  addAttachment,
296
310
  removeAttachment,
311
+ diffComments,
312
+ addDiffComment,
313
+ removeDiffComment,
297
314
  address,
298
315
  turnOptions,
299
316
  edit,
package/src/index.ts CHANGED
@@ -35,8 +35,16 @@ export type {
35
35
  DiffLayout,
36
36
  GemieFileDiffRenderer,
37
37
  GemiePatchViewProps,
38
+ GemieDiffAnnotation,
38
39
  } from './components/diff/diff-renderer';
39
40
  export { PatchLines } from './components/diff/PatchLines';
41
+ export type {
42
+ DiffComment,
43
+ DiffLinePoint,
44
+ DiffLineRange,
45
+ DiffSelection,
46
+ DiffSide,
47
+ } from './runtime/thread/diff-comments';
40
48
  export { GemieAskProvider, useAskGemie } from './components/GemieAskProvider';
41
49
  export type {
42
50
  GemieAsk,
@@ -1,3 +1,4 @@
1
+ import { splitTurnText } from '../runtime/thread/diff-comments';
1
2
  import { processMessage } from '../runtime/thread/message-processor';
2
3
 
3
4
  /** A single part of a multi-part chat message content array. */
@@ -32,6 +33,15 @@ export function messageText(message: { content: MessageContent | null | undefine
32
33
  return processMessage(message.content ? getTextFromContent(message.content) : '', 'app').text;
33
34
  }
34
35
 
36
+ /**
37
+ * A person's turn as the thread draws it: their words and, apart from them, the diff comments it
38
+ * carried, which travel inside the message's text.
39
+ */
40
+ export function questionParts(message: { content: MessageContent | null | undefined }) {
41
+ const { text, diffComments } = splitTurnText(getTextFromContent(message.content));
42
+ return { text: messageText({ content: text }), diffComments };
43
+ }
44
+
35
45
  /**
36
46
  * Extract image URLs from multi-part message content.
37
47
  */
@@ -84,6 +84,21 @@ export const COPY_EN: Readonly<Record<string, CopyEntry>> = {
84
84
  'chat.dislike': 'Dislike',
85
85
  'chat.edit': 'Edit',
86
86
  'chat.feedbackFailed': "Your feedback couldn't be saved.",
87
+ 'chat.diffComments.add': 'Add to message',
88
+ 'chat.diffComments.cancel': 'Cancel',
89
+ 'chat.diffComments.chip': '{{file}}, {{lines}}',
90
+ 'chat.diffComments.comment.current': 'Comment on line {{line}}',
91
+ 'chat.diffComments.comment.removed': 'Comment on removed line {{line}}',
92
+ 'chat.diffComments.current.line': 'Line {{line}}',
93
+ 'chat.diffComments.current.lines': 'Lines {{start}}–{{end}}',
94
+ 'chat.diffComments.field': '{{lines}}: your comment',
95
+ 'chat.diffComments.hint':
96
+ 'Select line numbers to comment on them. Comments are sent with your next message.',
97
+ 'chat.diffComments.placeholder': 'Add a comment…',
98
+ 'chat.diffComments.remove': 'Remove comment, {{lines}}',
99
+ 'chat.diffComments.removeFrom': 'Remove comment on {{file}}, {{lines}}',
100
+ 'chat.diffComments.removed.line': 'Removed line {{line}}',
101
+ 'chat.diffComments.removed.lines': 'Removed lines {{start}}–{{end}}',
87
102
  'chat.fileChanges.binary': 'Binary file, no preview',
88
103
  'chat.fileChanges.chip': { one: '1 file changed', other: '{{count}} files changed' },
89
104
  'chat.fileChanges.collapseAll': 'Collapse all',
@@ -80,6 +80,21 @@ export const COPY_ES: Readonly<Record<string, CopyEntry>> = {
80
80
  'chat.dislike': 'No me gusta',
81
81
  'chat.edit': 'Editar',
82
82
  'chat.feedbackFailed': 'No se ha podido guardar tu opinión.',
83
+ 'chat.diffComments.add': 'Añadir al mensaje',
84
+ 'chat.diffComments.cancel': 'Cancelar',
85
+ 'chat.diffComments.chip': '{{file}}, {{lines}}',
86
+ 'chat.diffComments.comment.current': 'Comentar la línea {{line}}',
87
+ 'chat.diffComments.comment.removed': 'Comentar la línea eliminada {{line}}',
88
+ 'chat.diffComments.current.line': 'Línea {{line}}',
89
+ 'chat.diffComments.current.lines': 'Líneas {{start}}–{{end}}',
90
+ 'chat.diffComments.field': '{{lines}}: tu comentario',
91
+ 'chat.diffComments.hint':
92
+ 'Selecciona números de línea para comentarlas. Los comentarios se envían con tu próximo mensaje.',
93
+ 'chat.diffComments.placeholder': 'Añade un comentario…',
94
+ 'chat.diffComments.remove': 'Quitar el comentario, {{lines}}',
95
+ 'chat.diffComments.removeFrom': 'Quitar el comentario de {{file}}, {{lines}}',
96
+ 'chat.diffComments.removed.line': 'Línea eliminada {{line}}',
97
+ 'chat.diffComments.removed.lines': 'Líneas eliminadas {{start}}–{{end}}',
83
98
  'chat.fileChanges.binary': 'Archivo binario, sin vista previa',
84
99
  'chat.fileChanges.chip': { one: '1 archivo cambiado', other: '{{count}} archivos cambiados' },
85
100
  'chat.fileChanges.collapseAll': 'Contraer todo',