@@ -3,14 +3,19 @@ import type { SetStateAction } from 'react';
33import type { UIBlock } from './block' ;
44import { FileIcon , LoaderIcon , MessageIcon , PencilEditIcon } from './icons' ;
55
6- const getActionText = ( type : 'create' | 'update' | 'request-suggestions' ) => {
6+ const getActionText = (
7+ type : 'create' | 'update' | 'request-suggestions' ,
8+ tense : 'present' | 'past' ,
9+ ) => {
710 switch ( type ) {
811 case 'create' :
9- return ' Creating';
12+ return tense === 'present' ? ' Creating' : 'Created ';
1013 case 'update' :
11- return ' Updating';
14+ return tense === 'present' ? ' Updating' : 'Updated ';
1215 case 'request-suggestions' :
13- return 'Adding suggestions' ;
16+ return tense === 'present'
17+ ? 'Adding suggestions'
18+ : 'Added suggestions to' ;
1419 default :
1520 return null ;
1621 }
@@ -26,7 +31,6 @@ interface DocumentToolResultProps {
2631export function DocumentToolResult ( {
2732 type,
2833 result,
29- block,
3034 setBlock,
3135} : DocumentToolResultProps ) {
3236 return (
@@ -62,8 +66,8 @@ export function DocumentToolResult({
6266 < MessageIcon />
6367 ) : null }
6468 </ div >
65- < div className = "" >
66- { getActionText ( type ) } { result . title }
69+ < div className = "text-left " >
70+ { ` ${ getActionText ( type , 'past' ) } " $ {result . title } "` }
6771 </ div >
6872 </ button >
6973 ) ;
@@ -72,11 +76,35 @@ export function DocumentToolResult({
7276interface DocumentToolCallProps {
7377 type : 'create' | 'update' | 'request-suggestions' ;
7478 args : { title : string } ;
79+ setBlock : ( value : SetStateAction < UIBlock > ) => void ;
7580}
7681
77- export function DocumentToolCall ( { type, args } : DocumentToolCallProps ) {
82+ export function DocumentToolCall ( {
83+ type,
84+ args,
85+ setBlock,
86+ } : DocumentToolCallProps ) {
7887 return (
79- < div className = "w-fit border py-2 px-3 rounded-xl flex flex-row items-start justify-between gap-3" >
88+ < button
89+ type = "button"
90+ className = "cursor pointer w-fit border py-2 px-3 rounded-xl flex flex-row items-start justify-between gap-3"
91+ onClick = { ( event ) => {
92+ const rect = event . currentTarget . getBoundingClientRect ( ) ;
93+
94+ const boundingBox = {
95+ top : rect . top ,
96+ left : rect . left ,
97+ width : rect . width ,
98+ height : rect . height ,
99+ } ;
100+
101+ setBlock ( ( currentBlock ) => ( {
102+ ...currentBlock ,
103+ isVisible : true ,
104+ boundingBox,
105+ } ) ) ;
106+ } }
107+ >
80108 < div className = "flex flex-row gap-3 items-start" >
81109 < div className = "text-zinc-500 mt-1" >
82110 { type === 'create' ? (
@@ -88,12 +116,12 @@ export function DocumentToolCall({ type, args }: DocumentToolCallProps) {
88116 ) : null }
89117 </ div >
90118
91- < div className = "" >
92- { getActionText ( type ) } { args . title }
119+ < div className = "text-left " >
120+ { ` ${ getActionText ( type , 'present' ) } $ {args . title ? `" ${ args . title } "` : '' } ` }
93121 </ div >
94122 </ div >
95123
96124 < div className = "animate-spin mt-1" > { < LoaderIcon /> } </ div >
97- </ div >
125+ </ button >
98126 ) ;
99127}
0 commit comments