An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
Merge branch 'main' of https://github.com/miurla/morphic into v1.0.0
Yoshiki Miura414d5b94c6e8
diff --cc .env.local.exampleindex 7bb94614,87bee6c9..72319c16--- a/.env.local.example+++ b/.env.local.example@@@ -1,91 -1,81 +1,130 @@@###############################################################################-# Required Configuration-# These settings are essential for the basic functionality of the system.+# Morphic Configuration###############################################################################-# OpenAI API key retrieved here: https://platform.openai.com/api-keys+# =============================================================================+# REQUIRED CONFIGURATION+# These settings are essential for the application to function+# =============================================================================++# -----------------------------------------------------------------------------+# Database Configuration (Required)+# -----------------------------------------------------------------------------+# PostgreSQL connection string (supports Neon, Supabase, or standard PostgreSQL)+# Format: postgresql://[user]:[password]@[host]/[database]?sslmode=require+DATABASE_URL=[YOUR_DATABASE_URL]++# -----------------------------------------------------------------------------+# AI Provider Configuration (At least one required)+# -----------------------------------------------------------------------------+# IMPORTANT: When using non-OpenAI providers, you must update the model+# configuration in config/models/*.json to use compatible model IDs for your+# chosen provider. See docs/CONFIGURATION.md for provider-specific model IDs.++# Option 1: OpenAI+# Get your API key at: https://platform.openai.com/api-keysOPENAI_API_KEY=[YOUR_OPENAI_API_KEY]++<<<<<<< HEAD+# Option 2: Anthropic Claude+# Requires updating config/models/*.json with Anthropic model IDs++=======+ # Search Configuration+ TAVILY_API_KEY=[YOUR_TAVILY_API_KEY] # Get your API key at: https://app.tavily.com/home+ # FIRECRAWL_API_KEY=[YOUR_FIRECRAWL_API_KEY] # Get your API key at: https://www.firecrawl.dev/app++ # Optional Docker Configuration (only needed in some Docker environments)+ # BASE_URL=http://localhost:3000 # Use only if models.json fails to load in Docker++ ###############################################################################+ # Optional Features+ # Enable these features by uncommenting and configuring the settings below+ ###############################################################################++ #------------------------------------------------------------------------------+ # Chat History Storage+ # Enable persistent chat history across sessions+ #------------------------------------------------------------------------------+ # ENABLE_SAVE_CHAT_HISTORY=true # enable chat history storage++ # Redis Configuration (Required if ENABLE_SAVE_CHAT_HISTORY=true)+ # Choose between local Redis or Upstash Redis+ # OPTION 1: Local Redis+ # USE_LOCAL_REDIS=false # use local Redis+ # LOCAL_REDIS_URL=redis://localhost:6379 # local Redis URL (if USE_LOCAL_REDIS=true)++ # OPTION 2: Upstash Redis (Recommended for production)+ # UPSTASH_REDIS_REST_URL=[YOUR_UPSTASH_REDIS_REST_URL] # Upstash Redis REST URL (if USE_LOCAL_REDIS=false)+ # UPSTASH_REDIS_REST_TOKEN=[YOUR_UPSTASH_REDIS_REST_TOKEN] # Upstash Redis REST Token (if USE_LOCAL_REDIS=false)++ #------------------------------------------------------------------------------+ # Additional AI Providers+ # Enable alternative AI models by configuring these providers+ #------------------------------------------------------------------------------+ # Google Generative AI+ # GOOGLE_GENERATIVE_AI_API_KEY=[YOUR_GOOGLE_GENERATIVE_AI_API_KEY]++ # Anthropic (Claude)++>>>>>>> 021a97905e6be6cd63de8881a5e4f50a0fde28d2# ANTHROPIC_API_KEY=[YOUR_ANTHROPIC_API_KEY]-# Groq-# GROQ_API_KEY=[YOUR_GROQ_API_KEY]--# Ollama-# OLLAMA_BASE_URL=http://localhost:11434--# Azure OpenAI-# AZURE_API_KEY=-# AZURE_RESOURCE_NAME=--# DeepSeek-# DEEPSEEK_API_KEY=[YOUR_DEEPSEEK_API_KEY]--# Fireworks-# FIREWORKS_API_KEY=[YOUR_FIREWORKS_API_KEY]--# xAI (Grok)-# XAI_API_KEY=[YOUR_XAI_API_KEY]--# OpenAI Compatible Model-# OPENAI_COMPATIBLE_API_KEY=-# OPENAI_COMPATIBLE_API_BASE_URL=+# Option 3: Google Gemini+# Requires updating config/models/*.json with Google model IDs+# GOOGLE_GENERATIVE_AI_API_KEY=[YOUR_GOOGLE_GENERATIVE_AI_API_KEY]-#------------------------------------------------------------------------------+# Option 4: Vercel AI Gateway+# Unified API gateway for multiple providers+# AI_GATEWAY_API_KEY=[YOUR_AI_GATEWAY_API_KEY]++# -----------------------------------------------------------------------------+# Search Provider Configuration (Required)+# -----------------------------------------------------------------------------+# Tavily Search+# Get your API key at: https://app.tavily.com/home+TAVILY_API_KEY=[YOUR_TAVILY_API_KEY]++# Brave Search (Required for comprehensive search results)+# Get your API key at: https://brave.com/search/api/+# Note: Can be made optional by commenting out after initial setup+BRAVE_SEARCH_API_KEY=[YOUR_BRAVE_SEARCH_API_KEY]++# -----------------------------------------------------------------------------+# Authentication Configuration (Required)+# -----------------------------------------------------------------------------+# Supabase Authentication+# Get your project URL and anon key from: https://supabase.com/dashboard+# Note: Can be made optional in future releases for anonymous-only usage+NEXT_PUBLIC_SUPABASE_URL=[YOUR_SUPABASE_PROJECT_URL]+NEXT_PUBLIC_SUPABASE_ANON_KEY=[YOUR_SUPABASE_ANON_KEY]++# =============================================================================+# OPTIONAL FEATURES+# Enable additional functionality as needed+# =============================================================================++# -----------------------------------------------------------------------------+# File Upload Support (Cloudflare R2)+# Enable file and image upload functionality+# -----------------------------------------------------------------------------+# R2_ACCOUNT_ID=[YOUR_R2_ACCOUNT_ID]+# R2_ACCESS_KEY_ID=[YOUR_R2_ACCESS_KEY_ID]+# R2_SECRET_ACCESS_KEY=[YOUR_R2_SECRET_ACCESS_KEY]+# R2_BUCKET_NAME=user-uploads # Default: user-uploads+# R2_PUBLIC_URL=[YOUR_R2_PUBLIC_URL] # e.g., https://pub-xxx.r2.dev++# -----------------------------------------------------------------------------# Alternative Search Providers-# Configure different search backends (default: Tavily)-#-------------------------------------------------------------------------------# SEARCH_API=searxng # Available options: tavily, searxng, exa, firecrawl+# Configure different search backends+# -----------------------------------------------------------------------------+# Select search provider (default: tavily)- # SEARCH_API=tavily # Options: tavily, searxng, exa++# SEARCH_API=tavily # Options: tavily, searxng, exa, firecrawl++# Exa Neural Search+# EXA_API_KEY=[YOUR_EXA_API_KEY]-# SearXNG Configuration (Required if SEARCH_API=searxng)-# SEARXNG_API_URL=http://localhost:8080 # Replace with your local SearXNG API URL or docker http://searxng:8080-# SEARXNG_SECRET="" # generate a secret key e.g. openssl rand -base64 32+# SearXNG (Self-hosted)+# SEARXNG_API_URL=http://localhost:8080 # Or docker: http://searxng:8080+# SEARXNG_SECRET=[YOUR_SECRET_KEY] # Generate: openssl rand -base64 32# SEARXNG_PORT=8080# SEARXNG_BIND_ADDRESS=0.0.0.0# SEARXNG_IMAGE_PROXY=truediff --cc README.mdindex 0e3fee43,038518b1..fdc200d3--- a/README.md+++ b/README.md@@@ -91,12 -86,12 +91,13 @@@ Models are configured in `config/models### AI & Search-- [OpenAI](https://openai.com/) - Default AI provider (Optional: Google AI, Anthropic, Groq, Ollama, Azure OpenAI, DeepSeek, Fireworks)-- [Tavily AI](https://tavily.com/) - Default search provider-- Alternative providers:+- [OpenAI](https://openai.com/) - Default AI provider (Optional: Google AI, Anthropic)+- [Tavily AI](https://tavily.com/) - AI-optimized search with context+- [Brave Search](https://brave.com/search/api/) - Traditional web search results+- Tavily alternatives:- [SearXNG](https://docs.searxng.org/) - Self-hosted search- - [Exa](https://exa.ai/) - Neural search+ - [Exa](https://exa.ai/) - Meaning-based search powered by embeddings+ - [Firecrawl](https://firecrawl.dev/) - Web, news, and image search with crawling, scraping, LLM-ready extraction, and [open source](https://github.com/firecrawl/firecrawl).### Data Storagediff --cc components/chat-messages.tsxindex c1a2f632,af176829..0b33f0d3--- a/components/chat-messages.tsx+++ b/components/chat-messages.tsx@@@ -1,16 -1,14 +1,15 @@@'use client'-import { useEffect, useMemo, useState } from 'react'+import { useEffect, useRef, useState } from 'react'-import { ChatRequestOptions, JSONValue, Message } from 'ai'+import { UseChatHelpers } from '@ai-sdk/react'+import type { UIDataTypes, UIMessage, UITools } from '@/lib/types/ai'import { cn } from '@/lib/utils'- import { AnimatedLogo } from './ui/animated-logo'-import { Spinner } from './ui/spinner'+import { ChatError } from './chat-error'- import { DefaultSkeleton } from './default-skeleton'import { RenderMessage } from './render-message'-import { ToolSection } from './tool-section'++import { AnimatedLogo } from './ui/animated-logo'// Import section structure interfaceinterface ChatSection {diff --cc components/chat.tsxindex 579862b9,93d5dc62..1a7c0907--- a/components/chat.tsx+++ b/components/chat.tsx@@@ -215,12 -140,17 +220,12 @@@ export function Chat(})}}- }, [sections, messages])+ }, [sections, messages, id])- useEffect(() => {- setMessages(savedMessages)- // eslint-disable-next-line react-hooks/exhaustive-deps- }, [id])-const onQuerySelect = (query: string) => {- append({+ sendMessage({role: 'user',- content: query+ parts: [{ type: 'text', text: query }]})}diff --cc components/message-actions.tsxindex 1f4f921a,e4ffb1e2..8faa70c4--- a/components/message-actions.tsx+++ b/components/message-actions.tsx@@@ -1,19 -1,14 +1,19 @@@'use client'-import { useChat } from '@ai-sdk/react'-import { Copy } from 'lucide-react'+import { useMemo, useState } from 'react'++import { UseChatHelpers } from '@ai-sdk/react'+import { Copy, ThumbsDown, ThumbsUp } from 'lucide-react'import { toast } from 'sonner'+import type { SearchResultItem } from '@/lib/types'+import type { UIDataTypes, UIMessage, UITools } from '@/lib/types/ai'import { cn } from '@/lib/utils'+import { processCitations } from '@/lib/utils/citation'--import { Button } from './ui/button'import { ChatShare } from './chat-share'import { RetryButton } from './retry-button'++import { Button } from './ui/button'interface MessageActionsProps {message: stringdiff --cc components/related-questions.tsxindex 48d328e3,d81aadec..e4271055--- a/components/related-questions.tsx+++ b/components/related-questions.tsx@@@ -2,18 -2,28 +2,18 @@@import React from 'react'-import { useChat } from '@ai-sdk/react'-import { JSONValue } from 'ai'import { ArrowRight } from 'lucide-react'-import { Button } from './ui/button'-import { Skeleton } from './ui/skeleton'+import type { RelatedQuestionsData } from '@/lib/types/ai'+- import { Button } from './ui/button'- import { Skeleton } from './ui/skeleton'import { CollapsibleMessage } from './collapsible-message'import { Section } from './section'++import { Button } from './ui/button'++import { Skeleton } from './ui/skeleton'-export interface RelatedQuestionsProps {- annotations: JSONValue[]+interface RelatedQuestionsProps {+ data: RelatedQuestionsDataonQuerySelect: (query: string) => void- isOpen: boolean- onOpenChange: (open: boolean) => void- chatId: string-}--interface RelatedQuestionsAnnotation extends Record<string, JSONValue> {- type: 'related-questions'- data: {- items: Array<{ query: string }>- }}export const RelatedQuestions: React.FC<RelatedQuestionsProps> = ({diff --cc components/render-message.tsxindex ceb311d3,cc15dac0..1ddad90c--- a/components/render-message.tsx+++ b/components/render-message.tsx@@@ -1,27 -1,17 +1,24 @@@-import { useMemo } from 'react'+import { UseChatHelpers } from '@ai-sdk/react'-import { ChatRequestOptions, JSONValue, Message, ToolInvocation } from 'ai'+import type {+ UIDataTypes,+ UIMessage,+ UIMessageMetadata,+ UITools+} from '@/lib/types/ai'+import type { DynamicToolPart } from '@/lib/types/dynamic-tools'+import { extractCitationMaps } from '@/lib/utils/citation'import { AnswerSection } from './answer-section'- import { DataSection } from './data-section'-import { ReasoningSection } from './reasoning-section'-import RelatedQuestions from './related-questions'-import { ToolSection } from './tool-section'-import { UserMessage } from './user-message'+import { DynamicToolDisplay } from './dynamic-tool-display'- import { ReasoningSection } from './reasoning-section'+import ResearchProcessSection from './research-process-section'- import { ToolSection } from './tool-section'+import { UserFileSection } from './user-file-section'+import { UserTextSection } from './user-text-section'interface RenderMessageProps {- message: Message+ message: UIMessagemessageId: string- getIsOpen: (id: string) => boolean+ getIsOpen: (id: string, partType?: string, hasNextPart?: boolean) => booleanonOpenChange: (id: string, open: boolean) => voidonQuerySelect: (query: string) => voidchatId?: stringdiff --cc components/search-section.tsxindex 92f87463,baaa6f07..6589e212--- a/components/search-section.tsx+++ b/components/search-section.tsx@@@ -9,26 -7,17 +9,26 @@@ import { cn } from '@/lib/utilsimport { useArtifact } from '@/components/artifact/artifact-context'- import { StatusIndicator } from './ui/status-indicator'import { CollapsibleMessage } from './collapsible-message'import { SearchSkeleton } from './default-skeleton'+import ProcessHeader from './process-header'import { SearchResults } from './search-results'import { SearchResultsImageSection } from './search-results-image'-import { Section, ToolArgsSection } from './section'+import { Section } from './section'++import { StatusIndicator } from './ui/status-indicator'+import {+ createVideoSearchResults,+ VideoSearchResults+} from './video-search-results'interface SearchSectionProps {- tool: ToolInvocation+ tool: ToolPart<'search'>isOpen: booleanonOpenChange: (open: boolean) => void- chatId: string+ status?: UseChatHelpers<UIMessage<unknown, UIDataTypes, UITools>>['status']+ borderless?: boolean+ isFirst?: boolean+ isLast?: boolean}export function SearchSection({diff --cc components/section.tsxindex f71bdef3,403111b9..db347a5a--- a/components/section.tsx+++ b/components/section.tsx@@@ -16,10 -16,10 +16,10 @@@ importimport { cn } from '@/lib/utils'++import { ToolBadge } from './tool-badge'import { Badge } from './ui/badge'import { Separator } from './ui/separator'import { StatusIndicator } from './ui/status-indicator'--import { ToolBadge } from './tool-badge'type SectionProps = {children: React.ReactNodediff --cc lib/tools/search/providers/index.tsindex 2ccf1676,fcd39912..fdd1d6dd--- a/lib/tools/search/providers/index.ts+++ b/lib/tools/search/providers/index.ts@@@ -1,10 -1,10 +1,16 @@@import { SearchProvider } from './base'+import { BraveSearchProvider } from './brave'import { ExaSearchProvider } from './exa'+ import { FirecrawlSearchProvider } from './firecrawl'import { SearXNGSearchProvider } from './searxng'import { TavilySearchProvider } from './tavily'- export type SearchProviderType = 'tavily' | 'exa' | 'searxng' | 'brave'-export type SearchProviderType = 'tavily' | 'exa' | 'searxng' | 'firecrawl'++export type SearchProviderType =++ | 'tavily'++ | 'exa'++ | 'searxng'++ | 'firecrawl'++ | 'brave'export const DEFAULT_PROVIDER: SearchProviderType = 'tavily'export function createSearchProvider(@@@ -20,16 -20,16 +26,19 @@@return new ExaSearchProvider()case 'searxng':return new SearXNGSearchProvider()+ case 'brave':+ return new BraveSearchProvider()+ case 'firecrawl':+ return new FirecrawlSearchProvider()default:// Default to TavilySearchProvider if an unknown provider is specifiedreturn new TavilySearchProvider()}}+export { BraveSearchProvider } from './brave'export type { ExaSearchProvider } from './exa'+ export type { FirecrawlSearchProvider } from './firecrawl'export { SearXNGSearchProvider } from './searxng'export { TavilySearchProvider } from './tavily'export type { SearchProvider }