@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.
Files changed (39) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +4 -0
  3. package/package.json +1 -1
  4. package/src/components/GemieChatContent.tsx +117 -27
  5. package/src/components/GemieComposer.tsx +25 -4
  6. package/src/components/diff/AnnotatedPatch.tsx +125 -0
  7. package/src/components/diff/DiffCommentCards.tsx +132 -0
  8. package/src/components/diff/DiffCommentChips.tsx +57 -0
  9. package/src/components/diff/FileChangeSection.tsx +12 -5
  10. package/src/components/diff/FileChangesViewer.tsx +21 -5
  11. package/src/components/diff/PatchLines.tsx +124 -13
  12. package/src/components/diff/diff-comments-context.ts +29 -0
  13. package/src/components/diff/diff-renderer.ts +17 -1
  14. package/src/components/thread/FollowUpStatus.tsx +35 -0
  15. package/src/components/thread/GemieThread.tsx +25 -1
  16. package/src/components/thread/ThreadFindBar.tsx +121 -0
  17. package/src/components/thread/ThreadPanel.tsx +34 -0
  18. package/src/components/thread/ThreadRow.tsx +52 -12
  19. package/src/components/thread/ThreadSearch.tsx +61 -78
  20. package/src/components/thread/ThreadTurns.tsx +94 -0
  21. package/src/components/thread/TurnDiffComments.tsx +52 -0
  22. package/src/hooks/useChatComposer.ts +20 -3
  23. package/src/hooks/useFindShortcut.ts +57 -0
  24. package/src/hooks/useRowJump.ts +79 -0
  25. package/src/hooks/useThreadNavigation.ts +134 -0
  26. package/src/hooks/useTimelineWindow.ts +18 -1
  27. package/src/index.ts +8 -0
  28. package/src/lib/content-utils.ts +10 -0
  29. package/src/lib/copy-en.ts +26 -0
  30. package/src/lib/copy-es.ts +26 -0
  31. package/src/runtime/composer-draft-store.ts +43 -16
  32. package/src/runtime/model.ts +1 -0
  33. package/src/runtime/thread/diff-comments.ts +227 -0
  34. package/src/runtime/thread/message-processor.ts +58 -37
  35. package/src/runtime/thread/thread-find.ts +102 -0
  36. package/src/runtime/use-approval-actions.ts +7 -1
  37. package/src/runtime/use-conversation-thread.ts +10 -4
  38. package/src/runtime/use-start-conversation.ts +2 -1
  39. package/src/runtime/use-turn-edit.ts +5 -3
