Skip to content

Commit 1e90a6a

Browse files
committed
improve typing
1 parent fe5982e commit 1e90a6a

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

templates/types/streaming/nextjs/app/components/ui/chat/tools/query-index.tsx

+21-12
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,25 @@ const QueryIndexSchema = z.object({
1616
}),
1717
tool_id: z.string(),
1818
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+
}),
2838
),
2939
return_direct: z.boolean().optional(),
3040
});
@@ -69,7 +79,7 @@ export function RetrieverComponent() {
6979

7080
if (initial.tool_output) {
7181
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}`,
7383
});
7484
}
7585

@@ -103,8 +113,7 @@ export function ChatSourcesComponent() {
103113
const sources: SourceNode[] = useMemo(() => {
104114
return (
105115
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 || [];
108117
return sourceNodes.map((node) => {
109118
return {
110119
id: node.node.id_,

0 commit comments

Comments
 (0)