@@ -4,6 +4,7 @@ import { getSpaceLanguage } from '@/intl/server';
4
4
import { t } from '@/intl/translate' ;
5
5
import type { GitBookSiteContext } from '@/lib/context' ;
6
6
import { resolveContentRef } from '@/lib/references' ;
7
+ import { tcls } from '@/lib/tailwind' ;
7
8
import type {
8
9
AIToolCall ,
9
10
AIToolCallGetPageContent ,
@@ -37,7 +38,7 @@ function ToolCallSummary(props: { toolCall: AIToolCall; context: GitBookSiteCont
37
38
const { toolCall, context } = props ;
38
39
39
40
return (
40
- < div className = "flex items-start gap-2 text-sm text-tint-subtle" >
41
+ < div className = "flex origin-left animate-[scaleIn_500ms_500ms_both] items-start gap-2 text-sm text-tint-subtle" >
41
42
< Icon
42
43
icon = { getIconForToolCall ( toolCall ) }
43
44
className = "mt-1 size-3 shrink-0 text-tint-subtle/8"
@@ -144,69 +145,80 @@ async function DescriptionForSearchToolCall(props: {
144
145
} )
145
146
) ;
146
147
148
+ const hasResults = toolCall . results . length > 0 ;
149
+
147
150
return (
148
- < details className = "-ml-5 group flex w-full flex-col gap-2" >
149
- < summary className = "-mx-2 -mt-2 flex cursor-pointer list-none items-center gap-2 rounded-corners:rounded-md py-2 pr-4 pl-7 transition-colors marker:hidden hover:bg-primary-hover" >
151
+ < details className = { tcls ( '-ml-5 group flex w-full flex-col' , hasResults ? 'gap-2' : '' ) } >
152
+ < summary
153
+ className = { tcls (
154
+ '-mx-2 flex list-none items-center gap-2 rounded-corners:rounded-md pr-4 pl-7 transition-colors marker:hidden' ,
155
+ hasResults ? '-my-2 cursor-pointer py-2 hover:bg-primary-hover' : ''
156
+ ) }
157
+ >
150
158
< div className = "flex flex-col" >
151
159
< p > { t ( language , 'searched_for' , < strong > { toolCall . query } </ strong > ) } </ p >
152
160
< p className = "text-tint-subtle text-xs" >
153
- { toolCall . results . length
161
+ { hasResults
154
162
? t ( language , 'search_results_count' , toolCall . results . length )
155
163
: t ( language , 'search_no_results' ) }
156
164
</ p >
157
165
</ div >
158
- < div className = "ml-auto flex items-center gap-1" >
159
- < span className = "block group-open:hidden" > { t ( language , 'view' ) } </ span >
160
- < span className = "hidden group-open:block" > { t ( language , 'close' ) } </ span >
161
- < Icon
162
- icon = "chevron-right"
163
- className = "size-3 shrink-0 transition-transform group-open:rotate-90"
164
- />
165
- </ div >
166
+ { hasResults ? (
167
+ < div className = "ml-auto flex items-center gap-1" >
168
+ < span className = "block group-open:hidden" > { t ( language , 'view' ) } </ span >
169
+ < span className = "hidden group-open:block" > { t ( language , 'close' ) } </ span >
170
+ < Icon
171
+ icon = "chevron-right"
172
+ className = "size-3 shrink-0 transition-transform group-open:rotate-90"
173
+ />
174
+ </ div >
175
+ ) : null }
166
176
</ summary >
167
- < div className = "max-h-0 overflow-y-auto circular-corners:rounded-2xl rounded-corners:rounded-lg border border-tint-subtle p-2 opacity-0 transition-all duration-500 [transition-behavior:allow-discrete] group-open:max-h-96 group-open:opacity-11" >
168
- < ol className = "space-y-1" >
169
- { searchResultsWithHrefs . map ( ( result , index ) => (
170
- < li
171
- key = { `${ result . pageId } -${ index } ` }
172
- className = "animate-fadeIn"
173
- style = { {
174
- animationDelay : `${ index * 25 } ms` ,
175
- } }
176
- >
177
- < Link
178
- href = { result . href }
179
- className = "flex items-start gap-2 circular-corners:rounded-2xl rounded-corners:rounded-md px-3 py-2 transition-colors hover:bg-primary-hover"
177
+ { hasResults ? (
178
+ < div className = "max-h-0 overflow-y-auto circular-corners:rounded-2xl rounded-corners:rounded-lg border border-tint-subtle p-2 opacity-0 transition-all duration-500 [transition-behavior:allow-discrete] group-open:max-h-96 group-open:opacity-11" >
179
+ < ol className = "space-y-1" >
180
+ { searchResultsWithHrefs . map ( ( result , index ) => (
181
+ < li
182
+ key = { `${ result . pageId } -${ index } ` }
183
+ className = "animate-fadeIn"
184
+ style = { {
185
+ animationDelay : `${ index * 25 } ms` ,
186
+ } }
180
187
>
181
- < Icon
182
- icon = "memo"
183
- className = "mt-1 size-3 shrink-0 text-tint-subtle"
184
- />
185
- < div className = "flex flex-col gap-1 text-tint" >
186
- < h3 className = "line-clamp-2 font-medium text-sm text-tint" >
187
- < HighlightQuery
188
- query = { toolCall . query }
189
- text = { result . title }
190
- />
191
- </ h3 >
192
- { result . description && (
193
- < p className = "line-clamp-2 text-tint-subtle text-xs" >
188
+ < Link
189
+ href = { result . href }
190
+ className = "flex items-start gap-2 circular-corners:rounded-2xl rounded-corners:rounded-md px-3 py-2 transition-colors hover:bg-primary-hover"
191
+ >
192
+ < Icon
193
+ icon = "memo"
194
+ className = "mt-1 size-3 shrink-0 text-tint-subtle"
195
+ />
196
+ < div className = "flex flex-col gap-1 text-tint" >
197
+ < h3 className = "line-clamp-2 font-medium text-sm text-tint" >
194
198
< HighlightQuery
195
199
query = { toolCall . query }
196
- text = { result . description }
200
+ text = { result . title }
197
201
/>
198
- </ p >
199
- ) }
200
- </ div >
201
- < Icon
202
- icon = "chevron-right"
203
- className = "ml-auto size-3 shrink-0 self-center"
204
- />
205
- </ Link >
206
- </ li >
207
- ) ) }
208
- </ ol >
209
- </ div >
202
+ </ h3 >
203
+ { result . description && (
204
+ < p className = "line-clamp-2 text-tint-subtle text-xs" >
205
+ < HighlightQuery
206
+ query = { toolCall . query }
207
+ text = { result . description }
208
+ />
209
+ </ p >
210
+ ) }
211
+ </ div >
212
+ < Icon
213
+ icon = "chevron-right"
214
+ className = "ml-auto size-3 shrink-0 self-center"
215
+ />
216
+ </ Link >
217
+ </ li >
218
+ ) ) }
219
+ </ ol >
220
+ </ div >
221
+ ) : null }
210
222
</ details >
211
223
) ;
212
224
}
0 commit comments