Skip to content

An AI-powered search engine with a generative UI

feat: add UIToolInvocation type exports to tool definitions

Yoshiki Miura1f55339a8b6f
diff --git a/lib/agents/researcher.ts b/lib/agents/researcher.ts
index b7725349..9d12ac40 100644
--- a/lib/agents/researcher.ts
+++ b/lib/agents/researcher.ts
@@ -40,6 +40,7 @@ function wrapSearchToolForQuickMode<
throw new Error('Search tool execute function is not defined')
}
+ // Force optimized type for quick mode
const result = await executeFunc(
{
...params,
@@ -48,26 +49,6 @@ function wrapSearchToolForQuickMode<
context
)
- // Handle AsyncIterable case with proper typing
- if (
- result &&
- typeof result === 'object' &&
- Symbol.asyncIterator in result
- ) {
- let searchResults: any = null
- for await (const chunk of result) {
- searchResults = chunk
- }
- return (
- searchResults || {
- results: [],
- images: [],
- query: params.query,
- number_of_results: 0
- }
- )
- }
-
return (
result || {
results: [],
diff --git a/lib/tools/fetch.ts b/lib/tools/fetch.ts
index e4985aa3..d1b996ea 100644
--- a/lib/tools/fetch.ts
+++ b/lib/tools/fetch.ts
@@ -1,4 +1,4 @@
-import { tool } from 'ai'
+import { tool, UIToolInvocation } from 'ai'
import { fetchSchema } from '@/lib/schema/fetch'
import { SearchResults as SearchResultsType } from '@/lib/types'
@@ -180,3 +180,6 @@ export const fetchTool = tool({
return results
}
})
+
+// Export type for UI tool invocation
+export type FetchUIToolInvocation = UIToolInvocation<typeof fetchTool>
diff --git a/lib/tools/search.ts b/lib/tools/search.ts
index 0bf7154c..842c436c 100644
--- a/lib/tools/search.ts
+++ b/lib/tools/search.ts
@@ -1,4 +1,4 @@
-import { tool } from 'ai'
+import { tool, UIToolInvocation } from 'ai'
import { getSearchSchemaForModel } from '@/lib/schema/search'
import { SearchResultItem, SearchResults } from '@/lib/types'
@@ -145,6 +145,9 @@ export function createSearchTool(fullModel: string) {
// Default export for backward compatibility, using a default model
export const searchTool = createSearchTool('openai:gpt-4o-mini')
+// Export type for UI tool invocation
+export type SearchUIToolInvocation = UIToolInvocation<typeof searchTool>
+
export async function search(
query: string,
maxResults: number = 10,