@@ -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,
@@ -0,0 +1,57 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { Platform } from 'react-native';
3
+ import type { ShortcutKeyEvent } from './useApprovalShortcuts';
4
+
5
+ /** Where keys are heard. A test brings its own. */
6
+ export type ShortcutTarget = Pick<EventTarget, 'addEventListener' | 'removeEventListener'>;
7
+
8
+ /**
9
+ * Every chat on screen that offers find, the newest last: a sheet over a screen has two, and only
10
+ * the one on top answers.
11
+ */
12
+ const owners: object[] = [];
13
+
14
+ /** ⌘F on a Mac, Ctrl+F elsewhere. Ctrl+F on a Mac moves the caret and stays the field's. */
15
+ export function isFindShortcut(event: ShortcutKeyEvent, mac: boolean): boolean {
16
+ if (event.defaultPrevented || event.isComposing || event.altKey || event.shiftKey) return false;
17
+ const modifier = mac ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey;
18
+ return modifier === true && event.key.toLowerCase() === 'f';
19
+ }
20
+
21
+ function isMac(): boolean {
22
+ const platform = (globalThis as { navigator?: { platform?: string } }).navigator?.platform;
23
+ return /mac|iphone|ipad/i.test(platform ?? '');
24
+ }
25
+
26
+ /**
27
+ * The web shortcut for find in the thread. The browser's own find cannot see the rows above the
28
+ * thread's mounted window, so while a chat offers find it takes the key; `undefined` leaves the
29
+ * key to the browser. Heard in the capture phase, because a text field stops its keys bubbling.
30
+ */
31
+ export function useFindShortcut(
32
+ open: (() => void) | undefined,
33
+ target: ShortcutTarget | undefined = Platform.OS === 'web'
34
+ ? (globalThis as { window?: Window }).window
35
+ : undefined,
36
+ ): void {
37
+ const latest = useRef(open);
38
+ latest.current = open;
39
+ const enabled = open !== undefined;
40
+
41
+ useEffect(() => {
42
+ if (!enabled || target === undefined) return;
43
+ const owner = {};
44
+ owners.push(owner);
45
+ const onKeyDown = (event: Event) => {
46
+ const key = event as unknown as ShortcutKeyEvent;
47
+ if (owners.at(-1) !== owner || !isFindShortcut(key, isMac())) return;
48
+ key.preventDefault?.();
49
+ latest.current?.();
50
+ };
51
+ target.addEventListener('keydown', onKeyDown, true);
52
+ return () => {
53
+ owners.splice(owners.indexOf(owner), 1);
54
+ target.removeEventListener('keydown', onKeyDown, true);
55
+ };
56
+ }, [enabled, target]);
57
+ }
@@ -0,0 +1,79 @@
1
+ import type { AiChatThreadHandle } from '@oxy.so/bloom/ai-chat';
2
+ import { type ComponentRef, type RefObject, useCallback, useLayoutEffect, useRef } from 'react';
3
+ import type { View } from 'react-native';
4
+ import type { ThreadJumpTarget } from './useThreadNavigation';
5
+ import { nextFrame } from './useTimelineWindow';
6
+
7
+ /**
8
+ * A mounted view: a row of the thread, or the list that holds them. An interface rather than an
9
+ * alias, so a declaration that returns one can name it (see `TextInputHandle`).
10
+ */
11
+ export interface RowView extends ComponentRef<typeof View> {}
12
+
13
+ /**
14
+ * The room the find bar takes at the top of the thread, px: its card at its tallest, with the
15
+ * line about unloaded history. The thread keeps that much clear while it marks a match.
16
+ */
17
+ export const FIND_BAR_CLEARANCE = 104;
18
+
19
+ interface Options {
20
+ /** The row asked for, if any. A new `request` asks again. */
21
+ target: ThreadJumpTarget | null | undefined;
22
+ /** Every row's id, in reading order. */
23
+ ids: readonly string[];
24
+ /** Mount the row at this index (`useTimelineWindow.reveal`). */
25
+ reveal: (index: number) => void;
26
+ threadRef: RefObject<AiChatThreadHandle | null>;
27
+ /** Room to leave above the row, px: what floats over the top of the thread. */
28
+ clearance: number;
29
+ }
30
+
31
+ /**
32
+ * Bring a row into view.
33
+ *
34
+ * Bloom's thread scrolls to an offset, not to an index, so the row is first mounted (it may be
35
+ * above the window) and then measured against the list. It is measured when the jump is made
36
+ * rather than remembered from its layout: a row's position changes whenever anything above it
37
+ * does, and on web no layout event says so.
38
+ */
39
+ export function useRowJump({ target, ids, reveal, threadRef, clearance }: Options) {
40
+ const rows = useRef(new Map<string, RowView>());
41
+ const listRef = useRef<RowView | null>(null);
42
+ const waiting = useRef<string | null>(null);
43
+ const latest = useRef({ ids, reveal });
44
+ useLayoutEffect(() => {
45
+ latest.current = { ids, reveal };
46
+ });
47
+
48
+ const registerRow = useCallback((id: string, node: RowView | null) => {
49
+ if (node === null) rows.current.delete(id);
50
+ else rows.current.set(id, node);
51
+ }, []);
52
+
53
+ const request = target?.request;
54
+ const targetId = target?.id;
55
+ useLayoutEffect(() => {
56
+ if (request === undefined || targetId === undefined) return;
57
+ const index = latest.current.ids.indexOf(targetId);
58
+ if (index === -1) return;
59
+ waiting.current = targetId;
60
+ latest.current.reveal(index);
61
+ }, [request, targetId]);
62
+
63
+ // After every commit, because the row asked for may mount a render after it was asked for.
64
+ useLayoutEffect(() => {
65
+ const id = waiting.current;
66
+ const row = id === null ? undefined : rows.current.get(id);
67
+ const list = listRef.current;
68
+ if (row === undefined || list === null) return;
69
+ waiting.current = null;
70
+ // A frame later, once the rows revealed with it have laid out.
71
+ nextFrame(() => {
72
+ row.measureLayout(list, (_x, y) => {
73
+ threadRef.current?.scrollToOffset({ offset: Math.max(0, y - clearance) });
74
+ });
75
+ });
76
+ });
77
+
78
+ return { listRef, registerRow };
79
+ }
@@ -0,0 +1,134 @@
1
+ import { useCallback, useMemo, useRef, useState } from 'react';
2
+ import { findMatches, stepMatch, threadTurns } from '../runtime/thread/thread-find';
3
+ import type { Message } from '../runtime/types';
4
+
5
+ /** Ask the thread to bring a row into view. `request` tells two asks for the same row apart. */
6
+ export interface ThreadJumpTarget {
7
+ id: string;
8
+ request: number;
9
+ }
10
+
11
+ interface NavigationState {
12
+ panel: 'find' | 'turns' | null;
13
+ query: string;
14
+ /** The match the reader is on, by message id: ids survive the rows changing around it. */
15
+ activeId: string | null;
16
+ jump: ThreadJumpTarget | null;
17
+ /** Bumped each time find is asked for, so an open bar takes the caret back. */
18
+ focusRequest: number;
19
+ }
20
+
21
+ const CLOSED: NavigationState = {
22
+ panel: null,
23
+ query: '',
24
+ activeId: null,
25
+ jump: null,
26
+ focusRequest: 0,
27
+ };
28
+
29
+ const NOTHING: readonly string[] = [];
30
+
31
+ const jumpTo = (current: NavigationState, id: string): ThreadJumpTarget => ({
32
+ id,
33
+ request: (current.jump?.request ?? 0) + 1,
34
+ });
35
+
36
+ /**
37
+ * Moving around a long thread: the find bar's query and current match, the list of turns, and the
38
+ * row either of them asks the thread to show.
39
+ *
40
+ * Matches are numbered in reading order and a search starts on the newest, which is where the
41
+ * reader already is. Only something the person does moves the thread: a reply streaming in can
42
+ * add a match, and never scrolls to it.
43
+ */
44
+ export function useThreadNavigation(rows: readonly Message[], conversationId: string | undefined) {
45
+ const [state, setState] = useState<NavigationState & { owner: string | undefined }>({
46
+ ...CLOSED,
47
+ owner: conversationId,
48
+ });
49
+ // Another conversation has other words: nothing found or listed carries over.
50
+ if (state.owner !== conversationId) setState({ ...CLOSED, owner: conversationId });
51
+
52
+ // Read through a ref by the actions, which must not change identity per streamed token.
53
+ const latestRows = useRef(rows);
54
+ latestRows.current = rows;
55
+
56
+ const finding = state.panel === 'find';
57
+ const matches = useMemo(
58
+ () => (finding ? findMatches(rows, state.query) : NOTHING),
59
+ [finding, rows, state.query],
60
+ );
61
+ const found = state.activeId === null ? -1 : matches.indexOf(state.activeId);
62
+ // A match that is gone (the reply was edited or regenerated) hands over to the newest.
63
+ const current = found === -1 ? matches.length - 1 : found;
64
+
65
+ const turns = useMemo(
66
+ () => (state.panel === 'turns' ? threadTurns(rows) : []),
67
+ [state.panel, rows],
68
+ );
69
+
70
+ const openFind = useCallback(() => {
71
+ setState((s) => ({
72
+ ...(s.panel === 'find' ? s : { ...CLOSED, owner: s.owner, jump: s.jump }),
73
+ panel: 'find',
74
+ focusRequest: s.focusRequest + 1,
75
+ }));
76
+ }, []);
77
+ const openTurns = useCallback(() => {
78
+ setState((s) => ({ ...CLOSED, owner: s.owner, jump: s.jump, panel: 'turns' }));
79
+ }, []);
80
+ const close = useCallback(() => {
81
+ setState((s) =>
82
+ s.panel === null ? s : { ...CLOSED, owner: s.owner, jump: s.jump, panel: null },
83
+ );
84
+ }, []);
85
+
86
+ const setQuery = useCallback((query: string) => {
87
+ const newest = findMatches(latestRows.current, query).at(-1) ?? null;
88
+ setState((s) => ({
89
+ ...s,
90
+ query,
91
+ activeId: newest,
92
+ jump: newest === null ? s.jump : jumpTo(s, newest),
93
+ }));
94
+ }, []);
95
+
96
+ const step = useCallback((delta: 1 | -1) => {
97
+ setState((s) => {
98
+ const ids = findMatches(latestRows.current, s.query);
99
+ const at = s.activeId === null ? -1 : ids.indexOf(s.activeId);
100
+ const next = ids[stepMatch(at === -1 ? ids.length - 1 : at, delta, ids.length)];
101
+ return next === undefined ? s : { ...s, activeId: next, jump: jumpTo(s, next) };
102
+ });
103
+ }, []);
104
+ const older = useCallback(() => step(-1), [step]);
105
+ const newer = useCallback(() => step(1), [step]);
106
+
107
+ /** Land on a turn from the list, and close the list over it. */
108
+ const jumpToTurn = useCallback((id: string) => {
109
+ setState((s) => ({ ...CLOSED, owner: s.owner, panel: null, jump: jumpTo(s, id) }));
110
+ }, []);
111
+
112
+ return {
113
+ panel: state.panel,
114
+ query: state.query,
115
+ /** How many loaded messages hold the query. */
116
+ total: matches.length,
117
+ /** The current match's position, counted from 0 in reading order; -1 with none. */
118
+ current,
119
+ /** The message the thread marks: the current match, while find is open. */
120
+ highlightedId: matches[current] ?? null,
121
+ jump: state.jump,
122
+ focusRequest: state.focusRequest,
123
+ turns,
124
+ openFind,
125
+ openTurns,
126
+ close,
127
+ setQuery,
128
+ older,
129
+ newer,
130
+ jumpToTurn,
131
+ };
132
+ }
133
+
134
+ export type ThreadNavigation = ReturnType<typeof useThreadNavigation>;
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  type Message,
3
3
  TAIL,
