@terreno/ui 58.0.5 → 58.1.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 (59) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/dist/AiSuggestionBox.js +3 -3
  3. package/dist/AiSuggestionBox.js.map +1 -1
  4. package/dist/Common.d.ts +38 -0
  5. package/dist/Common.d.ts.map +1 -1
  6. package/dist/Common.js.map +1 -1
  7. package/dist/DataTable.d.ts.map +1 -1
  8. package/dist/DataTable.js +3 -1
  9. package/dist/DataTable.js.map +1 -1
  10. package/dist/DraggableList.d.ts +7 -4
  11. package/dist/DraggableList.d.ts.map +1 -1
  12. package/dist/DraggableList.js +206 -4
  13. package/dist/DraggableList.js.map +1 -1
  14. package/dist/FeedbackCommentField.d.ts +8 -0
  15. package/dist/FeedbackCommentField.d.ts.map +1 -0
  16. package/dist/FeedbackCommentField.js +39 -0
  17. package/dist/FeedbackCommentField.js.map +1 -0
  18. package/dist/GPTChat.d.ts +15 -1
  19. package/dist/GPTChat.d.ts.map +1 -1
  20. package/dist/GPTChat.js +148 -43
  21. package/dist/GPTChat.js.map +1 -1
  22. package/dist/LabeledCheckBox.d.ts +3 -2
  23. package/dist/LabeledCheckBox.d.ts.map +1 -1
  24. package/dist/LabeledCheckBox.js +3 -2
  25. package/dist/LabeledCheckBox.js.map +1 -1
  26. package/dist/TextField.d.ts.map +1 -1
  27. package/dist/TextField.js +10 -7
  28. package/dist/TextField.js.map +1 -1
  29. package/dist/ThumbsUpDownButtons.d.ts +9 -0
  30. package/dist/ThumbsUpDownButtons.d.ts.map +1 -0
  31. package/dist/ThumbsUpDownButtons.js +60 -0
  32. package/dist/ThumbsUpDownButtons.js.map +1 -0
  33. package/dist/ThumbsUpDownFeedback.d.ts +3 -2
  34. package/dist/ThumbsUpDownFeedback.d.ts.map +1 -1
  35. package/dist/ThumbsUpDownFeedback.js +10 -52
  36. package/dist/ThumbsUpDownFeedback.js.map +1 -1
  37. package/dist/index.d.ts +1 -0
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +1 -0
  40. package/dist/index.js.map +1 -1
  41. package/package.json +2 -2
  42. package/src/AiSuggestionBox.tsx +3 -3
  43. package/src/Common.ts +39 -0
  44. package/src/DataTable.test.tsx +31 -0
  45. package/src/DataTable.tsx +3 -1
  46. package/src/DraggableList.test.tsx +141 -1
  47. package/src/DraggableList.tsx +359 -6
  48. package/src/FeedbackCommentField.test.tsx +107 -0
  49. package/src/FeedbackCommentField.tsx +74 -0
  50. package/src/GPTChat.test.tsx +327 -14
  51. package/src/GPTChat.tsx +463 -259
  52. package/src/LabeledCheckBox.tsx +3 -2
  53. package/src/TextField.test.tsx +126 -1
  54. package/src/TextField.tsx +13 -7
  55. package/src/ThumbsUpDownButtons.tsx +120 -0
  56. package/src/ThumbsUpDownFeedback.test.tsx +154 -1
  57. package/src/ThumbsUpDownFeedback.tsx +26 -101
  58. package/src/__snapshots__/DataTable.test.tsx.snap +28 -28
  59. package/src/index.tsx +1 -0
package/src/GPTChat.tsx CHANGED
@@ -13,9 +13,11 @@ import {
13
13
  findNodeHandle,
14
14
  Platform,
15
15
  Image as RNImage,
16
+ ScrollView,
16
17
  type ScrollViewInstance,
17
18
  type TextInputInstance,
18
19
  type TextInstance,
20
+ useWindowDimensions,
19
21
  View,
20
22
  type ViewInstance,
21
23
  } from "react-native";
@@ -30,12 +32,14 @@ import {BlocksView} from "./blocks/BlocksView";
30
32
  import type {BlocksViewProps} from "./Common";
31
33
  import {DropdownMenuItem} from "./DropdownMenuItem";
32
34
  import {DropdownPanel} from "./DropdownPanel";
35
+ import {FeedbackCommentField} from "./FeedbackCommentField";
33
36
  import type {SelectedFile} from "./FilePickerButton";
34
37
  import {FilePickerButton} from "./FilePickerButton";
35
38
  import {FormContainer} from "./FormContainer";
36
39
  import {Heading} from "./Heading";
37
40
  import {Icon} from "./Icon";
38
41
  import {IconButton} from "./IconButton";
42
+ import {LabeledCheckBox} from "./LabeledCheckBox";
39
43
  import {MarkdownView} from "./MarkdownView";
40
44
  import {Modal} from "./Modal";
41
45
  import {SelectField} from "./SelectField";
