An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
feat: update CLI to support new API with model types and search modes
Yoshiki Miura81ef267c718f
diff --git a/scripts/README.md b/scripts/README.mdindex e2b67e7d..81f1f015 100644--- a/scripts/README.md+++ b/scripts/README.md@@ -10,9 +10,10 @@ A command-line interface for testing the chat API without a browser client. This- Send messages to the chat API via command line- Real-time Server-Sent Events (SSE) streaming output-- Support for different AI models-- Search mode enabled by default+- Support for model types (speed/quality) with automatic model selection+- Configurable search modes (quick/planning/adaptive) or disabled- Chat session continuity+- Message regeneration support- Secure authentication via environment variables- URL validation for security (localhost only)@@ -35,12 +36,18 @@ bun scripts/chat-cli.ts -m "Hello, how are you?"# Disable search modebun chat -m "Tell me a joke" --no-search-# Use a specific model-bun chat -m "Explain quantum computing" --model claude-3-5-sonnet+# Use quality model type for better responses+bun chat -m "Explain quantum computing" --model-type quality++# Use planning search mode for complex queries+bun chat -m "Research the latest AI developments" --search-mode planning# Continue an existing chatbun chat -c "chat_123" -m "Tell me more"+# Regenerate the last assistant message+bun chat -c "chat_123" -t regenerate --message-id "msg_456"+# Show helpbun chat --help```@@ -50,9 +57,12 @@ bun chat --help- `-m, --message <text>` - Message to send (default: "Hello, how are you?")- `-u, --url <url>` - API URL (default: http://localhost:3000/api/chat, localhost only)- `-c, --chat-id <id>` - Chat ID for session continuity (default: auto-generated)-- `-s, --search` - Enable search mode (default: true)+- `-s, --search` - Enable search mode with adaptive strategy (default)- `--no-search` - Disable search mode-- `--model <name>` - AI model to use: `gpt-4o`, `gpt-4o-mini`, `claude-3-5-sonnet`+- `--search-mode <type>` - Search strategy: `quick`, `planning`, or `adaptive`+- `--model-type <type>` - Model type: `speed` (default) or `quality`+- `-t, --trigger <type>` - Trigger type: `submit` (default) or `regenerate`+- `--message-id <id>` - Message ID (required for regenerate trigger)- `-h, --help` - Show help message### Output Format@@ -60,13 +70,41 @@ bun chat --helpThe script displays:- π Request details-- π€ Selected model-- π Search mode status+- π€ Model type (speed/quality)+- π Search mode status (quick/planning/adaptive/disabled)- π¬ Chat ID for reference- Real-time AI responses with proper formatting- π§ Tool usage (when search mode is enabled)- β Completion status+### Model Types++- **speed**: Fast responses using optimized models (default)+- **quality**: Higher quality responses using advanced models++### Search Modes++- **quick**: Fast search with basic results+- **planning**: Comprehensive search for complex queries+- **adaptive**: Intelligent search strategy based on query type (default)+- **disabled**: No search functionality (`--no-search`)++### Advanced Usage++#### Message Regeneration+You can regenerate the last assistant message in a conversation:++```bash+# First, send a message and note the chat ID and message ID from the output+bun chat -m "Tell me about AI"++# Then regenerate the assistant's response+bun chat -c "chat_123" -t regenerate --message-id "msg_456"++# Or edit the user message and regenerate+bun chat -c "chat_123" -t regenerate --message-id "msg_456" -m "Tell me about machine learning instead"+```+### Security Features- **Authentication**: Uses environment variables only (no file-based auth)@@ -82,6 +120,7 @@ The script displays:### Troubleshooting+#### Authentication ErrorsIf you encounter "User not authenticated" errors:1. Ensure you're logged into Morphic in your browser@@ -89,8 +128,29 @@ If you encounter "User not authenticated" errors:3. Update `MORPHIC_COOKIES` in `.env.local`4. Cookies expire after ~1 hour, so refresh them if needed-For other issues:+#### API Errors+If you encounter "Selected provider is not enabled" errors:++1. Check that the model type is correctly configured in your system+2. Verify the development server supports the requested model type+3. Try switching between `--model-type speed` and `--model-type quality`++#### General Issues- Check the development server is running: `bun dev`- Verify `.env.local` exists and contains `MORPHIC_COOKIES`- Use `DEBUG=1` prefix for verbose output+- Ensure the API URL is accessible (default: `http://localhost:3000/api/chat`)++#### Command Examples for Testing++```bash+# Test basic functionality+bun chat -m "Hello, test message" --no-search++# Test with quality model+bun chat -m "Complex analysis task" --model-type quality --search-mode planning++# Debug mode+DEBUG=1 bun chat -m "Debug test" --model-type speed+```diff --git a/scripts/chat-cli.ts b/scripts/chat-cli.tsindex 3bd5f6f6..1e3fd4ee 100755--- a/scripts/chat-cli.ts+++ b/scripts/chat-cli.ts@@ -14,16 +14,9 @@ interface ChatApiConfig {apiUrl: stringmessage: stringchatId?: string- selectedModel?: {- id: string- name: string- provider: string- providerId: string- enabled: boolean- toolCallType: string- }- searchMode?: boolean- trigger?: 'submit-user-message' | 'regenerate-assistant-message'+ modelType?: 'speed' | 'quality'+ searchMode?: 'quick' | 'planning' | 'adaptive' | boolean+ trigger?: 'submit-message' | 'regenerate-message'messageId?: string}@@ -41,7 +34,7 @@ interface UIMessage {interface ChatPayload {chatId: string- trigger: 'submit-user-message' | 'regenerate-assistant-message'+ trigger: 'submit-message' | 'regenerate-message'message?: UIMessagemessageId?: stringisNewChat?: boolean@@ -95,16 +88,9 @@ class ChatApiTester {this.validateUrl(config.apiUrl) || 'http://localhost:3000/api/chat',message: config.message || DEFAULT_MESSAGE,chatId: config.chatId || this.generateId(),- selectedModel: config.selectedModel || {- id: 'gpt-4o-mini',- name: 'GPT-4o mini',- provider: 'OpenAI',- providerId: 'openai',- enabled: true,- toolCallType: 'native'- },- searchMode: config.searchMode ?? true,- trigger: config.trigger || 'submit-user-message',+ modelType: config.modelType || 'speed',+ searchMode: config.searchMode ?? 'adaptive',+ trigger: config.trigger || 'submit-message',messageId: config.messageId}}@@ -145,11 +131,11 @@ class ChatApiTester {const payload: ChatPayload = {chatId: this.config.chatId!,- trigger: this.config.trigger || 'submit-user-message'+ trigger: this.config.trigger || 'submit-message'}// Add message for submit trigger or messageId for regenerate- if (this.config.trigger === 'regenerate-assistant-message') {+ if (this.config.trigger === 'regenerate-message') {if (!this.config.messageId) {console.error('β Message ID is required for regeneration')process.exit(1)@@ -173,7 +159,7 @@ class ChatApiTester {console.log('π Sending request to:', this.config.apiUrl)console.log('π¦ Payload:', JSON.stringify(payload, null, 2))- console.log('π€ Selected Model:', this.config.selectedModel?.name)+ console.log('π€ Model Type:', this.config.modelType)console.log('π Search Mode:', this.config.searchMode)console.log('π¬ Chat ID:', this.config.chatId)console.log('\n---\n')@@ -183,17 +169,19 @@ class ChatApiTester {if (cookies) {// If cookies from env exist, append our settings to themcookieString = cookies- if (!cookieString.includes('selectedModel=')) {- cookieString += `; selectedModel=${encodeURIComponent(JSON.stringify(this.config.selectedModel))}`+ if (!cookieString.includes('modelType=')) {+ cookieString += `; modelType=${this.config.modelType}`}- if (!cookieString.includes('search-mode=')) {- cookieString += `; search-mode=${this.config.searchMode}`+ if (!cookieString.includes('searchMode=')) {+ const searchModeValue = this.config.searchMode === false ? 'disabled' : this.config.searchMode+ cookieString += `; searchMode=${searchModeValue}`}} else {// If no cookies from env, just use our settings+ const searchModeValue = this.config.searchMode === false ? 'disabled' : this.config.searchModecookieString = [- `selectedModel=${encodeURIComponent(JSON.stringify(this.config.selectedModel))}`,- `search-mode=${this.config.searchMode}`+ `modelType=${this.config.modelType}`,+ `searchMode=${searchModeValue}`].join('; ')}@@ -339,60 +327,39 @@ function parseArgs(): Partial<ChatApiConfig> {breakcase '-s':case '--search':- config.searchMode = true+ config.searchMode = 'adaptive'breakcase '--no-search':config.searchMode = falsebreak- case '--model':- const modelId = args[++i]- // Map common model names- const modelMap: Record<string, any> = {- 'gpt-4.1': {- id: 'gpt-4.1',- name: 'GPT-4.1',- provider: 'OpenAI',- providerId: 'openai',- enabled: true,- toolCallType: 'native'- },- 'gpt-4o-mini': {- id: 'gpt-4o-mini',- name: 'GPT-4o mini',- provider: 'OpenAI',- providerId: 'openai',- enabled: true,- toolCallType: 'native'- },- 'claude-4-0-sonnet': {- id: 'claude-4-0-sonnet',- name: 'Claude 4.0 Sonnet',- provider: 'Anthropic',- providerId: 'anthropic',- enabled: true,- toolCallType: 'native'- },- 'claude-3-5-haiku-20241022': {- id: 'claude-3-5-haiku-20241022',- name: 'Claude 3.5 Haiku',- provider: 'Anthropic',- providerId: 'anthropic',- enabled: true,- toolCallType: 'native'- }+ case '--search-mode':+ const searchMode = args[++i]+ if (['quick', 'planning', 'adaptive'].includes(searchMode)) {+ config.searchMode = searchMode as 'quick' | 'planning' | 'adaptive'+ } else {+ console.error('β Invalid search mode. Use: quick, planning, or adaptive')+ process.exit(1)+ }+ break+ case '--model-type':+ const modelType = args[++i]+ if (['speed', 'quality'].includes(modelType)) {+ config.modelType = modelType as 'speed' | 'quality'+ } else {+ console.error('β Invalid model type. Use: speed or quality')+ process.exit(1)}- config.selectedModel = modelMap[modelId] || modelMap['gpt-4o-mini']breakcase '-t':case '--trigger':const trigger = args[++i]if (trigger === 'regenerate' ||- trigger === 'regenerate-assistant-message'+ trigger === 'regenerate-message') {- config.trigger = 'regenerate-assistant-message'+ config.trigger = 'regenerate-message'} else {- config.trigger = 'submit-user-message'+ config.trigger = 'submit-message'}breakcase '--message-id':@@ -409,9 +376,10 @@ Options:-m, --message <text> Message to send (default: "Hello, how are you?")-u, --url <url> API URL (default: http://localhost:3000/api/chat)-c, --chat-id <id> Chat ID (default: auto-generated)- -s, --search Enable search mode (default: true)+ -s, --search Enable search mode with adaptive strategy (default)--no-search Disable search mode- --model <name> Model to use: gpt-4o, gpt-4o-mini, claude-3-5-sonnet+ --search-mode <type> Search strategy: quick, planning, or adaptive+ --model-type <type> Model type: speed (default) or quality-t, --trigger <type> Trigger type: submit (default) or regenerate--message-id <id> Message ID (required for regenerate)-h, --help Show this help message@@ -423,8 +391,8 @@ Examples:# Without search modebun scripts/chat-cli.ts -m "Tell me a joke" --no-search- # With specific model- bun scripts/chat-cli.ts -m "Tell me a joke" --model claude-3-5-sonnet+ # With quality model type+ bun scripts/chat-cli.ts -m "Tell me a joke" --model-type quality# Continue existing chatbun scripts/chat-cli.ts -c "chat_123" -m "Tell me more"