4
+ FOCUS_MARGIN,
4
5
  TOP,
5
6
  type TimelineAnchor,
6
7
  type TimelinePosition,
@@ -79,7 +80,7 @@ function awaitingRows(pending: { current: PendingScroll | null }, ids: readonly
79
80
  /** The state before the first key: nothing mounted yet, so nothing to remember. */
80
81
  const MOUNTING = Symbol('mounting');
81
82
 
82
- const nextFrame = (run: () => void): void => {
83
+ export const nextFrame = (run: () => void): void => {
83
84
  if (typeof requestAnimationFrame === 'function') requestAnimationFrame(run);
84
85
  else setTimeout(run, 0);
85
86
  };
@@ -205,6 +206,21 @@ export function useTimelineWindow({
205
206
  loadHistory?.();
206
207
  }, [setAnchor]);
207
208
 
209
+ /**
210
+ * Mount the row at `index` for a jump to it, with a few rows above, and keep it mounted. A
211
+ * scroll still waiting (a restore) gives way to it.
212
+ */
213
+ const reveal = useCallback(
214
+ (index: number) => {
215
+ pending.current = null;
216
+ atBottom.current = false;
217
+ const { ids: rows, start: first } = latest.current;
218
+ const wanted = Math.max(0, index - FOCUS_MARGIN);
219
+ if (wanted < first) setAnchor(pinAnchor(rows, wanted));
220
+ },
221
+ [setAnchor],
222
+ );
223
+
208
224
  const handleScroll = useCallback(
209
225
  (event: NativeSyntheticEvent<NativeScrollEvent>) => {
210
226
  const { contentOffset, contentSize, layoutMeasurement } = event.nativeEvent;
@@ -248,6 +264,7 @@ export function useTimelineWindow({
248
264
  return {
249
265
  /** Index of the first mounted row. */
250
266
  start,
267
+ reveal,
251
268
  /** For `AiChatThread`: absent when there is nothing above to reveal or load. */
252
269
  onStartReached: start > 0 || onLoadHistory !== undefined ? handleStartReached : undefined,
253
270
  onScroll: handleScroll,
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',
@@ -112,6 +127,14 @@ export const COPY_EN: Readonly<Record<string, CopyEntry>> = {
112
127
  'chat.fileChanges.unified': 'Unified',
113
128
  'chat.fileChanges.unrecorded': 'The agent did not record what changed in this file',
114
129
  'chat.fileChanges.wrap': 'Wrap lines',
130
+ 'chat.find.count': '{{current}} of {{total}}',
131
+ 'chat.find.loadedOnly': 'Only the messages loaded here are searched.',
132
+ 'chat.find.newer': 'Next match',
133
+ 'chat.find.none': 'No matches',
134
+ 'chat.find.older': 'Previous match',
135
+ 'chat.find.placeholder': 'Find in conversation',
136
+ 'chat.followUp.queued': 'Waiting to send your message…',
137
+ 'chat.followUp.steering': 'Sending your reply to {{agent}}…',
115
138
  'chat.like': 'Like',
116
139
  'chat.actionApproval.send': 'Send',
117
140
  'chat.actionApproval.approve': 'Approve',
@@ -190,6 +213,9 @@ export const COPY_EN: Readonly<Record<string, CopyEntry>> = {
190
213
  'chat.turnFailed': "Alia couldn't answer right now.",
191
214
  'chat.turnFailedRetryHint': 'Try again.',
192
215
  'chat.turnInterrupted': 'Alia was interrupted before finishing.',
216
+ 'chat.turns.attachment': 'Attachment',
217
+ 'chat.turns.loadEarlier': 'Load earlier messages',
218
+ 'chat.turns.title': 'Jump to a turn',
193
219
  'chat.working': 'Working',
194
220
  'chat.yesterday': 'Yesterday',
195
221
  'common.close': 'Close',
@@ -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',
@@ -111,6 +126,14 @@ export const COPY_ES: Readonly<Record<string, CopyEntry>> = {
111
126
  'chat.fileChanges.unified': 'Unificada',
112
127
  'chat.fileChanges.unrecorded': 'El agente no registró qué cambió en este archivo',
113
128
  'chat.fileChanges.wrap': 'Ajustar líneas',
129
+ 'chat.find.count': '{{current}} de {{total}}',
130
+ 'chat.find.loadedOnly': 'Solo se busca en los mensajes cargados aquí.',
131
+ 'chat.find.newer': 'Coincidencia siguiente',
132
+ 'chat.find.none': 'Sin coincidencias',
133
+ 'chat.find.older': 'Coincidencia anterior',
134
+ 'chat.find.placeholder': 'Buscar en la conversación',
135
+ 'chat.followUp.queued': 'Esperando para enviar tu mensaje…',
136
+ 'chat.followUp.steering': 'Enviando tu respuesta a {{agent}}…',
114
137
  'chat.like': 'Me gusta',
115
138
  'chat.actionApproval.send': 'Enviar',
116
139
  'chat.actionApproval.approve': 'Aprobar',
@@ -189,6 +212,9 @@ export const COPY_ES: Readonly<Record<string, CopyEntry>> = {
189
212
  'chat.turnFailed': 'Alia no ha podido responder ahora mismo.',
190
213
  'chat.turnFailedRetryHint': 'Inténtalo de nuevo.',
191
214
  'chat.turnInterrupted': 'Alia se interrumpió antes de terminar.',
215
+ 'chat.turns.attachment': 'Adjunto',
216
+ 'chat.turns.loadEarlier': 'Cargar mensajes anteriores',
217
+ 'chat.turns.title': 'Ir a un turno',
192
218
  'chat.working': 'Trabajando',
193
219
  'chat.yesterday': 'Ayer',
194
220
  'common.close': 'Cerrar',
@@ -1,11 +1,12 @@
1
1
  import { useMemo } from 'react';
2
2
  import { create } from 'zustand';
3
3
  import type { GemieAttachment } from '../types';
4
+ import type { DiffComment } from './thread/diff-comments';
4
5
 
5
6
  /**
6
- * What a composer is holding before it is sent: the text, the attachments and
7
- * the turn's own choices (connector, skills). One record per account and
8
- * composer, and the only place any of it lives.
7
+ * What a composer is holding before it is sent: the text, the attachments, the
8
+ * comments on diff lines and the turn's own choices (connector, skills). One
9
+ * record per account and composer, and the only place any of it lives.
9
10
  *
10
11
  * ## Why this replaced three owners
11
12
  *
@@ -61,6 +62,8 @@ export interface DraftAddress {
61
62
  export interface ComposerDraft {
62
63
  text: string;
63
64
  attachments: GemieAttachment[];
65
+ /** The comments on diff lines the next message carries (`composeTurnText`). */
66
+ diffComments: DiffComment[];
64
67
  /** The connector chosen for the next turn. */
65
68
  mcpServerId: string | null;
66
69
  /** The skills chosen for the next turn. */
@@ -76,7 +79,10 @@ export interface ComposerDraft {
76
79
  export type DraftTurn = Pick<ComposerDraft, 'mcpServerId' | 'skillNames'>;
77
80
 
78
81
  /** What the composer held before an edit took it over, for a cancel to give back. */
79
- export type DraftBeforeEdit = Pick<ComposerDraft, 'text' | 'mcpServerId' | 'skillNames'>;
82
+ export type DraftBeforeEdit = Pick<
83
+ ComposerDraft,
84
+ 'text' | 'diffComments' | 'mcpServerId' | 'skillNames'
85
+ >;
80
86
 
81
87
  export interface DraftEdit {
82
88
  /** The user turn being rewritten. */
@@ -84,15 +90,20 @@ export interface DraftEdit {
84
90
  before: DraftBeforeEdit;
85
91
  }
86
92
 
87
- /** The turn an edit loads into the composer: its words and the options it was sent with. */
93
+ /**
94
+ * The turn an edit loads into the composer: its words, the comments it carried and the options it
95
+ * was sent with.
96
+ */
88
97
  export interface EditedTurn extends DraftTurn {
89
98
  messageId: string;
90
99
  text: string;
100
+ diffComments: DiffComment[];
91
101
  }
92
102
 
93
103
  const EMPTY_DRAFT: ComposerDraft = Object.freeze({
94
104
  text: '',
95
105
  attachments: [],
106
+ diffComments: [],
96
107
  mcpServerId: null,
97
108
  skillNames: [],
98
109
  }) as ComposerDraft;
@@ -117,6 +128,12 @@ export function releaseAttachments(attachments: readonly GemieAttachment[]): voi
117
128
 
118
129
  const keyOf = (target: DraftTarget) => target ?? '';
119
130
 
131
+ /** What comes back to a draft, ahead of what was added to it since. */
132
+ function inFront<T extends { id: string }>(returning: readonly T[] = [], current: T[]): T[] {
133
+ const ids = new Set(returning.map((item) => item.id));
134
+ return [...returning, ...current.filter((item) => !ids.has(item.id))];
135
+ }
136
+
120
137
  interface DraftStoreState {
121
138
  /** The account whose drafts these are; `null` while signed out. */
122
139
  account: string | null;
@@ -130,12 +147,14 @@ interface DraftStoreState {
130
147
  addAttachment: (address: DraftAddress, attachment: GemieAttachment) => void;
131
148
  /** Takes the tile away and releases its URL. */
132
149
  removeAttachment: (address: DraftAddress, id: string) => void;
150
+ addDiffComment: (address: DraftAddress, comment: DiffComment) => void;
151
+ removeDiffComment: (address: DraftAddress, id: string) => void;
133
152
  /** Change the turn's connector and skills, from what the draft holds now. */
134
153
  updateTurn: (address: DraftAddress, change: (turn: DraftTurn) => DraftTurn) => void;
135
154
  /**
136
155
  * Put a draft back — a send that failed, or text another screen hands to a
137
- * composer. The fields given replace the draft's; attachments given are put
138
- * back in front of any added since, which are kept.
156
+ * composer. The fields given replace the draft's; attachments and diff comments
157
+ * given are put back in front of any added since, which are kept.
139
158
  */
140
159
  restore: (address: DraftAddress, draft: Partial<ComposerDraft>) => void;
141
160
  /**
@@ -210,6 +229,15 @@ export const useComposerDraftStore = create<DraftStoreState>((set, get) => {
210
229
  return { ...draft, attachments: draft.attachments.filter((a) => a.id !== id) };
211
230
  }),
212
231
 
232
+ addDiffComment: (address, comment) =>
233
+ write(address, (draft) => ({ ...draft, diffComments: [...draft.diffComments, comment] })),
234
+
235
+ removeDiffComment: (address, id) =>
236
+ write(address, (draft) => ({
237
+ ...draft,
238
+ diffComments: draft.diffComments.filter((comment) => comment.id !== id),
239
+ })),
240
+
213
241
  updateTurn: (address, change) =>
214
242
  write(address, (draft) => ({
215
243
  ...draft,
@@ -219,15 +247,12 @@ export const useComposerDraftStore = create<DraftStoreState>((set, get) => {
219
247
  restore: (address, restored) =>
220
248
  write(
221
249
  address,
222
- (draft) => {
223
- const returning = restored.attachments ?? [];
224
- const ids = new Set(returning.map((a) => a.id));
225
- return {
226
- ...draft,
227
- ...restored,
228
- attachments: [...returning, ...draft.attachments.filter((a) => !ids.has(a.id))],
229
- };
230
- },
250
+ (draft) => ({
251
+ ...draft,
252
+ ...restored,
253
+ attachments: inFront(restored.attachments, draft.attachments),
254
+ diffComments: inFront(restored.diffComments, draft.diffComments),
255
+ }),
231
256
  () => releaseAttachments(restored.attachments ?? []),
232
257
  ),
233
258
 
@@ -237,12 +262,14 @@ export const useComposerDraftStore = create<DraftStoreState>((set, get) => {
237
262
  write(address, (draft) => ({
238
263
  ...draft,
239
264
  text: turn.text,
265
+ diffComments: turn.diffComments,
240
266
  mcpServerId: turn.mcpServerId,
241
267
  skillNames: turn.skillNames,
242
268
  editing: {
243
269
  messageId: turn.messageId,
244
270
  before: draft.editing?.before ?? {
245
271
  text: draft.text,
272
+ diffComments: draft.diffComments,
246
273
  mcpServerId: draft.mcpServerId,
247
274
  skillNames: draft.skillNames,
248
275
  },
@@ -17,6 +17,7 @@ export * from './thread/agent-work';
17
17
  export * from './thread/automation-labels';
18
18
  export * from './thread/command-output';
19
19
  export * from './thread/conversation-export';
20
+ export * from './thread/diff-comments';
20
21
  export * from './thread/file-changes';
21
22
  export * from './thread/message-days';
22
23
  export * from './thread/message-processor';