@@ -115,6 +119,8 @@ export interface GPTChatMessage {
115
119
  id?: string;
116
120
  contentParts?: MessageContentPart[];
117
121
  rating?: "up" | "down";
122
+ /** A comment already sent with `rating`; shows the sent state instead of the comment field. */
123
+ ratingComment?: string;
118
124
  role: "user" | "assistant" | "system" | "tool-call" | "tool-result";
119
125
  toolCall?: ToolCallInfo;
120
126
  toolResult?: ToolResultInfo;
@@ -135,6 +141,11 @@ export interface MCPServerStatus {
135
141
  export interface MCPToolDetail {
136
142
  name: string;
137
143
  description?: string;
144
+ /**
145
+ * JSON Schema for the arguments the assistant passes. The tools list reads `properties`,
146
+ * `required`, and each property's `type` and `description`.
147
+ */
148
+ inputSchema?: Record<string, unknown>;
138
149
  }
139
150
 
140
151
  export interface GPTChatProps {
@@ -170,6 +181,13 @@ export interface GPTChatProps {
170
181
  onMemoryEdit?: (memory: string) => void;
171
182
  onModelChange?: (modelId: string) => void;
172
183
  onRateFeedback?: (promptIndex: number, rating: "up" | "down" | null) => void;
184
+ /**
185
+ * Called with a free-text comment on a rated assistant message. When set, a comment field
186
+ * appears under the rating buttons of every rated assistant message.
187
+ */
188
+ onRateComment?: (promptIndex: number, comment: string) => void | Promise<void>;
189
+ /** Called after a passive action on an assistant message, such as a successful copy. */
190
+ onMessageSignal?: (promptIndex: number, signal: "copied") => void;
173
191
  onRemoveAttachment?: (index: number) => void;
174
192
  onSelectHistory: (id: string) => void;
175
193
  onSubmit: (prompt: string) => void;
@@ -227,75 +245,123 @@ const ExpandableContent = ({
227
245
  return <>{children}</>;
228
246
  };
229
247
 
230
- const ToolCallCard = ({toolCall}: {toolCall: ToolCallInfo}): React.ReactElement => {
231
- const [isExpanded, setIsExpanded] = useState(false);
248
+ /** Cap on an expanded tool call so a large result scrolls instead of stretching the transcript. */
249
+ const TOOL_BODY_MAX_HEIGHT = 240;
232
250
 
233
- return (
234
- <Box border="default" padding={2} rounding="md">
235
- <Box
236
- accessibilityHint="Toggle tool call details"
237
- accessibilityLabel={`Tool: ${toolCall.toolName}`}
238
- alignItems="center"
239
- direction="row"
240
- gap={1}
241
- onClick={() => setIsExpanded(!isExpanded)}
242
- >
243
- <Icon iconName="wrench" size="xs" />
244
- <Text bold size="sm">
245
- Tool: {toolCall.toolName}
246
- </Text>
247
- <Icon iconName={isExpanded ? "chevron-up" : "chevron-down"} size="xs" />
248
- </Box>
249
- <ExpandableContent isExpanded={isExpanded}>
250
- <Box marginTop={1} padding={1}>
251
- <Text color="secondaryDark" size="sm">
252
- {JSON.stringify(toolCall.args, null, 2)}
253
- </Text>
254
- </Box>
255
- </ExpandableContent>
256
- </Box>
257
- );
251
+ const formatToolPayload = (value: unknown): string => {
252
+ if (typeof value === "string") {
253
+ return value;
254
+ }
255
+ try {
256
+ return JSON.stringify(value, null, 2);
257
+ } catch {
258
+ return String(value);
259
+ }
258
260
  };
259
261
 
260
- const ToolResultText = ({result}: {result: unknown}): React.ReactElement => {
261
- if (typeof result === "string") {
262
- return (
263
- <Text color="secondaryDark" size="sm">
264
- {result}
265
- </Text>
266
- );
262
+ interface ToolArgument {
263
+ description?: string;
264
+ name: string;
265
+ required: boolean;
266
+ type: string;
267
+ }
268
+
269
+ const argumentsFromSchema = (schema: Record<string, unknown> | undefined): ToolArgument[] => {
270
+ if (!schema) {
271
+ return [];
267
272
  }
273
+ const properties = schema.properties;
274
+ if (!properties || typeof properties !== "object") {
275
+ return [];
276
+ }
277
+ const requiredNames = Array.isArray(schema.required)
278
+ ? schema.required.filter((name): name is string => typeof name === "string")
279
+ : [];
280
+ const required = new Set(requiredNames);
281
+ return Object.entries(properties as Record<string, unknown>).map(([name, value]) => {
282
+ const property = value && typeof value === "object" ? (value as Record<string, unknown>) : {};
283
+ const type = typeof property.type === "string" ? property.type : "value";
284
+ const description = typeof property.description === "string" ? property.description : undefined;
285
+ return {description, name, required: required.has(name), type};
286
+ });
287
+ };
288
+
289
+ const ToolPayloadText = ({value}: {value: unknown}): React.ReactElement => {
268
290
  return (
269
291
  <Text color="secondaryDark" size="sm">
270
- {JSON.stringify(result, null, 2)}
292
+ {formatToolPayload(value)}
271
293
  </Text>
272
294
  );
273
295
  };
274
296
 
275
- const ToolResultCard = ({toolResult}: {toolResult: ToolResultInfo}): React.ReactElement => {
297
+ /**
298
+ * One disclosure for a tool invocation. The call and its result share the row, and the body
299
+ * scrolls inside a fixed height so a large payload does not stretch the transcript.
300
+ */
301
+ const ToolTurnRow = ({
302
+ toolCall,
303
+ toolResult,
304
+ }: {
305
+ toolCall?: ToolCallInfo;
306
+ toolResult?: ToolResultInfo;
307
+ }): React.ReactElement => {
276
308
  const [isExpanded, setIsExpanded] = useState(false);
309
+ const name = toolCall?.toolName || toolResult?.toolName || "tool";
310
+ const toolId = toolCall?.toolCallId || toolResult?.toolCallId || name;
311
+ const isRunning = Boolean(toolCall) && !toolResult;
312
+
313
+ const handleToggle = useCallback((): void => {
314
+ setIsExpanded((current) => !current);
315
+ }, []);
277
316
 
278
317
  return (
279
- <Box border="default" padding={2} rounding="md">
318
+ <Box testID={`gpt-tool-${toolId}`} width="100%">
280
319
  <Box
281
- accessibilityHint="Toggle tool result details"
282
- accessibilityLabel={`Result: ${toolResult.toolName}`}
320
+ accessibilityHint="Show or hide what this tool was given and what it returned"
321
+ accessibilityLabel={`Tool: ${name}`}
283
322
  alignItems="center"
284
323
  direction="row"
285
- gap={1}
286
- onClick={() => setIsExpanded(!isExpanded)}
324
+ gap={2}
325
+ onClick={handleToggle}
326
+ paddingY={1}
287
327
  >
288
- <Icon iconName="check" size="xs" />
289
- <Text bold size="sm">
290
- Result: {toolResult.toolName}
328
+ <Icon iconName={isExpanded ? "chevron-down" : "chevron-right"} size="xs" />
329
+ <Text color="secondaryDark" size="sm">
330
+ {isRunning ? `Running ${name}` : name}
291
331
  </Text>
292
- <Icon iconName={isExpanded ? "chevron-up" : "chevron-down"} size="xs" />
293
332
  </Box>
294
- <ExpandableContent isExpanded={isExpanded}>
295
- <Box marginTop={1} padding={1}>
296
- <ToolResultText result={toolResult.result} />
333
+ {isExpanded ? (
334
+ <Box color="neutralLight" marginBottom={1} rounding="md">
335
+ <ScrollView
336
+ nestedScrollEnabled
337
+ style={{maxHeight: TOOL_BODY_MAX_HEIGHT}}
338
+ testID={`gpt-tool-body-${toolId}`}
339
+ >
340
+ <Box gap={2} padding={2}>
341
+ {toolCall ? (
342
+ <Box gap={1}>
343
+ <Text bold color="secondaryDark" size="sm">
344
+ Input
345
+ </Text>
346
+ <ToolPayloadText value={toolCall.args} />
347
+ </Box>
348
+ ) : null}
349
+ {toolResult ? (
350
+ <Box gap={1}>
351
+ <Text bold color="secondaryDark" size="sm">
352
+ Result
353
+ </Text>
354
+ <ToolPayloadText value={toolResult.result} />
355
+ </Box>
356
+ ) : (
357
+ <Text color="secondaryDark" size="sm">
358
+ Waiting for a result.
359
+ </Text>
360
+ )}
361
+ </Box>
362
+ </ScrollView>
297
363
  </Box>
298
- </ExpandableContent>
364
+ ) : null}
299
365
  </Box>
300
366
  );
301
367
  };
@@ -360,55 +426,18 @@ const copyImageToClipboard = async (part: ImageContentPart): Promise<void> => {
360
426
  }
361
427
  };
362
428
 
363
- const ImageActions = ({part}: {part: ImageContentPart}): React.ReactElement => {
364
- const handleCopy = useCallback(async (): Promise<void> => {
365
- try {
366
- await copyImageToClipboard(part);
367
- } catch (error) {
368
- console.warn("Failed to copy image", error);
369
- }
370
- }, [part]);
371
-
372
- const handleDownload = useCallback((): void => {
373
- handleDownloadFile(part.url, getImageFilename(part));
374
- }, [part]);
375
-
376
- return (
377
- <Box direction="row" gap={1} testID="gpt-image-actions">
378
- <IconButton
379
- accessibilityLabel="Copy image"
380
- iconName="copy"
381
- onClick={handleCopy}
382
- testID="gpt-copy-image"
383
- variant="ghost"
384
- />
385
- {Platform.OS === "web" ? (
386
- <IconButton
387
- accessibilityLabel="Download image"
388
- iconName="download"
389
- onClick={handleDownload}
390
- testID="gpt-download-image"
391
- variant="ghost"
392
- />
393
- ) : null}
394
- </Box>
395
- );
396
- };
397
-
398
429
  const MessageContentParts = ({parts}: {parts: MessageContentPart[]}): React.ReactElement => {
399
430
  return (
400
431
  <Box gap={2}>
401
432
  {parts.map((part, index) => {
402
433
  if (part.type === "image") {
403
434
  return (
404
- <Box gap={1} key={`content-${index}`}>
405
- <RNImage
406
- resizeMode="contain"
407
- source={{uri: part.url}}
408
- style={{borderRadius: 8, height: 400, maxWidth: 800, minWidth: 400, width: "100%"}}
409
- />
410
- <ImageActions part={part} />
411
- </Box>
435
+ <RNImage
436
+ key={`content-${index}`}
437
+ resizeMode="contain"
438
+ source={{uri: part.url}}
439
+ style={{borderRadius: 12, height: 320, maxWidth: "100%", width: "100%"}}
440
+ />
412
441
  );
413
442
  }
414
443
  if (part.type === "file") {
@@ -887,7 +916,7 @@ const MessageText = ({
887
916
  if (role === "assistant") {
888
917
  return <MarkdownView>{content}</MarkdownView>;
889
918
  }
890
- return <Text color={role === "user" ? "inverted" : "primary"}>{content}</Text>;
919
+ return <Text color={role === "user" ? "primary" : "secondaryDark"}>{content}</Text>;
891
920
  };
892
921
 
893
922
  const RatingButtons = ({
@@ -922,29 +951,70 @@ const RatingButtons = ({
922
951
  );
923
952
  };
924
953
 
954
+ const firstImagePart = (message: GPTChatMessage): ImageContentPart | undefined => {
955
+ return message.contentParts?.find((part): part is ImageContentPart => part.type === "image");
956
+ };
957
+
925
958
  const AssistantActions = ({
926
959
  handleCopyMessage,
927
960
  index,
928
961
  message,
962
+ onRateComment,
929
963
  onRateFeedback,
930
964
  }: {
931
- handleCopyMessage: (message: GPTChatMessage) => void;
965
+ handleCopyMessage: (message: GPTChatMessage, index: number) => void;
932
966
  index: number;
933
967
  message: GPTChatMessage;
968
+ onRateComment?: (promptIndex: number, comment: string) => void | Promise<void>;
934
969
  onRateFeedback?: (promptIndex: number, rating: "up" | "down" | null) => void;
935
970
  }): React.ReactElement | null => {
936
- if (message.role !== "assistant") {
971
+ const image = firstImagePart(message);
972
+ const hasText = message.content.trim().length > 0;
973
+ const showCopy = hasText || Boolean(image);
974
+
975
+ const handleDownload = useCallback((): void => {
976
+ if (!image) {
977
+ return;
978
+ }
979
+ handleDownloadFile(image.url, getImageFilename(image));
980
+ }, [image]);
981
+
982
+ if (message.role !== "assistant" || (!showCopy && !onRateFeedback)) {
937
983
  return null;
938
984
  }
985
+ const showComment = Boolean(onRateFeedback && onRateComment && message.rating);
939
986
  return (
940
- <Box alignItems="end" direction="row" gap={1} justifyContent="end" marginTop={1}>
941
- <RatingButtons index={index} onRateFeedback={onRateFeedback} rating={message.rating} />
942
- <IconButton
943
- accessibilityLabel="Copy message"
944
- iconName="copy"
945
- onClick={() => handleCopyMessage(message)}
946
- testID={`gpt-copy-msg-${index}`}
947
- />
987
+ <Box gap={2} marginTop={2} testID={`gpt-message-actions-${index}`}>
988
+ <Box alignItems="center" direction="row" gap={1}>
989
+ {showCopy ? (
990
+ <IconButton
991
+ accessibilityLabel={image && !hasText ? "Copy image" : "Copy message"}
992
+ iconName="copy"
993
+ onClick={() => handleCopyMessage(message, index)}
994
+ testID={`gpt-copy-msg-${index}`}
995
+ variant="muted"
996
+ />
997
+ ) : null}
998
+ {image && Platform.OS === "web" ? (
999
+ <IconButton
1000
+ accessibilityLabel="Download image"
1001
+ iconName="download"
1002
+ onClick={handleDownload}
1003
+ testID={`gpt-download-image-${index}`}
1004
+ variant="muted"
1005
+ />
1006
+ ) : null}
1007
+ <RatingButtons index={index} onRateFeedback={onRateFeedback} rating={message.rating} />
1008
+ </Box>
1009
+ {showComment && onRateComment ? (
1010
+ // Keyed by rating so a changed vote starts a fresh comment.
1011
+ <FeedbackCommentField
1012
+ key={message.rating}
1013
+ onSubmit={(comment) => onRateComment(index, comment)}
1014
+ sentComment={message.ratingComment}
1015
+ testID={`gpt-rating-comment-${index}`}
1016
+ />
1017
+ ) : null}
948
1018
  </Box>
949
1019
  );
950
1020
  };
@@ -1100,6 +1170,7 @@ const MessageList = ({
1100
1170
  isStreaming,
1101
1171
  onAskSubmit,
1102
1172
  onBlockEvent,
1173
+ onRateComment,
1103
1174
  onRateFeedback,
1104
1175
  pendingElements,
1105
1176
  resolveAskFiles,
@@ -1112,12 +1183,13 @@ const MessageList = ({
1112
1183
  askErrors?: Record<string, AskValidationError[]>;
1113
1184
  blockOverrides: Record<string, Record<string, Block>>;
1114
1185
  currentMessages: GPTChatMessage[];
1115
- handleCopyMessage: (message: GPTChatMessage) => void;
1186
+ handleCopyMessage: (message: GPTChatMessage, index: number) => void;
1116
1187
  hostActions?: readonly string[];
1117
1188
  imageHosts?: readonly string[];
1118
1189
  isStreaming: boolean;
1119
1190
  onAskSubmit?: AskSubmitHandler;
1120
1191
  onBlockEvent: (event: BlockChatEvent) => void;
1192
+ onRateComment?: (promptIndex: number, comment: string) => void | Promise<void>;
1121
1193
  onRateFeedback?: (promptIndex: number, rating: "up" | "down" | null) => void;
1122
1194
  pendingElements: Record<string, readonly string[]>;
1123
1195
  resolveAskFiles?: AskFilesResolver;
@@ -1127,14 +1199,34 @@ const MessageList = ({
1127
1199
  }): React.ReactElement => {
1128
1200
  const askToolCallIds = new Set<string>();
1129
1201
  const toolResults = new Map<string, unknown>();
1202
+ const toolCallIds = new Set<string>();
1130
1203
  for (const message of currentMessages) {
1131
1204
  if (message.role === "tool-call" && message.ask) {
1132
1205
  askToolCallIds.add(message.ask.toolCallId);
1133
1206
  }
1207
+ if (message.role === "tool-call" && message.toolCall && !message.ask) {
1208
+ toolCallIds.add(message.toolCall.toolCallId);
1209
+ }
1134
1210
  if (message.role === "tool-result" && message.toolResult) {
1135
1211
  toolResults.set(message.toolResult.toolCallId, message.toolResult.result);
1136
1212
  }
1137
1213
  }
1214
+ const pairedToolResults = new Map<string, ToolResultInfo>();
1215
+ const pairedResultIndexes = new Set<number>();
1216
+ currentMessages.forEach((message, index) => {
1217
+ const toolResult = message.toolResult;
1218
+ if (message.role !== "tool-result" || !toolResult) {
1219
+ return;
1220
+ }
1221
+ if (!toolCallIds.has(toolResult.toolCallId) || askToolCallIds.has(toolResult.toolCallId)) {
1222
+ return;
1223
+ }
1224
+ if (pairedToolResults.has(toolResult.toolCallId)) {
1225
+ return;
1226
+ }
1227
+ pairedToolResults.set(toolResult.toolCallId, toolResult);
1228
+ pairedResultIndexes.add(index);
1229
+ });
1138
1230
 
1139
1231
  // The live reply stays partial after an ask is appended, so a draft document does not
1140
1232
  // validate as a finished message while the turn is still streaming.
@@ -1189,39 +1281,44 @@ const MessageList = ({
1189
1281
  }
1190
1282
  if (message.role === "tool-call" && message.toolCall) {
1191
1283
  return (
1192
- <Box alignItems="start" key={`msg-${index}`} maxWidth="80%">
1193
- <ToolCallCard toolCall={message.toolCall} />
1194
- </Box>
1284
+ <ToolTurnRow
1285
+ key={`msg-${index}`}
1286
+ toolCall={message.toolCall}
1287
+ toolResult={pairedToolResults.get(message.toolCall.toolCallId)}
1288
+ />
1195
1289
  );
1196
1290
  }
1197
1291
  if (message.role === "tool-result" && message.toolResult) {
1198
- return (
1199
- <Box alignItems="start" key={`msg-${index}`} maxWidth="80%">
1200
- <ToolResultCard toolResult={message.toolResult} />
1201
- </Box>
1202
- );
1292
+ if (pairedResultIndexes.has(sourceIndex)) {
1293
+ return null;
1294
+ }
1295
+ return <ToolTurnRow key={`msg-${index}`} toolResult={message.toolResult} />;
1203
1296
  }
1204
1297
 
1205
- const hasImages = message.contentParts?.some((p) => p.type === "image");
1206
1298
  const messageId = messageKey;
1207
- return (
1208
- <Box alignItems={message.role === "user" ? "end" : "start"} key={messageKey}>
1209
- <Box
1210
- color={message.role === "user" ? "primary" : "neutralLight"}
1211
- maxWidth={hasImages ? "90%" : "80%"}
1212
- padding={3}
1213
- rounding="lg"
1214
- >
1215
- <ContentPartsPreview
1216
- hasContent={Boolean(message.content)}
1217
- parts={message.contentParts}
1218
- />
1299
+ const isUser = message.role === "user";
1300
+ const isLive = liveAssistantIndex >= 0 && sourceIndex === liveAssistantIndex;
1301
+ const hasBody =
1302
+ Boolean(message.content.trim()) ||
1303
+ Boolean(message.contentParts?.length) ||
1304
+ Boolean(message.blockNote) ||
1305
+ (uiBlocks && isLive && message.role === "assistant");
1306
+ if (!hasBody) {
1307
+ return null;
1308
+ }
1309
+ const body = (
1310
+ <>
1311
+ <ContentPartsPreview
1312
+ hasContent={Boolean(message.content)}
1313
+ parts={message.contentParts}
1314
+ />
1315
+ {message.content || (uiBlocks && isLive && message.role === "assistant") ? (
1219
1316
  <MessageText
1220
1317
  allowHtml={allowHtml}
1221
1318
  content={message.content}
1222
1319
  hostActions={hostActions}
1223
1320
  imageHosts={imageHosts}
1224
- isPartial={liveAssistantIndex >= 0 && sourceIndex === liveAssistantIndex}
1321
+ isPartial={isLive}
1225
1322
  messageId={messageId}
1226
1323
  onBlockEvent={onBlockEvent}
1227
1324
  overrides={blockOverrides[messageId]}
@@ -1231,18 +1328,33 @@ const MessageList = ({
1231
1328
  role={message.role}
1232
1329
  uiBlocks={uiBlocks}
1233
1330
  />
1234
- {message.blockNote ? (
1235
- <Text color="secondaryLight" size="sm" testID={`gpt-block-note-${messageId}`}>
1236
- {message.blockNote}
1237
- </Text>
1238
- ) : null}
1239
- <AssistantActions
1240
- handleCopyMessage={handleCopyMessage}
1241
- index={sourceIndex}
1242
- message={message}
1243
- onRateFeedback={sourceIndex >= 0 ? onRateFeedback : undefined}
1244
- />
1331
+ ) : null}
1332
+ {message.blockNote ? (
1333
+ <Text color="secondaryLight" size="sm" testID={`gpt-block-note-${messageId}`}>
1334
+ {message.blockNote}
1335
+ </Text>
1336
+ ) : null}
1337
+ <AssistantActions
1338
+ handleCopyMessage={handleCopyMessage}
1339
+ index={sourceIndex}
1340
+ message={message}
1341
+ onRateComment={sourceIndex >= 0 ? onRateComment : undefined}
1342
+ onRateFeedback={sourceIndex >= 0 ? onRateFeedback : undefined}
1343
+ />
1344
+ </>
1345
+ );
1346
+ if (isUser) {
1347
+ return (
1348
+ <Box alignItems="end" key={messageKey} width="100%">
1349
+ <Box color="neutralLight" maxWidth="80%" paddingX={3} paddingY={2} rounding="xl">
1350
+ {body}
1351
+ </Box>
1245
1352
  </Box>
1353
+ );
1354
+ }
1355
+ return (
1356
+ <Box key={messageKey} width="100%">
1357
+ {body}
1246
1358
  </Box>
1247
1359
  );
1248
1360
  })}
@@ -1317,6 +1429,18 @@ const AttachButton = ({
1317
1429
  );
1318
1430
  };
1319
1431
 
1432
+ const TOOLS_LIST_INTRO =
1433
+ "The assistant can call these tools while it answers. You don't run them yourself.";
1434
+
1435
+ /** Tallest the tool list grows on a large screen. */
1436
+ const TOOLS_LIST_MAX_HEIGHT = 640;
1437
+
1438
+ /**
1439
+ * Estimated height of the Modal's title, close control, padding, and margins, measured in the
1440
+ * demo. The list cap is the window height minus this, so raise it if the Modal chrome grows.
1441
+ */
1442
+ const TOOLS_MODAL_CHROME = 220;
1443
+
1320
1444
  const ToolsModal = ({
1321
1445
  isVisible,
1322
1446
  mcpTools,
@@ -1326,31 +1450,81 @@ const ToolsModal = ({
1326
1450
  mcpTools: MCPToolDetail[];
1327
1451
  onDismiss: () => void;
1328
1452
  }): React.ReactElement => {
1453
+ const [showArguments, setShowArguments] = useState(false);
1454
+ const {height: windowHeight} = useWindowDimensions();
1455
+ const listMaxHeight = Math.min(
1456
+ TOOLS_LIST_MAX_HEIGHT,
1457
+ Math.max(160, windowHeight - TOOLS_MODAL_CHROME)
1458
+ );
1459
+
1460
+ const handleToggleArguments = useCallback((checked: boolean): void => {
1461
+ setShowArguments(checked);
1462
+ }, []);
1463
+
1464
+ const handleDismiss = useCallback((): void => {
1465
+ setShowArguments(false);
1466
+ onDismiss();
1467
+ }, [onDismiss]);
1468
+
1329
1469
  return (
1330
- <Modal onDismiss={onDismiss} size="md" title="Available Tools" visible={isVisible}>
1331
- <Box gap={2} padding={3}>
1332
- {mcpTools.length === 0 ? (
1470
+ <Modal onDismiss={handleDismiss} size="lg" title="Tools" visible={isVisible}>
1471
+ <ScrollView style={{maxHeight: listMaxHeight}} testID="gpt-tools-scroll">
1472
+ <Box gap={3} padding={3} testID="gpt-tools-list">
1333
1473
  <Text color="secondaryDark" size="sm">
1334
- No tools available.
1474
+ {TOOLS_LIST_INTRO}
1335
1475
  </Text>
1336
- ) : (
1337
- mcpTools.map((tool) => (
1338
- <Box border="default" gap={1} key={tool.name} padding={3} rounding="md">
1339
- <Box alignItems="center" direction="row" gap={2}>
1340
- <Icon iconName="wrench" size="xs" />
1341
- <Text bold size="sm">
1342
- {tool.name}
1343
- </Text>
1344
- </Box>
1345
- {tool.description && (
1346
- <Text color="secondaryDark" size="sm">
1347
- {tool.description}
1348
- </Text>
1349
- )}
1350
- </Box>
1351
- ))
1352
- )}
1353
- </Box>
1476
+ {mcpTools.length > 0 ? (
1477
+ <LabeledCheckBox
1478
+ checked={showArguments}
1479
+ label="Show arguments"
1480
+ onChange={handleToggleArguments}
1481
+ testID="gpt-tools-arguments-toggle"
1482
+ />
1483
+ ) : null}
1484
+ {mcpTools.length === 0 ? (
1485
+ <Text color="secondaryDark" size="sm">
1486
+ No tools are available in this chat.
1487
+ </Text>
1488
+ ) : (
1489
+ mcpTools.map((tool) => {
1490
+ const toolArguments = argumentsFromSchema(tool.inputSchema);
1491
+ return (
1492
+ <Box gap={1} key={tool.name} testID={`gpt-tool-detail-${tool.name}`}>
1493
+ <Text bold>{tool.name}</Text>
1494
+ <Text color="secondaryDark" size="sm">
1495
+ {tool.description ?? "No description provided."}
1496
+ </Text>
1497
+ {showArguments ? (
1498
+ <>
1499
+ <Text bold color="secondaryDark" size="sm">
1500
+ Arguments
1501
+ </Text>
1502
+ {toolArguments.length === 0 ? (
1503
+ <Text color="secondaryDark" size="sm">
1504
+ None. The assistant calls it with an empty input.
1505
+ </Text>
1506
+ ) : (
1507
+ toolArguments.map((toolArgument) => (
1508
+ <Box gap={1} key={toolArgument.name}>
1509
+ <Text size="sm">
1510
+ {`${toolArgument.name} (${toolArgument.type}) · ${toolArgument.required ? "required" : "optional"}`}
1511
+ </Text>
1512
+ {toolArgument.description ? (
1513
+ <Text color="secondaryDark" size="sm">
1514
+ {toolArgument.description}
1515
+ </Text>
1516
+ ) : null}
1517
+ </Box>
1518
+ ))
1519
+ )}
1520
+ </>
1521
+ ) : null}
1522
+ </Box>
1523
+ );
1524
+ })
1525
+ )}
1526
+ </Box>
1527
+ </ScrollView>
1354
1528
  </Modal>
1355
1529
  );
1356
1530
  };
@@ -1432,7 +1606,9 @@ export const GPTChat = ({
1432
1606
  onDeleteHistory,
1433
1607
  onGeminiApiKeyChange,
1434
1608
  onMemoryEdit,
1609
+ onMessageSignal,
1435
1610
  onModelChange,
1611
+ onRateComment,
1436
1612
  onRateFeedback,
1437
1613
  onRemoveAttachment,
1438
1614
  onSelectHistory,
@@ -1587,21 +1763,36 @@ export const GPTChat = ({
1587
1763
  }, [inputElement]);
1588
1764
 
1589
1765
  // Image-only replies have no meaningful text, so copy the image instead of a placeholder.
1590
- const handleCopyMessage = useCallback(async (message: GPTChatMessage) => {
1591
- const firstImage = message.contentParts?.find(
1592
- (part): part is ImageContentPart => part.type === "image"
1593
- );
1594
- if (firstImage && !message.content.trim()) {
1766
+ // Signals "copied" only after the clipboard write succeeds, and only for stored messages.
1767
+ const handleCopyMessage = useCallback(
1768
+ async (message: GPTChatMessage, index: number) => {
1769
+ const signalCopied = (): void => {
1770
+ if (index >= 0) {
1771
+ onMessageSignal?.(index, "copied");
1772
+ }
1773
+ };
1774
+ const firstImage = message.contentParts?.find(
1775
+ (part): part is ImageContentPart => part.type === "image"
1776
+ );
1777
+ if (firstImage && !message.content.trim()) {
1778
+ try {
1779
+ await copyImageToClipboard(firstImage);
1780
+ signalCopied();
1781
+ } catch (error) {
1782
+ console.warn("Failed to copy image", error);
1783
+ }
1784
+ return;
1785
+ }
1595
1786
  try {
1596
- await copyImageToClipboard(firstImage);
1787
+ const Clipboard = await import("expo-clipboard");
1788
+ await Clipboard.setStringAsync(message.content);
1789
+ signalCopied();
1597
1790
  } catch (error) {
1598
- console.warn("Failed to copy image", error);
1791
+ console.warn("Failed to copy message", error);
1599
1792
  }
1600
- return;
1601
- }
1602
- const Clipboard = await import("expo-clipboard");
1603
- await Clipboard.setStringAsync(message.content);
1604
- }, []);
1793
+ },
1794
+ [onMessageSignal]
1795
+ );
1605
1796
 
1606
1797
  const scrollToBottom = useCallback(() => {
1607
1798
  scrollViewRef.current?.scrollToEnd({animated: true});
@@ -1755,6 +1946,7 @@ export const GPTChat = ({
1755
1946
  onClick={() => onSelectHistory(history.id)}
1756
1947
  padding={2}
1757
1948
  rounding="md"
1949
+ testID={`gpt-history-${history.id}`}
1758
1950
  >
1759
1951
  <HistoryItemTitle
1760
1952
  currentHistoryId={currentHistoryId}
@@ -1781,103 +1973,115 @@ export const GPTChat = ({
1781
1973
  )}
1782
1974
 
1783
1975
  {/* Chat Panel */}
1784
- <Box direction="column" flex="grow" padding={4}>
1785
- {/* Messages */}
1786
- <Box flex="grow" marginBottom={3} onLayout={handleViewportLayout} testID="gpt-viewport">
1787
- <Box flex="grow" gap={3} onScroll={handleScroll} scroll={true} scrollRef={scrollViewRef}>
1788
- <Box flex="grow" gap={3} onLayout={handleContentLayout} testID="gpt-messages">
1789
- {isEmptyChat ? (
1790
- <EmptyChatHero
1791
- handleSuggestedPrompt={handleSuggestedPrompt}
1792
- isStreaming={isStreaming}
1793
- mascot={mascot}
1794
- suggestedPrompts={suggestedPrompts}
1795
- viewportHeight={viewportHeight}
1796
- />
1797
- ) : (
1798
- <>
1799
- <MessageList
1800
- allowHtml={allowHtml}
1801
- appendedByMessage={appendedByMessage}
1802
- askErrors={askErrors}
1803
- blockOverrides={blockOverrides}
1804
- currentMessages={currentMessages}
1805
- handleCopyMessage={handleCopyMessage}
1806
- hostActions={hostActions}
1807
- imageHosts={imageHosts}
1976
+ <Box alignItems="center" direction="column" flex="grow" padding={4}>
1977
+ <Box direction="column" flex="grow" maxWidth={760} width="100%">
1978
+ {/* Messages */}
1979
+ <Box flex="grow" marginBottom={3} onLayout={handleViewportLayout} testID="gpt-viewport">
1980
+ <Box
1981
+ flex="grow"
1982
+ gap={5}
1983
+ onScroll={handleScroll}
1984
+ scroll={true}
1985
+ scrollRef={scrollViewRef}
1986
+ >
1987
+ <Box flex="grow" gap={5} onLayout={handleContentLayout} testID="gpt-messages">
1988
+ {isEmptyChat ? (
1989
+ <EmptyChatHero
1990
+ handleSuggestedPrompt={handleSuggestedPrompt}
1808
1991
  isStreaming={isStreaming}
1809
- onAskSubmit={onAskSubmit}
1810
- onBlockEvent={handleBlockEvent}
1811
- onRateFeedback={onRateFeedback}
1812
- pendingElements={pendingElements}
1813
- resolveAskFiles={resolveAskFiles}
1814
- resolveDataset={resolveDataset}
1815
- resolveImage={resolveImage}
1816
- uiBlocks={uiBlocks}
1817
- />
1818
- <StreamingIndicator
1819
- isStreaming={
1820
- isStreaming &&
1821
- !(
1822
- uiBlocks &&
1823
- currentMessages[currentMessages.length - 1]?.role === "assistant"
1824
- )
1825
- }
1992
+ mascot={mascot}
1993
+ suggestedPrompts={suggestedPrompts}
1994
+ viewportHeight={viewportHeight}
1826
1995
  />
1827
- </>
1828
- )}
1996
+ ) : (
1997
+ <>
1998
+ <MessageList
1999
+ allowHtml={allowHtml}
2000
+ appendedByMessage={appendedByMessage}
2001
+ askErrors={askErrors}
2002
+ blockOverrides={blockOverrides}
2003
+ currentMessages={currentMessages}
2004
+ handleCopyMessage={handleCopyMessage}
2005
+ hostActions={hostActions}
2006
+ imageHosts={imageHosts}
2007
+ isStreaming={isStreaming}
2008
+ onAskSubmit={onAskSubmit}
2009
+ onBlockEvent={handleBlockEvent}
2010
+ onRateComment={onRateComment}
2011
+ onRateFeedback={onRateFeedback}
2012
+ pendingElements={pendingElements}
2013
+ resolveAskFiles={resolveAskFiles}
2014
+ resolveDataset={resolveDataset}
2015
+ resolveImage={resolveImage}
2016
+ uiBlocks={uiBlocks}
2017
+ />
2018
+ <StreamingIndicator
2019
+ isStreaming={
2020
+ isStreaming &&
2021
+ !(
2022
+ uiBlocks &&
2023
+ currentMessages[currentMessages.length - 1]?.role === "assistant"
2024
+ )
2025
+ }
2026
+ />
2027
+ </>
2028
+ )}
2029
+ </Box>
1829
2030
  </Box>
1830
2031
  </Box>
1831
- </Box>
1832
2032
 
1833
- <ScrollToBottomButton
1834
- isScrolledUp={isScrolledUp && !isEmptyChat}
1835
- scrollToBottom={scrollToBottom}
1836
- />
1837
- <AttachmentSection attachments={attachments} onRemoveAttachment={onRemoveAttachment} />
1838
-
1839
- {/* Input */}
1840
- <Box direction="row" gap={2} testID="gpt-composer">
1841
- {onAttachFiles ? (
1842
- <Box justifyContent="center" testID="gpt-composer-attach">
1843
- <AttachButton
1844
- handleFilesSelected={handleFilesSelected}
1845
- isStreaming={isStreaming}
1846
- onAttachFiles={onAttachFiles}
2033
+ <ScrollToBottomButton
2034
+ isScrolledUp={isScrolledUp && !isEmptyChat}
2035
+ scrollToBottom={scrollToBottom}
2036
+ />
2037
+ <AttachmentSection attachments={attachments} onRemoveAttachment={onRemoveAttachment} />
2038
+
2039
+ {/* Input */}
2040
+ <Box direction="row" gap={2} testID="gpt-composer">
2041
+ {onAttachFiles ? (
2042
+ <Box justifyContent="center" testID="gpt-composer-attach">
2043
+ <AttachButton
2044
+ handleFilesSelected={handleFilesSelected}
2045
+ isStreaming={isStreaming}
2046
+ onAttachFiles={onAttachFiles}
2047
+ />
2048
+ </Box>
2049
+ ) : null}
2050
+ {mcpTools && mcpTools.length > 0 ? (
2051
+ <Box justifyContent="center" testID="gpt-composer-tools">
2052
+ <Button
2053
+ accessibilityLabel="Show available tools"
2054
+ iconName="wrench"
2055
+ onClick={() => setIsToolsModalVisible(true)}
2056
+ size="sm"
2057
+ testID="gpt-tools-button"
2058
+ text="Tools"
2059
+ variant="outline"
2060
+ />
2061
+ </Box>
2062
+ ) : null}
2063
+ <Box flex="grow" justifyContent="center">
2064
+ <TextArea
2065
+ blurOnSubmit={false}
2066
+ disabled={isStreaming}
2067
+ grow
2068
+ inputRef={handleInputRef}
2069
+ maxHeight={COMPOSER_MAX_HEIGHT}
2070
+ onChange={setInputValue}
2071
+ placeholder="Type a message..."
2072
+ testID="gpt-input"
2073
+ value={inputValue}
1847
2074
  />
1848
2075
  </Box>
1849
- ) : null}
1850
- {mcpTools && mcpTools.length > 0 && (
1851
- <Box justifyContent="center" testID="gpt-composer-tools">
1852
- <IconButton
1853
- accessibilityLabel="Show available tools"
1854
- iconName="hammer"
1855
- onClick={() => setIsToolsModalVisible(true)}
1856
- testID="gpt-tools-button"
2076
+ <Box justifyContent="center" testID="gpt-composer-send">
2077
+ <Button
2078
+ disabled={!inputValue.trim() || isStreaming}
2079
+ iconName="paper-plane"
2080
+ onClick={handleSubmit}
2081
+ testID="gpt-submit"
2082
+ text="Send"
1857
2083
  />
1858
2084
  </Box>
1859
- )}
1860
- <Box flex="grow" justifyContent="center">
1861
- <TextArea
1862
- blurOnSubmit={false}
1863
- disabled={isStreaming}
1864
- grow
1865
- inputRef={handleInputRef}
1866
- maxHeight={COMPOSER_MAX_HEIGHT}
1867
- onChange={setInputValue}
1868
- placeholder="Type a message..."
1869
- testID="gpt-input"
1870
- value={inputValue}
1871
- />
1872
- </Box>
1873
- <Box justifyContent="center" testID="gpt-composer-send">
1874
- <Button
1875
- disabled={!inputValue.trim() || isStreaming}
1876
- iconName="paper-plane"
1877
- onClick={handleSubmit}
1878
- testID="gpt-submit"
1879
- text="Send"
1880
- />
1881
2085
  </Box>
1882
2086
  </Box>
1883
2087
  </Box>