An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
import type { ReasoningPart, TextPart } from '@ai-sdk/provider-utils'
import type { InferUITool, UIMessage as AIMessage } from 'ai'
import type { fetchTool } from '@/lib/tools/fetch'
import type { askQuestionTool } from '@/lib/tools/question'
import type { searchTool } from '@/lib/tools/search'
import { createTodoTools, type TodoItem } from '@/lib/tools/todo'
import type { SearchMode } from '@/lib/types/search'
// Re-export TodoItem for external use
export type { TodoItem }
// Define metadata type for messages
export interface UIMessageMetadata {
traceId?: string
feedbackScore?: number | null
searchMode?: SearchMode
modelId?: string
[key: string]: any
}
export type UIMessage<
TMetadata = UIMessageMetadata,
TDataTypes = UIDataTypes,
TTools = UITools
> = AIMessage
export type UIDataTypes = {
sources?: any[]
// User-authored attachments (composer): a pasted text blob and a pasted URL.
// `nonce` is the delimiter assigned server-side by `assignDataPartNonces`;
// the composer never sets it.
pastedContent?: { text: string; nonce?: string }
quotedContext?: { text: string; nonce?: string }
noteContext?: { title?: string; text: string; nonce?: string }
sourceUrl?: { url: string }
}
// Create todo tools instance for type inference
const todoTools = createTodoTools()
export type UITools = {
search: InferUITool<typeof searchTool>
fetch: InferUITool<typeof fetchTool>
askQuestion: InferUITool<typeof askQuestionTool>
todoWrite: InferUITool<typeof todoTools.todoWrite>
// Dynamic tools will be added at runtime
[key: string]: any
}
export type ToolPart<T extends keyof UITools = keyof UITools> = {
type: `tool-${T}`
toolCallId: string
input: UITools[T]['input']
output?: UITools[T]['output']
state:
| 'input-streaming'
| 'input-available'
| 'output-available'
| 'output-error'
errorText?: string
}
// Opens the chat's draft in the inspector panel; not a message part.
export type DraftPanelPart = { type: 'draft' }
export type Part = TextPart | ReasoningPart | ToolPart | DraftPanelPart