File tree 1 file changed +21
-12
lines changed
templates/types/streaming/nextjs/app/components/ui/chat/tools
1 file changed +21
-12
lines changed Original file line number Diff line number Diff line change @@ -16,15 +16,25 @@ const QueryIndexSchema = z.object({
16
16
} ) ,
17
17
tool_id : z . string ( ) ,
18
18
tool_output : z . optional (
19
- z
20
- . object ( {
21
- content : z . string ( ) ,
22
- tool_name : z . string ( ) ,
23
- raw_input : z . record ( z . unknown ( ) ) ,
24
- raw_output : z . record ( z . unknown ( ) ) ,
25
- is_error : z . boolean ( ) . optional ( ) ,
26
- } )
27
- . optional ( ) ,
19
+ z . object ( {
20
+ content : z . string ( ) ,
21
+ tool_name : z . string ( ) ,
22
+ raw_output : z . object ( {
23
+ source_nodes : z . array (
24
+ z . object ( {
25
+ node : z . object ( {
26
+ id_ : z . string ( ) ,
27
+ metadata : z . object ( {
28
+ url : z . string ( ) ,
29
+ } ) ,
30
+ text : z . string ( ) ,
31
+ } ) ,
32
+ score : z . number ( ) ,
33
+ } ) ,
34
+ ) ,
35
+ } ) ,
36
+ is_error : z . boolean ( ) . optional ( ) ,
37
+ } ) ,
28
38
) ,
29
39
return_direct : z . boolean ( ) . optional ( ) ,
30
40
} ) ;
@@ -69,7 +79,7 @@ export function RetrieverComponent() {
69
79
70
80
if ( initial . tool_output ) {
71
81
eventData . push ( {
72
- title : `Got ${ JSON . stringify ( ( initial . tool_output ?. raw_output as any ) . source_nodes ?. length ?? 0 ) } sources for query: ${ initial . tool_kwargs . input } ` ,
82
+ title : `Got ${ JSON . stringify ( initial . tool_output ?. raw_output . source_nodes ?. length ?? 0 ) } sources for query: ${ initial . tool_kwargs . input } ` ,
73
83
} ) ;
74
84
}
75
85
@@ -103,8 +113,7 @@ export function ChatSourcesComponent() {
103
113
const sources : SourceNode [ ] = useMemo ( ( ) => {
104
114
return (
105
115
queryIndexEvents ?. flatMap ( ( event ) => {
106
- const sourceNodes =
107
- ( event . tool_output ?. raw_output ?. source_nodes as any [ ] ) || [ ] ;
116
+ const sourceNodes = event . tool_output ?. raw_output ?. source_nodes || [ ] ;
108
117
return sourceNodes . map ( ( node ) => {
109
118
return {
110
119
id : node . node . id_ ,
You can’t perform that action at this time.
0 commit comments